LLVM  4.0.0
Dwarf.cpp
Go to the documentation of this file.
1 //===-- llvm/Support/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 
14 #include "llvm/Support/Dwarf.h"
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) \
26  case DW_TAG_##NAME: \
27  return "DW_TAG_" #NAME;
28 #include "llvm/Support/Dwarf.def"
29  }
30 }
31 
34 #define HANDLE_DW_TAG(ID, NAME) .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
35 #include "llvm/Support/Dwarf.def"
36  .Default(DW_TAG_invalid);
37 }
38 
40  switch (Children) {
41  case DW_CHILDREN_no: return "DW_CHILDREN_no";
42  case DW_CHILDREN_yes: return "DW_CHILDREN_yes";
43  }
44  return StringRef();
45 }
46 
48  switch (Attribute) {
49  default:
50  return StringRef();
51 #define HANDLE_DW_AT(ID, NAME) \
52  case DW_AT_##NAME: \
53  return "DW_AT_" #NAME;
54 #include "llvm/Support/Dwarf.def"
55  }
56 }
57 
59  switch (Encoding) {
60  default:
61  return StringRef();
62 #define HANDLE_DW_FORM(ID, NAME) \
63  case DW_FORM_##NAME: \
64  return "DW_FORM_" #NAME;
65 #include "llvm/Support/Dwarf.def"
66  }
67 }
68 
70  switch (Encoding) {
71  default:
72  return StringRef();
73 #define HANDLE_DW_OP(ID, NAME) \
74  case DW_OP_##NAME: \
75  return "DW_OP_" #NAME;
76 #include "llvm/Support/Dwarf.def"
78  return "DW_OP_LLVM_fragment";
79  }
80 }
81 
84 #define HANDLE_DW_OP(ID, NAME) .Case("DW_OP_" #NAME, DW_OP_##NAME)
85 #include "llvm/Support/Dwarf.def"
86  .Case("DW_OP_LLVM_fragment", DW_OP_LLVM_fragment)
87  .Default(0);
88 }
89 
91  switch (Encoding) {
92  default:
93  return StringRef();
94 #define HANDLE_DW_ATE(ID, NAME) \
95  case DW_ATE_##NAME: \
96  return "DW_ATE_" #NAME;
97 #include "llvm/Support/Dwarf.def"
98  }
99 }
100 
102  return StringSwitch<unsigned>(EncodingString)
103 #define HANDLE_DW_ATE(ID, NAME) .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
104 #include "llvm/Support/Dwarf.def"
105  .Default(0);
106 }
107 
109  switch (Sign) {
110  case DW_DS_unsigned: return "DW_DS_unsigned";
111  case DW_DS_leading_overpunch: return "DW_DS_leading_overpunch";
112  case DW_DS_trailing_overpunch: return "DW_DS_trailing_overpunch";
113  case DW_DS_leading_separate: return "DW_DS_leading_separate";
114  case DW_DS_trailing_separate: return "DW_DS_trailing_separate";
115  }
116  return StringRef();
117 }
118 
120  switch (Endian) {
121  case DW_END_default: return "DW_END_default";
122  case DW_END_big: return "DW_END_big";
123  case DW_END_little: return "DW_END_little";
124  case DW_END_lo_user: return "DW_END_lo_user";
125  case DW_END_hi_user: return "DW_END_hi_user";
126  }
127  return StringRef();
128 }
129 
131  switch (Access) {
132  // Accessibility codes
133  case DW_ACCESS_public: return "DW_ACCESS_public";
134  case DW_ACCESS_protected: return "DW_ACCESS_protected";
135  case DW_ACCESS_private: return "DW_ACCESS_private";
136  }
137  return StringRef();
138 }
139 
141  switch (Visibility) {
142  case DW_VIS_local: return "DW_VIS_local";
143  case DW_VIS_exported: return "DW_VIS_exported";
144  case DW_VIS_qualified: return "DW_VIS_qualified";
145  }
146  return StringRef();
147 }
148 
150  switch (Virtuality) {
151  default:
152  return StringRef();
153 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
154  case DW_VIRTUALITY_##NAME: \
155  return "DW_VIRTUALITY_" #NAME;
156 #include "llvm/Support/Dwarf.def"
157  }
158 }
159 
162 #define HANDLE_DW_VIRTUALITY(ID, NAME) \
163  .Case("DW_VIRTUALITY_" #NAME, DW_VIRTUALITY_##NAME)
164 #include "llvm/Support/Dwarf.def"
165  .Default(DW_VIRTUALITY_invalid);
166 }
167 
169  switch (Language) {
170  default:
171  return StringRef();
172 #define HANDLE_DW_LANG(ID, NAME) \
173  case DW_LANG_##NAME: \
174  return "DW_LANG_" #NAME;
175 #include "llvm/Support/Dwarf.def"
176  }
177 }
178 
181 #define HANDLE_DW_LANG(ID, NAME) .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
182 #include "llvm/Support/Dwarf.def"
183  .Default(0);
184 }
185 
187  switch (Case) {
188  case DW_ID_case_sensitive: return "DW_ID_case_sensitive";
189  case DW_ID_up_case: return "DW_ID_up_case";
190  case DW_ID_down_case: return "DW_ID_down_case";
191  case DW_ID_case_insensitive: return "DW_ID_case_insensitive";
192  }
193  return StringRef();
194 }
195 
197  switch (CC) {
198  default:
199  return StringRef();
200 #define HANDLE_DW_CC(ID, NAME) \
201  case DW_CC_##NAME: \
202  return "DW_CC_" #NAME;
203 #include "llvm/Support/Dwarf.def"
204  }
205 }
206 
208  return StringSwitch<unsigned>(CCString)
209 #define HANDLE_DW_CC(ID, NAME) .Case("DW_CC_" #NAME, DW_CC_##NAME)
210 #include "llvm/Support/Dwarf.def"
211  .Default(0);
212 }
213 
215  switch (Code) {
216  case DW_INL_not_inlined: return "DW_INL_not_inlined";
217  case DW_INL_inlined: return "DW_INL_inlined";
218  case DW_INL_declared_not_inlined: return "DW_INL_declared_not_inlined";
219  case DW_INL_declared_inlined: return "DW_INL_declared_inlined";
220  }
221  return StringRef();
222 }
223 
225  switch (Order) {
226  case DW_ORD_row_major: return "DW_ORD_row_major";
227  case DW_ORD_col_major: return "DW_ORD_col_major";
228  }
229  return StringRef();
230 }
231 
233  switch (Discriminant) {
234  case DW_DSC_label: return "DW_DSC_label";
235  case DW_DSC_range: return "DW_DSC_range";
236  }
237  return StringRef();
238 }
239 
241  switch (Standard) {
242  default:
243  return StringRef();
244 #define HANDLE_DW_LNS(ID, NAME) \
245  case DW_LNS_##NAME: \
246  return "DW_LNS_" #NAME;
247 #include "llvm/Support/Dwarf.def"
248  }
249 }
250 
252  switch (Encoding) {
253  default:
254  return StringRef();
255 #define HANDLE_DW_LNE(ID, NAME) \
256  case DW_LNE_##NAME: \
257  return "DW_LNE_" #NAME;
258 #include "llvm/Support/Dwarf.def"
259  }
260 }
261 
263  switch (Encoding) {
264  // Macinfo Type Encodings
265  case DW_MACINFO_define: return "DW_MACINFO_define";
266  case DW_MACINFO_undef: return "DW_MACINFO_undef";
267  case DW_MACINFO_start_file: return "DW_MACINFO_start_file";
268  case DW_MACINFO_end_file: return "DW_MACINFO_end_file";
269  case DW_MACINFO_vendor_ext: return "DW_MACINFO_vendor_ext";
270  case DW_MACINFO_invalid: return "DW_MACINFO_invalid";
271  }
272  return StringRef();
273 }
274 
277  .Case("DW_MACINFO_define", DW_MACINFO_define)
278  .Case("DW_MACINFO_undef", DW_MACINFO_undef)
279  .Case("DW_MACINFO_start_file", DW_MACINFO_start_file)
280  .Case("DW_MACINFO_end_file", DW_MACINFO_end_file)
281  .Case("DW_MACINFO_vendor_ext", DW_MACINFO_vendor_ext)
283 }
284 
286  switch (Encoding) {
287  default:
288  return StringRef();
289 #define HANDLE_DW_CFA(ID, NAME) \
290  case DW_CFA_##NAME: \
291  return "DW_CFA_" #NAME;
292 #include "llvm/Support/Dwarf.def"
293  }
294 }
295 
297  switch (Prop) {
298  default:
299  return StringRef();
300 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) \
301  case DW_APPLE_PROPERTY_##NAME: \
302  return "DW_APPLE_PROPERTY_" #NAME;
303 #include "llvm/Support/Dwarf.def"
304  }
305 }
306 
308  switch (AT) {
309  case dwarf::DW_ATOM_null:
310  return "DW_ATOM_null";
312  return "DW_ATOM_die_offset";
313  case DW_ATOM_cu_offset:
314  return "DW_ATOM_cu_offset";
315  case DW_ATOM_die_tag:
316  return "DW_ATOM_die_tag";
317  case DW_ATOM_type_flags:
318  return "DW_ATOM_type_flags";
319  }
320  return StringRef();
321 }
322 
324  switch (Kind) {
325  case GIEK_NONE:
326  return "NONE";
327  case GIEK_TYPE:
328  return "TYPE";
329  case GIEK_VARIABLE:
330  return "VARIABLE";
331  case GIEK_FUNCTION:
332  return "FUNCTION";
333  case GIEK_OTHER:
334  return "OTHER";
335  case GIEK_UNUSED5:
336  return "UNUSED5";
337  case GIEK_UNUSED6:
338  return "UNUSED6";
339  case GIEK_UNUSED7:
340  return "UNUSED7";
341  }
342  llvm_unreachable("Unknown GDBIndexEntryKind value");
343 }
344 
345 StringRef
347  switch (Linkage) {
348  case GIEL_EXTERNAL:
349  return "EXTERNAL";
350  case GIEL_STATIC:
351  return "STATIC";
352  }
353  llvm_unreachable("Unknown GDBIndexEntryLinkage value");
354 }
355 
356 StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
357  switch (Attr) {
358  case DW_AT_accessibility:
359  return AccessibilityString(Val);
360  case DW_AT_virtuality:
361  return VirtualityString(Val);
362  case DW_AT_language:
363  return LanguageString(Val);
364  case DW_AT_encoding:
365  return AttributeEncodingString(Val);
366  case DW_AT_decimal_sign:
367  return DecimalSignString(Val);
368  case DW_AT_endianity:
369  return EndianityString(Val);
370  case DW_AT_visibility:
371  return VisibilityString(Val);
372  case DW_AT_identifier_case:
373  return CaseString(Val);
374  case DW_AT_calling_convention:
375  return ConventionString(Val);
376  case DW_AT_inline:
377  return InlineCodeString(Val);
378  case DW_AT_ordering:
379  return ArrayOrderString(Val);
380  case DW_AT_discr_value:
381  return DiscriminantString(Val);
382  }
383 
384  return StringRef();
385 }
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:296
StringRef AtomTypeString(unsigned Atom)
Definition: Dwarf.cpp:307
Attribute
Attributes.
Definition: Dwarf.h:94
StringRef LNExtendedString(unsigned Encoding)
Definition: Dwarf.cpp:251
StringRef LNStandardString(unsigned Standard)
Definition: Dwarf.cpp:240
GDBIndexEntryKind
Definition: Dwarf.h:331
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:661
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:160
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:58
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
Only used in LLVM metadata.
Definition: Dwarf.h:112
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:47
StringRef LanguageString(unsigned Language)
Definition: Dwarf.cpp:168
StringRef DecimalSignString(unsigned Sign)
Definition: Dwarf.cpp:108
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:356
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
Definition: Dwarf.cpp:323
#define HANDLE_DW_VIRTUALITY(ID, NAME)
StringRef AccessibilityString(unsigned Access)
Definition: Dwarf.cpp:130
StringRef EndianityString(unsigned Endian)
Definition: Dwarf.cpp:119
StringRef AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:90
StringRef CallFrameString(unsigned Encoding)
Definition: Dwarf.cpp:285
#define HANDLE_DW_OP(ID, NAME)
unsigned getCallingConvention(StringRef LanguageString)
Definition: Dwarf.cpp:207
unsigned getOperationEncoding(StringRef OperationEncodingString)
Definition: Dwarf.cpp:82
StringRef DiscriminantString(unsigned Discriminant)
Definition: Dwarf.cpp:232
StringRef ArrayOrderString(unsigned Order)
Definition: Dwarf.cpp:224
#define HANDLE_DW_CC(ID, NAME)
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
Definition: Dwarf.cpp:346
unsigned getLanguage(StringRef LanguageString)
Definition: Dwarf.cpp:179
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef VirtualityString(unsigned Virtuality)
Definition: Dwarf.cpp:149
StringRef OperationEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:69
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
#define HANDLE_DW_TAG(ID, NAME)
StringRef CaseString(unsigned Case)
Definition: Dwarf.cpp:186
StringRef VisibilityString(unsigned Visibility)
Definition: Dwarf.cpp:140
#define HANDLE_DW_ATE(ID, NAME)
#define HANDLE_DW_LANG(ID, NAME)
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
StringRef InlineCodeString(unsigned Code)
Definition: Dwarf.cpp:214
StringRef ConventionString(unsigned Convention)
Definition: Dwarf.cpp:196
unsigned getMacinfo(StringRef MacinfoString)
Definition: Dwarf.cpp:275
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:39
const unsigned Kind
unsigned getAttributeEncoding(StringRef EncodingString)
Definition: Dwarf.cpp:101
GDBIndexEntryLinkage
Definition: Dwarf.h:342
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
StringRef MacinfoString(unsigned Encoding)
Definition: Dwarf.cpp:262