status_t ArchitectureX8664::DisassembleCode(FunctionDebugInfo* function, const void* buffer, size_t bufferSize, DisassembledCode*& _sourceCode) { DisassembledCode* source = new(std::nothrow) DisassembledCode( fAssemblyLanguage); if (source == NULL) return B_NO_MEMORY; BReference<DisassembledCode> sourceReference(source, true); // init disassembler DisassemblerX8664 disassembler; status_t error = disassembler.Init(function->Address(), buffer, bufferSize); if (error != B_OK) return error; // add a function name line BString functionName(function->PrettyName()); if (!source->AddCommentLine((functionName << ':').String())) return B_NO_MEMORY; // disassemble the instructions BString line; target_addr_t instructionAddress; target_size_t instructionSize; bool breakpointAllowed; while (disassembler.GetNextInstruction(line, instructionAddress, instructionSize, breakpointAllowed) == B_OK) { // TODO: Respect breakpointAllowed! if (!source->AddInstructionLine(line, instructionAddress, instructionSize)) { return B_NO_MEMORY; } } _sourceCode = sourceReference.Detach(); return B_OK; }
status_t ElfFile::CreateSymbolLookup(uint64 textDelta, ElfSymbolLookup*& _lookup) const { // Get the symbol table + corresponding string section. There may be two // symbol tables: the dynamic and the non-dynamic one. The former contains // only the symbols needed at run-time. The latter, if existing, is likely // more complete. So try to find and use the latter one, falling back to the // former. ElfSection* symbolSection; ElfSection* stringSection; if (!_FindSymbolSections(symbolSection, stringSection, SHT_SYMTAB) && !_FindSymbolSections(symbolSection, stringSection, SHT_DYNSYM)) { return B_ENTRY_NOT_FOUND; } // create a source with a segment for each section SymbolLookupSource* source = new(std::nothrow) SymbolLookupSource(fFD); if (source == NULL) return B_NO_MEMORY; BReference<SymbolLookupSource> sourceReference(source, true); if (!source->AddSegment(symbolSection->Offset(), symbolSection->Size(), symbolSection->Offset()) || !source->AddSegment(stringSection->Offset(), stringSection->Size(), stringSection->Offset())) { return B_NO_MEMORY; } // create the lookup size_t symbolTableEntrySize = Is64Bit() ? sizeof(ElfClass64::Sym) : sizeof(ElfClass32::Sym); uint32 symbolCount = uint32(symbolSection->Size() / symbolTableEntrySize); return ElfSymbolLookup::Create(source, symbolSection->Offset(), 0, stringSection->Offset(), symbolCount, symbolTableEntrySize, textDelta, f64Bit, fSwappedByteOrder, true, _lookup); }