OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef DWARF_READER_DWARF_READER_H_ | |
6 #define DWARF_READER_DWARF_READER_H_ | |
7 | |
8 #include "common/types.h" | |
9 #include "common/dwarf/dwarf2enums.h" | |
10 | |
11 namespace dwarf_reader { | |
12 | |
13 using dwarf2reader::DwarfAttribute; | |
14 using dwarf2reader::DwarfForm; | |
15 using dwarf2reader::DwarfTag; | |
16 | |
17 /// The interface for processing DWARF Data | |
18 class IDwarfReader { | |
19 // All offsets are from the beginning of the .debug_info for this module | |
20 // and when combined with the module uniquely identify the object. In | |
21 // addition all notifications function which can have children return a | |
22 // context as a void *, which be passed into any child references to | |
23 // facility building of tree structure. The order of calls and the values | |
24 // they pass can be seen bellow: | |
25 // | |
26 // root = StartCompilationUnit(...) | |
27 // child = StartDIE(root, ....) | |
28 // Property(child, ....) | |
29 // sub = StartDIE(child, ...) | |
30 // Property(sub, ....) | |
31 // EndDIE(sub) | |
32 // EndDIE(child) | |
33 // AddDir(root, ...) | |
34 // AddFile(root, ...) | |
35 // AddLine(root, ...) | |
36 // EndComplicationUnit(root) | |
37 // TODO(mlinck) remove unused ctx args and return values from this interface. | |
38 public: | |
39 /// Call Frame Information (CFI) handling | |
40 enum CFI_RuleType { | |
41 CFIRT_UNDEFINED, | |
42 CFIRT_SAMEVALUE, | |
43 CFIRT_OFFSET, | |
44 CFIRT_VALOFFSET, | |
45 CFIRT_REGISTER, | |
46 CFIRT_EXPRESSION, | |
47 CFIRT_VALEXPRESSION | |
48 }; | |
49 | |
50 /// Start to process a compilation unit at OFFSET from the beginning of the | |
51 /// .debug_info section. Return false if you would like to skip this | |
52 /// compilation unit. | |
53 /// @param[in] offset The offset of this compilation unit in its file | |
54 /// segment. | |
55 /// @param[in] address_size The size of an address on this architecture. | |
56 /// @param[in] offset_size The size of an offset on this architecture. | |
57 /// @param[in] cu_length The length of the compilation unit entry. | |
58 /// @param[in] dwarf_version The version of the dwarf_spec being used. | |
59 /// @return a context to be handed to the next call to this function (if | |
60 /// used.) | |
61 virtual void *StartCompilationUnit(uint64 offset, | |
62 uint8 address_size, | |
63 uint8 offset_size, | |
64 uint64 cu_length, | |
65 uint8 dwarf_version) = 0; | |
66 | |
67 /// Called when finished processing the CompilationUnit at OFFSET. | |
68 /// CU's are in the form of a linear list, so each one forms the root of | |
69 /// a DIE tree. TODO(mlinck) it may be possible to get rid of this function. | |
70 /// @param[in] ctx This argument is not used in the SymbolDatabase | |
71 /// @param[in] ctx The offset identifies which compilation unit is being | |
72 /// ended. | |
73 virtual void EndCompilationUnit(void *ctx, uint64 offset) = 0; | |
74 | |
75 /// Start to process a DIE at |offset| from the beginning of the .debug_info | |
76 /// section. Return false if you would like to skip this DIE. | |
77 /// @param[in] ctx Context returned by the previous call to StartDIE (if | |
78 /// used.) | |
79 /// @param[in] parent The offset of this DIE's parent (or 0) | |
80 /// @param[in] offset This DIE's offset in the .debug_info section. | |
81 /// @param[in] tag This DIE's type descriptor. | |
82 /// @return A context that may be passed to this DIE's children (if used.) | |
83 virtual void *StartDIE(void *ctx, | |
84 uint64 parent, | |
85 uint64 offset, | |
86 enum DwarfTag tag) = 0; | |
87 | |
88 /// Called when finished processing the DIE at OFFSET. | |
89 /// Because DWARF2/3 specifies a tree of DIEs, you may get starts | |
90 /// before ends of the previous DIE, as we process children before | |
91 /// ending the parent. | |
92 /// @param[in] ctx The context returned when this DIE was started (if used.) | |
93 /// @param[in] offset The offset of this DIE'd end-point in the .debug_info | |
94 /// section. | |
95 virtual void EndDIE(void *ctx, uint64 offset) = 0; | |
96 | |
97 /// Called when we have an attribute with unsigned data to give to our | |
98 /// handler. The attribute is for the DIE at OFFSET from the beginning of the | |
99 /// .debug_info section. Its name is ATTR, its form is FORM, and its value is | |
100 /// DATA. | |
101 /// @param[in] ctx To be removed. | |
102 /// @param[in] offset The offset of this attribute in the .debug_info | |
103 /// section. | |
104 /// @param[in] parent The DIE modified by this attribute. | |
105 /// @param[in] attr The type specifier for this attribute. | |
106 /// @param[in] form The form of data that is associated with this attribute. | |
107 /// @param[in] data The actual data. | |
108 virtual void ProcessAttributeUnsigned(void *ctx, | |
109 uint64 offset, | |
110 uint64 parent, | |
111 enum DwarfAttribute attr, | |
112 enum DwarfForm form, | |
113 uint64 data) = 0; | |
114 | |
115 /// Called when we have an attribute with signed data to give to our handler. | |
116 /// The attribute is for the DIE at OFFSET from the beginning of the | |
117 /// .debug_info section. Its name is ATTR, its form is FORM, and its value is | |
118 /// DATA. | |
119 /// @param[in] ctx To be removed. | |
120 /// @param[in] offset The offset of this attribute in the .debug_info | |
121 /// section. | |
122 /// @param[in] parent The DIE modified by this attribute. | |
123 /// @param[in] attr The type specifier for this attribute. | |
124 /// @param[in] form The form of data that is associated with this attribute. | |
125 /// @param[in] data The actual data. | |
126 virtual void ProcessAttributeSigned(void *ctx, | |
127 uint64 offset, | |
128 uint64 parent, | |
129 enum DwarfAttribute attr, | |
130 enum DwarfForm form, | |
131 int64 data) = 0; | |
132 | |
133 /// Called when we have an attribute whose value is a reference to | |
134 /// another DIE. The attribute belongs to the DIE at OFFSET from the | |
135 /// beginning of the .debug_info section. Its name is ATTR, its form | |
136 /// is FORM, and the offset of the DIE being referred to from the | |
137 /// beginning of the .debug_info section is DATA. | |
138 /// @param[in] ctx To be removed. | |
139 /// @param[in] offset The offset of this attribute in the .debug_info | |
140 /// section. | |
141 /// @param[in] parent The DIE modified by this attribute. | |
142 /// @param[in] attr The type specifier for this attribute. | |
143 /// @param[in] form The form of data that is associated with this attribute. | |
144 /// @param[in] data The actual data. | |
145 virtual void ProcessAttributeReference(void *ctx, | |
146 uint64 offset, | |
147 uint64 parent, | |
148 enum DwarfAttribute attr, | |
149 enum DwarfForm form, | |
150 uint64 data) = 0; | |
151 | |
152 /// Called when we have an attribute with a buffer of data to give to our | |
153 /// handler. The attribute is for the DIE at OFFSET from the beginning of the | |
154 /// .debug_info section. Its name is ATTR, its form is FORM, DATA points to | |
155 /// the buffer's contents, and its length in bytes is LENGTH. The buffer is | |
156 /// owned by the caller, not the callee, and may not persist for very long. | |
157 /// If you want the data to be available later, it needs to be copied. | |
158 /// @param[in] ctx To be removed. | |
159 /// @param[in] offset The offset of this attribute in the .debug_info | |
160 /// section. | |
161 /// @param[in] parent The DIE modified by this attribute. | |
162 /// @param[in] attr The type specifier for this attribute. | |
163 /// @param[in] form The form of data that is associated with this attribute. | |
164 /// @param[in] data The actual data. | |
165 virtual void ProcessAttributeBuffer(void *ctx, | |
166 uint64 offset, | |
167 uint64 parent, | |
168 enum DwarfAttribute attr, | |
169 enum DwarfForm form, | |
170 const char* data, | |
171 uint64 len) = 0; | |
172 | |
173 /// Called when we have an attribute with string data to give to our handler. | |
174 /// The attribute is for the DIE at OFFSET from the beginning of the | |
175 /// .debug_info section. Its name is ATTR, its form is FORM, and its value is | |
176 /// DATA. | |
177 /// @param[in] ctx To be removed. | |
178 /// @param[in] offset The offset of this attribute in the .debug_info | |
179 /// section. | |
180 /// @param[in] parent The DIE modified by this attribute. | |
181 /// @param[in] attr The type specifier for this attribute. | |
182 /// @param[in] form The form of data that is associated with this attribute. | |
183 /// @param[in] data The actual data. | |
184 virtual void ProcessAttributeString(void *ctx, | |
185 uint64 offset, | |
186 uint64 parent, | |
187 enum DwarfAttribute attr, | |
188 enum DwarfForm form, | |
189 const char* data) = 0; | |
190 | |
191 /// Called when we define a directory. | |
192 /// @param[in] ctx Whatever was passed back by |StartCompileUnit| | |
193 /// @param[in] name The name of the directory. | |
194 /// @param[in] dir_num The directory handle. | |
195 virtual void DefineDir(void *ctx, const char *name, uint32 dir_num) = 0; | |
196 | |
197 /// Called when we define a file. | |
198 /// @param[in] ctx Whatever was passed back by |StartCompileUnit| | |
199 /// @param[in] name The file name. | |
200 /// @param[in] file_num The file handle. | |
201 /// @param[in] dir_num The file's parent directory's handle. | |
202 /// @param[in] mod_time The last time the file was modified. | |
203 /// @param[in] length The file's length. | |
204 virtual void DefineFile(void *ctx, | |
205 const char *name, | |
206 int32 file_num, | |
207 uint32 dir_num, | |
208 uint64 mod_time, | |
209 uint64 length) = 0; | |
210 | |
211 /// Called when the line info reader has a new line, address pair | |
212 /// ready for us. | |
213 /// @param[in] ctx Whatever was passed back by |StartCompileUnit| | |
214 /// @param[in] address The offset of the code relative of the start of the | |
215 /// .debug_line section of the binary. | |
216 /// @param[in] length The length of its machine code in bytes. | |
217 /// @param[in] file_num The file number containing the code. | |
218 /// @param[in] line_num The line number in that file for the code. | |
219 /// @param[in] column_num The column number the code starts at if we know, | |
220 /// 0 otherwise. | |
221 virtual void AddLine(void *ctx, | |
222 uint64 address, | |
223 uint64 length, | |
224 uint32 file_num, | |
225 uint32 line_num, | |
226 uint32 column_num) = 0; | |
227 | |
228 /// Called when the location list reader has a new location list entry | |
229 /// ready for us. | |
230 /// @param[in] offset The offset of this entry from the beginning of the | |
231 /// .debug_loc section. This is used elsewhere to identify the location | |
232 /// list. | |
233 /// @param[in] is_first_entry If true, signifies that this entry is the | |
234 /// first entry in a new list. The DWARF info refers to lists by their | |
235 /// first entry, so if is_first_entry is false it's not particularly | |
236 /// important to remember the value of offset. | |
237 /// @param[in] low_pc Beginning of the range of program counter values for | |
238 /// which this location entry is valid. | |
239 /// @param[in] high_pc End of the range of program counter values for which | |
240 /// this location entry is valid. | |
241 /// @param[in] data The beginning of an array of bytes containg DWARF VM | |
242 /// instructions that can be used to decode the address encoded in this loc | |
243 /// entry. | |
244 /// @param[in] dataSize The size of the array of bytes. | |
245 virtual void AddLocListEntry(uint64 offset, | |
246 bool is_first_entry, | |
247 uint64 lowPc, | |
248 uint64 highPc, | |
249 const void* data, | |
250 size_t dataSize) = 0; | |
251 | |
252 /// Starts a new Call Frame Information entry (CFI) in the reader. Call | |
253 /// Frame information entries allow the debugger to perform manipulations on | |
254 /// the call state of the program beign debugged, for example to reproduce | |
255 /// the state of the stack at a particular point during execution. | |
256 /// @param[in] offset The offset of the CFI relative to the beginning of the | |
257 /// .eh_frame section of the binary. | |
258 /// @param[in] address The address of the call frame being modified. | |
259 /// @param[in] length The length of the CFI entry. | |
260 /// @param[in] version The version of the CFI entry (this area of the spec | |
261 /// changes) | |
262 /// @param[in] augmentation The augmentation to be performed on the call | |
263 /// frame as required by the architecture (See section 6.4.1 of the DWARF 3 | |
264 /// spec) | |
265 /// @param[in] return_address The inex of the register that holds the return | |
266 /// address from the call frame being described. | |
267 /// @return |true| if the operation was successful. | |
268 virtual bool BeginCfiEntry(size_t offset, | |
269 uint64 address, | |
270 uint64 length, | |
271 uint8 version, | |
272 const char* augmentation, | |
273 unsigned return_address) = 0; | |
274 | |
275 /// Starts a new Call Frame rule. For a description of call frame rules, | |
276 /// please read dwarf2reader.h and DWARF spec 3, section 6.4.2.3 | |
277 /// @param[in] address The address at which this Rule becomes applicable. | |
278 /// It becomes inapplicable when overridden by a rule for the same register | |
279 /// at a higher address. | |
280 /// @param[in] reg The register to which this rule applies. | |
281 /// @param[in] rule_type The type of rule (Undefined, Same Value, Offset, | |
282 /// Value Offset, Register, Expression or Value Expression) | |
283 /// @param[in] base_register If the type of the rule is any kind of offset | |
284 /// rule, then the offset is relative to the content of this register. | |
285 /// @param[in] offset The offset, to be applied as part of this rule, if an | |
286 /// offset rule. | |
287 /// @param[in] expression The expression to be used if this is an Expression | |
288 /// or a Value Expression rule. | |
289 /// @param[in] expression_length The size of the expression. | |
290 /// @return |true| of the operation was successful. | |
291 virtual bool AddCfiRule(uint64 address, | |
292 int reg, | |
293 CFI_RuleType rule_type, | |
294 int base_register, | |
295 int32 offset, | |
296 const void* expression, | |
297 uint32 expression_length) = 0; | |
298 | |
299 /// Notifies the reader that the end of a call frame information entry has | |
300 /// been reached. | |
301 /// @return |true| of the operation was successful. | |
302 virtual bool EndCfiEntry() = 0; | |
303 | |
304 /// Range List handling. | |
305 /// @param[in] offset The offset of this entry's range list from the | |
306 /// beginning of the .debug_ranges section of the binary. | |
307 /// @param[in] base_address The base address to be applied to this entry. | |
308 /// If this is 0xFFFFFFFF for 32 bit or 0xFFFFFFFFFFFFFFFF for 64 bit, then | |
309 /// the Compilation Unit's base is to be used instead. | |
310 /// @param[in] low_pc The beginning of the range described by this entry. | |
311 /// @param[in] high_pc The end of the range described by this entry. | |
312 virtual void AddRangeListEntry(uint64 offset, | |
313 uint64 base_address, | |
314 uint64 low_pc, | |
315 uint64 high_pc) = 0; | |
316 }; | |
317 | |
318 } // namespace dwarf_reader | |
319 | |
320 #endif // DWARF_READER_DWARF_READER_H_ | |
321 | |
OLD | NEW |