Have cygdb pass gdb command line arguments to gdb
authorMark Florisson <markflorisson88@gmail.com>
Fri, 24 Sep 2010 10:36:11 +0000 (12:36 +0200)
committerMark Florisson <markflorisson88@gmail.com>
Fri, 24 Sep 2010 10:36:11 +0000 (12:36 +0200)
Write cython_debug to the actual build directory (distutils and the cython
                                                  command line tool)
List --debug flag in cython's usage

Cython/Compiler/CmdLine.py
Cython/Compiler/Main.py
Cython/Compiler/ParseTreeTransforms.py
Cython/Debugger/cygdb.py
Cython/Distutils/build_ext.py
bin/cygdb
cygdb.py

index bc0925d26faa02a40432cbff63f1aad0926f0804..42aaa500f2438ac35dd14e2930c92534d89b2e03 100644 (file)
@@ -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':
index 761f60fefc9dfee06f9642737bf29a8e1f758d7f..817518b3b92c6ecee3960c4ea0d08fced19eabec 100644 (file)
@@ -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 = []
             
index 0279112c48fa600086c64a3b359b4a549554613e..819c87730c475d2c7fde208c696ff7cfd343cd2e 100644 (file)
@@ -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
index 9c45dfaebf6c321df79e25fab38e911bf2b548e1..f9d6f42988985fa1fea88654a1d30854948d1d50 100644 (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()
index 98416ff6194d5de3503b01672ebf44b941f05e5b..16f9b3e0ebeb44a467c74edfe47adad62712f091 100644 (file)
@@ -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)
index 8c52f9f2ed5b35267ce17e22b24b231d668a0be4..cad7d089c38eacdd23927b51e1b75757a9b5ce39 100755 (executable)
--- 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()
index 8c52f9f2ed5b35267ce17e22b24b231d668a0be4..cad7d089c38eacdd23927b51e1b75757a9b5ce39 100644 (file)
--- 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()