1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>Source Level Debugging with LLVM</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
11 <h1>Source Level Debugging with LLVM</h1>
13 <table class="layout" style="width:100%">
17 <li><a href="#introduction">Introduction</a>
19 <li><a href="#phil">Philosophy behind LLVM debugging information</a></li>
20 <li><a href="#consumers">Debug information consumers</a></li>
21 <li><a href="#debugopt">Debugging optimized code</a></li>
23 <li><a href="#format">Debugging information format</a>
25 <li><a href="#debug_info_descriptors">Debug information descriptors</a>
27 <li><a href="#format_compile_units">Compile unit descriptors</a></li>
28 <li><a href="#format_files">File descriptors</a></li>
29 <li><a href="#format_global_variables">Global variable descriptors</a></li>
30 <li><a href="#format_subprograms">Subprogram descriptors</a></li>
31 <li><a href="#format_blocks">Block descriptors</a></li>
32 <li><a href="#format_basic_type">Basic type descriptors</a></li>
33 <li><a href="#format_derived_type">Derived type descriptors</a></li>
34 <li><a href="#format_composite_type">Composite type descriptors</a></li>
35 <li><a href="#format_subrange">Subrange descriptors</a></li>
36 <li><a href="#format_enumeration">Enumerator descriptors</a></li>
37 <li><a href="#format_variables">Local variables</a></li>
39 <li><a href="#format_common_intrinsics">Debugger intrinsic functions</a>
41 <li><a href="#format_common_declare">llvm.dbg.declare</a></li>
42 <li><a href="#format_common_value">llvm.dbg.value</a></li>
45 <li><a href="#format_common_lifetime">Object lifetimes and scoping</a></li>
46 <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a>
48 <li><a href="#ccxx_compile_units">C/C++ source file information</a></li>
49 <li><a href="#ccxx_global_variable">C/C++ global variable information</a></li>
50 <li><a href="#ccxx_subprogram">C/C++ function information</a></li>
51 <li><a href="#ccxx_basic_types">C/C++ basic types</a></li>
52 <li><a href="#ccxx_derived_types">C/C++ derived types</a></li>
53 <li><a href="#ccxx_composite_types">C/C++ struct/union types</a></li>
54 <li><a href="#ccxx_enumeration_types">C/C++ enumeration types</a></li>
56 <li><a href="#llvmdwarfextension">LLVM Dwarf Extensions</a>
58 <li><a href="#objcproperty">Debugging Information Extension
59 for Objective C Properties</a>
61 <li><a href="#objcpropertyintroduction">Introduction</a></li>
62 <li><a href="#objcpropertyproposal">Proposal</a></li>
63 <li><a href="#objcpropertynewattributes">New DWARF Attributes</a></li>
64 <li><a href="#objcpropertynewconstants">New DWARF Constants</a></li>
67 <li><a href="#acceltable">Name Accelerator Tables</a>
69 <li><a href="#acceltableintroduction">Introduction</a></li>
70 <li><a href="#acceltablehashes">Hash Tables</a></li>
71 <li><a href="#acceltabledetails">Details</a></li>
72 <li><a href="#acceltablecontents">Contents</a></li>
73 <li><a href="#acceltableextensions">Language Extensions and File Format Changes</a></li>
81 <img src="img/venusflytrap.jpg" alt="A leafy and green bug eater" width="247"
86 <div class="doc_author">
87 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
88 and <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
92 <!-- *********************************************************************** -->
93 <h2><a name="introduction">Introduction</a></h2>
94 <!-- *********************************************************************** -->
98 <p>This document is the central repository for all information pertaining to
99 debug information in LLVM. It describes the <a href="#format">actual format
100 that the LLVM debug information</a> takes, which is useful for those
101 interested in creating front-ends or dealing directly with the information.
102 Further, this document provides specific examples of what debug information
103 for C/C++ looks like.</p>
105 <!-- ======================================================================= -->
107 <a name="phil">Philosophy behind LLVM debugging information</a>
112 <p>The idea of the LLVM debugging information is to capture how the important
113 pieces of the source-language's Abstract Syntax Tree map onto LLVM code.
114 Several design aspects have shaped the solution that appears here. The
115 important ones are:</p>
118 <li>Debugging information should have very little impact on the rest of the
119 compiler. No transformations, analyses, or code generators should need to
120 be modified because of debugging information.</li>
122 <li>LLVM optimizations should interact in <a href="#debugopt">well-defined and
123 easily described ways</a> with the debugging information.</li>
125 <li>Because LLVM is designed to support arbitrary programming languages,
126 LLVM-to-LLVM tools should not need to know anything about the semantics of
127 the source-level-language.</li>
129 <li>Source-level languages are often <b>widely</b> different from one another.
130 LLVM should not put any restrictions of the flavor of the source-language,
131 and the debugging information should work with any language.</li>
133 <li>With code generator support, it should be possible to use an LLVM compiler
134 to compile a program to native machine code and standard debugging
135 formats. This allows compatibility with traditional machine-code level
136 debuggers, like GDB or DBX.</li>
139 <p>The approach used by the LLVM implementation is to use a small set
140 of <a href="#format_common_intrinsics">intrinsic functions</a> to define a
141 mapping between LLVM program objects and the source-level objects. The
142 description of the source-level program is maintained in LLVM metadata
143 in an <a href="#ccxx_frontend">implementation-defined format</a>
144 (the C/C++ front-end currently uses working draft 7 of
145 the <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3
148 <p>When a program is being debugged, a debugger interacts with the user and
149 turns the stored debug information into source-language specific information.
150 As such, a debugger must be aware of the source-language, and is thus tied to
151 a specific language or family of languages.</p>
155 <!-- ======================================================================= -->
157 <a name="consumers">Debug information consumers</a>
162 <p>The role of debug information is to provide meta information normally
163 stripped away during the compilation process. This meta information provides
164 an LLVM user a relationship between generated code and the original program
167 <p>Currently, debug information is consumed by DwarfDebug to produce dwarf
168 information used by the gdb debugger. Other targets could use the same
169 information to produce stabs or other debug forms.</p>
171 <p>It would also be reasonable to use debug information to feed profiling tools
172 for analysis of generated code, or, tools for reconstructing the original
173 source from generated code.</p>
175 <p>TODO - expound a bit more.</p>
179 <!-- ======================================================================= -->
181 <a name="debugopt">Debugging optimized code</a>
186 <p>An extremely high priority of LLVM debugging information is to make it
187 interact well with optimizations and analysis. In particular, the LLVM debug
188 information provides the following guarantees:</p>
191 <li>LLVM debug information <b>always provides information to accurately read
192 the source-level state of the program</b>, regardless of which LLVM
193 optimizations have been run, and without any modification to the
194 optimizations themselves. However, some optimizations may impact the
195 ability to modify the current state of the program with a debugger, such
196 as setting program variables, or calling functions that have been
199 <li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM
200 debugging information, allowing them to update the debugging information
201 as they perform aggressive optimizations. This means that, with effort,
202 the LLVM optimizers could optimize debug code just as well as non-debug
205 <li>LLVM debug information does not prevent optimizations from
206 happening (for example inlining, basic block reordering/merging/cleanup,
207 tail duplication, etc).</li>
209 <li>LLVM debug information is automatically optimized along with the rest of
210 the program, using existing facilities. For example, duplicate
211 information is automatically merged by the linker, and unused information
212 is automatically removed.</li>
215 <p>Basically, the debug information allows you to compile a program with
216 "<tt>-O0 -g</tt>" and get full debug information, allowing you to arbitrarily
217 modify the program as it executes from a debugger. Compiling a program with
218 "<tt>-O3 -g</tt>" gives you full debug information that is always available
219 and accurate for reading (e.g., you get accurate stack traces despite tail
220 call elimination and inlining), but you might lose the ability to modify the
221 program and call functions where were optimized out of the program, or
222 inlined away completely.</p>
224 <p><a href="TestingGuide.html#quicktestsuite">LLVM test suite</a> provides a
225 framework to test optimizer's handling of debugging information. It can be
228 <div class="doc_code">
230 % cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level
235 <p>This will test impact of debugging information on optimization passes. If
236 debugging information influences optimization passes then it will be reported
237 as a failure. See <a href="TestingGuide.html">TestingGuide</a> for more
238 information on LLVM test infrastructure and how to run various tests.</p>
244 <!-- *********************************************************************** -->
246 <a name="format">Debugging information format</a>
248 <!-- *********************************************************************** -->
252 <p>LLVM debugging information has been carefully designed to make it possible
253 for the optimizer to optimize the program and debugging information without
254 necessarily having to know anything about debugging information. In
255 particular, the use of metadata avoids duplicated debugging information from
256 the beginning, and the global dead code elimination pass automatically
257 deletes debugging information for a function if it decides to delete the
260 <p>To do this, most of the debugging information (descriptors for types,
261 variables, functions, source files, etc) is inserted by the language
262 front-end in the form of LLVM metadata. </p>
264 <p>Debug information is designed to be agnostic about the target debugger and
265 debugging information representation (e.g. DWARF/Stabs/etc). It uses a
266 generic pass to decode the information that represents variables, types,
267 functions, namespaces, etc: this allows for arbitrary source-language
268 semantics and type-systems to be used, as long as there is a module
269 written for the target debugger to interpret the information. </p>
271 <p>To provide basic functionality, the LLVM debugger does have to make some
272 assumptions about the source-level language being debugged, though it keeps
273 these to a minimum. The only common features that the LLVM debugger assumes
274 exist are <a href="#format_files">source files</a>,
275 and <a href="#format_global_variables">program objects</a>. These abstract
276 objects are used by a debugger to form stack traces, show information about
277 local variables, etc.</p>
279 <p>This section of the documentation first describes the representation aspects
280 common to any source-language. The <a href="#ccxx_frontend">next section</a>
281 describes the data layout conventions used by the C and C++ front-ends.</p>
283 <!-- ======================================================================= -->
285 <a name="debug_info_descriptors">Debug information descriptors</a>
290 <p>In consideration of the complexity and volume of debug information, LLVM
291 provides a specification for well formed debug descriptors. </p>
293 <p>Consumers of LLVM debug information expect the descriptors for program
294 objects to start in a canonical format, but the descriptors can include
295 additional information appended at the end that is source-language
296 specific. All LLVM debugging information is versioned, allowing backwards
297 compatibility in the case that the core structures need to change in some
298 way. Also, all debugging information objects start with a tag to indicate
299 what type of object it is. The source-language is allowed to define its own
300 objects, by using unreserved tag numbers. We recommend using with tags in
301 the range 0x1000 through 0x2000 (there is a defined enum DW_TAG_user_base =
304 <p>The fields of debug descriptors used internally by LLVM
305 are restricted to only the simple data types <tt>i32</tt>, <tt>i1</tt>,
306 <tt>float</tt>, <tt>double</tt>, <tt>mdstring</tt> and <tt>mdnode</tt>. </p>
308 <div class="doc_code">
317 <p><a name="LLVMDebugVersion">The first field of a descriptor is always an
318 <tt>i32</tt> containing a tag value identifying the content of the
319 descriptor. The remaining fields are specific to the descriptor. The values
320 of tags are loosely bound to the tag values of DWARF information entries.
321 However, that does not restrict the use of the information supplied to DWARF
322 targets. To facilitate versioning of debug information, the tag is augmented
323 with the current debug version (LLVMDebugVersion = 8 << 16 or
324 0x80000 or 524288.)</a></p>
326 <p>The details of the various descriptors follow.</p>
328 <!-- ======================================================================= -->
330 <a name="format_compile_units">Compile unit descriptors</a>
335 <div class="doc_code">
338 i32, ;; Tag = 17 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
339 ;; (DW_TAG_compile_unit)
340 i32, ;; Unused field.
341 i32, ;; DWARF language identifier (ex. DW_LANG_C89)
342 metadata, ;; Source file name
343 metadata, ;; Source file directory (includes trailing slash)
344 metadata ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
345 i1, ;; True if this is a main compile unit.
346 i1, ;; True if this is optimized.
348 i32 ;; Runtime version
349 metadata ;; List of enums types
350 metadata ;; List of retained types
351 metadata ;; List of subprograms
352 metadata ;; List of global variables
357 <p>These descriptors contain a source language ID for the file (we use the DWARF
358 3.0 ID numbers, such as <tt>DW_LANG_C89</tt>, <tt>DW_LANG_C_plus_plus</tt>,
359 <tt>DW_LANG_Cobol74</tt>, etc), three strings describing the filename,
360 working directory of the compiler, and an identifier string for the compiler
361 that produced it.</p>
363 <p>Compile unit descriptors provide the root context for objects declared in a
364 specific compilation unit. File descriptors are defined using this context.
365 These descriptors are collected by a named metadata
366 <tt>!llvm.dbg.cu</tt>. Compile unit descriptor keeps track of subprograms,
367 global variables and type information.
371 <!-- ======================================================================= -->
373 <a name="format_files">File descriptors</a>
378 <div class="doc_code">
381 i32, ;; Tag = 41 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
382 ;; (DW_TAG_file_type)
383 metadata, ;; Source file name
384 metadata, ;; Source file directory (includes trailing slash)
390 <p>These descriptors contain information for a file. Global variables and top
391 level functions would be defined using this context.k File descriptors also
392 provide context for source line correspondence. </p>
394 <p>Each input file is encoded as a separate file descriptor in LLVM debugging
395 information output. </p>
399 <!-- ======================================================================= -->
401 <a name="format_global_variables">Global variable descriptors</a>
406 <div class="doc_code">
409 i32, ;; Tag = 52 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
411 i32, ;; Unused field.
412 metadata, ;; Reference to context descriptor
414 metadata, ;; Display name (fully qualified C++ name)
415 metadata, ;; MIPS linkage name (for C++)
416 metadata, ;; Reference to file where defined
417 i32, ;; Line number where defined
418 metadata, ;; Reference to type descriptor
419 i1, ;; True if the global is local to compile unit (static)
420 i1, ;; True if the global is defined in the compile unit (not extern)
421 {}* ;; Reference to the global variable
426 <p>These descriptors provide debug information about globals variables. The
427 provide details such as name, type and where the variable is defined. All
428 global variables are collected by named metadata <tt>!llvm.dbg.gv</tt>.</p>
432 <!-- ======================================================================= -->
434 <a name="format_subprograms">Subprogram descriptors</a>
439 <div class="doc_code">
442 i32, ;; Tag = 46 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
443 ;; (DW_TAG_subprogram)
444 i32, ;; Unused field.
445 metadata, ;; Reference to context descriptor
447 metadata, ;; Display name (fully qualified C++ name)
448 metadata, ;; MIPS linkage name (for C++)
449 metadata, ;; Reference to file where defined
450 i32, ;; Line number where defined
451 metadata, ;; Reference to type descriptor
452 i1, ;; True if the global is local to compile unit (static)
453 i1, ;; True if the global is defined in the compile unit (not extern)
454 i32, ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
455 i32, ;; Index into a virtual function
456 metadata, ;; indicates which base type contains the vtable pointer for the
458 i32, ;; Flags - Artifical, Private, Protected, Explicit, Prototyped.
460 Function *,;; Pointer to LLVM function
461 metadata, ;; Lists function template parameters
462 metadata ;; Function declaration descriptor
463 metadata ;; List of function variables
468 <p>These descriptors provide debug information about functions, methods and
469 subprograms. They provide details such as name, return types and the source
470 location where the subprogram is defined.
475 <!-- ======================================================================= -->
477 <a name="format_blocks">Block descriptors</a>
482 <div class="doc_code">
485 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
486 metadata,;; Reference to context descriptor
488 i32, ;; Column number
489 metadata,;; Reference to source file
490 i32 ;; Unique ID to identify blocks from a template function
495 <p>This descriptor provides debug information about nested blocks within a
496 subprogram. The line number and column numbers are used to dinstinguish
497 two lexical blocks at same depth. </p>
499 <div class="doc_code">
502 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
503 metadata ;; Reference to the scope we're annotating with a file change
504 metadata,;; Reference to the file the scope is enclosed in.
509 <p>This descriptor provides a wrapper around a lexical scope to handle file
510 changes in the middle of a lexical block.</p>
514 <!-- ======================================================================= -->
516 <a name="format_basic_type">Basic type descriptors</a>
521 <div class="doc_code">
524 i32, ;; Tag = 36 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
525 ;; (DW_TAG_base_type)
526 metadata, ;; Reference to context
527 metadata, ;; Name (may be "" for anonymous types)
528 metadata, ;; Reference to file where defined (may be NULL)
529 i32, ;; Line number where defined (may be 0)
531 i64, ;; Alignment in bits
532 i64, ;; Offset in bits
534 i32 ;; DWARF type encoding
539 <p>These descriptors define primitive types used in the code. Example int, bool
540 and float. The context provides the scope of the type, which is usually the
541 top level. Since basic types are not usually user defined the context
542 and line number can be left as NULL and 0. The size, alignment and offset
543 are expressed in bits and can be 64 bit values. The alignment is used to
544 round the offset when embedded in a
545 <a href="#format_composite_type">composite type</a> (example to keep float
546 doubles on 64 bit boundaries.) The offset is the bit offset if embedded in
547 a <a href="#format_composite_type">composite type</a>.</p>
549 <p>The type encoding provides the details of the type. The values are typically
550 one of the following:</p>
552 <div class="doc_code">
558 DW_ATE_signed_char = 6
560 DW_ATE_unsigned_char = 8
566 <!-- ======================================================================= -->
568 <a name="format_derived_type">Derived type descriptors</a>
573 <div class="doc_code">
576 i32, ;; Tag (see below)
577 metadata, ;; Reference to context
578 metadata, ;; Name (may be "" for anonymous types)
579 metadata, ;; Reference to file where defined (may be NULL)
580 i32, ;; Line number where defined (may be 0)
582 i64, ;; Alignment in bits
583 i64, ;; Offset in bits
584 i32, ;; Flags to encode attributes, e.g. private
585 metadata, ;; Reference to type derived from
586 metadata, ;; (optional) Name of the Objective C property associated with
587 ;; Objective-C an ivar
588 metadata, ;; (optional) Name of the Objective C property getter selector.
589 metadata, ;; (optional) Name of the Objective C property setter selector.
590 i32 ;; (optional) Objective C property attributes.
595 <p>These descriptors are used to define types derived from other types. The
596 value of the tag varies depending on the meaning. The following are possible
599 <div class="doc_code">
601 DW_TAG_formal_parameter = 5
603 DW_TAG_pointer_type = 15
604 DW_TAG_reference_type = 16
606 DW_TAG_const_type = 38
607 DW_TAG_volatile_type = 53
608 DW_TAG_restrict_type = 55
612 <p><tt>DW_TAG_member</tt> is used to define a member of
613 a <a href="#format_composite_type">composite type</a>
614 or <a href="#format_subprograms">subprogram</a>. The type of the member is
615 the <a href="#format_derived_type">derived
616 type</a>. <tt>DW_TAG_formal_parameter</tt> is used to define a member which
617 is a formal argument of a subprogram.</p>
619 <p><tt>DW_TAG_typedef</tt> is used to provide a name for the derived type.</p>
621 <p><tt>DW_TAG_pointer_type</tt>, <tt>DW_TAG_reference_type</tt>,
622 <tt>DW_TAG_const_type</tt>, <tt>DW_TAG_volatile_type</tt> and
623 <tt>DW_TAG_restrict_type</tt> are used to qualify
624 the <a href="#format_derived_type">derived type</a>. </p>
626 <p><a href="#format_derived_type">Derived type</a> location can be determined
627 from the context and line number. The size, alignment and offset are
628 expressed in bits and can be 64 bit values. The alignment is used to round
629 the offset when embedded in a <a href="#format_composite_type">composite
630 type</a> (example to keep float doubles on 64 bit boundaries.) The offset is
631 the bit offset if embedded in a <a href="#format_composite_type">composite
634 <p>Note that the <tt>void *</tt> type is expressed as a type derived from NULL.
639 <!-- ======================================================================= -->
641 <a name="format_composite_type">Composite type descriptors</a>
646 <div class="doc_code">
649 i32, ;; Tag (see below)
650 metadata, ;; Reference to context
651 metadata, ;; Name (may be "" for anonymous types)
652 metadata, ;; Reference to file where defined (may be NULL)
653 i32, ;; Line number where defined (may be 0)
655 i64, ;; Alignment in bits
656 i64, ;; Offset in bits
658 metadata, ;; Reference to type derived from
659 metadata, ;; Reference to array of member descriptors
660 i32 ;; Runtime languages
665 <p>These descriptors are used to define types that are composed of 0 or more
666 elements. The value of the tag varies depending on the meaning. The following
667 are possible tag values:</p>
669 <div class="doc_code">
671 DW_TAG_array_type = 1
672 DW_TAG_enumeration_type = 4
673 DW_TAG_structure_type = 19
674 DW_TAG_union_type = 23
675 DW_TAG_vector_type = 259
676 DW_TAG_subroutine_type = 21
677 DW_TAG_inheritance = 28
681 <p>The vector flag indicates that an array type is a native packed vector.</p>
683 <p>The members of array types (tag = <tt>DW_TAG_array_type</tt>) or vector types
684 (tag = <tt>DW_TAG_vector_type</tt>) are <a href="#format_subrange">subrange
685 descriptors</a>, each representing the range of subscripts at that level of
688 <p>The members of enumeration types (tag = <tt>DW_TAG_enumeration_type</tt>) are
689 <a href="#format_enumeration">enumerator descriptors</a>, each representing
690 the definition of enumeration value for the set. All enumeration type
691 descriptors are collected by named metadata <tt>!llvm.dbg.enum</tt>.</p>
693 <p>The members of structure (tag = <tt>DW_TAG_structure_type</tt>) or union (tag
694 = <tt>DW_TAG_union_type</tt>) types are any one of
695 the <a href="#format_basic_type">basic</a>,
696 <a href="#format_derived_type">derived</a>
697 or <a href="#format_composite_type">composite</a> type descriptors, each
698 representing a field member of the structure or union.</p>
700 <p>For C++ classes (tag = <tt>DW_TAG_structure_type</tt>), member descriptors
701 provide information about base classes, static members and member
702 functions. If a member is a <a href="#format_derived_type">derived type
703 descriptor</a> and has a tag of <tt>DW_TAG_inheritance</tt>, then the type
704 represents a base class. If the member of is
705 a <a href="#format_global_variables">global variable descriptor</a> then it
706 represents a static member. And, if the member is
707 a <a href="#format_subprograms">subprogram descriptor</a> then it represents
708 a member function. For static members and member
709 functions, <tt>getName()</tt> returns the members link or the C++ mangled
710 name. <tt>getDisplayName()</tt> the simplied version of the name.</p>
712 <p>The first member of subroutine (tag = <tt>DW_TAG_subroutine_type</tt>) type
713 elements is the return type for the subroutine. The remaining elements are
714 the formal arguments to the subroutine.</p>
716 <p><a href="#format_composite_type">Composite type</a> location can be
717 determined from the context and line number. The size, alignment and
718 offset are expressed in bits and can be 64 bit values. The alignment is used
719 to round the offset when embedded in
720 a <a href="#format_composite_type">composite type</a> (as an example, to keep
721 float doubles on 64 bit boundaries.) The offset is the bit offset if embedded
722 in a <a href="#format_composite_type">composite type</a>.</p>
726 <!-- ======================================================================= -->
728 <a name="format_subrange">Subrange descriptors</a>
733 <div class="doc_code">
736 i32, ;; Tag = 33 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_subrange_type)
743 <p>These descriptors are used to define ranges of array subscripts for an array
744 <a href="#format_composite_type">composite type</a>. The low value defines
745 the lower bounds typically zero for C/C++. The high value is the upper
746 bounds. Values are 64 bit. High - low + 1 is the size of the array. If low
747 > high the array bounds are not included in generated debugging information.
752 <!-- ======================================================================= -->
754 <a name="format_enumeration">Enumerator descriptors</a>
759 <div class="doc_code">
762 i32, ;; Tag = 40 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
763 ;; (DW_TAG_enumerator)
770 <p>These descriptors are used to define members of an
771 enumeration <a href="#format_composite_type">composite type</a>, it
772 associates the name to the value.</p>
776 <!-- ======================================================================= -->
778 <a name="format_variables">Local variables</a>
783 <div class="doc_code">
786 i32, ;; Tag (see below)
789 metadata, ;; Reference to file where defined
790 i32, ;; 24 bit - Line number where defined
791 ;; 8 bit - Argument number. 1 indicates 1st argument.
792 metadata, ;; Type descriptor
794 metadata ;; (optional) Reference to inline location
799 <p>These descriptors are used to define variables local to a sub program. The
800 value of the tag depends on the usage of the variable:</p>
802 <div class="doc_code">
804 DW_TAG_auto_variable = 256
805 DW_TAG_arg_variable = 257
806 DW_TAG_return_variable = 258
810 <p>An auto variable is any variable declared in the body of the function. An
811 argument variable is any variable that appears as a formal argument to the
812 function. A return variable is used to track the result of a function and
813 has no source correspondent.</p>
815 <p>The context is either the subprogram or block where the variable is defined.
816 Name the source variable name. Context and line indicate where the
817 variable was defined. Type descriptor defines the declared type of the
824 <!-- ======================================================================= -->
826 <a name="format_common_intrinsics">Debugger intrinsic functions</a>
831 <p>LLVM uses several intrinsic functions (name prefixed with "llvm.dbg") to
832 provide debug information at various points in generated code.</p>
834 <!-- ======================================================================= -->
836 <a name="format_common_declare">llvm.dbg.declare</a>
841 void %<a href="#format_common_declare">llvm.dbg.declare</a>(metadata, metadata)
844 <p>This intrinsic provides information about a local element (e.g., variable). The
845 first argument is metadata holding the alloca for the variable. The
846 second argument is metadata containing a description of the variable.</p>
849 <!-- ======================================================================= -->
851 <a name="format_common_value">llvm.dbg.value</a>
856 void %<a href="#format_common_value">llvm.dbg.value</a>(metadata, i64, metadata)
859 <p>This intrinsic provides information when a user source variable is set to a
860 new value. The first argument is the new value (wrapped as metadata). The
861 second argument is the offset in the user source variable where the new value
862 is written. The third argument is metadata containing a description of the
863 user source variable.</p>
868 <!-- ======================================================================= -->
870 <a name="format_common_lifetime">Object lifetimes and scoping</a>
874 <p>In many languages, the local variables in functions can have their lifetimes
875 or scopes limited to a subset of a function. In the C family of languages,
876 for example, variables are only live (readable and writable) within the
877 source block that they are defined in. In functional languages, values are
878 only readable after they have been defined. Though this is a very obvious
879 concept, it is non-trivial to model in LLVM, because it has no notion of
880 scoping in this sense, and does not want to be tied to a language's scoping
883 <p>In order to handle this, the LLVM debug format uses the metadata attached to
884 llvm instructions to encode line number and scoping information. Consider
885 the following C fragment, for example:</p>
887 <div class="doc_code">
901 <p>Compiled to LLVM, this function would be represented like this:</p>
903 <div class="doc_code">
905 define void @foo() nounwind ssp {
907 %X = alloca i32, align 4 ; <i32*> [#uses=4]
908 %Y = alloca i32, align 4 ; <i32*> [#uses=4]
909 %Z = alloca i32, align 4 ; <i32*> [#uses=3]
910 %0 = bitcast i32* %X to {}* ; <{}*> [#uses=1]
911 call void @llvm.dbg.declare(metadata !{i32 * %X}, metadata !0), !dbg !7
912 store i32 21, i32* %X, !dbg !8
913 %1 = bitcast i32* %Y to {}* ; <{}*> [#uses=1]
914 call void @llvm.dbg.declare(metadata !{i32 * %Y}, metadata !9), !dbg !10
915 store i32 22, i32* %Y, !dbg !11
916 %2 = bitcast i32* %Z to {}* ; <{}*> [#uses=1]
917 call void @llvm.dbg.declare(metadata !{i32 * %Z}, metadata !12), !dbg !14
918 store i32 23, i32* %Z, !dbg !15
919 %tmp = load i32* %X, !dbg !16 ; <i32> [#uses=1]
920 %tmp1 = load i32* %Y, !dbg !16 ; <i32> [#uses=1]
921 %add = add nsw i32 %tmp, %tmp1, !dbg !16 ; <i32> [#uses=1]
922 store i32 %add, i32* %Z, !dbg !16
923 %tmp2 = load i32* %Y, !dbg !17 ; <i32> [#uses=1]
924 store i32 %tmp2, i32* %X, !dbg !17
928 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
930 !0 = metadata !{i32 459008, metadata !1, metadata !"X",
931 metadata !3, i32 2, metadata !6}; [ DW_TAG_auto_variable ]
932 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
933 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", metadata !"foo",
934 metadata !"foo", metadata !3, i32 1, metadata !4,
935 i1 false, i1 true}; [DW_TAG_subprogram ]
936 !3 = metadata !{i32 458769, i32 0, i32 12, metadata !"foo.c",
937 metadata !"/private/tmp", metadata !"clang 1.1", i1 true,
938 i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
939 !4 = metadata !{i32 458773, metadata !3, metadata !"", null, i32 0, i64 0, i64 0,
940 i64 0, i32 0, null, metadata !5, i32 0}; [DW_TAG_subroutine_type ]
941 !5 = metadata !{null}
942 !6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0,
943 i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ]
944 !7 = metadata !{i32 2, i32 7, metadata !1, null}
945 !8 = metadata !{i32 2, i32 3, metadata !1, null}
946 !9 = metadata !{i32 459008, metadata !1, metadata !"Y", metadata !3, i32 3,
947 metadata !6}; [ DW_TAG_auto_variable ]
948 !10 = metadata !{i32 3, i32 7, metadata !1, null}
949 !11 = metadata !{i32 3, i32 3, metadata !1, null}
950 !12 = metadata !{i32 459008, metadata !13, metadata !"Z", metadata !3, i32 5,
951 metadata !6}; [ DW_TAG_auto_variable ]
952 !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
953 !14 = metadata !{i32 5, i32 9, metadata !13, null}
954 !15 = metadata !{i32 5, i32 5, metadata !13, null}
955 !16 = metadata !{i32 6, i32 5, metadata !13, null}
956 !17 = metadata !{i32 8, i32 3, metadata !1, null}
957 !18 = metadata !{i32 9, i32 1, metadata !2, null}
961 <p>This example illustrates a few important details about LLVM debugging
962 information. In particular, it shows how the <tt>llvm.dbg.declare</tt>
963 intrinsic and location information, which are attached to an instruction,
964 are applied together to allow a debugger to analyze the relationship between
965 statements, variable definitions, and the code used to implement the
968 <div class="doc_code">
970 call void @llvm.dbg.declare(metadata, metadata !0), !dbg !7
974 <p>The first intrinsic
975 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
976 encodes debugging information for the variable <tt>X</tt>. The metadata
977 <tt>!dbg !7</tt> attached to the intrinsic provides scope information for the
978 variable <tt>X</tt>.</p>
980 <div class="doc_code">
982 !7 = metadata !{i32 2, i32 7, metadata !1, null}
983 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
984 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo",
985 metadata !"foo", metadata !"foo", metadata !3, i32 1,
986 metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
990 <p>Here <tt>!7</tt> is metadata providing location information. It has four
991 fields: line number, column number, scope, and original scope. The original
992 scope represents inline location if this instruction is inlined inside a
993 caller, and is null otherwise. In this example, scope is encoded by
994 <tt>!1</tt>. <tt>!1</tt> represents a lexical block inside the scope
995 <tt>!2</tt>, where <tt>!2</tt> is a
996 <a href="#format_subprograms">subprogram descriptor</a>. This way the
997 location information attached to the intrinsics indicates that the
998 variable <tt>X</tt> is declared at line number 2 at a function level scope in
999 function <tt>foo</tt>.</p>
1001 <p>Now lets take another example.</p>
1003 <div class="doc_code">
1005 call void @llvm.dbg.declare(metadata, metadata !12), !dbg !14
1009 <p>The second intrinsic
1010 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
1011 encodes debugging information for variable <tt>Z</tt>. The metadata
1012 <tt>!dbg !14</tt> attached to the intrinsic provides scope information for
1013 the variable <tt>Z</tt>.</p>
1015 <div class="doc_code">
1017 !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
1018 !14 = metadata !{i32 5, i32 9, metadata !13, null}
1022 <p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declared at line number 5 and
1023 column number 9 inside of lexical scope <tt>!13</tt>. The lexical scope
1024 itself resides inside of lexical scope <tt>!1</tt> described above.</p>
1026 <p>The scope information attached with each instruction provides a
1027 straightforward way to find instructions covered by a scope.</p>
1033 <!-- *********************************************************************** -->
1035 <a name="ccxx_frontend">C/C++ front-end specific debug information</a>
1037 <!-- *********************************************************************** -->
1041 <p>The C and C++ front-ends represent information about the program in a format
1042 that is effectively identical
1043 to <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3.0</a> in
1044 terms of information content. This allows code generators to trivially
1045 support native debuggers by generating standard dwarf information, and
1046 contains enough information for non-dwarf targets to translate it as
1049 <p>This section describes the forms used to represent C and C++ programs. Other
1050 languages could pattern themselves after this (which itself is tuned to
1051 representing programs in the same way that DWARF 3 does), or they could
1052 choose to provide completely different forms if they don't fit into the DWARF
1053 model. As support for debugging information gets added to the various LLVM
1054 source-language front-ends, the information used should be documented
1057 <p>The following sections provide examples of various C/C++ constructs and the
1058 debug information that would best describe those constructs.</p>
1060 <!-- ======================================================================= -->
1062 <a name="ccxx_compile_units">C/C++ source file information</a>
1067 <p>Given the source files <tt>MySource.cpp</tt> and <tt>MyHeader.h</tt> located
1068 in the directory <tt>/Users/mine/sources</tt>, the following code:</p>
1070 <div class="doc_code">
1072 #include "MyHeader.h"
1074 int main(int argc, char *argv[]) {
1080 <p>a C/C++ front-end would generate the following descriptors:</p>
1082 <div class="doc_code">
1086 ;; Define the compile unit for the main source file "/Users/mine/sources/MySource.cpp".
1091 i32 4, ;; Language Id
1092 metadata !"MySource.cpp",
1093 metadata !"/Users/mine/sources",
1094 metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)",
1095 i1 true, ;; Main Compile Unit
1096 i1 false, ;; Optimized compile unit
1097 metadata !"", ;; Compiler flags
1098 i32 0} ;; Runtime version
1101 ;; Define the file for the file "/Users/mine/sources/MySource.cpp".
1105 metadata !"MySource.cpp",
1106 metadata !"/Users/mine/sources",
1107 metadata !2 ;; Compile unit
1111 ;; Define the file for the file "/Users/mine/sources/Myheader.h"
1115 metadata !"Myheader.h"
1116 metadata !"/Users/mine/sources",
1117 metadata !2 ;; Compile unit
1124 <p>llvm::Instruction provides easy access to metadata attached with an
1125 instruction. One can extract line number information encoded in LLVM IR
1126 using <tt>Instruction::getMetadata()</tt> and
1127 <tt>DILocation::getLineNumber()</tt>.
1129 if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction
1130 DILocation Loc(N); // DILocation is in DebugInfo.h
1131 unsigned Line = Loc.getLineNumber();
1132 StringRef File = Loc.getFilename();
1133 StringRef Dir = Loc.getDirectory();
1138 <!-- ======================================================================= -->
1140 <a name="ccxx_global_variable">C/C++ global variable information</a>
1145 <p>Given an integer global variable declared as follows:</p>
1147 <div class="doc_code">
1153 <p>a C/C++ front-end would generate the following descriptors:</p>
1155 <div class="doc_code">
1158 ;; Define the global itself.
1160 %MyGlobal = global int 100
1163 ;; List of debug info of globals
1165 !llvm.dbg.gv = !{!0}
1168 ;; Define the global variable descriptor. Note the reference to the global
1169 ;; variable anchor and the global variable itself.
1174 metadata !1, ;; Context
1175 metadata !"MyGlobal", ;; Name
1176 metadata !"MyGlobal", ;; Display Name
1177 metadata !"MyGlobal", ;; Linkage Name
1178 metadata !3, ;; Compile Unit
1179 i32 1, ;; Line Number
1180 metadata !4, ;; Type
1181 i1 false, ;; Is a local variable
1182 i1 true, ;; Is this a definition
1183 i32* @MyGlobal ;; The global variable
1187 ;; Define the basic type of 32 bit signed integer. Note that since int is an
1188 ;; intrinsic type the source file is NULL and line 0.
1192 metadata !1, ;; Context
1193 metadata !"int", ;; Name
1194 metadata !1, ;; File
1195 i32 0, ;; Line number
1196 i64 32, ;; Size in Bits
1197 i64 32, ;; Align in Bits
1198 i64 0, ;; Offset in Bits
1208 <!-- ======================================================================= -->
1210 <a name="ccxx_subprogram">C/C++ function information</a>
1215 <p>Given a function declared as follows:</p>
1217 <div class="doc_code">
1219 int main(int argc, char *argv[]) {
1225 <p>a C/C++ front-end would generate the following descriptors:</p>
1227 <div class="doc_code">
1230 ;; Define the anchor for subprograms. Note that the second field of the
1231 ;; anchor is 46, which is the same as the tag for subprograms
1232 ;; (46 = DW_TAG_subprogram.)
1237 metadata !1, ;; Context
1238 metadata !"main", ;; Name
1239 metadata !"main", ;; Display name
1240 metadata !"main", ;; Linkage name
1241 metadata !1, ;; File
1242 i32 1, ;; Line number
1243 metadata !4, ;; Type
1244 i1 false, ;; Is local
1245 i1 true, ;; Is definition
1246 i32 0, ;; Virtuality attribute, e.g. pure virtual function
1247 i32 0, ;; Index into virtual table for C++ methods
1248 i32 0, ;; Type that holds virtual table.
1250 i1 false, ;; True if this function is optimized
1251 Function *, ;; Pointer to llvm::Function
1252 null ;; Function template parameters
1255 ;; Define the subprogram itself.
1257 define i32 @main(i32 %argc, i8** %argv) {
1265 <!-- ======================================================================= -->
1267 <a name="ccxx_basic_types">C/C++ basic types</a>
1272 <p>The following are the basic type descriptors for C/C++ core types:</p>
1274 <!-- ======================================================================= -->
1276 <a name="ccxx_basic_type_bool">bool</a>
1281 <div class="doc_code">
1285 metadata !1, ;; Context
1286 metadata !"bool", ;; Name
1287 metadata !1, ;; File
1288 i32 0, ;; Line number
1289 i64 8, ;; Size in Bits
1290 i64 8, ;; Align in Bits
1291 i64 0, ;; Offset in Bits
1300 <!-- ======================================================================= -->
1302 <a name="ccxx_basic_char">char</a>
1307 <div class="doc_code">
1311 metadata !1, ;; Context
1312 metadata !"char", ;; Name
1313 metadata !1, ;; File
1314 i32 0, ;; Line number
1315 i64 8, ;; Size in Bits
1316 i64 8, ;; Align in Bits
1317 i64 0, ;; Offset in Bits
1326 <!-- ======================================================================= -->
1328 <a name="ccxx_basic_unsigned_char">unsigned char</a>
1333 <div class="doc_code">
1337 metadata !1, ;; Context
1338 metadata !"unsigned char",
1339 metadata !1, ;; File
1340 i32 0, ;; Line number
1341 i64 8, ;; Size in Bits
1342 i64 8, ;; Align in Bits
1343 i64 0, ;; Offset in Bits
1352 <!-- ======================================================================= -->
1354 <a name="ccxx_basic_short">short</a>
1359 <div class="doc_code">
1363 metadata !1, ;; Context
1364 metadata !"short int",
1365 metadata !1, ;; File
1366 i32 0, ;; Line number
1367 i64 16, ;; Size in Bits
1368 i64 16, ;; Align in Bits
1369 i64 0, ;; Offset in Bits
1378 <!-- ======================================================================= -->
1380 <a name="ccxx_basic_unsigned_short">unsigned short</a>
1385 <div class="doc_code">
1389 metadata !1, ;; Context
1390 metadata !"short unsigned int",
1391 metadata !1, ;; File
1392 i32 0, ;; Line number
1393 i64 16, ;; Size in Bits
1394 i64 16, ;; Align in Bits
1395 i64 0, ;; Offset in Bits
1404 <!-- ======================================================================= -->
1406 <a name="ccxx_basic_int">int</a>
1411 <div class="doc_code">
1415 metadata !1, ;; Context
1416 metadata !"int", ;; Name
1417 metadata !1, ;; File
1418 i32 0, ;; Line number
1419 i64 32, ;; Size in Bits
1420 i64 32, ;; Align in Bits
1421 i64 0, ;; Offset in Bits
1429 <!-- ======================================================================= -->
1431 <a name="ccxx_basic_unsigned_int">unsigned int</a>
1436 <div class="doc_code">
1440 metadata !1, ;; Context
1441 metadata !"unsigned int",
1442 metadata !1, ;; File
1443 i32 0, ;; Line number
1444 i64 32, ;; Size in Bits
1445 i64 32, ;; Align in Bits
1446 i64 0, ;; Offset in Bits
1455 <!-- ======================================================================= -->
1457 <a name="ccxx_basic_long_long">long long</a>
1462 <div class="doc_code">
1466 metadata !1, ;; Context
1467 metadata !"long long int",
1468 metadata !1, ;; File
1469 i32 0, ;; Line number
1470 i64 64, ;; Size in Bits
1471 i64 64, ;; Align in Bits
1472 i64 0, ;; Offset in Bits
1481 <!-- ======================================================================= -->
1483 <a name="ccxx_basic_unsigned_long_long">unsigned long long</a>
1488 <div class="doc_code">
1492 metadata !1, ;; Context
1493 metadata !"long long unsigned int",
1494 metadata !1, ;; File
1495 i32 0, ;; Line number
1496 i64 64, ;; Size in Bits
1497 i64 64, ;; Align in Bits
1498 i64 0, ;; Offset in Bits
1507 <!-- ======================================================================= -->
1509 <a name="ccxx_basic_float">float</a>
1514 <div class="doc_code">
1518 metadata !1, ;; Context
1520 metadata !1, ;; File
1521 i32 0, ;; Line number
1522 i64 32, ;; Size in Bits
1523 i64 32, ;; Align in Bits
1524 i64 0, ;; Offset in Bits
1533 <!-- ======================================================================= -->
1535 <a name="ccxx_basic_double">double</a>
1540 <div class="doc_code">
1544 metadata !1, ;; Context
1545 metadata !"double",;; Name
1546 metadata !1, ;; File
1547 i32 0, ;; Line number
1548 i64 64, ;; Size in Bits
1549 i64 64, ;; Align in Bits
1550 i64 0, ;; Offset in Bits
1561 <!-- ======================================================================= -->
1563 <a name="ccxx_derived_types">C/C++ derived types</a>
1568 <p>Given the following as an example of C/C++ derived type:</p>
1570 <div class="doc_code">
1572 typedef const int *IntPtr;
1576 <p>a C/C++ front-end would generate the following descriptors:</p>
1578 <div class="doc_code">
1581 ;; Define the typedef "IntPtr".
1585 metadata !1, ;; Context
1586 metadata !"IntPtr", ;; Name
1587 metadata !3, ;; File
1588 i32 0, ;; Line number
1589 i64 0, ;; Size in bits
1590 i64 0, ;; Align in bits
1591 i64 0, ;; Offset in bits
1593 metadata !4 ;; Derived From type
1597 ;; Define the pointer type.
1601 metadata !1, ;; Context
1602 metadata !"", ;; Name
1603 metadata !1, ;; File
1604 i32 0, ;; Line number
1605 i64 64, ;; Size in bits
1606 i64 64, ;; Align in bits
1607 i64 0, ;; Offset in bits
1609 metadata !5 ;; Derived From type
1612 ;; Define the const type.
1616 metadata !1, ;; Context
1617 metadata !"", ;; Name
1618 metadata !1, ;; File
1619 i32 0, ;; Line number
1620 i64 32, ;; Size in bits
1621 i64 32, ;; Align in bits
1622 i64 0, ;; Offset in bits
1624 metadata !6 ;; Derived From type
1627 ;; Define the int type.
1631 metadata !1, ;; Context
1632 metadata !"int", ;; Name
1633 metadata !1, ;; File
1634 i32 0, ;; Line number
1635 i64 32, ;; Size in bits
1636 i64 32, ;; Align in bits
1637 i64 0, ;; Offset in bits
1646 <!-- ======================================================================= -->
1648 <a name="ccxx_composite_types">C/C++ struct/union types</a>
1653 <p>Given the following as an example of C/C++ struct type:</p>
1655 <div class="doc_code">
1665 <p>a C/C++ front-end would generate the following descriptors:</p>
1667 <div class="doc_code">
1670 ;; Define basic type for unsigned int.
1674 metadata !1, ;; Context
1675 metadata !"unsigned int",
1676 metadata !1, ;; File
1677 i32 0, ;; Line number
1678 i64 32, ;; Size in Bits
1679 i64 32, ;; Align in Bits
1680 i64 0, ;; Offset in Bits
1685 ;; Define composite type for struct Color.
1689 metadata !1, ;; Context
1690 metadata !"Color", ;; Name
1691 metadata !1, ;; Compile unit
1692 i32 1, ;; Line number
1693 i64 96, ;; Size in bits
1694 i64 32, ;; Align in bits
1695 i64 0, ;; Offset in bits
1697 null, ;; Derived From
1698 metadata !3, ;; Elements
1699 i32 0 ;; Runtime Language
1703 ;; Define the Red field.
1707 metadata !1, ;; Context
1708 metadata !"Red", ;; Name
1709 metadata !1, ;; File
1710 i32 2, ;; Line number
1711 i64 32, ;; Size in bits
1712 i64 32, ;; Align in bits
1713 i64 0, ;; Offset in bits
1715 metadata !5 ;; Derived From type
1719 ;; Define the Green field.
1723 metadata !1, ;; Context
1724 metadata !"Green", ;; Name
1725 metadata !1, ;; File
1726 i32 3, ;; Line number
1727 i64 32, ;; Size in bits
1728 i64 32, ;; Align in bits
1729 i64 32, ;; Offset in bits
1731 metadata !5 ;; Derived From type
1735 ;; Define the Blue field.
1739 metadata !1, ;; Context
1740 metadata !"Blue", ;; Name
1741 metadata !1, ;; File
1742 i32 4, ;; Line number
1743 i64 32, ;; Size in bits
1744 i64 32, ;; Align in bits
1745 i64 64, ;; Offset in bits
1747 metadata !5 ;; Derived From type
1751 ;; Define the array of fields used by the composite type Color.
1753 !3 = metadata !{metadata !4, metadata !6, metadata !7}
1759 <!-- ======================================================================= -->
1761 <a name="ccxx_enumeration_types">C/C++ enumeration types</a>
1766 <p>Given the following as an example of C/C++ enumeration type:</p>
1768 <div class="doc_code">
1778 <p>a C/C++ front-end would generate the following descriptors:</p>
1780 <div class="doc_code">
1783 ;; Define composite type for enum Trees
1787 metadata !1, ;; Context
1788 metadata !"Trees", ;; Name
1789 metadata !1, ;; File
1790 i32 1, ;; Line number
1791 i64 32, ;; Size in bits
1792 i64 32, ;; Align in bits
1793 i64 0, ;; Offset in bits
1795 null, ;; Derived From type
1796 metadata !3, ;; Elements
1797 i32 0 ;; Runtime language
1801 ;; Define the array of enumerators used by composite type Trees.
1803 !3 = metadata !{metadata !4, metadata !5, metadata !6}
1806 ;; Define Spruce enumerator.
1808 !4 = metadata !{i32 524328, metadata !"Spruce", i64 100}
1811 ;; Define Oak enumerator.
1813 !5 = metadata !{i32 524328, metadata !"Oak", i64 200}
1816 ;; Define Maple enumerator.
1818 !6 = metadata !{i32 524328, metadata !"Maple", i64 300}
1828 <!-- *********************************************************************** -->
1830 <a name="llvmdwarfextension">Debugging information format</a>
1832 <!-- *********************************************************************** -->
1834 <!-- ======================================================================= -->
1836 <a name="objcproperty">Debugging Information Extension for Objective C Properties</a>
1839 <!-- *********************************************************************** -->
1841 <a name="objcpropertyintroduction">Introduction</a>
1843 <!-- *********************************************************************** -->
1846 <p>Objective C provides a simpler way to declare and define accessor methods
1847 using declared properties. The language provides features to declare a
1848 property and to let compiler synthesize accessor methods.
1851 <p>The debugger lets developer inspect Objective C interfaces and their
1852 instance variables and class variables. However, the debugger does not know
1853 anything about the properties defined in Objective C interfaces. The debugger
1854 consumes information generated by compiler in DWARF format. The format does
1855 not support encoding of Objective C properties. This proposal describes DWARF
1856 extensions to encode Objective C properties, which the debugger can use to let
1857 developers inspect Objective C properties.
1863 <!-- *********************************************************************** -->
1865 <a name="objcpropertyproposal">Proposal</a>
1867 <!-- *********************************************************************** -->
1870 <p>Objective C properties exist separately from class members. A property
1871 can be defined only by "setter" and "getter" selectors, and
1872 be calculated anew on each access. Or a property can just be a direct access
1873 to some declared ivar. Finally it can have an ivar "automatically
1874 synthesized" for it by the compiler, in which case the property can be
1875 referred to in user code directly using the standard C dereference syntax as
1876 well as through the property "dot" syntax, but there is no entry in
1877 the @interface declaration corresponding to this ivar.
1880 To facilitate debugging, these properties we will add a new DWARF TAG into the
1881 DW_TAG_structure_type definition for the class to hold the description of a
1882 given property, and a set of DWARF attributes that provide said description.
1883 The property tag will also contain the name and declared type of the property.
1886 If there is a related ivar, there will also be a DWARF property attribute placed
1887 in the DW_TAG_member DIE for that ivar referring back to the property TAG for
1888 that property. And in the case where the compiler synthesizes the ivar directly,
1889 the compiler is expected to generate a DW_TAG_member for that ivar (with the
1890 DW_AT_artificial set to 1), whose name will be the name used to access this
1891 ivar directly in code, and with the property attribute pointing back to the
1892 property it is backing.
1895 The following examples will serve as illustration for our discussion:
1898 <div class="doc_code">
1910 @synthesize p2 = n2;
1916 This produces the following DWARF (this is a "pseudo dwarfdump" output):
1918 <div class="doc_code">
1920 0x00000100: TAG_structure_type [7] *
1921 AT_APPLE_runtime_class( 0x10 )
1923 AT_decl_file( "Objc_Property.m" )
1926 0x00000110 TAG_APPLE_property
1928 AT_type ( {0x00000150} ( int ) )
1930 0x00000120: TAG_APPLE_property
1932 AT_type ( {0x00000150} ( int ) )
1934 0x00000130: TAG_member [8]
1936 AT_APPLE_property ( {0x00000110} "p1" )
1937 AT_type( {0x00000150} ( int ) )
1938 AT_artificial ( 0x1 )
1940 0x00000140: TAG_member [8]
1942 AT_APPLE_property ( {0x00000120} "p2" )
1943 AT_type( {0x00000150} ( int ) )
1945 0x00000150: AT_type( ( int ) )
1949 <p> Note, the current convention is that the name of the ivar for an
1950 auto-synthesized property is the name of the property from which it derives with
1951 an underscore prepended, as is shown in the example.
1952 But we actually don't need to know this convention, since we are given the name
1953 of the ivar directly.
1957 Also, it is common practice in ObjC to have different property declarations in
1958 the @interface and @implementation - e.g. to provide a read-only property in
1959 the interface,and a read-write interface in the implementation. In that case,
1960 the compiler should emit whichever property declaration will be in force in the
1961 current translation unit.
1964 <p> Developers can decorate a property with attributes which are encoded using
1965 DW_AT_APPLE_property_attribute.
1968 <div class="doc_code">
1970 @property (readonly, nonatomic) int pr;
1974 Which produces a property tag:
1976 <div class="doc_code">
1978 TAG_APPLE_property [8]
1980 AT_type ( {0x00000147} (int) )
1981 AT_APPLE_property_attribute (DW_APPLE_PROPERTY_readonly, DW_APPLE_PROPERTY_nonatomic)
1985 <p> The setter and getter method names are attached to the property using
1986 DW_AT_APPLE_property_setter and DW_AT_APPLE_property_getter attributes.
1988 <div class="doc_code">
1991 @property (setter=myOwnP3Setter:) int p3;
1992 -(void)myOwnP3Setter:(int)a;
1997 -(void)myOwnP3Setter:(int)a{ }
2003 The DWARF for this would be:
2005 <div class="doc_code">
2007 0x000003bd: TAG_structure_type [7] *
2008 AT_APPLE_runtime_class( 0x10 )
2010 AT_decl_file( "Objc_Property.m" )
2013 0x000003cd TAG_APPLE_property
2015 AT_APPLE_property_setter ( "myOwnP3Setter:" )
2016 AT_type( {0x00000147} ( int ) )
2018 0x000003f3: TAG_member [8]
2020 AT_type ( {0x00000147} ( int ) )
2021 AT_APPLE_property ( {0x000003cd} )
2022 AT_artificial ( 0x1 )
2028 <!-- *********************************************************************** -->
2030 <a name="objcpropertynewtags">New DWARF Tags</a>
2032 <!-- *********************************************************************** -->
2035 <table border="1" cellspacing="0">
2037 <th width=200 >TAG</th>
2038 <th width=200 >Value</th>
2041 <td width=200 >DW_TAG_APPLE_property</td>
2042 <td width=200 >0x4200</td>
2048 <!-- *********************************************************************** -->
2050 <a name="objcpropertynewattributes">New DWARF Attributes</a>
2052 <!-- *********************************************************************** -->
2055 <table border="1" cellspacing="0">
2057 <th width=200 >Attribute</th>
2058 <th width=200 >Value</th>
2059 <th width=200 >Classes</th>
2062 <td width=200 >DW_AT_APPLE_property</td>
2063 <td width=200 >0x3fed</td>
2064 <td width=200 >Reference</td>
2067 <td width=200 >DW_AT_APPLE_property_getter</td>
2068 <td width=200 >0x3fe9</td>
2069 <td width=200 >String</td>
2072 <td width=200 >DW_AT_APPLE_property_setter</td>
2073 <td width=200 >0x3fea</td>
2074 <td width=200 >String</td>
2077 <td width=200 >DW_AT_APPLE_property_attribute</td>
2078 <td width=200 >0x3feb</td>
2079 <td width=200 >Constant</td>
2085 <!-- *********************************************************************** -->
2087 <a name="objcpropertynewconstants">New DWARF Constants</a>
2089 <!-- *********************************************************************** -->
2092 <table border="1" cellspacing="0">
2094 <th width=200 >Name</th>
2095 <th width=200 >Value</th>
2098 <td width=200 >DW_AT_APPLE_PROPERTY_readonly</td>
2099 <td width=200 >0x1</td>
2102 <td width=200 >DW_AT_APPLE_PROPERTY_readwrite</td>
2103 <td width=200 >0x2</td>
2106 <td width=200 >DW_AT_APPLE_PROPERTY_assign</td>
2107 <td width=200 >0x4</td>
2110 <td width=200 >DW_AT_APPLE_PROPERTY_retain</td>
2111 <td width=200 >0x8</td>
2114 <td width=200 >DW_AT_APPLE_PROPERTY_copy</td>
2115 <td width=200 >0x10</td>
2118 <td width=200 >DW_AT_APPLE_PROPERTY_nonatomic</td>
2119 <td width=200 >0x20</td>
2128 <!-- ======================================================================= -->
2130 <a name="acceltable">Name Accelerator Tables</a>
2132 <!-- ======================================================================= -->
2133 <!-- ======================================================================= -->
2135 <a name="acceltableintroduction">Introduction</a>
2137 <!-- ======================================================================= -->
2139 <p>The .debug_pubnames and .debug_pubtypes formats are not what a debugger
2140 needs. The "pub" in the section name indicates that the entries in the
2141 table are publicly visible names only. This means no static or hidden
2142 functions show up in the .debug_pubnames. No static variables or private class
2143 variables are in the .debug_pubtypes. Many compilers add different things to
2144 these tables, so we can't rely upon the contents between gcc, icc, or clang.</p>
2146 <p>The typical query given by users tends not to match up with the contents of
2147 these tables. For example, the DWARF spec states that "In the case of the
2148 name of a function member or static data member of a C++ structure, class or
2149 union, the name presented in the .debug_pubnames section is not the simple
2150 name given by the DW_AT_name attribute of the referenced debugging information
2151 entry, but rather the fully qualified name of the data or function member."
2152 So the only names in these tables for complex C++ entries is a fully
2153 qualified name. Debugger users tend not to enter their search strings as
2154 "a::b::c(int,const Foo&) const", but rather as "c", "b::c" , or "a::b::c". So
2155 the name entered in the name table must be demangled in order to chop it up
2156 appropriately and additional names must be manually entered into the table
2157 to make it effective as a name lookup table for debuggers to use.</p>
2159 <p>All debuggers currently ignore the .debug_pubnames table as a result of
2160 its inconsistent and useless public-only name content making it a waste of
2161 space in the object file. These tables, when they are written to disk, are
2162 not sorted in any way, leaving every debugger to do its own parsing
2163 and sorting. These tables also include an inlined copy of the string values
2164 in the table itself making the tables much larger than they need to be on
2165 disk, especially for large C++ programs.</p>
2167 <p>Can't we just fix the sections by adding all of the names we need to this
2168 table? No, because that is not what the tables are defined to contain and we
2169 won't know the difference between the old bad tables and the new good tables.
2170 At best we could make our own renamed sections that contain all of the data
2173 <p>These tables are also insufficient for what a debugger like LLDB needs.
2174 LLDB uses clang for its expression parsing where LLDB acts as a PCH. LLDB is
2175 then often asked to look for type "foo" or namespace "bar", or list items in
2176 namespace "baz". Namespaces are not included in the pubnames or pubtypes
2177 tables. Since clang asks a lot of questions when it is parsing an expression,
2178 we need to be very fast when looking up names, as it happens a lot. Having new
2179 accelerator tables that are optimized for very quick lookups will benefit
2180 this type of debugging experience greatly.</p>
2182 <p>We would like to generate name lookup tables that can be mapped into
2183 memory from disk, and used as is, with little or no up-front parsing. We would
2184 also be able to control the exact content of these different tables so they
2185 contain exactly what we need. The Name Accelerator Tables were designed
2186 to fix these issues. In order to solve these issues we need to:</p>
2189 <li>Have a format that can be mapped into memory from disk and used as is</li>
2190 <li>Lookups should be very fast</li>
2191 <li>Extensible table format so these tables can be made by many producers</li>
2192 <li>Contain all of the names needed for typical lookups out of the box</li>
2193 <li>Strict rules for the contents of tables</li>
2196 <p>Table size is important and the accelerator table format should allow the
2197 reuse of strings from common string tables so the strings for the names are
2198 not duplicated. We also want to make sure the table is ready to be used as-is
2199 by simply mapping the table into memory with minimal header parsing.</p>
2201 <p>The name lookups need to be fast and optimized for the kinds of lookups
2202 that debuggers tend to do. Optimally we would like to touch as few parts of
2203 the mapped table as possible when doing a name lookup and be able to quickly
2204 find the name entry we are looking for, or discover there are no matches. In
2205 the case of debuggers we optimized for lookups that fail most of the time.</p>
2207 <p>Each table that is defined should have strict rules on exactly what is in
2208 the accelerator tables and documented so clients can rely on the content.</p>
2212 <!-- ======================================================================= -->
2214 <a name="acceltablehashes">Hash Tables</a>
2216 <!-- ======================================================================= -->
2219 <h5>Standard Hash Tables</h5>
2221 <p>Typical hash tables have a header, buckets, and each bucket points to the
2225 <div class="doc_code">
2237 <p>The BUCKETS are an array of offsets to DATA for each hash:</p>
2239 <div class="doc_code">
2242 | 0x00001000 | BUCKETS[0]
2243 | 0x00002000 | BUCKETS[1]
2244 | 0x00002200 | BUCKETS[2]
2245 | 0x000034f0 | BUCKETS[3]
2247 | 0xXXXXXXXX | BUCKETS[n_buckets]
2252 <p>So for bucket[3] in the example above, we have an offset into the table
2253 0x000034f0 which points to a chain of entries for the bucket. Each bucket
2254 must contain a next pointer, full 32 bit hash value, the string itself,
2255 and the data for the current string value.</p>
2257 <div class="doc_code">
2260 0x000034f0: | 0x00003500 | next pointer
2261 | 0x12345678 | 32 bit hash
2262 | "erase" | string value
2263 | data[n] | HashData for this bucket
2265 0x00003500: | 0x00003550 | next pointer
2266 | 0x29273623 | 32 bit hash
2267 | "dump" | string value
2268 | data[n] | HashData for this bucket
2270 0x00003550: | 0x00000000 | next pointer
2271 | 0x82638293 | 32 bit hash
2272 | "main" | string value
2273 | data[n] | HashData for this bucket
2278 <p>The problem with this layout for debuggers is that we need to optimize for
2279 the negative lookup case where the symbol we're searching for is not present.
2280 So if we were to lookup "printf" in the table above, we would make a 32 hash
2281 for "printf", it might match bucket[3]. We would need to go to the offset
2282 0x000034f0 and start looking to see if our 32 bit hash matches. To do so, we
2283 need to read the next pointer, then read the hash, compare it, and skip to
2284 the next bucket. Each time we are skipping many bytes in memory and touching
2285 new cache pages just to do the compare on the full 32 bit hash. All of these
2286 accesses then tell us that we didn't have a match.</p>
2288 <h5>Name Hash Tables</h5>
2290 <p>To solve the issues mentioned above we have structured the hash tables
2291 a bit differently: a header, buckets, an array of all unique 32 bit hash
2292 values, followed by an array of hash value data offsets, one for each hash
2293 value, then the data for all hash values:</p>
2295 <div class="doc_code">
2311 <p>The BUCKETS in the name tables are an index into the HASHES array. By
2312 making all of the full 32 bit hash values contiguous in memory, we allow
2313 ourselves to efficiently check for a match while touching as little
2314 memory as possible. Most often checking the 32 bit hash values is as far as
2315 the lookup goes. If it does match, it usually is a match with no collisions.
2316 So for a table with "n_buckets" buckets, and "n_hashes" unique 32 bit hash
2317 values, we can clarify the contents of the BUCKETS, HASHES and OFFSETS as:</p>
2319 <div class="doc_code">
2321 .-------------------------.
2322 | HEADER.magic | uint32_t
2323 | HEADER.version | uint16_t
2324 | HEADER.hash_function | uint16_t
2325 | HEADER.bucket_count | uint32_t
2326 | HEADER.hashes_count | uint32_t
2327 | HEADER.header_data_len | uint32_t
2328 | HEADER_DATA | HeaderData
2329 |-------------------------|
2330 | BUCKETS | uint32_t[n_buckets] // 32 bit hash indexes
2331 |-------------------------|
2332 | HASHES | uint32_t[n_buckets] // 32 bit hash values
2333 |-------------------------|
2334 | OFFSETS | uint32_t[n_buckets] // 32 bit offsets to hash value data
2335 |-------------------------|
2337 `-------------------------'
2341 <p>So taking the exact same data from the standard hash example above we end up
2344 <div class="doc_code">
2354 | ... | BUCKETS[n_buckets]
2356 | 0x........ | HASHES[0]
2357 | 0x........ | HASHES[1]
2358 | 0x........ | HASHES[2]
2359 | 0x........ | HASHES[3]
2360 | 0x........ | HASHES[4]
2361 | 0x........ | HASHES[5]
2362 | 0x12345678 | HASHES[6] hash for BUCKETS[3]
2363 | 0x29273623 | HASHES[7] hash for BUCKETS[3]
2364 | 0x82638293 | HASHES[8] hash for BUCKETS[3]
2365 | 0x........ | HASHES[9]
2366 | 0x........ | HASHES[10]
2367 | 0x........ | HASHES[11]
2368 | 0x........ | HASHES[12]
2369 | 0x........ | HASHES[13]
2370 | 0x........ | HASHES[n_hashes]
2372 | 0x........ | OFFSETS[0]
2373 | 0x........ | OFFSETS[1]
2374 | 0x........ | OFFSETS[2]
2375 | 0x........ | OFFSETS[3]
2376 | 0x........ | OFFSETS[4]
2377 | 0x........ | OFFSETS[5]
2378 | 0x000034f0 | OFFSETS[6] offset for BUCKETS[3]
2379 | 0x00003500 | OFFSETS[7] offset for BUCKETS[3]
2380 | 0x00003550 | OFFSETS[8] offset for BUCKETS[3]
2381 | 0x........ | OFFSETS[9]
2382 | 0x........ | OFFSETS[10]
2383 | 0x........ | OFFSETS[11]
2384 | 0x........ | OFFSETS[12]
2385 | 0x........ | OFFSETS[13]
2386 | 0x........ | OFFSETS[n_hashes]
2394 0x000034f0: | 0x00001203 | .debug_str ("erase")
2395 | 0x00000004 | A 32 bit array count - number of HashData with name "erase"
2396 | 0x........ | HashData[0]
2397 | 0x........ | HashData[1]
2398 | 0x........ | HashData[2]
2399 | 0x........ | HashData[3]
2400 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2402 0x00003500: | 0x00001203 | String offset into .debug_str ("collision")
2403 | 0x00000002 | A 32 bit array count - number of HashData with name "collision"
2404 | 0x........ | HashData[0]
2405 | 0x........ | HashData[1]
2406 | 0x00001203 | String offset into .debug_str ("dump")
2407 | 0x00000003 | A 32 bit array count - number of HashData with name "dump"
2408 | 0x........ | HashData[0]
2409 | 0x........ | HashData[1]
2410 | 0x........ | HashData[2]
2411 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2413 0x00003550: | 0x00001203 | String offset into .debug_str ("main")
2414 | 0x00000009 | A 32 bit array count - number of HashData with name "main"
2415 | 0x........ | HashData[0]
2416 | 0x........ | HashData[1]
2417 | 0x........ | HashData[2]
2418 | 0x........ | HashData[3]
2419 | 0x........ | HashData[4]
2420 | 0x........ | HashData[5]
2421 | 0x........ | HashData[6]
2422 | 0x........ | HashData[7]
2423 | 0x........ | HashData[8]
2424 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2429 <p>So we still have all of the same data, we just organize it more efficiently
2430 for debugger lookup. If we repeat the same "printf" lookup from above, we
2431 would hash "printf" and find it matches BUCKETS[3] by taking the 32 bit hash
2432 value and modulo it by n_buckets. BUCKETS[3] contains "6" which is the index
2433 into the HASHES table. We would then compare any consecutive 32 bit hashes
2434 values in the HASHES array as long as the hashes would be in BUCKETS[3]. We
2435 do this by verifying that each subsequent hash value modulo n_buckets is still
2436 3. In the case of a failed lookup we would access the memory for BUCKETS[3], and
2437 then compare a few consecutive 32 bit hashes before we know that we have no match.
2438 We don't end up marching through multiple words of memory and we really keep the
2439 number of processor data cache lines being accessed as small as possible.</p>
2441 <p>The string hash that is used for these lookup tables is the Daniel J.
2442 Bernstein hash which is also used in the ELF GNU_HASH sections. It is a very
2443 good hash for all kinds of names in programs with very few hash collisions.</p>
2445 <p>Empty buckets are designated by using an invalid hash index of UINT32_MAX.</p>
2448 <!-- ======================================================================= -->
2450 <a name="acceltabledetails">Details</a>
2452 <!-- ======================================================================= -->
2454 <p>These name hash tables are designed to be generic where specializations of
2455 the table get to define additional data that goes into the header
2456 ("HeaderData"), how the string value is stored ("KeyType") and the content
2457 of the data for each hash value.</p>
2459 <h5>Header Layout</h5>
2460 <p>The header has a fixed part, and the specialized part. The exact format of
2462 <div class="doc_code">
2466 uint32_t magic; // 'HASH' magic value to allow endian detection
2467 uint16_t version; // Version number
2468 uint16_t hash_function; // The hash function enumeration that was used
2469 uint32_t bucket_count; // The number of buckets in this hash table
2470 uint32_t hashes_count; // The total number of unique hash values and hash data offsets in this table
2471 uint32_t header_data_len; // The bytes to skip to get to the hash indexes (buckets) for correct alignment
2472 // Specifically the length of the following HeaderData field - this does not
2473 // include the size of the preceding fields
2474 HeaderData header_data; // Implementation specific header data
2478 <p>The header starts with a 32 bit "magic" value which must be 'HASH' encoded as
2479 an ASCII integer. This allows the detection of the start of the hash table and
2480 also allows the table's byte order to be determined so the table can be
2481 correctly extracted. The "magic" value is followed by a 16 bit version number
2482 which allows the table to be revised and modified in the future. The current
2483 version number is 1. "hash_function" is a uint16_t enumeration that specifies
2484 which hash function was used to produce this table. The current values for the
2485 hash function enumerations include:</p>
2486 <div class="doc_code">
2488 enum HashFunctionType
2490 eHashFunctionDJB = 0u, // Daniel J Bernstein hash function
2494 <p>"bucket_count" is a 32 bit unsigned integer that represents how many buckets
2495 are in the BUCKETS array. "hashes_count" is the number of unique 32 bit hash
2496 values that are in the HASHES array, and is the same number of offsets are
2497 contained in the OFFSETS array. "header_data_len" specifies the size in
2498 bytes of the HeaderData that is filled in by specialized versions of this
2501 <h5>Fixed Lookup</h5>
2502 <p>The header is followed by the buckets, hashes, offsets, and hash value
2504 <div class="doc_code">
2508 uint32_t buckets[Header.bucket_count]; // An array of hash indexes into the "hashes[]" array below
2509 uint32_t hashes [Header.hashes_count]; // Every unique 32 bit hash for the entire table is in this table
2510 uint32_t offsets[Header.hashes_count]; // An offset that corresponds to each item in the "hashes[]" array above
2514 <p>"buckets" is an array of 32 bit indexes into the "hashes" array. The
2515 "hashes" array contains all of the 32 bit hash values for all names in the
2516 hash table. Each hash in the "hashes" table has an offset in the "offsets"
2517 array that points to the data for the hash value.</p>
2519 <p>This table setup makes it very easy to repurpose these tables to contain
2520 different data, while keeping the lookup mechanism the same for all tables.
2521 This layout also makes it possible to save the table to disk and map it in
2522 later and do very efficient name lookups with little or no parsing.</p>
2524 <p>DWARF lookup tables can be implemented in a variety of ways and can store
2525 a lot of information for each name. We want to make the DWARF tables
2526 extensible and able to store the data efficiently so we have used some of the
2527 DWARF features that enable efficient data storage to define exactly what kind
2528 of data we store for each name.</p>
2530 <p>The "HeaderData" contains a definition of the contents of each HashData
2531 chunk. We might want to store an offset to all of the debug information
2532 entries (DIEs) for each name. To keep things extensible, we create a list of
2533 items, or Atoms, that are contained in the data for each name. First comes the
2534 type of the data in each atom:</p>
2535 <div class="doc_code">
2540 eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
2541 eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that contains the item in question
2542 eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed 255) or DW_FORM_data2
2543 eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
2544 eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags
2548 <p>The enumeration values and their meanings are:</p>
2549 <div class="doc_code">
2551 eAtomTypeNULL - a termination atom that specifies the end of the atom list
2552 eAtomTypeDIEOffset - an offset into the .debug_info section for the DWARF DIE for this name
2553 eAtomTypeCUOffset - an offset into the .debug_info section for the CU that contains the DIE
2554 eAtomTypeDIETag - The DW_TAG_XXX enumeration value so you don't have to parse the DWARF to see what it is
2555 eAtomTypeNameFlags - Flags for functions and global variables (isFunction, isInlined, isExternal...)
2556 eAtomTypeTypeFlags - Flags for types (isCXXClass, isObjCClass, ...)
2559 <p>Then we allow each atom type to define the atom type and how the data for
2560 each atom type data is encoded:</p>
2561 <div class="doc_code">
2565 uint16_t type; // AtomType enum value
2566 uint16_t form; // DWARF DW_FORM_XXX defines
2570 <p>The "form" type above is from the DWARF specification and defines the
2571 exact encoding of the data for the Atom type. See the DWARF specification for
2572 the DW_FORM_ definitions.</p>
2573 <div class="doc_code">
2577 uint32_t die_offset_base;
2578 uint32_t atom_count;
2579 Atoms atoms[atom_count0];
2583 <p>"HeaderData" defines the base DIE offset that should be added to any atoms
2584 that are encoded using the DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4,
2585 DW_FORM_ref8 or DW_FORM_ref_udata. It also defines what is contained in
2586 each "HashData" object -- Atom.form tells us how large each field will be in
2587 the HashData and the Atom.type tells us how this data should be interpreted.</p>
2589 <p>For the current implementations of the ".apple_names" (all functions + globals),
2590 the ".apple_types" (names of all types that are defined), and the
2591 ".apple_namespaces" (all namespaces), we currently set the Atom array to be:</p>
2592 <div class="doc_code">
2594 HeaderData.atom_count = 1;
2595 HeaderData.atoms[0].type = eAtomTypeDIEOffset;
2596 HeaderData.atoms[0].form = DW_FORM_data4;
2599 <p>This defines the contents to be the DIE offset (eAtomTypeDIEOffset) that is
2600 encoded as a 32 bit value (DW_FORM_data4). This allows a single name to have
2601 multiple matching DIEs in a single file, which could come up with an inlined
2602 function for instance. Future tables could include more information about the
2603 DIE such as flags indicating if the DIE is a function, method, block,
2606 <p>The KeyType for the DWARF table is a 32 bit string table offset into the
2607 ".debug_str" table. The ".debug_str" is the string table for the DWARF which
2608 may already contain copies of all of the strings. This helps make sure, with
2609 help from the compiler, that we reuse the strings between all of the DWARF
2610 sections and keeps the hash table size down. Another benefit to having the
2611 compiler generate all strings as DW_FORM_strp in the debug info, is that
2612 DWARF parsing can be made much faster.</p>
2614 <p>After a lookup is made, we get an offset into the hash data. The hash data
2615 needs to be able to deal with 32 bit hash collisions, so the chunk of data
2616 at the offset in the hash data consists of a triple:</p>
2617 <div class="doc_code">
2620 uint32_t hash_data_count
2621 HashData[hash_data_count]
2624 <p>If "str_offset" is zero, then the bucket contents are done. 99.9% of the
2625 hash data chunks contain a single item (no 32 bit hash collision):</p>
2626 <div class="doc_code">
2629 | 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
2630 | 0x00000004 | uint32_t HashData count
2631 | 0x........ | uint32_t HashData[0] DIE offset
2632 | 0x........ | uint32_t HashData[1] DIE offset
2633 | 0x........ | uint32_t HashData[2] DIE offset
2634 | 0x........ | uint32_t HashData[3] DIE offset
2635 | 0x00000000 | uint32_t KeyType (end of hash chain)
2639 <p>If there are collisions, you will have multiple valid string offsets:</p>
2640 <div class="doc_code">
2643 | 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
2644 | 0x00000004 | uint32_t HashData count
2645 | 0x........ | uint32_t HashData[0] DIE offset
2646 | 0x........ | uint32_t HashData[1] DIE offset
2647 | 0x........ | uint32_t HashData[2] DIE offset
2648 | 0x........ | uint32_t HashData[3] DIE offset
2649 | 0x00002023 | uint32_t KeyType (.debug_str[0x0002023] => "print")
2650 | 0x00000002 | uint32_t HashData count
2651 | 0x........ | uint32_t HashData[0] DIE offset
2652 | 0x........ | uint32_t HashData[1] DIE offset
2653 | 0x00000000 | uint32_t KeyType (end of hash chain)
2657 <p>Current testing with real world C++ binaries has shown that there is around 1
2658 32 bit hash collision per 100,000 name entries.</p>
2660 <!-- ======================================================================= -->
2662 <a name="acceltablecontents">Contents</a>
2664 <!-- ======================================================================= -->
2666 <p>As we said, we want to strictly define exactly what is included in the
2667 different tables. For DWARF, we have 3 tables: ".apple_names", ".apple_types",
2668 and ".apple_namespaces".</p>
2670 <p>".apple_names" sections should contain an entry for each DWARF DIE whose
2671 DW_TAG is a DW_TAG_label, DW_TAG_inlined_subroutine, or DW_TAG_subprogram that
2672 has address attributes: DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges or
2673 DW_AT_entry_pc. It also contains DW_TAG_variable DIEs that have a DW_OP_addr
2674 in the location (global and static variables). All global and static variables
2675 should be included, including those scoped withing functions and classes. For
2676 example using the following code:</p>
2677 <div class="doc_code">
2687 <p>Both of the static "var" variables would be included in the table. All
2688 functions should emit both their full names and their basenames. For C or C++,
2689 the full name is the mangled name (if available) which is usually in the
2690 DW_AT_MIPS_linkage_name attribute, and the DW_AT_name contains the function
2691 basename. If global or static variables have a mangled name in a
2692 DW_AT_MIPS_linkage_name attribute, this should be emitted along with the
2693 simple name found in the DW_AT_name attribute.</p>
2695 <p>".apple_types" sections should contain an entry for each DWARF DIE whose
2698 <li>DW_TAG_array_type</li>
2699 <li>DW_TAG_class_type</li>
2700 <li>DW_TAG_enumeration_type</li>
2701 <li>DW_TAG_pointer_type</li>
2702 <li>DW_TAG_reference_type</li>
2703 <li>DW_TAG_string_type</li>
2704 <li>DW_TAG_structure_type</li>
2705 <li>DW_TAG_subroutine_type</li>
2706 <li>DW_TAG_typedef</li>
2707 <li>DW_TAG_union_type</li>
2708 <li>DW_TAG_ptr_to_member_type</li>
2709 <li>DW_TAG_set_type</li>
2710 <li>DW_TAG_subrange_type</li>
2711 <li>DW_TAG_base_type</li>
2712 <li>DW_TAG_const_type</li>
2713 <li>DW_TAG_constant</li>
2714 <li>DW_TAG_file_type</li>
2715 <li>DW_TAG_namelist</li>
2716 <li>DW_TAG_packed_type</li>
2717 <li>DW_TAG_volatile_type</li>
2718 <li>DW_TAG_restrict_type</li>
2719 <li>DW_TAG_interface_type</li>
2720 <li>DW_TAG_unspecified_type</li>
2721 <li>DW_TAG_shared_type</li>
2723 <p>Only entries with a DW_AT_name attribute are included, and the entry must
2724 not be a forward declaration (DW_AT_declaration attribute with a non-zero value).
2725 For example, using the following code:</p>
2726 <div class="doc_code">
2735 <p>We get a few type DIEs:</p>
2736 <div class="doc_code">
2738 0x00000067: TAG_base_type [5]
2739 AT_encoding( DW_ATE_signed )
2741 AT_byte_size( 0x04 )
2743 0x0000006e: TAG_pointer_type [6]
2744 AT_type( {0x00000067} ( int ) )
2745 AT_byte_size( 0x08 )
2748 <p>The DW_TAG_pointer_type is not included because it does not have a DW_AT_name.</p>
2750 <p>".apple_namespaces" section should contain all DW_TAG_namespace DIEs. If
2751 we run into a namespace that has no name this is an anonymous namespace,
2752 and the name should be output as "(anonymous namespace)" (without the quotes).
2753 Why? This matches the output of the abi::cxa_demangle() that is in the standard
2754 C++ library that demangles mangled names.</p>
2757 <!-- ======================================================================= -->
2759 <a name="acceltableextensions">Language Extensions and File Format Changes</a>
2761 <!-- ======================================================================= -->
2763 <h5>Objective-C Extensions</h5>
2764 <p>".apple_objc" section should contain all DW_TAG_subprogram DIEs for an
2765 Objective-C class. The name used in the hash table is the name of the
2766 Objective-C class itself. If the Objective-C class has a category, then an
2767 entry is made for both the class name without the category, and for the class
2768 name with the category. So if we have a DIE at offset 0x1234 with a name
2769 of method "-[NSString(my_additions) stringWithSpecialString:]", we would add
2770 an entry for "NSString" that points to DIE 0x1234, and an entry for
2771 "NSString(my_additions)" that points to 0x1234. This allows us to quickly
2772 track down all Objective-C methods for an Objective-C class when doing
2773 expressions. It is needed because of the dynamic nature of Objective-C where
2774 anyone can add methods to a class. The DWARF for Objective-C methods is also
2775 emitted differently from C++ classes where the methods are not usually
2776 contained in the class definition, they are scattered about across one or more
2777 compile units. Categories can also be defined in different shared libraries.
2778 So we need to be able to quickly find all of the methods and class functions
2779 given the Objective-C class name, or quickly find all methods and class
2780 functions for a class + category name. This table does not contain any selector
2781 names, it just maps Objective-C class names (or class names + category) to all
2782 of the methods and class functions. The selectors are added as function
2783 basenames in the .debug_names section.</p>
2785 <p>In the ".apple_names" section for Objective-C functions, the full name is the
2786 entire function name with the brackets ("-[NSString stringWithCString:]") and the
2787 basename is the selector only ("stringWithCString:").</p>
2789 <h5>Mach-O Changes</h5>
2790 <p>The sections names for the apple hash tables are for non mach-o files. For
2791 mach-o files, the sections should be contained in the "__DWARF" segment with
2792 names as follows:</p>
2794 <li>".apple_names" -> "__apple_names"</li>
2795 <li>".apple_types" -> "__apple_types"</li>
2796 <li>".apple_namespaces" -> "__apple_namespac" (16 character limit)</li>
2797 <li> ".apple_objc" -> "__apple_objc"</li>
2802 <!-- *********************************************************************** -->
2806 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
2807 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
2808 <a href="http://validator.w3.org/check/referer"><img
2809 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
2811 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
2812 <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br>
2813 Last modified: $Date$