[gobject-introspection] scanner: Add various static debug hooks in GI_SCANNER_DEBUG



commit 4905b753cbad546875616eae13918eca539680c9
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 7 09:52:54 2010 -0400

    scanner: Add various static debug hooks in GI_SCANNER_DEBUG
    
    For backwards compat, keep the presence of the environment
    variable at all to mean "exception".
    
    Also start a HACKING file.

 HACKING                  |    2 ++
 giscanner/message.py     |    3 +++
 giscanner/scannermain.py |    6 ++++--
 giscanner/utils.py       |   21 +++++++++++++++++++++
 tools/g-ir-scanner.in    |    3 ++-
 5 files changed, 32 insertions(+), 3 deletions(-)
---
diff --git a/HACKING b/HACKING
new file mode 100644
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.
diff --git a/giscanner/message.py b/giscanner/message.py
index 7644c1e..a522b75 100644
--- a/giscanner/message.py
+++ b/giscanner/message.py
@@ -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
 
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index 42f74b7..630acb6 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -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)
diff --git a/giscanner/utils.py b/giscanner/utils.py
index dba958e..2263b8c 100644
--- a/giscanner/utils.py
+++ b/giscanner/utils.py
@@ -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])')
diff --git a/tools/g-ir-scanner.in b/tools/g-ir-scanner.in
index 5b8035b..943d9ba 100755
--- a/tools/g-ir-scanner.in
+++ b/tools/g-ir-scanner.in
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]