LLVM  6.0.0svn
Dwarf.cpp
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/Dwarf.cpp - Dwarf Framework ------------*- 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 // This file contains support for generic dwarf information.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/StringSwitch.h"
17 
18 using namespace llvm;
19 using namespace dwarf;
20 
22  switch (Tag) {
23  default:
24  return StringRef();
25 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
26  case DW_TAG_##NAME: \
27  return "DW_TAG_" #NAME;
28 #include "llvm/BinaryFormat/Dwarf.def"
29  }
30 }
31 
34 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
35  .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
36 #include "llvm/BinaryFormat/Dwarf.def"
37  .Default(DW_TAG_invalid);
38 }
39 
41  switch (Tag) {
42  default:
43  return 0;
44 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
45  case DW_TAG_##NAME: \
46  return VERSION;
47 #include "llvm/BinaryFormat/Dwarf.def"
48  }
49 }
50 
52  switch (Tag) {
53  default:
54  return 0;
55 #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) \
56  case DW_TAG_##NAME: \
57  return DWARF_VENDOR_##VENDOR;
58 #include "llvm/BinaryFormat/Dwarf.def"
59  }
60 }
61 
63  switch (Children) {
64  case DW_CHILDREN_no:
65  return "DW_CHILDREN_no";
66  case DW_CHILDREN_yes:
67  return "DW_CHILDREN_yes";
68  }
69  return StringRef();
70 }
71 
73  switch (Attribute) {
74  default:
75  return StringRef();
76 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
77  case DW_AT_##NAME: \
78  return "DW_AT_" #NAME;
79 #include "llvm/BinaryFormat/Dwarf.def"
80  }
81 }
82 
84  switch (Attribute) {
85  default:
86  return 0;
87 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
88  case DW_AT_##NAME: \
89  return VERSION;
90 #include "llvm/BinaryFormat/Dwarf.def"
91  }
92 }
93 
95  switch (Attribute) {
96  default:
97  return 0;
98 #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) \
99  case DW_AT_##NAME: \
100  return DWARF_VENDOR_##VENDOR;
101 #include "llvm/BinaryFormat/Dwarf.def"
102  }
103 }
104 
106  switch (Encoding) {
107  default:
108  return StringRef();
109 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
110  case DW_FORM_##NAME: \
111  return "DW_FORM_" #NAME;
112 #include "llvm/BinaryFormat/Dwarf.def"
113  }
114 }
115 
117  switch (Form) {
118  default:
119  return 0;
120 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
121  case DW_FORM_##NAME: \
122  return VERSION;
123 #include "llvm/BinaryFormat/Dwarf.def"
124  }
125 }
126 
128  switch (Form) {
129  default:
130  return 0;
131 #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) \
132  case DW_FORM_##NAME: \
133  return DWARF_VENDOR_##VENDOR;
134 #include "llvm/BinaryFormat/Dwarf.def"
135  }
136 }
137 
139  switch (Encoding) {
140  default:
141  return StringRef();
142 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
143  case DW_OP_##NAME: \
144  return "DW_OP_" #NAME;
145 #include "llvm/BinaryFormat/Dwarf.def"
146  case DW_OP_LLVM_fragment:
147  return "DW_OP_LLVM_fragment";
148  }
149 }
150 
153 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
154  .Case("DW_OP_" #NAME, DW_OP_##NAME)
155 #include "llvm/BinaryFormat/Dwarf.def"
156  .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment)
157  .Default(0);
158 }
159 
161  switch (Op) {
162  default:
163  return 0;
164 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
165  case DW_OP_##NAME: \
166  return VERSION;
167 #include "llvm/BinaryFormat/Dwarf.def"
168  }
169 }
170 
172  switch (Op) {
173  default:
174  return 0;
175 #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) \
176  case DW_OP_##NAME: \
177  return DWARF_VENDOR_##VENDOR;
178 #include "llvm/BinaryFormat/Dwarf.def"
179  }
180 }
181 
183  switch (Encoding) {
184  default:
185  return StringRef();
186 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
187  case DW_ATE_##NAME: \
188  return "DW_ATE_" #NAME;
189 #include "llvm/BinaryFormat/Dwarf.def"
190  }
191 }
192 
194  return StringSwitch<unsigned>(EncodingString)
195 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
196  .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
197 #include "llvm/BinaryFormat/Dwarf.def"
198  .Default(0);
199 }
200 
202  switch (ATE) {
203  default:
204  return 0;
205 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
206  case DW_ATE_##NAME: \
207  return VERSION;
208 #include "llvm/BinaryFormat/Dwarf.def"
209  }
210 }
211 
213  switch (ATE) {
214  default:
215  return 0;
216 #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) \
217  case DW_ATE_##NAME: \
218  return DWARF_VENDOR_##VENDOR;
219 #include "llvm/BinaryFormat/Dwarf.def"
220  }
221 }
222 
224  switch (Sign) {
225  case DW_DS_unsigned:
226  return "DW_DS_unsigned";
228  return "DW_DS_leading_overpunch";
230  return "DW_DS_trailing_overpunch";
232  return "DW_DS_leading_separate";
234  return "DW_DS_trailing_separate";
235  }
236  return StringRef();
237 }
238 
240  switch (Endian) {
241  case DW_END_default:
242  return "DW_END_default";
243  case DW_END_big:
244  return "DW_END_big";
245  case DW_END_little:
246  return "DW_END_little";
247  case DW_END_lo_user:
248  return "DW_END_lo_user";
249  case DW_END_hi_user:
250  return "DW_END_hi_user";
251  }
252  return StringRef();
253 }
254 
256  switch (Access) {
257  // Accessibility codes
258  case DW_ACCESS_public:
259  return "DW_ACCESS_public";
260  case DW_ACCESS_protected:
261  return "DW_ACCESS_protected";
262  case DW_ACCESS_private:
263  return "DW_ACCESS_private";
264  }
265  return StringRef();
266 }
267 
269  switch (Visibility) {
270  case DW_VIS_local:
271  return "DW_VIS_local";
272  case DW_VIS_exported:
273  return "DW_VIS_exported";
274  case DW_VIS_qualified:
275  return "DW_VIS_qualified";
276  }
277  return StringRef();
278 }
279 
281  switch (Virtuality) {
282  default:
283  return StringRef();
284 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
285  case DW_VIRTUALITY_##NAME: \
286  return "DW_VIRTUALITY_" #NAME;
287 #include "llvm/BinaryFormat/Dwarf.def"
288  }
289 }
290 
293 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
294  .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
295 #include "llvm/BinaryFormat/Dwarf.def"
296  .Default(DW_VIRTUALITY_invalid);
297 }
298 
300  switch (Language) {
301  default:
302  return StringRef();
303 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
304  case DW_LANG_##NAME: \
305  return "DW_LANG_" #NAME;
306 #include "llvm/BinaryFormat/Dwarf.def"
307  }
308 }
309 
312 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
313  .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
314 #include "llvm/BinaryFormat/Dwarf.def"
315  .Default(0);
316 }
317 
319  switch (Lang) {
320  default:
321  return 0;
322 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
323  case DW_LANG_##NAME: \
324  return VERSION;
325 #include "llvm/BinaryFormat/Dwarf.def"
326  }
327 }
328 
330  switch (Lang) {
331  default:
332  return 0;
333 #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
334  case DW_LANG_##NAME: \
335  return DWARF_VENDOR_##VENDOR;
336 #include "llvm/BinaryFormat/Dwarf.def"
337  }
338 }
339 
341  switch (Case) {
343  return "DW_ID_case_sensitive";
344  case DW_ID_up_case:
345  return "DW_ID_up_case";
346  case DW_ID_down_case:
347  return "DW_ID_down_case";
349  return "DW_ID_case_insensitive";
350  }
351  return StringRef();
352 }
353 
355  switch (CC) {
356  default:
357  return StringRef();
358 #define HANDLE_DW_CC(ID, NAME) \
359  case DW_CC_##NAME: \
360  return "DW_CC_" #NAME;
361 #include "llvm/BinaryFormat/Dwarf.def"
362  }
363 }
364 
366  return StringSwitch<unsigned>(CCString)
367 #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
368 #include "llvm/BinaryFormat/Dwarf.def"
369  .Default(0);
370 }
371 
373  switch (Code) {
374  case DW_INL_not_inlined:
375  return "DW_INL_not_inlined";
376  case DW_INL_inlined:
377  return "DW_INL_inlined";
379  return "DW_INL_declared_not_inlined";
381  return "DW_INL_declared_inlined";
382  }
383  return StringRef();
384 }
385 
387  switch (Order) {
388  case DW_ORD_row_major:
389  return "DW_ORD_row_major";
390  case DW_ORD_col_major:
391  return "DW_ORD_col_major";
392  }
393  return StringRef();
394 }
395 
397  switch (Discriminant) {
398  case DW_DSC_label:
399  return "DW_DSC_label";
400  case DW_DSC_range:
401  return "DW_DSC_range";
402  }
403  return StringRef();
404 }
405 
407  switch (Standard) {
408  default:
409  return StringRef();
410 #define HANDLE_DW_LNS(ID, NAME) \
411  case DW_LNS_##NAME: \
412  return "DW_LNS_" #NAME;
413 #include "llvm/BinaryFormat/Dwarf.def"
414  }
415 }
416 
418  switch (Encoding) {
419  default:
420  return StringRef();
421 #define HANDLE_DW_LNE(ID, NAME) \
422  case DW_LNE_##NAME: \
423  return "DW_LNE_" #NAME;
424 #include "llvm/BinaryFormat/Dwarf.def"
425  }
426 }
427 
429  switch (Encoding) {
430  // Macinfo Type Encodings
431  case DW_MACINFO_define:
432  return "DW_MACINFO_define";
433  case DW_MACINFO_undef:
434  return "DW_MACINFO_undef";
436  return "DW_MACINFO_start_file";
437  case DW_MACINFO_end_file:
438  return "DW_MACINFO_end_file";
440  return "DW_MACINFO_vendor_ext";
441  case DW_MACINFO_invalid:
442  return "DW_MACINFO_invalid";
443  }
444  return StringRef();
445 }
446 
449  .Case("DW_MACINFO_define", DW_MACINFO_define)
450  .Case("DW_MACINFO_undef", DW_MACINFO_undef)
451  .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
452  .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
453  .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
455 }
456 
458  switch (Encoding) {
459  default:
460  return StringRef();
461 #define HANDLE_DW_CFA(ID, NAME) \
462  case DW_CFA_##NAME: \
463  return "DW_CFA_" #NAME;
464 #include "llvm/BinaryFormat/Dwarf.def"
465  }
466 }
467 
469  switch (Prop) {
470  default:
471  return StringRef();
472 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
473  case DW_APPLE_PROPERTY_##NAME: \
474  return "DW_APPLE_PROPERTY_" #NAME;
475 #include "llvm/BinaryFormat/Dwarf.def"
476  }
477 }
478 
480  switch (UT) {
481  default:
482  return StringRef();
483 #define HANDLE_DW_UT(ID, NAME) \
484  case DW_UT_##NAME: \
485  return "DW_UT_" #NAME;
486 #include "llvm/BinaryFormat/Dwarf.def"
487  }
488 }
489 
491  switch (AT) {
492  case dwarf::DW_ATOM_null:
493  return "DW_ATOM_null";
495  return "DW_ATOM_die_offset";
496  case DW_ATOM_cu_offset:
497  return "DW_ATOM_cu_offset";
498  case DW_ATOM_die_tag:
499  return "DW_ATOM_die_tag";
500  case DW_ATOM_type_flags:
501  return "DW_ATOM_type_flags";
502  }
503  return StringRef();
504 }
505 
507  switch (Kind) {
508  case GIEK_NONE:
509  return "NONE";
510  case GIEK_TYPE:
511  return "TYPE";
512  case GIEK_VARIABLE:
513  return "VARIABLE";
514  case GIEK_FUNCTION:
515  return "FUNCTION";
516  case GIEK_OTHER:
517  return "OTHER";
518  case GIEK_UNUSED5:
519  return "UNUSED5";
520  case GIEK_UNUSED6:
521  return "UNUSED6";
522  case GIEK_UNUSED7:
523  return "UNUSED7";
524  }
525  llvm_unreachable("Unknown GDBIndexEntryKind value");
526 }
527 
528 StringRef
530  switch (Linkage) {
531  case GIEL_EXTERNAL:
532  return "EXTERNAL";
533  case GIEL_STATIC:
534  return "STATIC";
535  }
536  llvm_unreachable("Unknown GDBIndexEntryLinkage value");
537 }
538 
539 StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
540  switch (Attr) {
541  case DW_AT_accessibility:
542  return AccessibilityString(Val);
543  case DW_AT_virtuality:
544  return VirtualityString(Val);
545  case DW_AT_language:
546  return LanguageString(Val);
547  case DW_AT_encoding:
548  return AttributeEncodingString(Val);
549  case DW_AT_decimal_sign:
550  return DecimalSignString(Val);
551  case DW_AT_endianity:
552  return EndianityString(Val);
553  case DW_AT_visibility:
554  return VisibilityString(Val);
555  case DW_AT_identifier_case:
556  return CaseString(Val);
557  case DW_AT_calling_convention:
558  return ConventionString(Val);
559  case DW_AT_inline:
560  return InlineCodeString(Val);
561  case DW_AT_ordering:
562  return ArrayOrderString(Val);
563  case DW_AT_discr_value:
564  return DiscriminantString(Val);
565  }
566 
567  return StringRef();
568 }
569 
571  bool ExtensionsOk) {
572  if (FormVendor(F) == DWARF_VENDOR_DWARF) {
573  unsigned FV = FormVersion(F);
574  return FV > 0 && FV <= Version;
575  }
576  return ExtensionsOk;
577 }
578 
580  uint32_t H = 5381;
581  for (char C : Buffer.bytes())
582  H = ((H << 5) + H) + C;
583  return H;
584 }
#define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR)
uint64_t CallInst * C
LocationAtom
Definition: Dwarf.h:120
unsigned FormVersion(Form F)
Definition: Dwarf.cpp:116
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:468
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
StringRef AtomTypeString(unsigned Atom)
Definition: Dwarf.cpp:490
unsigned FormVendor(Form F)
Definition: Dwarf.cpp:127
#define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR)
Attribute
Attributes.
Definition: Dwarf.h:107
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:417
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:406
unsigned TagVendor(Tag T)
Definition: Dwarf.cpp:51
GDBIndexEntryKind
Definition: Dwarf.h:377
F(f)
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:735
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:291
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
#define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR)
unsigned TagVersion(Tag T)
Definition: Dwarf.cpp:40
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
unsigned AttributeVendor(Attribute A)
Definition: Dwarf.cpp:94
iterator_range< const unsigned char * > bytes() const
Definition: StringRef.h:116
Only used in LLVM metadata.
Definition: Dwarf.h:125
unsigned LanguageVendor(SourceLanguage L)
Definition: Dwarf.cpp:329
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:299
StringRef DecimalSignString(unsigned Sign)
Definition: Dwarf.cpp:223
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:539
unsigned LanguageVersion(SourceLanguage L)
Definition: Dwarf.cpp:318
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:506
#define HANDLE_DW_VIRTUALITY(ID, NAME)
StringRef AccessibilityString(unsigned Access)
Definition: Dwarf.cpp:255
StringRef EndianityString(unsigned Endian)
Definition: Dwarf.cpp:239
StringRef AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:182
StringRef CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:457
unsigned OperationVendor(LocationAtom O)
Definition: Dwarf.cpp:171
unsigned getCallingConvention(StringRef LanguageString)
Definition: Dwarf.cpp:365
SourceLanguage
Definition: Dwarf.h:179
#define H(x, y, z)
Definition: MD5.cpp:57
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:151
StringRef DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:396
StringRef ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:386
unsigned OperationVersion(LocationAtom O)
Definition: Dwarf.cpp:160
#define HANDLE_DW_CC(ID, NAME)
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:529
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:310
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:280
StringRef OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:138
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
StringRef CaseString(unsigned Case)
Definition: Dwarf.cpp:340
unsigned AttributeVersion(Attribute A)
Definition: Dwarf.cpp:83
unsigned AttributeEncodingVersion(TypeKind E)
Definition: Dwarf.cpp:201
StringRef VisibilityString(unsigned Visibility)
Definition: Dwarf.cpp:268
This file contains constants used for implementing Dwarf debug support.
StringRef UnitTypeString(unsigned)
Definition: Dwarf.cpp:479
uint32_t djbHash(StringRef Buffer)
The Bernstein hash function used by the accelerator tables.
Definition: Dwarf.cpp:579
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
unsigned AttributeEncodingVendor(TypeKind E)
Definition: Dwarf.cpp:212
StringRef InlineCodeString(unsigned Code)
Definition: Dwarf.cpp:372
StringRef ConventionString(unsigned Convention)
Definition: Dwarf.cpp:354
#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR)
unsigned getMacinfo(StringRef MacinfoString)
Definition: Dwarf.cpp:447
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:62
bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition: Dwarf.cpp:570
const unsigned Kind
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:193
GDBIndexEntryLinkage
Definition: Dwarf.h:388
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:428
const uint64_t Version
Definition: InstrProf.h:867