From: Armin R. <ar...@us...> - 2003-01-17 14:42:34
|
Update of /cvsroot/psyco/psyco/py-utils In directory sc8-pr-cvs1:/tmp/cvs-serv32609/py-utils Modified Files: httpxam.py xam.py Added Files: .cvsignore Log Message: major update --- NEW FILE: .cvsignore --- *.py[co] Index: httpxam.py =================================================================== RCS file: /cvsroot/psyco/psyco/py-utils/httpxam.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** httpxam.py 11 Sep 2002 09:11:19 -0000 1.8 --- httpxam.py 17 Jan 2003 14:41:55 -0000 1.9 *************** *** 1,3 **** ! import sys, re, cStringIO, os, dis, types, traceback import xam, psyco from SimpleHTTPServer import SimpleHTTPRequestHandler, test --- 1,3 ---- ! import sys, re, cStringIO, os, dis, types import xam, psyco from SimpleHTTPServer import SimpleHTTPRequestHandler, test *************** *** 32,71 **** return text re_codebuf = re.compile(r'[/]0x([0-9A-Fa-f]+)$') re_proxy = re.compile(r'[/]proxy(\d+)$') ! def cache_load(filename): ! if not filename.endswith('.py'): ! return 0, "Not a module name" ! path = filename[:-3].split(os.sep) ! if os.path.isabs(filename): ! # translate absolute paths into paths relative to sys.path ! pathlist = sys.path[:] ! pathlist.sort() ! pathlist.reverse() # roughly: subdirs first ! for p in pathlist: ! if os.path.isabs(p): ! p = p.split(os.sep) ! if path[:len(p)] == p: ! # module name is relative to 'p' ! del path[:len(p)] ! break ! while '.' in path: ! path.remove('.') ! while '..' in path: ! i = path.index('..') ! if i == 0: ! return 0, "Outside of the current directory" ! path.remove(i) ! path.remove(i-1) ! modulename = '.'.join(path) try: ! mod = __import__(modulename, globals(), locals(), ['__doc__']) ! return 1, mod.__dict__ ! except: ! f = cStringIO.StringIO() ! print >> f, "While importing module '%s':" % modulename ! traceback.print_exc(file=f) ! return 0, f.getvalue() class CodeBufHTTPHandler(SimpleHTTPRequestHandler): --- 32,69 ---- return text + def summary_vinfos(array, d, path=[]): + text = '' + indent = ' ' * len(path) + for i in range(len(array)): + vi = array[i] + text += indent + if vi is None: + text += "[NULL]\n" + else: + text += "%d. %s" % (i, vi.getsummarytext()) + if d.has_key(vi.addr): + text += " (already seen above)" + else: + d[vi.addr] = 1 + text += '\n' + if vi.array: + text += summary_vinfos(vi.array, d, path+[i]) + return text + re_codebuf = re.compile(r'[/]0x([0-9A-Fa-f]+)$') re_proxy = re.compile(r'[/]proxy(\d+)$') + re_summary = re.compile(r'[/]summary(\d+)$') ! def cache_load(filename, cache={}): try: ! return cache[filename] ! except KeyError: ! data = {} ! try: ! f = execfile(filename, data) ! except: ! data = None ! cache[filename] = data ! return data class CodeBufHTTPHandler(SimpleHTTPRequestHandler): *************** *** 167,174 **** if match: title = 'Snapshot' ! proxy = codebufs[int(match.group(1))] ! filename = proxy.co_filename ! ok, moduledata = cache_load(filename) ! if not ok: co = None else: --- 165,191 ---- if match: title = 'Snapshot' ! n = int(match.group(1)) ! proxy = codebufs[n] ! for n1 in xrange(n-1, -1, -1): ! pprev = codebufs[n1] ! if (pprev.nextinstr == proxy.nextinstr and ! pprev.co_name == proxy.co_name and ! pprev.co_filename == proxy.co_filename): ! pprev = n1 ! break ! else: ! pprev = None ! for n1 in xrange(n+1, len(codebufs)): ! pnext = codebufs[n1] ! if (pnext.nextinstr == proxy.nextinstr and ! pnext.co_name == proxy.co_name and ! pnext.co_filename == proxy.co_filename): ! pnext = n1 ! break ! else: ! pnext = None ! filename = os.path.join(DIRECTORY, proxy.co_filename) ! moduledata = cache_load(filename) ! if moduledata is None: co = None else: *************** *** 176,192 **** try: co = psyco.unproxy(co) - except TypeError: - pass except psyco.error: pass if hasattr(co, 'func_code'): co = co.func_code ! data = '<p>PsycoObject structure at this point:</p>\n' data += show_vinfos(proxy.vlocals, {}, co) data += '<hr><p>Disassembly of %s:%s:%s:</p>\n' % ( proxy.co_filename, proxy.co_name, proxy.get_next_instr()) ! if not ok: ! txt = "While loading the file '%s':\n%s\n" % ( ! filename, moduledata) else: if not hasattr(co, 'co_code'): --- 193,219 ---- try: co = psyco.unproxy(co) except psyco.error: pass + except TypeError: + pass if hasattr(co, 'func_code'): co = co.func_code ! data = '<p>PsycoObject structure at this point:' ! data += ' ' * 20 ! data += '[' ! data += ' <a href="summary%d">summary</a> ' % n ! if pprev is not None or pnext is not None: ! if pprev is not None: ! data += ' <a href="proxy%d"><<< previous</a> ' % pprev ! if pnext is not None: ! data += ' <a href="proxy%d">next >>></a> ' % pnext ! data += ']' ! data += '</p>\n' data += show_vinfos(proxy.vlocals, {}, co) data += '<hr><p>Disassembly of %s:%s:%s:</p>\n' % ( proxy.co_filename, proxy.co_name, proxy.get_next_instr()) ! if moduledata is None: ! txt = "(exception while loading the file '%s')\n" % ( ! filename) else: if not hasattr(co, 'co_code'): *************** *** 205,208 **** --- 232,245 ---- data += "<br><a href='/0x%x'>Back</a>\n" % proxy.addr else: + match = re_summary.match(self.path) + if match: + n = int(match.group(1)) + proxy = codebufs[n] + data = summary_vinfos(proxy.vlocals, {}) + f = cStringIO.StringIO(data) + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + return f self.send_error(404, "Invalid path") return None *************** *** 220,225 **** print " are loaded from the <directory>." sys.exit(1) ! os.chdir(sys.argv[1]) del sys.argv[1] ! codebufs = xam.readdump('psyco.dump') test(CodeBufHTTPHandler) --- 257,262 ---- print " are loaded from the <directory>." sys.exit(1) ! DIRECTORY = sys.argv[1] del sys.argv[1] ! codebufs = xam.readdump(os.path.join(DIRECTORY, 'psyco.dump')) test(CodeBufHTTPHandler) Index: xam.py =================================================================== RCS file: /cvsroot/psyco/psyco/py-utils/xam.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** xam.py 4 Oct 2002 10:30:51 -0000 1.12 --- xam.py 17 Jan 2003 14:41:56 -0000 1.13 *************** *** 82,90 **** def codeat(addr): ! i = bisect.bisect_left(codeboundary, (addr, None)) ! if i<len(codeboundary): ! addrend, codebuf = codeboundary[i] ! if isinstance(codebuf, CodeBuf) and \ ! codebuf.addr <= addr < codebuf.addr + len(codebuf.data): return codebuf --- 82,89 ---- def codeat(addr): ! i = bisect.bisect(codeboundary, (addr, None)) ! if i>0: ! addrend, codebuf = codeboundary[i-1] ! if isinstance(codebuf, CodeBuf): return codebuf *************** *** 100,104 **** def __init__(self, mode, co_filename, co_name, nextinstr, ! addr, data, stackdepth): self.mode = mode self.co_filename = co_filename --- 99,103 ---- def __init__(self, mode, co_filename, co_name, nextinstr, ! addr, stackdepth): self.mode = mode self.co_filename = co_filename *************** *** 106,115 **** self.nextinstr = nextinstr self.addr = addr ! self.data = data self.stackdepth = stackdepth #self.reverse_lookup = [] # list of (offset, codebuf pointing there) self.specdict = [] ! if self.data: ! codeboundary.append((self.addr+len(self.data)-1, self)) #for i in range(4, len(data)+1): # offset, = struct.unpack('l', data[i-4:i]) --- 105,116 ---- self.nextinstr = nextinstr self.addr = addr ! #self.data = data self.stackdepth = stackdepth #self.reverse_lookup = [] # list of (offset, codebuf pointing there) self.specdict = [] ! if self.mode != "proxy": ! codeboundary.append((self.addr-0.5, self)) ! else: ! self.data = "" #for i in range(4, len(data)+1): # offset, = struct.unpack('l', data[i-4:i]) *************** *** 117,138 **** def __getattr__(self, attr): if attr == 'cache_text': # produce the disassembly listing data = self.data addr = self.addr ! self.cache_text = [] ! for i in range(0, 16): ! if data[i:i+4] == '\x66\x66\x66\x66': ! # detected a rt_local_buf_t structure ! next, key = struct.unpack('ll', data[i+4:i+12]) ! data = data[i+12:] ! addr += i+12 ! self.cache_text = [ ! 'Created by promotion of the value 0x%x\n' % key, ! 'Next promoted value at buffer 0x%x\n' % next, ! ] ! break ! if data[i:i+1] != '\xCC': ! break f = open(tmpfile, 'wb') f.write(data) --- 118,148 ---- def __getattr__(self, attr): + if attr == 'data': + i = bisect.bisect(codeboundary, (self.addr-0.5, self)) + assert codeboundary[i-1][1] is self + next = codeboundary[i][1] + while not isinstance(codeboundary[i][1], BigBuffer): + i = i + 1 + bigbuf = codeboundary[i][1] + self.data = data = bigbuf.load(self.addr, next.addr) + return data if attr == 'cache_text': # produce the disassembly listing data = self.data addr = self.addr ! k = 0 ! while data[k:k+1] == '\xCC': ! k = k + 1 ! if data[k:k+4] == '\x66\x66\x66\x66': ! # detected a rt_local_buf_t structure ! next, key = struct.unpack('ll', data[k+4:k+12]) ! data = data[k+12:] ! addr += k+12 ! self.cache_text = [ ! 'Created by promotion of the value 0x%x\n' % key, ! 'Next promoted value at buffer 0x%x\n' % next, ! ] ! else: ! self.cache_text = [] f = open(tmpfile, 'wb') f.write(data) *************** *** 268,271 **** --- 278,298 ---- + class BigBuffer: + def __init__(self, file, start, length): + #print 'BigBuffer:', hex(start), hex(start+length), '(%d)' % length + self.file = file + self.offset = file.tell() + self.start = start + self.length = length + self.addr = start + length # end address + codeboundary.append((self.addr+0.5, self)) + file.seek(self.length, 1) + def load(self, begin, end): + assert self.start <= begin <= self.addr, \ + (hex(self.start), hex(begin), hex(end), hex(self.addr)) + self.file.seek(self.offset + (begin-self.start)) + return self.file.read(min(self.addr, end) - begin) + + class VInfo: pass *************** *** 282,285 **** --- 309,318 ---- text += ", reference" return text + def getsummarytext(self): + text = "Compile-time" + if self.flags & 1: + text += " fixed" + text += " 0x%x" % self.value + return text class RunTimeVInfo(VInfo): *************** *** 299,307 **** text += " in stack [ESP+0x%x] or from top %d" % \ (self.stackdepth - stack, stack) - if self.source & 0x04000000: - text += " non-negative" if not (self.source & 0x08000000): text += " holding a reference" return text class VirtualTimeVInfo(VInfo): --- 332,342 ---- text += " in stack [ESP+0x%x] or from top %d" % \ (self.stackdepth - stack, stack) if not (self.source & 0x08000000): text += " holding a reference" + if self.source & 0x04000000: + text += " >=0" return text + def getsummarytext(self): + return "Run-time" class VirtualTimeVInfo(VInfo): *************** *** 310,331 **** def gettext(self): return "Virtual-time source (%x)" % self.vs def readdump(filename = 'psyco.dump'): re_symb1 = re.compile(r"(\w+?)[:]\s0x([0-9a-fA-F]+)") ! re_codebuf = re.compile(r"CodeBufferObject 0x([0-9a-fA-F]+) (\d+) (\-?\d+) \'(.*?)\' \'(.*?)\' (\-?\d+) \'(.*?)\'$") re_specdict = re.compile(r"spec_dict 0x([0-9a-fA-F]+)") re_vinfo_array = re.compile(r"vinfo_array") re_spec1 = re.compile(r"0x([0-9a-fA-F]+)\s(.*)$") codebufs = [] dumpfile = open(filename, 'rb') bufcount, = struct.unpack("i", dumpfile.read(4)) ! buftable = struct.unpack("l"*bufcount, dumpfile.read(4*bufcount)) if buftable: ! filesize = buftable[0] else: filesize = sys.maxint filesize *= 1.0 nextp = 0.1 for filename in symbolfiles: line = dumpfile.readline() --- 345,371 ---- def gettext(self): return "Virtual-time source (%x)" % self.vs + def getsummarytext(self): + return "Virtual-time (%x)" % self.vs def readdump(filename = 'psyco.dump'): re_symb1 = re.compile(r"(\w+?)[:]\s0x([0-9a-fA-F]+)") ! re_codebuf = re.compile(r"CodeBufferObject 0x([0-9a-fA-F]+) (\-?\d+) \'(.*?)\' \'(.*?)\' (\-?\d+) \'(.*?)\'$") re_specdict = re.compile(r"spec_dict 0x([0-9a-fA-F]+)") re_vinfo_array = re.compile(r"vinfo_array") re_spec1 = re.compile(r"0x([0-9a-fA-F]+)\s(.*)$") + re_bigbuffer = re.compile(r"BigBuffer 0x([0-9a-fA-F]+) (\d+)$") codebufs = [] dumpfile = open(filename, 'rb') bufcount, = struct.unpack("i", dumpfile.read(4)) ! buftable = list(struct.unpack("l"*bufcount, dumpfile.read(4*bufcount))) ! buftable.reverse() if buftable: ! filesize = buftable[-1] else: filesize = sys.maxint filesize *= 1.0 nextp = 0.1 + cbsortedsize = 0 for filename in symbolfiles: line = dumpfile.readline() *************** *** 345,358 **** sys.stderr.write('%d%%...' % int(100*percent)) nextp += 0.1 ! size = int(match.group(2)) ! data = dumpfile.read(size) ! assert len(data) == size ! codebuf = CodeBuf(match.group(7), match.group(4), match.group(5), ! int(match.group(6)), long(match.group(1), 16), ! data, int(match.group(3))) codebuf.complete_list = codebufs codebuf.dumpfile = dumpfile ! codebuf.vlocalsofs = buftable[0] ! buftable = buftable[1:] codebufs.insert(0, codebuf) else: --- 385,397 ---- sys.stderr.write('%d%%...' % int(100*percent)) nextp += 0.1 ! #size = int(match.group(2)) ! #data = dumpfile.read(size) ! #assert len(data) == size ! codebuf = CodeBuf(match.group(6), match.group(3), match.group(4), ! int(match.group(5)), long(match.group(1), 16), ! int(match.group(2))) codebuf.complete_list = codebufs codebuf.dumpfile = dumpfile ! codebuf.vlocalsofs = buftable.pop() codebufs.insert(0, codebuf) else: *************** *** 360,367 **** if match: addr = long(match.group(1), 16) ! for codebuf in codebufs: ! if codebuf.addr < addr <= codebuf.addr+len(codebuf.data): ! break ! else: raise "spec_dict with no matching code buffer", line while 1: --- 399,407 ---- if match: addr = long(match.group(1), 16) ! if len(codeboundary) != cbsortedsize: ! codeboundary.sort() ! cbsortedsize = len(codeboundary) ! codebuf = codeat(addr-4) ! if codebuf is None: raise "spec_dict with no matching code buffer", line while 1: *************** *** 376,381 **** break else: ! raise "invalid line", line ! codeboundary.sort() codemap = {} for codebuf in codebufs: --- 416,427 ---- break else: ! match = re_bigbuffer.match(line) ! if match: ! BigBuffer(dumpfile, long(match.group(1), 16), ! int(match.group(2))) ! else: ! raise "invalid line", line ! if len(codeboundary) != cbsortedsize: ! codeboundary.sort() codemap = {} for codebuf in codebufs: |