diff options
author | Colin Walters <walters@verbum.org> | 2010-09-07 09:52:54 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-09-07 10:22:23 -0400 |
commit | 4905b753cbad546875616eae13918eca539680c9 (patch) | |
tree | f251134c64683fadf1774d230e17056130b34c1f | |
parent | 2eb614e805311841e17fd4dbe76aa70443f3a911 (diff) | |
download | gobject-introspection-4905b753cbad546875616eae13918eca539680c9.tar.gz |
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.
-rw-r--r-- | HACKING | 2 | ||||
-rw-r--r-- | giscanner/message.py | 3 | ||||
-rw-r--r-- | giscanner/scannermain.py | 6 | ||||
-rw-r--r-- | giscanner/utils.py | 21 | ||||
-rwxr-xr-x | tools/g-ir-scanner.in | 3 |
5 files changed, 32 insertions, 3 deletions
diff --git a/HACKING b/HACKING new file mode 100644 index 00000000..11a9275e --- /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 7644c1ea..a522b75c 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 42f74b7d..630acb6f 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 dba958ef..2263b8cd 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 5b8035b7..943d9baa 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 |