-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdwarfstrings.c
464 lines (393 loc) · 12.9 KB
/
dwarfstrings.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/*
Copyright (C) 2010, 2011, 2012, 2014 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
it under the terms of either
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at
your option) any later version
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at
your option) any later version
or both in parallel, as here.
elfutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see <http://www.gnu.org/licenses/>. */
#include <dwarf.h>
#include <inttypes.h>
#include <stdio.h>
#include <libintl.h>
#include "dwarfstrings.h"
const char *
dwarf_tag_string (unsigned int tag)
{
static const char *const known_tags[] =
{
[DW_TAG_array_type] = "array_type",
[DW_TAG_class_type] = "class_type",
[DW_TAG_entry_point] = "entry_point",
[DW_TAG_enumeration_type] = "enumeration_type",
[DW_TAG_formal_parameter] = "formal_parameter",
[DW_TAG_imported_declaration] = "imported_declaration",
[DW_TAG_label] = "label",
[DW_TAG_lexical_block] = "lexical_block",
[DW_TAG_member] = "member",
[DW_TAG_pointer_type] = "pointer_type",
[DW_TAG_reference_type] = "reference_type",
[DW_TAG_compile_unit] = "compile_unit",
[DW_TAG_string_type] = "string_type",
[DW_TAG_structure_type] = "structure_type",
[DW_TAG_subroutine_type] = "subroutine_type",
[DW_TAG_typedef] = "typedef",
[DW_TAG_union_type] = "union_type",
[DW_TAG_unspecified_parameters] = "unspecified_parameters",
[DW_TAG_variant] = "variant",
[DW_TAG_common_block] = "common_block",
[DW_TAG_common_inclusion] = "common_inclusion",
[DW_TAG_inheritance] = "inheritance",
[DW_TAG_inlined_subroutine] = "inlined_subroutine",
[DW_TAG_module] = "module",
[DW_TAG_ptr_to_member_type] = "ptr_to_member_type",
[DW_TAG_set_type] = "set_type",
[DW_TAG_subrange_type] = "subrange_type",
[DW_TAG_with_stmt] = "with_stmt",
[DW_TAG_access_declaration] = "access_declaration",
[DW_TAG_base_type] = "base_type",
[DW_TAG_catch_block] = "catch_block",
[DW_TAG_const_type] = "const_type",
[DW_TAG_constant] = "constant",
[DW_TAG_enumerator] = "enumerator",
[DW_TAG_file_type] = "file_type",
[DW_TAG_friend] = "friend",
[DW_TAG_namelist] = "namelist",
[DW_TAG_namelist_item] = "namelist_item",
[DW_TAG_packed_type] = "packed_type",
[DW_TAG_subprogram] = "subprogram",
[DW_TAG_template_type_parameter] = "template_type_parameter",
[DW_TAG_template_value_parameter] = "template_value_parameter",
[DW_TAG_thrown_type] = "thrown_type",
[DW_TAG_try_block] = "try_block",
[DW_TAG_variant_part] = "variant_part",
[DW_TAG_variable] = "variable",
[DW_TAG_volatile_type] = "volatile_type",
[DW_TAG_dwarf_procedure] = "dwarf_procedure",
[DW_TAG_restrict_type] = "restrict_type",
[DW_TAG_interface_type] = "interface_type",
[DW_TAG_namespace] = "namespace",
[DW_TAG_imported_module] = "imported_module",
[DW_TAG_unspecified_type] = "unspecified_type",
[DW_TAG_partial_unit] = "partial_unit",
[DW_TAG_imported_unit] = "imported_unit",
[DW_TAG_condition] = "condition",
[DW_TAG_shared_type] = "shared_type",
[DW_TAG_type_unit] = "type_unit",
[DW_TAG_rvalue_reference_type] = "rvalue_reference_type",
[DW_TAG_template_alias] = "template_alias",
};
const unsigned int nknown_tags = (sizeof (known_tags)
/ sizeof (known_tags[0]));
static char buf[40];
const char *result = NULL;
if (tag < nknown_tags)
result = known_tags[tag];
if (result == NULL)
/* There are a few known extensions. */
switch (tag)
{
case DW_TAG_MIPS_loop:
result = "MIPS_loop";
break;
case DW_TAG_format_label:
result = "format_label";
break;
case DW_TAG_function_template:
result = "function_template";
break;
case DW_TAG_class_template:
result = "class_template";
break;
case DW_TAG_GNU_BINCL:
result = "GNU_BINCL";
break;
case DW_TAG_GNU_EINCL:
result = "GNU_EINCL";
break;
case DW_TAG_GNU_template_template_param:
result = "GNU_template_template_param";
break;
case DW_TAG_GNU_template_parameter_pack:
result = "GNU_template_parameter_pack";
break;
case DW_TAG_GNU_formal_parameter_pack:
result = "GNU_formal_parameter_pack";
break;
case DW_TAG_GNU_call_site:
result = "DW_TAG_GNU_call_site";
break;
case DW_TAG_GNU_call_site_parameter:
result = "DW_TAG_GNU_call_site_parameter";
break;
default:
if (tag < DW_TAG_lo_user)
snprintf (buf, sizeof buf, gettext ("unknown tag %hx"), tag);
else
snprintf (buf, sizeof buf, gettext ("unknown user tag %hx"), tag);
result = buf;
break;
}
return result;
}
const char *
dwarf_attr_string (unsigned int attrnum)
{
static const char *const known_attrs[] =
{
[DW_AT_sibling] = "sibling",
[DW_AT_location] = "location",
[DW_AT_name] = "name",
[DW_AT_ordering] = "ordering",
[DW_AT_subscr_data] = "subscr_data",
[DW_AT_byte_size] = "byte_size",
[DW_AT_bit_offset] = "bit_offset",
[DW_AT_bit_size] = "bit_size",
[DW_AT_element_list] = "element_list",
[DW_AT_stmt_list] = "stmt_list",
[DW_AT_low_pc] = "low_pc",
[DW_AT_high_pc] = "high_pc",
[DW_AT_language] = "language",
[DW_AT_member] = "member",
[DW_AT_discr] = "discr",
[DW_AT_discr_value] = "discr_value",
[DW_AT_visibility] = "visibility",
[DW_AT_import] = "import",
[DW_AT_string_length] = "string_length",
[DW_AT_common_reference] = "common_reference",
[DW_AT_comp_dir] = "comp_dir",
[DW_AT_const_value] = "const_value",
[DW_AT_containing_type] = "containing_type",
[DW_AT_default_value] = "default_value",
[DW_AT_inline] = "inline",
[DW_AT_is_optional] = "is_optional",
[DW_AT_lower_bound] = "lower_bound",
[DW_AT_producer] = "producer",
[DW_AT_prototyped] = "prototyped",
[DW_AT_return_addr] = "return_addr",
[DW_AT_start_scope] = "start_scope",
[DW_AT_bit_stride] = "bit_stride",
[DW_AT_upper_bound] = "upper_bound",
[DW_AT_abstract_origin] = "abstract_origin",
[DW_AT_accessibility] = "accessibility",
[DW_AT_address_class] = "address_class",
[DW_AT_artificial] = "artificial",
[DW_AT_base_types] = "base_types",
[DW_AT_calling_convention] = "calling_convention",
[DW_AT_count] = "count",
[DW_AT_data_member_location] = "data_member_location",
[DW_AT_decl_column] = "decl_column",
[DW_AT_decl_file] = "decl_file",
[DW_AT_decl_line] = "decl_line",
[DW_AT_declaration] = "declaration",
[DW_AT_discr_list] = "discr_list",
[DW_AT_encoding] = "encoding",
[DW_AT_external] = "external",
[DW_AT_frame_base] = "frame_base",
[DW_AT_friend] = "friend",
[DW_AT_identifier_case] = "identifier_case",
[DW_AT_macro_info] = "macro_info",
[DW_AT_namelist_item] = "namelist_item",
[DW_AT_priority] = "priority",
[DW_AT_segment] = "segment",
[DW_AT_specification] = "specification",
[DW_AT_static_link] = "static_link",
[DW_AT_type] = "type",
[DW_AT_use_location] = "use_location",
[DW_AT_variable_parameter] = "variable_parameter",
[DW_AT_virtuality] = "virtuality",
[DW_AT_vtable_elem_location] = "vtable_elem_location",
[DW_AT_allocated] = "allocated",
[DW_AT_associated] = "associated",
[DW_AT_data_location] = "data_location",
[DW_AT_byte_stride] = "byte_stride",
[DW_AT_entry_pc] = "entry_pc",
[DW_AT_use_UTF8] = "use_UTF8",
[DW_AT_extension] = "extension",
[DW_AT_ranges] = "ranges",
[DW_AT_trampoline] = "trampoline",
[DW_AT_call_column] = "call_column",
[DW_AT_call_file] = "call_file",
[DW_AT_call_line] = "call_line",
[DW_AT_description] = "description",
[DW_AT_binary_scale] = "binary_scale",
[DW_AT_decimal_scale] = "decimal_scale",
[DW_AT_small] = "small",
[DW_AT_decimal_sign] = "decimal_sign",
[DW_AT_digit_count] = "digit_count",
[DW_AT_picture_string] = "picture_string",
[DW_AT_mutable] = "mutable",
[DW_AT_threads_scaled] = "threads_scaled",
[DW_AT_explicit] = "explicit",
[DW_AT_object_pointer] = "object_pointer",
[DW_AT_endianity] = "endianity",
[DW_AT_elemental] = "elemental",
[DW_AT_pure] = "pure",
[DW_AT_recursive] = "recursive",
[DW_AT_signature] = "signature",
[DW_AT_main_subprogram] = "main_subprogram",
[DW_AT_data_bit_offset] = "data_bit_offset",
[DW_AT_const_expr] = "const_expr",
[DW_AT_enum_class] = "enum_class",
[DW_AT_linkage_name] = "linkage_name",
};
const unsigned int nknown_attrs = (sizeof (known_attrs)
/ sizeof (known_attrs[0]));
static char buf[40];
const char *result = NULL;
if (attrnum < nknown_attrs)
result = known_attrs[attrnum];
if (result == NULL)
/* There are a few known extensions. */
switch (attrnum)
{
case DW_AT_MIPS_fde:
result = "MIPS_fde";
break;
case DW_AT_MIPS_loop_begin:
result = "MIPS_loop_begin";
break;
case DW_AT_MIPS_tail_loop_begin:
result = "MIPS_tail_loop_begin";
break;
case DW_AT_MIPS_epilog_begin:
result = "MIPS_epilog_begin";
break;
case DW_AT_MIPS_loop_unroll_factor:
result = "MIPS_loop_unroll_factor";
break;
case DW_AT_MIPS_software_pipeline_depth:
result = "MIPS_software_pipeline_depth";
break;
case DW_AT_MIPS_linkage_name:
result = "MIPS_linkage_name";
break;
case DW_AT_MIPS_stride:
result = "MIPS_stride";
break;
case DW_AT_MIPS_abstract_name:
result = "MIPS_abstract_name";
break;
case DW_AT_MIPS_clone_origin:
result = "MIPS_clone_origin";
break;
case DW_AT_MIPS_has_inlines:
result = "MIPS_has_inlines";
break;
case DW_AT_MIPS_stride_byte:
result = "MIPS_stride_byte";
break;
case DW_AT_MIPS_stride_elem:
result = "MIPS_stride_elem";
break;
case DW_AT_MIPS_ptr_dopetype:
result = "MIPS_ptr_dopetype";
break;
case DW_AT_MIPS_allocatable_dopetype:
result = "MIPS_allocatable_dopetype";
break;
case DW_AT_MIPS_assumed_shape_dopetype:
result = "MIPS_assumed_shape_dopetype";
break;
case DW_AT_MIPS_assumed_size:
result = "MIPS_assumed_size";
break;
case DW_AT_sf_names:
result = "sf_names";
break;
case DW_AT_src_info:
result = "src_info";
break;
case DW_AT_mac_info:
result = "mac_info";
break;
case DW_AT_src_coords:
result = "src_coords";
break;
case DW_AT_body_begin:
result = "body_begin";
break;
case DW_AT_body_end:
result = "body_end";
break;
case DW_AT_GNU_vector:
result = "GNU_vector";
break;
case DW_AT_GNU_guarded_by:
result = "GNU_guarded_by";
break;
case DW_AT_GNU_pt_guarded_by:
result = "GNU_pt_guarded_by";
break;
case DW_AT_GNU_guarded:
result = "GNU_guarded";
break;
case DW_AT_GNU_pt_guarded:
result = "GNU_pt_guarded";
break;
case DW_AT_GNU_locks_excluded:
result = "GNU_locks_excluded";
break;
case DW_AT_GNU_exclusive_locks_required:
result = "GNU_exclusive_locks_required";
break;
case DW_AT_GNU_shared_locks_required:
result = "GNU_shared_locks_required";
break;
case DW_AT_GNU_odr_signature:
result = "GNU_odr_signature";
break;
case DW_AT_GNU_template_name:
result = "GNU_template_name";
break;
case DW_AT_GNU_call_site_value:
result = "GNU_call_site_value";
break;
case DW_AT_GNU_call_site_data_value:
result = "GNU_call_site_data_value";
break;
case DW_AT_GNU_call_site_target:
result = "GNU_call_site_target";
break;
case DW_AT_GNU_call_site_target_clobbered:
result = "GNU_call_site_target_clobbered";
break;
case DW_AT_GNU_tail_call:
result = "GNU_tail_call";
break;
case DW_AT_GNU_all_tail_call_sites:
result = "GNU_all_tail_call_sites";
break;
case DW_AT_GNU_all_call_sites:
result = "GNU_all_call_sites";
break;
case DW_AT_GNU_all_source_call_sites:
result = "GNU_all_source_call_sites";
break;
case DW_AT_GNU_macros:
result = "GNU_macros";
break;
default:
if (attrnum < DW_AT_lo_user)
snprintf (buf, sizeof buf, gettext ("unknown attribute %hx"),
attrnum);
else
snprintf (buf, sizeof buf, gettext ("unknown user attribute %hx"),
attrnum);
result = buf;
break;
}
return result;
}