1 //===-- DWARFDefines.c ------------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "DWARFDefines.h"
11 #include <cstdio>
12 #include <cstring>
13 #include <string>
14 #include "lldb/Core/ConstString.h"
15
16 namespace lldb_private {
17
18 const char *
DW_TAG_value_to_name(uint32_t val)19 DW_TAG_value_to_name (uint32_t val)
20 {
21 static char invalid[100];
22
23 if (val == 0)
24 return "NULL";
25
26 const char *llvmstr = llvm::dwarf::TagString (val);
27 if (llvmstr == NULL)
28 {
29 snprintf (invalid, sizeof (invalid), "Unknown DW_TAG constant: 0x%x", val);
30 return invalid;
31 }
32 return llvmstr;
33 }
34
35 const char *
DW_CHILDREN_value_to_name(uint8_t val)36 DW_CHILDREN_value_to_name (uint8_t val)
37 {
38 static char invalid[100];
39 const char *llvmstr = llvm::dwarf::ChildrenString (val);
40 if (llvmstr == NULL)
41 {
42 snprintf (invalid, sizeof (invalid), "Unknown DW_CHILDREN constant: 0x%x", val);
43 return invalid;
44 }
45 return llvmstr;
46 }
47
48 const char *
DW_AT_value_to_name(uint32_t val)49 DW_AT_value_to_name (uint32_t val)
50 {
51 static char invalid[100];
52 const char *llvmstr = llvm::dwarf::AttributeString (val);
53 if (llvmstr == NULL)
54 {
55 snprintf (invalid, sizeof (invalid), "Unknown DW_AT constant: 0x%x", val);
56 return invalid;
57 }
58 return llvmstr;
59 }
60
61 const char *
DW_FORM_value_to_name(uint32_t val)62 DW_FORM_value_to_name (uint32_t val)
63 {
64 static char invalid[100];
65 const char *llvmstr = llvm::dwarf::FormEncodingString (val);
66 if (llvmstr == NULL)
67 {
68 snprintf (invalid, sizeof (invalid), "Unknown DW_FORM constant: 0x%x", val);
69 return invalid;
70 }
71 return llvmstr;
72 }
73
74 const char *
DW_OP_value_to_name(uint32_t val)75 DW_OP_value_to_name (uint32_t val)
76 {
77 static char invalid[100];
78 const char *llvmstr = llvm::dwarf::OperationEncodingString (val);
79 if (llvmstr == NULL)
80 {
81 snprintf (invalid, sizeof (invalid), "Unknown DW_OP constant: 0x%x", val);
82 return invalid;
83 }
84 return llvmstr;
85 }
86
87 DRC_class
DW_OP_value_to_class(uint32_t val)88 DW_OP_value_to_class (uint32_t val)
89 {
90 switch (val) {
91 case 0x03: return DRC_ONEOPERAND;
92 case 0x06: return DRC_ZEROOPERANDS;
93 case 0x08: return DRC_ONEOPERAND;
94 case 0x09: return DRC_ONEOPERAND;
95 case 0x0a: return DRC_ONEOPERAND;
96 case 0x0b: return DRC_ONEOPERAND;
97 case 0x0c: return DRC_ONEOPERAND;
98 case 0x0d: return DRC_ONEOPERAND;
99 case 0x0e: return DRC_ONEOPERAND;
100 case 0x0f: return DRC_ONEOPERAND;
101 case 0x10: return DRC_ONEOPERAND;
102 case 0x11: return DRC_ONEOPERAND;
103 case 0x12: return DRC_ZEROOPERANDS;
104 case 0x13: return DRC_ZEROOPERANDS;
105 case 0x14: return DRC_ZEROOPERANDS;
106 case 0x15: return DRC_ONEOPERAND;
107 case 0x16: return DRC_ZEROOPERANDS;
108 case 0x17: return DRC_ZEROOPERANDS;
109 case 0x18: return DRC_ZEROOPERANDS;
110 case 0x19: return DRC_ZEROOPERANDS;
111 case 0x1a: return DRC_ZEROOPERANDS;
112 case 0x1b: return DRC_ZEROOPERANDS;
113 case 0x1c: return DRC_ZEROOPERANDS;
114 case 0x1d: return DRC_ZEROOPERANDS;
115 case 0x1e: return DRC_ZEROOPERANDS;
116 case 0x1f: return DRC_ZEROOPERANDS;
117 case 0x20: return DRC_ZEROOPERANDS;
118 case 0x21: return DRC_ZEROOPERANDS;
119 case 0x22: return DRC_ZEROOPERANDS;
120 case 0x23: return DRC_ONEOPERAND;
121 case 0x24: return DRC_ZEROOPERANDS;
122 case 0x25: return DRC_ZEROOPERANDS;
123 case 0x26: return DRC_ZEROOPERANDS;
124 case 0x27: return DRC_ZEROOPERANDS;
125 case 0x2f: return DRC_ONEOPERAND;
126 case 0x28: return DRC_ONEOPERAND;
127 case 0x29: return DRC_ZEROOPERANDS;
128 case 0x2a: return DRC_ZEROOPERANDS;
129 case 0x2b: return DRC_ZEROOPERANDS;
130 case 0x2c: return DRC_ZEROOPERANDS;
131 case 0x2d: return DRC_ZEROOPERANDS;
132 case 0x2e: return DRC_ZEROOPERANDS;
133 case 0x30: return DRC_ZEROOPERANDS;
134 case 0x31: return DRC_ZEROOPERANDS;
135 case 0x32: return DRC_ZEROOPERANDS;
136 case 0x33: return DRC_ZEROOPERANDS;
137 case 0x34: return DRC_ZEROOPERANDS;
138 case 0x35: return DRC_ZEROOPERANDS;
139 case 0x36: return DRC_ZEROOPERANDS;
140 case 0x37: return DRC_ZEROOPERANDS;
141 case 0x38: return DRC_ZEROOPERANDS;
142 case 0x39: return DRC_ZEROOPERANDS;
143 case 0x3a: return DRC_ZEROOPERANDS;
144 case 0x3b: return DRC_ZEROOPERANDS;
145 case 0x3c: return DRC_ZEROOPERANDS;
146 case 0x3d: return DRC_ZEROOPERANDS;
147 case 0x3e: return DRC_ZEROOPERANDS;
148 case 0x3f: return DRC_ZEROOPERANDS;
149 case 0x40: return DRC_ZEROOPERANDS;
150 case 0x41: return DRC_ZEROOPERANDS;
151 case 0x42: return DRC_ZEROOPERANDS;
152 case 0x43: return DRC_ZEROOPERANDS;
153 case 0x44: return DRC_ZEROOPERANDS;
154 case 0x45: return DRC_ZEROOPERANDS;
155 case 0x46: return DRC_ZEROOPERANDS;
156 case 0x47: return DRC_ZEROOPERANDS;
157 case 0x48: return DRC_ZEROOPERANDS;
158 case 0x49: return DRC_ZEROOPERANDS;
159 case 0x4a: return DRC_ZEROOPERANDS;
160 case 0x4b: return DRC_ZEROOPERANDS;
161 case 0x4c: return DRC_ZEROOPERANDS;
162 case 0x4d: return DRC_ZEROOPERANDS;
163 case 0x4e: return DRC_ZEROOPERANDS;
164 case 0x4f: return DRC_ZEROOPERANDS;
165 case 0x50: return DRC_ZEROOPERANDS;
166 case 0x51: return DRC_ZEROOPERANDS;
167 case 0x52: return DRC_ZEROOPERANDS;
168 case 0x53: return DRC_ZEROOPERANDS;
169 case 0x54: return DRC_ZEROOPERANDS;
170 case 0x55: return DRC_ZEROOPERANDS;
171 case 0x56: return DRC_ZEROOPERANDS;
172 case 0x57: return DRC_ZEROOPERANDS;
173 case 0x58: return DRC_ZEROOPERANDS;
174 case 0x59: return DRC_ZEROOPERANDS;
175 case 0x5a: return DRC_ZEROOPERANDS;
176 case 0x5b: return DRC_ZEROOPERANDS;
177 case 0x5c: return DRC_ZEROOPERANDS;
178 case 0x5d: return DRC_ZEROOPERANDS;
179 case 0x5e: return DRC_ZEROOPERANDS;
180 case 0x5f: return DRC_ZEROOPERANDS;
181 case 0x60: return DRC_ZEROOPERANDS;
182 case 0x61: return DRC_ZEROOPERANDS;
183 case 0x62: return DRC_ZEROOPERANDS;
184 case 0x63: return DRC_ZEROOPERANDS;
185 case 0x64: return DRC_ZEROOPERANDS;
186 case 0x65: return DRC_ZEROOPERANDS;
187 case 0x66: return DRC_ZEROOPERANDS;
188 case 0x67: return DRC_ZEROOPERANDS;
189 case 0x68: return DRC_ZEROOPERANDS;
190 case 0x69: return DRC_ZEROOPERANDS;
191 case 0x6a: return DRC_ZEROOPERANDS;
192 case 0x6b: return DRC_ZEROOPERANDS;
193 case 0x6c: return DRC_ZEROOPERANDS;
194 case 0x6d: return DRC_ZEROOPERANDS;
195 case 0x6e: return DRC_ZEROOPERANDS;
196 case 0x6f: return DRC_ZEROOPERANDS;
197 case 0x70: return DRC_ONEOPERAND;
198 case 0x71: return DRC_ONEOPERAND;
199 case 0x72: return DRC_ONEOPERAND;
200 case 0x73: return DRC_ONEOPERAND;
201 case 0x74: return DRC_ONEOPERAND;
202 case 0x75: return DRC_ONEOPERAND;
203 case 0x76: return DRC_ONEOPERAND;
204 case 0x77: return DRC_ONEOPERAND;
205 case 0x78: return DRC_ONEOPERAND;
206 case 0x79: return DRC_ONEOPERAND;
207 case 0x7a: return DRC_ONEOPERAND;
208 case 0x7b: return DRC_ONEOPERAND;
209 case 0x7c: return DRC_ONEOPERAND;
210 case 0x7d: return DRC_ONEOPERAND;
211 case 0x7e: return DRC_ONEOPERAND;
212 case 0x7f: return DRC_ONEOPERAND;
213 case 0x80: return DRC_ONEOPERAND;
214 case 0x81: return DRC_ONEOPERAND;
215 case 0x82: return DRC_ONEOPERAND;
216 case 0x83: return DRC_ONEOPERAND;
217 case 0x84: return DRC_ONEOPERAND;
218 case 0x85: return DRC_ONEOPERAND;
219 case 0x86: return DRC_ONEOPERAND;
220 case 0x87: return DRC_ONEOPERAND;
221 case 0x88: return DRC_ONEOPERAND;
222 case 0x89: return DRC_ONEOPERAND;
223 case 0x8a: return DRC_ONEOPERAND;
224 case 0x8b: return DRC_ONEOPERAND;
225 case 0x8c: return DRC_ONEOPERAND;
226 case 0x8d: return DRC_ONEOPERAND;
227 case 0x8e: return DRC_ONEOPERAND;
228 case 0x8f: return DRC_ONEOPERAND;
229 case 0x90: return DRC_ONEOPERAND;
230 case 0x91: return DRC_ONEOPERAND;
231 case 0x92: return DRC_TWOOPERANDS;
232 case 0x93: return DRC_ONEOPERAND;
233 case 0x94: return DRC_ONEOPERAND;
234 case 0x95: return DRC_ONEOPERAND;
235 case 0x96: return DRC_ZEROOPERANDS;
236 case 0x97: return DRC_DWARFv3 | DRC_ZEROOPERANDS;
237 case 0x98: return DRC_DWARFv3 | DRC_ONEOPERAND;
238 case 0x99: return DRC_DWARFv3 | DRC_ONEOPERAND;
239 case 0x9a: return DRC_DWARFv3 | DRC_ONEOPERAND;
240 case 0xf0: return DRC_ZEROOPERANDS; /* DW_OP_APPLE_uninit */
241 case 0xe0: return 0;
242 case 0xff: return 0;
243 default: return 0;
244 }
245 }
246
247 const char *
DW_ATE_value_to_name(uint32_t val)248 DW_ATE_value_to_name (uint32_t val)
249 {
250 static char invalid[100];
251 const char *llvmstr = llvm::dwarf::AttributeEncodingString (val);
252 if (llvmstr == NULL)
253 {
254 snprintf (invalid, sizeof (invalid), "Unknown DW_ATE constant: 0x%x", val);
255 return invalid;
256 }
257 return llvmstr;
258 }
259
260 const char *
DW_ACCESS_value_to_name(uint32_t val)261 DW_ACCESS_value_to_name (uint32_t val)
262 {
263 static char invalid[100];
264
265 const char *llvmstr = llvm::dwarf::AccessibilityString (val);
266 if (llvmstr == NULL)
267 {
268 snprintf (invalid, sizeof (invalid), "Unknown DW_ACCESS constant: 0x%x", val);
269 return invalid;
270 }
271 return llvmstr;
272 }
273
274 const char *
DW_VIS_value_to_name(uint32_t val)275 DW_VIS_value_to_name (uint32_t val)
276 {
277 static char invalid[100];
278 const char *llvmstr = llvm::dwarf::VisibilityString (val);
279 if (llvmstr == NULL)
280 {
281 snprintf (invalid, sizeof (invalid), "Unknown DW_VIS constant: 0x%x", val);
282 return invalid;
283 }
284 return llvmstr;
285 }
286
287 const char *
DW_VIRTUALITY_value_to_name(uint32_t val)288 DW_VIRTUALITY_value_to_name (uint32_t val)
289 {
290 static char invalid[100];
291 const char *llvmstr = llvm::dwarf::VirtualityString (val);
292 if (llvmstr == NULL)
293 {
294 snprintf (invalid, sizeof (invalid), "Unknown DW_VIRTUALITY constant: 0x%x", val);
295 return invalid;
296 }
297 return llvmstr;
298 }
299
300 const char *
DW_LANG_value_to_name(uint32_t val)301 DW_LANG_value_to_name (uint32_t val)
302 {
303 static char invalid[100];
304 const char *llvmstr = llvm::dwarf::LanguageString (val);
305 if (llvmstr == NULL)
306 {
307 snprintf (invalid, sizeof (invalid), "Unknown DW_LANG constant: 0x%x", val);
308 return invalid;
309 }
310 return llvmstr;
311 }
312
313 const char *
DW_ID_value_to_name(uint32_t val)314 DW_ID_value_to_name (uint32_t val)
315 {
316 static char invalid[100];
317 const char *llvmstr = llvm::dwarf::CaseString (val);
318 if (llvmstr == NULL)
319 {
320 snprintf (invalid, sizeof (invalid), "Unknown DW_ID constant: 0x%x", val);
321 return invalid;
322 }
323 return llvmstr;
324 }
325
326 const char *
DW_CC_value_to_name(uint32_t val)327 DW_CC_value_to_name (uint32_t val)
328 {
329 static char invalid[100];
330 const char *llvmstr = llvm::dwarf::ConventionString (val);
331 if (llvmstr == NULL)
332 {
333 snprintf (invalid, sizeof (invalid), "Unknown DW_CC constant: 0x%x", val);
334 return invalid;
335 }
336 return llvmstr;
337 }
338
339 const char *
DW_INL_value_to_name(uint32_t val)340 DW_INL_value_to_name (uint32_t val)
341 {
342 static char invalid[100];
343 const char *llvmstr = llvm::dwarf::InlineCodeString (val);
344 if (llvmstr == NULL)
345 {
346 snprintf (invalid, sizeof (invalid), "Unknown DW_INL constant: 0x%x", val);
347 return invalid;
348 }
349 return llvmstr;
350 }
351
352 const char *
DW_ORD_value_to_name(uint32_t val)353 DW_ORD_value_to_name (uint32_t val)
354 {
355 static char invalid[100];
356 const char *llvmstr = llvm::dwarf::ArrayOrderString (val);
357 if (llvmstr == NULL)
358 {
359 snprintf (invalid, sizeof (invalid), "Unknown DW_ORD constant: 0x%x", val);
360 return invalid;
361 }
362 return llvmstr;
363 }
364
365 const char *
DW_DSC_value_to_name(uint32_t val)366 DW_DSC_value_to_name (uint32_t val)
367 {
368 static char invalid[100];
369 const char *llvmstr = llvm::dwarf::DiscriminantString (val);
370 if (llvmstr == NULL)
371 {
372 snprintf (invalid, sizeof (invalid), "Unknown DW_DSC constant: 0x%x", val);
373 return invalid;
374 }
375 return llvmstr;
376 }
377
378 const char *
DW_LNS_value_to_name(uint32_t val)379 DW_LNS_value_to_name (uint32_t val)
380 {
381 static char invalid[100];
382 const char *llvmstr = llvm::dwarf::LNStandardString (val);
383 if (llvmstr == NULL)
384 {
385 snprintf (invalid, sizeof (invalid), "Unknown DW_LNS constant: 0x%x", val);
386 return invalid;
387 }
388 return llvmstr;
389 }
390
391 const char *
DW_LNE_value_to_name(uint32_t val)392 DW_LNE_value_to_name (uint32_t val)
393 {
394 static char invalid[100];
395 const char *llvmstr = llvm::dwarf::LNExtendedString (val);
396 if (llvmstr == NULL)
397 {
398 snprintf (invalid, sizeof (invalid), "Unknown DW_LNE constant: 0x%x", val);
399 return invalid;
400 }
401 return llvmstr;
402 }
403
404 const char *
DW_MACINFO_value_to_name(uint32_t val)405 DW_MACINFO_value_to_name (uint32_t val)
406 {
407 static char invalid[100];
408 const char *llvmstr = llvm::dwarf::MacinfoString (val);
409 if (llvmstr == NULL)
410 {
411 snprintf (invalid, sizeof (invalid), "Unknown DW_MACINFO constant: 0x%x", val);
412 return invalid;
413 }
414 return llvmstr;
415 }
416
417 const char *
DW_CFA_value_to_name(uint32_t val)418 DW_CFA_value_to_name (uint32_t val)
419 {
420 static char invalid[100];
421 const char *llvmstr = llvm::dwarf::CallFrameString (val);
422 if (llvmstr == NULL)
423 {
424 snprintf (invalid, sizeof (invalid), "Unknown DW_CFA constant: 0x%x", val);
425 return invalid;
426 }
427 return llvmstr;
428 }
429
430 DW_TAG_CategoryEnum
get_tag_category(uint16_t tag)431 get_tag_category (uint16_t tag)
432 {
433 switch (tag)
434 {
435 case DW_TAG_array_type : return TagCategoryType;
436 case DW_TAG_class_type : return TagCategoryType;
437 case DW_TAG_entry_point : return TagCategoryProgram;
438 case DW_TAG_enumeration_type : return TagCategoryType;
439 case DW_TAG_formal_parameter : return TagCategoryVariable;
440 case DW_TAG_imported_declaration : return TagCategoryProgram;
441 case DW_TAG_label : return TagCategoryProgram;
442 case DW_TAG_lexical_block : return TagCategoryProgram;
443 case DW_TAG_member : return TagCategoryType;
444 case DW_TAG_pointer_type : return TagCategoryType;
445 case DW_TAG_reference_type : return TagCategoryType;
446 case DW_TAG_compile_unit : return TagCategoryProgram;
447 case DW_TAG_string_type : return TagCategoryType;
448 case DW_TAG_structure_type : return TagCategoryType;
449 case DW_TAG_subroutine_type : return TagCategoryType;
450 case DW_TAG_typedef : return TagCategoryType;
451 case DW_TAG_union_type : return TagCategoryType;
452 case DW_TAG_unspecified_parameters : return TagCategoryVariable;
453 case DW_TAG_variant : return TagCategoryType;
454 case DW_TAG_common_block : return TagCategoryProgram;
455 case DW_TAG_common_inclusion : return TagCategoryProgram;
456 case DW_TAG_inheritance : return TagCategoryType;
457 case DW_TAG_inlined_subroutine : return TagCategoryProgram;
458 case DW_TAG_module : return TagCategoryProgram;
459 case DW_TAG_ptr_to_member_type : return TagCategoryType;
460 case DW_TAG_set_type : return TagCategoryType;
461 case DW_TAG_subrange_type : return TagCategoryType;
462 case DW_TAG_with_stmt : return TagCategoryProgram;
463 case DW_TAG_access_declaration : return TagCategoryProgram;
464 case DW_TAG_base_type : return TagCategoryType;
465 case DW_TAG_catch_block : return TagCategoryProgram;
466 case DW_TAG_const_type : return TagCategoryType;
467 case DW_TAG_constant : return TagCategoryVariable;
468 case DW_TAG_enumerator : return TagCategoryType;
469 case DW_TAG_file_type : return TagCategoryType;
470 case DW_TAG_friend : return TagCategoryType;
471 case DW_TAG_namelist : return TagCategoryVariable;
472 case DW_TAG_namelist_item : return TagCategoryVariable;
473 case DW_TAG_packed_type : return TagCategoryType;
474 case DW_TAG_subprogram : return TagCategoryProgram;
475 case DW_TAG_template_type_parameter : return TagCategoryType;
476 case DW_TAG_template_value_parameter : return TagCategoryType;
477 case DW_TAG_thrown_type : return TagCategoryType;
478 case DW_TAG_try_block : return TagCategoryProgram;
479 case DW_TAG_variant_part : return TagCategoryType;
480 case DW_TAG_variable : return TagCategoryVariable;
481 case DW_TAG_volatile_type : return TagCategoryType;
482 case DW_TAG_dwarf_procedure : return TagCategoryProgram;
483 case DW_TAG_restrict_type : return TagCategoryType;
484 case DW_TAG_interface_type : return TagCategoryType;
485 case DW_TAG_namespace : return TagCategoryProgram;
486 case DW_TAG_imported_module : return TagCategoryProgram;
487 case DW_TAG_unspecified_type : return TagCategoryType;
488 case DW_TAG_partial_unit : return TagCategoryProgram;
489 case DW_TAG_imported_unit : return TagCategoryProgram;
490 case DW_TAG_shared_type : return TagCategoryType;
491 default: break;
492 }
493 return TagCategoryProgram;
494 }
495
496 } // namespace lldb_private
497
498