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")))
"""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 {}