From 3a1ce93bc72bfa23e0f46642c256aa735fb80426 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 11 Nov 2010 23:58:17 +0000 Subject: [PATCH] When computing absolute addresses, take the image relocation delta into account. Fixes retrieving the addresses and consequently values of static variables. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39407 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../debugger/debug_info/DwarfImageDebugInfo.cpp | 7 ++++--- .../debug_info/DwarfStackFrameDebugInfo.cpp | 9 +++++---- .../debugger/debug_info/DwarfStackFrameDebugInfo.h | 1 + src/apps/debugger/debug_info/DwarfTypes.cpp | 7 ++++--- src/apps/debugger/debug_info/DwarfTypes.h | 4 ++++ .../debugger/dwarf/DwarfExpressionEvaluator.cpp | 13 +++++++------ src/apps/debugger/dwarf/DwarfExpressionEvaluator.h | 6 ++++-- src/apps/debugger/dwarf/DwarfFile.cpp | 6 ++++-- src/apps/debugger/dwarf/DwarfFile.h | 1 + 9 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp index d9c5f90e36..aaa94edda7 100644 --- a/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp @@ -402,7 +402,8 @@ DwarfImageDebugInfo::GetType(GlobalTypeCache* cache, if (typeContext == NULL) { typeContext = new(std::nothrow) DwarfTypeContext(fArchitecture, fImageInfo.ImageID(), fFile, - unit, NULL, 0, 0, &inputInterface, fromDwarfMap); + unit, NULL, 0, 0, fRelocationDelta, &inputInterface, + fromDwarfMap); if (typeContext == NULL) return B_NO_MEMORY; typeContextReference.SetTo(typeContext, true); @@ -504,8 +505,8 @@ DwarfImageDebugInfo::CreateFrame(Image* image, DwarfStackFrameDebugInfo* stackFrameDebugInfo = new(std::nothrow) DwarfStackFrameDebugInfo(fArchitecture, fImageInfo.ImageID(), fFile, unit, subprogramEntry, fTypeLookup, - fTypeCache, instructionPointer, framePointer, inputInterface, - fromDwarfMap); + fTypeCache, instructionPointer, framePointer, fRelocationDelta, + inputInterface, fromDwarfMap); if (stackFrameDebugInfo == NULL) return B_NO_MEMORY; Reference stackFrameDebugInfoReference( diff --git a/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.cpp b/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.cpp index 0f9f39ca40..1e6a1feea2 100644 --- a/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.cpp +++ b/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.cpp @@ -124,13 +124,13 @@ DwarfStackFrameDebugInfo::DwarfStackFrameDebugInfo(Architecture* architecture, image_id imageID, DwarfFile* file, CompilationUnit* compilationUnit, DIESubprogram* subprogramEntry, GlobalTypeLookup* typeLookup, GlobalTypeCache* typeCache, target_addr_t instructionPointer, - target_addr_t framePointer, DwarfTargetInterface* targetInterface, - RegisterMap* fromDwarfRegisterMap) + target_addr_t framePointer, target_addr_t relocationDelta, + DwarfTargetInterface* targetInterface, RegisterMap* fromDwarfRegisterMap) : StackFrameDebugInfo(), fTypeContext(new(std::nothrow) DwarfTypeContext(architecture, imageID, file, compilationUnit, subprogramEntry, instructionPointer, framePointer, - targetInterface, fromDwarfRegisterMap)), + relocationDelta, targetInterface, fromDwarfRegisterMap)), fTypeLookup(typeLookup), fTypeCache(typeCache) { @@ -159,7 +159,8 @@ DwarfStackFrameDebugInfo::Init() DwarfTypeContext* typeContext = new(std::nothrow) DwarfTypeContext( fTypeContext->GetArchitecture(), fTypeContext->ImageID(), fTypeContext->File(), fTypeContext->GetCompilationUnit(), NULL, 0, 0, - fTypeContext->TargetInterface(), fTypeContext->FromDwarfRegisterMap()); + fTypeContext->RelocationDelta(), fTypeContext->TargetInterface(), + fTypeContext->FromDwarfRegisterMap()); if (typeContext == NULL) return B_NO_MEMORY; Reference typeContextReference(typeContext, true); diff --git a/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.h b/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.h index bcf17f468e..e55d0d2ed1 100644 --- a/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.h +++ b/src/apps/debugger/debug_info/DwarfStackFrameDebugInfo.h @@ -41,6 +41,7 @@ public: GlobalTypeCache* typeCache, target_addr_t instructionPointer, target_addr_t framePointer, + target_addr_t relocationDelta, DwarfTargetInterface* targetInterface, RegisterMap* fromDwarfRegisterMap); ~DwarfStackFrameDebugInfo(); diff --git a/src/apps/debugger/debug_info/DwarfTypes.cpp b/src/apps/debugger/debug_info/DwarfTypes.cpp index 11d902e829..dff27bb625 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.cpp +++ b/src/apps/debugger/debug_info/DwarfTypes.cpp @@ -56,8 +56,8 @@ struct HasByteStridePredicate { DwarfTypeContext::DwarfTypeContext(Architecture* architecture, image_id imageID, DwarfFile* file, CompilationUnit* compilationUnit, DIESubprogram* subprogramEntry, target_addr_t instructionPointer, - target_addr_t framePointer, DwarfTargetInterface* targetInterface, - RegisterMap* fromDwarfRegisterMap) + target_addr_t framePointer, target_addr_t relocationDelta, + DwarfTargetInterface* targetInterface, RegisterMap* fromDwarfRegisterMap) : fArchitecture(architecture), fImageID(imageID), @@ -66,6 +66,7 @@ DwarfTypeContext::DwarfTypeContext(Architecture* architecture, image_id imageID, fSubprogramEntry(subprogramEntry), fInstructionPointer(instructionPointer), fFramePointer(framePointer), + fRelocationDelta(relocationDelta), fTargetInterface(targetInterface), fFromDwarfRegisterMap(fromDwarfRegisterMap) { @@ -218,7 +219,7 @@ DwarfType::ResolveLocation(DwarfTypeContext* typeContext, typeContext->GetCompilationUnit(), typeContext->SubprogramEntry(), description, typeContext->TargetInterface(), typeContext->InstructionPointer(), objectAddress, - typeContext->FramePointer(), _location); + typeContext->FramePointer(), typeContext->RelocationDelta(), _location); if (error != B_OK) return error; diff --git a/src/apps/debugger/debug_info/DwarfTypes.h b/src/apps/debugger/debug_info/DwarfTypes.h index cc13265d56..5e7b87db51 100644 --- a/src/apps/debugger/debug_info/DwarfTypes.h +++ b/src/apps/debugger/debug_info/DwarfTypes.h @@ -49,6 +49,7 @@ public: DIESubprogram* subprogramEntry, target_addr_t instructionPointer, target_addr_t framePointer, + target_addr_t relocationDelta, DwarfTargetInterface* targetInterface, RegisterMap* fromDwarfRegisterMap); ~DwarfTypeContext(); @@ -67,6 +68,8 @@ public: { return fInstructionPointer; } target_addr_t FramePointer() const { return fFramePointer; } + target_addr_t RelocationDelta() const + { return fRelocationDelta; } DwarfTargetInterface* TargetInterface() const { return fTargetInterface; } RegisterMap* FromDwarfRegisterMap() const @@ -80,6 +83,7 @@ private: DIESubprogram* fSubprogramEntry; target_addr_t fInstructionPointer; target_addr_t fFramePointer; + target_addr_t fRelocationDelta; DwarfTargetInterface* fTargetInterface; RegisterMap* fFromDwarfRegisterMap; }; diff --git a/src/apps/debugger/dwarf/DwarfExpressionEvaluator.cpp b/src/apps/debugger/dwarf/DwarfExpressionEvaluator.cpp index 611ffca2fb..4bcea53a33 100644 --- a/src/apps/debugger/dwarf/DwarfExpressionEvaluator.cpp +++ b/src/apps/debugger/dwarf/DwarfExpressionEvaluator.cpp @@ -159,8 +159,8 @@ DwarfExpressionEvaluator::Evaluate(const void* expression, size_t size, status_t DwarfExpressionEvaluator::EvaluateLocation(const void* expression, size_t size, - ValueLocation& _location) -{ + target_addr_t relocationDelta, ValueLocation& _location) +{ _location.Clear(); // the empty expression is a valid one @@ -181,7 +181,7 @@ DwarfExpressionEvaluator::EvaluateLocation(const void* expression, size_t size, _Push(objectAddress); ValuePieceLocation piece; - status_t error = _Evaluate(&piece); + status_t error = _Evaluate(&piece, relocationDelta); if (error != B_OK) return error; @@ -229,7 +229,7 @@ DwarfExpressionEvaluator::EvaluateLocation(const void* expression, size_t size, _Push(objectAddress); ValuePieceLocation piece; - status_t error = _Evaluate(&piece); + status_t error = _Evaluate(&piece, relocationDelta); if (error != B_OK) return error; @@ -262,7 +262,8 @@ DwarfExpressionEvaluator::EvaluateLocation(const void* expression, size_t size, status_t -DwarfExpressionEvaluator::_Evaluate(ValuePieceLocation* _piece) +DwarfExpressionEvaluator::_Evaluate(ValuePieceLocation* _piece, + target_addr_t relocationDelta) { TRACE_EXPR_ONLY({ TRACE_EXPR("DwarfExpressionEvaluator::_Evaluate(%p, %lld)\n", @@ -282,7 +283,7 @@ DwarfExpressionEvaluator::_Evaluate(ValuePieceLocation* _piece) switch (opcode) { case DW_OP_addr: TRACE_EXPR(" DW_OP_addr\n"); - _Push(fDataReader.ReadAddress(0)); + _Push(fDataReader.ReadAddress(0) + relocationDelta); break; case DW_OP_const1u: TRACE_EXPR(" DW_OP_const1u\n"); diff --git a/src/apps/debugger/dwarf/DwarfExpressionEvaluator.h b/src/apps/debugger/dwarf/DwarfExpressionEvaluator.h index c1edb40252..1a67d86a88 100644 --- a/src/apps/debugger/dwarf/DwarfExpressionEvaluator.h +++ b/src/apps/debugger/dwarf/DwarfExpressionEvaluator.h @@ -57,7 +57,8 @@ public: status_t Evaluate(const void* expression, size_t size, target_addr_t& _result); status_t EvaluateLocation(const void* expression, - size_t size, ValueLocation& _location); + size_t size, target_addr_t relocationDelta, + ValueLocation& _location); // The returned location will have DWARF // semantics regarding register numbers and // bit offsets/sizes (cf. bit pieces). @@ -71,7 +72,8 @@ private: inline void _Push(target_addr_t value); inline target_addr_t _Pop(); - status_t _Evaluate(ValuePieceLocation* _piece); + status_t _Evaluate(ValuePieceLocation* _piece, + target_addr_t relocationDelta = 0); void _DereferenceAddress(uint8 addressSize); void _DereferenceAddressSpaceAddress( uint8 addressSize); diff --git a/src/apps/debugger/dwarf/DwarfFile.cpp b/src/apps/debugger/dwarf/DwarfFile.cpp index b1c9e7258f..b1f7c224db 100644 --- a/src/apps/debugger/dwarf/DwarfFile.cpp +++ b/src/apps/debugger/dwarf/DwarfFile.cpp @@ -843,7 +843,8 @@ DwarfFile::ResolveLocation(CompilationUnit* unit, DIESubprogram* subprogramEntry, const LocationDescription* location, const DwarfTargetInterface* targetInterface, target_addr_t instructionPointer, target_addr_t objectPointer, - target_addr_t framePointer, ValueLocation& _result) + target_addr_t framePointer, target_addr_t relocationDelta, + ValueLocation& _result) { // get the expression const void* expression; @@ -857,7 +858,8 @@ DwarfFile::ResolveLocation(CompilationUnit* unit, ExpressionEvaluationContext context(this, unit, subprogramEntry, targetInterface, instructionPointer, objectPointer, framePointer); DwarfExpressionEvaluator evaluator(&context); - return evaluator.EvaluateLocation(expression, expressionLength, _result); + return evaluator.EvaluateLocation(expression, expressionLength, + relocationDelta, _result); } diff --git a/src/apps/debugger/dwarf/DwarfFile.h b/src/apps/debugger/dwarf/DwarfFile.h index 2d213809cb..c6f8d196b1 100644 --- a/src/apps/debugger/dwarf/DwarfFile.h +++ b/src/apps/debugger/dwarf/DwarfFile.h @@ -69,6 +69,7 @@ public: target_addr_t instructionPointer, target_addr_t objectPointer, target_addr_t framePointer, + target_addr_t relocationDelta, ValueLocation& _result); // The returned location will have DWARF // semantics regarding register numbers and