blob: 45f7e2282220d454ed00f32be42fa1fa9ed867bf [file] [log] [blame]
Chris Lattner1811fca2004-01-05 05:06:33 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
Bill Wendlinge9353d72009-05-17 05:52:39 +00005 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Chris Lattner1811fca2004-01-05 05:06:33 +00006 <title>Source Level Debugging with LLVM</title>
Daniel Dunbar46d611a2012-04-19 20:20:34 +00007 <link rel="stylesheet" href="_static/llvm.css" type="text/css">
Chris Lattner1811fca2004-01-05 05:06:33 +00008</head>
9<body>
10
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +000011<h1>Source Level Debugging with LLVM</h1>
Chris Lattner1811fca2004-01-05 05:06:33 +000012
Reid Spencerc3c4c4f2004-11-01 08:19:36 +000013<table class="layout" style="width:100%">
14 <tr class="layout">
15 <td class="left">
Chris Lattner1811fca2004-01-05 05:06:33 +000016<ul>
Misha Brukmanf91d9942004-05-12 19:21:57 +000017 <li><a href="#introduction">Introduction</a>
Chris Lattner1811fca2004-01-05 05:06:33 +000018 <ol>
19 <li><a href="#phil">Philosophy behind LLVM debugging information</a></li>
Jim Laskey5dcfd562006-03-23 17:54:33 +000020 <li><a href="#consumers">Debug information consumers</a></li>
Chris Lattner1811fca2004-01-05 05:06:33 +000021 <li><a href="#debugopt">Debugging optimized code</a></li>
Misha Brukmanf91d9942004-05-12 19:21:57 +000022 </ol></li>
Misha Brukmanf91d9942004-05-12 19:21:57 +000023 <li><a href="#format">Debugging information format</a>
Chris Lattner1811fca2004-01-05 05:06:33 +000024 <ol>
Jim Laskey14edc932006-03-14 18:08:46 +000025 <li><a href="#debug_info_descriptors">Debug information descriptors</a>
Chris Lattner1811fca2004-01-05 05:06:33 +000026 <ul>
Jim Laskey14edc932006-03-14 18:08:46 +000027 <li><a href="#format_compile_units">Compile unit descriptors</a></li>
Devang Patel59445db2010-03-09 00:44:10 +000028 <li><a href="#format_files">File descriptors</a></li>
Jim Laskey14edc932006-03-14 18:08:46 +000029 <li><a href="#format_global_variables">Global variable descriptors</a></li>
30 <li><a href="#format_subprograms">Subprogram descriptors</a></li>
Jim Laskey9dcffe72006-03-15 19:10:52 +000031 <li><a href="#format_blocks">Block descriptors</a></li>
Jim Laskey14edc932006-03-14 18:08:46 +000032 <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>
Jim Laskey5dcfd562006-03-23 17:54:33 +000037 <li><a href="#format_variables">Local variables</a></li>
Misha Brukmanf91d9942004-05-12 19:21:57 +000038 </ul></li>
Jim Laskey14edc932006-03-14 18:08:46 +000039 <li><a href="#format_common_intrinsics">Debugger intrinsic functions</a>
40 <ul>
Jim Laskey14edc932006-03-14 18:08:46 +000041 <li><a href="#format_common_declare">llvm.dbg.declare</a></li>
Victor Hernandez0b62cc62010-01-11 22:53:48 +000042 <li><a href="#format_common_value">llvm.dbg.value</a></li>
Jim Laskey14edc932006-03-14 18:08:46 +000043 </ul></li>
Misha Brukmanf91d9942004-05-12 19:21:57 +000044 </ol></li>
Devang Patel4da997b2009-11-25 23:28:01 +000045 <li><a href="#format_common_lifetime">Object lifetimes and scoping</a></li>
Misha Brukmanf91d9942004-05-12 19:21:57 +000046 <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a>
Chris Lattner1811fca2004-01-05 05:06:33 +000047 <ol>
Jim Laskey14edc932006-03-14 18:08:46 +000048 <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>
Misha Brukmanf91d9942004-05-12 19:21:57 +000055 </ol></li>
Devang Patel8cd89642011-11-15 22:59:54 +000056 <li><a href="#llvmdwarfextension">LLVM Dwarf Extensions</a>
57 <ol>
Eric Christopher5acc7c12012-03-06 02:25:36 +000058 <li><a href="#objcproperty">Debugging Information Extension
Bill Wendling23d60ac2012-03-06 09:17:39 +000059 for Objective C Properties</a>
60 <ul>
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>
65 </ul>
66 </li>
67 <li><a href="#acceltable">Name Accelerator Tables</a>
68 <ul>
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>
74 </ul>
75 </li>
Devang Patel8cd89642011-11-15 22:59:54 +000076 </ol>
77 </li>
Chris Lattner1811fca2004-01-05 05:06:33 +000078</ul>
Misha Brukmanf91d9942004-05-12 19:21:57 +000079</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +000080<td class="right">
Misha Brukman3c1f8e72004-05-12 21:26:16 +000081<img src="img/venusflytrap.jpg" alt="A leafy and green bug eater" width="247"
Misha Brukmanf91d9942004-05-12 19:21:57 +000082height="369">
83</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +000084</tr></table>
Misha Brukmanf91d9942004-05-12 19:21:57 +000085
Chris Lattner020e1fc2004-05-23 21:07:27 +000086<div class="doc_author">
Jim Laskey14edc932006-03-14 18:08:46 +000087 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
Jim Laskey6e8a2f42007-03-14 19:32:21 +000088 and <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
Chris Lattner020e1fc2004-05-23 21:07:27 +000089</div>
90
Chris Lattner1811fca2004-01-05 05:06:33 +000091
92<!-- *********************************************************************** -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +000093<h2><a name="introduction">Introduction</a></h2>
Misha Brukmancda6a9b2004-12-09 20:27:37 +000094<!-- *********************************************************************** -->
Chris Lattner1811fca2004-01-05 05:06:33 +000095
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +000096<div>
Chris Lattner1811fca2004-01-05 05:06:33 +000097
98<p>This document is the central repository for all information pertaining to
Bill Wendlinge9353d72009-05-17 05:52:39 +000099 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.
Chris Lattnercb3f64f2009-07-18 21:47:15 +0000102 Further, this document provides specific examples of what debug information
Chris Lattner92ec3d12011-01-18 06:12:10 +0000103 for C/C++ looks like.</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000104
Chris Lattner1811fca2004-01-05 05:06:33 +0000105<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000106<h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000107 <a name="phil">Philosophy behind LLVM debugging information</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000108</h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000109
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000110<div>
Chris Lattner1811fca2004-01-05 05:06:33 +0000111
Misha Brukmanf91d9942004-05-12 19:21:57 +0000112<p>The idea of the LLVM debugging information is to capture how the important
Bill Wendlinge9353d72009-05-17 05:52:39 +0000113 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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000116
Misha Brukmanf91d9942004-05-12 19:21:57 +0000117<ul>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000118 <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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000121
Bill Wendlinge9353d72009-05-17 05:52:39 +0000122 <li>LLVM optimizations should interact in <a href="#debugopt">well-defined and
123 easily described ways</a> with the debugging information.</li>
Chris Lattner1811fca2004-01-05 05:06:33 +0000124
Bill Wendlinge9353d72009-05-17 05:52:39 +0000125 <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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000128
Bill Wendlinge9353d72009-05-17 05:52:39 +0000129 <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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000132
Bill Wendlinge9353d72009-05-17 05:52:39 +0000133 <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>
Misha Brukmanf91d9942004-05-12 19:21:57 +0000137</ul>
Chris Lattner1811fca2004-01-05 05:06:33 +0000138
Bill Wendlinge9353d72009-05-17 05:52:39 +0000139<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
Devang Patel80ae3492009-08-28 23:24:31 +0000142 description of the source-level program is maintained in LLVM metadata
143 in an <a href="#ccxx_frontend">implementation-defined format</a>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000144 (the C/C++ front-end currently uses working draft 7 of
145 the <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3
146 standard</a>).</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000147
Jim Laskey14edc932006-03-14 18:08:46 +0000148<p>When a program is being debugged, a debugger interacts with the user and
Bill Wendlinge9353d72009-05-17 05:52:39 +0000149 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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000152
153</div>
154
Chris Lattner1811fca2004-01-05 05:06:33 +0000155<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000156<h3>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000157 <a name="consumers">Debug information consumers</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000158</h3>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000159
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000160<div>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000161
Jim Laskey5dcfd562006-03-23 17:54:33 +0000162<p>The role of debug information is to provide meta information normally
Bill Wendlinge9353d72009-05-17 05:52:39 +0000163 stripped away during the compilation process. This meta information provides
164 an LLVM user a relationship between generated code and the original program
165 source code.</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000166
Chris Lattner904f2172010-04-05 04:11:11 +0000167<p>Currently, debug information is consumed by DwarfDebug to produce dwarf
Bill Wendlinge9353d72009-05-17 05:52:39 +0000168 information used by the gdb debugger. Other targets could use the same
169 information to produce stabs or other debug forms.</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000170
171<p>It would also be reasonable to use debug information to feed profiling tools
Bill Wendlinge9353d72009-05-17 05:52:39 +0000172 for analysis of generated code, or, tools for reconstructing the original
173 source from generated code.</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000174
175<p>TODO - expound a bit more.</p>
176
177</div>
178
179<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000180<h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000181 <a name="debugopt">Debugging optimized code</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000182</h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000183
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000184<div>
Chris Lattner1811fca2004-01-05 05:06:33 +0000185
Misha Brukmanf91d9942004-05-12 19:21:57 +0000186<p>An extremely high priority of LLVM debugging information is to make it
Bill Wendlinge9353d72009-05-17 05:52:39 +0000187 interact well with optimizations and analysis. In particular, the LLVM debug
188 information provides the following guarantees:</p>
Misha Brukmanf91d9942004-05-12 19:21:57 +0000189
190<ul>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000191 <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
197 deleted.</li>
Chris Lattner1811fca2004-01-05 05:06:33 +0000198
Bill Wendlinge9353d72009-05-17 05:52:39 +0000199 <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
203 code.</li>
Chris Lattner1811fca2004-01-05 05:06:33 +0000204
Devang Patel5c26a852011-05-31 17:45:27 +0000205 <li>LLVM debug information does not prevent optimizations from
Bill Wendlinge9353d72009-05-17 05:52:39 +0000206 happening (for example inlining, basic block reordering/merging/cleanup,
Devang Patel1d81ea82011-05-31 18:06:14 +0000207 tail duplication, etc).</li>
Chris Lattner1811fca2004-01-05 05:06:33 +0000208
Bill Wendlinge9353d72009-05-17 05:52:39 +0000209 <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>
Misha Brukmanf91d9942004-05-12 19:21:57 +0000213</ul>
Chris Lattner1811fca2004-01-05 05:06:33 +0000214
Misha Brukmanf91d9942004-05-12 19:21:57 +0000215<p>Basically, the debug information allows you to compile a program with
Bill Wendlinge9353d72009-05-17 05:52:39 +0000216 "<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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000223
Misha Brukman39dcddf2008-12-16 02:54:22 +0000224<p><a href="TestingGuide.html#quicktestsuite">LLVM test suite</a> provides a
Bill Wendlinge9353d72009-05-17 05:52:39 +0000225 framework to test optimizer's handling of debugging information. It can be
226 run like this:</p>
Devang Patelb885a912008-11-21 19:35:57 +0000227
228<div class="doc_code">
229<pre>
230% cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level
231% make TEST=dbgopt
232</pre>
233</div>
234
Bill Wendlinge9353d72009-05-17 05:52:39 +0000235<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>
Devang Patelb885a912008-11-21 19:35:57 +0000239
Chris Lattner1811fca2004-01-05 05:06:33 +0000240</div>
241
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000242</div>
243
Chris Lattner1811fca2004-01-05 05:06:33 +0000244<!-- *********************************************************************** -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000245<h2>
Chris Lattner941515c2004-01-06 05:31:32 +0000246 <a name="format">Debugging information format</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000247</h2>
Chris Lattner1811fca2004-01-05 05:06:33 +0000248<!-- *********************************************************************** -->
249
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000250<div>
Chris Lattner1811fca2004-01-05 05:06:33 +0000251
252<p>LLVM debugging information has been carefully designed to make it possible
Bill Wendlinge9353d72009-05-17 05:52:39 +0000253 for the optimizer to optimize the program and debugging information without
254 necessarily having to know anything about debugging information. In
John Criswell2a4b0802010-03-17 15:01:50 +0000255 particular, the use of metadata avoids duplicated debugging information from
Eric Christopher5acc7c12012-03-06 02:25:36 +0000256 the beginning, and the global dead code elimination pass automatically
257 deletes debugging information for a function if it decides to delete the
Devang Patel80ae3492009-08-28 23:24:31 +0000258 function. </p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000259
260<p>To do this, most of the debugging information (descriptors for types,
Bill Wendlinge9353d72009-05-17 05:52:39 +0000261 variables, functions, source files, etc) is inserted by the language
Devang Patel80ae3492009-08-28 23:24:31 +0000262 front-end in the form of LLVM metadata. </p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000263
Jim Laskey14edc932006-03-14 18:08:46 +0000264<p>Debug information is designed to be agnostic about the target debugger and
Bill Wendlinge9353d72009-05-17 05:52:39 +0000265 debugging information representation (e.g. DWARF/Stabs/etc). It uses a
Eric Christopher5acc7c12012-03-06 02:25:36 +0000266 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
Devang Patel80ae3492009-08-28 23:24:31 +0000269 written for the target debugger to interpret the information. </p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000270
Misha Brukmanf91d9942004-05-12 19:21:57 +0000271<p>To provide basic functionality, the LLVM debugger does have to make some
Bill Wendlinge9353d72009-05-17 05:52:39 +0000272 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
Devang Patel59445db2010-03-09 00:44:10 +0000274 exist are <a href="#format_files">source files</a>,
Bill Wendlinge9353d72009-05-17 05:52:39 +0000275 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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000278
279<p>This section of the documentation first describes the representation aspects
Bill Wendlinge9353d72009-05-17 05:52:39 +0000280 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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000282
Chris Lattner1811fca2004-01-05 05:06:33 +0000283<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000284<h3>
Jim Laskey14edc932006-03-14 18:08:46 +0000285 <a name="debug_info_descriptors">Debug information descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000286</h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000287
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000288<div>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000289
Jim Laskey14edc932006-03-14 18:08:46 +0000290<p>In consideration of the complexity and volume of debug information, LLVM
Devang Patel80ae3492009-08-28 23:24:31 +0000291 provides a specification for well formed debug descriptors. </p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000292
Jim Laskey14edc932006-03-14 18:08:46 +0000293<p>Consumers of LLVM debug information expect the descriptors for program
Bill Wendlinge9353d72009-05-17 05:52:39 +0000294 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
Benjamin Kramer0f420382009-10-12 14:46:08 +0000301 the range 0x1000 through 0x2000 (there is a defined enum DW_TAG_user_base =
Bill Wendlinge9353d72009-05-17 05:52:39 +0000302 0x1000.)</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000303
Eric Christopher5acc7c12012-03-06 02:25:36 +0000304<p>The fields of debug descriptors used internally by LLVM
Nick Lewyckya87014f2010-03-31 07:50:17 +0000305 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>
Chris Lattner1811fca2004-01-05 05:06:33 +0000307
Bill Wendlinge9353d72009-05-17 05:52:39 +0000308<div class="doc_code">
Misha Brukmanf91d9942004-05-12 19:21:57 +0000309<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000310!1 = metadata !{
Nick Lewyckya87014f2010-03-31 07:50:17 +0000311 i32, ;; A tag
Bill Wendlinge9353d72009-05-17 05:52:39 +0000312 ...
313}
Misha Brukmanf91d9942004-05-12 19:21:57 +0000314</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000315</div>
Chris Lattner1811fca2004-01-05 05:06:33 +0000316
Jim Laskeyb2ff2d42006-06-16 13:14:03 +0000317<p><a name="LLVMDebugVersion">The first field of a descriptor is always an
Nick Lewyckya87014f2010-03-31 07:50:17 +0000318 <tt>i32</tt> containing a tag value identifying the content of the
Bill Wendlinge9353d72009-05-17 05:52:39 +0000319 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
Nick Lewyckyf6e37112011-07-25 21:13:23 +0000323 with the current debug version (LLVMDebugVersion = 8 &lt;&lt; 16 or
324 0x80000 or 524288.)</a></p>
Jim Laskey14edc932006-03-14 18:08:46 +0000325
Eric Christopher5acc7c12012-03-06 02:25:36 +0000326<p>The details of the various descriptors follow.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000327
Jim Laskey14edc932006-03-14 18:08:46 +0000328<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000329<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000330 <a name="format_compile_units">Compile unit descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000331</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000332
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000333<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000334
Bill Wendlinge9353d72009-05-17 05:52:39 +0000335<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000336<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000337!0 = metadata !{
Eric Christopher5acc7c12012-03-06 02:25:36 +0000338 i32, ;; Tag = 17 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel80ae3492009-08-28 23:24:31 +0000339 ;; (DW_TAG_compile_unit)
Eric Christopher5acc7c12012-03-06 02:25:36 +0000340 i32, ;; Unused field.
341 i32, ;; DWARF language identifier (ex. DW_LANG_C89)
Devang Patel80ae3492009-08-28 23:24:31 +0000342 metadata, ;; Source file name
343 metadata, ;; Source file directory (includes trailing slash)
344 metadata ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
Eric Christopher5acc7c12012-03-06 02:25:36 +0000345 i1, ;; True if this is a main compile unit.
Devang Patel80ae3492009-08-28 23:24:31 +0000346 i1, ;; True if this is optimized.
347 metadata, ;; Flags
348 i32 ;; Runtime version
Devang Patel24a674b2011-09-09 17:07:15 +0000349 metadata ;; List of enums types
350 metadata ;; List of retained types
351 metadata ;; List of subprograms
352 metadata ;; List of global variables
Bill Wendlinge9353d72009-05-17 05:52:39 +0000353}
Jim Laskey14edc932006-03-14 18:08:46 +0000354</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000355</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000356
Bill Wendlinge9353d72009-05-17 05:52:39 +0000357<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>
Jim Laskey14edc932006-03-14 18:08:46 +0000362
Bill Wendlinge9353d72009-05-17 05:52:39 +0000363<p>Compile unit descriptors provide the root context for objects declared in a
Devang Patel09fa69e2011-05-03 16:18:28 +0000364 specific compilation unit. File descriptors are defined using this context.
Eric Christopher5acc7c12012-03-06 02:25:36 +0000365 These descriptors are collected by a named metadata
Devang Patel24a674b2011-09-09 17:07:15 +0000366 <tt>!llvm.dbg.cu</tt>. Compile unit descriptor keeps track of subprograms,
367 global variables and type information.
Jim Laskey14edc932006-03-14 18:08:46 +0000368
Devang Patel59445db2010-03-09 00:44:10 +0000369</div>
370
371<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000372<h4>
Devang Patel59445db2010-03-09 00:44:10 +0000373 <a name="format_files">File descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000374</h4>
Devang Patel59445db2010-03-09 00:44:10 +0000375
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000376<div>
Devang Patel59445db2010-03-09 00:44:10 +0000377
378<div class="doc_code">
379<pre>
380!0 = metadata !{
Eric Christopher5acc7c12012-03-06 02:25:36 +0000381 i32, ;; Tag = 41 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel59445db2010-03-09 00:44:10 +0000382 ;; (DW_TAG_file_type)
383 metadata, ;; Source file name
384 metadata, ;; Source file directory (includes trailing slash)
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000385 metadata ;; Unused
Devang Patel59445db2010-03-09 00:44:10 +0000386}
387</pre>
388</div>
389
John Criswell2a4b0802010-03-17 15:01:50 +0000390<p>These descriptors contain information for a file. Global variables and top
Devang Patel59445db2010-03-09 00:44:10 +0000391 level functions would be defined using this context.k File descriptors also
392 provide context for source line correspondence. </p>
393
394<p>Each input file is encoded as a separate file descriptor in LLVM debugging
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000395 information output. </p>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000396
Jim Laskey14edc932006-03-14 18:08:46 +0000397</div>
398
399<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000400<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000401 <a name="format_global_variables">Global variable descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000402</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000403
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000404<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000405
Bill Wendlinge9353d72009-05-17 05:52:39 +0000406<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000407<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000408!1 = metadata !{
Eric Christopher5acc7c12012-03-06 02:25:36 +0000409 i32, ;; Tag = 52 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel80ae3492009-08-28 23:24:31 +0000410 ;; (DW_TAG_variable)
411 i32, ;; Unused field.
412 metadata, ;; Reference to context descriptor
413 metadata, ;; Name
414 metadata, ;; Display name (fully qualified C++ name)
415 metadata, ;; MIPS linkage name (for C++)
Devang Patel59445db2010-03-09 00:44:10 +0000416 metadata, ;; Reference to file where defined
Devang Patel80ae3492009-08-28 23:24:31 +0000417 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)
Dan Gohmanaabfdb32010-05-28 17:13:49 +0000421 {}* ;; Reference to the global variable
Bill Wendlinge9353d72009-05-17 05:52:39 +0000422}
Jim Laskey14edc932006-03-14 18:08:46 +0000423</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000424</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000425
426<p>These descriptors provide debug information about globals variables. The
Devang Patel1c6b6812011-03-29 17:27:08 +0000427provide details such as name, type and where the variable is defined. All
Eric Christopher885ed822012-03-26 01:56:34 +0000428global variables are collected inside the named metadata
429<tt>!llvm.dbg.cu</tt>.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000430
431</div>
432
433<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000434<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000435 <a name="format_subprograms">Subprogram descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000436</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000437
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000438<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000439
Bill Wendlinge9353d72009-05-17 05:52:39 +0000440<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000441<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000442!2 = metadata !{
443 i32, ;; Tag = 46 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
444 ;; (DW_TAG_subprogram)
445 i32, ;; Unused field.
446 metadata, ;; Reference to context descriptor
447 metadata, ;; Name
448 metadata, ;; Display name (fully qualified C++ name)
449 metadata, ;; MIPS linkage name (for C++)
Devang Patel59445db2010-03-09 00:44:10 +0000450 metadata, ;; Reference to file where defined
Devang Patel80ae3492009-08-28 23:24:31 +0000451 i32, ;; Line number where defined
452 metadata, ;; Reference to type descriptor
453 i1, ;; True if the global is local to compile unit (static)
Devang Patel1d6bbd42011-04-22 23:10:17 +0000454 i1, ;; True if the global is defined in the compile unit (not extern)
Eric Christopher34164192012-04-03 00:43:49 +0000455 i32, ;; Line number where the scope of the subprogram begins
Devang Patel1d6bbd42011-04-22 23:10:17 +0000456 i32, ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
457 i32, ;; Index into a virtual function
Eric Christopher5acc7c12012-03-06 02:25:36 +0000458 metadata, ;; indicates which base type contains the vtable pointer for the
Devang Patele89b7592010-06-04 22:49:55 +0000459 ;; derived class
Devang Patelc16e1ed2011-12-16 17:50:04 +0000460 i32, ;; Flags - Artifical, Private, Protected, Explicit, Prototyped.
Devang Patel1d6bbd42011-04-22 23:10:17 +0000461 i1, ;; isOptimized
462 Function *,;; Pointer to LLVM function
463 metadata, ;; Lists function template parameters
464 metadata ;; Function declaration descriptor
Devang Patel59e27c52011-08-19 23:28:12 +0000465 metadata ;; List of function variables
Bill Wendlinge9353d72009-05-17 05:52:39 +0000466}
Jim Laskey14edc932006-03-14 18:08:46 +0000467</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000468</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000469
470<p>These descriptors provide debug information about functions, methods and
Bill Wendlinge9353d72009-05-17 05:52:39 +0000471 subprograms. They provide details such as name, return types and the source
Devang Patel1c6b6812011-03-29 17:27:08 +0000472 location where the subprogram is defined.
Devang Patel1c6b6812011-03-29 17:27:08 +0000473</p>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000474
475</div>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000476
Jim Laskey9dcffe72006-03-15 19:10:52 +0000477<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000478<h4>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000479 <a name="format_blocks">Block descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000480</h4>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000481
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000482<div>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000483
Bill Wendlinge9353d72009-05-17 05:52:39 +0000484<div class="doc_code">
Jim Laskey9dcffe72006-03-15 19:10:52 +0000485<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000486!3 = metadata !{
Devang Patel9fbc6802010-10-04 16:51:59 +0000487 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
Devang Patelcac38902010-10-01 22:45:00 +0000488 metadata,;; Reference to context descriptor
489 i32, ;; Line number
Devang Patelfb30b852011-03-08 16:25:29 +0000490 i32, ;; Column number
491 metadata,;; Reference to source file
492 i32 ;; Unique ID to identify blocks from a template function
Bill Wendlinge9353d72009-05-17 05:52:39 +0000493}
Jim Laskey9dcffe72006-03-15 19:10:52 +0000494</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000495</div>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000496
Eric Christopher6647b832011-10-11 22:59:11 +0000497<p>This descriptor provides debug information about nested blocks within a
Devang Patelcac38902010-10-01 22:45:00 +0000498 subprogram. The line number and column numbers are used to dinstinguish
499 two lexical blocks at same depth. </p>
Jim Laskey9dcffe72006-03-15 19:10:52 +0000500
Eric Christopher6647b832011-10-11 22:59:11 +0000501<div class="doc_code">
502<pre>
503!3 = metadata !{
504 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
505 metadata ;; Reference to the scope we're annotating with a file change
506 metadata,;; Reference to the file the scope is enclosed in.
507}
508</pre>
509</div>
510
511<p>This descriptor provides a wrapper around a lexical scope to handle file
512 changes in the middle of a lexical block.</p>
513
Jim Laskey14edc932006-03-14 18:08:46 +0000514</div>
515
516<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000517<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000518 <a name="format_basic_type">Basic type descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000519</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000520
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000521<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000522
Bill Wendlinge9353d72009-05-17 05:52:39 +0000523<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000524<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000525!4 = metadata !{
Eric Christopher5acc7c12012-03-06 02:25:36 +0000526 i32, ;; Tag = 36 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel80ae3492009-08-28 23:24:31 +0000527 ;; (DW_TAG_base_type)
Eric Christopher5acc7c12012-03-06 02:25:36 +0000528 metadata, ;; Reference to context
Devang Patel80ae3492009-08-28 23:24:31 +0000529 metadata, ;; Name (may be "" for anonymous types)
Devang Patel59445db2010-03-09 00:44:10 +0000530 metadata, ;; Reference to file where defined (may be NULL)
Devang Patel80ae3492009-08-28 23:24:31 +0000531 i32, ;; Line number where defined (may be 0)
532 i64, ;; Size in bits
533 i64, ;; Alignment in bits
534 i64, ;; Offset in bits
535 i32, ;; Flags
536 i32 ;; DWARF type encoding
Bill Wendlinge9353d72009-05-17 05:52:39 +0000537}
Jim Laskey14edc932006-03-14 18:08:46 +0000538</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000539</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000540
541<p>These descriptors define primitive types used in the code. Example int, bool
Bill Wendlinge9353d72009-05-17 05:52:39 +0000542 and float. The context provides the scope of the type, which is usually the
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000543 top level. Since basic types are not usually user defined the context
Bill Wendlinge9353d72009-05-17 05:52:39 +0000544 and line number can be left as NULL and 0. The size, alignment and offset
545 are expressed in bits and can be 64 bit values. The alignment is used to
546 round the offset when embedded in a
547 <a href="#format_composite_type">composite type</a> (example to keep float
548 doubles on 64 bit boundaries.) The offset is the bit offset if embedded in
549 a <a href="#format_composite_type">composite type</a>.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000550
551<p>The type encoding provides the details of the type. The values are typically
Bill Wendlinge9353d72009-05-17 05:52:39 +0000552 one of the following:</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000553
Bill Wendlinge9353d72009-05-17 05:52:39 +0000554<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000555<pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000556DW_ATE_address = 1
557DW_ATE_boolean = 2
558DW_ATE_float = 4
559DW_ATE_signed = 5
560DW_ATE_signed_char = 6
561DW_ATE_unsigned = 7
562DW_ATE_unsigned_char = 8
Jim Laskey14edc932006-03-14 18:08:46 +0000563</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000564</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000565
566</div>
567
568<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000569<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000570 <a name="format_derived_type">Derived type descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000571</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000572
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000573<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000574
Bill Wendlinge9353d72009-05-17 05:52:39 +0000575<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000576<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000577!5 = metadata !{
578 i32, ;; Tag (see below)
579 metadata, ;; Reference to context
580 metadata, ;; Name (may be "" for anonymous types)
Devang Patel59445db2010-03-09 00:44:10 +0000581 metadata, ;; Reference to file where defined (may be NULL)
Devang Patel80ae3492009-08-28 23:24:31 +0000582 i32, ;; Line number where defined (may be 0)
Devang Patelbed5e7d2010-10-01 19:19:30 +0000583 i64, ;; Size in bits
584 i64, ;; Alignment in bits
585 i64, ;; Offset in bits
Eric Christopher3e3ecd02011-12-16 23:42:33 +0000586 i32, ;; Flags to encode attributes, e.g. private
Devang Patel514b4002011-04-16 00:11:51 +0000587 metadata, ;; Reference to type derived from
Eric Christopher5acc7c12012-03-06 02:25:36 +0000588 metadata, ;; (optional) Name of the Objective C property associated with
589 ;; Objective-C an ivar
Devang Patel514b4002011-04-16 00:11:51 +0000590 metadata, ;; (optional) Name of the Objective C property getter selector.
591 metadata, ;; (optional) Name of the Objective C property setter selector.
592 i32 ;; (optional) Objective C property attributes.
Bill Wendlinge9353d72009-05-17 05:52:39 +0000593}
Jim Laskey14edc932006-03-14 18:08:46 +0000594</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000595</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000596
597<p>These descriptors are used to define types derived from other types. The
598value of the tag varies depending on the meaning. The following are possible
Misha Brukman39dcddf2008-12-16 02:54:22 +0000599tag values:</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000600
Bill Wendlinge9353d72009-05-17 05:52:39 +0000601<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000602<pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000603DW_TAG_formal_parameter = 5
604DW_TAG_member = 13
605DW_TAG_pointer_type = 15
606DW_TAG_reference_type = 16
607DW_TAG_typedef = 22
608DW_TAG_const_type = 38
609DW_TAG_volatile_type = 53
610DW_TAG_restrict_type = 55
Jim Laskey14edc932006-03-14 18:08:46 +0000611</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000612</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000613
Bill Wendlinge9353d72009-05-17 05:52:39 +0000614<p><tt>DW_TAG_member</tt> is used to define a member of
615 a <a href="#format_composite_type">composite type</a>
616 or <a href="#format_subprograms">subprogram</a>. The type of the member is
617 the <a href="#format_derived_type">derived
618 type</a>. <tt>DW_TAG_formal_parameter</tt> is used to define a member which
619 is a formal argument of a subprogram.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000620
Bill Wendlinge9353d72009-05-17 05:52:39 +0000621<p><tt>DW_TAG_typedef</tt> is used to provide a name for the derived type.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000622
Eric Christopher5acc7c12012-03-06 02:25:36 +0000623<p><tt>DW_TAG_pointer_type</tt>, <tt>DW_TAG_reference_type</tt>,
624 <tt>DW_TAG_const_type</tt>, <tt>DW_TAG_volatile_type</tt> and
Eric Christopher09cd3562011-12-16 23:42:35 +0000625 <tt>DW_TAG_restrict_type</tt> are used to qualify
Bill Wendlinge9353d72009-05-17 05:52:39 +0000626 the <a href="#format_derived_type">derived type</a>. </p>
Jim Laskey14edc932006-03-14 18:08:46 +0000627
628<p><a href="#format_derived_type">Derived type</a> location can be determined
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000629 from the context and line number. The size, alignment and offset are
Bill Wendlinge9353d72009-05-17 05:52:39 +0000630 expressed in bits and can be 64 bit values. The alignment is used to round
631 the offset when embedded in a <a href="#format_composite_type">composite
632 type</a> (example to keep float doubles on 64 bit boundaries.) The offset is
633 the bit offset if embedded in a <a href="#format_composite_type">composite
634 type</a>.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000635
Devang Patel7846c1e2011-02-03 00:22:17 +0000636<p>Note that the <tt>void *</tt> type is expressed as a type derived from NULL.
637</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000638
639</div>
640
641<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000642<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000643 <a name="format_composite_type">Composite type descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000644</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000645
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000646<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000647
Bill Wendlinge9353d72009-05-17 05:52:39 +0000648<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000649<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000650!6 = metadata !{
651 i32, ;; Tag (see below)
652 metadata, ;; Reference to context
653 metadata, ;; Name (may be "" for anonymous types)
Devang Patel59445db2010-03-09 00:44:10 +0000654 metadata, ;; Reference to file where defined (may be NULL)
Devang Patel80ae3492009-08-28 23:24:31 +0000655 i32, ;; Line number where defined (may be 0)
656 i64, ;; Size in bits
657 i64, ;; Alignment in bits
658 i64, ;; Offset in bits
659 i32, ;; Flags
660 metadata, ;; Reference to type derived from
661 metadata, ;; Reference to array of member descriptors
662 i32 ;; Runtime languages
Bill Wendlinge9353d72009-05-17 05:52:39 +0000663}
Jim Laskey14edc932006-03-14 18:08:46 +0000664</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000665</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000666
667<p>These descriptors are used to define types that are composed of 0 or more
668elements. The value of the tag varies depending on the meaning. The following
Misha Brukman39dcddf2008-12-16 02:54:22 +0000669are possible tag values:</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000670
Bill Wendlinge9353d72009-05-17 05:52:39 +0000671<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000672<pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000673DW_TAG_array_type = 1
674DW_TAG_enumeration_type = 4
675DW_TAG_structure_type = 19
676DW_TAG_union_type = 23
677DW_TAG_vector_type = 259
Bruno Cardoso Lopes9d809ca2009-05-29 17:08:57 +0000678DW_TAG_subroutine_type = 21
679DW_TAG_inheritance = 28
Jim Laskey14edc932006-03-14 18:08:46 +0000680</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000681</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000682
Jim Laskey19f964e2006-06-15 20:51:43 +0000683<p>The vector flag indicates that an array type is a native packed vector.</p>
684
Jim Laskeyb2ff2d42006-06-16 13:14:03 +0000685<p>The members of array types (tag = <tt>DW_TAG_array_type</tt>) or vector types
Bill Wendlinge9353d72009-05-17 05:52:39 +0000686 (tag = <tt>DW_TAG_vector_type</tt>) are <a href="#format_subrange">subrange
687 descriptors</a>, each representing the range of subscripts at that level of
688 indexing.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000689
690<p>The members of enumeration types (tag = <tt>DW_TAG_enumeration_type</tt>) are
Bill Wendlinge9353d72009-05-17 05:52:39 +0000691 <a href="#format_enumeration">enumerator descriptors</a>, each representing
Devang Patel1c6b6812011-03-29 17:27:08 +0000692 the definition of enumeration value for the set. All enumeration type
Eric Christopher885ed822012-03-26 01:56:34 +0000693 descriptors are collected inside the named metadata
694 <tt>!llvm.dbg.cu</tt>.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000695
696<p>The members of structure (tag = <tt>DW_TAG_structure_type</tt>) or union (tag
Bill Wendlinge9353d72009-05-17 05:52:39 +0000697 = <tt>DW_TAG_union_type</tt>) types are any one of
698 the <a href="#format_basic_type">basic</a>,
699 <a href="#format_derived_type">derived</a>
700 or <a href="#format_composite_type">composite</a> type descriptors, each
701 representing a field member of the structure or union.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000702
Jim Laskey4771cca2006-08-21 21:21:06 +0000703<p>For C++ classes (tag = <tt>DW_TAG_structure_type</tt>), member descriptors
Bill Wendlinge9353d72009-05-17 05:52:39 +0000704 provide information about base classes, static members and member
705 functions. If a member is a <a href="#format_derived_type">derived type
706 descriptor</a> and has a tag of <tt>DW_TAG_inheritance</tt>, then the type
707 represents a base class. If the member of is
708 a <a href="#format_global_variables">global variable descriptor</a> then it
709 represents a static member. And, if the member is
710 a <a href="#format_subprograms">subprogram descriptor</a> then it represents
711 a member function. For static members and member
712 functions, <tt>getName()</tt> returns the members link or the C++ mangled
713 name. <tt>getDisplayName()</tt> the simplied version of the name.</p>
Jim Laskey4771cca2006-08-21 21:21:06 +0000714
Bill Wendlinge9353d72009-05-17 05:52:39 +0000715<p>The first member of subroutine (tag = <tt>DW_TAG_subroutine_type</tt>) type
716 elements is the return type for the subroutine. The remaining elements are
717 the formal arguments to the subroutine.</p>
Jim Laskey4810c262006-06-20 21:13:20 +0000718
Jim Laskey14edc932006-03-14 18:08:46 +0000719<p><a href="#format_composite_type">Composite type</a> location can be
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000720 determined from the context and line number. The size, alignment and
Bill Wendlinge9353d72009-05-17 05:52:39 +0000721 offset are expressed in bits and can be 64 bit values. The alignment is used
722 to round the offset when embedded in
723 a <a href="#format_composite_type">composite type</a> (as an example, to keep
724 float doubles on 64 bit boundaries.) The offset is the bit offset if embedded
725 in a <a href="#format_composite_type">composite type</a>.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000726
727</div>
728
729<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000730<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000731 <a name="format_subrange">Subrange descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000732</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000733
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000734<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000735
Bill Wendlinge9353d72009-05-17 05:52:39 +0000736<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000737<pre>
Devang Patel7846c1e2011-02-03 00:22:17 +0000738!42 = metadata !{
Bill Wendlinge9353d72009-05-17 05:52:39 +0000739 i32, ;; Tag = 33 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_subrange_type)
740 i64, ;; Low value
741 i64 ;; High value
742}
Jim Laskey14edc932006-03-14 18:08:46 +0000743</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000744</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000745
746<p>These descriptors are used to define ranges of array subscripts for an array
Bill Wendlinge9353d72009-05-17 05:52:39 +0000747 <a href="#format_composite_type">composite type</a>. The low value defines
748 the lower bounds typically zero for C/C++. The high value is the upper
749 bounds. Values are 64 bit. High - low + 1 is the size of the array. If low
Devang Patel778947c2011-04-08 23:39:38 +0000750 > high the array bounds are not included in generated debugging information.
751</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000752
753</div>
754
755<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000756<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000757 <a name="format_enumeration">Enumerator descriptors</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000758</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000759
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000760<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000761
Bill Wendlinge9353d72009-05-17 05:52:39 +0000762<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +0000763<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000764!6 = metadata !{
Eric Christopher5acc7c12012-03-06 02:25:36 +0000765 i32, ;; Tag = 40 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel80ae3492009-08-28 23:24:31 +0000766 ;; (DW_TAG_enumerator)
767 metadata, ;; Name
768 i64 ;; Value
Bill Wendlinge9353d72009-05-17 05:52:39 +0000769}
Jim Laskey14edc932006-03-14 18:08:46 +0000770</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000771</div>
Jim Laskey14edc932006-03-14 18:08:46 +0000772
Bill Wendlinge9353d72009-05-17 05:52:39 +0000773<p>These descriptors are used to define members of an
774 enumeration <a href="#format_composite_type">composite type</a>, it
775 associates the name to the value.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000776
777</div>
778
779<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000780<h4>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000781 <a name="format_variables">Local variables</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000782</h4>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000783
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000784<div>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000785
786<div class="doc_code">
Jim Laskey5dcfd562006-03-23 17:54:33 +0000787<pre>
Devang Patel80ae3492009-08-28 23:24:31 +0000788!7 = metadata !{
789 i32, ;; Tag (see below)
790 metadata, ;; Context
791 metadata, ;; Name
Devang Patel59445db2010-03-09 00:44:10 +0000792 metadata, ;; Reference to file where defined
Devang Patele1aa67c2011-03-08 16:29:40 +0000793 i32, ;; 24 bit - Line number where defined
794 ;; 8 bit - Argument number. 1 indicates 1st argument.
Devang Patelac0a1f62011-07-27 18:14:50 +0000795 metadata, ;; Type descriptor
796 i32, ;; flags
797 metadata ;; (optional) Reference to inline location
Bill Wendlinge9353d72009-05-17 05:52:39 +0000798}
Jim Laskey5dcfd562006-03-23 17:54:33 +0000799</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000800</div>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000801
802<p>These descriptors are used to define variables local to a sub program. The
Bill Wendlinge9353d72009-05-17 05:52:39 +0000803 value of the tag depends on the usage of the variable:</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000804
Bill Wendlinge9353d72009-05-17 05:52:39 +0000805<div class="doc_code">
Jim Laskey5dcfd562006-03-23 17:54:33 +0000806<pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000807DW_TAG_auto_variable = 256
808DW_TAG_arg_variable = 257
809DW_TAG_return_variable = 258
Jim Laskey5dcfd562006-03-23 17:54:33 +0000810</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000811</div>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000812
813<p>An auto variable is any variable declared in the body of the function. An
Bill Wendlinge9353d72009-05-17 05:52:39 +0000814 argument variable is any variable that appears as a formal argument to the
815 function. A return variable is used to track the result of a function and
816 has no source correspondent.</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000817
Jim Laskey3481e122006-03-24 09:20:27 +0000818<p>The context is either the subprogram or block where the variable is defined.
Devang Pateleb1bb4e2011-08-16 22:09:43 +0000819 Name the source variable name. Context and line indicate where the
Bill Wendlinge9353d72009-05-17 05:52:39 +0000820 variable was defined. Type descriptor defines the declared type of the
821 variable.</p>
Jim Laskey5dcfd562006-03-23 17:54:33 +0000822
823</div>
824
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000825</div>
826
Jim Laskey5dcfd562006-03-23 17:54:33 +0000827<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000828<h3>
Jim Laskey14edc932006-03-14 18:08:46 +0000829 <a name="format_common_intrinsics">Debugger intrinsic functions</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000830</h3>
Jim Laskey14edc932006-03-14 18:08:46 +0000831
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000832<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000833
834<p>LLVM uses several intrinsic functions (name prefixed with "llvm.dbg") to
Bill Wendlinge9353d72009-05-17 05:52:39 +0000835 provide debug information at various points in generated code.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000836
Jim Laskey14edc932006-03-14 18:08:46 +0000837<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000838<h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000839 <a name="format_common_declare">llvm.dbg.declare</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000840</h4>
Jim Laskey14edc932006-03-14 18:08:46 +0000841
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000842<div>
Jim Laskey14edc932006-03-14 18:08:46 +0000843<pre>
Devang Patel6df452c2010-10-01 19:22:16 +0000844 void %<a href="#format_common_declare">llvm.dbg.declare</a>(metadata, metadata)
Jim Laskey14edc932006-03-14 18:08:46 +0000845</pre>
846
Chad Rosier991aa502012-02-18 01:38:41 +0000847<p>This intrinsic provides information about a local element (e.g., variable). The
848 first argument is metadata holding the alloca for the variable. The
849 second argument is metadata containing a description of the variable.</p>
Jim Laskey14edc932006-03-14 18:08:46 +0000850</div>
851
852<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000853<h4>
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000854 <a name="format_common_value">llvm.dbg.value</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000855</h4>
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000856
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000857<div>
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000858<pre>
Dan Gohmand6a6f612010-05-28 17:07:41 +0000859 void %<a href="#format_common_value">llvm.dbg.value</a>(metadata, i64, metadata)
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000860</pre>
861
862<p>This intrinsic provides information when a user source variable is set to a
863 new value. The first argument is the new value (wrapped as metadata). The
864 second argument is the offset in the user source variable where the new value
Chad Rosier991aa502012-02-18 01:38:41 +0000865 is written. The third argument is metadata containing a description of the
866 user source variable.</p>
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000867</div>
868
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000869</div>
870
Victor Hernandez0b62cc62010-01-11 22:53:48 +0000871<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000872<h3>
Chris Lattner941515c2004-01-06 05:31:32 +0000873 <a name="format_common_lifetime">Object lifetimes and scoping</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +0000874</h3>
Chris Lattner1811fca2004-01-05 05:06:33 +0000875
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +0000876<div>
Bill Wendling991b84e2009-12-01 00:53:11 +0000877<p>In many languages, the local variables in functions can have their lifetimes
878 or scopes limited to a subset of a function. In the C family of languages,
Bill Wendlinge9353d72009-05-17 05:52:39 +0000879 for example, variables are only live (readable and writable) within the
880 source block that they are defined in. In functional languages, values are
881 only readable after they have been defined. Though this is a very obvious
Bill Wendling991b84e2009-12-01 00:53:11 +0000882 concept, it is non-trivial to model in LLVM, because it has no notion of
Bill Wendlinge9353d72009-05-17 05:52:39 +0000883 scoping in this sense, and does not want to be tied to a language's scoping
884 rules.</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000885
Bill Wendling991b84e2009-12-01 00:53:11 +0000886<p>In order to handle this, the LLVM debug format uses the metadata attached to
Nick Lewyckya87014f2010-03-31 07:50:17 +0000887 llvm instructions to encode line number and scoping information. Consider
888 the following C fragment, for example:</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000889
Bill Wendlinge9353d72009-05-17 05:52:39 +0000890<div class="doc_code">
Misha Brukmanf91d9942004-05-12 19:21:57 +0000891<pre>
Chris Lattner1811fca2004-01-05 05:06:33 +00008921. void foo() {
Devang Patel4da997b2009-11-25 23:28:01 +00008932. int X = 21;
8943. int Y = 22;
Chris Lattner1811fca2004-01-05 05:06:33 +00008954. {
Devang Patel4da997b2009-11-25 23:28:01 +00008965. int Z = 23;
8976. Z = X;
Chris Lattner1811fca2004-01-05 05:06:33 +00008987. }
Devang Patel4da997b2009-11-25 23:28:01 +00008998. X = Y;
Chris Lattner1811fca2004-01-05 05:06:33 +00009009. }
Misha Brukmanf91d9942004-05-12 19:21:57 +0000901</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000902</div>
Chris Lattner1811fca2004-01-05 05:06:33 +0000903
Jim Laskey14edc932006-03-14 18:08:46 +0000904<p>Compiled to LLVM, this function would be represented like this:</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000905
Bill Wendlinge9353d72009-05-17 05:52:39 +0000906<div class="doc_code">
Misha Brukmanf91d9942004-05-12 19:21:57 +0000907<pre>
Bill Wendling991b84e2009-12-01 00:53:11 +0000908define void @foo() nounwind ssp {
Jim Laskey14edc932006-03-14 18:08:46 +0000909entry:
Bill Wendling05252352009-12-01 00:59:58 +0000910 %X = alloca i32, align 4 ; &lt;i32*&gt; [#uses=4]
911 %Y = alloca i32, align 4 ; &lt;i32*&gt; [#uses=4]
912 %Z = alloca i32, align 4 ; &lt;i32*&gt; [#uses=3]
Dan Gohmanaabfdb32010-05-28 17:13:49 +0000913 %0 = bitcast i32* %X to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel7846c1e2011-02-03 00:22:17 +0000914 call void @llvm.dbg.declare(metadata !{i32 * %X}, metadata !0), !dbg !7
Devang Patel4da997b2009-11-25 23:28:01 +0000915 store i32 21, i32* %X, !dbg !8
Dan Gohmanaabfdb32010-05-28 17:13:49 +0000916 %1 = bitcast i32* %Y to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel7846c1e2011-02-03 00:22:17 +0000917 call void @llvm.dbg.declare(metadata !{i32 * %Y}, metadata !9), !dbg !10
Devang Patel4da997b2009-11-25 23:28:01 +0000918 store i32 22, i32* %Y, !dbg !11
Dan Gohmanaabfdb32010-05-28 17:13:49 +0000919 %2 = bitcast i32* %Z to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel7846c1e2011-02-03 00:22:17 +0000920 call void @llvm.dbg.declare(metadata !{i32 * %Z}, metadata !12), !dbg !14
Devang Patel4da997b2009-11-25 23:28:01 +0000921 store i32 23, i32* %Z, !dbg !15
Bill Wendling05252352009-12-01 00:59:58 +0000922 %tmp = load i32* %X, !dbg !16 ; &lt;i32&gt; [#uses=1]
923 %tmp1 = load i32* %Y, !dbg !16 ; &lt;i32&gt; [#uses=1]
924 %add = add nsw i32 %tmp, %tmp1, !dbg !16 ; &lt;i32&gt; [#uses=1]
Devang Patel4da997b2009-11-25 23:28:01 +0000925 store i32 %add, i32* %Z, !dbg !16
Bill Wendling05252352009-12-01 00:59:58 +0000926 %tmp2 = load i32* %Y, !dbg !17 ; &lt;i32&gt; [#uses=1]
Devang Patel4da997b2009-11-25 23:28:01 +0000927 store i32 %tmp2, i32* %X, !dbg !17
928 ret void, !dbg !18
Chris Lattner1811fca2004-01-05 05:06:33 +0000929}
Devang Patel4da997b2009-11-25 23:28:01 +0000930
Devang Patel7846c1e2011-02-03 00:22:17 +0000931declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
Devang Patel4da997b2009-11-25 23:28:01 +0000932
Eric Christopher5acc7c12012-03-06 02:25:36 +0000933!0 = metadata !{i32 459008, metadata !1, metadata !"X",
Devang Patel4da997b2009-11-25 23:28:01 +0000934 metadata !3, i32 2, metadata !6}; [ DW_TAG_auto_variable ]
935!1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
Eric Christopher5acc7c12012-03-06 02:25:36 +0000936!2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", metadata !"foo",
937 metadata !"foo", metadata !3, i32 1, metadata !4,
Devang Patel4da997b2009-11-25 23:28:01 +0000938 i1 false, i1 true}; [DW_TAG_subprogram ]
Eric Christopher5acc7c12012-03-06 02:25:36 +0000939!3 = metadata !{i32 458769, i32 0, i32 12, metadata !"foo.c",
940 metadata !"/private/tmp", metadata !"clang 1.1", i1 true,
Devang Patel4da997b2009-11-25 23:28:01 +0000941 i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
Eric Christopher5acc7c12012-03-06 02:25:36 +0000942!4 = metadata !{i32 458773, metadata !3, metadata !"", null, i32 0, i64 0, i64 0,
Devang Patel4da997b2009-11-25 23:28:01 +0000943 i64 0, i32 0, null, metadata !5, i32 0}; [DW_TAG_subroutine_type ]
944!5 = metadata !{null}
Eric Christopher5acc7c12012-03-06 02:25:36 +0000945!6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0,
Devang Patel4da997b2009-11-25 23:28:01 +0000946 i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ]
947!7 = metadata !{i32 2, i32 7, metadata !1, null}
948!8 = metadata !{i32 2, i32 3, metadata !1, null}
Eric Christopher5acc7c12012-03-06 02:25:36 +0000949!9 = metadata !{i32 459008, metadata !1, metadata !"Y", metadata !3, i32 3,
Devang Patel4da997b2009-11-25 23:28:01 +0000950 metadata !6}; [ DW_TAG_auto_variable ]
951!10 = metadata !{i32 3, i32 7, metadata !1, null}
952!11 = metadata !{i32 3, i32 3, metadata !1, null}
Eric Christopher5acc7c12012-03-06 02:25:36 +0000953!12 = metadata !{i32 459008, metadata !13, metadata !"Z", metadata !3, i32 5,
Devang Patel4da997b2009-11-25 23:28:01 +0000954 metadata !6}; [ DW_TAG_auto_variable ]
955!13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
956!14 = metadata !{i32 5, i32 9, metadata !13, null}
957!15 = metadata !{i32 5, i32 5, metadata !13, null}
958!16 = metadata !{i32 6, i32 5, metadata !13, null}
959!17 = metadata !{i32 8, i32 3, metadata !1, null}
960!18 = metadata !{i32 9, i32 1, metadata !2, null}
Misha Brukmanf91d9942004-05-12 19:21:57 +0000961</pre>
Chris Lattner1811fca2004-01-05 05:06:33 +0000962</div>
963
Bill Wendling991b84e2009-12-01 00:53:11 +0000964<p>This example illustrates a few important details about LLVM debugging
965 information. In particular, it shows how the <tt>llvm.dbg.declare</tt>
966 intrinsic and location information, which are attached to an instruction,
967 are applied together to allow a debugger to analyze the relationship between
968 statements, variable definitions, and the code used to implement the
969 function.</p>
Chris Lattner1811fca2004-01-05 05:06:33 +0000970
Bill Wendling991b84e2009-12-01 00:53:11 +0000971<div class="doc_code">
Bill Wendling05252352009-12-01 00:59:58 +0000972<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +0000973call void @llvm.dbg.declare(metadata, metadata !0), !dbg !7
Bill Wendling991b84e2009-12-01 00:53:11 +0000974</pre>
975</div>
976
977<p>The first intrinsic
Devang Patel4da997b2009-11-25 23:28:01 +0000978 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
Bill Wendling991b84e2009-12-01 00:53:11 +0000979 encodes debugging information for the variable <tt>X</tt>. The metadata
980 <tt>!dbg !7</tt> attached to the intrinsic provides scope information for the
981 variable <tt>X</tt>.</p>
Bill Wendlinge9353d72009-05-17 05:52:39 +0000982
Bill Wendling991b84e2009-12-01 00:53:11 +0000983<div class="doc_code">
984<pre>
985!7 = metadata !{i32 2, i32 7, metadata !1, null}
986!1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
Eric Christopher5acc7c12012-03-06 02:25:36 +0000987!2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo",
988 metadata !"foo", metadata !"foo", metadata !3, i32 1,
989 metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
Bill Wendling991b84e2009-12-01 00:53:11 +0000990</pre>
991</div>
992
993<p>Here <tt>!7</tt> is metadata providing location information. It has four
994 fields: line number, column number, scope, and original scope. The original
995 scope represents inline location if this instruction is inlined inside a
996 caller, and is null otherwise. In this example, scope is encoded by
Devang Patel4da997b2009-11-25 23:28:01 +0000997 <tt>!1</tt>. <tt>!1</tt> represents a lexical block inside the scope
998 <tt>!2</tt>, where <tt>!2</tt> is a
Bill Wendling991b84e2009-12-01 00:53:11 +0000999 <a href="#format_subprograms">subprogram descriptor</a>. This way the
1000 location information attached to the intrinsics indicates that the
1001 variable <tt>X</tt> is declared at line number 2 at a function level scope in
1002 function <tt>foo</tt>.</p>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001003
Devang Patel4da997b2009-11-25 23:28:01 +00001004<p>Now lets take another example.</p>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001005
Bill Wendling991b84e2009-12-01 00:53:11 +00001006<div class="doc_code">
Bill Wendling05252352009-12-01 00:59:58 +00001007<pre>
Devang Patel7846c1e2011-02-03 00:22:17 +00001008call void @llvm.dbg.declare(metadata, metadata !12), !dbg !14
Bill Wendling991b84e2009-12-01 00:53:11 +00001009</pre>
1010</div>
1011
1012<p>The second intrinsic
Devang Patel4da997b2009-11-25 23:28:01 +00001013 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001014 encodes debugging information for variable <tt>Z</tt>. The metadata
Bill Wendling991b84e2009-12-01 00:53:11 +00001015 <tt>!dbg !14</tt> attached to the intrinsic provides scope information for
1016 the variable <tt>Z</tt>.</p>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001017
Bill Wendling991b84e2009-12-01 00:53:11 +00001018<div class="doc_code">
1019<pre>
1020!13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
1021!14 = metadata !{i32 5, i32 9, metadata !13, null}
1022</pre>
1023</div>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001024
John Criswell2a4b0802010-03-17 15:01:50 +00001025<p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declared at line number 5 and
Bill Wendling991b84e2009-12-01 00:53:11 +00001026 column number 9 inside of lexical scope <tt>!13</tt>. The lexical scope
1027 itself resides inside of lexical scope <tt>!1</tt> described above.</p>
1028
1029<p>The scope information attached with each instruction provides a
1030 straightforward way to find instructions covered by a scope.</p>
1031
Bill Wendlinge9353d72009-05-17 05:52:39 +00001032</div>
Chris Lattner1811fca2004-01-05 05:06:33 +00001033
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001034</div>
1035
Chris Lattner1811fca2004-01-05 05:06:33 +00001036<!-- *********************************************************************** -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001037<h2>
Chris Lattner941515c2004-01-06 05:31:32 +00001038 <a name="ccxx_frontend">C/C++ front-end specific debug information</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001039</h2>
Misha Brukmancda6a9b2004-12-09 20:27:37 +00001040<!-- *********************************************************************** -->
Chris Lattner1811fca2004-01-05 05:06:33 +00001041
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001042<div>
Chris Lattner1811fca2004-01-05 05:06:33 +00001043
Misha Brukmanf91d9942004-05-12 19:21:57 +00001044<p>The C and C++ front-ends represent information about the program in a format
Bill Wendlinge9353d72009-05-17 05:52:39 +00001045 that is effectively identical
1046 to <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3.0</a> in
1047 terms of information content. This allows code generators to trivially
1048 support native debuggers by generating standard dwarf information, and
1049 contains enough information for non-dwarf targets to translate it as
1050 needed.</p>
Chris Lattner1811fca2004-01-05 05:06:33 +00001051
Jim Laskey14edc932006-03-14 18:08:46 +00001052<p>This section describes the forms used to represent C and C++ programs. Other
Bill Wendlinge9353d72009-05-17 05:52:39 +00001053 languages could pattern themselves after this (which itself is tuned to
1054 representing programs in the same way that DWARF 3 does), or they could
1055 choose to provide completely different forms if they don't fit into the DWARF
1056 model. As support for debugging information gets added to the various LLVM
1057 source-language front-ends, the information used should be documented
1058 here.</p>
Chris Lattner1811fca2004-01-05 05:06:33 +00001059
Jim Laskey14edc932006-03-14 18:08:46 +00001060<p>The following sections provide examples of various C/C++ constructs and the
Bill Wendlinge9353d72009-05-17 05:52:39 +00001061 debug information that would best describe those constructs.</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001062
Chris Lattner1811fca2004-01-05 05:06:33 +00001063<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001064<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001065 <a name="ccxx_compile_units">C/C++ source file information</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001066</h3>
Chris Lattner1811fca2004-01-05 05:06:33 +00001067
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001068<div>
Chris Lattner1811fca2004-01-05 05:06:33 +00001069
Bill Wendlinge9353d72009-05-17 05:52:39 +00001070<p>Given the source files <tt>MySource.cpp</tt> and <tt>MyHeader.h</tt> located
1071 in the directory <tt>/Users/mine/sources</tt>, the following code:</p>
Chris Lattner941515c2004-01-06 05:31:32 +00001072
Bill Wendlinge9353d72009-05-17 05:52:39 +00001073<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001074<pre>
1075#include "MyHeader.h"
Chris Lattner941515c2004-01-06 05:31:32 +00001076
Jim Laskey14edc932006-03-14 18:08:46 +00001077int main(int argc, char *argv[]) {
1078 return 0;
1079}
1080</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001081</div>
Chris Lattner941515c2004-01-06 05:31:32 +00001082
Misha Brukman39dcddf2008-12-16 02:54:22 +00001083<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001084
Bill Wendlinge9353d72009-05-17 05:52:39 +00001085<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001086<pre>
1087...
1088;;
Devang Patel59445db2010-03-09 00:44:10 +00001089;; Define the compile unit for the main source file "/Users/mine/sources/MySource.cpp".
Jim Laskey14edc932006-03-14 18:08:46 +00001090;;
Devang Patel59445db2010-03-09 00:44:10 +00001091!2 = metadata !{
1092 i32 524305, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001093 i32 0, ;; Unused
1094 i32 4, ;; Language Id
Eric Christopher5acc7c12012-03-06 02:25:36 +00001095 metadata !"MySource.cpp",
1096 metadata !"/Users/mine/sources",
1097 metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)",
Devang Patel80ae3492009-08-28 23:24:31 +00001098 i1 true, ;; Main Compile Unit
1099 i1 false, ;; Optimized compile unit
1100 metadata !"", ;; Compiler flags
1101 i32 0} ;; Runtime version
1102
Jim Laskey14edc932006-03-14 18:08:46 +00001103;;
Devang Patel59445db2010-03-09 00:44:10 +00001104;; Define the file for the file "/Users/mine/sources/MySource.cpp".
Jim Laskey14edc932006-03-14 18:08:46 +00001105;;
Devang Patel80ae3492009-08-28 23:24:31 +00001106!1 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001107 i32 524329, ;; Tag
Eric Christopher5acc7c12012-03-06 02:25:36 +00001108 metadata !"MySource.cpp",
1109 metadata !"/Users/mine/sources",
Devang Patel4a7904d62010-07-13 16:53:20 +00001110 metadata !2 ;; Compile unit
Devang Patel59445db2010-03-09 00:44:10 +00001111}
1112
1113;;
1114;; Define the file for the file "/Users/mine/sources/Myheader.h"
1115;;
1116!3 = metadata !{
1117 i32 524329, ;; Tag
1118 metadata !"Myheader.h"
Eric Christopher5acc7c12012-03-06 02:25:36 +00001119 metadata !"/Users/mine/sources",
Devang Patel4a7904d62010-07-13 16:53:20 +00001120 metadata !2 ;; Compile unit
Devang Patel59445db2010-03-09 00:44:10 +00001121}
Jim Laskey14edc932006-03-14 18:08:46 +00001122
Jim Laskey14edc932006-03-14 18:08:46 +00001123...
1124</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001125</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001126
Eric Christopher5acc7c12012-03-06 02:25:36 +00001127<p>llvm::Instruction provides easy access to metadata attached with an
Devang Patel5bc1c4b2010-03-26 19:08:36 +00001128instruction. One can extract line number information encoded in LLVM IR
Eric Christopher5acc7c12012-03-06 02:25:36 +00001129using <tt>Instruction::getMetadata()</tt> and
Devang Patel5bc1c4b2010-03-26 19:08:36 +00001130<tt>DILocation::getLineNumber()</tt>.
1131<pre>
1132 if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction
1133 DILocation Loc(N); // DILocation is in DebugInfo.h
1134 unsigned Line = Loc.getLineNumber();
1135 StringRef File = Loc.getFilename();
1136 StringRef Dir = Loc.getDirectory();
1137 }
1138</pre>
Chris Lattner941515c2004-01-06 05:31:32 +00001139</div>
1140
1141<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001142<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001143 <a name="ccxx_global_variable">C/C++ global variable information</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001144</h3>
Chris Lattner941515c2004-01-06 05:31:32 +00001145
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001146<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001147
Misha Brukman39dcddf2008-12-16 02:54:22 +00001148<p>Given an integer global variable declared as follows:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001149
Bill Wendlinge9353d72009-05-17 05:52:39 +00001150<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001151<pre>
1152int MyGlobal = 100;
1153</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001154</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001155
Misha Brukman39dcddf2008-12-16 02:54:22 +00001156<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001157
Bill Wendlinge9353d72009-05-17 05:52:39 +00001158<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001159<pre>
1160;;
Jim Laskey14edc932006-03-14 18:08:46 +00001161;; Define the global itself.
1162;;
1163%MyGlobal = global int 100
1164...
1165;;
Devang Patel80ae3492009-08-28 23:24:31 +00001166;; List of debug info of globals
Jim Laskey14edc932006-03-14 18:08:46 +00001167;;
Eric Christopher885ed822012-03-26 01:56:34 +00001168!llvm.dbg.cu = !{!0}
Jim Laskey14edc932006-03-14 18:08:46 +00001169
Eric Christopher885ed822012-03-26 01:56:34 +00001170;; Define the compile unit.
Devang Patel80ae3492009-08-28 23:24:31 +00001171!0 = metadata !{
Eric Christopher885ed822012-03-26 01:56:34 +00001172 i32 786449, ;; Tag
1173 i32 0, ;; Context
1174 i32 4, ;; Language
1175 metadata !"foo.cpp", ;; File
1176 metadata !"/Volumes/Data/tmp", ;; Directory
1177 metadata !"clang version 3.1 ", ;; Producer
1178 i1 true, ;; Deprecated field
1179 i1 false, ;; "isOptimized"?
1180 metadata !"", ;; Flags
1181 i32 0, ;; Runtime Version
1182 metadata !1, ;; Enum Types
1183 metadata !1, ;; Retained Types
1184 metadata !1, ;; Subprograms
1185 metadata !3 ;; Global Variables
1186} ; [ DW_TAG_compile_unit ]
1187
1188;; The Array of Global Variables
1189!3 = metadata !{
1190 metadata !4
1191}
1192
1193!4 = metadata !{
1194 metadata !5
Devang Patel80ae3492009-08-28 23:24:31 +00001195}
1196
Jim Laskey14edc932006-03-14 18:08:46 +00001197;;
Eric Christopher885ed822012-03-26 01:56:34 +00001198;; Define the global variable itself.
Eric Christopher5acc7c12012-03-06 02:25:36 +00001199;;
Eric Christopher885ed822012-03-26 01:56:34 +00001200!5 = metadata !{
1201 i32 786484, ;; Tag
1202 i32 0, ;; Unused
1203 null, ;; Unused
1204 metadata !"MyGlobal", ;; Name
1205 metadata !"MyGlobal", ;; Display Name
1206 metadata !"", ;; Linkage Name
1207 metadata !6, ;; File
1208 i32 1, ;; Line
1209 metadata !7, ;; Type
1210 i32 0, ;; IsLocalToUnit
1211 i32 1, ;; IsDefinition
1212 i32* @MyGlobal ;; LLVM-IR Value
1213} ; [ DW_TAG_variable ]
1214
1215;;
1216;; Define the file
1217;;
1218!6 = metadata !{
1219 i32 786473, ;; Tag
1220 metadata !"foo.cpp", ;; File
1221 metadata !"/Volumes/Data/tmp", ;; Directory
1222 null ;; Unused
1223} ; [ DW_TAG_file_type ]
1224
1225;;
1226;; Define the type
1227;;
1228!7 = metadata !{
1229 i32 786468, ;; Tag
1230 null, ;; Unused
1231 metadata !"int", ;; Name
1232 null, ;; Unused
1233 i32 0, ;; Line
1234 i64 32, ;; Size in Bits
1235 i64 32, ;; Align in Bits
1236 i64 0, ;; Offset
1237 i32 0, ;; Flags
1238 i32 5 ;; Encoding
1239} ; [ DW_TAG_base_type ]
Jim Laskey14edc932006-03-14 18:08:46 +00001240
Jim Laskey14edc932006-03-14 18:08:46 +00001241</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001242</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001243
Chris Lattner941515c2004-01-06 05:31:32 +00001244</div>
Chris Lattner1811fca2004-01-05 05:06:33 +00001245
Jim Laskey14edc932006-03-14 18:08:46 +00001246<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001247<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001248 <a name="ccxx_subprogram">C/C++ function information</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001249</h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001250
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001251<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001252
Misha Brukman39dcddf2008-12-16 02:54:22 +00001253<p>Given a function declared as follows:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001254
Bill Wendlinge9353d72009-05-17 05:52:39 +00001255<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001256<pre>
1257int main(int argc, char *argv[]) {
1258 return 0;
1259}
1260</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001261</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001262
Misha Brukman39dcddf2008-12-16 02:54:22 +00001263<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001264
Bill Wendlinge9353d72009-05-17 05:52:39 +00001265<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001266<pre>
1267;;
Jim Laskey14edc932006-03-14 18:08:46 +00001268;; Define the anchor for subprograms. Note that the second field of the
1269;; anchor is 46, which is the same as the tag for subprograms
1270;; (46 = DW_TAG_subprogram.)
1271;;
Devang Patel59445db2010-03-09 00:44:10 +00001272!6 = metadata !{
1273 i32 524334, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001274 i32 0, ;; Unused
1275 metadata !1, ;; Context
1276 metadata !"main", ;; Name
1277 metadata !"main", ;; Display name
1278 metadata !"main", ;; Linkage name
Devang Patel59445db2010-03-09 00:44:10 +00001279 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001280 i32 1, ;; Line number
Devang Patel59445db2010-03-09 00:44:10 +00001281 metadata !4, ;; Type
Eric Christopher5acc7c12012-03-06 02:25:36 +00001282 i1 false, ;; Is local
Devang Patel9f738842011-04-05 22:52:06 +00001283 i1 true, ;; Is definition
1284 i32 0, ;; Virtuality attribute, e.g. pure virtual function
1285 i32 0, ;; Index into virtual table for C++ methods
1286 i32 0, ;; Type that holds virtual table.
1287 i32 0, ;; Flags
1288 i1 false, ;; True if this function is optimized
1289 Function *, ;; Pointer to llvm::Function
1290 null ;; Function template parameters
Devang Patel80ae3492009-08-28 23:24:31 +00001291}
Jim Laskey14edc932006-03-14 18:08:46 +00001292;;
1293;; Define the subprogram itself.
1294;;
Devang Patel80ae3492009-08-28 23:24:31 +00001295define i32 @main(i32 %argc, i8** %argv) {
Jim Laskey14edc932006-03-14 18:08:46 +00001296...
1297}
1298</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001299</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001300
1301</div>
1302
1303<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001304<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001305 <a name="ccxx_basic_types">C/C++ basic types</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001306</h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001307
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001308<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001309
Misha Brukman39dcddf2008-12-16 02:54:22 +00001310<p>The following are the basic type descriptors for C/C++ core types:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001311
Jim Laskey14edc932006-03-14 18:08:46 +00001312<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001313<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001314 <a name="ccxx_basic_type_bool">bool</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001315</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001316
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001317<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001318
Bill Wendlinge9353d72009-05-17 05:52:39 +00001319<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001320<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001321!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001322 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001323 metadata !1, ;; Context
1324 metadata !"bool", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001325 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001326 i32 0, ;; Line number
1327 i64 8, ;; Size in Bits
1328 i64 8, ;; Align in Bits
1329 i64 0, ;; Offset in Bits
1330 i32 0, ;; Flags
1331 i32 2 ;; Encoding
1332}
Jim Laskey14edc932006-03-14 18:08:46 +00001333</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001334</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001335
1336</div>
1337
1338<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001339<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001340 <a name="ccxx_basic_char">char</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001341</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001342
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001343<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001344
Bill Wendlinge9353d72009-05-17 05:52:39 +00001345<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001346<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001347!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001348 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001349 metadata !1, ;; Context
1350 metadata !"char", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001351 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001352 i32 0, ;; Line number
1353 i64 8, ;; Size in Bits
1354 i64 8, ;; Align in Bits
1355 i64 0, ;; Offset in Bits
1356 i32 0, ;; Flags
1357 i32 6 ;; Encoding
1358}
Jim Laskey14edc932006-03-14 18:08:46 +00001359</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001360</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001361
1362</div>
1363
1364<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001365<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001366 <a name="ccxx_basic_unsigned_char">unsigned char</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001367</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001368
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001369<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001370
Bill Wendlinge9353d72009-05-17 05:52:39 +00001371<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001372<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001373!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001374 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001375 metadata !1, ;; Context
Eric Christopher5acc7c12012-03-06 02:25:36 +00001376 metadata !"unsigned char",
Devang Patel59445db2010-03-09 00:44:10 +00001377 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001378 i32 0, ;; Line number
1379 i64 8, ;; Size in Bits
1380 i64 8, ;; Align in Bits
1381 i64 0, ;; Offset in Bits
1382 i32 0, ;; Flags
1383 i32 8 ;; Encoding
1384}
Jim Laskey14edc932006-03-14 18:08:46 +00001385</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001386</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001387
1388</div>
1389
1390<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001391<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001392 <a name="ccxx_basic_short">short</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001393</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001394
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001395<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001396
Bill Wendlinge9353d72009-05-17 05:52:39 +00001397<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001398<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001399!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001400 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001401 metadata !1, ;; Context
1402 metadata !"short int",
Devang Patel59445db2010-03-09 00:44:10 +00001403 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001404 i32 0, ;; Line number
1405 i64 16, ;; Size in Bits
1406 i64 16, ;; Align in Bits
1407 i64 0, ;; Offset in Bits
1408 i32 0, ;; Flags
1409 i32 5 ;; Encoding
1410}
Jim Laskey14edc932006-03-14 18:08:46 +00001411</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001412</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001413
1414</div>
1415
1416<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001417<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001418 <a name="ccxx_basic_unsigned_short">unsigned short</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001419</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001420
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001421<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001422
Bill Wendlinge9353d72009-05-17 05:52:39 +00001423<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001424<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001425!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001426 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001427 metadata !1, ;; Context
1428 metadata !"short unsigned int",
Devang Patel59445db2010-03-09 00:44:10 +00001429 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001430 i32 0, ;; Line number
1431 i64 16, ;; Size in Bits
1432 i64 16, ;; Align in Bits
1433 i64 0, ;; Offset in Bits
1434 i32 0, ;; Flags
1435 i32 7 ;; Encoding
1436}
Jim Laskey14edc932006-03-14 18:08:46 +00001437</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001438</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001439
1440</div>
1441
1442<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001443<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001444 <a name="ccxx_basic_int">int</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001445</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001446
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001447<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001448
Bill Wendlinge9353d72009-05-17 05:52:39 +00001449<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001450<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001451!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001452 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001453 metadata !1, ;; Context
1454 metadata !"int", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001455 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001456 i32 0, ;; Line number
1457 i64 32, ;; Size in Bits
1458 i64 32, ;; Align in Bits
1459 i64 0, ;; Offset in Bits
1460 i32 0, ;; Flags
1461 i32 5 ;; Encoding
1462}
Bill Wendlinge9353d72009-05-17 05:52:39 +00001463</pre></div>
Jim Laskey14edc932006-03-14 18:08:46 +00001464
1465</div>
1466
1467<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001468<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001469 <a name="ccxx_basic_unsigned_int">unsigned int</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001470</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001471
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001472<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001473
Bill Wendlinge9353d72009-05-17 05:52:39 +00001474<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001475<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001476!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001477 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001478 metadata !1, ;; Context
1479 metadata !"unsigned int",
Devang Patel59445db2010-03-09 00:44:10 +00001480 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001481 i32 0, ;; Line number
1482 i64 32, ;; Size in Bits
1483 i64 32, ;; Align in Bits
1484 i64 0, ;; Offset in Bits
1485 i32 0, ;; Flags
1486 i32 7 ;; Encoding
1487}
Jim Laskey14edc932006-03-14 18:08:46 +00001488</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001489</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001490
1491</div>
1492
1493<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001494<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001495 <a name="ccxx_basic_long_long">long long</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001496</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001497
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001498<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001499
Bill Wendlinge9353d72009-05-17 05:52:39 +00001500<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001501<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001502!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001503 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001504 metadata !1, ;; Context
1505 metadata !"long long int",
Devang Patel59445db2010-03-09 00:44:10 +00001506 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001507 i32 0, ;; Line number
1508 i64 64, ;; Size in Bits
1509 i64 64, ;; Align in Bits
1510 i64 0, ;; Offset in Bits
1511 i32 0, ;; Flags
1512 i32 5 ;; Encoding
1513}
Jim Laskey14edc932006-03-14 18:08:46 +00001514</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001515</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001516
1517</div>
1518
1519<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001520<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001521 <a name="ccxx_basic_unsigned_long_long">unsigned long long</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001522</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001523
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001524<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001525
Bill Wendlinge9353d72009-05-17 05:52:39 +00001526<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001527<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001528!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001529 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001530 metadata !1, ;; Context
1531 metadata !"long long unsigned int",
Devang Patel59445db2010-03-09 00:44:10 +00001532 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001533 i32 0, ;; Line number
1534 i64 64, ;; Size in Bits
1535 i64 64, ;; Align in Bits
1536 i64 0, ;; Offset in Bits
1537 i32 0, ;; Flags
1538 i32 7 ;; Encoding
1539}
Jim Laskey14edc932006-03-14 18:08:46 +00001540</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001541</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001542
1543</div>
1544
1545<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001546<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001547 <a name="ccxx_basic_float">float</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001548</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001549
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001550<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001551
Bill Wendlinge9353d72009-05-17 05:52:39 +00001552<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001553<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001554!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001555 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001556 metadata !1, ;; Context
1557 metadata !"float",
Devang Patel59445db2010-03-09 00:44:10 +00001558 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001559 i32 0, ;; Line number
1560 i64 32, ;; Size in Bits
1561 i64 32, ;; Align in Bits
1562 i64 0, ;; Offset in Bits
1563 i32 0, ;; Flags
1564 i32 4 ;; Encoding
1565}
Jim Laskey14edc932006-03-14 18:08:46 +00001566</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001567</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001568
1569</div>
1570
1571<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001572<h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001573 <a name="ccxx_basic_double">double</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001574</h4>
Jim Laskey14edc932006-03-14 18:08:46 +00001575
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001576<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001577
Bill Wendlinge9353d72009-05-17 05:52:39 +00001578<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001579<pre>
Devang Patel80ae3492009-08-28 23:24:31 +00001580!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001581 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001582 metadata !1, ;; Context
1583 metadata !"double",;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001584 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001585 i32 0, ;; Line number
1586 i64 64, ;; Size in Bits
1587 i64 64, ;; Align in Bits
1588 i64 0, ;; Offset in Bits
1589 i32 0, ;; Flags
1590 i32 4 ;; Encoding
1591}
Jim Laskey14edc932006-03-14 18:08:46 +00001592</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001593</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001594
1595</div>
1596
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001597</div>
1598
Jim Laskey14edc932006-03-14 18:08:46 +00001599<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001600<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001601 <a name="ccxx_derived_types">C/C++ derived types</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001602</h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001603
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001604<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001605
Misha Brukman39dcddf2008-12-16 02:54:22 +00001606<p>Given the following as an example of C/C++ derived type:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001607
Bill Wendlinge9353d72009-05-17 05:52:39 +00001608<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001609<pre>
1610typedef const int *IntPtr;
1611</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001612</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001613
Misha Brukman39dcddf2008-12-16 02:54:22 +00001614<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001615
Bill Wendlinge9353d72009-05-17 05:52:39 +00001616<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001617<pre>
1618;;
1619;; Define the typedef "IntPtr".
1620;;
Devang Patel80ae3492009-08-28 23:24:31 +00001621!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001622 i32 524310, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001623 metadata !1, ;; Context
1624 metadata !"IntPtr", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001625 metadata !3, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001626 i32 0, ;; Line number
1627 i64 0, ;; Size in bits
1628 i64 0, ;; Align in bits
1629 i64 0, ;; Offset in bits
1630 i32 0, ;; Flags
1631 metadata !4 ;; Derived From type
1632}
Jim Laskey14edc932006-03-14 18:08:46 +00001633
1634;;
1635;; Define the pointer type.
1636;;
Devang Patel80ae3492009-08-28 23:24:31 +00001637!4 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001638 i32 524303, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001639 metadata !1, ;; Context
1640 metadata !"", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001641 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001642 i32 0, ;; Line number
1643 i64 64, ;; Size in bits
1644 i64 64, ;; Align in bits
1645 i64 0, ;; Offset in bits
1646 i32 0, ;; Flags
1647 metadata !5 ;; Derived From type
1648}
Jim Laskey14edc932006-03-14 18:08:46 +00001649;;
1650;; Define the const type.
1651;;
Devang Patel80ae3492009-08-28 23:24:31 +00001652!5 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001653 i32 524326, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001654 metadata !1, ;; Context
1655 metadata !"", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001656 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001657 i32 0, ;; Line number
1658 i64 32, ;; Size in bits
1659 i64 32, ;; Align in bits
1660 i64 0, ;; Offset in bits
1661 i32 0, ;; Flags
1662 metadata !6 ;; Derived From type
1663}
Jim Laskey14edc932006-03-14 18:08:46 +00001664;;
1665;; Define the int type.
1666;;
Devang Patel80ae3492009-08-28 23:24:31 +00001667!6 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001668 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001669 metadata !1, ;; Context
1670 metadata !"int", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001671 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001672 i32 0, ;; Line number
1673 i64 32, ;; Size in bits
1674 i64 32, ;; Align in bits
1675 i64 0, ;; Offset in bits
1676 i32 0, ;; Flags
1677 5 ;; Encoding
1678}
Jim Laskey14edc932006-03-14 18:08:46 +00001679</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001680</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001681
1682</div>
1683
1684<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001685<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001686 <a name="ccxx_composite_types">C/C++ struct/union types</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001687</h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001688
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001689<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001690
Misha Brukman39dcddf2008-12-16 02:54:22 +00001691<p>Given the following as an example of C/C++ struct type:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001692
Bill Wendlinge9353d72009-05-17 05:52:39 +00001693<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001694<pre>
1695struct Color {
1696 unsigned Red;
1697 unsigned Green;
1698 unsigned Blue;
1699};
1700</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001701</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001702
Misha Brukman39dcddf2008-12-16 02:54:22 +00001703<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001704
Bill Wendlinge9353d72009-05-17 05:52:39 +00001705<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001706<pre>
1707;;
1708;; Define basic type for unsigned int.
1709;;
Devang Patel80ae3492009-08-28 23:24:31 +00001710!5 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001711 i32 524324, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001712 metadata !1, ;; Context
1713 metadata !"unsigned int",
Devang Patel59445db2010-03-09 00:44:10 +00001714 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001715 i32 0, ;; Line number
1716 i64 32, ;; Size in Bits
1717 i64 32, ;; Align in Bits
1718 i64 0, ;; Offset in Bits
1719 i32 0, ;; Flags
1720 i32 7 ;; Encoding
1721}
Jim Laskey14edc932006-03-14 18:08:46 +00001722;;
1723;; Define composite type for struct Color.
1724;;
Devang Patel80ae3492009-08-28 23:24:31 +00001725!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001726 i32 524307, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001727 metadata !1, ;; Context
1728 metadata !"Color", ;; Name
1729 metadata !1, ;; Compile unit
1730 i32 1, ;; Line number
1731 i64 96, ;; Size in bits
1732 i64 32, ;; Align in bits
1733 i64 0, ;; Offset in bits
1734 i32 0, ;; Flags
1735 null, ;; Derived From
1736 metadata !3, ;; Elements
1737 i32 0 ;; Runtime Language
1738}
Jim Laskey14edc932006-03-14 18:08:46 +00001739
1740;;
1741;; Define the Red field.
1742;;
Devang Patel80ae3492009-08-28 23:24:31 +00001743!4 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001744 i32 524301, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001745 metadata !1, ;; Context
1746 metadata !"Red", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001747 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001748 i32 2, ;; Line number
1749 i64 32, ;; Size in bits
1750 i64 32, ;; Align in bits
1751 i64 0, ;; Offset in bits
1752 i32 0, ;; Flags
1753 metadata !5 ;; Derived From type
1754}
Jim Laskey14edc932006-03-14 18:08:46 +00001755
1756;;
1757;; Define the Green field.
1758;;
Devang Patel80ae3492009-08-28 23:24:31 +00001759!6 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001760 i32 524301, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001761 metadata !1, ;; Context
1762 metadata !"Green", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001763 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001764 i32 3, ;; Line number
1765 i64 32, ;; Size in bits
1766 i64 32, ;; Align in bits
1767 i64 32, ;; Offset in bits
1768 i32 0, ;; Flags
1769 metadata !5 ;; Derived From type
1770}
Jim Laskey14edc932006-03-14 18:08:46 +00001771
1772;;
1773;; Define the Blue field.
1774;;
Devang Patel80ae3492009-08-28 23:24:31 +00001775!7 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001776 i32 524301, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001777 metadata !1, ;; Context
1778 metadata !"Blue", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001779 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001780 i32 4, ;; Line number
1781 i64 32, ;; Size in bits
1782 i64 32, ;; Align in bits
1783 i64 64, ;; Offset in bits
1784 i32 0, ;; Flags
1785 metadata !5 ;; Derived From type
1786}
Jim Laskey14edc932006-03-14 18:08:46 +00001787
1788;;
1789;; Define the array of fields used by the composite type Color.
1790;;
Devang Patel80ae3492009-08-28 23:24:31 +00001791!3 = metadata !{metadata !4, metadata !6, metadata !7}
Jim Laskey14edc932006-03-14 18:08:46 +00001792</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001793</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001794
1795</div>
1796
1797<!-- ======================================================================= -->
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001798<h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001799 <a name="ccxx_enumeration_types">C/C++ enumeration types</a>
NAKAMURA Takumifc8d9302011-04-18 23:59:50 +00001800</h3>
Jim Laskey14edc932006-03-14 18:08:46 +00001801
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001802<div>
Jim Laskey14edc932006-03-14 18:08:46 +00001803
Misha Brukman39dcddf2008-12-16 02:54:22 +00001804<p>Given the following as an example of C/C++ enumeration type:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001805
Bill Wendlinge9353d72009-05-17 05:52:39 +00001806<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001807<pre>
1808enum Trees {
1809 Spruce = 100,
1810 Oak = 200,
1811 Maple = 300
1812};
1813</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001814</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001815
Misha Brukman39dcddf2008-12-16 02:54:22 +00001816<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskey14edc932006-03-14 18:08:46 +00001817
Bill Wendlinge9353d72009-05-17 05:52:39 +00001818<div class="doc_code">
Jim Laskey14edc932006-03-14 18:08:46 +00001819<pre>
1820;;
1821;; Define composite type for enum Trees
1822;;
Devang Patel80ae3492009-08-28 23:24:31 +00001823!2 = metadata !{
Devang Patel59445db2010-03-09 00:44:10 +00001824 i32 524292, ;; Tag
Devang Patel80ae3492009-08-28 23:24:31 +00001825 metadata !1, ;; Context
1826 metadata !"Trees", ;; Name
Devang Patel59445db2010-03-09 00:44:10 +00001827 metadata !1, ;; File
Devang Patel80ae3492009-08-28 23:24:31 +00001828 i32 1, ;; Line number
1829 i64 32, ;; Size in bits
1830 i64 32, ;; Align in bits
1831 i64 0, ;; Offset in bits
1832 i32 0, ;; Flags
1833 null, ;; Derived From type
1834 metadata !3, ;; Elements
1835 i32 0 ;; Runtime language
1836}
Devang Patel02aac922009-08-25 05:24:07 +00001837
Devang Patelf08e35d2009-08-26 05:01:18 +00001838;;
1839;; Define the array of enumerators used by composite type Trees.
1840;;
Devang Patel80ae3492009-08-28 23:24:31 +00001841!3 = metadata !{metadata !4, metadata !5, metadata !6}
1842
1843;;
1844;; Define Spruce enumerator.
1845;;
Devang Patel59445db2010-03-09 00:44:10 +00001846!4 = metadata !{i32 524328, metadata !"Spruce", i64 100}
Devang Patel80ae3492009-08-28 23:24:31 +00001847
1848;;
1849;; Define Oak enumerator.
1850;;
Devang Patel59445db2010-03-09 00:44:10 +00001851!5 = metadata !{i32 524328, metadata !"Oak", i64 200}
Devang Patel80ae3492009-08-28 23:24:31 +00001852
1853;;
1854;; Define Maple enumerator.
1855;;
Devang Patel59445db2010-03-09 00:44:10 +00001856!6 = metadata !{i32 524328, metadata !"Maple", i64 300}
Devang Patel80ae3492009-08-28 23:24:31 +00001857
Jim Laskey14edc932006-03-14 18:08:46 +00001858</pre>
Bill Wendlinge9353d72009-05-17 05:52:39 +00001859</div>
Jim Laskey14edc932006-03-14 18:08:46 +00001860
1861</div>
Chris Lattner1811fca2004-01-05 05:06:33 +00001862
NAKAMURA Takumiaa3d6242011-04-23 00:30:22 +00001863</div>
1864
Devang Patel8cd89642011-11-15 22:59:54 +00001865
1866<!-- *********************************************************************** -->
1867<h2>
1868 <a name="llvmdwarfextension">Debugging information format</a>
1869</h2>
1870<!-- *********************************************************************** -->
1871<div>
1872<!-- ======================================================================= -->
1873<h3>
Bill Wendling23d60ac2012-03-06 09:17:39 +00001874 <a name="objcproperty">Debugging Information Extension for Objective C Properties</a>
Devang Patel8cd89642011-11-15 22:59:54 +00001875</h3>
1876<div>
1877<!-- *********************************************************************** -->
1878<h4>
1879 <a name="objcpropertyintroduction">Introduction</a>
1880</h4>
1881<!-- *********************************************************************** -->
1882
1883<div>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001884<p>Objective C provides a simpler way to declare and define accessor methods
1885using declared properties. The language provides features to declare a
Devang Patel8cd89642011-11-15 22:59:54 +00001886property and to let compiler synthesize accessor methods.
1887</p>
1888
Eric Christopher5acc7c12012-03-06 02:25:36 +00001889<p>The debugger lets developer inspect Objective C interfaces and their
1890instance variables and class variables. However, the debugger does not know
Devang Patel8cd89642011-11-15 22:59:54 +00001891anything about the properties defined in Objective C interfaces. The debugger
Eric Christopher5acc7c12012-03-06 02:25:36 +00001892consumes information generated by compiler in DWARF format. The format does
Devang Patel8cd89642011-11-15 22:59:54 +00001893not support encoding of Objective C properties. This proposal describes DWARF
1894extensions to encode Objective C properties, which the debugger can use to let
1895developers inspect Objective C properties.
1896</p>
1897
1898</div>
1899
1900
1901<!-- *********************************************************************** -->
1902<h4>
1903 <a name="objcpropertyproposal">Proposal</a>
1904</h4>
1905<!-- *********************************************************************** -->
1906
1907<div>
Devang Patelc0449632012-02-06 18:18:25 +00001908<p>Objective C properties exist separately from class members. A property
Eric Christopher5acc7c12012-03-06 02:25:36 +00001909can be defined only by &quot;setter&quot; and &quot;getter&quot; selectors, and
1910be calculated anew on each access. Or a property can just be a direct access
1911to some declared ivar. Finally it can have an ivar &quot;automatically
1912synthesized&quot; for it by the compiler, in which case the property can be
1913referred to in user code directly using the standard C dereference syntax as
1914well as through the property &quot;dot&quot; syntax, but there is no entry in
Devang Patelc0449632012-02-06 18:18:25 +00001915the @interface declaration corresponding to this ivar.
1916</p>
1917<p>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001918To facilitate debugging, these properties we will add a new DWARF TAG into the
1919DW_TAG_structure_type definition for the class to hold the description of a
Devang Patelc0449632012-02-06 18:18:25 +00001920given property, and a set of DWARF attributes that provide said description.
Eric Christopher5acc7c12012-03-06 02:25:36 +00001921The property tag will also contain the name and declared type of the property.
Devang Patelc0449632012-02-06 18:18:25 +00001922</p>
1923<p>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001924If there is a related ivar, there will also be a DWARF property attribute placed
1925in the DW_TAG_member DIE for that ivar referring back to the property TAG for
1926that property. And in the case where the compiler synthesizes the ivar directly,
1927the compiler is expected to generate a DW_TAG_member for that ivar (with the
1928DW_AT_artificial set to 1), whose name will be the name used to access this
1929ivar directly in code, and with the property attribute pointing back to the
Devang Patelc0449632012-02-06 18:18:25 +00001930property it is backing.
1931</p>
1932<p>
1933The following examples will serve as illustration for our discussion:
Devang Patel8cd89642011-11-15 22:59:54 +00001934</p>
1935
1936<div class="doc_code">
1937<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001938@interface I1 {
Devang Patel8cd89642011-11-15 22:59:54 +00001939 int n2;
Eric Christopher5acc7c12012-03-06 02:25:36 +00001940}
Devang Patel8cd89642011-11-15 22:59:54 +00001941
Eric Christopher5acc7c12012-03-06 02:25:36 +00001942@property int p1;
1943@property int p2;
Devang Patel8cd89642011-11-15 22:59:54 +00001944@end
1945
Eric Christopher5acc7c12012-03-06 02:25:36 +00001946@implementation I1
1947@synthesize p1;
1948@synthesize p2 = n2;
Devang Patel8cd89642011-11-15 22:59:54 +00001949@end
Devang Patel8cd89642011-11-15 22:59:54 +00001950</pre>
1951</div>
1952
Devang Patelc0449632012-02-06 18:18:25 +00001953<p>
1954This produces the following DWARF (this is a &quot;pseudo dwarfdump&quot; output):
1955</p>
1956<div class="doc_code">
1957<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +000019580x00000100: TAG_structure_type [7] *
Devang Patelc0449632012-02-06 18:18:25 +00001959 AT_APPLE_runtime_class( 0x10 )
1960 AT_name( "I1" )
Eric Christopher5acc7c12012-03-06 02:25:36 +00001961 AT_decl_file( "Objc_Property.m" )
Devang Patelc0449632012-02-06 18:18:25 +00001962 AT_decl_line( 3 )
1963
19640x00000110 TAG_APPLE_property
1965 AT_name ( "p1" )
1966 AT_type ( {0x00000150} ( int ) )
1967
19680x00000120: TAG_APPLE_property
1969 AT_name ( "p2" )
1970 AT_type ( {0x00000150} ( int ) )
1971
Eric Christopher5acc7c12012-03-06 02:25:36 +000019720x00000130: TAG_member [8]
Devang Patelc0449632012-02-06 18:18:25 +00001973 AT_name( "_p1" )
1974 AT_APPLE_property ( {0x00000110} "p1" )
1975 AT_type( {0x00000150} ( int ) )
1976 AT_artificial ( 0x1 )
1977
Eric Christopher5acc7c12012-03-06 02:25:36 +000019780x00000140: TAG_member [8]
Devang Patelc0449632012-02-06 18:18:25 +00001979 AT_name( "n2" )
1980 AT_APPLE_property ( {0x00000120} "p2" )
1981 AT_type( {0x00000150} ( int ) )
1982
19830x00000150: AT_type( ( int ) )
1984</pre>
1985</div>
1986
Eric Christopher5acc7c12012-03-06 02:25:36 +00001987<p> Note, the current convention is that the name of the ivar for an
Devang Patelc0449632012-02-06 18:18:25 +00001988auto-synthesized property is the name of the property from which it derives with
1989an underscore prepended, as is shown in the example.
1990But we actually don't need to know this convention, since we are given the name
1991of the ivar directly.
1992</p>
1993
1994<p>
Eric Christopher5acc7c12012-03-06 02:25:36 +00001995Also, it is common practice in ObjC to have different property declarations in
1996the @interface and @implementation - e.g. to provide a read-only property in
1997the interface,and a read-write interface in the implementation. In that case,
1998the compiler should emit whichever property declaration will be in force in the
Devang Patelc0449632012-02-06 18:18:25 +00001999current translation unit.
2000</p>
2001
Eric Christopher5acc7c12012-03-06 02:25:36 +00002002<p> Developers can decorate a property with attributes which are encoded using
Devang Patel8cd89642011-11-15 22:59:54 +00002003DW_AT_APPLE_property_attribute.
2004</p>
2005
2006<div class="doc_code">
2007<pre>
2008@property (readonly, nonatomic) int pr;
Devang Patelc0449632012-02-06 18:18:25 +00002009</pre>
2010</div>
2011<p>
2012Which produces a property tag:
2013<p>
2014<div class="doc_code">
2015<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +00002016TAG_APPLE_property [8]
2017 AT_name( "pr" )
2018 AT_type ( {0x00000147} (int) )
Devang Patel8cd89642011-11-15 22:59:54 +00002019 AT_APPLE_property_attribute (DW_APPLE_PROPERTY_readonly, DW_APPLE_PROPERTY_nonatomic)
2020</pre>
2021</div>
2022
Eric Christopher5acc7c12012-03-06 02:25:36 +00002023<p> The setter and getter method names are attached to the property using
Devang Patel8cd89642011-11-15 22:59:54 +00002024DW_AT_APPLE_property_setter and DW_AT_APPLE_property_getter attributes.
2025</p>
2026<div class="doc_code">
2027<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +00002028@interface I1
2029@property (setter=myOwnP3Setter:) int p3;
2030-(void)myOwnP3Setter:(int)a;
Devang Patel8cd89642011-11-15 22:59:54 +00002031@end
2032
Eric Christopher5acc7c12012-03-06 02:25:36 +00002033@implementation I1
Devang Patel8cd89642011-11-15 22:59:54 +00002034@synthesize p3;
Eric Christopher5acc7c12012-03-06 02:25:36 +00002035-(void)myOwnP3Setter:(int)a{ }
Devang Patel8cd89642011-11-15 22:59:54 +00002036@end
Devang Patelc0449632012-02-06 18:18:25 +00002037</pre>
2038</div>
Devang Patel8cd89642011-11-15 22:59:54 +00002039
Devang Patelc0449632012-02-06 18:18:25 +00002040<p>
2041The DWARF for this would be:
2042</p>
2043<div class="doc_code">
2044<pre>
Eric Christopher5acc7c12012-03-06 02:25:36 +000020450x000003bd: TAG_structure_type [7] *
Devang Patel8cd89642011-11-15 22:59:54 +00002046 AT_APPLE_runtime_class( 0x10 )
2047 AT_name( "I1" )
Eric Christopher5acc7c12012-03-06 02:25:36 +00002048 AT_decl_file( "Objc_Property.m" )
Devang Patel8cd89642011-11-15 22:59:54 +00002049 AT_decl_line( 3 )
Devang Patelc0449632012-02-06 18:18:25 +00002050
20510x000003cd TAG_APPLE_property
2052 AT_name ( "p3" )
2053 AT_APPLE_property_setter ( "myOwnP3Setter:" )
2054 AT_type( {0x00000147} ( int ) )
Eric Christopher5acc7c12012-03-06 02:25:36 +00002055
20560x000003f3: TAG_member [8]
2057 AT_name( "_p3" )
Devang Patelc0449632012-02-06 18:18:25 +00002058 AT_type ( {0x00000147} ( int ) )
2059 AT_APPLE_property ( {0x000003cd} )
2060 AT_artificial ( 0x1 )
Devang Patel8cd89642011-11-15 22:59:54 +00002061</pre>
2062</div>
2063
2064</div>
2065
2066<!-- *********************************************************************** -->
2067<h4>
Devang Patelc0449632012-02-06 18:18:25 +00002068 <a name="objcpropertynewtags">New DWARF Tags</a>
2069</h4>
2070<!-- *********************************************************************** -->
2071
2072<div>
2073<table border="1" cellspacing="0">
Bill Wendling4af807c2012-03-06 09:22:03 +00002074 <col width="200">
2075 <col width="200">
Devang Patelc0449632012-02-06 18:18:25 +00002076 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002077 <th>TAG</th>
2078 <th>Value</th>
Devang Patelc0449632012-02-06 18:18:25 +00002079 </tr>
2080 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002081 <td>DW_TAG_APPLE_property</td>
2082 <td>0x4200</td>
Devang Patelc0449632012-02-06 18:18:25 +00002083 </tr>
2084</table>
2085
2086</div>
2087
2088<!-- *********************************************************************** -->
2089<h4>
Devang Patel8cd89642011-11-15 22:59:54 +00002090 <a name="objcpropertynewattributes">New DWARF Attributes</a>
2091</h4>
2092<!-- *********************************************************************** -->
2093
2094<div>
2095<table border="1" cellspacing="0">
Bill Wendling4af807c2012-03-06 09:22:03 +00002096 <col width="200">
2097 <col width="200">
2098 <col width="200">
Devang Patel8cd89642011-11-15 22:59:54 +00002099 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002100 <th>Attribute</th>
2101 <th>Value</th>
2102 <th>Classes</th>
Devang Patel8cd89642011-11-15 22:59:54 +00002103 </tr>
2104 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002105 <td>DW_AT_APPLE_property</td>
2106 <td>0x3fed</td>
2107 <td>Reference</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002108 </tr>
2109 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002110 <td>DW_AT_APPLE_property_getter</td>
2111 <td>0x3fe9</td>
2112 <td>String</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002113 </tr>
2114 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002115 <td>DW_AT_APPLE_property_setter</td>
2116 <td>0x3fea</td>
2117 <td>String</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002118 </tr>
2119 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002120 <td>DW_AT_APPLE_property_attribute</td>
2121 <td>0x3feb</td>
2122 <td>Constant</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002123 </tr>
2124</table>
2125
2126</div>
2127
2128<!-- *********************************************************************** -->
2129<h4>
2130 <a name="objcpropertynewconstants">New DWARF Constants</a>
2131</h4>
2132<!-- *********************************************************************** -->
2133
2134<div>
2135<table border="1" cellspacing="0">
Bill Wendling4af807c2012-03-06 09:22:03 +00002136 <col width="200">
2137 <col width="200">
Devang Patel8cd89642011-11-15 22:59:54 +00002138 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002139 <th>Name</th>
2140 <th>Value</th>
Devang Patel8cd89642011-11-15 22:59:54 +00002141 </tr>
2142 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002143 <td>DW_AT_APPLE_PROPERTY_readonly</td>
2144 <td>0x1</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002145 </tr>
2146 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002147 <td>DW_AT_APPLE_PROPERTY_readwrite</td>
2148 <td>0x2</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002149 </tr>
2150 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002151 <td>DW_AT_APPLE_PROPERTY_assign</td>
2152 <td>0x4</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002153 </tr>
2154 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002155 <td>DW_AT_APPLE_PROPERTY_retain</td>
2156 <td>0x8</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002157 </tr>
2158 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002159 <td>DW_AT_APPLE_PROPERTY_copy</td>
2160 <td>0x10</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002161 </tr>
2162 <tr>
Bill Wendling61d5e4d2012-03-06 09:20:59 +00002163 <td>DW_AT_APPLE_PROPERTY_nonatomic</td>
2164 <td>0x20</td>
Devang Patel8cd89642011-11-15 22:59:54 +00002165 </tr>
2166</table>
2167
2168</div>
2169</div>
Devang Patel8cd89642011-11-15 22:59:54 +00002170
Eric Christopher85cd2a02012-03-06 02:25:38 +00002171<!-- ======================================================================= -->
2172<h3>
2173 <a name="acceltable">Name Accelerator Tables</a>
2174</h3>
2175<!-- ======================================================================= -->
NAKAMURA Takumic9d9b922012-03-27 11:25:16 +00002176<div>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002177<!-- ======================================================================= -->
2178<h4>
Eric Christopher8c096d62012-03-06 02:25:41 +00002179 <a name="acceltableintroduction">Introduction</a>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002180</h4>
2181<!-- ======================================================================= -->
2182<div>
2183<p>The .debug_pubnames and .debug_pubtypes formats are not what a debugger
2184 needs. The "pub" in the section name indicates that the entries in the
2185 table are publicly visible names only. This means no static or hidden
2186 functions show up in the .debug_pubnames. No static variables or private class
2187 variables are in the .debug_pubtypes. Many compilers add different things to
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002188 these tables, so we can't rely upon the contents between gcc, icc, or clang.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002189
2190<p>The typical query given by users tends not to match up with the contents of
2191 these tables. For example, the DWARF spec states that "In the case of the
2192 name of a function member or static data member of a C++ structure, class or
2193 union, the name presented in the .debug_pubnames section is not the simple
2194 name given by the DW_AT_name attribute of the referenced debugging information
2195 entry, but rather the fully qualified name of the data or function member."
2196 So the only names in these tables for complex C++ entries is a fully
2197 qualified name. Debugger users tend not to enter their search strings as
2198 "a::b::c(int,const Foo&) const", but rather as "c", "b::c" , or "a::b::c". So
2199 the name entered in the name table must be demangled in order to chop it up
2200 appropriately and additional names must be manually entered into the table
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002201 to make it effective as a name lookup table for debuggers to use.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002202
2203<p>All debuggers currently ignore the .debug_pubnames table as a result of
2204 its inconsistent and useless public-only name content making it a waste of
2205 space in the object file. These tables, when they are written to disk, are
2206 not sorted in any way, leaving every debugger to do its own parsing
2207 and sorting. These tables also include an inlined copy of the string values
2208 in the table itself making the tables much larger than they need to be on
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002209 disk, especially for large C++ programs.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002210
2211<p>Can't we just fix the sections by adding all of the names we need to this
2212 table? No, because that is not what the tables are defined to contain and we
2213 won't know the difference between the old bad tables and the new good tables.
2214 At best we could make our own renamed sections that contain all of the data
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002215 we need.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002216
2217<p>These tables are also insufficient for what a debugger like LLDB needs.
2218 LLDB uses clang for its expression parsing where LLDB acts as a PCH. LLDB is
2219 then often asked to look for type "foo" or namespace "bar", or list items in
2220 namespace "baz". Namespaces are not included in the pubnames or pubtypes
2221 tables. Since clang asks a lot of questions when it is parsing an expression,
2222 we need to be very fast when looking up names, as it happens a lot. Having new
2223 accelerator tables that are optimized for very quick lookups will benefit
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002224 this type of debugging experience greatly.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002225
2226<p>We would like to generate name lookup tables that can be mapped into
2227 memory from disk, and used as is, with little or no up-front parsing. We would
2228 also be able to control the exact content of these different tables so they
2229 contain exactly what we need. The Name Accelerator Tables were designed
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002230 to fix these issues. In order to solve these issues we need to:</p>
2231
Eric Christopher85cd2a02012-03-06 02:25:38 +00002232<ul>
2233 <li>Have a format that can be mapped into memory from disk and used as is</li>
2234 <li>Lookups should be very fast</li>
2235 <li>Extensible table format so these tables can be made by many producers</li>
2236 <li>Contain all of the names needed for typical lookups out of the box</li>
2237 <li>Strict rules for the contents of tables</li>
2238</ul>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002239
Eric Christopher85cd2a02012-03-06 02:25:38 +00002240<p>Table size is important and the accelerator table format should allow the
2241 reuse of strings from common string tables so the strings for the names are
2242 not duplicated. We also want to make sure the table is ready to be used as-is
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002243 by simply mapping the table into memory with minimal header parsing.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002244
2245<p>The name lookups need to be fast and optimized for the kinds of lookups
2246 that debuggers tend to do. Optimally we would like to touch as few parts of
2247 the mapped table as possible when doing a name lookup and be able to quickly
2248 find the name entry we are looking for, or discover there are no matches. In
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002249 the case of debuggers we optimized for lookups that fail most of the time.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002250
2251<p>Each table that is defined should have strict rules on exactly what is in
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002252 the accelerator tables and documented so clients can rely on the content.</p>
2253
Eric Christopher85cd2a02012-03-06 02:25:38 +00002254</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002255
Eric Christopher85cd2a02012-03-06 02:25:38 +00002256<!-- ======================================================================= -->
2257<h4>
2258 <a name="acceltablehashes">Hash Tables</a>
2259</h4>
2260<!-- ======================================================================= -->
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002261
Eric Christopher85cd2a02012-03-06 02:25:38 +00002262<div>
2263<h5>Standard Hash Tables</h5>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002264
Eric Christopher85cd2a02012-03-06 02:25:38 +00002265<p>Typical hash tables have a header, buckets, and each bucket points to the
2266bucket contents:
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002267</p>
2268
Eric Christopher85cd2a02012-03-06 02:25:38 +00002269<div class="doc_code">
2270<pre>
2271.------------.
2272| HEADER |
2273|------------|
2274| BUCKETS |
2275|------------|
2276| DATA |
2277`------------'
2278</pre>
2279</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002280
2281<p>The BUCKETS are an array of offsets to DATA for each hash:</p>
2282
Eric Christopher85cd2a02012-03-06 02:25:38 +00002283<div class="doc_code">
2284<pre>
2285.------------.
2286| 0x00001000 | BUCKETS[0]
2287| 0x00002000 | BUCKETS[1]
2288| 0x00002200 | BUCKETS[2]
2289| 0x000034f0 | BUCKETS[3]
2290| | ...
2291| 0xXXXXXXXX | BUCKETS[n_buckets]
2292'------------'
2293</pre>
2294</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002295
Eric Christopher85cd2a02012-03-06 02:25:38 +00002296<p>So for bucket[3] in the example above, we have an offset into the table
2297 0x000034f0 which points to a chain of entries for the bucket. Each bucket
2298 must contain a next pointer, full 32 bit hash value, the string itself,
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002299 and the data for the current string value.</p>
2300
Eric Christopher85cd2a02012-03-06 02:25:38 +00002301<div class="doc_code">
2302<pre>
2303 .------------.
23040x000034f0: | 0x00003500 | next pointer
2305 | 0x12345678 | 32 bit hash
2306 | "erase" | string value
2307 | data[n] | HashData for this bucket
2308 |------------|
23090x00003500: | 0x00003550 | next pointer
2310 | 0x29273623 | 32 bit hash
2311 | "dump" | string value
2312 | data[n] | HashData for this bucket
2313 |------------|
23140x00003550: | 0x00000000 | next pointer
2315 | 0x82638293 | 32 bit hash
2316 | "main" | string value
2317 | data[n] | HashData for this bucket
2318 `------------'
2319</pre>
2320</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002321
Eric Christopher85cd2a02012-03-06 02:25:38 +00002322<p>The problem with this layout for debuggers is that we need to optimize for
2323 the negative lookup case where the symbol we're searching for is not present.
2324 So if we were to lookup "printf" in the table above, we would make a 32 hash
2325 for "printf", it might match bucket[3]. We would need to go to the offset
2326 0x000034f0 and start looking to see if our 32 bit hash matches. To do so, we
2327 need to read the next pointer, then read the hash, compare it, and skip to
2328 the next bucket. Each time we are skipping many bytes in memory and touching
2329 new cache pages just to do the compare on the full 32 bit hash. All of these
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002330 accesses then tell us that we didn't have a match.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002331
2332<h5>Name Hash Tables</h5>
2333
2334<p>To solve the issues mentioned above we have structured the hash tables
2335 a bit differently: a header, buckets, an array of all unique 32 bit hash
2336 values, followed by an array of hash value data offsets, one for each hash
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002337 value, then the data for all hash values:</p>
2338
Eric Christopher85cd2a02012-03-06 02:25:38 +00002339<div class="doc_code">
2340<pre>
2341.-------------.
2342| HEADER |
2343|-------------|
2344| BUCKETS |
2345|-------------|
2346| HASHES |
2347|-------------|
2348| OFFSETS |
2349|-------------|
2350| DATA |
2351`-------------'
2352</pre>
2353</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002354
Eric Christopher8c096d62012-03-06 02:25:41 +00002355<p>The BUCKETS in the name tables are an index into the HASHES array. By
Eric Christopher85cd2a02012-03-06 02:25:38 +00002356 making all of the full 32 bit hash values contiguous in memory, we allow
2357 ourselves to efficiently check for a match while touching as little
Eric Christopher8c096d62012-03-06 02:25:41 +00002358 memory as possible. Most often checking the 32 bit hash values is as far as
Eric Christopher85cd2a02012-03-06 02:25:38 +00002359 the lookup goes. If it does match, it usually is a match with no collisions.
2360 So for a table with "n_buckets" buckets, and "n_hashes" unique 32 bit hash
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002361 values, we can clarify the contents of the BUCKETS, HASHES and OFFSETS as:</p>
2362
Eric Christopher85cd2a02012-03-06 02:25:38 +00002363<div class="doc_code">
2364<pre>
2365.-------------------------.
2366| HEADER.magic | uint32_t
2367| HEADER.version | uint16_t
2368| HEADER.hash_function | uint16_t
2369| HEADER.bucket_count | uint32_t
2370| HEADER.hashes_count | uint32_t
2371| HEADER.header_data_len | uint32_t
2372| HEADER_DATA | HeaderData
2373|-------------------------|
2374| BUCKETS | uint32_t[n_buckets] // 32 bit hash indexes
2375|-------------------------|
2376| HASHES | uint32_t[n_buckets] // 32 bit hash values
2377|-------------------------|
2378| OFFSETS | uint32_t[n_buckets] // 32 bit offsets to hash value data
2379|-------------------------|
2380| ALL HASH DATA |
2381`-------------------------'
2382</pre>
2383</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002384
Eric Christopher85cd2a02012-03-06 02:25:38 +00002385<p>So taking the exact same data from the standard hash example above we end up
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002386 with:</p>
2387
Eric Christopher85cd2a02012-03-06 02:25:38 +00002388<div class="doc_code">
2389<pre>
2390 .------------.
2391 | HEADER |
2392 |------------|
2393 | 0 | BUCKETS[0]
2394 | 2 | BUCKETS[1]
2395 | 5 | BUCKETS[2]
2396 | 6 | BUCKETS[3]
2397 | | ...
2398 | ... | BUCKETS[n_buckets]
2399 |------------|
2400 | 0x........ | HASHES[0]
2401 | 0x........ | HASHES[1]
2402 | 0x........ | HASHES[2]
2403 | 0x........ | HASHES[3]
2404 | 0x........ | HASHES[4]
2405 | 0x........ | HASHES[5]
2406 | 0x12345678 | HASHES[6] hash for BUCKETS[3]
2407 | 0x29273623 | HASHES[7] hash for BUCKETS[3]
2408 | 0x82638293 | HASHES[8] hash for BUCKETS[3]
2409 | 0x........ | HASHES[9]
2410 | 0x........ | HASHES[10]
2411 | 0x........ | HASHES[11]
2412 | 0x........ | HASHES[12]
2413 | 0x........ | HASHES[13]
2414 | 0x........ | HASHES[n_hashes]
2415 |------------|
2416 | 0x........ | OFFSETS[0]
2417 | 0x........ | OFFSETS[1]
2418 | 0x........ | OFFSETS[2]
2419 | 0x........ | OFFSETS[3]
2420 | 0x........ | OFFSETS[4]
2421 | 0x........ | OFFSETS[5]
2422 | 0x000034f0 | OFFSETS[6] offset for BUCKETS[3]
2423 | 0x00003500 | OFFSETS[7] offset for BUCKETS[3]
2424 | 0x00003550 | OFFSETS[8] offset for BUCKETS[3]
2425 | 0x........ | OFFSETS[9]
2426 | 0x........ | OFFSETS[10]
2427 | 0x........ | OFFSETS[11]
2428 | 0x........ | OFFSETS[12]
2429 | 0x........ | OFFSETS[13]
2430 | 0x........ | OFFSETS[n_hashes]
2431 |------------|
2432 | |
2433 | |
2434 | |
2435 | |
2436 | |
2437 |------------|
24380x000034f0: | 0x00001203 | .debug_str ("erase")
2439 | 0x00000004 | A 32 bit array count - number of HashData with name "erase"
2440 | 0x........ | HashData[0]
2441 | 0x........ | HashData[1]
2442 | 0x........ | HashData[2]
2443 | 0x........ | HashData[3]
2444 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2445 |------------|
24460x00003500: | 0x00001203 | String offset into .debug_str ("collision")
2447 | 0x00000002 | A 32 bit array count - number of HashData with name "collision"
2448 | 0x........ | HashData[0]
2449 | 0x........ | HashData[1]
2450 | 0x00001203 | String offset into .debug_str ("dump")
2451 | 0x00000003 | A 32 bit array count - number of HashData with name "dump"
2452 | 0x........ | HashData[0]
2453 | 0x........ | HashData[1]
2454 | 0x........ | HashData[2]
2455 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2456 |------------|
24570x00003550: | 0x00001203 | String offset into .debug_str ("main")
2458 | 0x00000009 | A 32 bit array count - number of HashData with name "main"
2459 | 0x........ | HashData[0]
2460 | 0x........ | HashData[1]
2461 | 0x........ | HashData[2]
2462 | 0x........ | HashData[3]
2463 | 0x........ | HashData[4]
2464 | 0x........ | HashData[5]
2465 | 0x........ | HashData[6]
2466 | 0x........ | HashData[7]
2467 | 0x........ | HashData[8]
2468 | 0x00000000 | String offset into .debug_str (terminate data for hash)
2469 `------------'
2470</pre>
2471</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002472
Eric Christopher85cd2a02012-03-06 02:25:38 +00002473<p>So we still have all of the same data, we just organize it more efficiently
2474 for debugger lookup. If we repeat the same "printf" lookup from above, we
2475 would hash "printf" and find it matches BUCKETS[3] by taking the 32 bit hash
2476 value and modulo it by n_buckets. BUCKETS[3] contains "6" which is the index
2477 into the HASHES table. We would then compare any consecutive 32 bit hashes
2478 values in the HASHES array as long as the hashes would be in BUCKETS[3]. We
2479 do this by verifying that each subsequent hash value modulo n_buckets is still
2480 3. In the case of a failed lookup we would access the memory for BUCKETS[3], and
2481 then compare a few consecutive 32 bit hashes before we know that we have no match.
2482 We don't end up marching through multiple words of memory and we really keep the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002483 number of processor data cache lines being accessed as small as possible.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002484
2485<p>The string hash that is used for these lookup tables is the Daniel J.
2486 Bernstein hash which is also used in the ELF GNU_HASH sections. It is a very
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002487 good hash for all kinds of names in programs with very few hash collisions.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002488
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002489<p>Empty buckets are designated by using an invalid hash index of UINT32_MAX.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002490</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002491
Eric Christopher85cd2a02012-03-06 02:25:38 +00002492<!-- ======================================================================= -->
2493<h4>
2494 <a name="acceltabledetails">Details</a>
2495</h4>
2496<!-- ======================================================================= -->
2497<div>
2498<p>These name hash tables are designed to be generic where specializations of
2499 the table get to define additional data that goes into the header
2500 ("HeaderData"), how the string value is stored ("KeyType") and the content
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002501 of the data for each hash value.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002502
2503<h5>Header Layout</h5>
2504<p>The header has a fixed part, and the specialized part. The exact format of
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002505 the header is:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002506<div class="doc_code">
2507<pre>
2508struct Header
2509{
2510 uint32_t magic; // 'HASH' magic value to allow endian detection
2511 uint16_t version; // Version number
2512 uint16_t hash_function; // The hash function enumeration that was used
2513 uint32_t bucket_count; // The number of buckets in this hash table
2514 uint32_t hashes_count; // The total number of unique hash values and hash data offsets in this table
2515 uint32_t header_data_len; // The bytes to skip to get to the hash indexes (buckets) for correct alignment
2516 // Specifically the length of the following HeaderData field - this does not
2517 // include the size of the preceding fields
2518 HeaderData header_data; // Implementation specific header data
2519};
2520</pre>
2521</div>
2522<p>The header starts with a 32 bit "magic" value which must be 'HASH' encoded as
2523 an ASCII integer. This allows the detection of the start of the hash table and
2524 also allows the table's byte order to be determined so the table can be
2525 correctly extracted. The "magic" value is followed by a 16 bit version number
2526 which allows the table to be revised and modified in the future. The current
2527 version number is 1. "hash_function" is a uint16_t enumeration that specifies
2528 which hash function was used to produce this table. The current values for the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002529 hash function enumerations include:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002530<div class="doc_code">
2531<pre>
2532enum HashFunctionType
2533{
2534 eHashFunctionDJB = 0u, // Daniel J Bernstein hash function
2535};
2536</pre>
2537</div>
2538<p>"bucket_count" is a 32 bit unsigned integer that represents how many buckets
2539 are in the BUCKETS array. "hashes_count" is the number of unique 32 bit hash
2540 values that are in the HASHES array, and is the same number of offsets are
2541 contained in the OFFSETS array. "header_data_len" specifies the size in
2542 bytes of the HeaderData that is filled in by specialized versions of this
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002543 table.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002544
2545<h5>Fixed Lookup</h5>
2546<p>The header is followed by the buckets, hashes, offsets, and hash value
2547 data.
2548<div class="doc_code">
2549<pre>
2550struct FixedTable
2551{
2552 uint32_t buckets[Header.bucket_count]; // An array of hash indexes into the "hashes[]" array below
2553 uint32_t hashes [Header.hashes_count]; // Every unique 32 bit hash for the entire table is in this table
2554 uint32_t offsets[Header.hashes_count]; // An offset that corresponds to each item in the "hashes[]" array above
2555};
2556</pre>
2557</div>
2558<p>"buckets" is an array of 32 bit indexes into the "hashes" array. The
2559 "hashes" array contains all of the 32 bit hash values for all names in the
2560 hash table. Each hash in the "hashes" table has an offset in the "offsets"
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002561 array that points to the data for the hash value.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002562
2563<p>This table setup makes it very easy to repurpose these tables to contain
2564 different data, while keeping the lookup mechanism the same for all tables.
2565 This layout also makes it possible to save the table to disk and map it in
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002566 later and do very efficient name lookups with little or no parsing.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002567
2568<p>DWARF lookup tables can be implemented in a variety of ways and can store
2569 a lot of information for each name. We want to make the DWARF tables
2570 extensible and able to store the data efficiently so we have used some of the
2571 DWARF features that enable efficient data storage to define exactly what kind
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002572 of data we store for each name.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002573
2574<p>The "HeaderData" contains a definition of the contents of each HashData
2575 chunk. We might want to store an offset to all of the debug information
2576 entries (DIEs) for each name. To keep things extensible, we create a list of
2577 items, or Atoms, that are contained in the data for each name. First comes the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002578 type of the data in each atom:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002579<div class="doc_code">
2580<pre>
2581enum AtomType
2582{
2583 eAtomTypeNULL = 0u,
2584 eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding
2585 eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that contains the item in question
2586 eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed 255) or DW_FORM_data2
2587 eAtomTypeNameFlags = 4u, // Flags from enum NameFlags
2588 eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags
2589};
2590</pre>
2591</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002592<p>The enumeration values and their meanings are:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002593<div class="doc_code">
2594<pre>
2595 eAtomTypeNULL - a termination atom that specifies the end of the atom list
2596 eAtomTypeDIEOffset - an offset into the .debug_info section for the DWARF DIE for this name
2597 eAtomTypeCUOffset - an offset into the .debug_info section for the CU that contains the DIE
2598 eAtomTypeDIETag - The DW_TAG_XXX enumeration value so you don't have to parse the DWARF to see what it is
2599 eAtomTypeNameFlags - Flags for functions and global variables (isFunction, isInlined, isExternal...)
2600 eAtomTypeTypeFlags - Flags for types (isCXXClass, isObjCClass, ...)
2601</pre>
2602</div>
2603<p>Then we allow each atom type to define the atom type and how the data for
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002604 each atom type data is encoded:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002605<div class="doc_code">
2606<pre>
2607struct Atom
2608{
2609 uint16_t type; // AtomType enum value
2610 uint16_t form; // DWARF DW_FORM_XXX defines
2611};
2612</pre>
2613</div>
2614<p>The "form" type above is from the DWARF specification and defines the
2615 exact encoding of the data for the Atom type. See the DWARF specification for
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002616 the DW_FORM_ definitions.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002617<div class="doc_code">
2618<pre>
2619struct HeaderData
2620{
2621 uint32_t die_offset_base;
2622 uint32_t atom_count;
2623 Atoms atoms[atom_count0];
2624};
2625</pre>
2626</div>
2627<p>"HeaderData" defines the base DIE offset that should be added to any atoms
2628 that are encoded using the DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4,
2629 DW_FORM_ref8 or DW_FORM_ref_udata. It also defines what is contained in
2630 each "HashData" object -- Atom.form tells us how large each field will be in
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002631 the HashData and the Atom.type tells us how this data should be interpreted.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002632
2633<p>For the current implementations of the ".apple_names" (all functions + globals),
2634 the ".apple_types" (names of all types that are defined), and the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002635 ".apple_namespaces" (all namespaces), we currently set the Atom array to be:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002636<div class="doc_code">
2637<pre>
2638HeaderData.atom_count = 1;
2639HeaderData.atoms[0].type = eAtomTypeDIEOffset;
2640HeaderData.atoms[0].form = DW_FORM_data4;
2641</pre>
2642</div>
2643<p>This defines the contents to be the DIE offset (eAtomTypeDIEOffset) that is
2644 encoded as a 32 bit value (DW_FORM_data4). This allows a single name to have
2645 multiple matching DIEs in a single file, which could come up with an inlined
2646 function for instance. Future tables could include more information about the
2647 DIE such as flags indicating if the DIE is a function, method, block,
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002648 or inlined.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002649
2650<p>The KeyType for the DWARF table is a 32 bit string table offset into the
2651 ".debug_str" table. The ".debug_str" is the string table for the DWARF which
2652 may already contain copies of all of the strings. This helps make sure, with
2653 help from the compiler, that we reuse the strings between all of the DWARF
2654 sections and keeps the hash table size down. Another benefit to having the
2655 compiler generate all strings as DW_FORM_strp in the debug info, is that
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002656 DWARF parsing can be made much faster.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002657
2658<p>After a lookup is made, we get an offset into the hash data. The hash data
2659 needs to be able to deal with 32 bit hash collisions, so the chunk of data
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002660 at the offset in the hash data consists of a triple:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002661<div class="doc_code">
2662<pre>
2663uint32_t str_offset
2664uint32_t hash_data_count
2665HashData[hash_data_count]
2666</pre>
2667</div>
2668<p>If "str_offset" is zero, then the bucket contents are done. 99.9% of the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002669 hash data chunks contain a single item (no 32 bit hash collision):</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002670<div class="doc_code">
2671<pre>
2672.------------.
2673| 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
2674| 0x00000004 | uint32_t HashData count
2675| 0x........ | uint32_t HashData[0] DIE offset
2676| 0x........ | uint32_t HashData[1] DIE offset
2677| 0x........ | uint32_t HashData[2] DIE offset
2678| 0x........ | uint32_t HashData[3] DIE offset
2679| 0x00000000 | uint32_t KeyType (end of hash chain)
2680`------------'
2681</pre>
2682</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002683<p>If there are collisions, you will have multiple valid string offsets:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002684<div class="doc_code">
2685<pre>
2686.------------.
2687| 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main")
2688| 0x00000004 | uint32_t HashData count
2689| 0x........ | uint32_t HashData[0] DIE offset
2690| 0x........ | uint32_t HashData[1] DIE offset
2691| 0x........ | uint32_t HashData[2] DIE offset
2692| 0x........ | uint32_t HashData[3] DIE offset
2693| 0x00002023 | uint32_t KeyType (.debug_str[0x0002023] => "print")
2694| 0x00000002 | uint32_t HashData count
2695| 0x........ | uint32_t HashData[0] DIE offset
2696| 0x........ | uint32_t HashData[1] DIE offset
2697| 0x00000000 | uint32_t KeyType (end of hash chain)
2698`------------'
2699</pre>
2700</div>
2701<p>Current testing with real world C++ binaries has shown that there is around 1
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002702 32 bit hash collision per 100,000 name entries.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002703</div>
2704<!-- ======================================================================= -->
2705<h4>
2706 <a name="acceltablecontents">Contents</a>
2707</h4>
2708<!-- ======================================================================= -->
2709<div>
2710<p>As we said, we want to strictly define exactly what is included in the
2711 different tables. For DWARF, we have 3 tables: ".apple_names", ".apple_types",
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002712 and ".apple_namespaces".</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002713
2714<p>".apple_names" sections should contain an entry for each DWARF DIE whose
2715 DW_TAG is a DW_TAG_label, DW_TAG_inlined_subroutine, or DW_TAG_subprogram that
2716 has address attributes: DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges or
2717 DW_AT_entry_pc. It also contains DW_TAG_variable DIEs that have a DW_OP_addr
2718 in the location (global and static variables). All global and static variables
2719 should be included, including those scoped withing functions and classes. For
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002720 example using the following code:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002721<div class="doc_code">
2722<pre>
2723static int var = 0;
2724
2725void f ()
2726{
2727 static int var = 0;
2728}
2729</pre>
2730</div>
2731<p>Both of the static "var" variables would be included in the table. All
2732 functions should emit both their full names and their basenames. For C or C++,
2733 the full name is the mangled name (if available) which is usually in the
2734 DW_AT_MIPS_linkage_name attribute, and the DW_AT_name contains the function
2735 basename. If global or static variables have a mangled name in a
2736 DW_AT_MIPS_linkage_name attribute, this should be emitted along with the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002737 simple name found in the DW_AT_name attribute.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002738
2739<p>".apple_types" sections should contain an entry for each DWARF DIE whose
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002740 tag is one of:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002741<ul>
2742 <li>DW_TAG_array_type</li>
2743 <li>DW_TAG_class_type</li>
2744 <li>DW_TAG_enumeration_type</li>
2745 <li>DW_TAG_pointer_type</li>
2746 <li>DW_TAG_reference_type</li>
2747 <li>DW_TAG_string_type</li>
2748 <li>DW_TAG_structure_type</li>
2749 <li>DW_TAG_subroutine_type</li>
2750 <li>DW_TAG_typedef</li>
2751 <li>DW_TAG_union_type</li>
2752 <li>DW_TAG_ptr_to_member_type</li>
2753 <li>DW_TAG_set_type</li>
2754 <li>DW_TAG_subrange_type</li>
2755 <li>DW_TAG_base_type</li>
2756 <li>DW_TAG_const_type</li>
2757 <li>DW_TAG_constant</li>
2758 <li>DW_TAG_file_type</li>
2759 <li>DW_TAG_namelist</li>
2760 <li>DW_TAG_packed_type</li>
2761 <li>DW_TAG_volatile_type</li>
2762 <li>DW_TAG_restrict_type</li>
2763 <li>DW_TAG_interface_type</li>
2764 <li>DW_TAG_unspecified_type</li>
2765 <li>DW_TAG_shared_type</li>
2766</ul>
2767<p>Only entries with a DW_AT_name attribute are included, and the entry must
2768 not be a forward declaration (DW_AT_declaration attribute with a non-zero value).
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002769 For example, using the following code:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002770<div class="doc_code">
2771<pre>
2772int main ()
2773{
2774 int *b = 0;
2775 return *b;
2776}
2777</pre>
2778</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002779<p>We get a few type DIEs:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002780<div class="doc_code">
2781<pre>
27820x00000067: TAG_base_type [5]
2783 AT_encoding( DW_ATE_signed )
2784 AT_name( "int" )
2785 AT_byte_size( 0x04 )
2786
27870x0000006e: TAG_pointer_type [6]
2788 AT_type( {0x00000067} ( int ) )
2789 AT_byte_size( 0x08 )
2790</pre>
2791</div>
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002792<p>The DW_TAG_pointer_type is not included because it does not have a DW_AT_name.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002793
2794<p>".apple_namespaces" section should contain all DW_TAG_namespace DIEs. If
2795 we run into a namespace that has no name this is an anonymous namespace,
2796 and the name should be output as "(anonymous namespace)" (without the quotes).
2797 Why? This matches the output of the abi::cxa_demangle() that is in the standard
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002798 C++ library that demangles mangled names.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002799</div>
2800
2801<!-- ======================================================================= -->
2802<h4>
2803 <a name="acceltableextensions">Language Extensions and File Format Changes</a>
2804</h4>
2805<!-- ======================================================================= -->
2806<div>
2807<h5>Objective-C Extensions</h5>
2808<p>".apple_objc" section should contain all DW_TAG_subprogram DIEs for an
2809 Objective-C class. The name used in the hash table is the name of the
2810 Objective-C class itself. If the Objective-C class has a category, then an
2811 entry is made for both the class name without the category, and for the class
2812 name with the category. So if we have a DIE at offset 0x1234 with a name
2813 of method "-[NSString(my_additions) stringWithSpecialString:]", we would add
2814 an entry for "NSString" that points to DIE 0x1234, and an entry for
2815 "NSString(my_additions)" that points to 0x1234. This allows us to quickly
2816 track down all Objective-C methods for an Objective-C class when doing
2817 expressions. It is needed because of the dynamic nature of Objective-C where
2818 anyone can add methods to a class. The DWARF for Objective-C methods is also
2819 emitted differently from C++ classes where the methods are not usually
2820 contained in the class definition, they are scattered about across one or more
2821 compile units. Categories can also be defined in different shared libraries.
2822 So we need to be able to quickly find all of the methods and class functions
2823 given the Objective-C class name, or quickly find all methods and class
2824 functions for a class + category name. This table does not contain any selector
2825 names, it just maps Objective-C class names (or class names + category) to all
2826 of the methods and class functions. The selectors are added as function
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002827 basenames in the .debug_names section.</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002828
2829<p>In the ".apple_names" section for Objective-C functions, the full name is the
2830 entire function name with the brackets ("-[NSString stringWithCString:]") and the
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002831 basename is the selector only ("stringWithCString:").</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002832
2833<h5>Mach-O Changes</h5>
2834<p>The sections names for the apple hash tables are for non mach-o files. For
2835 mach-o files, the sections should be contained in the "__DWARF" segment with
Bill Wendling4bf1cc82012-03-06 08:59:13 +00002836 names as follows:</p>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002837<ul>
2838 <li>".apple_names" -> "__apple_names"</li>
2839 <li>".apple_types" -> "__apple_types"</li>
2840 <li>".apple_namespaces" -> "__apple_namespac" (16 character limit)</li>
2841 <li> ".apple_objc" -> "__apple_objc"</li>
2842</ul>
2843</div>
2844</div>
NAKAMURA Takumic9d9b922012-03-27 11:25:16 +00002845</div>
Eric Christopher85cd2a02012-03-06 02:25:38 +00002846
Chris Lattner1811fca2004-01-05 05:06:33 +00002847<!-- *********************************************************************** -->
Misha Brukmanf91d9942004-05-12 19:21:57 +00002848
Chris Lattner1811fca2004-01-05 05:06:33 +00002849<hr>
Misha Brukmanf91d9942004-05-12 19:21:57 +00002850<address>
2851 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00002852 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmanf91d9942004-05-12 19:21:57 +00002853 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00002854 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Misha Brukmanf91d9942004-05-12 19:21:57 +00002855
2856 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
NAKAMURA Takumica46f5a2011-04-09 02:13:37 +00002857 <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br>
Chris Lattner1811fca2004-01-05 05:06:33 +00002858 Last modified: $Date$
Misha Brukmanf91d9942004-05-12 19:21:57 +00002859</address>
Chris Lattner1811fca2004-01-05 05:06:33 +00002860
2861</body>
2862</html>