Minor fixes in GDB scripts.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 09 Apr 2015 15:04:14 +0100
changeset 4 ca45a88235bd
parent 3 b3e318335eed
child 5 370848e6fc80
Minor fixes in GDB scripts.
hacking.sublime-project
stx/gdb/commands.py
stx/gdb/objects/__init__.py
--- a/hacking.sublime-project	Thu Apr 09 15:03:16 2015 +0100
+++ b/hacking.sublime-project	Thu Apr 09 15:04:14 2015 +0100
@@ -1,10 +1,19 @@
 {
-	
+
 	"folders":
 	[
 	    {
 	    	"path" : "stx"
-	    },
+        },
+        {
+            "path" : "tapset"
+        },
+        {
+            "path" : "tapscripts"
+        },
+        {
+            "path" : "c"
+        }
 	],
 
 	"settings":
--- a/stx/gdb/commands.py	Thu Apr 09 15:03:16 2015 +0100
+++ b/stx/gdb/commands.py	Thu Apr 09 15:04:14 2015 +0100
@@ -8,29 +8,34 @@
 
     @staticmethod
     def decorate(frame):
-        if frame.function().name == '__jInterpret':
+    	function = frame.function()
+    	if function == None:
+	    return CFrameDecorator_jit(frame)
+        if function.name == '__jInterpret':
             return CFrameDecorator_jInterpret(frame)
         else:
             c , s = stx.util.demangle(frame.name())
             if (c != None):
                 if (s != None):
-                    return CFrameDecorator_stcMethod(frame, c, s) 
+                    return CFrameDecorator_stcMethod(frame, c, s)
             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() , 
+        return "%3s 0x%8x %s ( %s)" % (
+            kind ,
+            self.pc(),
+            self.name() ,
             self.args_string() )
 
     def older(self):
         older = self._obj.older()
+        if older == None:
+            return None
         # special case, because of longjmp(), parent frame-point might point
         # to clean area, filled by 0xa5a5a5a5 (malloc() does this)
         if older.pc() != 0xa5a5a5a5:
@@ -49,17 +54,17 @@
         """Returns a top-level block (i.e., block for the function)"""
         b = self._obj.block()
         while b.function == None:
-            b = b.superblock            
+            b = b.superblock
         return b
-    
+
     def args_string(self):
