def get_used_size(self): size = 0 fields = self.obj.type.fields() for f in fields: # check if it is static field if not hasattr(f, "bitpos"): continue # process base class size if f.is_base_class: size += common_helpers.get_instance_size(self.obj.cast(f.type.strip_typedefs())) continue # process simple field size += common_helpers.get_instance_size(self.obj[f.name]) return size
def invoke(self, arg, from_tty): try: args = gdb.string_to_argv(arg) obj = gdb.parse_and_eval(args[0]) logfile = open(args[1], 'a') size = common_helpers.get_instance_size(obj) logfile.write("%s %s: %d\n" % (str(datetime.datetime.now()), args[0], size)) logfile.close() except Exception as e: print(traceback.format_exc()) raise e
def invoke(self, arg, from_tty): try: args = gdb.string_to_argv(arg) obj = gdb.parse_and_eval(args[1]) obj_type = obj.type print (args[1] + " is " + str(obj_type)) size = common_helpers.get_instance_size(obj) UsedSizeCommand.assign_value(args[0], size) print (size) except Exception as e: print(traceback.format_exc()) raise e
def get_used_size(self): is_special = common_helpers.is_special_type(self.element_type()) head = self.obj['_M_impl']['_M_node'] # nodetype = find_type(self.obj.type, '_Node') nodetype = head.type nodetype = nodetype.strip_typedefs().pointer() current = head['_M_next'] size = self.obj.type.sizeof while current != head.address: if is_special: elem = current.cast(nodetype).dereference() size += common_helpers.get_instance_size(elem) else: size += self.element_type().sizeof current = current['_M_next'] return size