blah
authorJorge Gorbe <j.gorbe@stcsl.es>
Thu, 29 Nov 2012 12:24:02 +0000 (13:24 +0100)
committerJorge Gorbe <j.gorbe@stcsl.es>
Thu, 29 Nov 2012 12:24:02 +0000 (13:24 +0100)
samples/view.py

index fc86c6faebb78a6ba6f2666bdd7fa7c890c19db0..e3ebb88d81ed69477818d345575ad852fdcf5a12 100644 (file)
@@ -8,10 +8,6 @@ import math
 import random
 import sys, traceback
 
-def merge_dict(dst, src):
-    for i in src:
-        dst[i] = src[i]
-
 def address_to_uint(addr):
     return int(addr.cast(gdb.lookup_type("unsigned int")))
 
@@ -36,42 +32,40 @@ def find_outgoing_pointers(value):
     """Finds all outgoing pointers from a value, traversing each non-pointer member of a composite type
     (e.g. struct members inside structs) and also each member in every base class, recursively.
     Returns a dict of {field_name:address} where field_name is a string, and address is a gdb.Value."""
-    print "find_outgoing_pointers(",str(value),")"
+
+    def merge_dict(dst, src):
+        for i in src:
+            dst[i] = src[i]
+
+    # try to find the runtime type of the value. this can throw
     try:
         valuetype = value.dynamic_type
     except gdb.error:
         print "error: dynamic_type"
         valuetype = value.type
 
+    # dereference references before looking at the value
     if type_is_reference(valuetype):
         return find_outgoing_pointers(value.referenced_value())
     
     if type_is_pointer(valuetype):
-        print "following ptr"
         return {"*": value}
     elif type_has_fields(valuetype):
-        print "type has fields"
         result = {}
         for f in value.type.fields():
-            print "field: ", f.name, "(", f.type, ")"
             if f.is_base_class:
-                print "is base class"
                 base_pointers = find_outgoing_pointers(value.cast(f.type))
                 merge_dict(result, base_pointers)
             elif type_has_fields(f.type):
-                print "has fields"
                 member_pointers = find_outgoing_pointers(value[f.name])
                 merge_dict(result, member_pointers)
             elif type_is_pointer(f.type):
-                print "is pointer"
                 result[f.name] = value[f.name]
             elif type_is_reference(f.type):
-                print "is_reference"
                 result[f.name] = value[f.name].referenced_value().address
 
         return result
     else:
-        print "blah"
         return {}