scanner: Add various static debug hooks in GI_SCANNER_DEBUG
authorColin Walters <walters@verbum.org>
Tue, 7 Sep 2010 13:52:54 +0000 (09:52 -0400)
committerColin Walters <walters@verbum.org>
Tue, 7 Sep 2010 14:22:23 +0000 (10:22 -0400)
For backwards compat, keep the presence of the environment
variable at all to mean "exception".

Also start a HACKING file.

HACKING [new file with mode: 0644]
giscanner/message.py
giscanner/scannermain.py
giscanner/utils.py
tools/g-ir-scanner.in

diff --git a/HACKING b/HACKING
new file mode 100644 (file)
index 0000000..11a9275
--- /dev/null
+++ b/HACKING
@@ -0,0 +1,2 @@
+* You can use the GI_SCANNER_DEBUG environment variable; see utils.py
+  for a list of debug flags.
index 7644c1e..a522b75 100644 (file)
@@ -24,6 +24,7 @@ import os
 import sys
 
 from . import ast
+from . import utils
 
 (WARNING,
  ERROR,
@@ -56,6 +57,8 @@ class MessageLogger(object):
     def log(self, log_type, text, file_positions=None, prefix=None):
         """Log a warning, using optional file positioning information.
 If the warning is related to a ast.Node type, see log_node_warning()."""
+        utils.break_on_debug_flag('warning')
+
         if not self._enable_warnings:
             return
 
index 42f74b7..630acb6 100644 (file)
@@ -40,7 +40,7 @@ from giscanner.maintransformer import MainTransformer
 from giscanner.shlibs import resolve_shlibs
 from giscanner.sourcescanner import SourceScanner
 from giscanner.transformer import Transformer
-from giscanner.utils import files_are_identical
+from . import utils
 
 def _get_option_parser():
     parser = optparse.OptionParser('%prog [options] sources')
@@ -334,6 +334,8 @@ def scanner_main(args):
     main = MainTransformer(transformer, blocks)
     main.transform()
 
+    utils.break_on_debug_flag('tree')
+
     final = IntrospectablePass(transformer)
     final.validate()
 
@@ -362,7 +364,7 @@ def scanner_main(args):
         temp_f = os.fdopen(temp_f, 'w')
         passthrough_gir(main_f_name, temp_f)
         temp_f.close()
-        if not files_are_identical(main_f_name, temp_f_name):
+        if not utils.files_are_identical(main_f_name, temp_f_name):
             _error("Failed to re-parse gir file; scanned=%r passthrough=%r" % (
                 main_f_name, temp_f_name))
         os.unlink(temp_f_name)
index dba958e..2263b8c 100644 (file)
@@ -22,6 +22,27 @@ import re
 import os
 import subprocess
 
+_debugflags = None
+def have_debug_flag(flag):
+    """Check for whether a specific debugging feature is enabled.
+Well-known flags:
+ * start: Drop into debugger just after processing arguments
+ * exception: Drop into debugger on fatalexception
+ * warning: Drop into debugger on warning
+ * posttrans: Drop into debugger just before introspectable pass
+"""
+    global _debugflags
+    if _debugflags is None:
+        _debugflags = os.environ.get('GI_SCANNER_DEBUG', '').split(',')
+        if '' in _debugflags:
+            _debugflags.remove('')
+    return flag in _debugflags
+
+def break_on_debug_flag(flag):
+    if have_debug_flag(flag):
+        import pdb
+        pdb.set_trace()
+
 # Copied from h2defs.py
 _upperstr_pat1 = re.compile(r'([^A-Z])([A-Z])')
 _upperstr_pat2 = re.compile(r'([A-Z][A-Z])([A-Z][0-9a-z])')
index 5b8035b..943d9ba 100755 (executable)
@@ -23,7 +23,8 @@ import os
 import sys
 
 if 'GI_SCANNER_DEBUG' in os.environ:
-    def on_exception(type, value, tb):
+    def on_exception(exctype, value, tb):
+        print "Caught exception: %r %r" % (exctype, value)
         import pdb
         pdb.pm()
     sys.excepthook = on_exception