xref: /haiku/src/kits/debugger/debug_info/DwarfImageDebugInfo.h (revision 5d0fd0e4220b461e2021d5768ebaa936c13417f8)
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 DIEType;
25 class DwarfFunctionDebugInfo;
26 class DwarfStackFrameDebugInfo;
27 class DwarfFile;
28 class ElfSegment;
29 class FileManager;
30 class FileSourceCode;
31 class FunctionID;
32 class FunctionInstance;
33 class GlobalTypeCache;
34 class GlobalTypeLookup;
35 class LocatableFile;
36 class SourceCode;
37 class TeamFunctionSourceInformation;
38 
39 
40 class DwarfImageDebugInfo : public SpecificImageDebugInfo {
41 public:
42 								DwarfImageDebugInfo(const ImageInfo& imageInfo,
43 									DebuggerInterface* interface,
44 									Architecture* architecture,
45 									FileManager* fileManager,
46 									GlobalTypeLookup* typeLookup,
47 									GlobalTypeCache* typeCache,
48 									TeamFunctionSourceInformation* sourceInfo,
49 									DwarfFile* file);
50 	virtual						~DwarfImageDebugInfo();
51 
52 			status_t			Init();
53 
54 			target_addr_t		RelocationDelta() const
55 									{ return fRelocationDelta; }
56 
57 	virtual	status_t			GetFunctions(
58 									const BObjectList<SymbolInfo>& symbols,
59 									BObjectList<FunctionDebugInfo>& functions);
60 	virtual	status_t			GetType(GlobalTypeCache* cache,
61 									const BString& name,
62 									const TypeLookupConstraints& constraints,
63 									Type*& _type);
64 	virtual	bool				HasType(const BString& name,
65 									const TypeLookupConstraints& constraints)
66 									const;
67 
68 	virtual AddressSectionType	GetAddressSectionType(target_addr_t address);
69 
70 	virtual	status_t			CreateFrame(Image* image,
71 									FunctionInstance* functionInstance,
72 									CpuState* cpuState,
73 									bool getFullFrameInfo,
74 									ReturnValueInfoList* returnValueInfos,
75 									StackFrame*& _frame,
76 									CpuState*& _previousCpuState);
77 	virtual	status_t			GetStatement(FunctionDebugInfo* function,
78 									target_addr_t address,
79 									Statement*& _statement);
80 	virtual	status_t			GetStatementAtSourceLocation(
81 									FunctionDebugInfo* function,
82 									const SourceLocation& sourceLocation,
83 									Statement*& _statement);
84 
85 	virtual	status_t			GetSourceLanguage(FunctionDebugInfo* function,
86 									SourceLanguage*& _language);
87 
88 	virtual	ssize_t				ReadCode(target_addr_t address, void* buffer,
89 									size_t size);
90 
91 	virtual	status_t			AddSourceCodeInfo(LocatableFile* file,
92 									FileSourceCode* sourceCode);
93 
94 private:
95 			struct BasicTargetInterface;
96 			struct UnwindTargetInterface;
97 			struct EntryListWrapper;
98 
99 			struct TypeNameKey;
100 			struct TypeNameEntry;
101 			struct TypeNameEntryHashDefinition;
102 
103 			typedef BOpenHashTable<TypeNameEntryHashDefinition>
104 				TypeNameTable;
105 
106 			struct TypeEntryInfo;
107 			typedef BObjectList<TypeEntryInfo> TypeEntryList;
108 
109 private:
110 			status_t 			_AddSourceCodeInfo(CompilationUnit* unit,
111 									FileSourceCode* sourceCode,
112 									int32 fileIndex);
113 			int32				_GetSourceFileIndex(CompilationUnit* unit,
114 									LocatableFile* sourceFile) const;
115 
116 			status_t			_CreateLocalVariables(CompilationUnit* unit,
117 									StackFrame* frame, FunctionID* functionID,
118 									DwarfStackFrameDebugInfo& factory,
119 									target_addr_t instructionPointer,
120 									target_addr_t lowPC,
121 									const EntryListWrapper& variableEntries,
122 									const EntryListWrapper& blockEntries);
123 
124 			status_t			_CreateReturnValues(
125 									ReturnValueInfoList* returnValueInfos,
126 									Image* image,
127 									StackFrame* frame,
128 									DwarfStackFrameDebugInfo& factory);
129 
130 			bool				_EvaluateBaseTypeConstraints(DIEType* type,
131 									const TypeLookupConstraints& constraints)
132 									const;
133 
134 			status_t			_BuildTypeNameTable();
135 			status_t			_RecursiveAddTypeNames(DIEType* type,
136 									CompilationUnit* unit);
137 			status_t			_RecursiveTraverseNamespaceForTypes(
138 									DIENamespace* nsEntry,
139 									CompilationUnit* unit);
140 
141 private:
142 			BLocker				fLock;
143 			ImageInfo			fImageInfo;
144 			DebuggerInterface*	fDebuggerInterface;
145 			Architecture*		fArchitecture;
146 			FileManager*		fFileManager;
147 			GlobalTypeLookup*	fTypeLookup;
148 			GlobalTypeCache*	fTypeCache;
149 			TeamFunctionSourceInformation* fSourceInfo;
150 			TypeNameTable*		fTypeNameTable;
151 			DwarfFile*			fFile;
152 			ElfSegment*			fTextSegment;
153 			target_addr_t		fRelocationDelta;
154 			target_addr_t		fTextSectionStart;
155 			target_addr_t		fTextSectionEnd;
156 			target_addr_t		fPLTSectionStart;
157 			target_addr_t		fPLTSectionEnd;
158 };
159 
160 
161 #endif	// DWARF_IMAGE_DEBUG_INFO_H
162