From: Mark Florisson Date: Fri, 24 Sep 2010 10:36:11 +0000 (+0200) Subject: Have cygdb pass gdb command line arguments to gdb X-Git-Tag: 0.14.beta0~1^2~55 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9eaba3880f97dcbb2164bc9a6a4371344b48b843;p=cython.git 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 --- diff --git a/Cython/Compiler/CmdLine.py b/Cython/Compiler/CmdLine.py index bc0925d2..42aaa500 100644 --- a/Cython/Compiler/CmdLine.py +++ b/Cython/Compiler/CmdLine.py @@ -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 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': diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index 761f60fe..817518b3 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -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 = [] diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 0279112c..819c8773 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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 diff --git a/Cython/Debugger/cygdb.py b/Cython/Debugger/cygdb.py index 9c45dfae..f9d6f429 100644 --- a/Cython/Debugger/cygdb.py +++ b/Cython/Debugger/cygdb.py @@ -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() diff --git a/Cython/Distutils/build_ext.py b/Cython/Distutils/build_ext.py index 98416ff6..16f9b3e0 100644 --- a/Cython/Distutils/build_ext.py +++ b/Cython/Distutils/build_ext.py @@ -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) diff --git a/bin/cygdb b/bin/cygdb index 8c52f9f2..cad7d089 100755 --- a/bin/cygdb +++ b/bin/cygdb @@ -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() diff --git a/cygdb.py b/cygdb.py index 8c52f9f2..cad7d089 100644 --- a/cygdb.py +++ b/cygdb.py @@ -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()