1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013-2014, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6
7 #include "DebugInfoEntries.h"
8
9 #include <new>
10
11 #include "AttributeValue.h"
12 #include "Dwarf.h"
13
14
15 #define DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(name) \
16 status_t \
17 DebugInfoEntry::AddAttribute_##name(uint16 attributeName, \
18 const AttributeValue& value) \
19 { \
20 return ATTRIBUTE_NOT_HANDLED; \
21 }
22
23
DebugInfoEntry()24 DebugInfoEntry::DebugInfoEntry()
25 :
26 fParent(NULL)
27 {
28 }
29
30
~DebugInfoEntry()31 DebugInfoEntry::~DebugInfoEntry()
32 {
33 }
34
35
36 status_t
InitAfterHierarchy(DebugInfoEntryInitInfo & info)37 DebugInfoEntry::InitAfterHierarchy(DebugInfoEntryInitInfo& info)
38 {
39 return B_OK;
40 }
41
42
43 status_t
InitAfterAttributes(DebugInfoEntryInitInfo & info)44 DebugInfoEntry::InitAfterAttributes(DebugInfoEntryInitInfo& info)
45 {
46 return B_OK;
47 }
48
49
50 void
SetParent(DebugInfoEntry * parent)51 DebugInfoEntry::SetParent(DebugInfoEntry* parent)
52 {
53 fParent = parent;
54 }
55
56
57 bool
IsType() const58 DebugInfoEntry::IsType() const
59 {
60 return false;
61 }
62
63
64 bool
IsNamespace() const65 DebugInfoEntry::IsNamespace() const
66 {
67 return false;
68 }
69
70
71 const char*
Name() const72 DebugInfoEntry::Name() const
73 {
74 return NULL;
75 }
76
77 const char*
Description() const78 DebugInfoEntry::Description() const
79 {
80 return NULL;
81 }
82
83
84 DebugInfoEntry*
Specification() const85 DebugInfoEntry::Specification() const
86 {
87 return NULL;
88 }
89
90
91 DebugInfoEntry*
AbstractOrigin() const92 DebugInfoEntry::AbstractOrigin() const
93 {
94 return NULL;
95 }
96
97
98 DebugInfoEntry*
SignatureType() const99 DebugInfoEntry::SignatureType() const
100 {
101 return NULL;
102 }
103
104
105 LocationDescription*
GetLocationDescription()106 DebugInfoEntry::GetLocationDescription()
107 {
108 return NULL;
109 }
110
111
112 bool
GetDeclarationFile(uint32 & _file) const113 DebugInfoEntry::GetDeclarationFile(uint32& _file) const
114 {
115 DeclarationLocation* location = const_cast<DebugInfoEntry*>(this)
116 ->GetDeclarationLocation();
117 if (location == NULL || !location->IsFileSet())
118 return false;
119
120 _file = location->file;
121 return true;
122 }
123
124
125 bool
GetDeclarationLine(uint32 & _line) const126 DebugInfoEntry::GetDeclarationLine(uint32& _line) const
127 {
128 DeclarationLocation* location = const_cast<DebugInfoEntry*>(this)
129 ->GetDeclarationLocation();
130 if (location == NULL || !location->IsLineSet())
131 return false;
132
133 _line = location->line;
134 return true;
135 }
136
137
138 bool
GetDeclarationColumn(uint32 & _column) const139 DebugInfoEntry::GetDeclarationColumn(uint32& _column) const
140 {
141 DeclarationLocation* location = const_cast<DebugInfoEntry*>(this)
142 ->GetDeclarationLocation();
143 if (location == NULL || !location->IsColumnSet())
144 return false;
145
146 _column = location->column;
147 return true;
148 }
149
150
151 status_t
AddChild(DebugInfoEntry * child)152 DebugInfoEntry::AddChild(DebugInfoEntry* child)
153 {
154 // ignore children where we don't expect them
155 return ENTRY_NOT_HANDLED;
156 }
157
158
159 status_t
AddAttribute_decl_file(uint16 attributeName,const AttributeValue & value)160 DebugInfoEntry::AddAttribute_decl_file(uint16 attributeName,
161 const AttributeValue& value)
162 {
163 if (DeclarationLocation* location = GetDeclarationLocation()) {
164 location->SetFile(value.constant);
165 return B_OK;
166 }
167
168 return ATTRIBUTE_NOT_HANDLED;
169 }
170
171
172 status_t
AddAttribute_decl_line(uint16 attributeName,const AttributeValue & value)173 DebugInfoEntry::AddAttribute_decl_line(uint16 attributeName,
174 const AttributeValue& value)
175 {
176 if (DeclarationLocation* location = GetDeclarationLocation()) {
177 location->SetLine(value.constant);
178 return B_OK;
179 }
180
181 return ATTRIBUTE_NOT_HANDLED;
182 }
183
184
185 status_t
AddAttribute_decl_column(uint16 attributeName,const AttributeValue & value)186 DebugInfoEntry::AddAttribute_decl_column(uint16 attributeName,
187 const AttributeValue& value)
188 {
189 if (DeclarationLocation* location = GetDeclarationLocation()) {
190 location->SetColumn(value.constant);
191 return B_OK;
192 }
193
194 return ATTRIBUTE_NOT_HANDLED;
195 }
196
197
198 status_t
AddAttribute_location(uint16 attributeName,const AttributeValue & value)199 DebugInfoEntry::AddAttribute_location(uint16 attributeName,
200 const AttributeValue& value)
201 {
202 if (LocationDescription* location = GetLocationDescription()) {
203 if (value.attributeClass == ATTRIBUTE_CLASS_LOCLIST) {
204 location->SetToLocationList(value.pointer);
205 return B_OK;
206 }
207
208 if (value.attributeClass == ATTRIBUTE_CLASS_BLOCK) {
209 location->SetToExpression(value.block.data, value.block.length);
210 return B_OK;
211 }
212 return B_BAD_DATA;
213 }
214
215 return ATTRIBUTE_NOT_HANDLED;
216 }
217
218
219 status_t
AddAttribute_sibling(uint16 attributeName,const AttributeValue & value)220 DebugInfoEntry::AddAttribute_sibling(uint16 attributeName,
221 const AttributeValue& value)
222 {
223 // This attribute is only intended to help the debug info consumer. We don't
224 // need it.
225 return B_OK;
226 }
227
228
229 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(name)
DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(ordering)230 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(ordering)
231 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(byte_size)
232 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(bit_offset)
233 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(bit_size)
234 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(stmt_list)
235 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(low_pc)
236 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(high_pc)
237 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(language)
238 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(discr)
239 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(discr_value)
240 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(visibility)
241 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(import)
242 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(string_length)
243 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(common_reference)
244 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(comp_dir)
245 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(const_value)
246 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(containing_type)
247 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(default_value)
248 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(inline)
249 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(is_optional)
250 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(lower_bound)
251 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(producer)
252 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(prototyped)
253 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(return_addr)
254 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(start_scope)
255 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(bit_stride)
256 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(upper_bound)
257 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(abstract_origin)
258 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(accessibility)
259 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(address_class)
260 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(artificial)
261 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(base_types)
262 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(calling_convention)
263 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(count)
264 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(data_member_location)
265 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(declaration)
266 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(discr_list)
267 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(encoding)
268 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(external)
269 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(frame_base)
270 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(friend)
271 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(identifier_case)
272 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(macro_info)
273 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(namelist_item)
274 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(priority)
275 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(segment)
276 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(specification)
277 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(static_link)
278 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(type)
279 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(use_location)
280 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(variable_parameter)
281 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(virtuality)
282 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(vtable_elem_location)
283 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(allocated)
284 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(associated)
285 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(data_location)
286 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(byte_stride)
287 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(entry_pc)
288 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(use_UTF8)
289 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(extension)
290 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(ranges)
291 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(trampoline)
292 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_column)
293 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_file)
294 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_line)
295 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(description)
296 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(binary_scale)
297 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(decimal_scale)
298 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(small)
299 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(decimal_sign)
300 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(digit_count)
301 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(picture_string)
302 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(mutable)
303 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(threads_scaled)
304 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(explicit)
305 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(object_pointer)
306 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(endianity)
307 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(elemental)
308 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(pure)
309 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(recursive)
310 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(signature)
311 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(main_subprogram)
312 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(data_bit_offset)
313 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(const_expr)
314 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(enum_class)
315 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(linkage_name)
316 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(string_length_bit_size)
317 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(string_length_byte_size)
318 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(rank)
319 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(str_offsets_base)
320 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(addr_base)
321 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(rnglists_base)
322 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(dwo_name)
323 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(reference)
324 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(rvalue_reference)
325 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(macros)
326 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_all_calls)
327 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_all_source_calls)
328 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_all_tail_calls)
329 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_return_pc)
330 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_value)
331 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_origin)
332 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_parameter)
333 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_pc)
334 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_tail_call)
335 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_target)
336 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_target_clobbered)
337 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_data_location)
338 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_data_value)
339 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(noreturn)
340 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(alignment)
341 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(export_symbols)
342 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(deleted)
343 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(defaulted)
344 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(loclists_base)
345 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_site_value)
346 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_site_data_value)
347 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_site_target)
348 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(call_site_target_clobbered)
349 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(tail_call)
350 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(all_tail_call_sites)
351 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(all_call_sites)
352 DEFINE_DEBUG_INFO_ENTRY_ATTR_SETTER(all_source_call_sites)
353
354
355 DeclarationLocation*
356 DebugInfoEntry::GetDeclarationLocation()
357 {
358 return NULL;
359 }
360
361
362 status_t
SetDynamicAttributeValue(DynamicAttributeValue & toSet,const AttributeValue & value)363 DebugInfoEntry::SetDynamicAttributeValue(DynamicAttributeValue& toSet,
364 const AttributeValue& value)
365 {
366 switch (value.attributeClass) {
367 case ATTRIBUTE_CLASS_CONSTANT:
368 toSet.SetTo(value.constant);
369 return B_OK;
370 case ATTRIBUTE_CLASS_REFERENCE:
371 toSet.SetTo(value.reference);
372 return B_OK;
373 case ATTRIBUTE_CLASS_BLOCK:
374 toSet.SetTo(value.block.data, value.block.length);
375 return B_OK;
376 default:
377 return B_BAD_DATA;
378 }
379 }
380
381
382 status_t
SetConstantAttributeValue(ConstantAttributeValue & toSet,const AttributeValue & value)383 DebugInfoEntry::SetConstantAttributeValue(ConstantAttributeValue& toSet,
384 const AttributeValue& value)
385 {
386 switch (value.attributeClass) {
387 case ATTRIBUTE_CLASS_CONSTANT:
388 toSet.SetTo(value.constant);
389 return B_OK;
390 case ATTRIBUTE_CLASS_STRING:
391 toSet.SetTo(value.string);
392 return B_OK;
393 case ATTRIBUTE_CLASS_BLOCK:
394 toSet.SetTo(value.block.data, value.block.length);
395 return B_OK;
396 default:
397 return B_BAD_DATA;
398 }
399 }
400
401
402 status_t
SetMemberLocation(MemberLocation & toSet,const AttributeValue & value)403 DebugInfoEntry::SetMemberLocation(MemberLocation& toSet,
404 const AttributeValue& value)
405 {
406 switch (value.attributeClass) {
407 case ATTRIBUTE_CLASS_CONSTANT:
408 toSet.SetToConstant(value.constant);
409 return B_OK;
410 case ATTRIBUTE_CLASS_BLOCK:
411 toSet.SetToExpression(value.block.data, value.block.length);
412 return B_OK;
413 case ATTRIBUTE_CLASS_LOCLIST:
414 toSet.SetToLocationList(value.pointer);
415 return B_OK;
416 default:
417 return B_BAD_DATA;
418 }
419 }
420