summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HACKING2
-rw-r--r--giscanner/message.py3
-rw-r--r--giscanner/scannermain.py6
-rw-r--r--giscanner/utils.py21
-rwxr-xr-xtools/g-ir-scanner.in3
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