def __init__(self, gdbval): WrappedPointer.__init__(self, gdbval) # Cache some values: # This is the high-water mark: at this point and beyond, the bytes of # memory are untouched since malloc: self.pool_address = self.field('pool_address')
def __init__(self, gdbval, arenaobj): WrappedPointer.__init__(self, gdbval) assert (isinstance(arenaobj, ArenaObject)) self.arenaobj = arenaobj # obmalloc.c sets up arenaobj->pool_address to the first pool # address, aligning it to POOL_SIZE_MASK: self.initial_pool_addr = self.as_address() self.num_pools = ARENA_SIZE // POOL_SIZE self.excess = self.initial_pool_addr & POOL_SIZE_MASK if self.excess != 0: self.num_pools -= 1 self.initial_pool_addr += POOL_SIZE - self.excess
def __init__(self, gdbval, arenaobj): WrappedPointer.__init__(self, gdbval) assert(isinstance(arenaobj, ArenaObject)) self.arenaobj = arenaobj # obmalloc.c sets up arenaobj->pool_address to the first pool # address, aligning it to POOL_SIZE_MASK: self.initial_pool_addr = self.as_address() self.num_pools = ARENA_SIZE / POOL_SIZE self.excess = self.initial_pool_addr & POOL_SIZE_MASK if self.excess != 0: self.num_pools -= 1 self.initial_pool_addr += POOL_SIZE - self.excess
def categorize_refs(self, usage_set, level=0, detail=None): # This gives us access to the freetype library: FT_Library = WrappedPointer(self._gdbval['library']) # This is actually a "struct FT_LibraryRec_", in FreeType's # include/freetype/internal/ftobjs.h # print FT_Library._gdbval.dereference() usage_set.set_addr_category(FT_Library.as_address(), Category('FreeType', 'Library', ''), level=level+1, debug=True) usage_set.set_addr_category(int(FT_Library.field('raster_pool')), Category('FreeType', 'raster_pool', ''), level=level+2, debug=True)
class GTypeInstancePtr(WrappedPointer): @classmethod def from_gtypeinstance_ptr(cls, addr, typenode): typename = cls.get_type_name(typenode) if typename: cls = cls.get_class_for_typename(typename) return cls(addr, typenode, typename) @classmethod def get_class_for_typename(cls, typename): '''Get the GTypeInstance subclass for the given type name''' if typename in typemap: return typemap[typename] return GTypeInstancePtr def __init__(self, addr, typenode, typename): # Try to cast the ptr to the named type: addr = gdb.Value(addr) try: if is_typename_castable(typename): # This requires, say, gtk2-debuginfo: ptr_type = caching_lookup_type(typename).pointer() addr = addr.cast(ptr_type) #print typename, addr.dereference() #if typename == 'GdkPixbuf': # print 'GOT PIXELS', addr['pixels'] except RuntimeError, e: pass #print addr, e WrappedPointer.__init__(self, addr) self.typenode = typenode self.typename = typename """
def categorize_refs(self, usage_set, level=0, detail=None): # This gives us access to the freetype library: FT_Library = WrappedPointer(self._gdbval['library']) # This is actually a "struct FT_LibraryRec_", in FreeType's # include/freetype/internal/ftobjs.h # print FT_Library._gdbval.dereference() usage_set.set_addr_category(FT_Library.as_address(), Category('FreeType', 'Library', ''), level=level + 1, debug=True) usage_set.set_addr_category(int(FT_Library.field('raster_pool')), Category('FreeType', 'raster_pool', ''), level=level + 2, debug=True)
def __init__(self, addr, typenode, typename): # Try to cast the ptr to the named type: addr = gdb.Value(addr) try: if is_typename_castable(typename): # This requires, say, gtk2-debuginfo: ptr_type = caching_lookup_type(typename).pointer() addr = addr.cast(ptr_type) #print typename, addr.dereference() #if typename == 'GdkPixbuf': # print 'GOT PIXELS', addr['pixels'] except RuntimeError as e: pass #print addr, e WrappedPointer.__init__(self, addr) self.typenode = typenode self.typename = typename """
def categorize_refs(self, usage_set, level=0, detail=None): priv_type = caching_lookup_type('GdkImagePrivateX11').pointer() priv_data = WrappedPointer(self._gdbval['windowing_data'].cast(priv_type)) usage_set.set_addr_category(priv_data.as_address(), Category('GType', 'GdkImagePrivateX11', ''), level=level+1, debug=True) ximage = WrappedPointer(priv_data.field('ximage')) dims = '%sw x %sh x %sbpp' % (ximage.field('width'), ximage.field('height'), ximage.field('depth')) usage_set.set_addr_category(ximage.as_address(), Category('X11', 'Image', dims), level=level+2, debug=True) usage_set.set_addr_category(int(ximage.field('data')), Category('X11', 'Image data', dims), level=level+2, debug=True)
def categorize_refs(self, usage_set, level=0, detail=None): priv_type = caching_lookup_type('GdkImagePrivateX11').pointer() priv_data = WrappedPointer( self._gdbval['windowing_data'].cast(priv_type)) usage_set.set_addr_category(priv_data.as_address(), Category('GType', 'GdkImagePrivateX11', ''), level=level + 1, debug=True) ximage = WrappedPointer(priv_data.field('ximage')) dims = '%sw x %sh x %sbpp' % (ximage.field('width'), ximage.field('height'), ximage.field('depth')) usage_set.set_addr_category(ximage.as_address(), Category('X11', 'Image', dims), level=level + 2, debug=True) usage_set.set_addr_category(int(ximage.field('data')), Category('X11', 'Image data', dims), level=level + 2, debug=True)
def invoke(self, args, from_tty): from heap.glibc import iter_mappings,lookup_symbol from heap import WrappedPointer,caching_lookup_type SIZE_SZ = caching_lookup_type('size_t').sizeof type_size_t = gdb.lookup_type('size_t') type_size_t_ptr = type_size_t.pointer() arg_list = gdb.string_to_argv(args) parser = argparse.ArgumentParser(add_help=True, usage="objdump [-v][-s SIZE] <ADDR>") parser.add_argument('addr', metavar='ADDR', type=str, nargs=1, help="Target address") parser.add_argument('-s', dest='size', default=None, help='Total dump size') parser.add_argument('-v', dest='verbose', action="store_true", default=False, help='Verbose') try: args_dict = parser.parse_args(args=arg_list) except: return addr_arg = args_dict.addr[0] if addr_arg.startswith('0x'): addr = int(addr_arg, 16) else: addr = int(addr_arg) if args_dict.size: if args_dict.size.startswith('0x'): total_size = int(args_dict.size, 16) else: total_size = int(args_dict.size) else: total_size = 10 * SIZE_SZ if args_dict.verbose: print('Searching in the following object ranges') print('-------------------------------------------------') text = [] #list of tuples (start, end, pathname, ...) of a valid memory map #XXX why pid would be 0? for pid in [ o.pid for o in gdb.inferiors() if o.pid !=0 ]: for r in iter_mappings(pid): if args_dict.verbose: print("%s - %s : %s" % (hex(r[0]), hex(r[1]), r[2])) text.append((r[0], r[1], r[2])) print('\nDumping Object at address %s' % fmt_addr(addr)) print('-------------------------------------------------') for a in range(addr, addr + (total_size * SIZE_SZ), SIZE_SZ): ptr = WrappedPointer(gdb.Value(a).cast(type_size_t_ptr)) #dereference first, at the first access denied bail out, dont go further try: val = ptr.dereference() found = False val_int = int(str(val.cast(type_size_t))) #XXX Error occurred in Python command: invalid literal for int() with base 10: '0x418' pathname = "" for t in text: if val_int >= t[0] and val_int < t[1]: found = True pathname = t[2] if found: sym = lookup_symbol(val_int) if sym: out_line = "%s => %s (%s in %s)" % (fmt_addr(ptr.as_address()), fmt_addr(val_int), sym, pathname ) else: out_line = "%s => %s (%s)" % (fmt_addr(ptr.as_address()), fmt_addr(val_int), pathname ) else: out_line = "%s => %s" % (fmt_addr(ptr.as_address()), fmt_addr(val_int) ) #if it's not a symbol, try a string # try just a few chars #if not found: print(out_line) except gdb.MemoryError: print("Error accessing memory at %s" % fmt_addr(ptr.as_address())) return