1200483Srwatson/* 2200483Srwatson * Copyright 2009-2010, Ingo Weinhold, ingo_weinhold@gmx.de. 3200483Srwatson * Copyright 2012, Rene Gollent, rene@gollent.com. 4200483Srwatson * Distributed under the terms of the MIT License. 5200483Srwatson */ 6200483Srwatson#ifndef DWARF_FILE_H 7200483Srwatson#define DWARF_FILE_H 8200483Srwatson 9200483Srwatson 10200483Srwatson#include <ObjectList.h> 11200483Srwatson#include <Referenceable.h> 12200483Srwatson#include <util/DoublyLinkedList.h> 13200483Srwatson 14200483Srwatson#include "DebugInfoEntries.h" 15200483Srwatson 16200483Srwatson 17200483Srwatsonclass AbbreviationEntry; 18200483Srwatsonclass AbbreviationTable; 19200483Srwatsonclass BVariant; 20200483Srwatsonclass CfaContext; 21200483Srwatsonclass CompilationUnit; 22200483Srwatsonclass DataReader; 23200483Srwatsonclass DwarfTargetInterface; 24200483Srwatsonclass ElfFile; 25200483Srwatsonclass ElfSection; 26200483Srwatsonclass TargetAddressRangeList; 27200483Srwatsonclass ValueLocation; 28200483Srwatson 29200483Srwatson 30200483Srwatsonclass DwarfFile : public BReferenceable, 31200483Srwatson public DoublyLinkedListLinkImpl<DwarfFile> { 32200483Srwatsonpublic: 33200483Srwatson DwarfFile(); 34200483Srwatson ~DwarfFile(); 35200483Srwatson 36200483Srwatson status_t Load(const char* fileName); 37200483Srwatson status_t FinishLoading(); 38200483Srwatson 39200483Srwatson const char* Name() const { return fName; } 40200483Srwatson ElfFile* GetElfFile() const { return fElfFile; } 41200483Srwatson 42200483Srwatson int32 CountCompilationUnits() const; 43200483Srwatson CompilationUnit* CompilationUnitAt(int32 index) const; 44200483Srwatson CompilationUnit* CompilationUnitForDIE( 45200483Srwatson const DebugInfoEntry* entry) const; 46200483Srwatson 47200483Srwatson TargetAddressRangeList* ResolveRangeList(CompilationUnit* unit, 48200483Srwatson uint64 offset) const; 49200483Srwatson 50200483Srwatson status_t UnwindCallFrame(CompilationUnit* unit, 51200483Srwatson uint8 addressSize, 52200483Srwatson DIESubprogram* subprogramEntry, 53200483Srwatson target_addr_t location, 54200483Srwatson const DwarfTargetInterface* inputInterface, 55200483Srwatson DwarfTargetInterface* outputInterface, 56200483Srwatson target_addr_t& _framePointer); 57200483Srwatson 58200483Srwatson status_t EvaluateExpression(CompilationUnit* unit, 59200483Srwatson uint8 addressSize, 60200483Srwatson DIESubprogram* subprogramEntry, 61200483Srwatson const void* expression, 62200483Srwatson off_t expressionLength, 63200483Srwatson const DwarfTargetInterface* targetInterface, 64200483Srwatson target_addr_t instructionPointer, 65200483Srwatson target_addr_t framePointer, 66200483Srwatson target_addr_t valueToPush, bool pushValue, 67200483Srwatson target_addr_t& _result); 68200483Srwatson status_t ResolveLocation(CompilationUnit* unit, 69200483Srwatson uint8 addressSize, 70200483Srwatson DIESubprogram* subprogramEntry, 71200483Srwatson const LocationDescription* location, 72200483Srwatson const DwarfTargetInterface* targetInterface, 73200483Srwatson target_addr_t instructionPointer, 74200483Srwatson target_addr_t objectPointer, 75200483Srwatson bool hasObjectPointer, 76200483Srwatson target_addr_t framePointer, 77200483Srwatson target_addr_t relocationDelta, 78200483Srwatson ValueLocation& _result); 79200483Srwatson // The returned location will have DWARF 80200483Srwatson // semantics regarding register numbers and 81200483Srwatson // bit offsets/sizes (cf. bit pieces). 82200483Srwatson 83200483Srwatson status_t EvaluateConstantValue(CompilationUnit* unit, 84200483Srwatson uint8 addressSize, 85200483Srwatson DIESubprogram* subprogramEntry, 86200483Srwatson const ConstantAttributeValue* value, 87200483Srwatson const DwarfTargetInterface* targetInterface, 88200483Srwatson target_addr_t instructionPointer, 89200483Srwatson target_addr_t framePointer, 90200483Srwatson BVariant& _result); 91200483Srwatson status_t EvaluateDynamicValue(CompilationUnit* unit, uint8 addressSize, 92200483Srwatson DIESubprogram* subprogramEntry, 93200483Srwatson const DynamicAttributeValue* value, 94200483Srwatson const DwarfTargetInterface* targetInterface, 95200483Srwatson target_addr_t instructionPointer, 96200483Srwatson target_addr_t framePointer, 97200483Srwatson BVariant& _result, DIEType** _type = NULL); 98200483Srwatson 99200483Srwatsonprivate: 100200483Srwatson struct ExpressionEvaluationContext; 101200483Srwatson struct FDEAugmentation; 102200483Srwatson struct CIEAugmentation; 103200483Srwatson 104200483Srwatson typedef DoublyLinkedList<AbbreviationTable> AbbreviationTableList; 105200483Srwatson typedef BObjectList<CompilationUnit> CompilationUnitList; 106200483Srwatson 107200483Srwatsonprivate: 108200483Srwatson status_t _ParseCompilationUnit(CompilationUnit* unit); 109200483Srwatson status_t _ParseDebugInfoEntry(DataReader& dataReader, 110200483Srwatson AbbreviationTable* abbreviationTable, 111200483Srwatson DebugInfoEntry*& _entry, 112200483Srwatson bool& _endOfEntryList, int level = 0); 113200483Srwatson status_t _FinishCompilationUnit(CompilationUnit* unit); 114200483Srwatson status_t _ParseEntryAttributes(DataReader& dataReader, 115200483Srwatson DebugInfoEntry* entry, 116200483Srwatson AbbreviationEntry& abbreviationEntry); 117200483Srwatson 118200483Srwatson status_t _ParseLineInfo(CompilationUnit* unit); 119200483Srwatson 120200483Srwatson status_t _UnwindCallFrame(bool usingEHFrameSection, 121200483Srwatson CompilationUnit* unit, 122200483Srwatson uint8 addressSize, 123200483Srwatson DIESubprogram* subprogramEntry, 124200483Srwatson target_addr_t location, 125200483Srwatson const DwarfTargetInterface* inputInterface, 126200483Srwatson DwarfTargetInterface* outputInterface, 127200483Srwatson target_addr_t& _framePointer); 128200483Srwatson 129200483Srwatson status_t _ParseCIEHeader(ElfSection* debugFrameSection, 130200483Srwatson bool usingEHFrameSection, 131200483Srwatson CompilationUnit* unit, 132200483Srwatson uint8 addressSize, 133200483Srwatson CfaContext& context, off_t cieOffset, 134200483Srwatson CIEAugmentation& cieAugmentation, 135200483Srwatson DataReader& reader, 136200483Srwatson off_t& _cieRemaining); 137200483Srwatson status_t _ParseFrameInfoInstructions( 138200483Srwatson CompilationUnit* unit, CfaContext& context, 139200483Srwatson DataReader& dataReader, 140200483Srwatson CIEAugmentation& cieAugmentation); 141200483Srwatson 142200483Srwatson status_t _ParsePublicTypesInfo(); 143200483Srwatson status_t _ParsePublicTypesInfo(DataReader& dataReader, 144200483Srwatson bool dwarf64); 145200483Srwatson 146200483Srwatson status_t _GetAbbreviationTable(off_t offset, 147200483Srwatson AbbreviationTable*& _table); 148200483Srwatson 149200483Srwatson DebugInfoEntry* _ResolveReference(CompilationUnit* unit, 150200483Srwatson uint64 offset, bool localReference) const; 151200483Srwatson 152200483Srwatson status_t _GetLocationExpression(CompilationUnit* unit, 153200483Srwatson const LocationDescription* location, 154200483Srwatson target_addr_t instructionPointer, 155200483Srwatson const void*& _expression, 156200483Srwatson off_t& _length) const; 157200483Srwatson status_t _FindLocationExpression(CompilationUnit* unit, 158200483Srwatson uint64 offset, target_addr_t address, 159200483Srwatson const void*& _expression, 160200483Srwatson off_t& _length) const; 161200483Srwatson 162200483Srwatson status_t _LocateDebugInfo(); 163200483Srwatson status_t _GetDebugInfoPath(const char* fileName, 164200483Srwatson BString& _infoPath); 165200483Srwatson 166200483Srwatsonprivate: 167200483Srwatson friend class DwarfFile::ExpressionEvaluationContext; 168200483Srwatson 169200483Srwatsonprivate: 170200483Srwatson char* fName; 171200483Srwatson char* fAlternateName; 172200483Srwatson ElfFile* fElfFile; 173200483Srwatson ElfFile* fAlternateElfFile; 174200483Srwatson ElfSection* fDebugInfoSection; 175200483Srwatson ElfSection* fDebugAbbrevSection; 176200483Srwatson ElfSection* fDebugStringSection; 177200483Srwatson ElfSection* fDebugRangesSection; 178200483Srwatson ElfSection* fDebugLineSection; 179200483Srwatson ElfSection* fDebugFrameSection; 180200483Srwatson ElfSection* fEHFrameSection; 181200483Srwatson ElfSection* fDebugLocationSection; 182200483Srwatson ElfSection* fDebugPublicTypesSection; 183200483Srwatson AbbreviationTableList fAbbreviationTables; 184200483Srwatson DebugInfoEntryFactory fDebugInfoFactory; 185200483Srwatson CompilationUnitList fCompilationUnits; 186200483Srwatson CompilationUnit* fCurrentCompilationUnit; 187200483Srwatson bool fFinished; 188200483Srwatson status_t fFinishError; 189200483Srwatson}; 190200483Srwatson 191200483Srwatson 192200483Srwatson#endif // DWARF_FILE_H 193200483Srwatson