--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,4 @@
+syntax: glob
+*.pyc
+hacking.sublime-workspace
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hacking.sublime-project Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,15 @@
+{
+
+ "folders":
+ [
+ {
+ "path" : "stx"
+ },
+ ],
+
+ "settings":
+ {
+ "tab_size": 4,
+ "translate_tabs_to_spaces": true
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stx/gdb/__init__.py Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,1 @@
+import stx.gdb.commands
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stx/gdb/commands.py Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,95 @@
+import gdb
+import stx.support
+
+class CFrameDecorator ( stx.support.Decorator ):
+ """An abstract gdb.Frame decorator"""
+
+ @staticmethod
+ def decorate(frame):
+ if frame.function().name == '__jInterpret':
+ return CFrameDecorator_jInterpret(frame)
+ else:
+ return CFrameDecorator(frame)
+
+ def __str__(self):
+ kind = self.kind()
+ if kind != None:
+ kind = "%2s" % kind
+ else:
+ kind = ' '
+ return "%3s 0x%8x %s ( %s)" % (
+ kind ,
+ self.pc(),
+ self.name() ,
+ self.args_string() )
+
+ def older(self):
+ older = self._obj.older()
+ # special case, because of longjmp(), parent frame-point might point
+ # to clean area, filled by 0xa5a5a5a5 (malloc() does this)
+ if older.pc() != 0xa5a5a5a5:
+ return CFrameDecorator.decorate(older)
+ else:
+ return None
+
+ def newer(self):
+ return CFrameDecorator.decorate(self._obj.newer())
+
+ def kind(self):
+ """Returns 3 char identification of frame kind or None"""
+ return None # generic frame
+
+ def function_block(self):
+ """Returns a top-level block (i.e., block for the function)"""
+ b = self._obj.block()
+ while b.function == None:
+ b = b.superblock
+ return b
+
+ def args_string(self):
+ """Returns a string representation of arguments"""
+ s = ''
+ for sym in self.function_block():
+ if sym.is_argument:
+ s = s + self.arg_string(sym) + ' '
+ return s
+
+ def arg_string(self, sym):
+ """Given an argument symbol, returns its string representation"""
+ val = self._obj.read_var(sym, self._obj.block())
+ return "%s=%s" % ( sym.print_name , val )
+
+class CFrameDecorator_jInterpret ( CFrameDecorator ):
+
+ def kind(self):
+ return "J-I"
+
+class Backtrace ( gdb.Command ):
+ '''
+ Prints a VM backtrace.
+
+ Print additional information for well-known VM functions such
+ as __interpret, __jinterpret, etc.
+ '''
+
+ def __init__ ( self ):
+ super (Backtrace, self).__init__("bt", gdb.COMMAND_STACK)
+
+ def invoke ( self , args , from_tty ):
+ argv = gdb.string_to_argv(args)
+ limit = None
+ if len(argv) == 1:
+ limit = int(argv[0])
+ fno = 0
+ frame = CFrameDecorator.decorate(gdb.newest_frame())
+ framesel = gdb.selected_frame()
+ while ( frame != None ) and ( limit == None or fno < limit ):
+ if frame.target() == framesel:
+ star = '*'
+ else:
+ star = ' '
+ print "%s%3d %s" % (star, fno , frame )
+ frame = frame.older()
+ fno = fno +1
+
+Backtrace()
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stx/gdb/load.py Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,9 @@
+if __name__ == '__main__':
+ import os
+ import sys
+ my_dir = os.path.dirname(__file__)
+ inc_dir = os.path.join(my_dir, '../..')
+
+ sys.path.append(inc_dir)
+
+ import stx.gdb
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stx/support.py Sun Sep 08 23:18:16 2013 +0100
@@ -0,0 +1,24 @@
+class Decorator ( object ):
+ '''
+ Generic decorator class
+ '''
+
+ _obj = None
+
+ def __init__ ( self , obj ):
+ object.__setattr__(self, "_obj", obj)
+
+ def target(self):
+ return self._obj
+
+ def __getattr__(self, aname):
+ target = self._obj
+ f = getattr(target, aname)
+ if isinstance(f, types.MethodType):
+ # Rebind the method to the target.
+ return new.instancemethod(f.im_func, self, target.__class__)
+ else:
+ return f
+
+ def __repr__( self ):
+ return "[" +str(self.__class__) + ' : ' + self._obj.__repr__() + "]"
\ No newline at end of file