1 //===-- llvm/Support/Dwarf.h ---Dwarf Constants------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // \brief This file contains constants used for implementing Dwarf
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.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_SUPPORT_DWARF_H
21 #define LLVM_SUPPORT_DWARF_H
23 #include "llvm/Support/Compiler.h"
24 #include "llvm/Support/DataTypes.h"
31 //===----------------------------------------------------------------------===//
32 // Dwarf constants as gleaned from the DWARF Debugging Information Format V.4
33 // reference manual http://www.dwarfstd.org/.
36 // Do not mix the following two enumerations sets. DW_TAG_invalid changes the
37 // enumeration base type.
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.
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.
52 // Special ID values that distinguish a CIE from a FDE in DWARF CFI.
53 // Not inside an enum because a 64-bit value is needed.
54 const uint32_t DW_CIE_ID = UINT32_MAX;
55 const uint64_t DW64_CIE_ID = UINT64_MAX;
58 #define HANDLE_DW_TAG(ID, NAME) DW_TAG_##NAME = ID,
59 #include "llvm/Support/Dwarf.def"
60 DW_TAG_lo_user = 0x4080,
61 DW_TAG_hi_user = 0xffff,
62 DW_TAG_user_base = 0x1000 // Recommended base for user tags.
65 inline bool isType(Tag T) {
67 case DW_TAG_array_type:
68 case DW_TAG_class_type:
69 case DW_TAG_interface_type:
70 case DW_TAG_enumeration_type:
71 case DW_TAG_pointer_type:
72 case DW_TAG_reference_type:
73 case DW_TAG_rvalue_reference_type:
74 case DW_TAG_string_type:
75 case DW_TAG_structure_type:
76 case DW_TAG_subroutine_type:
77 case DW_TAG_union_type:
78 case DW_TAG_ptr_to_member_type:
80 case DW_TAG_subrange_type:
81 case DW_TAG_base_type:
82 case DW_TAG_const_type:
83 case DW_TAG_file_type:
84 case DW_TAG_packed_type:
85 case DW_TAG_volatile_type:
94 enum Attribute : uint16_t {
95 #define HANDLE_DW_AT(ID, NAME) DW_AT_##NAME = ID,
96 #include "llvm/Support/Dwarf.def"
97 DW_AT_lo_user = 0x2000,
98 DW_AT_hi_user = 0x3fff,
101 enum Form : uint16_t {
102 #define HANDLE_DW_FORM(ID, NAME) DW_FORM_##NAME = ID,
103 #include "llvm/Support/Dwarf.def"
104 DW_FORM_lo_user = 0x1f00, ///< Not specified by DWARF.
108 #define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID,
109 #include "llvm/Support/Dwarf.def"
110 DW_OP_lo_user = 0xe0,
111 DW_OP_hi_user = 0xff,
112 DW_OP_LLVM_fragment = 0x1000 ///< Only used in LLVM metadata.
116 #define HANDLE_DW_ATE(ID, NAME) DW_ATE_##NAME = ID,
117 #include "llvm/Support/Dwarf.def"
118 DW_ATE_lo_user = 0x80,
119 DW_ATE_hi_user = 0xff
122 enum DecimalSignEncoding {
123 // Decimal sign attribute values
124 DW_DS_unsigned = 0x01,
125 DW_DS_leading_overpunch = 0x02,
126 DW_DS_trailing_overpunch = 0x03,
127 DW_DS_leading_separate = 0x04,
128 DW_DS_trailing_separate = 0x05
131 enum EndianityEncoding {
132 // Endianity attribute values
133 DW_END_default = 0x00,
135 DW_END_little = 0x02,
136 DW_END_lo_user = 0x40,
137 DW_END_hi_user = 0xff
140 enum AccessAttribute {
141 // Accessibility codes
142 DW_ACCESS_public = 0x01,
143 DW_ACCESS_protected = 0x02,
144 DW_ACCESS_private = 0x03
147 enum VisibilityAttribute {
150 DW_VIS_exported = 0x02,
151 DW_VIS_qualified = 0x03
154 enum VirtualityAttribute {
155 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
156 #include "llvm/Support/Dwarf.def"
157 DW_VIRTUALITY_max = 0x02
160 enum DefaultedMemberAttribute {
161 #define HANDLE_DW_DEFAULTED(ID, NAME) DW_DEFAULTED_##NAME = ID,
162 #include "llvm/Support/Dwarf.def"
163 DW_DEFAULTED_max = 0x02
166 enum SourceLanguage {
167 #define HANDLE_DW_LANG(ID, NAME) DW_LANG_##NAME = ID,
168 #include "llvm/Support/Dwarf.def"
169 DW_LANG_lo_user = 0x8000,
170 DW_LANG_hi_user = 0xffff
173 enum CaseSensitivity {
174 // Identifier case codes
175 DW_ID_case_sensitive = 0x00,
176 DW_ID_up_case = 0x01,
177 DW_ID_down_case = 0x02,
178 DW_ID_case_insensitive = 0x03
181 enum CallingConvention {
182 // Calling convention codes
183 #define HANDLE_DW_CC(ID, NAME) DW_CC_##NAME = ID,
184 #include "llvm/Support/Dwarf.def"
185 DW_CC_lo_user = 0x40,
189 enum InlineAttribute {
191 DW_INL_not_inlined = 0x00,
192 DW_INL_inlined = 0x01,
193 DW_INL_declared_not_inlined = 0x02,
194 DW_INL_declared_inlined = 0x03
197 enum ArrayDimensionOrdering {
199 DW_ORD_row_major = 0x00,
200 DW_ORD_col_major = 0x01
203 enum DiscriminantList {
204 // Discriminant descriptor values
209 /// Line Number Standard Opcode Encodings.
210 enum LineNumberOps : uint8_t {
211 #define HANDLE_DW_LNS(ID, NAME) DW_LNS_##NAME = ID,
212 #include "llvm/Support/Dwarf.def"
215 /// Line Number Extended Opcode Encodings.
216 enum LineNumberExtendedOps {
217 #define HANDLE_DW_LNE(ID, NAME) DW_LNE_##NAME = ID,
218 #include "llvm/Support/Dwarf.def"
219 DW_LNE_lo_user = 0x80,
220 DW_LNE_hi_user = 0xff
223 enum LinerNumberEntryFormat {
224 #define HANDLE_DW_LNCT(ID, NAME) DW_DEFAULTED_##NAME = ID,
225 #include "llvm/Support/Dwarf.def"
226 DW_LNCT_lo_user = 0x2000,
227 DW_LNCT_hi_user = 0x3fff,
230 enum MacinfoRecordType {
231 // Macinfo Type Encodings
232 DW_MACINFO_define = 0x01,
233 DW_MACINFO_undef = 0x02,
234 DW_MACINFO_start_file = 0x03,
235 DW_MACINFO_end_file = 0x04,
236 DW_MACINFO_vendor_ext = 0xff
239 /// DWARF v5 macro information entry type encodings.
240 enum MacroEntryType {
241 #define HANDLE_DW_MACRO(ID, NAME) DW_MACRO_##NAME = ID,
242 #include "llvm/Support/Dwarf.def"
243 DW_MACRO_lo_user = 0xe0,
244 DW_MACRO_hi_user = 0xff
247 /// DWARF v5 range list entry encoding values.
248 enum RangeListEntries {
249 #define HANDLE_DW_RLE(ID, NAME) DW_RLE_##NAME = ID,
250 #include "llvm/Support/Dwarf.def"
254 /// Call frame instruction encodings.
256 #define HANDLE_DW_CFA(ID, NAME) DW_CFA_##NAME = ID,
257 #include "llvm/Support/Dwarf.def"
258 DW_CFA_extended = 0x00,
260 DW_CFA_lo_user = 0x1c,
261 DW_CFA_hi_user = 0x3f
266 DW_CHILDREN_no = 0x00,
267 DW_CHILDREN_yes = 0x01,
269 DW_EH_PE_absptr = 0x00,
270 DW_EH_PE_omit = 0xff,
271 DW_EH_PE_uleb128 = 0x01,
272 DW_EH_PE_udata2 = 0x02,
273 DW_EH_PE_udata4 = 0x03,
274 DW_EH_PE_udata8 = 0x04,
275 DW_EH_PE_sleb128 = 0x09,
276 DW_EH_PE_sdata2 = 0x0A,
277 DW_EH_PE_sdata4 = 0x0B,
278 DW_EH_PE_sdata8 = 0x0C,
279 DW_EH_PE_signed = 0x08,
280 DW_EH_PE_pcrel = 0x10,
281 DW_EH_PE_textrel = 0x20,
282 DW_EH_PE_datarel = 0x30,
283 DW_EH_PE_funcrel = 0x40,
284 DW_EH_PE_aligned = 0x50,
285 DW_EH_PE_indirect = 0x80
288 /// Constants for location lists in DWARF v5.
289 enum LocationListEntry : unsigned char {
290 DW_LLE_end_of_list = 0x00,
291 DW_LLE_base_addressx = 0x01,
292 DW_LLE_startx_endx = 0x02,
293 DW_LLE_startx_length = 0x03,
294 DW_LLE_offset_pair = 0x04,
295 DW_LLE_default_location = 0x05,
296 DW_LLE_base_address = 0x06,
297 DW_LLE_start_end = 0x07,
298 DW_LLE_start_length = 0x08
301 /// Constants for the DW_APPLE_PROPERTY_attributes attribute.
302 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind!
303 enum ApplePropertyAttributes {
304 #define HANDLE_DW_APPLE_PROPERTY(ID, NAME) DW_APPLE_PROPERTY_##NAME = ID,
305 #include "llvm/Support/Dwarf.def"
308 // Constants for the DWARF5 Accelerator Table Proposal
309 enum AcceleratorTable {
310 // Data layout descriptors.
311 DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
312 DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
313 DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
315 DW_ATOM_die_tag = 3u, // A tag entry.
316 DW_ATOM_type_flags = 4u, // Set of flags for a type.
318 // DW_ATOM_type_flags values.
320 // Always set for C++, only set for ObjC if this is the @implementation for a
322 DW_FLAG_type_implementation = 2u,
326 // Daniel J. Bernstein hash.
327 DW_hash_function_djb = 0u
330 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
331 enum GDBIndexEntryKind {
342 enum GDBIndexEntryLinkage {
347 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
349 /// All these functions map their argument's value back to the
350 /// corresponding enumerator name or return nullptr if the value isn't
354 StringRef TagString(unsigned Tag);
355 StringRef ChildrenString(unsigned Children);
356 StringRef AttributeString(unsigned Attribute);
357 StringRef FormEncodingString(unsigned Encoding);
358 StringRef OperationEncodingString(unsigned Encoding);
359 StringRef AttributeEncodingString(unsigned Encoding);
360 StringRef DecimalSignString(unsigned Sign);
361 StringRef EndianityString(unsigned Endian);
362 StringRef AccessibilityString(unsigned Access);
363 StringRef VisibilityString(unsigned Visibility);
364 StringRef VirtualityString(unsigned Virtuality);
365 StringRef LanguageString(unsigned Language);
366 StringRef CaseString(unsigned Case);
367 StringRef ConventionString(unsigned Convention);
368 StringRef InlineCodeString(unsigned Code);
369 StringRef ArrayOrderString(unsigned Order);
370 StringRef DiscriminantString(unsigned Discriminant);
371 StringRef LNStandardString(unsigned Standard);
372 StringRef LNExtendedString(unsigned Encoding);
373 StringRef MacinfoString(unsigned Encoding);
374 StringRef CallFrameString(unsigned Encoding);
375 StringRef ApplePropertyString(unsigned);
376 StringRef AtomTypeString(unsigned Atom);
377 StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
378 StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
381 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
383 /// These functions map their strings back to the corresponding enumeration
384 /// value or return 0 if there is none, except for these exceptions:
386 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
387 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
388 /// \li \a getMacinfo() returns \a DW_MACINFO_invalid on invalid input.
391 unsigned getTag(StringRef TagString);
392 unsigned getOperationEncoding(StringRef OperationEncodingString);
393 unsigned getVirtuality(StringRef VirtualityString);
394 unsigned getLanguage(StringRef LanguageString);
395 unsigned getCallingConvention(StringRef LanguageString);
396 unsigned getAttributeEncoding(StringRef EncodingString);
397 unsigned getMacinfo(StringRef MacinfoString);
400 /// \brief Returns the symbolic string representing Val when used as a value
401 /// for attribute Attr.
402 StringRef AttributeValueString(uint16_t Attr, unsigned Val);
404 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
406 /// The gnu_pub* kind looks like:
410 /// 7 0 == global, 1 == static
412 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
413 /// offset of the cu within the debug_info section stored in those 24 bits.
414 struct PubIndexEntryDescriptor {
415 GDBIndexEntryKind Kind;
416 GDBIndexEntryLinkage Linkage;
417 PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
418 : Kind(Kind), Linkage(Linkage) {}
419 /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
420 : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
421 explicit PubIndexEntryDescriptor(uint8_t Value)
422 : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
424 Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
426 uint8_t toBits() const {
427 return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET;
433 KIND_MASK = 7 << KIND_OFFSET,
435 LINKAGE_MASK = 1 << LINKAGE_OFFSET
439 /// Constants that define the DWARF format as 32 or 64 bit.
440 enum DwarfFormat { DWARF32, DWARF64 };
442 } // End of namespace dwarf
444 } // End of namespace llvm