diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index cf2e3c4b62..513379bd16 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -292,10 +292,15 @@ printf(" %ld compilation units\n", fFile->CountCompilationUnits()); status_t -DwarfImageDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, +DwarfImageDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* _function, CpuState* cpuState, StackFrame*& _previousFrame, CpuState*& _previousCpuState) { + DwarfFunctionDebugInfo* function + = dynamic_cast(_function); + if (function == NULL) + return B_BAD_VALUE; + int32 registerCount = fArchitecture->CountRegisters(); const Register* registers = fArchitecture->Registers(); @@ -324,7 +329,7 @@ DwarfImageDebugInfo::CreateFrame(Image* image, FunctionDebugInfo* function, // do the unwinding target_addr_t framePointer; - error = fFile->UnwindCallFrame( + error = fFile->UnwindCallFrame(function->GetCompilationUnit(), cpuState->InstructionPointer() - fRelocationDelta, &inputInterface, &outputInterface, framePointer); if (error != B_OK) @@ -610,7 +615,7 @@ DwarfImageDebugInfo::_AddSourceCodeInfo(CompilationUnit* unit, int32 statementLine = -1; int32 statementColumn = -1; while (program.GetNextRow(state)) { -printf(" %#lx (%ld, %ld, %ld) %d\n", state.address, state.file, state.line, state.column, state.isStatement); +printf(" %#llx (%ld, %ld, %ld) %d\n", state.address, state.file, state.line, state.column, state.isStatement); bool isOurFile = state.file == fileIndex; if (statementAddress != 0 diff --git a/src/apps/debugger/dwarf/AbbreviationTable.cpp b/src/apps/debugger/dwarf/AbbreviationTable.cpp index 15de90cfbc..158a854fec 100644 --- a/src/apps/debugger/dwarf/AbbreviationTable.cpp +++ b/src/apps/debugger/dwarf/AbbreviationTable.cpp @@ -38,7 +38,8 @@ AbbreviationTable::Init(const void* section, off_t sectionSize) if (error != B_OK) return error; - DataReader abbrevReader(fData, fSize); + DataReader abbrevReader(fData, fSize, 4); + // address size doesn't matter here while (true) { bool nullEntry; diff --git a/src/apps/debugger/dwarf/AbbreviationTable.h b/src/apps/debugger/dwarf/AbbreviationTable.h index 17756cd633..b3a2e9e171 100644 --- a/src/apps/debugger/dwarf/AbbreviationTable.h +++ b/src/apps/debugger/dwarf/AbbreviationTable.h @@ -40,7 +40,8 @@ struct AbbreviationEntry { void SetTo(uint32 code, const void* data, off_t size) { fCode = code; - fAttributesReader.SetTo(data, size); + fAttributesReader.SetTo(data, size, 4); + // address size doesn't matter here fTag = fAttributesReader.ReadUnsignedLEB128(0); fHasChildren = fAttributesReader.Read(0); fData = fAttributesReader.Data(); diff --git a/src/apps/debugger/dwarf/AttributeValue.cpp b/src/apps/debugger/dwarf/AttributeValue.cpp index 36e24f4c78..2e052ca5ea 100644 --- a/src/apps/debugger/dwarf/AttributeValue.cpp +++ b/src/apps/debugger/dwarf/AttributeValue.cpp @@ -15,10 +15,10 @@ AttributeValue::ToString(char* buffer, size_t size) { switch (attributeClass) { case ATTRIBUTE_CLASS_ADDRESS: - snprintf(buffer, size, "%#lx", address); + snprintf(buffer, size, "%#llx", address); return buffer; case ATTRIBUTE_CLASS_BLOCK: - snprintf(buffer, size, "(%p, %#lx)", block.data, block.length); + snprintf(buffer, size, "(%p, %#llx)", block.data, block.length); return buffer; case ATTRIBUTE_CLASS_CONSTANT: snprintf(buffer, size, "%#llx", constant); @@ -30,7 +30,7 @@ AttributeValue::ToString(char* buffer, size_t size) case ATTRIBUTE_CLASS_LOCLISTPTR: case ATTRIBUTE_CLASS_MACPTR: case ATTRIBUTE_CLASS_RANGELISTPTR: - snprintf(buffer, size, "%#lx", pointer); + snprintf(buffer, size, "%#llx", pointer); return buffer; case ATTRIBUTE_CLASS_REFERENCE: snprintf(buffer, size, "%p", reference); diff --git a/src/apps/debugger/dwarf/AttributeValue.h b/src/apps/debugger/dwarf/AttributeValue.h index e0b4e2de81..4edeac79a3 100644 --- a/src/apps/debugger/dwarf/AttributeValue.h +++ b/src/apps/debugger/dwarf/AttributeValue.h @@ -6,8 +6,8 @@ #define ATTRIBUTE_VALUE_H #include "AttributeClasses.h" -#include "DwarfTypes.h" #include "TargetAddressRangeList.h" +#include "Types.h" class DebugInfoEntry; @@ -15,15 +15,15 @@ class DebugInfoEntry; struct AttributeValue { union { - dwarf_addr_t address; + target_addr_t address; struct { const void* data; - dwarf_size_t length; + off_t length; } block; uint64 constant; bool flag; TargetAddressRangeList* rangeList; - dwarf_off_t pointer; + off_t pointer; DebugInfoEntry* reference; const char* string; }; @@ -43,14 +43,14 @@ struct AttributeValue { Unset(); } - void SetToAddress(dwarf_addr_t address) + void SetToAddress(target_addr_t address) { Unset(); attributeClass = ATTRIBUTE_CLASS_ADDRESS; this->address = address; } - void SetToBlock(const void* data, dwarf_size_t length) + void SetToBlock(const void* data, off_t length) { Unset(); attributeClass = ATTRIBUTE_CLASS_BLOCK; @@ -73,21 +73,21 @@ struct AttributeValue { this->flag = value; } - void SetToLinePointer(dwarf_off_t value) + void SetToLinePointer(off_t value) { Unset(); attributeClass = ATTRIBUTE_CLASS_LINEPTR; this->pointer = value; } - void SetToLocationListPointer(dwarf_off_t value) + void SetToLocationListPointer(off_t value) { Unset(); attributeClass = ATTRIBUTE_CLASS_LOCLISTPTR; this->pointer = value; } - void SetToMacroPointer(dwarf_off_t value) + void SetToMacroPointer(off_t value) { Unset(); attributeClass = ATTRIBUTE_CLASS_MACPTR; @@ -136,7 +136,7 @@ struct DynamicAttributeValue { DebugInfoEntry* reference; struct { const void* data; - dwarf_size_t length; + off_t length; } block; }; uint8 attributeClass; @@ -160,7 +160,7 @@ struct DynamicAttributeValue { attributeClass = ATTRIBUTE_CLASS_REFERENCE; } - void SetTo(const void* data, dwarf_size_t length) + void SetTo(const void* data, off_t length) { block.data = data; block.length = length; @@ -175,7 +175,7 @@ struct ConstantAttributeValue { const char* string; struct { const void* data; - dwarf_size_t length; + off_t length; } block; }; uint8 attributeClass; @@ -199,7 +199,7 @@ struct ConstantAttributeValue { attributeClass = ATTRIBUTE_CLASS_STRING; } - void SetTo(const void* data, dwarf_size_t length) + void SetTo(const void* data, off_t length) { block.data = data; block.length = length; diff --git a/src/apps/debugger/dwarf/CfaContext.cpp b/src/apps/debugger/dwarf/CfaContext.cpp index 2b03592008..6205ad0a0d 100644 --- a/src/apps/debugger/dwarf/CfaContext.cpp +++ b/src/apps/debugger/dwarf/CfaContext.cpp @@ -9,8 +9,8 @@ #include "CfaContext.h" -CfaContext::CfaContext(dwarf_addr_t targetLocation, - dwarf_addr_t initialLocation) +CfaContext::CfaContext(target_addr_t targetLocation, + target_addr_t initialLocation) : fTargetLocation(targetLocation), fLocation(initialLocation), @@ -80,7 +80,7 @@ CfaContext::PopRuleSet() void -CfaContext::SetLocation(dwarf_addr_t location) +CfaContext::SetLocation(target_addr_t location) { fLocation = location; } diff --git a/src/apps/debugger/dwarf/CfaContext.h b/src/apps/debugger/dwarf/CfaContext.h index b3033463d1..b652e010c8 100644 --- a/src/apps/debugger/dwarf/CfaContext.h +++ b/src/apps/debugger/dwarf/CfaContext.h @@ -9,12 +9,13 @@ #include #include "CfaRuleSet.h" +#include "Types.h" class CfaContext { public: - CfaContext(dwarf_addr_t targetLocation, - dwarf_addr_t initialLocation); + CfaContext(target_addr_t targetLocation, + target_addr_t initialLocation); ~CfaContext(); status_t Init(uint32 registerCount); @@ -23,12 +24,12 @@ public: status_t PushRuleSet(); status_t PopRuleSet(); - dwarf_addr_t TargetLocation() const + target_addr_t TargetLocation() const { return fTargetLocation; } - dwarf_addr_t Location() const + target_addr_t Location() const { return fLocation; } - void SetLocation(dwarf_addr_t location); + void SetLocation(target_addr_t location); uint32 CodeAlignment() const { return fCodeAlignment; } @@ -53,8 +54,8 @@ private: typedef BObjectList RuleSetList; private: - dwarf_addr_t fTargetLocation; - dwarf_addr_t fLocation; + target_addr_t fTargetLocation; + target_addr_t fLocation; uint32 fCodeAlignment; int32 fDataAlignment; uint32 fReturnAddressRegister; diff --git a/src/apps/debugger/dwarf/CfaRule.h b/src/apps/debugger/dwarf/CfaRule.h index a1939c2a11..a9033d084b 100644 --- a/src/apps/debugger/dwarf/CfaRule.h +++ b/src/apps/debugger/dwarf/CfaRule.h @@ -6,7 +6,7 @@ #define CFA_RULE_H -#include "DwarfTypes.h" +#include "Types.h" enum cfa_rule_type { diff --git a/src/apps/debugger/dwarf/CompilationUnit.cpp b/src/apps/debugger/dwarf/CompilationUnit.cpp index 810b53280e..4eb9792a87 100644 --- a/src/apps/debugger/dwarf/CompilationUnit.cpp +++ b/src/apps/debugger/dwarf/CompilationUnit.cpp @@ -22,9 +22,9 @@ struct CompilationUnit::File { }; -CompilationUnit::CompilationUnit(dwarf_off_t headerOffset, - dwarf_off_t contentOffset, dwarf_off_t totalSize, - dwarf_off_t abbreviationOffset) +CompilationUnit::CompilationUnit(off_t headerOffset, off_t contentOffset, + off_t totalSize, off_t abbreviationOffset, uint8 addressSize, + bool isDwarf64) : fHeaderOffset(headerOffset), fContentOffset(contentOffset), @@ -33,7 +33,10 @@ CompilationUnit::CompilationUnit(dwarf_off_t headerOffset, fAbbreviationTable(NULL), fUnitEntry(NULL), fDirectories(10, true), - fFiles(10, true) + fFiles(10, true), + fLineNumberProgram(addressSize), + fAddressSize(addressSize), + fIsDwarf64(isDwarf64) { } @@ -51,7 +54,7 @@ CompilationUnit::SetAbbreviationTable(AbbreviationTable* abbreviationTable) status_t -CompilationUnit::AddDebugInfoEntry(DebugInfoEntry* entry, dwarf_off_t offset) +CompilationUnit::AddDebugInfoEntry(DebugInfoEntry* entry, off_t offset) { if (!fEntries.Add(entry)) return B_NO_MEMORY; @@ -80,7 +83,7 @@ CompilationUnit::CountEntries() const void CompilationUnit::GetEntryAt(int index, DebugInfoEntry*& entry, - dwarf_off_t& offset) const + off_t& offset) const { entry = fEntries[index]; offset = fEntryOffsets[index]; @@ -88,7 +91,7 @@ CompilationUnit::GetEntryAt(int index, DebugInfoEntry*& entry, DebugInfoEntry* -CompilationUnit::EntryForOffset(dwarf_off_t offset) const +CompilationUnit::EntryForOffset(off_t offset) const { if (fEntries.IsEmpty()) return NULL; diff --git a/src/apps/debugger/dwarf/CompilationUnit.h b/src/apps/debugger/dwarf/CompilationUnit.h index 5f2e7b490a..5210fa9cc6 100644 --- a/src/apps/debugger/dwarf/CompilationUnit.h +++ b/src/apps/debugger/dwarf/CompilationUnit.h @@ -10,8 +10,8 @@ #include #include "Array.h" -#include "DwarfTypes.h" #include "LineNumberProgram.h" +#include "Types.h" class AbbreviationTable; @@ -21,23 +21,28 @@ class DIECompileUnitBase; class CompilationUnit { public: - CompilationUnit(dwarf_off_t headerOffset, - dwarf_off_t contentOffset, - dwarf_off_t totalSize, - dwarf_off_t abbreviationOffset); + CompilationUnit(off_t headerOffset, + off_t contentOffset, + off_t totalSize, + off_t abbreviationOffset, + uint8 addressSize, bool isDwarf64); ~CompilationUnit(); - dwarf_off_t HeaderOffset() const { return fHeaderOffset; } - dwarf_off_t ContentOffset() const { return fContentOffset; } - dwarf_off_t RelativeContentOffset() const + off_t HeaderOffset() const { return fHeaderOffset; } + off_t ContentOffset() const { return fContentOffset; } + off_t RelativeContentOffset() const { return fContentOffset - fHeaderOffset; } - dwarf_off_t TotalSize() const { return fTotalSize; } - dwarf_off_t ContentSize() const + off_t TotalSize() const { return fTotalSize; } + off_t ContentSize() const { return fTotalSize - RelativeContentOffset(); } - dwarf_off_t AbbreviationOffset() const + off_t AbbreviationOffset() const { return fAbbreviationOffset; } + uint8 AddressSize() const { return fAddressSize; } + inline target_addr_t MaxAddress() const; + bool IsDwarf64() const { return fIsDwarf64; } + AbbreviationTable* GetAbbreviationTable() const { return fAbbreviationTable; } void SetAbbreviationTable( @@ -50,11 +55,11 @@ public: { return fLineNumberProgram; } status_t AddDebugInfoEntry(DebugInfoEntry* entry, - dwarf_off_t offset); + off_t offset); int CountEntries() const; void GetEntryAt(int index, DebugInfoEntry*& entry, - dwarf_off_t& offset) const; - DebugInfoEntry* EntryForOffset(dwarf_off_t offset) const; + off_t& offset) const; + DebugInfoEntry* EntryForOffset(off_t offset) const; bool AddDirectory(const char* directory); int32 CountDirectories() const; @@ -71,18 +76,27 @@ private: typedef BObjectList FileList; private: - dwarf_off_t fHeaderOffset; - dwarf_off_t fContentOffset; - dwarf_off_t fTotalSize; - dwarf_off_t fAbbreviationOffset; + off_t fHeaderOffset; + off_t fContentOffset; + off_t fTotalSize; + off_t fAbbreviationOffset; AbbreviationTable* fAbbreviationTable; DIECompileUnitBase* fUnitEntry; Array fEntries; - Array fEntryOffsets; + Array fEntryOffsets; DirectoryList fDirectories; FileList fFiles; LineNumberProgram fLineNumberProgram; + uint8 fAddressSize; + bool fIsDwarf64; }; +target_addr_t +CompilationUnit::MaxAddress() const +{ + return fAddressSize == 4 ? 0xffffffffULL : 0xffffffffffffffffULL; +} + + #endif // COMPILATION_UNIT_H diff --git a/src/apps/debugger/dwarf/DataReader.h b/src/apps/debugger/dwarf/DataReader.h index 33852879ef..0167ce7d8f 100644 --- a/src/apps/debugger/dwarf/DataReader.h +++ b/src/apps/debugger/dwarf/DataReader.h @@ -5,7 +5,8 @@ #ifndef DATA_READER_H #define DATA_READER_H -#include + +#include "Types.h" class DataReader { @@ -15,19 +16,21 @@ public: fData(NULL), fSize(0), fInitialSize(0), + fAddressSize(4), fOverflow(false) { } - DataReader(const void* data, off_t size) + DataReader(const void* data, off_t size, uint8 addressSize) { - SetTo(data, size); + SetTo(data, size, addressSize); } - void SetTo(const void* data, off_t size) + void SetTo(const void* data, off_t size, uint8 addressSize) { fData = (const uint8*)data; fInitialSize = fSize = size; + fAddressSize = addressSize; fOverflow = false; } @@ -36,6 +39,16 @@ public: return fSize > 0; } + uint32 AddressSize() const + { + return fAddressSize; + } + + void SetAddressSize(uint8 addressSize) + { + fAddressSize = addressSize; + } + bool HasOverflow() const { return fOverflow; @@ -85,6 +98,13 @@ public: return data; } + target_addr_t ReadAddress(target_addr_t defaultValue) + { + return fAddressSize == 4 + ? (target_addr_t)Read(defaultValue) + : (target_addr_t)Read(defaultValue); + } + uint64 ReadUnsignedLEB128(uint64 defaultValue) { uint64 result = 0; @@ -165,6 +185,7 @@ private: const uint8* fData; off_t fSize; off_t fInitialSize; + uint8 fAddressSize; bool fOverflow; }; diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.cpp b/src/apps/debugger/dwarf/DebugInfoEntries.cpp index 5a1698e739..bd2927ccb0 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntries.cpp +++ b/src/apps/debugger/dwarf/DebugInfoEntries.cpp @@ -73,7 +73,7 @@ DIECompileUnitBase::Name() const } -dwarf_addr_t +target_addr_t DIECompileUnitBase::AddressRangeBase() const { if (fAddressRanges != NULL) @@ -1991,7 +1991,7 @@ DIECondition::Tag() const DIESharedType::DIESharedType() { - fBlockSize.SetTo(DWARF_ADDRESS_MAX); + fBlockSize.SetTo(~(uint64)0); } diff --git a/src/apps/debugger/dwarf/DebugInfoEntries.h b/src/apps/debugger/dwarf/DebugInfoEntries.h index 04ef0fc22a..e974e5cec0 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntries.h +++ b/src/apps/debugger/dwarf/DebugInfoEntries.h @@ -154,11 +154,11 @@ public: TargetAddressRangeList* AddressRanges() const { return fAddressRanges; } - dwarf_addr_t LowPC() const { return fLowPC; } - dwarf_addr_t HighPC() const { return fHighPC; } - dwarf_addr_t AddressRangeBase() const; + target_addr_t LowPC() const { return fLowPC; } + target_addr_t HighPC() const { return fHighPC; } + target_addr_t AddressRangeBase() const; - dwarf_off_t StatementListOffset() const + off_t StatementListOffset() const { return fStatementListOffset; } virtual status_t AddChild(DebugInfoEntry* child); @@ -198,10 +198,10 @@ public: protected: const char* fName; const char* fCompilationDir; - dwarf_addr_t fLowPC; - dwarf_addr_t fHighPC; - dwarf_off_t fStatementListOffset; - dwarf_off_t fMacroInfoOffset; + target_addr_t fLowPC; + target_addr_t fHighPC; + off_t fStatementListOffset; + off_t fMacroInfoOffset; TargetAddressRangeList* fAddressRanges; DIECompileUnitBase* fBaseTypesUnit; DebugInfoEntryList fTypes; @@ -1028,8 +1028,8 @@ public: TargetAddressRangeList* AddressRanges() const { return fAddressRanges; } - dwarf_addr_t LowPC() const { return fLowPC; } - dwarf_addr_t HighPC() const { return fHighPC; } + target_addr_t LowPC() const { return fLowPC; } + target_addr_t HighPC() const { return fHighPC; } bool IsPrototyped() const { return fPrototyped; } uint8 Inline() const { return fInline; } @@ -1055,8 +1055,8 @@ public: const AttributeValue& value); protected: - dwarf_addr_t fLowPC; - dwarf_addr_t fHighPC; + target_addr_t fLowPC; + target_addr_t fHighPC; TargetAddressRangeList* fAddressRanges; DIESubprogram* fSpecification; DIESubprogram* fAbstractOrigin; diff --git a/src/apps/debugger/dwarf/DebugInfoEntry.h b/src/apps/debugger/dwarf/DebugInfoEntry.h index cd9b7f5740..838a2291dd 100644 --- a/src/apps/debugger/dwarf/DebugInfoEntry.h +++ b/src/apps/debugger/dwarf/DebugInfoEntry.h @@ -9,7 +9,7 @@ #include -#include "DwarfTypes.h" +#include "Types.h" #define DECLARE_DEBUG_INFO_ENTRY_ATTR_SETTER(name) \ diff --git a/src/apps/debugger/dwarf/DwarfFile.cpp b/src/apps/debugger/dwarf/DwarfFile.cpp index 24e6e9d37a..dc544f74d1 100644 --- a/src/apps/debugger/dwarf/DwarfFile.cpp +++ b/src/apps/debugger/dwarf/DwarfFile.cpp @@ -94,13 +94,14 @@ DwarfFile::Load(const char* fileName) // iterate through the debug info section DataReader dataReader(fDebugInfoSection->Data(), - fDebugInfoSection->Size()); + fDebugInfoSection->Size(), 4); + // address size doesn't matter here while (dataReader.HasData()) { - dwarf_off_t unitHeaderOffset = dataReader.Offset(); + off_t unitHeaderOffset = dataReader.Offset(); bool dwarf64; uint64 unitLength = dataReader.ReadInitialLength(dwarf64); - dwarf_off_t unitLengthOffset = dataReader.Offset(); + off_t unitLengthOffset = dataReader.Offset(); // the unitLength starts here if (unitLengthOffset + unitLength @@ -131,19 +132,20 @@ DwarfFile::Load(const char* fileName) break; } - if (addressSize != 4) { + if (addressSize != 4 && addressSize != 8) { printf("\"%s\": Unsupported address size: %d\n", fileName, addressSize); break; } + dataReader.SetAddressSize(addressSize); - dwarf_off_t unitContentOffset = dataReader.Offset(); + off_t unitContentOffset = dataReader.Offset(); // create a compilation unit object CompilationUnit* unit = new(std::nothrow) CompilationUnit( unitHeaderOffset, unitContentOffset, unitLength + (unitLengthOffset - unitHeaderOffset), - abbrevOffset); + abbrevOffset, addressSize, dwarf64); if (unit == NULL || !fCompilationUnits.AddItem(unit)) { delete unit; return B_NO_MEMORY; @@ -222,7 +224,7 @@ DwarfFile::CompilationUnitForDIE(const DebugInfoEntry* entry) const status_t -DwarfFile::UnwindCallFrame(target_addr_t location, +DwarfFile::UnwindCallFrame(CompilationUnit* unit, target_addr_t location, const DwarfTargetInterface* inputInterface, DwarfTargetInterface* outputInterface, target_addr_t& _framePointer) { @@ -232,7 +234,7 @@ DwarfFile::UnwindCallFrame(target_addr_t location, printf("DwarfFile::UnwindCallFrame(%#llx)\n", location); DataReader dataReader((uint8*)fDebugFrameSection->Data(), - fDebugFrameSection->Size()); + fDebugFrameSection->Size(), unit->AddressSize()); while (dataReader.BytesRemaining() > 0) { // length @@ -249,8 +251,8 @@ printf("DwarfFile::UnwindCallFrame(%#llx)\n", location); // this is a CIE -- skip it } else { // this is a FDE - dwarf_addr_t initialLocation = dataReader.Read(0); - dwarf_size_t addressRange = dataReader.Read(0); + target_addr_t initialLocation = dataReader.ReadAddress(0); + target_size_t addressRange = dataReader.ReadAddress(0); if (dataReader.HasOverflow()) return B_BAD_DATA; @@ -262,7 +264,7 @@ printf("DwarfFile::UnwindCallFrame(%#llx)\n", location); - (dataReader.Offset() - lengthOffset); if (remaining < 0) return B_BAD_DATA; -printf(" found fde: length: %llu (%lld), CIE offset: %llu, location: %#lx, range: %#lx\n", length, remaining, cieID, +printf(" found fde: length: %llu (%lld), CIE offset: %llu, location: %#llx, range: %#llx\n", length, remaining, cieID, initialLocation, addressRange); CfaContext context(location, initialLocation); @@ -285,7 +287,7 @@ initialLocation, addressRange); } // process the CIE - error = _ParseCIE(context, cieID); + error = _ParseCIE(unit, context, cieID); if (error != B_OK) return error; @@ -293,7 +295,7 @@ initialLocation, addressRange); if (error != B_OK) return error; - error = _ParseFrameInfoInstructions(context, + error = _ParseFrameInfoInstructions(unit, context, dataReader.Offset(), remaining); if (error != B_OK) return error; @@ -302,7 +304,7 @@ printf(" found row!\n"); // apply the rules of the final row // get the frameAddress first - dwarf_addr_t frameAddress; + target_addr_t frameAddress; CfaCfaRule* cfaCfaRule = context.GetCfaCfaRule(); switch (cfaCfaRule->Type()) { case CFA_CFA_RULE_REGISTER_OFFSET: @@ -323,7 +325,7 @@ printf(" found row!\n"); default: return B_BAD_VALUE; } -printf(" frame address: %#lx\n", frameAddress); +printf(" frame address: %#llx\n", frameAddress); // apply the register rules for (uint32 i = 0; i < registerCount; i++) { @@ -412,7 +414,7 @@ DwarfFile::_ParseCompilationUnit(CompilationUnit* unit) DataReader dataReader( (const uint8*)fDebugInfoSection->Data() + unit->ContentOffset(), - unit->ContentSize()); + unit->ContentSize(), unit->AddressSize()); DebugInfoEntry* entry; bool endOfEntryList; @@ -447,7 +449,7 @@ DwarfFile::_ParseDebugInfoEntry(DataReader& dataReader, AbbreviationTable* abbreviationTable, DebugInfoEntry*& _entry, bool& _endOfEntryList, int level) { - dwarf_off_t entryOffset = dataReader.Offset() + off_t entryOffset = dataReader.Offset() + fCurrentCompilationUnit->RelativeContentOffset(); uint32 code = dataReader.ReadUnsignedLEB128(0); @@ -467,7 +469,7 @@ DwarfFile::_ParseDebugInfoEntry(DataReader& dataReader, fprintf(stderr, "No abbreviation entry for code %lu\n", code); return B_BAD_DATA; } -printf("%*sentry at %lu: %lu, tag: %s (%lu), children: %d\n", level * 2, "", +printf("%*sentry at %lld: %lu, tag: %s (%lu), children: %d\n", level * 2, "", entryOffset, abbreviationEntry.Code(), get_entry_tag_name(abbreviationEntry.Tag()), abbreviationEntry.Tag(), abbreviationEntry.HasChildren()); @@ -536,10 +538,7 @@ printf("\nfinishing compilation unit %p\n", unit); DataReader dataReader( (const uint8*)fDebugInfoSection->Data() + unit->HeaderOffset(), - unit->TotalSize()); -// DataReader dataReader( -// (const uint8*)fDebugInfoSection->Data() + unit->ContentOffset(), -// unit->ContentSize()); + unit->TotalSize(), unit->AddressSize()); DebugInfoEntryInitInfo entryInitInfo; @@ -547,9 +546,9 @@ printf("\nfinishing compilation unit %p\n", unit); for (int i = 0; i < entryCount; i++) { // get the entry DebugInfoEntry* entry; - dwarf_off_t offset; + off_t offset; unit->GetEntryAt(i, entry, offset); -printf("entry %p at %lu\n", entry, offset); +printf("entry %p at %lld\n", entry, offset); // seek the reader to the entry dataReader.SeekAbsolute(offset); @@ -617,12 +616,12 @@ DwarfFile::_ParseEntryAttributes(DataReader& dataReader, // those that need additional processing, we read a temporary value // first. uint64 value = 0; - dwarf_size_t blockLength = 0; + off_t blockLength = 0; bool localReference = true; switch (attributeForm) { case DW_FORM_addr: - value = dataReader.Read(0); + value = dataReader.ReadAddress(0); break; case DW_FORM_block2: blockLength = dataReader.Read(0); @@ -661,9 +660,11 @@ DwarfFile::_ParseEntryAttributes(DataReader& dataReader, case DW_FORM_strp: { if (fDebugStringSection != NULL) { - dwarf_off_t offset = dataReader.Read(0); + off_t offset = fCurrentCompilationUnit->IsDwarf64() + ? (off_t)dataReader.Read(0) + : (off_t)dataReader.Read(0); if (offset >= fDebugStringSection->Size()) { - fprintf(stderr, "Invalid DW_FORM_strp offset: %lu\n", + fprintf(stderr, "Invalid DW_FORM_strp offset: %lld\n", offset); return B_BAD_DATA; } @@ -680,7 +681,9 @@ DwarfFile::_ParseEntryAttributes(DataReader& dataReader, value = dataReader.ReadUnsignedLEB128(0); break; case DW_FORM_ref_addr: - value = dataReader.Read(0); + value = fCurrentCompilationUnit->IsDwarf64() + ? dataReader.Read(0) + : (uint64)dataReader.Read(0); localReference = false; break; case DW_FORM_ref1: @@ -818,11 +821,11 @@ printf(" -> no attribute setter!\n"); status_t DwarfFile::_ParseLineInfo(CompilationUnit* unit) { - dwarf_off_t offset = unit->UnitEntry()->StatementListOffset(); -printf("DwarfFile::_ParseLineInfo(%p), offset: %lu\n", unit, offset); + off_t offset = unit->UnitEntry()->StatementListOffset(); +printf("DwarfFile::_ParseLineInfo(%p), offset: %lld\n", unit, offset); DataReader dataReader((uint8*)fDebugLineSection->Data() + offset, - fDebugLineSection->Size() - offset); + fDebugLineSection->Size() - offset, unit->AddressSize()); // unit length bool dwarf64; @@ -921,13 +924,14 @@ printf("DwarfFile::_ParseLineInfo(%p), offset: %lu\n", unit, offset); status_t -DwarfFile::_ParseCIE(CfaContext& context, dwarf_off_t cieOffset) +DwarfFile::_ParseCIE(CompilationUnit* unit, CfaContext& context, + off_t cieOffset) { if (cieOffset < 0 || cieOffset >= fDebugFrameSection->Size()) return B_BAD_DATA; DataReader dataReader((uint8*)fDebugFrameSection->Data() + cieOffset, - fDebugFrameSection->Size() - cieOffset); + fDebugFrameSection->Size() - cieOffset, unit->AddressSize()); // length bool dwarf64; @@ -962,20 +966,21 @@ context.ReturnAddressRegister()); if (remaining < 0) return B_BAD_DATA; - return _ParseFrameInfoInstructions(context, dataReader.Offset(), remaining); + return _ParseFrameInfoInstructions(unit, context, dataReader.Offset(), + remaining); } status_t -DwarfFile::_ParseFrameInfoInstructions(CfaContext& context, - dwarf_off_t instructionOffset, dwarf_off_t instructionSize) +DwarfFile::_ParseFrameInfoInstructions(CompilationUnit* unit, + CfaContext& context, off_t instructionOffset, off_t instructionSize) { if (instructionSize <= 0) return B_OK; DataReader dataReader( (uint8*)fDebugFrameSection->Data() + instructionOffset, - instructionSize); + instructionSize, unit->AddressSize()); while (dataReader.BytesRemaining() > 0) { printf(" [%2lld]", dataReader.BytesRemaining()); @@ -987,7 +992,7 @@ printf(" [%2lld]", dataReader.BytesRemaining()); case DW_CFA_advance_loc: { printf(" DW_CFA_advance_loc: %#lx\n", operand); - dwarf_addr_t location = context.Location() + target_addr_t location = context.Location() + operand * context.CodeAlignment(); if (location > context.TargetLocation()) return B_OK; @@ -1020,8 +1025,8 @@ printf(" DW_CFA_restore: %#lx\n", operand); } case DW_CFA_set_loc: { - dwarf_addr_t location = dataReader.Read(0); -printf(" DW_CFA_set_loc: %#lx\n", location); + target_addr_t location = dataReader.ReadAddress(0); +printf(" DW_CFA_set_loc: %#llx\n", location); if (location < context.Location()) return B_BAD_VALUE; if (location > context.TargetLocation()) @@ -1033,7 +1038,7 @@ printf(" DW_CFA_set_loc: %#lx\n", location); { uint32 delta = dataReader.Read(0); printf(" DW_CFA_advance_loc1: %#lx\n", delta); - dwarf_addr_t location = context.Location() + target_addr_t location = context.Location() + delta * context.CodeAlignment(); if (location > context.TargetLocation()) return B_OK; @@ -1044,7 +1049,7 @@ printf(" DW_CFA_advance_loc1: %#lx\n", delta); { uint32 delta = dataReader.Read(0); printf(" DW_CFA_advance_loc2: %#lx\n", delta); - dwarf_addr_t location = context.Location() + target_addr_t location = context.Location() + delta * context.CodeAlignment(); if (location > context.TargetLocation()) return B_OK; @@ -1055,7 +1060,7 @@ printf(" DW_CFA_advance_loc2: %#lx\n", delta); { uint32 delta = dataReader.Read(0); printf(" DW_CFA_advance_loc4: %#lx\n", delta); - dwarf_addr_t location = context.Location() + target_addr_t location = context.Location() + delta * context.CodeAlignment(); if (location > context.TargetLocation()) return B_OK; @@ -1243,7 +1248,7 @@ printf(" DW_CFA_val_expression: reg: %lu, block: %p, %llu\n", reg, block, blo { uint64 delta = dataReader.Read(0); printf(" DW_CFA_MIPS_advance_loc8: %#llx\n", delta); - dwarf_addr_t location = context.Location() + target_addr_t location = context.Location() + delta * context.CodeAlignment(); if (location > context.TargetLocation()) return B_OK; @@ -1347,20 +1352,22 @@ DwarfFile::_ResolveRangeList(uint64 offset) } Reference rangesReference(ranges); - dwarf_addr_t baseAddress + target_addr_t baseAddress = fCurrentCompilationUnit->UnitEntry()->AddressRangeBase(); + target_addr_t maxAddress = fCurrentCompilationUnit->MaxAddress(); DataReader dataReader((uint8*)fDebugRangesSection->Data() + offset, - fDebugRangesSection->Size() - offset); + fDebugRangesSection->Size() - offset, + fCurrentCompilationUnit->AddressSize()); while (true) { - dwarf_addr_t start = dataReader.Read(0); - dwarf_addr_t end = dataReader.Read(0); + target_addr_t start = dataReader.ReadAddress(0); + target_addr_t end = dataReader.ReadAddress(0); if (dataReader.HasOverflow()) return NULL; if (start == 0 && end == 0) break; - if (start == DWARF_ADDRESS_MAX) { + if (start == maxAddress) { baseAddress = end; continue; } diff --git a/src/apps/debugger/dwarf/DwarfFile.h b/src/apps/debugger/dwarf/DwarfFile.h index af328b1f57..46d5f0eb21 100644 --- a/src/apps/debugger/dwarf/DwarfFile.h +++ b/src/apps/debugger/dwarf/DwarfFile.h @@ -39,7 +39,8 @@ public: CompilationUnit* CompilationUnitForDIE( const DebugInfoEntry* entry) const; - status_t UnwindCallFrame(target_addr_t location, + status_t UnwindCallFrame(CompilationUnit* unit, + target_addr_t location, const DwarfTargetInterface* inputInterface, DwarfTargetInterface* outputInterface, target_addr_t& _framePointer); @@ -61,11 +62,12 @@ private: status_t _ParseLineInfo(CompilationUnit* unit); - status_t _ParseCIE(CfaContext& context, - dwarf_off_t cieOffset); - status_t _ParseFrameInfoInstructions(CfaContext& context, - dwarf_off_t instructionOffset, - dwarf_off_t instructionSize); + status_t _ParseCIE(CompilationUnit* unit, + CfaContext& context, off_t cieOffset); + status_t _ParseFrameInfoInstructions( + CompilationUnit* unit, CfaContext& context, + off_t instructionOffset, + off_t instructionSize); status_t _GetAbbreviationTable(off_t offset, AbbreviationTable*& _table); diff --git a/src/apps/debugger/dwarf/DwarfTypes.h b/src/apps/debugger/dwarf/DwarfTypes.h deleted file mode 100644 index b4c1a05f78..0000000000 --- a/src/apps/debugger/dwarf/DwarfTypes.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. - * Distributed under the terms of the MIT License. - */ -#ifndef DWARF_TYPES_H -#define DWARF_TYPES_H - -#include - - -// target address type -typedef uint32 dwarf_addr_t; - -// DWARF 32 or 64 offset/size types -typedef uint32 dwarf_off_t; -typedef uint32 dwarf_size_t; - - -#define DWARF_ADDRESS_MAX 0xffffffff - - -#endif // DWARF_TYPES_H diff --git a/src/apps/debugger/dwarf/LineNumberProgram.cpp b/src/apps/debugger/dwarf/LineNumberProgram.cpp index 1ac3361adb..646f1ebd78 100644 --- a/src/apps/debugger/dwarf/LineNumberProgram.cpp +++ b/src/apps/debugger/dwarf/LineNumberProgram.cpp @@ -18,7 +18,7 @@ static const uint8 kLineNumberStandardOpcodeOperands[] static const uint32 kLineNumberStandardOpcodeCount = 12; -LineNumberProgram::LineNumberProgram() +LineNumberProgram::LineNumberProgram(uint8 addressSize) : fProgram(NULL), fProgramSize(0), @@ -27,6 +27,7 @@ LineNumberProgram::LineNumberProgram() fLineBase(0), fLineRange(0), fOpcodeBase(0), + fAddressSize(addressSize), fStandardOpcodeLengths(NULL) { } @@ -72,7 +73,7 @@ LineNumberProgram::GetInitialState(State& state) const return; _SetToInitial(state); - state.dataReader.SetTo(fProgram, fProgramSize); + state.dataReader.SetTo(fProgram, fProgramSize, fAddressSize); } @@ -160,7 +161,7 @@ printf("unsupported standard opcode %u\n", opcode); appendRow = true; break; case DW_LNE_set_address: - state.address = dataReader.Read(0); + state.address = dataReader.ReadAddress(0); break; case DW_LNE_define_file: { diff --git a/src/apps/debugger/dwarf/LineNumberProgram.h b/src/apps/debugger/dwarf/LineNumberProgram.h index 24426f86a8..e1e3a64297 100644 --- a/src/apps/debugger/dwarf/LineNumberProgram.h +++ b/src/apps/debugger/dwarf/LineNumberProgram.h @@ -6,7 +6,7 @@ #define LINE_NUMBER_PROGRAM_H #include "DataReader.h" -#include "DwarfTypes.h" +#include "Types.h" class LineNumberProgram { @@ -14,7 +14,7 @@ public: struct State; public: - LineNumberProgram(); + LineNumberProgram(uint8 addressSize); ~LineNumberProgram(); status_t Init(const void* program, size_t programSize, @@ -38,12 +38,13 @@ private: int8 fLineBase; uint8 fLineRange; uint8 fOpcodeBase; + uint8 fAddressSize; const uint8* fStandardOpcodeLengths; }; struct LineNumberProgram::State { - dwarf_addr_t address; + target_addr_t address; int32 file; int32 line; int32 column;