Line data Source code
1 : //===-- llvm/Support/Dwarf.h ---Dwarf Constants------------------*- 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 : // \file
11 : // \brief This file contains constants used for implementing Dwarf
12 : // debug support.
13 : //
14 : // For details on the Dwarf specfication see the latest DWARF Debugging
15 : // Information Format standard document on http://www.dwarfstd.org. This
16 : // file often includes support for non-released standard features.
17 : //
18 : //===----------------------------------------------------------------------===//
19 :
20 : #ifndef LLVM_SUPPORT_DWARF_H
21 : #define LLVM_SUPPORT_DWARF_H
22 :
23 : #include "llvm/Support/Compiler.h"
24 : #include "llvm/Support/DataTypes.h"
25 :
26 : namespace llvm {
27 : class StringRef;
28 :
29 : namespace dwarf {
30 :
31 : //===----------------------------------------------------------------------===//
32 : // DWARF constants as gleaned from the DWARF Debugging Information Format V.5
33 : // reference manual http://www.dwarfstd.org/.
34 : //
35 :
36 : // Do not mix the following two enumerations sets. DW_TAG_invalid changes the
37 : // enumeration base type.
38 :
39 : enum LLVMConstants : uint32_t {
40 : // LLVM mock tags (see also llvm/Support/Dwarf.def).
41 : DW_TAG_invalid = ~0U, // Tag for invalid results.
42 : DW_VIRTUALITY_invalid = ~0U, // Virtuality for invalid results.
43 : DW_MACINFO_invalid = ~0U, // Macinfo type for invalid results.
44 :
45 : // Other constants.
46 : DWARF_VERSION = 4, // Default dwarf version we output.
47 : DW_PUBTYPES_VERSION = 2, // Section version number for .debug_pubtypes.
48 : DW_PUBNAMES_VERSION = 2, // Section version number for .debug_pubnames.
49 : DW_ARANGES_VERSION = 2, // Section version number for .debug_aranges.
50 : // Identifiers we use to distinguish vendor extensions.
51 : DWARF_VENDOR_DWARF = 0, // Defined in v2 or later of the DWARF standard.
52 : DWARF_VENDOR_APPLE = 1,
53 : DWARF_VENDOR_BORLAND = 2,
54 : DWARF_VENDOR_GNU = 3,
55 : DWARF_VENDOR_GOOGLE = 4,
56 : DWARF_VENDOR_LLVM = 5,
57 : DWARF_VENDOR_MIPS = 6
58 : };
59 :
60 : // Special ID values that distinguish a CIE from a FDE in DWARF CFI.
61 : // Not inside an enum because a 64-bit value is needed.
62 : const uint32_t DW_CIE_ID = UINT32_MAX;
63 : const uint64_t DW64_CIE_ID = UINT64_MAX;
64 :
65 : enum Tag : uint16_t {
66 : #define HANDLE_DW_TAG(ID, NAME, VERSION, VENDOR) DW_TAG_##NAME = ID,
67 : #include "llvm/Support/Dwarf.def"
68 : DW_TAG_lo_user = 0x4080,
69 : DW_TAG_hi_user = 0xffff,
70 : DW_TAG_user_base = 0x1000 // Recommended base for user tags.
71 : };
72 :
73 171 : inline bool isType(Tag T) {
74 171 : switch (T) {
75 : case DW_TAG_array_type:
76 : case DW_TAG_class_type:
77 : case DW_TAG_interface_type:
78 : case DW_TAG_enumeration_type:
79 : case DW_TAG_pointer_type:
80 : case DW_TAG_reference_type:
81 : case DW_TAG_rvalue_reference_type:
82 : case DW_TAG_string_type:
83 : case DW_TAG_structure_type:
84 : case DW_TAG_subroutine_type:
85 : case DW_TAG_union_type:
86 : case DW_TAG_ptr_to_member_type:
87 : case DW_TAG_set_type:
88 : case DW_TAG_subrange_type:
89 : case DW_TAG_base_type:
90 : case DW_TAG_const_type:
91 : case DW_TAG_file_type:
92 : case DW_TAG_packed_type:
93 : case DW_TAG_volatile_type:
94 : case DW_TAG_typedef:
95 : return true;
96 : default:
97 111 : return false;
98 : }
99 : }
100 :
101 : /// Attributes.
102 : enum Attribute : uint16_t {
103 : #define HANDLE_DW_AT(ID, NAME, VERSION, VENDOR) DW_AT_##NAME = ID,
104 : #include "llvm/Support/Dwarf.def"
105 : DW_AT_lo_user = 0x2000,
106 : DW_AT_hi_user = 0x3fff,
107 : };
108 :
109 : enum Form : uint16_t {
110 : #define HANDLE_DW_FORM(ID, NAME, VERSION, VENDOR) DW_FORM_##NAME = ID,
111 : #include "llvm/Support/Dwarf.def"
112 : DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
113 : };
114 :
115 : enum LocationAtom {
116 : #define HANDLE_DW_OP(ID, NAME, VERSION, VENDOR) DW_OP_##NAME = ID,
117 : #include "llvm/Support/Dwarf.def"
118 : DW_OP_lo_user = 0xe0,
119 : DW_OP_hi_user = 0xff,
120 : DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
121 : };
122 :
123 : enum TypeKind {
124 : #define HANDLE_DW_ATE(ID, NAME, VERSION, VENDOR) DW_ATE_##NAME = ID,
125 : #include "llvm/Support/Dwarf.def"
126 : DW_ATE_lo_user = 0x80,
127 : DW_ATE_hi_user = 0xff
128 : };
129 :
130 : enum DecimalSignEncoding {
131 : // Decimal sign attribute values
132 : DW_DS_unsigned = 0x01,
133 : DW_DS_leading_overpunch = 0x02,
134 : DW_DS_trailing_overpunch = 0x03,
135 : DW_DS_leading_separate = 0x04,
136 : DW_DS_trailing_separate = 0x05
137 : };
138 :
139 : enum EndianityEncoding {
140 : // Endianity attribute values
141 : DW_END_default = 0x00,
142 : DW_END_big = 0x01,
143 : DW_END_little = 0x02,
144 : DW_END_lo_user = 0x40,
145 : DW_END_hi_user = 0xff
146 : };
147 :
148 : enum AccessAttribute {
149 : // Accessibility codes
150 : DW_ACCESS_public = 0x01,
151 : DW_ACCESS_protected = 0x02,
152 : DW_ACCESS_private = 0x03
153 : };
154 :
155 : enum VisibilityAttribute {
156 : // Visibility codes
157 : DW_VIS_local = 0x01,
158 : DW_VIS_exported = 0x02,
159 : DW_VIS_qualified = 0x03
160 : };
161 :
162 : enum VirtualityAttribute {
163 : #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
164 : #include "llvm/Support/Dwarf.def"
165 : DW_VIRTUALITY_max = 0x02
166 : };
167 :
168 : enum DefaultedMemberAttribute {
169 : #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
170 : #include "llvm/Support/Dwarf.def"
171 : DW_DEFAULTED_max = 0x02
172 : };
173 :
174 : enum SourceLanguage {
175 : #define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) DW_LANG_##NAME = ID,
176 : #include "llvm/Support/Dwarf.def"
177 : DW_LANG_lo_user = 0x8000,
178 : DW_LANG_hi_user = 0xffff
179 : };
180 :
181 : enum CaseSensitivity {
182 : // Identifier case codes
183 : DW_ID_case_sensitive = 0x00,
184 : DW_ID_up_case = 0x01,
185 : DW_ID_down_case = 0x02,
186 : DW_ID_case_insensitive = 0x03
187 : };
188 :
189 : enum CallingConvention {
190 : // Calling convention codes
191 : #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
192 : #include "llvm/Support/Dwarf.def"
193 : DW_CC_lo_user = 0x40,
194 : DW_CC_hi_user = 0xff
195 : };
196 :
197 : enum InlineAttribute {
198 : // Inline codes
199 : DW_INL_not_inlined = 0x00,
200 : DW_INL_inlined = 0x01,
201 : DW_INL_declared_not_inlined = 0x02,
202 : DW_INL_declared_inlined = 0x03
203 : };
204 :
205 : enum ArrayDimensionOrdering {
206 : // Array ordering
207 : DW_ORD_row_major = 0x00,
208 : DW_ORD_col_major = 0x01
209 : };
210 :
211 : enum DiscriminantList {
212 : // Discriminant descriptor values
213 : DW_DSC_label = 0x00,
214 : DW_DSC_range = 0x01
215 : };
216 :
217 : /// Line Number Standard Opcode Encodings.
218 : enum LineNumberOps : uint8_t {
219 : #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
220 : #include "llvm/Support/Dwarf.def"
221 : };
222 :
223 : /// Line Number Extended Opcode Encodings.
224 : enum LineNumberExtendedOps {
225 : #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
226 : #include "llvm/Support/Dwarf.def"
227 : DW_LNE_lo_user = 0x80,
228 : DW_LNE_hi_user = 0xff
229 : };
230 :
231 : enum LineNumberEntryFormat {
232 : #define HANDLE_DW_LNCT(ID, NAME) DW_LNCT_##NAME = ID,
233 : #include "llvm/Support/Dwarf.def"
234 : DW_LNCT_lo_user = 0x2000,
235 : DW_LNCT_hi_user = 0x3fff,
236 : };
237 :
238 : enum MacinfoRecordType {
239 : // Macinfo Type Encodings
240 : DW_MACINFO_define = 0x01,
241 : DW_MACINFO_undef = 0x02,
242 : DW_MACINFO_start_file = 0x03,
243 : DW_MACINFO_end_file = 0x04,
244 : DW_MACINFO_vendor_ext = 0xff
245 : };
246 :
247 : /// DWARF v5 macro information entry type encodings.
248 : enum MacroEntryType {
249 : #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
250 : #include "llvm/Support/Dwarf.def"
251 : DW_MACRO_lo_user = 0xe0,
252 : DW_MACRO_hi_user = 0xff
253 : };
254 :
255 : /// DWARF v5 range list entry encoding values.
256 : enum RangeListEntries {
257 : #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
258 : #include "llvm/Support/Dwarf.def"
259 : };
260 :
261 :
262 : /// Call frame instruction encodings.
263 : enum CallFrameInfo {
264 : #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
265 : #include "llvm/Support/Dwarf.def"
266 : DW_CFA_extended = 0x00,
267 :
268 : DW_CFA_lo_user = 0x1c,
269 : DW_CFA_hi_user = 0x3f
270 : };
271 :
272 : enum Constants {
273 : // Children flag
274 : DW_CHILDREN_no = 0x00,
275 : DW_CHILDREN_yes = 0x01,
276 :
277 : DW_EH_PE_absptr = 0x00,
278 : DW_EH_PE_omit = 0xff,
279 : DW_EH_PE_uleb128 = 0x01,
280 : DW_EH_PE_udata2 = 0x02,
281 : DW_EH_PE_udata4 = 0x03,
282 : DW_EH_PE_udata8 = 0x04,
283 : DW_EH_PE_sleb128 = 0x09,
284 : DW_EH_PE_sdata2 = 0x0A,
285 : DW_EH_PE_sdata4 = 0x0B,
286 : DW_EH_PE_sdata8 = 0x0C,
287 : DW_EH_PE_signed = 0x08,
288 : DW_EH_PE_pcrel = 0x10,
289 : DW_EH_PE_textrel = 0x20,
290 : DW_EH_PE_datarel = 0x30,
291 : DW_EH_PE_funcrel = 0x40,
292 : DW_EH_PE_aligned = 0x50,
293 : DW_EH_PE_indirect = 0x80
294 : };
295 :
296 : /// Constants for location lists in DWARF v5.
297 : enum LocationListEntry : unsigned char {
298 : DW_LLE_end_of_list = 0x00,
299 : DW_LLE_base_addressx = 0x01,
300 : DW_LLE_startx_endx = 0x02,
301 : DW_LLE_startx_length = 0x03,
302 : DW_LLE_offset_pair = 0x04,
303 : DW_LLE_default_location = 0x05,
304 : DW_LLE_base_address = 0x06,
305 : DW_LLE_start_end = 0x07,
306 : DW_LLE_start_length = 0x08
307 : };
308 :
309 : /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
310 : /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
311 : enum ApplePropertyAttributes {
312 : #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
313 : #include "llvm/Support/Dwarf.def"
314 : };
315 :
316 : /// Constants for unit types in DWARF v5.
317 : enum UnitType : unsigned char {
318 : #define HANDLE_DW_UT(ID, NAME) DW_UT_##NAME = ID,
319 : #include "llvm/Support/Dwarf.def"
320 : DW_UT_lo_user = 0x80,
321 : DW_UT_hi_user = 0xff
322 : };
323 :
324 : // Constants for the DWARF v5 Accelerator Table Proposal
325 : enum AcceleratorTable {
326 : // Data layout descriptors.
327 : DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
328 : DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
329 : DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
330 : // item in question.
331 : DW_ATOM_die_tag = 3u, // A tag entry.
332 : DW_ATOM_type_flags = 4u, // Set of flags for a type.
333 :
334 : // DW_ATOM_type_flags values.
335 :
336 : // Always set for C++, only set for ObjC if this is the @implementation for a
337 : // class.
338 : DW_FLAG_type_implementation = 2u,
339 :
340 : // Hash functions.
341 :
342 : // Daniel J. Bernstein hash.
343 : DW_hash_function_djb = 0u
344 : };
345 :
346 : // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
347 : enum GDBIndexEntryKind {
348 : GIEK_NONE,
349 : GIEK_TYPE,
350 : GIEK_VARIABLE,
351 : GIEK_FUNCTION,
352 : GIEK_OTHER,
353 : GIEK_UNUSED5,
354 : GIEK_UNUSED6,
355 : GIEK_UNUSED7
356 : };
357 :
358 : enum GDBIndexEntryLinkage {
359 : GIEL_EXTERNAL,
360 : GIEL_STATIC
361 : };
362 :
363 : /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
364 : ///
365 : /// All these functions map their argument's value back to the
366 : /// corresponding enumerator name or return nullptr if the value isn't
367 : /// known.
368 : ///
369 : /// @{
370 : StringRef TagString(unsigned Tag);
371 : StringRef ChildrenString(unsigned Children);
372 : StringRef AttributeString(unsigned Attribute);
373 : StringRef FormEncodingString(unsigned Encoding);
374 : StringRef OperationEncodingString(unsigned Encoding);
375 : StringRef AttributeEncodingString(unsigned Encoding);
376 : StringRef DecimalSignString(unsigned Sign);
377 : StringRef EndianityString(unsigned Endian);
378 : StringRef AccessibilityString(unsigned Access);
379 : StringRef VisibilityString(unsigned Visibility);
380 : StringRef VirtualityString(unsigned Virtuality);
381 : StringRef LanguageString(unsigned Language);
382 : StringRef CaseString(unsigned Case);
383 : StringRef ConventionString(unsigned Convention);
384 : StringRef InlineCodeString(unsigned Code);
385 : StringRef ArrayOrderString(unsigned Order);
386 : StringRef DiscriminantString(unsigned Discriminant);
387 : StringRef LNStandardString(unsigned Standard);
388 : StringRef LNExtendedString(unsigned Encoding);
389 : StringRef MacinfoString(unsigned Encoding);
390 : StringRef CallFrameString(unsigned Encoding);
391 : StringRef ApplePropertyString(unsigned);
392 : StringRef UnitTypeString(unsigned);
393 : StringRef AtomTypeString(unsigned Atom);
394 : StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
395 : StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
396 : /// @}
397 :
398 : /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
399 : ///
400 : /// These functions map their strings back to the corresponding enumeration
401 : /// value or return 0 if there is none, except for these exceptions:
402 : ///
403 : /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
404 : /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
405 : /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
406 : ///
407 : /// @{
408 : unsigned getTag(StringRef TagString);
409 : unsigned getOperationEncoding(StringRef OperationEncodingString);
410 : unsigned getVirtuality(StringRef VirtualityString);
411 : unsigned getLanguage(StringRef LanguageString);
412 : unsigned getCallingConvention(StringRef LanguageString);
413 : unsigned getAttributeEncoding(StringRef EncodingString);
414 : unsigned getMacinfo(StringRef MacinfoString);
415 : /// @}
416 :
417 : /// \defgroup DwarfConstantsVersioning Dwarf version for constants
418 : ///
419 : /// For constants defined by DWARF, returns the DWARF version when the constant
420 : /// was first defined. For vendor extensions, if there is a version-related
421 : /// policy for when to emit it, returns a version number for that policy.
422 : /// Otherwise returns 0.
423 : ///
424 : /// @{
425 : unsigned TagVersion(Tag T);
426 : unsigned AttributeVersion(Attribute A);
427 : unsigned FormVersion(Form F);
428 : unsigned OperationVersion(LocationAtom O);
429 : unsigned AttributeEncodingVersion(TypeKind E);
430 : unsigned LanguageVersion(SourceLanguage L);
431 : /// @}
432 :
433 : /// \defgroup DwarfConstantsVendor Dwarf "vendor" for constants
434 : ///
435 : /// These functions return an identifier describing "who" defined the constant,
436 : /// either the DWARF standard itself or the vendor who defined the extension.
437 : ///
438 : /// @{
439 : unsigned TagVendor(Tag T);
440 : unsigned AttributeVendor(Attribute A);
441 : unsigned FormVendor(Form F);
442 : unsigned OperationVendor(LocationAtom O);
443 : unsigned AttributeEncodingVendor(TypeKind E);
444 : unsigned LanguageVendor(SourceLanguage L);
445 : /// @}
446 :
447 : /// Tells whether the specified form is defined in the specified version,
448 : /// or is an extension if extensions are allowed.
449 : bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk = true);
450 :
451 : /// \brief Returns the symbolic string representing Val when used as a value
452 : /// for attribute Attr.
453 : StringRef AttributeValueString(uint16_t Attr, unsigned Val);
454 :
455 : /// \brief Decsribes an entry of the various gnu_pub* debug sections.
456 : ///
457 : /// The gnu_pub* kind looks like:
458 : ///
459 : /// 0-3 reserved
460 : /// 4-6 symbol kind
461 : /// 7 0 == global, 1 == static
462 : ///
463 : /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
464 : /// offset of the cu within the debug_info section stored in those 24 bits.
465 : struct PubIndexEntryDescriptor {
466 : GDBIndexEntryKind Kind;
467 : GDBIndexEntryLinkage Linkage;
468 : PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
469 : : Kind(Kind), Linkage(Linkage) {}
470 : /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
471 : : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
472 : explicit PubIndexEntryDescriptor(uint8_t Value)
473 574 : : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
474 : KIND_OFFSET)),
475 574 : Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
476 1148 : LINKAGE_OFFSET)) {}
477 : uint8_t toBits() const {
478 56 : return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
479 : }
480 :
481 : private:
482 : enum {
483 : KIND_OFFSET = 4,
484 : KIND_MASK = 7 << KIND_OFFSET,
485 : LINKAGE_OFFSET = 7,
486 : LINKAGE_MASK = 1 << LINKAGE_OFFSET
487 : };
488 : };
489 :
490 : /// Constants that define the DWARF format as 32 or 64 bit.
491 : enum DwarfFormat { DWARF32, DWARF64 };
492 :
493 : } // End of namespace dwarf
494 :
495 : } // End of namespace llvm
496 :
497 : #endif
|