-        """Returns a string representation of arguments"""    
+        """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())
@@ -70,6 +75,18 @@
     def kind(self):
         return "J-I"
 
+class CFrameDecorator_jit ( CFrameDecorator ):
+
+    def kind(self):
+        return "?-J"
+
+    def function_block(self):
+    	return []
+
+    def name(self):
+    	return "???"
+
+
 class CFrameDecorator_stcMethod ( CFrameDecorator ):
     def __init__(self, frame, className = None, selectorValue = None):
         CFrameDecorator.__init__(self, frame)
@@ -78,36 +95,36 @@
         if (c == None or s == None):
             c, s = stx.util.demangle(frame.name())
         self.klassName = c
-        self.selectorValue = s 
+        self.selectorValue = s
 
     def name(self):
         return "%s >> #%s" % ( self.klassName, self.selectorValue )
 
 
     def kind(self):
-        return "S-S"
-        
+        return "S-C"
+
 class Backtrace ( gdb.Command ):
     '''
-    Prints a VM backtrace. 
+    Prints a VM backtrace.
 
     Print additional information for well-known VM functions such
     as __interpret, __jinterpret, etc.
     '''
-    
+
     def __init__ ( self ):
         super (Backtrace, self).__init__("btx", gdb.COMMAND_STACK)
-    
+
     def invoke ( self , args , from_tty ):
         try:
             argv = gdb.string_to_argv(args)
             limit = None
             if len(argv) == 1:
                 limit = int(argv[0])
-            fno = 0        
+            fno = 0
             frame = CFrameDecorator.decorate(gdb.newest_frame())
             framesel = gdb.selected_frame()
-            while ( frame != None ) and ( limit == None or fno < limit ):            
+            while ( frame != None ) and ( limit == None or fno < limit ):
                 if frame.target() == framesel:
                     star = '*'
                 else:
--- a/stx/gdb/objects/__init__.py	Thu Apr 09 15:03:16 2015 +0100
+++ b/stx/gdb/objects/__init__.py	Thu Apr 09 15:04:14 2015 +0100
@@ -28,22 +28,26 @@
 
     def __repr__(self):
         return self.display_string()
-    
+
     def display_string(self):
         try:
             value = self.display_value()
             klassName = '???'
-            
+
             klass = self.klass
             if klass == None:
                 klassName = '?None?'
             else:
                 klassName = klass.name
             if (value == None):
-                return "0x%08x (%s)" % ( self.address , klassName )            
+                return "0x%08x (%s)" % ( self.address , klassName )
             else:
                 return "0x%08x (%s %s)" % ( self.address , klassName , value )
         except:
+            survStartPtr = long(gdb.parse_and_eval("__survStartPtr"))
+            survEndPtr = long(gdb.parse_and_eval("__survEndPtr"))
+            if (survStartPtr <= self.address and self.address <= survEndPtr):
+                return "0x%08x (** survivor **)" % self.address
             return "0x%08x (** err **)" % self.address
 
     def display_value(self):
@@ -70,17 +74,17 @@
         '''Return size of the objects in slots (excluding header)'''
         # Not really 64bit safe...
         return (self.size_b() - 12) / 4
-    
+
     def size_b(self):
         '''Return size of the object in bytes, including header'''
-        return self._obj['o_size']                
+        return self._obj['o_size']
 
     @property
     def flags(self):
         return self._obj['o_flags']
 
 
-# Some flags defined in stc.h. 
+# Some flags defined in stc.h.
 # !!! MAKE SURE they are in sync !!!
 
 BYTEARRAY       = 1
@@ -96,20 +100,20 @@
 SLONGLONGARRAY  = 11
 #
 # reserved:       13-15
-# 
+#
 
 ARRAYMASK       = 0x0F
 
 BEHAVIOR_INSTS  = 0x0010
-FLOAT_INSTS     = 0x0020  
-BLOCK_INSTS     = 0x0040  
-METHOD_INSTS    = 0x0080  
-CONTEXT_INSTS   = 0x0100  
-BCONTEXT_INSTS  = 0x0200  
-SYMBOL_INSTS    = 0x0400  
+FLOAT_INSTS     = 0x0020
+BLOCK_INSTS     = 0x0040
+METHOD_INSTS    = 0x0080
+CONTEXT_INSTS   = 0x0100
+BCONTEXT_INSTS  = 0x0200
+SYMBOL_INSTS    = 0x0400
 
-NONOBJECT_INSTS = 0x0800  
-EXTERNALBYTES_INSTS = 0x1000 
+NONOBJECT_INSTS = 0x0800
+EXTERNALBYTES_INSTS = 0x1000
 EXTFUNC_INSTS   = 0x010000
 
 
@@ -117,34 +121,34 @@
 def create(val):
     import stx.gdb.objects.stx_libbasic
     addr = long(val)
-    
+
     # Here we should care for free/non objects
     # by comparing address agains newspace
-    # boundaries. 
+    # boundaries.
     # Well, later :-)
 
     if (addr == 0):
         return stx.gdb.objects.stx_libbasic.nil
 
     if ((addr & 1) == 1):
-        return stx.gdb.objects.stx_libbasic.SmallInteger(val)    
+        return stx.gdb.objects.stx_libbasic.SmallInteger(val)
     flags = long(val['o_class']['i_instvars'][1])
     if ((flags & 1) == 1):
         flags = flags >> 1
     else:
         raise Exception("Memory corruption? Class flags are not SmallInteger.")
-    
+
     if ((flags & BEHAVIOR_INSTS) != 0):
-        # Care for anonymous classes    
-        size = (val['o_size'] - 12) / 4 # Not 64bit safe        
+        # Care for anonymous classes
+        size = (val['o_size'] - 12) / 4 # Not 64bit safe
         if (size == 5):
             return stx.gdb.objects.stx_libbasic.Behavior(val)
         if (size == 6):
             return stx.gdb.objects.stx_libbasic.ClassDescription(val)
         if (size >= 17):
-            return stx.gdb.objects.stx_libbasic.Class(val)            
+            return stx.gdb.objects.stx_libbasic.Class(val)
         if (size >= 7):
-            return stx.gdb.objects.stx_libbasic.Metaclass(val)            
+            return stx.gdb.objects.stx_libbasic.Metaclass(val)
 
         raise Exception("Funny behaviour-like size (%s)" % size)
 
@@ -157,4 +161,3 @@
 
 
 
- 
\ No newline at end of file