Commits

Armin Rigo committed 6688b05

Try to reuse the World class from viewcode. It will correctly handle
the patching, so unlike the previous version, we see correct jump
targets, for example. It's still a mess because of various issues
like objdump truncating addresses to 4 bytes.

Comments (0)

Files changed (2)

pypy/tool/jitlogparser/parser.py

             name = entry[:entry.find('(') - 1].lower()
             addr = int(m.group(1), 16)
         addrs.setdefault(addr, []).append(name)
+    from rpython.jit.backend.tool.viewcode import World
+    world = World()
+    for entry in extract_category(log, 'jit-backend-dump'):
+        world.parse(entry.splitlines(True), load_symbols=False,
+                    truncate_addr=False)
     dumps = {}
-    for entry in extract_category(log, 'jit-backend-dump'):
-        backend, _, dump, _ = entry.split("\n")
-        _, addr, _, data = re.split(" +", dump)
-        backend_name = backend.split(" ")[1]
-        addr = int(addr[1:], 16)
-        if addr < 0:
-            addr += (2 * sys.maxint + 2)
-        if addr in addrs and addrs[addr]:
-            name = addrs[addr].pop(0) # they should come in order
-            dumps[name] = (backend_name, addr, data)
+    for r in world.ranges:
+        if r.addr in addrs and addrs[r.addr]:
+            name = addrs[r.addr].pop(0) # they should come in order
+            data = r.data.encode('hex')       # backward compatibility
+            dumps[name] = (world.backend_name, r.addr, data)
     loops = []
     for entry in extract_category(log, 'jit-log-opt'):
         parser = ParserCls(entry, None, {}, 'lltype', None,

rpython/jit/backend/tool/viewcode.py

         self.backend_name = None
         self.executable_name = None
 
-    def parse(self, f, textonly=True):
+    def parse(self, f, textonly=True, load_symbols=True, truncate_addr=True):
         for line in f:
             if line.startswith('BACKEND '):
                 self.backend_name = line.split(' ')[1].strip()
                 assert pieces[2].startswith('+')
                 if len(pieces) == 3:
                     continue     # empty line
-                baseaddr = long(pieces[1][1:], 16) & 0xFFFFFFFFL
+                baseaddr = long(pieces[1][1:], 16)
+                if truncate_addr:
+                    baseaddr &= 0xFFFFFFFFL
+                elif baseaddr < 0:
+                    baseaddr += (2 * sys.maxint + 2)
                 offset = int(pieces[2][1:])
                 addr = baseaddr + offset
                 data = pieces[3].replace(':', '').decode('hex')
                 pieces = line.split(None, 3)
                 assert pieces[1].startswith('@')
                 assert pieces[2].startswith('+')
-                baseaddr = long(pieces[1][1:], 16) & 0xFFFFFFFFL
+                baseaddr = long(pieces[1][1:], 16)
+                if truncate_addr:
+                    baseaddr &= 0xFFFFFFFFL
+                elif baseaddr < 0:
+                    baseaddr += (2 * sys.maxint + 2)
                 offset = int(pieces[2][1:])
                 addr = baseaddr + offset
                 self.logentries[addr] = pieces[3]
             elif line.startswith('SYS_EXECUTABLE '):
+                if not load_symbols:
+                    continue
                 filename = line[len('SYS_EXECUTABLE '):].strip()
                 if filename != self.executable_name and filename != '??':
                     self.symbols.update(load_symbols(filename))