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