1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2010-2018, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef DWARF_IMAGE_DEBUG_INFO_H 7 #define DWARF_IMAGE_DEBUG_INFO_H 8 9 10 #include <Locker.h> 11 12 #include <util/OpenHashTable.h> 13 14 #include "AddressSectionTypes.h" 15 #include "ImageInfo.h" 16 #include "SpecificImageDebugInfo.h" 17 #include "Type.h" 18 19 20 class Architecture; 21 class CompilationUnit; 22 class DebuggerInterface; 23 class DIENamespace; 24 class DIESubprogram; 25 class DIEType; 26 class DwarfFunctionDebugInfo; 27 class DwarfStackFrameDebugInfo; 28 class DwarfFile; 29 class ElfSegment; 30 class FileManager; 31 class FileSourceCode; 32 class FunctionID; 33 class FunctionInstance; 34 class GlobalTypeCache; 35 class GlobalTypeLookup; 36 class LocatableFile; 37 class SourceCode; 38 class TeamFunctionSourceInformation; 39 40 41 class DwarfImageDebugInfo : public SpecificImageDebugInfo { 42 public: 43 DwarfImageDebugInfo(const ImageInfo& imageInfo, 44 DebuggerInterface* interface, 45 Architecture* architecture, 46 FileManager* fileManager, 47 GlobalTypeLookup* typeLookup, 48 GlobalTypeCache* typeCache, 49 TeamFunctionSourceInformation* sourceInfo, 50 DwarfFile* file); 51 virtual ~DwarfImageDebugInfo(); 52 53 status_t Init(); 54 55 target_addr_t RelocationDelta() const 56 { return fRelocationDelta; } 57 58 virtual status_t GetFunctions( 59 const BObjectList<SymbolInfo>& symbols, 60 BObjectList<FunctionDebugInfo>& functions); 61 virtual status_t GetType(GlobalTypeCache* cache, 62 const BString& name, 63 const TypeLookupConstraints& constraints, 64 Type*& _type); 65 virtual bool HasType(const BString& name, 66 const TypeLookupConstraints& constraints) 67 const; 68 69 virtual AddressSectionType GetAddressSectionType(target_addr_t address); 70 71 virtual status_t CreateFrame(Image* image, 72 FunctionInstance* functionInstance, 73 CpuState* cpuState, 74 bool getFullFrameInfo, 75 ReturnValueInfoList* returnValueInfos, 76 StackFrame*& _frame, 77 CpuState*& _previousCpuState); 78 virtual status_t GetStatement(FunctionDebugInfo* function, 79 target_addr_t address, 80 Statement*& _statement); 81 virtual status_t GetStatementAtSourceLocation( 82 FunctionDebugInfo* function, 83 const SourceLocation& sourceLocation, 84 Statement*& _statement); 85 86 virtual status_t GetSourceLanguage(FunctionDebugInfo* function, 87 SourceLanguage*& _language); 88 89 virtual ssize_t ReadCode(target_addr_t address, void* buffer, 90 size_t size); 91 92 virtual status_t AddSourceCodeInfo(LocatableFile* file, 93 FileSourceCode* sourceCode); 94 95 private: 96 struct BasicTargetInterface; 97 struct UnwindTargetInterface; 98 struct EntryListWrapper; 99 100 struct TypeNameKey; 101 struct TypeNameEntry; 102 struct TypeNameEntryHashDefinition; 103 104 typedef BOpenHashTable<TypeNameEntryHashDefinition> 105 TypeNameTable; 106 107 struct TypeEntryInfo; 108 typedef BObjectList<TypeEntryInfo> TypeEntryList; 109 110 private: 111 status_t _AddSourceCodeInfo(CompilationUnit* unit, 112 FileSourceCode* sourceCode, 113 int32 fileIndex); 114 int32 _GetSourceFileIndex(CompilationUnit* unit, 115 LocatableFile* sourceFile) const; 116 117 status_t _CreateLocalVariables(CompilationUnit* unit, 118 StackFrame* frame, FunctionID* functionID, 119 DwarfStackFrameDebugInfo& factory, 120 target_addr_t instructionPointer, 121 target_addr_t lowPC, 122 const EntryListWrapper& variableEntries, 123 const EntryListWrapper& blockEntries); 124 125 status_t _CreateReturnValues( 126 ReturnValueInfoList* returnValueInfos, 127 Image* image, 128 StackFrame* frame, 129 DwarfStackFrameDebugInfo& factory); 130 131 bool _EvaluateBaseTypeConstraints(DIEType* type, 132 const TypeLookupConstraints& constraints) 133 const; 134 135 status_t _RecursiveTraverseNamespaceForFunctions( 136 DIENamespace* nsEntry, 137 CompilationUnit* unit, 138 BObjectList<FunctionDebugInfo>& functions); 139 status_t _AddFunction(DIESubprogram* subprogramEntry, 140 CompilationUnit* unit, 141 BObjectList<FunctionDebugInfo>& functions); 142 143 status_t _BuildTypeNameTable(); 144 status_t _RecursiveAddTypeNames(DIEType* type, 145 CompilationUnit* unit); 146 status_t _RecursiveTraverseNamespaceForTypes( 147 DIENamespace* nsEntry, 148 CompilationUnit* unit); 149 150 private: 151 BLocker fLock; 152 ImageInfo fImageInfo; 153 DebuggerInterface* fDebuggerInterface; 154 Architecture* fArchitecture; 155 FileManager* fFileManager; 156 GlobalTypeLookup* fTypeLookup; 157 GlobalTypeCache* fTypeCache; 158 TeamFunctionSourceInformation* fSourceInfo; 159 TypeNameTable* fTypeNameTable; 160 DwarfFile* fFile; 161 ElfSegment* fTextSegment; 162 target_addr_t fRelocationDelta; 163 target_addr_t fTextSectionStart; 164 target_addr_t fTextSectionEnd; 165 target_addr_t fPLTSectionStart; 166 target_addr_t fPLTSectionEnd; 167 }; 168 169 170 #endif // DWARF_IMAGE_DEBUG_INFO_H 171