blob: 399187d0daa35cf5dab3a0a2d59c52485822e231 [file] [log] [blame]
Chris Lattnerbdfb3392004-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 Wendling48839d92009-05-17 05:52:39 +00005 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Chris Lattnerbdfb3392004-01-05 05:06:33 +00006 <title>Source Level Debugging with LLVM</title>
7 <link rel="stylesheet" href="llvm.css" type="text/css">
8</head>
9<body>
10
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000011<h1>Source Level Debugging with LLVM</h1>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000012
Reid Spencerd3f876c2004-11-01 08:19:36 +000013<table class="layout" style="width:100%">
14 <tr class="layout">
15 <td class="left">
Chris Lattnerbdfb3392004-01-05 05:06:33 +000016<ul>
Misha Brukman82873732004-05-12 19:21:57 +000017 <li><a href="#introduction">Introduction</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000018 <ol>
19 <li><a href="#phil">Philosophy behind LLVM debugging information</a></li>
Jim Laskey383e0092006-03-23 17:54:33 +000020 <li><a href="#consumers">Debug information consumers</a></li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000021 <li><a href="#debugopt">Debugging optimized code</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000022 </ol></li>
Misha Brukman82873732004-05-12 19:21:57 +000023 <li><a href="#format">Debugging information format</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000024 <ol>
Jim Laskeycec12a52006-03-14 18:08:46 +000025 <li><a href="#debug_info_descriptors">Debug information descriptors</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000026 <ul>
Jim Laskeycec12a52006-03-14 18:08:46 +000027 <li><a href="#format_compile_units">Compile unit descriptors</a></li>
Devang Patel4b945502010-03-09 00:44:10 +000028 <li><a href="#format_files">File descriptors</a></li>
Jim Laskeycec12a52006-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 Laskey3d11bee2006-03-15 19:10:52 +000031 <li><a href="#format_blocks">Block descriptors</a></li>
Jim Laskeycec12a52006-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 Laskey383e0092006-03-23 17:54:33 +000037 <li><a href="#format_variables">Local variables</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000038 </ul></li>
Jim Laskeycec12a52006-03-14 18:08:46 +000039 <li><a href="#format_common_intrinsics">Debugger intrinsic functions</a>
40 <ul>
Jim Laskeycec12a52006-03-14 18:08:46 +000041 <li><a href="#format_common_declare">llvm.dbg.declare</a></li>
Victor Hernandez67a1a542010-01-11 22:53:48 +000042 <li><a href="#format_common_value">llvm.dbg.value</a></li>
Jim Laskeycec12a52006-03-14 18:08:46 +000043 </ul></li>
Misha Brukman82873732004-05-12 19:21:57 +000044 </ol></li>
Devang Patel744950d2009-11-25 23:28:01 +000045 <li><a href="#format_common_lifetime">Object lifetimes and scoping</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000046 <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000047 <ol>
Jim Laskeycec12a52006-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 Brukman82873732004-05-12 19:21:57 +000055 </ol></li>
Devang Patel6ac5b162011-11-15 22:59:54 +000056 <li><a href="#llvmdwarfextension">LLVM Dwarf Extensions</a>
57 <ol>
Eric Christopherfc7243a2012-03-06 02:25:36 +000058 <li><a href="#objcproperty">Debugging Information Extension
Devang Patel6ac5b162011-11-15 22:59:54 +000059 for Objective C Properties</a></li>
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
67 </ol>
68 </li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000069</ul>
Misha Brukman82873732004-05-12 19:21:57 +000070</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +000071<td class="right">
Misha Brukmane849a1a2004-05-12 21:26:16 +000072<img src="img/venusflytrap.jpg" alt="A leafy and green bug eater" width="247"
Misha Brukman82873732004-05-12 19:21:57 +000073height="369">
74</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +000075</tr></table>
Misha Brukman82873732004-05-12 19:21:57 +000076
Chris Lattner7911ce22004-05-23 21:07:27 +000077<div class="doc_author">
Jim Laskeycec12a52006-03-14 18:08:46 +000078 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
Jim Laskeyc760a922007-03-14 19:32:21 +000079 and <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
Chris Lattner7911ce22004-05-23 21:07:27 +000080</div>
81
Chris Lattnerbdfb3392004-01-05 05:06:33 +000082
83<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000084<h2><a name="introduction">Introduction</a></h2>
Misha Brukman94218a72004-12-09 20:27:37 +000085<!-- *********************************************************************** -->
Chris Lattnerbdfb3392004-01-05 05:06:33 +000086
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +000087<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000088
89<p>This document is the central repository for all information pertaining to
Bill Wendling48839d92009-05-17 05:52:39 +000090 debug information in LLVM. It describes the <a href="#format">actual format
91 that the LLVM debug information</a> takes, which is useful for those
92 interested in creating front-ends or dealing directly with the information.
Chris Lattner8ad2f982009-07-18 21:47:15 +000093 Further, this document provides specific examples of what debug information
Chris Lattner89940752011-01-18 06:12:10 +000094 for C/C++ looks like.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000095
Chris Lattnerbdfb3392004-01-05 05:06:33 +000096<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000097<h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000098 <a name="phil">Philosophy behind LLVM debugging information</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +000099</h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000100
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000101<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000102
Misha Brukman82873732004-05-12 19:21:57 +0000103<p>The idea of the LLVM debugging information is to capture how the important
Bill Wendling48839d92009-05-17 05:52:39 +0000104 pieces of the source-language's Abstract Syntax Tree map onto LLVM code.
105 Several design aspects have shaped the solution that appears here. The
106 important ones are:</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000107
Misha Brukman82873732004-05-12 19:21:57 +0000108<ul>
Bill Wendling48839d92009-05-17 05:52:39 +0000109 <li>Debugging information should have very little impact on the rest of the
110 compiler. No transformations, analyses, or code generators should need to
111 be modified because of debugging information.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000112
Bill Wendling48839d92009-05-17 05:52:39 +0000113 <li>LLVM optimizations should interact in <a href="#debugopt">well-defined and
114 easily described ways</a> with the debugging information.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000115
Bill Wendling48839d92009-05-17 05:52:39 +0000116 <li>Because LLVM is designed to support arbitrary programming languages,
117 LLVM-to-LLVM tools should not need to know anything about the semantics of
118 the source-level-language.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000119
Bill Wendling48839d92009-05-17 05:52:39 +0000120 <li>Source-level languages are often <b>widely</b> different from one another.
121 LLVM should not put any restrictions of the flavor of the source-language,
122 and the debugging information should work with any language.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000123
Bill Wendling48839d92009-05-17 05:52:39 +0000124 <li>With code generator support, it should be possible to use an LLVM compiler
125 to compile a program to native machine code and standard debugging
126 formats. This allows compatibility with traditional machine-code level
127 debuggers, like GDB or DBX.</li>
Misha Brukman82873732004-05-12 19:21:57 +0000128</ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000129
Bill Wendling48839d92009-05-17 05:52:39 +0000130<p>The approach used by the LLVM implementation is to use a small set
131 of <a href="#format_common_intrinsics">intrinsic functions</a> to define a
132 mapping between LLVM program objects and the source-level objects. The
Devang Patele4b27562009-08-28 23:24:31 +0000133 description of the source-level program is maintained in LLVM metadata
134 in an <a href="#ccxx_frontend">implementation-defined format</a>
Bill Wendling48839d92009-05-17 05:52:39 +0000135 (the C/C++ front-end currently uses working draft 7 of
136 the <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3
137 standard</a>).</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000138
Jim Laskeycec12a52006-03-14 18:08:46 +0000139<p>When a program is being debugged, a debugger interacts with the user and
Bill Wendling48839d92009-05-17 05:52:39 +0000140 turns the stored debug information into source-language specific information.
141 As such, a debugger must be aware of the source-language, and is thus tied to
142 a specific language or family of languages.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000143
144</div>
145
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000146<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000147<h3>
Jim Laskey383e0092006-03-23 17:54:33 +0000148 <a name="consumers">Debug information consumers</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000149</h3>
Jim Laskey383e0092006-03-23 17:54:33 +0000150
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000151<div>
Bill Wendling48839d92009-05-17 05:52:39 +0000152
Jim Laskey383e0092006-03-23 17:54:33 +0000153<p>The role of debug information is to provide meta information normally
Bill Wendling48839d92009-05-17 05:52:39 +0000154 stripped away during the compilation process. This meta information provides
155 an LLVM user a relationship between generated code and the original program
156 source code.</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000157
Chris Lattnerc3107782010-04-05 04:11:11 +0000158<p>Currently, debug information is consumed by DwarfDebug to produce dwarf
Bill Wendling48839d92009-05-17 05:52:39 +0000159 information used by the gdb debugger. Other targets could use the same
160 information to produce stabs or other debug forms.</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000161
162<p>It would also be reasonable to use debug information to feed profiling tools
Bill Wendling48839d92009-05-17 05:52:39 +0000163 for analysis of generated code, or, tools for reconstructing the original
164 source from generated code.</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000165
166<p>TODO - expound a bit more.</p>
167
168</div>
169
170<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000171<h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000172 <a name="debugopt">Debugging optimized code</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000173</h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000174
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000175<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000176
Misha Brukman82873732004-05-12 19:21:57 +0000177<p>An extremely high priority of LLVM debugging information is to make it
Bill Wendling48839d92009-05-17 05:52:39 +0000178 interact well with optimizations and analysis. In particular, the LLVM debug
179 information provides the following guarantees:</p>
Misha Brukman82873732004-05-12 19:21:57 +0000180
181<ul>
Bill Wendling48839d92009-05-17 05:52:39 +0000182 <li>LLVM debug information <b>always provides information to accurately read
183 the source-level state of the program</b>, regardless of which LLVM
184 optimizations have been run, and without any modification to the
185 optimizations themselves. However, some optimizations may impact the
186 ability to modify the current state of the program with a debugger, such
187 as setting program variables, or calling functions that have been
188 deleted.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000189
Bill Wendling48839d92009-05-17 05:52:39 +0000190 <li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM
191 debugging information, allowing them to update the debugging information
192 as they perform aggressive optimizations. This means that, with effort,
193 the LLVM optimizers could optimize debug code just as well as non-debug
194 code.</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000195
Devang Patele0bdc592011-05-31 17:45:27 +0000196 <li>LLVM debug information does not prevent optimizations from
Bill Wendling48839d92009-05-17 05:52:39 +0000197 happening (for example inlining, basic block reordering/merging/cleanup,
Devang Patelf729e912011-05-31 18:06:14 +0000198 tail duplication, etc).</li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000199
Bill Wendling48839d92009-05-17 05:52:39 +0000200 <li>LLVM debug information is automatically optimized along with the rest of
201 the program, using existing facilities. For example, duplicate
202 information is automatically merged by the linker, and unused information
203 is automatically removed.</li>
Misha Brukman82873732004-05-12 19:21:57 +0000204</ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000205
Misha Brukman82873732004-05-12 19:21:57 +0000206<p>Basically, the debug information allows you to compile a program with
Bill Wendling48839d92009-05-17 05:52:39 +0000207 "<tt>-O0 -g</tt>" and get full debug information, allowing you to arbitrarily
208 modify the program as it executes from a debugger. Compiling a program with
209 "<tt>-O3 -g</tt>" gives you full debug information that is always available
210 and accurate for reading (e.g., you get accurate stack traces despite tail
211 call elimination and inlining), but you might lose the ability to modify the
212 program and call functions where were optimized out of the program, or
213 inlined away completely.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000214
Misha Brukman96e00812008-12-16 02:54:22 +0000215<p><a href="TestingGuide.html#quicktestsuite">LLVM test suite</a> provides a
Bill Wendling48839d92009-05-17 05:52:39 +0000216 framework to test optimizer's handling of debugging information. It can be
217 run like this:</p>
Devang Patela5c05aa2008-11-21 19:35:57 +0000218
219<div class="doc_code">
220<pre>
221% cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level
222% make TEST=dbgopt
223</pre>
224</div>
225
Bill Wendling48839d92009-05-17 05:52:39 +0000226<p>This will test impact of debugging information on optimization passes. If
227 debugging information influences optimization passes then it will be reported
228 as a failure. See <a href="TestingGuide.html">TestingGuide</a> for more
229 information on LLVM test infrastructure and how to run various tests.</p>
Devang Patela5c05aa2008-11-21 19:35:57 +0000230
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000231</div>
232
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000233</div>
234
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000235<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000236<h2>
Chris Lattner8ff75902004-01-06 05:31:32 +0000237 <a name="format">Debugging information format</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000238</h2>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000239<!-- *********************************************************************** -->
240
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000241<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000242
243<p>LLVM debugging information has been carefully designed to make it possible
Bill Wendling48839d92009-05-17 05:52:39 +0000244 for the optimizer to optimize the program and debugging information without
245 necessarily having to know anything about debugging information. In
John Criswellb34500f2010-03-17 15:01:50 +0000246 particular, the use of metadata avoids duplicated debugging information from
Eric Christopherfc7243a2012-03-06 02:25:36 +0000247 the beginning, and the global dead code elimination pass automatically
248 deletes debugging information for a function if it decides to delete the
Devang Patele4b27562009-08-28 23:24:31 +0000249 function. </p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000250
251<p>To do this, most of the debugging information (descriptors for types,
Bill Wendling48839d92009-05-17 05:52:39 +0000252 variables, functions, source files, etc) is inserted by the language
Devang Patele4b27562009-08-28 23:24:31 +0000253 front-end in the form of LLVM metadata. </p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000254
Jim Laskeycec12a52006-03-14 18:08:46 +0000255<p>Debug information is designed to be agnostic about the target debugger and
Bill Wendling48839d92009-05-17 05:52:39 +0000256 debugging information representation (e.g. DWARF/Stabs/etc). It uses a
Eric Christopherfc7243a2012-03-06 02:25:36 +0000257 generic pass to decode the information that represents variables, types,
258 functions, namespaces, etc: this allows for arbitrary source-language
259 semantics and type-systems to be used, as long as there is a module
Devang Patele4b27562009-08-28 23:24:31 +0000260 written for the target debugger to interpret the information. </p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000261
Misha Brukman82873732004-05-12 19:21:57 +0000262<p>To provide basic functionality, the LLVM debugger does have to make some
Bill Wendling48839d92009-05-17 05:52:39 +0000263 assumptions about the source-level language being debugged, though it keeps
264 these to a minimum. The only common features that the LLVM debugger assumes
Devang Patel4b945502010-03-09 00:44:10 +0000265 exist are <a href="#format_files">source files</a>,
Bill Wendling48839d92009-05-17 05:52:39 +0000266 and <a href="#format_global_variables">program objects</a>. These abstract
267 objects are used by a debugger to form stack traces, show information about
268 local variables, etc.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000269
270<p>This section of the documentation first describes the representation aspects
Bill Wendling48839d92009-05-17 05:52:39 +0000271 common to any source-language. The <a href="#ccxx_frontend">next section</a>
272 describes the data layout conventions used by the C and C++ front-ends.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000273
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000274<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000275<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +0000276 <a name="debug_info_descriptors">Debug information descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000277</h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000278
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000279<div>
Bill Wendling48839d92009-05-17 05:52:39 +0000280
Jim Laskeycec12a52006-03-14 18:08:46 +0000281<p>In consideration of the complexity and volume of debug information, LLVM
Devang Patele4b27562009-08-28 23:24:31 +0000282 provides a specification for well formed debug descriptors. </p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000283
Jim Laskeycec12a52006-03-14 18:08:46 +0000284<p>Consumers of LLVM debug information expect the descriptors for program
Bill Wendling48839d92009-05-17 05:52:39 +0000285 objects to start in a canonical format, but the descriptors can include
286 additional information appended at the end that is source-language
287 specific. All LLVM debugging information is versioned, allowing backwards
288 compatibility in the case that the core structures need to change in some
289 way. Also, all debugging information objects start with a tag to indicate
290 what type of object it is. The source-language is allowed to define its own
291 objects, by using unreserved tag numbers. We recommend using with tags in
Benjamin Kramer8040cd32009-10-12 14:46:08 +0000292 the range 0x1000 through 0x2000 (there is a defined enum DW_TAG_user_base =
Bill Wendling48839d92009-05-17 05:52:39 +0000293 0x1000.)</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000294
Eric Christopherfc7243a2012-03-06 02:25:36 +0000295<p>The fields of debug descriptors used internally by LLVM
Nick Lewycky655fd032010-03-31 07:50:17 +0000296 are restricted to only the simple data types <tt>i32</tt>, <tt>i1</tt>,
297 <tt>float</tt>, <tt>double</tt>, <tt>mdstring</tt> and <tt>mdnode</tt>. </p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000298
Bill Wendling48839d92009-05-17 05:52:39 +0000299<div class="doc_code">
Misha Brukman82873732004-05-12 19:21:57 +0000300<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000301!1 = metadata !{
Nick Lewycky655fd032010-03-31 07:50:17 +0000302 i32, ;; A tag
Bill Wendling48839d92009-05-17 05:52:39 +0000303 ...
304}
Misha Brukman82873732004-05-12 19:21:57 +0000305</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000306</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000307
Jim Laskey7089f452006-06-16 13:14:03 +0000308<p><a name="LLVMDebugVersion">The first field of a descriptor is always an
Nick Lewycky655fd032010-03-31 07:50:17 +0000309 <tt>i32</tt> containing a tag value identifying the content of the
Bill Wendling48839d92009-05-17 05:52:39 +0000310 descriptor. The remaining fields are specific to the descriptor. The values
311 of tags are loosely bound to the tag values of DWARF information entries.
312 However, that does not restrict the use of the information supplied to DWARF
313 targets. To facilitate versioning of debug information, the tag is augmented
Nick Lewyckyf3379da2011-07-25 21:13:23 +0000314 with the current debug version (LLVMDebugVersion = 8 &lt;&lt; 16 or
315 0x80000 or 524288.)</a></p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000316
Eric Christopherfc7243a2012-03-06 02:25:36 +0000317<p>The details of the various descriptors follow.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000318
Jim Laskeycec12a52006-03-14 18:08:46 +0000319<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000320<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000321 <a name="format_compile_units">Compile unit descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000322</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000323
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000324<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000325
Bill Wendling48839d92009-05-17 05:52:39 +0000326<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000327<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000328!0 = metadata !{
Eric Christopherfc7243a2012-03-06 02:25:36 +0000329 i32, ;; Tag = 17 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patele4b27562009-08-28 23:24:31 +0000330 ;; (DW_TAG_compile_unit)
Eric Christopherfc7243a2012-03-06 02:25:36 +0000331 i32, ;; Unused field.
332 i32, ;; DWARF language identifier (ex. DW_LANG_C89)
Devang Patele4b27562009-08-28 23:24:31 +0000333 metadata, ;; Source file name
334 metadata, ;; Source file directory (includes trailing slash)
335 metadata ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
Eric Christopherfc7243a2012-03-06 02:25:36 +0000336 i1, ;; True if this is a main compile unit.
Devang Patele4b27562009-08-28 23:24:31 +0000337 i1, ;; True if this is optimized.
338 metadata, ;; Flags
339 i32 ;; Runtime version
Devang Patel9b4a2ac2011-09-09 17:07:15 +0000340 metadata ;; List of enums types
341 metadata ;; List of retained types
342 metadata ;; List of subprograms
343 metadata ;; List of global variables
Bill Wendling48839d92009-05-17 05:52:39 +0000344}
Jim Laskeycec12a52006-03-14 18:08:46 +0000345</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000346</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000347
Bill Wendling48839d92009-05-17 05:52:39 +0000348<p>These descriptors contain a source language ID for the file (we use the DWARF
349 3.0 ID numbers, such as <tt>DW_LANG_C89</tt>, <tt>DW_LANG_C_plus_plus</tt>,
350 <tt>DW_LANG_Cobol74</tt>, etc), three strings describing the filename,
351 working directory of the compiler, and an identifier string for the compiler
352 that produced it.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000353
Bill Wendling48839d92009-05-17 05:52:39 +0000354<p>Compile unit descriptors provide the root context for objects declared in a
Devang Patel464f4ef2011-05-03 16:18:28 +0000355 specific compilation unit. File descriptors are defined using this context.
Eric Christopherfc7243a2012-03-06 02:25:36 +0000356 These descriptors are collected by a named metadata
Devang Patel9b4a2ac2011-09-09 17:07:15 +0000357 <tt>!llvm.dbg.cu</tt>. Compile unit descriptor keeps track of subprograms,
358 global variables and type information.
Jim Laskeycec12a52006-03-14 18:08:46 +0000359
Devang Patel4b945502010-03-09 00:44:10 +0000360</div>
361
362<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000363<h4>
Devang Patel4b945502010-03-09 00:44:10 +0000364 <a name="format_files">File descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000365</h4>
Devang Patel4b945502010-03-09 00:44:10 +0000366
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000367<div>
Devang Patel4b945502010-03-09 00:44:10 +0000368
369<div class="doc_code">
370<pre>
371!0 = metadata !{
Eric Christopherfc7243a2012-03-06 02:25:36 +0000372 i32, ;; Tag = 41 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patel4b945502010-03-09 00:44:10 +0000373 ;; (DW_TAG_file_type)
374 metadata, ;; Source file name
375 metadata, ;; Source file directory (includes trailing slash)
Devang Patel94c7ddb2011-08-16 22:09:43 +0000376 metadata ;; Unused
Devang Patel4b945502010-03-09 00:44:10 +0000377}
378</pre>
379</div>
380
John Criswellb34500f2010-03-17 15:01:50 +0000381<p>These descriptors contain information for a file. Global variables and top
Devang Patel4b945502010-03-09 00:44:10 +0000382 level functions would be defined using this context.k File descriptors also
383 provide context for source line correspondence. </p>
384
385<p>Each input file is encoded as a separate file descriptor in LLVM debugging
Devang Patel94c7ddb2011-08-16 22:09:43 +0000386 information output. </p>
Bill Wendling48839d92009-05-17 05:52:39 +0000387
Jim Laskeycec12a52006-03-14 18:08:46 +0000388</div>
389
390<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000391<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000392 <a name="format_global_variables">Global variable descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000393</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000394
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000395<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000396
Bill Wendling48839d92009-05-17 05:52:39 +0000397<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000398<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000399!1 = metadata !{
Eric Christopherfc7243a2012-03-06 02:25:36 +0000400 i32, ;; Tag = 52 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patele4b27562009-08-28 23:24:31 +0000401 ;; (DW_TAG_variable)
402 i32, ;; Unused field.
403 metadata, ;; Reference to context descriptor
404 metadata, ;; Name
405 metadata, ;; Display name (fully qualified C++ name)
406 metadata, ;; MIPS linkage name (for C++)
Devang Patel4b945502010-03-09 00:44:10 +0000407 metadata, ;; Reference to file where defined
Devang Patele4b27562009-08-28 23:24:31 +0000408 i32, ;; Line number where defined
409 metadata, ;; Reference to type descriptor
410 i1, ;; True if the global is local to compile unit (static)
411 i1, ;; True if the global is defined in the compile unit (not extern)
Dan Gohmanfe47aae2010-05-28 17:13:49 +0000412 {}* ;; Reference to the global variable
Bill Wendling48839d92009-05-17 05:52:39 +0000413}
Jim Laskeycec12a52006-03-14 18:08:46 +0000414</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000415</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000416
417<p>These descriptors provide debug information about globals variables. The
Devang Patelda6eed32011-03-29 17:27:08 +0000418provide details such as name, type and where the variable is defined. All
419global variables are collected by named metadata <tt>!llvm.dbg.gv</tt>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000420
421</div>
422
423<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000424<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000425 <a name="format_subprograms">Subprogram descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000426</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000427
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000428<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000429
Bill Wendling48839d92009-05-17 05:52:39 +0000430<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000431<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000432!2 = metadata !{
433 i32, ;; Tag = 46 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
434 ;; (DW_TAG_subprogram)
435 i32, ;; Unused field.
436 metadata, ;; Reference to context descriptor
437 metadata, ;; Name
438 metadata, ;; Display name (fully qualified C++ name)
439 metadata, ;; MIPS linkage name (for C++)
Devang Patel4b945502010-03-09 00:44:10 +0000440 metadata, ;; Reference to file where defined
Devang Patele4b27562009-08-28 23:24:31 +0000441 i32, ;; Line number where defined
442 metadata, ;; Reference to type descriptor
443 i1, ;; True if the global is local to compile unit (static)
Devang Patel5e06bb82011-04-22 23:10:17 +0000444 i1, ;; True if the global is defined in the compile unit (not extern)
445 i32, ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
446 i32, ;; Index into a virtual function
Eric Christopherfc7243a2012-03-06 02:25:36 +0000447 metadata, ;; indicates which base type contains the vtable pointer for the
Devang Patel80ecc152010-06-04 22:49:55 +0000448 ;; derived class
Devang Patel473f95f2011-12-16 17:50:04 +0000449 i32, ;; Flags - Artifical, Private, Protected, Explicit, Prototyped.
Devang Patel5e06bb82011-04-22 23:10:17 +0000450 i1, ;; isOptimized
451 Function *,;; Pointer to LLVM function
452 metadata, ;; Lists function template parameters
453 metadata ;; Function declaration descriptor
Devang Patel93d39be2011-08-19 23:28:12 +0000454 metadata ;; List of function variables
Bill Wendling48839d92009-05-17 05:52:39 +0000455}
Jim Laskeycec12a52006-03-14 18:08:46 +0000456</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000457</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000458
459<p>These descriptors provide debug information about functions, methods and
Bill Wendling48839d92009-05-17 05:52:39 +0000460 subprograms. They provide details such as name, return types and the source
Devang Patelda6eed32011-03-29 17:27:08 +0000461 location where the subprogram is defined.
Devang Patelda6eed32011-03-29 17:27:08 +0000462</p>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000463
464</div>
Bill Wendling48839d92009-05-17 05:52:39 +0000465
Jim Laskey3d11bee2006-03-15 19:10:52 +0000466<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000467<h4>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000468 <a name="format_blocks">Block descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000469</h4>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000470
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000471<div>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000472
Bill Wendling48839d92009-05-17 05:52:39 +0000473<div class="doc_code">
Jim Laskey3d11bee2006-03-15 19:10:52 +0000474<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000475!3 = metadata !{
Devang Patelc79dda22010-10-04 16:51:59 +0000476 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
Devang Patel7f271fc2010-10-01 22:45:00 +0000477 metadata,;; Reference to context descriptor
478 i32, ;; Line number
Devang Patel90d81f12011-03-08 16:25:29 +0000479 i32, ;; Column number
480 metadata,;; Reference to source file
481 i32 ;; Unique ID to identify blocks from a template function
Bill Wendling48839d92009-05-17 05:52:39 +0000482}
Jim Laskey3d11bee2006-03-15 19:10:52 +0000483</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000484</div>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000485
Eric Christopher6618a242011-10-11 22:59:11 +0000486<p>This descriptor provides debug information about nested blocks within a
Devang Patel7f271fc2010-10-01 22:45:00 +0000487 subprogram. The line number and column numbers are used to dinstinguish
488 two lexical blocks at same depth. </p>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000489
Eric Christopher6618a242011-10-11 22:59:11 +0000490<div class="doc_code">
491<pre>
492!3 = metadata !{
493 i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block)
494 metadata ;; Reference to the scope we're annotating with a file change
495 metadata,;; Reference to the file the scope is enclosed in.
496}
497</pre>
498</div>
499
500<p>This descriptor provides a wrapper around a lexical scope to handle file
501 changes in the middle of a lexical block.</p>
502
Jim Laskeycec12a52006-03-14 18:08:46 +0000503</div>
504
505<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000506<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000507 <a name="format_basic_type">Basic type descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000508</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000509
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000510<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000511
Bill Wendling48839d92009-05-17 05:52:39 +0000512<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000513<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000514!4 = metadata !{
Eric Christopherfc7243a2012-03-06 02:25:36 +0000515 i32, ;; Tag = 36 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patele4b27562009-08-28 23:24:31 +0000516 ;; (DW_TAG_base_type)
Eric Christopherfc7243a2012-03-06 02:25:36 +0000517 metadata, ;; Reference to context
Devang Patele4b27562009-08-28 23:24:31 +0000518 metadata, ;; Name (may be "" for anonymous types)
Devang Patel4b945502010-03-09 00:44:10 +0000519 metadata, ;; Reference to file where defined (may be NULL)
Devang Patele4b27562009-08-28 23:24:31 +0000520 i32, ;; Line number where defined (may be 0)
521 i64, ;; Size in bits
522 i64, ;; Alignment in bits
523 i64, ;; Offset in bits
524 i32, ;; Flags
525 i32 ;; DWARF type encoding
Bill Wendling48839d92009-05-17 05:52:39 +0000526}
Jim Laskeycec12a52006-03-14 18:08:46 +0000527</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000528</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000529
530<p>These descriptors define primitive types used in the code. Example int, bool
Bill Wendling48839d92009-05-17 05:52:39 +0000531 and float. The context provides the scope of the type, which is usually the
Devang Patel94c7ddb2011-08-16 22:09:43 +0000532 top level. Since basic types are not usually user defined the context
Bill Wendling48839d92009-05-17 05:52:39 +0000533 and line number can be left as NULL and 0. The size, alignment and offset
534 are expressed in bits and can be 64 bit values. The alignment is used to
535 round the offset when embedded in a
536 <a href="#format_composite_type">composite type</a> (example to keep float
537 doubles on 64 bit boundaries.) The offset is the bit offset if embedded in
538 a <a href="#format_composite_type">composite type</a>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000539
540<p>The type encoding provides the details of the type. The values are typically
Bill Wendling48839d92009-05-17 05:52:39 +0000541 one of the following:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000542
Bill Wendling48839d92009-05-17 05:52:39 +0000543<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000544<pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000545DW_ATE_address = 1
546DW_ATE_boolean = 2
547DW_ATE_float = 4
548DW_ATE_signed = 5
549DW_ATE_signed_char = 6
550DW_ATE_unsigned = 7
551DW_ATE_unsigned_char = 8
Jim Laskeycec12a52006-03-14 18:08:46 +0000552</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000553</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000554
555</div>
556
557<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000558<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000559 <a name="format_derived_type">Derived type descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000560</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000561
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000562<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000563
Bill Wendling48839d92009-05-17 05:52:39 +0000564<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000565<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000566!5 = metadata !{
567 i32, ;; Tag (see below)
568 metadata, ;; Reference to context
569 metadata, ;; Name (may be "" for anonymous types)
Devang Patel4b945502010-03-09 00:44:10 +0000570 metadata, ;; Reference to file where defined (may be NULL)
Devang Patele4b27562009-08-28 23:24:31 +0000571 i32, ;; Line number where defined (may be 0)
Devang Patel0ffd10b2010-10-01 19:19:30 +0000572 i64, ;; Size in bits
573 i64, ;; Alignment in bits
574 i64, ;; Offset in bits
Eric Christopher402e12a2011-12-16 23:42:33 +0000575 i32, ;; Flags to encode attributes, e.g. private
Devang Patele9db5e22011-04-16 00:11:51 +0000576 metadata, ;; Reference to type derived from
Eric Christopherfc7243a2012-03-06 02:25:36 +0000577 metadata, ;; (optional) Name of the Objective C property associated with
578 ;; Objective-C an ivar
Devang Patele9db5e22011-04-16 00:11:51 +0000579 metadata, ;; (optional) Name of the Objective C property getter selector.
580 metadata, ;; (optional) Name of the Objective C property setter selector.
581 i32 ;; (optional) Objective C property attributes.
Bill Wendling48839d92009-05-17 05:52:39 +0000582}
Jim Laskeycec12a52006-03-14 18:08:46 +0000583</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000584</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000585
586<p>These descriptors are used to define types derived from other types. The
587value of the tag varies depending on the meaning. The following are possible
Misha Brukman96e00812008-12-16 02:54:22 +0000588tag values:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000589
Bill Wendling48839d92009-05-17 05:52:39 +0000590<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000591<pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000592DW_TAG_formal_parameter = 5
593DW_TAG_member = 13
594DW_TAG_pointer_type = 15
595DW_TAG_reference_type = 16
596DW_TAG_typedef = 22
597DW_TAG_const_type = 38
598DW_TAG_volatile_type = 53
599DW_TAG_restrict_type = 55
Jim Laskeycec12a52006-03-14 18:08:46 +0000600</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000601</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000602
Bill Wendling48839d92009-05-17 05:52:39 +0000603<p><tt>DW_TAG_member</tt> is used to define a member of
604 a <a href="#format_composite_type">composite type</a>
605 or <a href="#format_subprograms">subprogram</a>. The type of the member is
606 the <a href="#format_derived_type">derived
607 type</a>. <tt>DW_TAG_formal_parameter</tt> is used to define a member which
608 is a formal argument of a subprogram.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000609
Bill Wendling48839d92009-05-17 05:52:39 +0000610<p><tt>DW_TAG_typedef</tt> is used to provide a name for the derived type.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000611
Eric Christopherfc7243a2012-03-06 02:25:36 +0000612<p><tt>DW_TAG_pointer_type</tt>, <tt>DW_TAG_reference_type</tt>,
613 <tt>DW_TAG_const_type</tt>, <tt>DW_TAG_volatile_type</tt> and
Eric Christopheradfc1ef2011-12-16 23:42:35 +0000614 <tt>DW_TAG_restrict_type</tt> are used to qualify
Bill Wendling48839d92009-05-17 05:52:39 +0000615 the <a href="#format_derived_type">derived type</a>. </p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000616
617<p><a href="#format_derived_type">Derived type</a> location can be determined
Devang Patel94c7ddb2011-08-16 22:09:43 +0000618 from the context and line number. The size, alignment and offset are
Bill Wendling48839d92009-05-17 05:52:39 +0000619 expressed in bits and can be 64 bit values. The alignment is used to round
620 the offset when embedded in a <a href="#format_composite_type">composite
621 type</a> (example to keep float doubles on 64 bit boundaries.) The offset is
622 the bit offset if embedded in a <a href="#format_composite_type">composite
623 type</a>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000624
Devang Patel37280782011-02-03 00:22:17 +0000625<p>Note that the <tt>void *</tt> type is expressed as a type derived from NULL.
626</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000627
628</div>
629
630<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000631<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000632 <a name="format_composite_type">Composite type descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000633</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000634
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000635<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000636
Bill Wendling48839d92009-05-17 05:52:39 +0000637<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000638<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000639!6 = metadata !{
640 i32, ;; Tag (see below)
641 metadata, ;; Reference to context
642 metadata, ;; Name (may be "" for anonymous types)
Devang Patel4b945502010-03-09 00:44:10 +0000643 metadata, ;; Reference to file where defined (may be NULL)
Devang Patele4b27562009-08-28 23:24:31 +0000644 i32, ;; Line number where defined (may be 0)
645 i64, ;; Size in bits
646 i64, ;; Alignment in bits
647 i64, ;; Offset in bits
648 i32, ;; Flags
649 metadata, ;; Reference to type derived from
650 metadata, ;; Reference to array of member descriptors
651 i32 ;; Runtime languages
Bill Wendling48839d92009-05-17 05:52:39 +0000652}
Jim Laskeycec12a52006-03-14 18:08:46 +0000653</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000654</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000655
656<p>These descriptors are used to define types that are composed of 0 or more
657elements. The value of the tag varies depending on the meaning. The following
Misha Brukman96e00812008-12-16 02:54:22 +0000658are possible tag values:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000659
Bill Wendling48839d92009-05-17 05:52:39 +0000660<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000661<pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000662DW_TAG_array_type = 1
663DW_TAG_enumeration_type = 4
664DW_TAG_structure_type = 19
665DW_TAG_union_type = 23
666DW_TAG_vector_type = 259
Bruno Cardoso Lopesd80ddc02009-05-29 17:08:57 +0000667DW_TAG_subroutine_type = 21
668DW_TAG_inheritance = 28
Jim Laskeycec12a52006-03-14 18:08:46 +0000669</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000670</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000671
Jim Laskeyf8a01a92006-06-15 20:51:43 +0000672<p>The vector flag indicates that an array type is a native packed vector.</p>
673
Jim Laskey7089f452006-06-16 13:14:03 +0000674<p>The members of array types (tag = <tt>DW_TAG_array_type</tt>) or vector types
Bill Wendling48839d92009-05-17 05:52:39 +0000675 (tag = <tt>DW_TAG_vector_type</tt>) are <a href="#format_subrange">subrange
676 descriptors</a>, each representing the range of subscripts at that level of
677 indexing.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000678
679<p>The members of enumeration types (tag = <tt>DW_TAG_enumeration_type</tt>) are
Bill Wendling48839d92009-05-17 05:52:39 +0000680 <a href="#format_enumeration">enumerator descriptors</a>, each representing
Devang Patelda6eed32011-03-29 17:27:08 +0000681 the definition of enumeration value for the set. All enumeration type
682 descriptors are collected by named metadata <tt>!llvm.dbg.enum</tt>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000683
684<p>The members of structure (tag = <tt>DW_TAG_structure_type</tt>) or union (tag
Bill Wendling48839d92009-05-17 05:52:39 +0000685 = <tt>DW_TAG_union_type</tt>) types are any one of
686 the <a href="#format_basic_type">basic</a>,
687 <a href="#format_derived_type">derived</a>
688 or <a href="#format_composite_type">composite</a> type descriptors, each
689 representing a field member of the structure or union.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000690
Jim Laskey4a9df242006-08-21 21:21:06 +0000691<p>For C++ classes (tag = <tt>DW_TAG_structure_type</tt>), member descriptors
Bill Wendling48839d92009-05-17 05:52:39 +0000692 provide information about base classes, static members and member
693 functions. If a member is a <a href="#format_derived_type">derived type
694 descriptor</a> and has a tag of <tt>DW_TAG_inheritance</tt>, then the type
695 represents a base class. If the member of is
696 a <a href="#format_global_variables">global variable descriptor</a> then it
697 represents a static member. And, if the member is
698 a <a href="#format_subprograms">subprogram descriptor</a> then it represents
699 a member function. For static members and member
700 functions, <tt>getName()</tt> returns the members link or the C++ mangled
701 name. <tt>getDisplayName()</tt> the simplied version of the name.</p>
Jim Laskey4a9df242006-08-21 21:21:06 +0000702
Bill Wendling48839d92009-05-17 05:52:39 +0000703<p>The first member of subroutine (tag = <tt>DW_TAG_subroutine_type</tt>) type
704 elements is the return type for the subroutine. The remaining elements are
705 the formal arguments to the subroutine.</p>
Jim Laskey094ee722006-06-20 21:13:20 +0000706
Jim Laskeycec12a52006-03-14 18:08:46 +0000707<p><a href="#format_composite_type">Composite type</a> location can be
Devang Patel94c7ddb2011-08-16 22:09:43 +0000708 determined from the context and line number. The size, alignment and
Bill Wendling48839d92009-05-17 05:52:39 +0000709 offset are expressed in bits and can be 64 bit values. The alignment is used
710 to round the offset when embedded in
711 a <a href="#format_composite_type">composite type</a> (as an example, to keep
712 float doubles on 64 bit boundaries.) The offset is the bit offset if embedded
713 in a <a href="#format_composite_type">composite type</a>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000714
715</div>
716
717<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000718<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000719 <a name="format_subrange">Subrange descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000720</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000721
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000722<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000723
Bill Wendling48839d92009-05-17 05:52:39 +0000724<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000725<pre>
Devang Patel37280782011-02-03 00:22:17 +0000726!42 = metadata !{
Bill Wendling48839d92009-05-17 05:52:39 +0000727 i32, ;; Tag = 33 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_subrange_type)
728 i64, ;; Low value
729 i64 ;; High value
730}
Jim Laskeycec12a52006-03-14 18:08:46 +0000731</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000732</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000733
734<p>These descriptors are used to define ranges of array subscripts for an array
Bill Wendling48839d92009-05-17 05:52:39 +0000735 <a href="#format_composite_type">composite type</a>. The low value defines
736 the lower bounds typically zero for C/C++. The high value is the upper
737 bounds. Values are 64 bit. High - low + 1 is the size of the array. If low
Devang Patel3f932a72011-04-08 23:39:38 +0000738 > high the array bounds are not included in generated debugging information.
739</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000740
741</div>
742
743<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000744<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000745 <a name="format_enumeration">Enumerator descriptors</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000746</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000747
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000748<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000749
Bill Wendling48839d92009-05-17 05:52:39 +0000750<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +0000751<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000752!6 = metadata !{
Eric Christopherfc7243a2012-03-06 02:25:36 +0000753 i32, ;; Tag = 40 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a>
Devang Patele4b27562009-08-28 23:24:31 +0000754 ;; (DW_TAG_enumerator)
755 metadata, ;; Name
756 i64 ;; Value
Bill Wendling48839d92009-05-17 05:52:39 +0000757}
Jim Laskeycec12a52006-03-14 18:08:46 +0000758</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000759</div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000760
Bill Wendling48839d92009-05-17 05:52:39 +0000761<p>These descriptors are used to define members of an
762 enumeration <a href="#format_composite_type">composite type</a>, it
763 associates the name to the value.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000764
765</div>
766
767<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000768<h4>
Jim Laskey383e0092006-03-23 17:54:33 +0000769 <a name="format_variables">Local variables</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000770</h4>
Jim Laskey383e0092006-03-23 17:54:33 +0000771
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000772<div>
Bill Wendling48839d92009-05-17 05:52:39 +0000773
774<div class="doc_code">
Jim Laskey383e0092006-03-23 17:54:33 +0000775<pre>
Devang Patele4b27562009-08-28 23:24:31 +0000776!7 = metadata !{
777 i32, ;; Tag (see below)
778 metadata, ;; Context
779 metadata, ;; Name
Devang Patel4b945502010-03-09 00:44:10 +0000780 metadata, ;; Reference to file where defined
Devang Patela83688f2011-03-08 16:29:40 +0000781 i32, ;; 24 bit - Line number where defined
782 ;; 8 bit - Argument number. 1 indicates 1st argument.
Devang Patel0a2a3062011-07-27 18:14:50 +0000783 metadata, ;; Type descriptor
784 i32, ;; flags
785 metadata ;; (optional) Reference to inline location
Bill Wendling48839d92009-05-17 05:52:39 +0000786}
Jim Laskey383e0092006-03-23 17:54:33 +0000787</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000788</div>
Jim Laskey383e0092006-03-23 17:54:33 +0000789
790<p>These descriptors are used to define variables local to a sub program. The
Bill Wendling48839d92009-05-17 05:52:39 +0000791 value of the tag depends on the usage of the variable:</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000792
Bill Wendling48839d92009-05-17 05:52:39 +0000793<div class="doc_code">
Jim Laskey383e0092006-03-23 17:54:33 +0000794<pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000795DW_TAG_auto_variable = 256
796DW_TAG_arg_variable = 257
797DW_TAG_return_variable = 258
Jim Laskey383e0092006-03-23 17:54:33 +0000798</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000799</div>
Jim Laskey383e0092006-03-23 17:54:33 +0000800
801<p>An auto variable is any variable declared in the body of the function. An
Bill Wendling48839d92009-05-17 05:52:39 +0000802 argument variable is any variable that appears as a formal argument to the
803 function. A return variable is used to track the result of a function and
804 has no source correspondent.</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000805
Jim Laskey2d395d92006-03-24 09:20:27 +0000806<p>The context is either the subprogram or block where the variable is defined.
Devang Patel94c7ddb2011-08-16 22:09:43 +0000807 Name the source variable name. Context and line indicate where the
Bill Wendling48839d92009-05-17 05:52:39 +0000808 variable was defined. Type descriptor defines the declared type of the
809 variable.</p>
Jim Laskey383e0092006-03-23 17:54:33 +0000810
811</div>
812
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000813</div>
814
Jim Laskey383e0092006-03-23 17:54:33 +0000815<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000816<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +0000817 <a name="format_common_intrinsics">Debugger intrinsic functions</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000818</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +0000819
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000820<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000821
822<p>LLVM uses several intrinsic functions (name prefixed with "llvm.dbg") to
Bill Wendling48839d92009-05-17 05:52:39 +0000823 provide debug information at various points in generated code.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000824
Jim Laskeycec12a52006-03-14 18:08:46 +0000825<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000826<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000827 <a name="format_common_declare">llvm.dbg.declare</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000828</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +0000829
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000830<div>
Jim Laskeycec12a52006-03-14 18:08:46 +0000831<pre>
Devang Patel4c7c0c62010-10-01 19:22:16 +0000832 void %<a href="#format_common_declare">llvm.dbg.declare</a>(metadata, metadata)
Jim Laskeycec12a52006-03-14 18:08:46 +0000833</pre>
834
Chad Rosier5bfd9692012-02-18 01:38:41 +0000835<p>This intrinsic provides information about a local element (e.g., variable). The
836 first argument is metadata holding the alloca for the variable. The
837 second argument is metadata containing a description of the variable.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000838</div>
839
840<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000841<h4>
Victor Hernandez67a1a542010-01-11 22:53:48 +0000842 <a name="format_common_value">llvm.dbg.value</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000843</h4>
Victor Hernandez67a1a542010-01-11 22:53:48 +0000844
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000845<div>
Victor Hernandez67a1a542010-01-11 22:53:48 +0000846<pre>
Dan Gohman3dfb3cf2010-05-28 17:07:41 +0000847 void %<a href="#format_common_value">llvm.dbg.value</a>(metadata, i64, metadata)
Victor Hernandez67a1a542010-01-11 22:53:48 +0000848</pre>
849
850<p>This intrinsic provides information when a user source variable is set to a
851 new value. The first argument is the new value (wrapped as metadata). The
852 second argument is the offset in the user source variable where the new value
Chad Rosier5bfd9692012-02-18 01:38:41 +0000853 is written. The third argument is metadata containing a description of the
854 user source variable.</p>
Victor Hernandez67a1a542010-01-11 22:53:48 +0000855</div>
856
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000857</div>
858
Victor Hernandez67a1a542010-01-11 22:53:48 +0000859<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000860<h3>
Chris Lattner8ff75902004-01-06 05:31:32 +0000861 <a name="format_common_lifetime">Object lifetimes and scoping</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +0000862</h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000863
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +0000864<div>
Bill Wendlingcf493b82009-12-01 00:53:11 +0000865<p>In many languages, the local variables in functions can have their lifetimes
866 or scopes limited to a subset of a function. In the C family of languages,
Bill Wendling48839d92009-05-17 05:52:39 +0000867 for example, variables are only live (readable and writable) within the
868 source block that they are defined in. In functional languages, values are
869 only readable after they have been defined. Though this is a very obvious
Bill Wendlingcf493b82009-12-01 00:53:11 +0000870 concept, it is non-trivial to model in LLVM, because it has no notion of
Bill Wendling48839d92009-05-17 05:52:39 +0000871 scoping in this sense, and does not want to be tied to a language's scoping
872 rules.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000873
Bill Wendlingcf493b82009-12-01 00:53:11 +0000874<p>In order to handle this, the LLVM debug format uses the metadata attached to
Nick Lewycky655fd032010-03-31 07:50:17 +0000875 llvm instructions to encode line number and scoping information. Consider
876 the following C fragment, for example:</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000877
Bill Wendling48839d92009-05-17 05:52:39 +0000878<div class="doc_code">
Misha Brukman82873732004-05-12 19:21:57 +0000879<pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00008801. void foo() {
Devang Patel744950d2009-11-25 23:28:01 +00008812. int X = 21;
8823. int Y = 22;
Chris Lattnerbdfb3392004-01-05 05:06:33 +00008834. {
Devang Patel744950d2009-11-25 23:28:01 +00008845. int Z = 23;
8856. Z = X;
Chris Lattnerbdfb3392004-01-05 05:06:33 +00008867. }
Devang Patel744950d2009-11-25 23:28:01 +00008878. X = Y;
Chris Lattnerbdfb3392004-01-05 05:06:33 +00008889. }
Misha Brukman82873732004-05-12 19:21:57 +0000889</pre>
Bill Wendling48839d92009-05-17 05:52:39 +0000890</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000891
Jim Laskeycec12a52006-03-14 18:08:46 +0000892<p>Compiled to LLVM, this function would be represented like this:</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000893
Bill Wendling48839d92009-05-17 05:52:39 +0000894<div class="doc_code">
Misha Brukman82873732004-05-12 19:21:57 +0000895<pre>
Bill Wendlingcf493b82009-12-01 00:53:11 +0000896define void @foo() nounwind ssp {
Jim Laskeycec12a52006-03-14 18:08:46 +0000897entry:
Bill Wendling02216ff2009-12-01 00:59:58 +0000898 %X = alloca i32, align 4 ; &lt;i32*&gt; [#uses=4]
899 %Y = alloca i32, align 4 ; &lt;i32*&gt; [#uses=4]
900 %Z = alloca i32, align 4 ; &lt;i32*&gt; [#uses=3]
Dan Gohmanfe47aae2010-05-28 17:13:49 +0000901 %0 = bitcast i32* %X to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel37280782011-02-03 00:22:17 +0000902 call void @llvm.dbg.declare(metadata !{i32 * %X}, metadata !0), !dbg !7
Devang Patel744950d2009-11-25 23:28:01 +0000903 store i32 21, i32* %X, !dbg !8
Dan Gohmanfe47aae2010-05-28 17:13:49 +0000904 %1 = bitcast i32* %Y to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel37280782011-02-03 00:22:17 +0000905 call void @llvm.dbg.declare(metadata !{i32 * %Y}, metadata !9), !dbg !10
Devang Patel744950d2009-11-25 23:28:01 +0000906 store i32 22, i32* %Y, !dbg !11
Dan Gohmanfe47aae2010-05-28 17:13:49 +0000907 %2 = bitcast i32* %Z to {}* ; &lt;{}*&gt; [#uses=1]
Devang Patel37280782011-02-03 00:22:17 +0000908 call void @llvm.dbg.declare(metadata !{i32 * %Z}, metadata !12), !dbg !14
Devang Patel744950d2009-11-25 23:28:01 +0000909 store i32 23, i32* %Z, !dbg !15
Bill Wendling02216ff2009-12-01 00:59:58 +0000910 %tmp = load i32* %X, !dbg !16 ; &lt;i32&gt; [#uses=1]
911 %tmp1 = load i32* %Y, !dbg !16 ; &lt;i32&gt; [#uses=1]
912 %add = add nsw i32 %tmp, %tmp1, !dbg !16 ; &lt;i32&gt; [#uses=1]
Devang Patel744950d2009-11-25 23:28:01 +0000913 store i32 %add, i32* %Z, !dbg !16
Bill Wendling02216ff2009-12-01 00:59:58 +0000914 %tmp2 = load i32* %Y, !dbg !17 ; &lt;i32&gt; [#uses=1]
Devang Patel744950d2009-11-25 23:28:01 +0000915 store i32 %tmp2, i32* %X, !dbg !17
916 ret void, !dbg !18
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000917}
Devang Patel744950d2009-11-25 23:28:01 +0000918
Devang Patel37280782011-02-03 00:22:17 +0000919declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
Devang Patel744950d2009-11-25 23:28:01 +0000920
Eric Christopherfc7243a2012-03-06 02:25:36 +0000921!0 = metadata !{i32 459008, metadata !1, metadata !"X",
Devang Patel744950d2009-11-25 23:28:01 +0000922 metadata !3, i32 2, metadata !6}; [ DW_TAG_auto_variable ]
923!1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
Eric Christopherfc7243a2012-03-06 02:25:36 +0000924!2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", metadata !"foo",
925 metadata !"foo", metadata !3, i32 1, metadata !4,
Devang Patel744950d2009-11-25 23:28:01 +0000926 i1 false, i1 true}; [DW_TAG_subprogram ]
Eric Christopherfc7243a2012-03-06 02:25:36 +0000927!3 = metadata !{i32 458769, i32 0, i32 12, metadata !"foo.c",
928 metadata !"/private/tmp", metadata !"clang 1.1", i1 true,
Devang Patel744950d2009-11-25 23:28:01 +0000929 i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
Eric Christopherfc7243a2012-03-06 02:25:36 +0000930!4 = metadata !{i32 458773, metadata !3, metadata !"", null, i32 0, i64 0, i64 0,
Devang Patel744950d2009-11-25 23:28:01 +0000931 i64 0, i32 0, null, metadata !5, i32 0}; [DW_TAG_subroutine_type ]
932!5 = metadata !{null}
Eric Christopherfc7243a2012-03-06 02:25:36 +0000933!6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0,
Devang Patel744950d2009-11-25 23:28:01 +0000934 i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ]
935!7 = metadata !{i32 2, i32 7, metadata !1, null}
936!8 = metadata !{i32 2, i32 3, metadata !1, null}
Eric Christopherfc7243a2012-03-06 02:25:36 +0000937!9 = metadata !{i32 459008, metadata !1, metadata !"Y", metadata !3, i32 3,
Devang Patel744950d2009-11-25 23:28:01 +0000938 metadata !6}; [ DW_TAG_auto_variable ]
939!10 = metadata !{i32 3, i32 7, metadata !1, null}
940!11 = metadata !{i32 3, i32 3, metadata !1, null}
Eric Christopherfc7243a2012-03-06 02:25:36 +0000941!12 = metadata !{i32 459008, metadata !13, metadata !"Z", metadata !3, i32 5,
Devang Patel744950d2009-11-25 23:28:01 +0000942 metadata !6}; [ DW_TAG_auto_variable ]
943!13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
944!14 = metadata !{i32 5, i32 9, metadata !13, null}
945!15 = metadata !{i32 5, i32 5, metadata !13, null}
946!16 = metadata !{i32 6, i32 5, metadata !13, null}
947!17 = metadata !{i32 8, i32 3, metadata !1, null}
948!18 = metadata !{i32 9, i32 1, metadata !2, null}
Misha Brukman82873732004-05-12 19:21:57 +0000949</pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000950</div>
951
Bill Wendlingcf493b82009-12-01 00:53:11 +0000952<p>This example illustrates a few important details about LLVM debugging
953 information. In particular, it shows how the <tt>llvm.dbg.declare</tt>
954 intrinsic and location information, which are attached to an instruction,
955 are applied together to allow a debugger to analyze the relationship between
956 statements, variable definitions, and the code used to implement the
957 function.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000958
Bill Wendlingcf493b82009-12-01 00:53:11 +0000959<div class="doc_code">
Bill Wendling02216ff2009-12-01 00:59:58 +0000960<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +0000961call void @llvm.dbg.declare(metadata, metadata !0), !dbg !7
Bill Wendlingcf493b82009-12-01 00:53:11 +0000962</pre>
963</div>
964
965<p>The first intrinsic
Devang Patel744950d2009-11-25 23:28:01 +0000966 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
Bill Wendlingcf493b82009-12-01 00:53:11 +0000967 encodes debugging information for the variable <tt>X</tt>. The metadata
968 <tt>!dbg !7</tt> attached to the intrinsic provides scope information for the
969 variable <tt>X</tt>.</p>
Bill Wendling48839d92009-05-17 05:52:39 +0000970
Bill Wendlingcf493b82009-12-01 00:53:11 +0000971<div class="doc_code">
972<pre>
973!7 = metadata !{i32 2, i32 7, metadata !1, null}
974!1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
Eric Christopherfc7243a2012-03-06 02:25:36 +0000975!2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo",
976 metadata !"foo", metadata !"foo", metadata !3, i32 1,
977 metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
Bill Wendlingcf493b82009-12-01 00:53:11 +0000978</pre>
979</div>
980
981<p>Here <tt>!7</tt> is metadata providing location information. It has four
982 fields: line number, column number, scope, and original scope. The original
983 scope represents inline location if this instruction is inlined inside a
984 caller, and is null otherwise. In this example, scope is encoded by
Devang Patel744950d2009-11-25 23:28:01 +0000985 <tt>!1</tt>. <tt>!1</tt> represents a lexical block inside the scope
986 <tt>!2</tt>, where <tt>!2</tt> is a
Bill Wendlingcf493b82009-12-01 00:53:11 +0000987 <a href="#format_subprograms">subprogram descriptor</a>. This way the
988 location information attached to the intrinsics indicates that the
989 variable <tt>X</tt> is declared at line number 2 at a function level scope in
990 function <tt>foo</tt>.</p>
Bill Wendling48839d92009-05-17 05:52:39 +0000991
Devang Patel744950d2009-11-25 23:28:01 +0000992<p>Now lets take another example.</p>
Bill Wendling48839d92009-05-17 05:52:39 +0000993
Bill Wendlingcf493b82009-12-01 00:53:11 +0000994<div class="doc_code">
Bill Wendling02216ff2009-12-01 00:59:58 +0000995<pre>
Devang Patel37280782011-02-03 00:22:17 +0000996call void @llvm.dbg.declare(metadata, metadata !12), !dbg !14
Bill Wendlingcf493b82009-12-01 00:53:11 +0000997</pre>
998</div>
999
1000<p>The second intrinsic
Devang Patel744950d2009-11-25 23:28:01 +00001001 <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001002 encodes debugging information for variable <tt>Z</tt>. The metadata
Bill Wendlingcf493b82009-12-01 00:53:11 +00001003 <tt>!dbg !14</tt> attached to the intrinsic provides scope information for
1004 the variable <tt>Z</tt>.</p>
Bill Wendling48839d92009-05-17 05:52:39 +00001005
Bill Wendlingcf493b82009-12-01 00:53:11 +00001006<div class="doc_code">
1007<pre>
1008!13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
1009!14 = metadata !{i32 5, i32 9, metadata !13, null}
1010</pre>
1011</div>
Bill Wendling48839d92009-05-17 05:52:39 +00001012
John Criswellb34500f2010-03-17 15:01:50 +00001013<p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declared at line number 5 and
Bill Wendlingcf493b82009-12-01 00:53:11 +00001014 column number 9 inside of lexical scope <tt>!13</tt>. The lexical scope
1015 itself resides inside of lexical scope <tt>!1</tt> described above.</p>
1016
1017<p>The scope information attached with each instruction provides a
1018 straightforward way to find instructions covered by a scope.</p>
1019
Bill Wendling48839d92009-05-17 05:52:39 +00001020</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001021
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001022</div>
1023
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001024<!-- *********************************************************************** -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001025<h2>
Chris Lattner8ff75902004-01-06 05:31:32 +00001026 <a name="ccxx_frontend">C/C++ front-end specific debug information</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001027</h2>
Misha Brukman94218a72004-12-09 20:27:37 +00001028<!-- *********************************************************************** -->
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001029
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001030<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001031
Misha Brukman82873732004-05-12 19:21:57 +00001032<p>The C and C++ front-ends represent information about the program in a format
Bill Wendling48839d92009-05-17 05:52:39 +00001033 that is effectively identical
1034 to <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3.0</a> in
1035 terms of information content. This allows code generators to trivially
1036 support native debuggers by generating standard dwarf information, and
1037 contains enough information for non-dwarf targets to translate it as
1038 needed.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001039
Jim Laskeycec12a52006-03-14 18:08:46 +00001040<p>This section describes the forms used to represent C and C++ programs. Other
Bill Wendling48839d92009-05-17 05:52:39 +00001041 languages could pattern themselves after this (which itself is tuned to
1042 representing programs in the same way that DWARF 3 does), or they could
1043 choose to provide completely different forms if they don't fit into the DWARF
1044 model. As support for debugging information gets added to the various LLVM
1045 source-language front-ends, the information used should be documented
1046 here.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001047
Jim Laskeycec12a52006-03-14 18:08:46 +00001048<p>The following sections provide examples of various C/C++ constructs and the
Bill Wendling48839d92009-05-17 05:52:39 +00001049 debug information that would best describe those constructs.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001050
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001051<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001052<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001053 <a name="ccxx_compile_units">C/C++ source file information</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001054</h3>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001055
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001056<div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001057
Bill Wendling48839d92009-05-17 05:52:39 +00001058<p>Given the source files <tt>MySource.cpp</tt> and <tt>MyHeader.h</tt> located
1059 in the directory <tt>/Users/mine/sources</tt>, the following code:</p>
Chris Lattner8ff75902004-01-06 05:31:32 +00001060
Bill Wendling48839d92009-05-17 05:52:39 +00001061<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001062<pre>
1063#include "MyHeader.h"
Chris Lattner8ff75902004-01-06 05:31:32 +00001064
Jim Laskeycec12a52006-03-14 18:08:46 +00001065int main(int argc, char *argv[]) {
1066 return 0;
1067}
1068</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001069</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00001070
Misha Brukman96e00812008-12-16 02:54:22 +00001071<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001072
Bill Wendling48839d92009-05-17 05:52:39 +00001073<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001074<pre>
1075...
1076;;
Devang Patel4b945502010-03-09 00:44:10 +00001077;; Define the compile unit for the main source file "/Users/mine/sources/MySource.cpp".
Jim Laskeycec12a52006-03-14 18:08:46 +00001078;;
Devang Patel4b945502010-03-09 00:44:10 +00001079!2 = metadata !{
1080 i32 524305, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001081 i32 0, ;; Unused
1082 i32 4, ;; Language Id
Eric Christopherfc7243a2012-03-06 02:25:36 +00001083 metadata !"MySource.cpp",
1084 metadata !"/Users/mine/sources",
1085 metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)",
Devang Patele4b27562009-08-28 23:24:31 +00001086 i1 true, ;; Main Compile Unit
1087 i1 false, ;; Optimized compile unit
1088 metadata !"", ;; Compiler flags
1089 i32 0} ;; Runtime version
1090
Jim Laskeycec12a52006-03-14 18:08:46 +00001091;;
Devang Patel4b945502010-03-09 00:44:10 +00001092;; Define the file for the file "/Users/mine/sources/MySource.cpp".
Jim Laskeycec12a52006-03-14 18:08:46 +00001093;;
Devang Patele4b27562009-08-28 23:24:31 +00001094!1 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001095 i32 524329, ;; Tag
Eric Christopherfc7243a2012-03-06 02:25:36 +00001096 metadata !"MySource.cpp",
1097 metadata !"/Users/mine/sources",
Devang Patel9fea9c22010-07-13 16:53:20 +00001098 metadata !2 ;; Compile unit
Devang Patel4b945502010-03-09 00:44:10 +00001099}
1100
1101;;
1102;; Define the file for the file "/Users/mine/sources/Myheader.h"
1103;;
1104!3 = metadata !{
1105 i32 524329, ;; Tag
1106 metadata !"Myheader.h"
Eric Christopherfc7243a2012-03-06 02:25:36 +00001107 metadata !"/Users/mine/sources",
Devang Patel9fea9c22010-07-13 16:53:20 +00001108 metadata !2 ;; Compile unit
Devang Patel4b945502010-03-09 00:44:10 +00001109}
Jim Laskeycec12a52006-03-14 18:08:46 +00001110
Jim Laskeycec12a52006-03-14 18:08:46 +00001111...
1112</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001113</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001114
Eric Christopherfc7243a2012-03-06 02:25:36 +00001115<p>llvm::Instruction provides easy access to metadata attached with an
Devang Pateld98ec5f2010-03-26 19:08:36 +00001116instruction. One can extract line number information encoded in LLVM IR
Eric Christopherfc7243a2012-03-06 02:25:36 +00001117using <tt>Instruction::getMetadata()</tt> and
Devang Pateld98ec5f2010-03-26 19:08:36 +00001118<tt>DILocation::getLineNumber()</tt>.
1119<pre>
1120 if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction
1121 DILocation Loc(N); // DILocation is in DebugInfo.h
1122 unsigned Line = Loc.getLineNumber();
1123 StringRef File = Loc.getFilename();
1124 StringRef Dir = Loc.getDirectory();
1125 }
1126</pre>
Chris Lattner8ff75902004-01-06 05:31:32 +00001127</div>
1128
1129<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001130<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001131 <a name="ccxx_global_variable">C/C++ global variable information</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001132</h3>
Chris Lattner8ff75902004-01-06 05:31:32 +00001133
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001134<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001135
Misha Brukman96e00812008-12-16 02:54:22 +00001136<p>Given an integer global variable declared as follows:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001137
Bill Wendling48839d92009-05-17 05:52:39 +00001138<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001139<pre>
1140int MyGlobal = 100;
1141</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001142</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001143
Misha Brukman96e00812008-12-16 02:54:22 +00001144<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001145
Bill Wendling48839d92009-05-17 05:52:39 +00001146<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001147<pre>
1148;;
Jim Laskeycec12a52006-03-14 18:08:46 +00001149;; Define the global itself.
1150;;
1151%MyGlobal = global int 100
1152...
1153;;
Devang Patele4b27562009-08-28 23:24:31 +00001154;; List of debug info of globals
Jim Laskeycec12a52006-03-14 18:08:46 +00001155;;
Devang Patele4b27562009-08-28 23:24:31 +00001156!llvm.dbg.gv = !{!0}
Jim Laskeycec12a52006-03-14 18:08:46 +00001157
1158;;
1159;; Define the global variable descriptor. Note the reference to the global
1160;; variable anchor and the global variable itself.
1161;;
Devang Patele4b27562009-08-28 23:24:31 +00001162!0 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001163 i32 524340, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001164 i32 0, ;; Unused
1165 metadata !1, ;; Context
1166 metadata !"MyGlobal", ;; Name
1167 metadata !"MyGlobal", ;; Display Name
1168 metadata !"MyGlobal", ;; Linkage Name
Devang Patel4b945502010-03-09 00:44:10 +00001169 metadata !3, ;; Compile Unit
Devang Patele4b27562009-08-28 23:24:31 +00001170 i32 1, ;; Line Number
Devang Patel4b945502010-03-09 00:44:10 +00001171 metadata !4, ;; Type
Devang Patele4b27562009-08-28 23:24:31 +00001172 i1 false, ;; Is a local variable
1173 i1 true, ;; Is this a definition
1174 i32* @MyGlobal ;; The global variable
1175}
1176
Jim Laskeycec12a52006-03-14 18:08:46 +00001177;;
1178;; Define the basic type of 32 bit signed integer. Note that since int is an
1179;; intrinsic type the source file is NULL and line 0.
Eric Christopherfc7243a2012-03-06 02:25:36 +00001180;;
Devang Patel4b945502010-03-09 00:44:10 +00001181!4 = metadata !{
1182 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001183 metadata !1, ;; Context
1184 metadata !"int", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001185 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001186 i32 0, ;; Line number
1187 i64 32, ;; Size in Bits
1188 i64 32, ;; Align in Bits
1189 i64 0, ;; Offset in Bits
1190 i32 0, ;; Flags
1191 i32 5 ;; Encoding
1192}
Jim Laskeycec12a52006-03-14 18:08:46 +00001193
Jim Laskeycec12a52006-03-14 18:08:46 +00001194</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001195</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001196
Chris Lattner8ff75902004-01-06 05:31:32 +00001197</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001198
Jim Laskeycec12a52006-03-14 18:08:46 +00001199<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001200<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001201 <a name="ccxx_subprogram">C/C++ function information</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001202</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001203
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001204<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001205
Misha Brukman96e00812008-12-16 02:54:22 +00001206<p>Given a function declared as follows:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001207
Bill Wendling48839d92009-05-17 05:52:39 +00001208<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001209<pre>
1210int main(int argc, char *argv[]) {
1211 return 0;
1212}
1213</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001214</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001215
Misha Brukman96e00812008-12-16 02:54:22 +00001216<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001217
Bill Wendling48839d92009-05-17 05:52:39 +00001218<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001219<pre>
1220;;
Jim Laskeycec12a52006-03-14 18:08:46 +00001221;; Define the anchor for subprograms. Note that the second field of the
1222;; anchor is 46, which is the same as the tag for subprograms
1223;; (46 = DW_TAG_subprogram.)
1224;;
Devang Patel4b945502010-03-09 00:44:10 +00001225!6 = metadata !{
1226 i32 524334, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001227 i32 0, ;; Unused
1228 metadata !1, ;; Context
1229 metadata !"main", ;; Name
1230 metadata !"main", ;; Display name
1231 metadata !"main", ;; Linkage name
Devang Patel4b945502010-03-09 00:44:10 +00001232 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001233 i32 1, ;; Line number
Devang Patel4b945502010-03-09 00:44:10 +00001234 metadata !4, ;; Type
Eric Christopherfc7243a2012-03-06 02:25:36 +00001235 i1 false, ;; Is local
Devang Patelda194752011-04-05 22:52:06 +00001236 i1 true, ;; Is definition
1237 i32 0, ;; Virtuality attribute, e.g. pure virtual function
1238 i32 0, ;; Index into virtual table for C++ methods
1239 i32 0, ;; Type that holds virtual table.
1240 i32 0, ;; Flags
1241 i1 false, ;; True if this function is optimized
1242 Function *, ;; Pointer to llvm::Function
1243 null ;; Function template parameters
Devang Patele4b27562009-08-28 23:24:31 +00001244}
Jim Laskeycec12a52006-03-14 18:08:46 +00001245;;
1246;; Define the subprogram itself.
1247;;
Devang Patele4b27562009-08-28 23:24:31 +00001248define i32 @main(i32 %argc, i8** %argv) {
Jim Laskeycec12a52006-03-14 18:08:46 +00001249...
1250}
1251</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001252</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001253
1254</div>
1255
1256<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001257<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001258 <a name="ccxx_basic_types">C/C++ basic types</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001259</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001260
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001261<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001262
Misha Brukman96e00812008-12-16 02:54:22 +00001263<p>The following are the basic type descriptors for C/C++ core types:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001264
Jim Laskeycec12a52006-03-14 18:08:46 +00001265<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001266<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001267 <a name="ccxx_basic_type_bool">bool</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001268</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001269
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001270<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001271
Bill Wendling48839d92009-05-17 05:52:39 +00001272<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001273<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001274!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001275 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001276 metadata !1, ;; Context
1277 metadata !"bool", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001278 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001279 i32 0, ;; Line number
1280 i64 8, ;; Size in Bits
1281 i64 8, ;; Align in Bits
1282 i64 0, ;; Offset in Bits
1283 i32 0, ;; Flags
1284 i32 2 ;; Encoding
1285}
Jim Laskeycec12a52006-03-14 18:08:46 +00001286</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001287</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001288
1289</div>
1290
1291<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001292<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001293 <a name="ccxx_basic_char">char</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001294</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001295
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001296<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001297
Bill Wendling48839d92009-05-17 05:52:39 +00001298<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001299<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001300!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001301 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001302 metadata !1, ;; Context
1303 metadata !"char", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001304 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001305 i32 0, ;; Line number
1306 i64 8, ;; Size in Bits
1307 i64 8, ;; Align in Bits
1308 i64 0, ;; Offset in Bits
1309 i32 0, ;; Flags
1310 i32 6 ;; Encoding
1311}
Jim Laskeycec12a52006-03-14 18:08:46 +00001312</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001313</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001314
1315</div>
1316
1317<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001318<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001319 <a name="ccxx_basic_unsigned_char">unsigned char</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001320</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001321
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001322<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001323
Bill Wendling48839d92009-05-17 05:52:39 +00001324<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001325<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001326!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001327 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001328 metadata !1, ;; Context
Eric Christopherfc7243a2012-03-06 02:25:36 +00001329 metadata !"unsigned char",
Devang Patel4b945502010-03-09 00:44:10 +00001330 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001331 i32 0, ;; Line number
1332 i64 8, ;; Size in Bits
1333 i64 8, ;; Align in Bits
1334 i64 0, ;; Offset in Bits
1335 i32 0, ;; Flags
1336 i32 8 ;; Encoding
1337}
Jim Laskeycec12a52006-03-14 18:08:46 +00001338</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001339</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001340
1341</div>
1342
1343<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001344<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001345 <a name="ccxx_basic_short">short</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001346</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001347
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001348<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001349
Bill Wendling48839d92009-05-17 05:52:39 +00001350<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001351<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001352!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001353 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001354 metadata !1, ;; Context
1355 metadata !"short int",
Devang Patel4b945502010-03-09 00:44:10 +00001356 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001357 i32 0, ;; Line number
1358 i64 16, ;; Size in Bits
1359 i64 16, ;; Align in Bits
1360 i64 0, ;; Offset in Bits
1361 i32 0, ;; Flags
1362 i32 5 ;; Encoding
1363}
Jim Laskeycec12a52006-03-14 18:08:46 +00001364</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001365</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001366
1367</div>
1368
1369<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001370<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001371 <a name="ccxx_basic_unsigned_short">unsigned short</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001372</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001373
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001374<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001375
Bill Wendling48839d92009-05-17 05:52:39 +00001376<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001377<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001378!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001379 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001380 metadata !1, ;; Context
1381 metadata !"short unsigned int",
Devang Patel4b945502010-03-09 00:44:10 +00001382 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001383 i32 0, ;; Line number
1384 i64 16, ;; Size in Bits
1385 i64 16, ;; Align in Bits
1386 i64 0, ;; Offset in Bits
1387 i32 0, ;; Flags
1388 i32 7 ;; Encoding
1389}
Jim Laskeycec12a52006-03-14 18:08:46 +00001390</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001391</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001392
1393</div>
1394
1395<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001396<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001397 <a name="ccxx_basic_int">int</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001398</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001399
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001400<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001401
Bill Wendling48839d92009-05-17 05:52:39 +00001402<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001403<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001404!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001405 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001406 metadata !1, ;; Context
1407 metadata !"int", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001408 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001409 i32 0, ;; Line number
1410 i64 32, ;; Size in Bits
1411 i64 32, ;; Align in Bits
1412 i64 0, ;; Offset in Bits
1413 i32 0, ;; Flags
1414 i32 5 ;; Encoding
1415}
Bill Wendling48839d92009-05-17 05:52:39 +00001416</pre></div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001417
1418</div>
1419
1420<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001421<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001422 <a name="ccxx_basic_unsigned_int">unsigned int</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001423</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001424
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001425<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001426
Bill Wendling48839d92009-05-17 05:52:39 +00001427<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001428<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001429!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001430 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001431 metadata !1, ;; Context
1432 metadata !"unsigned int",
Devang Patel4b945502010-03-09 00:44:10 +00001433 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001434 i32 0, ;; Line number
1435 i64 32, ;; Size in Bits
1436 i64 32, ;; Align in Bits
1437 i64 0, ;; Offset in Bits
1438 i32 0, ;; Flags
1439 i32 7 ;; Encoding
1440}
Jim Laskeycec12a52006-03-14 18:08:46 +00001441</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001442</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001443
1444</div>
1445
1446<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001447<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001448 <a name="ccxx_basic_long_long">long long</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001449</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001450
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001451<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001452
Bill Wendling48839d92009-05-17 05:52:39 +00001453<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001454<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001455!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001456 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001457 metadata !1, ;; Context
1458 metadata !"long long int",
Devang Patel4b945502010-03-09 00:44:10 +00001459 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001460 i32 0, ;; Line number
1461 i64 64, ;; Size in Bits
1462 i64 64, ;; Align in Bits
1463 i64 0, ;; Offset in Bits
1464 i32 0, ;; Flags
1465 i32 5 ;; Encoding
1466}
Jim Laskeycec12a52006-03-14 18:08:46 +00001467</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001468</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001469
1470</div>
1471
1472<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001473<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001474 <a name="ccxx_basic_unsigned_long_long">unsigned long long</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001475</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001476
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001477<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001478
Bill Wendling48839d92009-05-17 05:52:39 +00001479<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001480<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001481!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001482 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001483 metadata !1, ;; Context
1484 metadata !"long long unsigned int",
Devang Patel4b945502010-03-09 00:44:10 +00001485 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001486 i32 0, ;; Line number
1487 i64 64, ;; Size in Bits
1488 i64 64, ;; Align in Bits
1489 i64 0, ;; Offset in Bits
1490 i32 0, ;; Flags
1491 i32 7 ;; Encoding
1492}
Jim Laskeycec12a52006-03-14 18:08:46 +00001493</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001494</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001495
1496</div>
1497
1498<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001499<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001500 <a name="ccxx_basic_float">float</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001501</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001502
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001503<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001504
Bill Wendling48839d92009-05-17 05:52:39 +00001505<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001506<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001507!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001508 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001509 metadata !1, ;; Context
1510 metadata !"float",
Devang Patel4b945502010-03-09 00:44:10 +00001511 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001512 i32 0, ;; Line number
1513 i64 32, ;; Size in Bits
1514 i64 32, ;; Align in Bits
1515 i64 0, ;; Offset in Bits
1516 i32 0, ;; Flags
1517 i32 4 ;; Encoding
1518}
Jim Laskeycec12a52006-03-14 18:08:46 +00001519</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001520</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001521
1522</div>
1523
1524<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001525<h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001526 <a name="ccxx_basic_double">double</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001527</h4>
Jim Laskeycec12a52006-03-14 18:08:46 +00001528
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001529<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001530
Bill Wendling48839d92009-05-17 05:52:39 +00001531<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001532<pre>
Devang Patele4b27562009-08-28 23:24:31 +00001533!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001534 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001535 metadata !1, ;; Context
1536 metadata !"double",;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001537 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001538 i32 0, ;; Line number
1539 i64 64, ;; Size in Bits
1540 i64 64, ;; Align in Bits
1541 i64 0, ;; Offset in Bits
1542 i32 0, ;; Flags
1543 i32 4 ;; Encoding
1544}
Jim Laskeycec12a52006-03-14 18:08:46 +00001545</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001546</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001547
1548</div>
1549
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001550</div>
1551
Jim Laskeycec12a52006-03-14 18:08:46 +00001552<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001553<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001554 <a name="ccxx_derived_types">C/C++ derived types</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001555</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001556
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001557<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001558
Misha Brukman96e00812008-12-16 02:54:22 +00001559<p>Given the following as an example of C/C++ derived type:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001560
Bill Wendling48839d92009-05-17 05:52:39 +00001561<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001562<pre>
1563typedef const int *IntPtr;
1564</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001565</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001566
Misha Brukman96e00812008-12-16 02:54:22 +00001567<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001568
Bill Wendling48839d92009-05-17 05:52:39 +00001569<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001570<pre>
1571;;
1572;; Define the typedef "IntPtr".
1573;;
Devang Patele4b27562009-08-28 23:24:31 +00001574!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001575 i32 524310, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001576 metadata !1, ;; Context
1577 metadata !"IntPtr", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001578 metadata !3, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001579 i32 0, ;; Line number
1580 i64 0, ;; Size in bits
1581 i64 0, ;; Align in bits
1582 i64 0, ;; Offset in bits
1583 i32 0, ;; Flags
1584 metadata !4 ;; Derived From type
1585}
Jim Laskeycec12a52006-03-14 18:08:46 +00001586
1587;;
1588;; Define the pointer type.
1589;;
Devang Patele4b27562009-08-28 23:24:31 +00001590!4 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001591 i32 524303, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001592 metadata !1, ;; Context
1593 metadata !"", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001594 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001595 i32 0, ;; Line number
1596 i64 64, ;; Size in bits
1597 i64 64, ;; Align in bits
1598 i64 0, ;; Offset in bits
1599 i32 0, ;; Flags
1600 metadata !5 ;; Derived From type
1601}
Jim Laskeycec12a52006-03-14 18:08:46 +00001602;;
1603;; Define the const type.
1604;;
Devang Patele4b27562009-08-28 23:24:31 +00001605!5 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001606 i32 524326, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001607 metadata !1, ;; Context
1608 metadata !"", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001609 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001610 i32 0, ;; Line number
1611 i64 32, ;; Size in bits
1612 i64 32, ;; Align in bits
1613 i64 0, ;; Offset in bits
1614 i32 0, ;; Flags
1615 metadata !6 ;; Derived From type
1616}
Jim Laskeycec12a52006-03-14 18:08:46 +00001617;;
1618;; Define the int type.
1619;;
Devang Patele4b27562009-08-28 23:24:31 +00001620!6 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001621 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001622 metadata !1, ;; Context
1623 metadata !"int", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001624 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001625 i32 0, ;; Line number
1626 i64 32, ;; Size in bits
1627 i64 32, ;; Align in bits
1628 i64 0, ;; Offset in bits
1629 i32 0, ;; Flags
1630 5 ;; Encoding
1631}
Jim Laskeycec12a52006-03-14 18:08:46 +00001632</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001633</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001634
1635</div>
1636
1637<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001638<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001639 <a name="ccxx_composite_types">C/C++ struct/union types</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001640</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001641
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001642<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001643
Misha Brukman96e00812008-12-16 02:54:22 +00001644<p>Given the following as an example of C/C++ struct type:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001645
Bill Wendling48839d92009-05-17 05:52:39 +00001646<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001647<pre>
1648struct Color {
1649 unsigned Red;
1650 unsigned Green;
1651 unsigned Blue;
1652};
1653</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001654</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001655
Misha Brukman96e00812008-12-16 02:54:22 +00001656<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001657
Bill Wendling48839d92009-05-17 05:52:39 +00001658<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001659<pre>
1660;;
1661;; Define basic type for unsigned int.
1662;;
Devang Patele4b27562009-08-28 23:24:31 +00001663!5 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001664 i32 524324, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001665 metadata !1, ;; Context
1666 metadata !"unsigned int",
Devang Patel4b945502010-03-09 00:44:10 +00001667 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001668 i32 0, ;; Line number
1669 i64 32, ;; Size in Bits
1670 i64 32, ;; Align in Bits
1671 i64 0, ;; Offset in Bits
1672 i32 0, ;; Flags
1673 i32 7 ;; Encoding
1674}
Jim Laskeycec12a52006-03-14 18:08:46 +00001675;;
1676;; Define composite type for struct Color.
1677;;
Devang Patele4b27562009-08-28 23:24:31 +00001678!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001679 i32 524307, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001680 metadata !1, ;; Context
1681 metadata !"Color", ;; Name
1682 metadata !1, ;; Compile unit
1683 i32 1, ;; Line number
1684 i64 96, ;; Size in bits
1685 i64 32, ;; Align in bits
1686 i64 0, ;; Offset in bits
1687 i32 0, ;; Flags
1688 null, ;; Derived From
1689 metadata !3, ;; Elements
1690 i32 0 ;; Runtime Language
1691}
Jim Laskeycec12a52006-03-14 18:08:46 +00001692
1693;;
1694;; Define the Red field.
1695;;
Devang Patele4b27562009-08-28 23:24:31 +00001696!4 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001697 i32 524301, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001698 metadata !1, ;; Context
1699 metadata !"Red", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001700 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001701 i32 2, ;; Line number
1702 i64 32, ;; Size in bits
1703 i64 32, ;; Align in bits
1704 i64 0, ;; Offset in bits
1705 i32 0, ;; Flags
1706 metadata !5 ;; Derived From type
1707}
Jim Laskeycec12a52006-03-14 18:08:46 +00001708
1709;;
1710;; Define the Green field.
1711;;
Devang Patele4b27562009-08-28 23:24:31 +00001712!6 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001713 i32 524301, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001714 metadata !1, ;; Context
1715 metadata !"Green", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001716 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001717 i32 3, ;; Line number
1718 i64 32, ;; Size in bits
1719 i64 32, ;; Align in bits
1720 i64 32, ;; Offset in bits
1721 i32 0, ;; Flags
1722 metadata !5 ;; Derived From type
1723}
Jim Laskeycec12a52006-03-14 18:08:46 +00001724
1725;;
1726;; Define the Blue field.
1727;;
Devang Patele4b27562009-08-28 23:24:31 +00001728!7 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001729 i32 524301, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001730 metadata !1, ;; Context
1731 metadata !"Blue", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001732 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001733 i32 4, ;; Line number
1734 i64 32, ;; Size in bits
1735 i64 32, ;; Align in bits
1736 i64 64, ;; Offset in bits
1737 i32 0, ;; Flags
1738 metadata !5 ;; Derived From type
1739}
Jim Laskeycec12a52006-03-14 18:08:46 +00001740
1741;;
1742;; Define the array of fields used by the composite type Color.
1743;;
Devang Patele4b27562009-08-28 23:24:31 +00001744!3 = metadata !{metadata !4, metadata !6, metadata !7}
Jim Laskeycec12a52006-03-14 18:08:46 +00001745</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001746</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001747
1748</div>
1749
1750<!-- ======================================================================= -->
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001751<h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001752 <a name="ccxx_enumeration_types">C/C++ enumeration types</a>
NAKAMURA Takumi05d02652011-04-18 23:59:50 +00001753</h3>
Jim Laskeycec12a52006-03-14 18:08:46 +00001754
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001755<div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001756
Misha Brukman96e00812008-12-16 02:54:22 +00001757<p>Given the following as an example of C/C++ enumeration type:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001758
Bill Wendling48839d92009-05-17 05:52:39 +00001759<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001760<pre>
1761enum Trees {
1762 Spruce = 100,
1763 Oak = 200,
1764 Maple = 300
1765};
1766</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001767</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001768
Misha Brukman96e00812008-12-16 02:54:22 +00001769<p>a C/C++ front-end would generate the following descriptors:</p>
Jim Laskeycec12a52006-03-14 18:08:46 +00001770
Bill Wendling48839d92009-05-17 05:52:39 +00001771<div class="doc_code">
Jim Laskeycec12a52006-03-14 18:08:46 +00001772<pre>
1773;;
1774;; Define composite type for enum Trees
1775;;
Devang Patele4b27562009-08-28 23:24:31 +00001776!2 = metadata !{
Devang Patel4b945502010-03-09 00:44:10 +00001777 i32 524292, ;; Tag
Devang Patele4b27562009-08-28 23:24:31 +00001778 metadata !1, ;; Context
1779 metadata !"Trees", ;; Name
Devang Patel4b945502010-03-09 00:44:10 +00001780 metadata !1, ;; File
Devang Patele4b27562009-08-28 23:24:31 +00001781 i32 1, ;; Line number
1782 i64 32, ;; Size in bits
1783 i64 32, ;; Align in bits
1784 i64 0, ;; Offset in bits
1785 i32 0, ;; Flags
1786 null, ;; Derived From type
1787 metadata !3, ;; Elements
1788 i32 0 ;; Runtime language
1789}
Devang Patel2a610c72009-08-25 05:24:07 +00001790
Devang Patel82459882009-08-26 05:01:18 +00001791;;
1792;; Define the array of enumerators used by composite type Trees.
1793;;
Devang Patele4b27562009-08-28 23:24:31 +00001794!3 = metadata !{metadata !4, metadata !5, metadata !6}
1795
1796;;
1797;; Define Spruce enumerator.
1798;;
Devang Patel4b945502010-03-09 00:44:10 +00001799!4 = metadata !{i32 524328, metadata !"Spruce", i64 100}
Devang Patele4b27562009-08-28 23:24:31 +00001800
1801;;
1802;; Define Oak enumerator.
1803;;
Devang Patel4b945502010-03-09 00:44:10 +00001804!5 = metadata !{i32 524328, metadata !"Oak", i64 200}
Devang Patele4b27562009-08-28 23:24:31 +00001805
1806;;
1807;; Define Maple enumerator.
1808;;
Devang Patel4b945502010-03-09 00:44:10 +00001809!6 = metadata !{i32 524328, metadata !"Maple", i64 300}
Devang Patele4b27562009-08-28 23:24:31 +00001810
Jim Laskeycec12a52006-03-14 18:08:46 +00001811</pre>
Bill Wendling48839d92009-05-17 05:52:39 +00001812</div>
Jim Laskeycec12a52006-03-14 18:08:46 +00001813
1814</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001815
NAKAMURA Takumif5af6ad2011-04-23 00:30:22 +00001816</div>
1817
Devang Patel6ac5b162011-11-15 22:59:54 +00001818
1819<!-- *********************************************************************** -->
1820<h2>
1821 <a name="llvmdwarfextension">Debugging information format</a>
1822</h2>
1823<!-- *********************************************************************** -->
1824<div>
1825<!-- ======================================================================= -->
1826<h3>
1827 <a name="objcproperty">Debugging Information Extension for Objective C
1828Properties</a></li>
1829</h3>
1830<div>
1831<!-- *********************************************************************** -->
1832<h4>
1833 <a name="objcpropertyintroduction">Introduction</a>
1834</h4>
1835<!-- *********************************************************************** -->
1836
1837<div>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001838<p>Objective C provides a simpler way to declare and define accessor methods
1839using declared properties. The language provides features to declare a
Devang Patel6ac5b162011-11-15 22:59:54 +00001840property and to let compiler synthesize accessor methods.
1841</p>
1842
Eric Christopherfc7243a2012-03-06 02:25:36 +00001843<p>The debugger lets developer inspect Objective C interfaces and their
1844instance variables and class variables. However, the debugger does not know
Devang Patel6ac5b162011-11-15 22:59:54 +00001845anything about the properties defined in Objective C interfaces. The debugger
Eric Christopherfc7243a2012-03-06 02:25:36 +00001846consumes information generated by compiler in DWARF format. The format does
Devang Patel6ac5b162011-11-15 22:59:54 +00001847not support encoding of Objective C properties. This proposal describes DWARF
1848extensions to encode Objective C properties, which the debugger can use to let
1849developers inspect Objective C properties.
1850</p>
1851
1852</div>
1853
1854
1855<!-- *********************************************************************** -->
1856<h4>
1857 <a name="objcpropertyproposal">Proposal</a>
1858</h4>
1859<!-- *********************************************************************** -->
1860
1861<div>
Devang Patelba98b6b2012-02-06 18:18:25 +00001862<p>Objective C properties exist separately from class members. A property
Eric Christopherfc7243a2012-03-06 02:25:36 +00001863can be defined only by &quot;setter&quot; and &quot;getter&quot; selectors, and
1864be calculated anew on each access. Or a property can just be a direct access
1865to some declared ivar. Finally it can have an ivar &quot;automatically
1866synthesized&quot; for it by the compiler, in which case the property can be
1867referred to in user code directly using the standard C dereference syntax as
1868well as through the property &quot;dot&quot; syntax, but there is no entry in
Devang Patelba98b6b2012-02-06 18:18:25 +00001869the @interface declaration corresponding to this ivar.
1870</p>
1871<p>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001872To facilitate debugging, these properties we will add a new DWARF TAG into the
1873DW_TAG_structure_type definition for the class to hold the description of a
Devang Patelba98b6b2012-02-06 18:18:25 +00001874given property, and a set of DWARF attributes that provide said description.
Eric Christopherfc7243a2012-03-06 02:25:36 +00001875The property tag will also contain the name and declared type of the property.
Devang Patelba98b6b2012-02-06 18:18:25 +00001876</p>
1877<p>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001878If there is a related ivar, there will also be a DWARF property attribute placed
1879in the DW_TAG_member DIE for that ivar referring back to the property TAG for
1880that property. And in the case where the compiler synthesizes the ivar directly,
1881the compiler is expected to generate a DW_TAG_member for that ivar (with the
1882DW_AT_artificial set to 1), whose name will be the name used to access this
1883ivar directly in code, and with the property attribute pointing back to the
Devang Patelba98b6b2012-02-06 18:18:25 +00001884property it is backing.
1885</p>
1886<p>
1887The following examples will serve as illustration for our discussion:
Devang Patel6ac5b162011-11-15 22:59:54 +00001888</p>
1889
1890<div class="doc_code">
1891<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001892@interface I1 {
Devang Patel6ac5b162011-11-15 22:59:54 +00001893 int n2;
Eric Christopherfc7243a2012-03-06 02:25:36 +00001894}
Devang Patel6ac5b162011-11-15 22:59:54 +00001895
Eric Christopherfc7243a2012-03-06 02:25:36 +00001896@property int p1;
1897@property int p2;
Devang Patel6ac5b162011-11-15 22:59:54 +00001898@end
1899
Eric Christopherfc7243a2012-03-06 02:25:36 +00001900@implementation I1
1901@synthesize p1;
1902@synthesize p2 = n2;
Devang Patel6ac5b162011-11-15 22:59:54 +00001903@end
Devang Patel6ac5b162011-11-15 22:59:54 +00001904</pre>
1905</div>
1906
Devang Patelba98b6b2012-02-06 18:18:25 +00001907<p>
1908This produces the following DWARF (this is a &quot;pseudo dwarfdump&quot; output):
1909</p>
1910<div class="doc_code">
1911<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +000019120x00000100: TAG_structure_type [7] *
Devang Patelba98b6b2012-02-06 18:18:25 +00001913 AT_APPLE_runtime_class( 0x10 )
1914 AT_name( "I1" )
Eric Christopherfc7243a2012-03-06 02:25:36 +00001915 AT_decl_file( "Objc_Property.m" )
Devang Patelba98b6b2012-02-06 18:18:25 +00001916 AT_decl_line( 3 )
1917
19180x00000110 TAG_APPLE_property
1919 AT_name ( "p1" )
1920 AT_type ( {0x00000150} ( int ) )
1921
19220x00000120: TAG_APPLE_property
1923 AT_name ( "p2" )
1924 AT_type ( {0x00000150} ( int ) )
1925
Eric Christopherfc7243a2012-03-06 02:25:36 +000019260x00000130: TAG_member [8]
Devang Patelba98b6b2012-02-06 18:18:25 +00001927 AT_name( "_p1" )
1928 AT_APPLE_property ( {0x00000110} "p1" )
1929 AT_type( {0x00000150} ( int ) )
1930 AT_artificial ( 0x1 )
1931
Eric Christopherfc7243a2012-03-06 02:25:36 +000019320x00000140: TAG_member [8]
Devang Patelba98b6b2012-02-06 18:18:25 +00001933 AT_name( "n2" )
1934 AT_APPLE_property ( {0x00000120} "p2" )
1935 AT_type( {0x00000150} ( int ) )
1936
19370x00000150: AT_type( ( int ) )
1938</pre>
1939</div>
1940
Eric Christopherfc7243a2012-03-06 02:25:36 +00001941<p> Note, the current convention is that the name of the ivar for an
Devang Patelba98b6b2012-02-06 18:18:25 +00001942auto-synthesized property is the name of the property from which it derives with
1943an underscore prepended, as is shown in the example.
1944But we actually don't need to know this convention, since we are given the name
1945of the ivar directly.
1946</p>
1947
1948<p>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001949Also, it is common practice in ObjC to have different property declarations in
1950the @interface and @implementation - e.g. to provide a read-only property in
1951the interface,and a read-write interface in the implementation. In that case,
1952the compiler should emit whichever property declaration will be in force in the
Devang Patelba98b6b2012-02-06 18:18:25 +00001953current translation unit.
1954</p>
1955
Eric Christopherfc7243a2012-03-06 02:25:36 +00001956<p> Developers can decorate a property with attributes which are encoded using
Devang Patel6ac5b162011-11-15 22:59:54 +00001957DW_AT_APPLE_property_attribute.
1958</p>
1959
1960<div class="doc_code">
1961<pre>
1962@property (readonly, nonatomic) int pr;
Devang Patelba98b6b2012-02-06 18:18:25 +00001963</pre>
1964</div>
1965<p>
1966Which produces a property tag:
1967<p>
1968<div class="doc_code">
1969<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001970TAG_APPLE_property [8]
1971 AT_name( "pr" )
1972 AT_type ( {0x00000147} (int) )
Devang Patel6ac5b162011-11-15 22:59:54 +00001973 AT_APPLE_property_attribute (DW_APPLE_PROPERTY_readonly, DW_APPLE_PROPERTY_nonatomic)
1974</pre>
1975</div>
1976
Eric Christopherfc7243a2012-03-06 02:25:36 +00001977<p> The setter and getter method names are attached to the property using
Devang Patel6ac5b162011-11-15 22:59:54 +00001978DW_AT_APPLE_property_setter and DW_AT_APPLE_property_getter attributes.
1979</p>
1980<div class="doc_code">
1981<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +00001982@interface I1
1983@property (setter=myOwnP3Setter:) int p3;
1984-(void)myOwnP3Setter:(int)a;
Devang Patel6ac5b162011-11-15 22:59:54 +00001985@end
1986
Eric Christopherfc7243a2012-03-06 02:25:36 +00001987@implementation I1
Devang Patel6ac5b162011-11-15 22:59:54 +00001988@synthesize p3;
Eric Christopherfc7243a2012-03-06 02:25:36 +00001989-(void)myOwnP3Setter:(int)a{ }
Devang Patel6ac5b162011-11-15 22:59:54 +00001990@end
Devang Patelba98b6b2012-02-06 18:18:25 +00001991</pre>
1992</div>
Devang Patel6ac5b162011-11-15 22:59:54 +00001993
Devang Patelba98b6b2012-02-06 18:18:25 +00001994<p>
1995The DWARF for this would be:
1996</p>
1997<div class="doc_code">
1998<pre>
Eric Christopherfc7243a2012-03-06 02:25:36 +000019990x000003bd: TAG_structure_type [7] *
Devang Patel6ac5b162011-11-15 22:59:54 +00002000 AT_APPLE_runtime_class( 0x10 )
2001 AT_name( "I1" )
Eric Christopherfc7243a2012-03-06 02:25:36 +00002002 AT_decl_file( "Objc_Property.m" )
Devang Patel6ac5b162011-11-15 22:59:54 +00002003 AT_decl_line( 3 )
Devang Patelba98b6b2012-02-06 18:18:25 +00002004
20050x000003cd TAG_APPLE_property
2006 AT_name ( "p3" )
2007 AT_APPLE_property_setter ( "myOwnP3Setter:" )
2008 AT_type( {0x00000147} ( int ) )
Eric Christopherfc7243a2012-03-06 02:25:36 +00002009
20100x000003f3: TAG_member [8]
2011 AT_name( "_p3" )
Devang Patelba98b6b2012-02-06 18:18:25 +00002012 AT_type ( {0x00000147} ( int ) )
2013 AT_APPLE_property ( {0x000003cd} )
2014 AT_artificial ( 0x1 )
Devang Patel6ac5b162011-11-15 22:59:54 +00002015</pre>
2016</div>
2017
2018</div>
2019
2020<!-- *********************************************************************** -->
2021<h4>
Devang Patelba98b6b2012-02-06 18:18:25 +00002022 <a name="objcpropertynewtags">New DWARF Tags</a>
2023</h4>
2024<!-- *********************************************************************** -->
2025
2026<div>
2027<table border="1" cellspacing="0">
2028 <tr>
2029 <th width=200 >TAG</th>
2030 <th width=200 >Value</th>
2031 </tr>
2032 <tr>
2033 <td width=200 >DW_TAG_APPLE_property</td>
2034 <td width=200 >0x4200</td>
2035 </tr>
2036</table>
2037
2038</div>
2039
2040<!-- *********************************************************************** -->
2041<h4>
Devang Patel6ac5b162011-11-15 22:59:54 +00002042 <a name="objcpropertynewattributes">New DWARF Attributes</a>
2043</h4>
2044<!-- *********************************************************************** -->
2045
2046<div>
2047<table border="1" cellspacing="0">
2048 <tr>
2049 <th width=200 >Attribute</th>
2050 <th width=200 >Value</th>
2051 <th width=200 >Classes</th>
2052 </tr>
2053 <tr>
Devang Patelba98b6b2012-02-06 18:18:25 +00002054 <td width=200 >DW_AT_APPLE_property</td>
2055 <td width=200 >0x3fed</td>
2056 <td width=200 >Reference</td>
Devang Patel6ac5b162011-11-15 22:59:54 +00002057 </tr>
2058 <tr>
2059 <td width=200 >DW_AT_APPLE_property_getter</td>
2060 <td width=200 >0x3fe9</td>
2061 <td width=200 >String</td>
2062 </tr>
2063 <tr>
2064 <td width=200 >DW_AT_APPLE_property_setter</td>
2065 <td width=200 >0x3fea</td>
2066 <td width=200 >String</td>
2067 </tr>
2068 <tr>
2069 <td width=200 >DW_AT_APPLE_property_attribute</td>
2070 <td width=200 >0x3feb</td>
2071 <td width=200 >Constant</td>
2072 </tr>
2073</table>
2074
2075</div>
2076
2077<!-- *********************************************************************** -->
2078<h4>
2079 <a name="objcpropertynewconstants">New DWARF Constants</a>
2080</h4>
2081<!-- *********************************************************************** -->
2082
2083<div>
2084<table border="1" cellspacing="0">
2085 <tr>
2086 <th width=200 >Name</th>
2087 <th width=200 >Value</th>
2088 </tr>
2089 <tr>
2090 <td width=200 >DW_AT_APPLE_PROPERTY_readonly</td>
2091 <td width=200 >0x1</td>
2092 </tr>
2093 <tr>
2094 <td width=200 >DW_AT_APPLE_PROPERTY_readwrite</td>
2095 <td width=200 >0x2</td>
2096 </tr>
2097 <tr>
2098 <td width=200 >DW_AT_APPLE_PROPERTY_assign</td>
2099 <td width=200 >0x4</td>
2100 </tr>
2101 <tr>
2102 <td width=200 >DW_AT_APPLE_PROPERTY_retain</td>
2103 <td width=200 >0x8</td>
2104 </tr>
2105 <tr>
2106 <td width=200 >DW_AT_APPLE_PROPERTY_copy</td>
2107 <td width=200 >0x10</td>
2108 </tr>
2109 <tr>
2110 <td width=200 >DW_AT_APPLE_PROPERTY_nonatomic</td>
2111 <td width=200 >0x20</td>
2112 </tr>
2113</table>
2114
2115</div>
2116</div>
2117</div>
2118
Chris Lattnerbdfb3392004-01-05 05:06:33 +00002119<!-- *********************************************************************** -->
Misha Brukman82873732004-05-12 19:21:57 +00002120
Chris Lattnerbdfb3392004-01-05 05:06:33 +00002121<hr>
Misha Brukman82873732004-05-12 19:21:57 +00002122<address>
2123 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +00002124 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukman82873732004-05-12 19:21:57 +00002125 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +00002126 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Misha Brukman82873732004-05-12 19:21:57 +00002127
2128 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
NAKAMURA Takumib9a33632011-04-09 02:13:37 +00002129 <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00002130 Last modified: $Date$
Misha Brukman82873732004-05-12 19:21:57 +00002131</address>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00002132
2133</body>
2134</html>