Commit 9eaba388 authored by Mark Florisson's avatar Mark Florisson

Have cygdb pass gdb command line arguments to gdb

Write cython_debug to the actual build directory (distutils and the cython
                                                  command line tool)
List --debug flag in cython's usage
parent 29e61a09
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Cython - Command Line Parsing # Cython - Command Line Parsing
# #
import os
import sys import sys
import Options import Options
...@@ -27,6 +28,7 @@ Options: ...@@ -27,6 +28,7 @@ Options:
Level indicates aggressiveness, default 0 releases nothing. Level indicates aggressiveness, default 0 releases nothing.
-w, --working <directory> Sets the working directory for Cython (the directory modules -w, --working <directory> Sets the working directory for Cython (the directory modules
are searched from) are searched from)
--debug Output debug information for cygdb
-D, --no-docstrings Remove docstrings. -D, --no-docstrings Remove docstrings.
-a, --annotate Produce a colorized HTML version of the source. -a, --annotate Produce a colorized HTML version of the source.
...@@ -115,6 +117,7 @@ def parse_command_line(args): ...@@ -115,6 +117,7 @@ def parse_command_line(args):
options.emit_linenums = True options.emit_linenums = True
elif option == "--debug": elif option == "--debug":
options.debug = True options.debug = True
options.output_dir = os.curdir
elif option == '-2': elif option == '-2':
options.language_level = 2 options.language_level = 2
elif option == '-3': elif option == '-3':
......
...@@ -179,8 +179,8 @@ class Context(object): ...@@ -179,8 +179,8 @@ class Context(object):
test_support.append(TreeAssertVisitor()) test_support.append(TreeAssertVisitor())
if options.debug: if options.debug:
import ParseTreeTransforms from ParseTreeTransforms import DebuggerTransform
debug_transform = [ParseTreeTransforms.DebuggerTransform(self)] debug_transform = [DebuggerTransform(self, options.output_dir)]
else: else:
debug_transform = [] debug_transform = []
......
...@@ -1476,11 +1476,13 @@ class DebuggerTransform(CythonTransform): ...@@ -1476,11 +1476,13 @@ class DebuggerTransform(CythonTransform):
enable debugging enable debugging
""" """
def __init__(self, context): def __init__(self, context, output_dir):
super(DebuggerTransform, self).__init__(context) super(DebuggerTransform, self).__init__(context)
self.output_dir = os.path.join(output_dir, 'cython_debug')
if etree is None: if etree is None:
raise Errors.NoElementTreeInstalledException() raise Errors.NoElementTreeInstalledException()
else:
self.tb = etree.TreeBuilder() self.tb = etree.TreeBuilder()
self.visited = set() self.visited = set()
...@@ -1564,7 +1566,7 @@ class DebuggerTransform(CythonTransform): ...@@ -1564,7 +1566,7 @@ class DebuggerTransform(CythonTransform):
xml_root_element = self.tb.close() xml_root_element = self.tb.close()
try: try:
os.mkdir('cython_debug') os.makedirs(self.output_dir)
except OSError, e: except OSError, e:
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
raise raise
...@@ -1573,8 +1575,8 @@ class DebuggerTransform(CythonTransform): ...@@ -1573,8 +1575,8 @@ class DebuggerTransform(CythonTransform):
kw = {} kw = {}
if have_lxml: if have_lxml:
kw['pretty_print'] = True kw['pretty_print'] = True
et.write("cython_debug/cython_debug_info_" + self.module_name,
encoding="UTF-8", fn = "cython_debug_info_" + self.module_name
**kw) et.write(os.path.join(self.output_dir, fn), encoding="UTF-8", **kw)
return root return root
\ No newline at end of file
...@@ -6,6 +6,9 @@ The Cython debugger ...@@ -6,6 +6,9 @@ The Cython debugger
The current directory should contain a directory named 'cython_debug', or a The current directory should contain a directory named 'cython_debug', or a
path to the cython project directory should be given (the parent directory of path to the cython project directory should be given (the parent directory of
cython_debug). cython_debug).
Additional gdb args can be provided only if a path to the project directory is
given.
""" """
import os import os
...@@ -14,7 +17,10 @@ import glob ...@@ -14,7 +17,10 @@ import glob
import tempfile import tempfile
import subprocess import subprocess
def main(import_libpython=False, path_to_debug_info=os.curdir): def usage():
print("Usage: cygdb [PATH GDB_ARGUMENTS]")
def main(gdb_argv=[], import_libpython=False, path_to_debug_info=os.curdir):
""" """
Start the Cython debugger. This tells gdb to import the Cython and Python Start the Cython debugger. This tells gdb to import the Cython and Python
extensions (libpython.py and libcython.py) and it enables gdb's pending extensions (libpython.py and libcython.py) and it enables gdb's pending
...@@ -29,6 +35,7 @@ def main(import_libpython=False, path_to_debug_info=os.curdir): ...@@ -29,6 +35,7 @@ def main(import_libpython=False, path_to_debug_info=os.curdir):
os.path.join(path_to_debug_info, 'cython_debug/cython_debug_info_*')) os.path.join(path_to_debug_info, 'cython_debug/cython_debug_info_*'))
if not debug_files: if not debug_files:
usage()
sys.exit('No debug files were found in %s. Aborting.' % ( sys.exit('No debug files were found in %s. Aborting.' % (
os.path.abspath(path_to_debug_info))) os.path.abspath(path_to_debug_info)))
...@@ -43,7 +50,7 @@ def main(import_libpython=False, path_to_debug_info=os.curdir): ...@@ -43,7 +50,7 @@ def main(import_libpython=False, path_to_debug_info=os.curdir):
f.write('\n'.join('cy import %s\n' % fn for fn in debug_files)) f.write('\n'.join('cy import %s\n' % fn for fn in debug_files))
f.close() f.close()
p = subprocess.Popen(['gdb', '-command', tempfilename]) p = subprocess.Popen(['gdb', '-command', tempfilename] + gdb_argv)
while True: while True:
try: try:
p.wait() p.wait()
......
...@@ -204,6 +204,10 @@ class build_ext(_build_ext.build_ext): ...@@ -204,6 +204,10 @@ class build_ext(_build_ext.build_ext):
if rebuild: if rebuild:
log.info("cythoning %s to %s", source, target) log.info("cythoning %s to %s", source, target)
self.mkpath(os.path.dirname(target)) self.mkpath(os.path.dirname(target))
if self.inplace:
output_dir = os.curdir
else:
output_dir = self.build_lib
options = CompilationOptions(pyrex_default_options, options = CompilationOptions(pyrex_default_options,
use_listing_file = create_listing, use_listing_file = create_listing,
include_path = includes, include_path = includes,
...@@ -212,6 +216,7 @@ class build_ext(_build_ext.build_ext): ...@@ -212,6 +216,7 @@ class build_ext(_build_ext.build_ext):
cplus = cplus, cplus = cplus,
emit_linenums = line_directives, emit_linenums = line_directives,
generate_pxi = pyrex_gen_pxi, generate_pxi = pyrex_gen_pxi,
output_dir = output_dir,
debug = pyrex_debug) debug = pyrex_debug)
result = cython_compile(source, options=options, result = cython_compile(source, options=options,
full_module_name=module_name) full_module_name=module_name)
......
...@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb ...@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 1: if len(sys.argv) > 1:
cygdb.main(path_to_debug_info=sys.argv[1]) cygdb.main(path_to_debug_info=sys.argv[1],
gdb_argv=sys.argv[2:])
else: else:
cygdb.main() cygdb.main()
...@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb ...@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 1: if len(sys.argv) > 1:
cygdb.main(path_to_debug_info=sys.argv[1]) cygdb.main(path_to_debug_info=sys.argv[1],
gdb_argv=sys.argv[2:])
else: else:
cygdb.main() cygdb.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment