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 @@
# Cython - Command Line Parsing
#
import os
import sys
import Options
......@@ -27,6 +28,7 @@ Options:
Level indicates aggressiveness, default 0 releases nothing.
-w, --working <directory> Sets the working directory for Cython (the directory modules
are searched from)
--debug Output debug information for cygdb
-D, --no-docstrings Remove docstrings.
-a, --annotate Produce a colorized HTML version of the source.
......@@ -115,6 +117,7 @@ def parse_command_line(args):
options.emit_linenums = True
elif option == "--debug":
options.debug = True
options.output_dir = os.curdir
elif option == '-2':
options.language_level = 2
elif option == '-3':
......
......@@ -179,8 +179,8 @@ class Context(object):
test_support.append(TreeAssertVisitor())
if options.debug:
import ParseTreeTransforms
debug_transform = [ParseTreeTransforms.DebuggerTransform(self)]
from ParseTreeTransforms import DebuggerTransform
debug_transform = [DebuggerTransform(self, options.output_dir)]
else:
debug_transform = []
......
......@@ -1476,12 +1476,14 @@ class DebuggerTransform(CythonTransform):
enable debugging
"""
def __init__(self, context):
def __init__(self, context, output_dir):
super(DebuggerTransform, self).__init__(context)
self.output_dir = os.path.join(output_dir, 'cython_debug')
if etree is None:
raise Errors.NoElementTreeInstalledException()
else:
self.tb = etree.TreeBuilder()
self.tb = etree.TreeBuilder()
self.visited = set()
def visit_ModuleNode(self, node):
......@@ -1564,7 +1566,7 @@ class DebuggerTransform(CythonTransform):
xml_root_element = self.tb.close()
try:
os.mkdir('cython_debug')
os.makedirs(self.output_dir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
......@@ -1573,8 +1575,8 @@ class DebuggerTransform(CythonTransform):
kw = {}
if have_lxml:
kw['pretty_print'] = True
et.write("cython_debug/cython_debug_info_" + self.module_name,
encoding="UTF-8",
**kw)
fn = "cython_debug_info_" + self.module_name
et.write(os.path.join(self.output_dir, fn), encoding="UTF-8", **kw)
return root
\ No newline at end of file
......@@ -6,6 +6,9 @@ The Cython debugger
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
cython_debug).
Additional gdb args can be provided only if a path to the project directory is
given.
"""
import os
......@@ -14,7 +17,10 @@ import glob
import tempfile
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
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):
os.path.join(path_to_debug_info, 'cython_debug/cython_debug_info_*'))
if not debug_files:
usage()
sys.exit('No debug files were found in %s. Aborting.' % (
os.path.abspath(path_to_debug_info)))
......@@ -42,8 +49,8 @@ def main(import_libpython=False, path_to_debug_info=os.curdir):
f.write('python from Cython.Debugger import libpython\n')
f.write('\n'.join('cy import %s\n' % fn for fn in debug_files))
f.close()
p = subprocess.Popen(['gdb', '-command', tempfilename])
p = subprocess.Popen(['gdb', '-command', tempfilename] + gdb_argv)
while True:
try:
p.wait()
......
......@@ -204,6 +204,10 @@ class build_ext(_build_ext.build_ext):
if rebuild:
log.info("cythoning %s to %s", source, 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,
use_listing_file = create_listing,
include_path = includes,
......@@ -212,6 +216,7 @@ class build_ext(_build_ext.build_ext):
cplus = cplus,
emit_linenums = line_directives,
generate_pxi = pyrex_gen_pxi,
output_dir = output_dir,
debug = pyrex_debug)
result = cython_compile(source, options=options,
full_module_name=module_name)
......
......@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb
if __name__ == '__main__':
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:
cygdb.main()
......@@ -6,6 +6,7 @@ from Cython.Debugger import cygdb
if __name__ == '__main__':
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:
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