Bug 1180984 - JS GDB pretty-printers: Support Python 3. r=sfink
authorJim Blandy <jimb@mozilla.com>
Tue, 07 Jul 2015 08:35:58 -0700
changeset 286821 bdad8334d636e3eff9f164a61b0aa122fbdbc35a
parent 286820 dde3457426b911e377c9f7b559a609a8d695a4b8
child 286822 6e93bd79e8481aa4ac809db3da2c1781871b7bde
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1180984
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1180984 - JS GDB pretty-printers: Support Python 3. r=sfink
js/src/gdb/lib-for-tests/catcher.py
js/src/gdb/lib-for-tests/prologue.py
js/src/gdb/mozilla/JSSymbol.py
js/src/gdb/mozilla/asmjs.py
js/src/gdb/run-tests.py
--- a/js/src/gdb/lib-for-tests/catcher.py
+++ b/js/src/gdb/lib-for-tests/catcher.py
@@ -10,13 +10,13 @@
 # simple as possible!
 
 import os
 import sys
 import traceback
 try:
     # testlibdir is set on the GDB command line, via:
     # --eval-command python testlibdir=...
-    execfile(os.path.join(testlibdir, 'prologue.py'))
+    exec(open(os.path.join(testlibdir, 'prologue.py')).read())
 except Exception as err:
     sys.stderr.write('Error running GDB prologue:\n')
     traceback.print_exc()
     sys.exit(1)
--- a/js/src/gdb/lib-for-tests/prologue.py
+++ b/js/src/gdb/lib-for-tests/prologue.py
@@ -18,19 +18,19 @@ def run_fragment(fragment, function='bre
         assert bp.hit_count == 1
     finally:
         bp.delete()
     gdb.execute('frame 1')
 
 # Assert that |actual| is equal to |expected|; if not, complain in a helpful way.
 def assert_eq(actual, expected):
     if actual != expected:
-        raise AssertionError, """Unexpected result:
+        raise AssertionError("""Unexpected result:
 expected: %r
-actual:   %r""" % (expected, actual)
+actual:   %r""" % (expected, actual))
 
 # Assert that |value|'s pretty-printed form is |form|. If |value| is a
 # string, then evaluate it with gdb.parse_and_eval to produce a value.
 def assert_pretty(value, form):
     if isinstance(value, str):
         value = gdb.parse_and_eval(value)
     assert_eq(str(value), form)
 
@@ -39,37 +39,37 @@ def assert_pretty(value, form):
 def assert_subprinter_registered(printer, subprinter):
     # Match a line containing |printer| followed by a colon, and then a
     # series of more-indented lines containing |subprinter|.
 
     names = { 'printer': re.escape(printer), 'subprinter': re.escape(subprinter) }
     pat = r'^( +)%(printer)s *\n(\1 +.*\n)*\1 +%(subprinter)s *\n' % names
     output = gdb.execute('info pretty-printer', to_string=True)
     if not re.search(pat, output, re.MULTILINE):
-        raise AssertionError, ("assert_subprinter_registered failed to find pretty-printer:\n"
-                               "  %s:%s\n"
-                               "'info pretty-printer' says:\n"
-                               "%s" % (printer, subprinter, output))
+        raise AssertionError("assert_subprinter_registered failed to find pretty-printer:\n"
+                             "  %s:%s\n"
+                             "'info pretty-printer' says:\n"
+                             "%s" % (printer, subprinter, output))
 
 # Request full stack traces for Python errors.
 gdb.execute('set python print-stack full')
 
 # Tell GDB not to ask the user about the things we tell it to do.
 gdb.execute('set confirm off', False)
 
 # Some print settings that make testing easier.
 gdb.execute('set print static-members off')
 gdb.execute('set print address off')
 gdb.execute('set print pretty off')
 gdb.execute('set width 0')
 
 try:
     # testscript is set on the GDB command line, via:
     # --eval-command python testscript=...
-    execfile(testscript)
+    exec(open(testscript).read())
 except AssertionError as err:
     sys.stderr.write('\nAssertion traceback:\n')
     (t, v, tb) = sys.exc_info()
     traceback.print_tb(tb)
     sys.stderr.write('\nTest assertion failed:\n')
     sys.stderr.write(str(err))
     sys.exit(1)
 
--- a/js/src/gdb/mozilla/JSSymbol.py
+++ b/js/src/gdb/mozilla/JSSymbol.py
@@ -13,17 +13,17 @@ UniqueSymbol = 0xffffffff
 
 @ptr_pretty_printer("JS::Symbol")
 class JSSymbolPtr(mozilla.prettyprinters.Pointer):
     def __init__(self, value, cache):
         super(JSSymbolPtr, self).__init__(value, cache)
         self.value = value
 
     def to_string(self):
-        code = int(self.value['code_'])
+        code = int(self.value['code_']) & 0xffffffff
         desc = str(self.value['description_'])
         if code == InSymbolRegistry:
             return "Symbol.for({})".format(desc)
         elif code == UniqueSymbol:
             return "Symbol({})".format(desc)
         else:
             # Well-known symbol. Strip off the quotes added by the JSString *
             # pretty-printer.
--- a/js/src/gdb/mozilla/asmjs.py
+++ b/js/src/gdb/mozilla/asmjs.py
@@ -20,17 +20,17 @@ def on_stop(event):
             sigaction_buffers[process] = buf
 
         # See if AsmJSFaultHandler is installed as the SIGSEGV signal action.
         sigaction_fn = gdb.parse_and_eval('__sigaction')
         sigaction_fn(SIGSEGV, 0, buf)
         AsmJSFaultHandler = gdb.parse_and_eval("AsmJSFaultHandler")
         if buf['__sigaction_handler']['sa_handler'] == AsmJSFaultHandler:
             # Advise the user that magic is happening.
-            print "js/src/gdb/mozilla/asmjs.py: Allowing AsmJSFaultHandler to run."
+            print("js/src/gdb/mozilla/asmjs.py: Allowing AsmJSFaultHandler to run.")
 
             # If AsmJSFaultHandler doesn't handle this segfault, it will unhook
             # itself and re-raise.
             gdb.execute("continue")
 
 def on_exited(event):
     if event.inferior in sigaction_buffers:
         del sigaction_buffers[event.inferior]
--- a/js/src/gdb/run-tests.py
+++ b/js/src/gdb/run-tests.py
@@ -156,17 +156,17 @@ class Test(TaskPool.Task):
         return [OPTIONS.gdb_executable,
                 '-nw',          # Don't create a window (unnecessary?)
                 '-nx',          # Don't read .gdbinit.
                 '--ex', 'add-auto-load-safe-path %s' % (OPTIONS.builddir,),
                 '--ex', 'set env LD_LIBRARY_PATH %s' % os.path.join(OPTIONS.objdir, 'js', 'src'),
                 '--ex', 'file %s' % (os.path.join(OPTIONS.builddir, 'gdb-tests'),),
                 '--eval-command', 'python testlibdir=%r' % (testlibdir,),
                 '--eval-command', 'python testscript=%r' % (self.test_path,),
-                '--eval-command', 'python execfile(%r)' % os.path.join(testlibdir, 'catcher.py')]
+                '--eval-command', 'python exec(open(%r).read())' % os.path.join(testlibdir, 'catcher.py')]
 
     def start(self, pipe, deadline):
         super(Test, self).start(pipe, deadline)
         if OPTIONS.show_cmd:
             self.summary.interleave_output(lambda: self.show_cmd(sys.stdout))
 
     def onStdout(self, text):
         self.stdout += text