def GetBaseTypes(module, type_name): t = FindGdbType(module, type_name) if t is None: # Type is a base type? return [JsDbgTypes.SBaseTypeResult(module, type_name, 0)] return GetBaseTypesFromGdbType(module, t)
def GetModuleForName(module): objfile = FindObjfileForName(module) if objfile: # Python has no API to find the base address # https://sourceware.org/bugzilla/show_bug.cgi?id=24481 return JsDbgTypes.SModule(module, 0) return None
def GetBaseTypesFromGdbType(module, type, extra_bitoffset=0): try: fields = type.fields() except: # Type does not have fields (not a struct/class/union) return [JsDbgTypes.SBaseTypeResult(module, type.name, 0)] resultFields = [] for field in fields: if not field.is_base_class: continue resultFields.append(JsDbgTypes.SBaseTypeResult( module, field.type.name, (extra_bitoffset + field.bitpos) / 8)) resultFields.extend(GetBaseTypesFromGdbType( module, field.type, extra_bitoffset + field.bitpos)) return resultFields
def LookupSymbolName(pointer): module = ModuleForAddress(pointer) val = gdb.parse_and_eval("(void*)%d" % pointer) # Result looks like: '0x4004f1 <twiddle<int []>(int)+17>' # If not found, just looks like '0x4004f1' symbol_and_offset = re.search('<(.+)>$', str(val)) if symbol_and_offset is None: return None groups = re.match("^(.*?)(\\+([0-9]+))?$", symbol_and_offset.groups()[0]).groups() symbol = groups[0] offset = 0 if groups[2]: offset = int(groups[2]) return JsDbgTypes.SSymbolNameAndDisplacement(module, symbol, offset)
def LookupConstants(module, type, value): type = FindGdbType(module, type) if type is None: return None if type.code != gdb.TYPE_CODE_ENUM: return None values = [] for f in type.fields(): if f.enumval != value: continue # GDB will give us "EnumType::Value", but we just want to return the # "Value" part. name = f.name name = name[name.rfind("::") + 2:] values.append(JsDbgTypes.SConstantResult(name, f.enumval)) return values