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/ADT/StringRef.h"
24 #include "llvm/Support/Compiler.h"
25 #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.
45 DWARF_VERSION = 4, // Default dwarf version we output.
46 DW_PUBTYPES_VERSION = 2, // Section version number for .debug_pubtypes.
47 DW_PUBNAMES_VERSION = 2, // Section version number for .debug_pubnames.
48 DW_ARANGES_VERSION = 2 // Section version number for .debug_aranges.
51 // Special ID values that distinguish a CIE from a FDE in DWARF CFI.
52 // Not inside an enum because a 64-bit value is needed.
53 const uint32_t DW_CIE_ID = UINT32_MAX;
54 const uint64_t DW64_CIE_ID = UINT64_MAX;
57 #define HANDLE_DW_TAG(ID, NAME) DW_TAG_##NAME = ID,
58 #include "llvm/Support/Dwarf.def"
59 DW_TAG_lo_user = 0x4080,
60 DW_TAG_hi_user = 0xffff,
61 DW_TAG_user_base = 0x1000 // Recommended base for user tags.
64 inline bool isType(Tag T) {
66 case DW_TAG_array_type:
67 case DW_TAG_class_type:
68 case DW_TAG_interface_type:
69 case DW_TAG_enumeration_type:
70 case DW_TAG_pointer_type:
71 case DW_TAG_reference_type:
72 case DW_TAG_rvalue_reference_type:
73 case DW_TAG_string_type:
74 case DW_TAG_structure_type:
75 case DW_TAG_subroutine_type:
76 case DW_TAG_union_type:
77 case DW_TAG_ptr_to_member_type:
79 case DW_TAG_subrange_type:
80 case DW_TAG_base_type:
81 case DW_TAG_const_type:
82 case DW_TAG_file_type:
83 case DW_TAG_packed_type:
84 case DW_TAG_volatile_type:
92 enum Attribute : uint16_t {
95 DW_AT_location = 0x02,
97 DW_AT_ordering = 0x09,
98 DW_AT_byte_size = 0x0b,
99 DW_AT_bit_offset = 0x0c,
100 DW_AT_bit_size = 0x0d,
101 DW_AT_stmt_list = 0x10,
103 DW_AT_high_pc = 0x12,
104 DW_AT_language = 0x13,
106 DW_AT_discr_value = 0x16,
107 DW_AT_visibility = 0x17,
109 DW_AT_string_length = 0x19,
110 DW_AT_common_reference = 0x1a,
111 DW_AT_comp_dir = 0x1b,
112 DW_AT_const_value = 0x1c,
113 DW_AT_containing_type = 0x1d,
114 DW_AT_default_value = 0x1e,
116 DW_AT_is_optional = 0x21,
117 DW_AT_lower_bound = 0x22,
118 DW_AT_producer = 0x25,
119 DW_AT_prototyped = 0x27,
120 DW_AT_return_addr = 0x2a,
121 DW_AT_start_scope = 0x2c,
122 DW_AT_bit_stride = 0x2e,
123 DW_AT_upper_bound = 0x2f,
124 DW_AT_abstract_origin = 0x31,
125 DW_AT_accessibility = 0x32,
126 DW_AT_address_class = 0x33,
127 DW_AT_artificial = 0x34,
128 DW_AT_base_types = 0x35,
129 DW_AT_calling_convention = 0x36,
131 DW_AT_data_member_location = 0x38,
132 DW_AT_decl_column = 0x39,
133 DW_AT_decl_file = 0x3a,
134 DW_AT_decl_line = 0x3b,
135 DW_AT_declaration = 0x3c,
136 DW_AT_discr_list = 0x3d,
137 DW_AT_encoding = 0x3e,
138 DW_AT_external = 0x3f,
139 DW_AT_frame_base = 0x40,
141 DW_AT_identifier_case = 0x42,
142 DW_AT_macro_info = 0x43,
143 DW_AT_namelist_item = 0x44,
144 DW_AT_priority = 0x45,
145 DW_AT_segment = 0x46,
146 DW_AT_specification = 0x47,
147 DW_AT_static_link = 0x48,
149 DW_AT_use_location = 0x4a,
150 DW_AT_variable_parameter = 0x4b,
151 DW_AT_virtuality = 0x4c,
152 DW_AT_vtable_elem_location = 0x4d,
153 DW_AT_allocated = 0x4e,
154 DW_AT_associated = 0x4f,
155 DW_AT_data_location = 0x50,
156 DW_AT_byte_stride = 0x51,
157 DW_AT_entry_pc = 0x52,
158 DW_AT_use_UTF8 = 0x53,
159 DW_AT_extension = 0x54,
161 DW_AT_trampoline = 0x56,
162 DW_AT_call_column = 0x57,
163 DW_AT_call_file = 0x58,
164 DW_AT_call_line = 0x59,
165 DW_AT_description = 0x5a,
166 DW_AT_binary_scale = 0x5b,
167 DW_AT_decimal_scale = 0x5c,
169 DW_AT_decimal_sign = 0x5e,
170 DW_AT_digit_count = 0x5f,
171 DW_AT_picture_string = 0x60,
172 DW_AT_mutable = 0x61,
173 DW_AT_threads_scaled = 0x62,
174 DW_AT_explicit = 0x63,
175 DW_AT_object_pointer = 0x64,
176 DW_AT_endianity = 0x65,
177 DW_AT_elemental = 0x66,
179 DW_AT_recursive = 0x68,
180 DW_AT_signature = 0x69,
181 DW_AT_main_subprogram = 0x6a,
182 DW_AT_data_bit_offset = 0x6b,
183 DW_AT_const_expr = 0x6c,
184 DW_AT_enum_class = 0x6d,
185 DW_AT_linkage_name = 0x6e,
188 DW_AT_string_length_bit_size = 0x6f,
189 DW_AT_string_length_byte_size = 0x70,
191 DW_AT_str_offsets_base = 0x72,
192 DW_AT_addr_base = 0x73,
193 DW_AT_ranges_base = 0x74,
195 DW_AT_dwo_name = 0x76,
196 DW_AT_reference = 0x77,
197 DW_AT_rvalue_reference = 0x78,
199 DW_AT_lo_user = 0x2000,
200 DW_AT_hi_user = 0x3fff,
202 DW_AT_MIPS_loop_begin = 0x2002,
203 DW_AT_MIPS_tail_loop_begin = 0x2003,
204 DW_AT_MIPS_epilog_begin = 0x2004,
205 DW_AT_MIPS_loop_unroll_factor = 0x2005,
206 DW_AT_MIPS_software_pipeline_depth = 0x2006,
207 DW_AT_MIPS_linkage_name = 0x2007,
208 DW_AT_MIPS_stride = 0x2008,
209 DW_AT_MIPS_abstract_name = 0x2009,
210 DW_AT_MIPS_clone_origin = 0x200a,
211 DW_AT_MIPS_has_inlines = 0x200b,
212 DW_AT_MIPS_stride_byte = 0x200c,
213 DW_AT_MIPS_stride_elem = 0x200d,
214 DW_AT_MIPS_ptr_dopetype = 0x200e,
215 DW_AT_MIPS_allocatable_dopetype = 0x200f,
216 DW_AT_MIPS_assumed_shape_dopetype = 0x2010,
218 // This one appears to have only been implemented by Open64 for
219 // fortran and may conflict with other extensions.
220 DW_AT_MIPS_assumed_size = 0x2011,
223 DW_AT_sf_names = 0x2101,
224 DW_AT_src_info = 0x2102,
225 DW_AT_mac_info = 0x2103,
226 DW_AT_src_coords = 0x2104,
227 DW_AT_body_begin = 0x2105,
228 DW_AT_body_end = 0x2106,
229 DW_AT_GNU_vector = 0x2107,
230 DW_AT_GNU_template_name = 0x2110,
232 DW_AT_GNU_odr_signature = 0x210f,
234 // Extensions for Fission proposal.
235 DW_AT_GNU_dwo_name = 0x2130,
236 DW_AT_GNU_dwo_id = 0x2131,
237 DW_AT_GNU_ranges_base = 0x2132,
238 DW_AT_GNU_addr_base = 0x2133,
239 DW_AT_GNU_pubnames = 0x2134,
240 DW_AT_GNU_pubtypes = 0x2135,
243 DW_AT_APPLE_optimized = 0x3fe1,
244 DW_AT_APPLE_flags = 0x3fe2,
245 DW_AT_APPLE_isa = 0x3fe3,
246 DW_AT_APPLE_block = 0x3fe4,
247 DW_AT_APPLE_major_runtime_vers = 0x3fe5,
248 DW_AT_APPLE_runtime_class = 0x3fe6,
249 DW_AT_APPLE_omit_frame_ptr = 0x3fe7,
250 DW_AT_APPLE_property_name = 0x3fe8,
251 DW_AT_APPLE_property_getter = 0x3fe9,
252 DW_AT_APPLE_property_setter = 0x3fea,
253 DW_AT_APPLE_property_attribute = 0x3feb,
254 DW_AT_APPLE_objc_complete_type = 0x3fec,
255 DW_AT_APPLE_property = 0x3fed
258 enum Form : uint16_t {
259 // Attribute form encodings
261 DW_FORM_block2 = 0x03,
262 DW_FORM_block4 = 0x04,
263 DW_FORM_data2 = 0x05,
264 DW_FORM_data4 = 0x06,
265 DW_FORM_data8 = 0x07,
266 DW_FORM_string = 0x08,
267 DW_FORM_block = 0x09,
268 DW_FORM_block1 = 0x0a,
269 DW_FORM_data1 = 0x0b,
271 DW_FORM_sdata = 0x0d,
273 DW_FORM_udata = 0x0f,
274 DW_FORM_ref_addr = 0x10,
279 DW_FORM_ref_udata = 0x15,
280 DW_FORM_indirect = 0x16,
281 DW_FORM_sec_offset = 0x17,
282 DW_FORM_exprloc = 0x18,
283 DW_FORM_flag_present = 0x19,
284 DW_FORM_ref_sig8 = 0x20,
286 // Extensions for Fission proposal
287 DW_FORM_GNU_addr_index = 0x1f01,
288 DW_FORM_GNU_str_index = 0x1f02
292 #define HANDLE_DW_OP(ID, NAME) DW_OP_##NAME = ID,
293 #include "llvm/Support/Dwarf.def"
294 DW_OP_lo_user = 0xe0,
299 #define HANDLE_DW_ATE(ID, NAME) DW_ATE_##NAME = ID,
300 #include "llvm/Support/Dwarf.def"
301 DW_ATE_lo_user = 0x80,
302 DW_ATE_hi_user = 0xff
305 enum DecimalSignEncoding {
306 // Decimal sign attribute values
307 DW_DS_unsigned = 0x01,
308 DW_DS_leading_overpunch = 0x02,
309 DW_DS_trailing_overpunch = 0x03,
310 DW_DS_leading_separate = 0x04,
311 DW_DS_trailing_separate = 0x05
314 enum EndianityEncoding {
315 // Endianity attribute values
316 DW_END_default = 0x00,
318 DW_END_little = 0x02,
319 DW_END_lo_user = 0x40,
320 DW_END_hi_user = 0xff
323 enum AccessAttribute {
324 // Accessibility codes
325 DW_ACCESS_public = 0x01,
326 DW_ACCESS_protected = 0x02,
327 DW_ACCESS_private = 0x03
330 enum VisibilityAttribute {
333 DW_VIS_exported = 0x02,
334 DW_VIS_qualified = 0x03
337 enum VirtualityAttribute {
338 #define HANDLE_DW_VIRTUALITY(ID, NAME) DW_VIRTUALITY_##NAME = ID,
339 #include "llvm/Support/Dwarf.def"
340 DW_VIRTUALITY_max = 0x02
343 enum SourceLanguage {
344 #define HANDLE_DW_LANG(ID, NAME) DW_LANG_##NAME = ID,
345 #include "llvm/Support/Dwarf.def"
346 DW_LANG_lo_user = 0x8000,
347 DW_LANG_hi_user = 0xffff
350 enum CaseSensitivity {
351 // Identifier case codes
352 DW_ID_case_sensitive = 0x00,
353 DW_ID_up_case = 0x01,
354 DW_ID_down_case = 0x02,
355 DW_ID_case_insensitive = 0x03
358 enum CallingConvention {
359 // Calling convention codes
361 DW_CC_program = 0x02,
363 DW_CC_lo_user = 0x40,
367 enum InlineAttribute {
369 DW_INL_not_inlined = 0x00,
370 DW_INL_inlined = 0x01,
371 DW_INL_declared_not_inlined = 0x02,
372 DW_INL_declared_inlined = 0x03
375 enum ArrayDimensionOrdering {
377 DW_ORD_row_major = 0x00,
378 DW_ORD_col_major = 0x01
381 enum DiscriminantList {
382 // Discriminant descriptor values
388 // Line Number Standard Opcode Encodings
389 DW_LNS_extended_op = 0x00,
391 DW_LNS_advance_pc = 0x02,
392 DW_LNS_advance_line = 0x03,
393 DW_LNS_set_file = 0x04,
394 DW_LNS_set_column = 0x05,
395 DW_LNS_negate_stmt = 0x06,
396 DW_LNS_set_basic_block = 0x07,
397 DW_LNS_const_add_pc = 0x08,
398 DW_LNS_fixed_advance_pc = 0x09,
399 DW_LNS_set_prologue_end = 0x0a,
400 DW_LNS_set_epilogue_begin = 0x0b,
401 DW_LNS_set_isa = 0x0c
404 enum LineNumberExtendedOps {
405 // Line Number Extended Opcode Encodings
406 DW_LNE_end_sequence = 0x01,
407 DW_LNE_set_address = 0x02,
408 DW_LNE_define_file = 0x03,
409 DW_LNE_set_discriminator = 0x04,
410 DW_LNE_lo_user = 0x80,
411 DW_LNE_hi_user = 0xff
414 enum MacinfoRecordType {
415 // Macinfo Type Encodings
416 DW_MACINFO_define = 0x01,
417 DW_MACINFO_undef = 0x02,
418 DW_MACINFO_start_file = 0x03,
419 DW_MACINFO_end_file = 0x04,
420 DW_MACINFO_vendor_ext = 0xff
424 // Call frame instruction encodings
425 DW_CFA_extended = 0x00,
427 DW_CFA_advance_loc = 0x40,
428 DW_CFA_offset = 0x80,
429 DW_CFA_restore = 0xc0,
430 DW_CFA_set_loc = 0x01,
431 DW_CFA_advance_loc1 = 0x02,
432 DW_CFA_advance_loc2 = 0x03,
433 DW_CFA_advance_loc4 = 0x04,
434 DW_CFA_offset_extended = 0x05,
435 DW_CFA_restore_extended = 0x06,
436 DW_CFA_undefined = 0x07,
437 DW_CFA_same_value = 0x08,
438 DW_CFA_register = 0x09,
439 DW_CFA_remember_state = 0x0a,
440 DW_CFA_restore_state = 0x0b,
441 DW_CFA_def_cfa = 0x0c,
442 DW_CFA_def_cfa_register = 0x0d,
443 DW_CFA_def_cfa_offset = 0x0e,
444 DW_CFA_def_cfa_expression = 0x0f,
445 DW_CFA_expression = 0x10,
446 DW_CFA_offset_extended_sf = 0x11,
447 DW_CFA_def_cfa_sf = 0x12,
448 DW_CFA_def_cfa_offset_sf = 0x13,
449 DW_CFA_val_offset = 0x14,
450 DW_CFA_val_offset_sf = 0x15,
451 DW_CFA_val_expression = 0x16,
452 DW_CFA_MIPS_advance_loc8 = 0x1d,
453 DW_CFA_GNU_window_save = 0x2d,
454 DW_CFA_GNU_args_size = 0x2e,
455 DW_CFA_lo_user = 0x1c,
456 DW_CFA_hi_user = 0x3f
461 DW_CHILDREN_no = 0x00,
462 DW_CHILDREN_yes = 0x01,
464 DW_EH_PE_absptr = 0x00,
465 DW_EH_PE_omit = 0xff,
466 DW_EH_PE_uleb128 = 0x01,
467 DW_EH_PE_udata2 = 0x02,
468 DW_EH_PE_udata4 = 0x03,
469 DW_EH_PE_udata8 = 0x04,
470 DW_EH_PE_sleb128 = 0x09,
471 DW_EH_PE_sdata2 = 0x0A,
472 DW_EH_PE_sdata4 = 0x0B,
473 DW_EH_PE_sdata8 = 0x0C,
474 DW_EH_PE_signed = 0x08,
475 DW_EH_PE_pcrel = 0x10,
476 DW_EH_PE_textrel = 0x20,
477 DW_EH_PE_datarel = 0x30,
478 DW_EH_PE_funcrel = 0x40,
479 DW_EH_PE_aligned = 0x50,
480 DW_EH_PE_indirect = 0x80
483 // Constants for debug_loc.dwo in the DWARF5 Split Debug Info Proposal
484 enum LocationListEntry : unsigned char {
485 DW_LLE_end_of_list_entry,
486 DW_LLE_base_address_selection_entry,
487 DW_LLE_start_end_entry,
488 DW_LLE_start_length_entry,
489 DW_LLE_offset_pair_entry
492 /// Contstants for the DW_APPLE_PROPERTY_attributes attribute.
493 /// Keep this list in sync with clang's DeclSpec.h ObjCPropertyAttributeKind.
494 enum ApplePropertyAttributes {
495 // Apple Objective-C Property Attributes
496 DW_APPLE_PROPERTY_readonly = 0x01,
497 DW_APPLE_PROPERTY_getter = 0x02,
498 DW_APPLE_PROPERTY_assign = 0x04,
499 DW_APPLE_PROPERTY_readwrite = 0x08,
500 DW_APPLE_PROPERTY_retain = 0x10,
501 DW_APPLE_PROPERTY_copy = 0x20,
502 DW_APPLE_PROPERTY_nonatomic = 0x40,
503 DW_APPLE_PROPERTY_setter = 0x80,
504 DW_APPLE_PROPERTY_atomic = 0x100,
505 DW_APPLE_PROPERTY_weak = 0x200,
506 DW_APPLE_PROPERTY_strong = 0x400,
507 DW_APPLE_PROPERTY_unsafe_unretained = 0x800
510 // Constants for the DWARF5 Accelerator Table Proposal
511 enum AcceleratorTable {
512 // Data layout descriptors.
513 DW_ATOM_null = 0u, // Marker as the end of a list of atoms.
514 DW_ATOM_die_offset = 1u, // DIE offset in the debug_info section.
515 DW_ATOM_cu_offset = 2u, // Offset of the compile unit header that contains the
517 DW_ATOM_die_tag = 3u, // A tag entry.
518 DW_ATOM_type_flags = 4u, // Set of flags for a type.
520 // DW_ATOM_type_flags values.
522 // Always set for C++, only set for ObjC if this is the @implementation for a
524 DW_FLAG_type_implementation = 2u,
528 // Daniel J. Bernstein hash.
529 DW_hash_function_djb = 0u
532 // Constants for the GNU pubnames/pubtypes extensions supporting gdb index.
533 enum GDBIndexEntryKind {
544 enum GDBIndexEntryLinkage {
549 /// \defgroup DwarfConstantsDumping Dwarf constants dumping functions
551 /// All these functions map their argument's value back to the
552 /// corresponding enumerator name or return nullptr if the value isn't
556 const char *TagString(unsigned Tag);
557 const char *ChildrenString(unsigned Children);
558 const char *AttributeString(unsigned Attribute);
559 const char *FormEncodingString(unsigned Encoding);
560 const char *OperationEncodingString(unsigned Encoding);
561 const char *AttributeEncodingString(unsigned Encoding);
562 const char *DecimalSignString(unsigned Sign);
563 const char *EndianityString(unsigned Endian);
564 const char *AccessibilityString(unsigned Access);
565 const char *VisibilityString(unsigned Visibility);
566 const char *VirtualityString(unsigned Virtuality);
567 const char *LanguageString(unsigned Language);
568 const char *CaseString(unsigned Case);
569 const char *ConventionString(unsigned Convention);
570 const char *InlineCodeString(unsigned Code);
571 const char *ArrayOrderString(unsigned Order);
572 const char *DiscriminantString(unsigned Discriminant);
573 const char *LNStandardString(unsigned Standard);
574 const char *LNExtendedString(unsigned Encoding);
575 const char *MacinfoString(unsigned Encoding);
576 const char *CallFrameString(unsigned Encoding);
577 const char *ApplePropertyString(unsigned);
578 const char *AtomTypeString(unsigned Atom);
579 const char *GDBIndexEntryKindString(GDBIndexEntryKind Kind);
580 const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
583 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
585 /// These functions map their strings back to the corresponding enumeration
586 /// value or return 0 if there is none, except for these exceptions:
588 /// \li \a getTag() returns \a DW_TAG_invalid on invalid input.
589 /// \li \a getVirtuality() returns \a DW_VIRTUALITY_invalid on invalid input.
592 unsigned getTag(StringRef TagString);
593 unsigned getOperationEncoding(StringRef OperationEncodingString);
594 unsigned getVirtuality(StringRef VirtualityString);
595 unsigned getLanguage(StringRef LanguageString);
596 unsigned getAttributeEncoding(StringRef EncodingString);
599 /// \brief Returns the symbolic string representing Val when used as a value
600 /// for attribute Attr.
601 const char *AttributeValueString(uint16_t Attr, unsigned Val);
603 /// \brief Decsribes an entry of the various gnu_pub* debug sections.
605 /// The gnu_pub* kind looks like:
609 /// 7 0 == global, 1 == static
611 /// A gdb_index descriptor includes the above kind, shifted 24 bits up with the
612 /// offset of the cu within the debug_info section stored in those 24 bits.
613 struct PubIndexEntryDescriptor {
614 GDBIndexEntryKind Kind;
615 GDBIndexEntryLinkage Linkage;
616 PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
617 : Kind(Kind), Linkage(Linkage) {}
618 /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
619 : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
620 explicit PubIndexEntryDescriptor(uint8_t Value)
621 : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
623 Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
625 uint8_t toBits() { return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET; }
630 KIND_MASK = 7 << KIND_OFFSET,
632 LINKAGE_MASK = 1 << LINKAGE_OFFSET
637 } // End of namespace dwarf
639 } // End of namespace llvm