blob: 2cbd35f3e96a268343f961299ecc69d5347dee28 [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>
5 <title>Source Level Debugging with LLVM</title>
6 <link rel="stylesheet" href="llvm.css" type="text/css">
7</head>
8<body>
9
10<div class="doc_title">Source Level Debugging with LLVM</div>
11
Reid Spencerd3f876c2004-11-01 08:19:36 +000012<table class="layout" style="width:100%">
13 <tr class="layout">
14 <td class="left">
Chris Lattnerbdfb3392004-01-05 05:06:33 +000015<ul>
Misha Brukman82873732004-05-12 19:21:57 +000016 <li><a href="#introduction">Introduction</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000017 <ol>
18 <li><a href="#phil">Philosophy behind LLVM debugging information</a></li>
Jim Laskey383e0092006-03-23 17:54:33 +000019 <li><a href="#consumers">Debug information consumers</a></li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000020 <li><a href="#debugopt">Debugging optimized code</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000021 </ol></li>
Misha Brukman82873732004-05-12 19:21:57 +000022 <li><a href="#format">Debugging information format</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000023 <ol>
Jim Laskeycec12a52006-03-14 18:08:46 +000024 <li><a href="#debug_info_descriptors">Debug information descriptors</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000025 <ul>
Jim Laskeycec12a52006-03-14 18:08:46 +000026 <li><a href="#format_anchors">Anchor descriptors</a></li>
27 <li><a href="#format_compile_units">Compile unit descriptors</a></li>
28 <li><a href="#format_global_variables">Global variable descriptors</a></li>
29 <li><a href="#format_subprograms">Subprogram descriptors</a></li>
Jim Laskey3d11bee2006-03-15 19:10:52 +000030 <li><a href="#format_blocks">Block descriptors</a></li>
Jim Laskeycec12a52006-03-14 18:08:46 +000031 <li><a href="#format_basic_type">Basic type descriptors</a></li>
32 <li><a href="#format_derived_type">Derived type descriptors</a></li>
33 <li><a href="#format_composite_type">Composite type descriptors</a></li>
34 <li><a href="#format_subrange">Subrange descriptors</a></li>
35 <li><a href="#format_enumeration">Enumerator descriptors</a></li>
Jim Laskey383e0092006-03-23 17:54:33 +000036 <li><a href="#format_variables">Local variables</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000037 </ul></li>
Jim Laskeycec12a52006-03-14 18:08:46 +000038 <li><a href="#format_common_intrinsics">Debugger intrinsic functions</a>
39 <ul>
40 <li><a href="#format_common_stoppoint">llvm.dbg.stoppoint</a></li>
41 <li><a href="#format_common_func_start">llvm.dbg.func.start</a></li>
42 <li><a href="#format_common_region_start">llvm.dbg.region.start</a></li>
43 <li><a href="#format_common_region_end">llvm.dbg.region.end</a></li>
44 <li><a href="#format_common_declare">llvm.dbg.declare</a></li>
45 </ul></li>
46 <li><a href="#format_common_stoppoints">Representing stopping points in the
47 source program</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000048 </ol></li>
49 <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000050 <ol>
Jim Laskeycec12a52006-03-14 18:08:46 +000051 <li><a href="#ccxx_compile_units">C/C++ source file information</a></li>
52 <li><a href="#ccxx_global_variable">C/C++ global variable information</a></li>
53 <li><a href="#ccxx_subprogram">C/C++ function information</a></li>
54 <li><a href="#ccxx_basic_types">C/C++ basic types</a></li>
55 <li><a href="#ccxx_derived_types">C/C++ derived types</a></li>
56 <li><a href="#ccxx_composite_types">C/C++ struct/union types</a></li>
57 <li><a href="#ccxx_enumeration_types">C/C++ enumeration types</a></li>
Misha Brukman82873732004-05-12 19:21:57 +000058 </ol></li>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000059</ul>
Misha Brukman82873732004-05-12 19:21:57 +000060</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +000061<td class="right">
Misha Brukmane849a1a2004-05-12 21:26:16 +000062<img src="img/venusflytrap.jpg" alt="A leafy and green bug eater" width="247"
Misha Brukman82873732004-05-12 19:21:57 +000063height="369">
64</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +000065</tr></table>
Misha Brukman82873732004-05-12 19:21:57 +000066
Chris Lattner7911ce22004-05-23 21:07:27 +000067<div class="doc_author">
Jim Laskeycec12a52006-03-14 18:08:46 +000068 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
69 and <a href="mailto:jlaskey@apple.com">Jim Laskey</a></p>
Chris Lattner7911ce22004-05-23 21:07:27 +000070</div>
71
Chris Lattnerbdfb3392004-01-05 05:06:33 +000072
73<!-- *********************************************************************** -->
Misha Brukman94218a72004-12-09 20:27:37 +000074<div class="doc_section"><a name="introduction">Introduction</a></div>
75<!-- *********************************************************************** -->
Chris Lattnerbdfb3392004-01-05 05:06:33 +000076
77<div class="doc_text">
78
79<p>This document is the central repository for all information pertaining to
Jim Laskeycec12a52006-03-14 18:08:46 +000080debug information in LLVM. It describes the <a href="#format">actual format
81that the LLVM debug information</a> takes, which is useful for those interested
82in creating front-ends or dealing directly with the information. Further, this
83document provides specifc examples of what debug information for C/C++.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +000084
85</div>
86
87<!-- ======================================================================= -->
88<div class="doc_subsection">
89 <a name="phil">Philosophy behind LLVM debugging information</a>
90</div>
91
92<div class="doc_text">
93
Misha Brukman82873732004-05-12 19:21:57 +000094<p>The idea of the LLVM debugging information is to capture how the important
Chris Lattnerbdfb3392004-01-05 05:06:33 +000095pieces of the source-language's Abstract Syntax Tree map onto LLVM code.
96Several design aspects have shaped the solution that appears here. The
97important ones are:</p>
98
Misha Brukman82873732004-05-12 19:21:57 +000099<ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000100<li>Debugging information should have very little impact on the rest of the
101compiler. No transformations, analyses, or code generators should need to be
102modified because of debugging information.</li>
103
104<li>LLVM optimizations should interact in <a href="#debugopt">well-defined and
105easily described ways</a> with the debugging information.</li>
106
107<li>Because LLVM is designed to support arbitrary programming languages,
108LLVM-to-LLVM tools should not need to know anything about the semantics of the
109source-level-language.</li>
110
111<li>Source-level languages are often <b>widely</b> different from one another.
112LLVM should not put any restrictions of the flavor of the source-language, and
113the debugging information should work with any language.</li>
114
115<li>With code generator support, it should be possible to use an LLVM compiler
Chris Lattner8ff75902004-01-06 05:31:32 +0000116to compile a program to native machine code and standard debugging formats.
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000117This allows compatibility with traditional machine-code level debuggers, like
118GDB or DBX.</li>
119
Misha Brukman82873732004-05-12 19:21:57 +0000120</ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000121
Misha Brukman82873732004-05-12 19:21:57 +0000122<p>The approach used by the LLVM implementation is to use a small set of <a
Chris Lattner8ff75902004-01-06 05:31:32 +0000123href="#format_common_intrinsics">intrinsic functions</a> to define a mapping
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000124between LLVM program objects and the source-level objects. The description of
125the source-level program is maintained in LLVM global variables in an <a
Chris Lattner8ff75902004-01-06 05:31:32 +0000126href="#ccxx_frontend">implementation-defined format</a> (the C/C++ front-end
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000127currently uses working draft 7 of the <a
128href="http://www.eagercon.com/dwarf/dwarf3std.htm">Dwarf 3 standard</a>).</p>
129
Jim Laskeycec12a52006-03-14 18:08:46 +0000130<p>When a program is being debugged, a debugger interacts with the user and
131turns the stored debug information into source-language specific information.
Jim Laskey3d11bee2006-03-15 19:10:52 +0000132As such, a debugger must be aware of the source-language, and is thus tied to
Jim Laskeycec12a52006-03-14 18:08:46 +0000133a specific language of family of languages.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000134
135</div>
136
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000137<!-- ======================================================================= -->
138<div class="doc_subsection">
Jim Laskey383e0092006-03-23 17:54:33 +0000139 <a name="consumers">Debug information consumers</a>
140</div>
141
142<div class="doc_text">
143<p>The role of debug information is to provide meta information normally
144stripped away during the compilation process. This meta information provides an
145llvm user a relationship between generated code and the original program source
146code.</p>
147
148<p>Currently, debug information is consumed by the DwarfWriter to produce dwarf
149information used by the gdb debugger. Other targets could use the same
150information to produce stabs or other debug forms.</p>
151
152<p>It would also be reasonable to use debug information to feed profiling tools
153for analysis of generated code, or, tools for reconstructing the original source
154from generated code.</p>
155
156<p>TODO - expound a bit more.</p>
157
158</div>
159
160<!-- ======================================================================= -->
161<div class="doc_subsection">
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000162 <a name="debugopt">Debugging optimized code</a>
163</div>
164
165<div class="doc_text">
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000166
Misha Brukman82873732004-05-12 19:21:57 +0000167<p>An extremely high priority of LLVM debugging information is to make it
168interact well with optimizations and analysis. In particular, the LLVM debug
169information provides the following guarantees:</p>
170
171<ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000172
173<li>LLVM debug information <b>always provides information to accurately read the
174source-level state of the program</b>, regardless of which LLVM optimizations
175have been run, and without any modification to the optimizations themselves.
176However, some optimizations may impact the ability to modify the current state
177of the program with a debugger, such as setting program variables, or calling
178function that have been deleted.</li>
179
180<li>LLVM optimizations gracefully interact with debugging information. If they
181are not aware of debug information, they are automatically disabled as necessary
182in the cases that would invalidate the debug info. This retains the LLVM
183features making it easy to write new transformations.</li>
184
185<li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM
186debugging information, allowing them to update the debugging information as they
187perform aggressive optimizations. This means that, with effort, the LLVM
188optimizers could optimize debug code just as well as non-debug code.</li>
189
190<li>LLVM debug information does not prevent many important optimizations from
191happening (for example inlining, basic block reordering/merging/cleanup, tail
192duplication, etc), further reducing the amount of the compiler that eventually
193is "aware" of debugging information.</li>
194
195<li>LLVM debug information is automatically optimized along with the rest of the
196program, using existing facilities. For example, duplicate information is
197automatically merged by the linker, and unused information is automatically
198removed.</li>
199
Misha Brukman82873732004-05-12 19:21:57 +0000200</ul>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000201
Misha Brukman82873732004-05-12 19:21:57 +0000202<p>Basically, the debug information allows you to compile a program with
203"<tt>-O0 -g</tt>" and get full debug information, allowing you to arbitrarily
Jim Laskey3d11bee2006-03-15 19:10:52 +0000204modify the program as it executes from a debugger. Compiling a program with
Misha Brukman82873732004-05-12 19:21:57 +0000205"<tt>-O3 -g</tt>" gives you full debug information that is always available and
206accurate for reading (e.g., you get accurate stack traces despite tail call
207elimination and inlining), but you might lose the ability to modify the program
208and call functions where were optimized out of the program, or inlined away
209completely.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000210
211</div>
212
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000213<!-- *********************************************************************** -->
214<div class="doc_section">
Chris Lattner8ff75902004-01-06 05:31:32 +0000215 <a name="format">Debugging information format</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000216</div>
217<!-- *********************************************************************** -->
218
219<div class="doc_text">
220
221<p>LLVM debugging information has been carefully designed to make it possible
222for the optimizer to optimize the program and debugging information without
223necessarily having to know anything about debugging information. In particular,
224the global constant merging pass automatically eliminates duplicated debugging
225information (often caused by header files), the global dead code elimination
226pass automatically deletes debugging information for a function if it decides to
227delete the function, and the linker eliminates debug information when it merges
228<tt>linkonce</tt> functions.</p>
229
230<p>To do this, most of the debugging information (descriptors for types,
231variables, functions, source files, etc) is inserted by the language front-end
232in the form of LLVM global variables. These LLVM global variables are no
233different from any other global variables, except that they have a web of LLVM
234intrinsic functions that point to them. If the last references to a particular
235piece of debugging information are deleted (for example, by the
236<tt>-globaldce</tt> pass), the extraneous debug information will automatically
237become dead and be removed by the optimizer.</p>
238
Jim Laskeycec12a52006-03-14 18:08:46 +0000239<p>Debug information is designed to be agnostic about the target debugger and
240debugging information representation (e.g. DWARF/Stabs/etc). It uses a generic
241machine debug information pass to decode the information that represents
242variables, types, functions, namespaces, etc: this allows for arbitrary
243source-language semantics and type-systems to be used, as long as there is a
244module written for the target debugger to interpret the information. In
245addition, debug global variables are declared in the <tt>"llvm.metadata"</tt>
246section. All values declared in this section are stripped away after target
247debug information is constructed and before the program object is emitted.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000248
Misha Brukman82873732004-05-12 19:21:57 +0000249<p>To provide basic functionality, the LLVM debugger does have to make some
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000250assumptions about the source-level language being debugged, though it keeps
251these to a minimum. The only common features that the LLVM debugger assumes
Jim Laskeycec12a52006-03-14 18:08:46 +0000252exist are <a href="#format_compile_units">source files</a>, and <a
253href="#format_global_variables">program objects</a>. These abstract objects are
Jim Laskey3d11bee2006-03-15 19:10:52 +0000254used by a debugger to form stack traces, show information about local
Misha Brukman82873732004-05-12 19:21:57 +0000255variables, etc.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000256
257<p>This section of the documentation first describes the representation aspects
Chris Lattner8ff75902004-01-06 05:31:32 +0000258common to any source-language. The <a href="#ccxx_frontend">next section</a>
259describes the data layout conventions used by the C and C++ front-ends.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000260
261</div>
262
263<!-- ======================================================================= -->
264<div class="doc_subsection">
Jim Laskeycec12a52006-03-14 18:08:46 +0000265 <a name="debug_info_descriptors">Debug information descriptors</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000266</div>
267
268<div class="doc_text">
Jim Laskeycec12a52006-03-14 18:08:46 +0000269<p>In consideration of the complexity and volume of debug information, LLVM
270provides a specification for well formed debug global variables. The constant
271value of each of these globals is one of a limited set of structures, known as
272debug descriptors.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000273
Jim Laskeycec12a52006-03-14 18:08:46 +0000274<p>Consumers of LLVM debug information expect the descriptors for program
275objects to start in a canonical format, but the descriptors can include
Jim Laskey383e0092006-03-23 17:54:33 +0000276additional information appended at the end that is source-language specific. All
277LLVM debugging information is versioned, allowing backwards compatibility in the
278case that the core structures need to change in some way. Also, all debugging
279information objects start with a tag to indicate what type of object it is. The
280source-language is allowed to define its own objects, by using unreserved tag
281numbers. We recommend using with tags in the range 0x1000 thru 0x2000 (there is
282a defined enum DW_TAG_user_base = 0x1000.)</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000283
284<p>The fields of debug descriptors used internally by LLVM (MachineDebugInfo)
285are restricted to only the simple data types <tt>int</tt>, <tt>uint</tt>,
286<tt>bool</tt>, <tt>float</tt>, <tt>double</tt>, <tt>sbyte*</tt> and <tt> { }*
287</tt>. References to arbitrary values are handled using a <tt> { }* </tt> and a
288cast to <tt> { }* </tt> expression; typically references to other field
289descriptors, arrays of descriptors or global variables.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000290
Misha Brukman82873732004-05-12 19:21:57 +0000291<pre>
Jim Laskeycec12a52006-03-14 18:08:46 +0000292 %llvm.dbg.object.type = type {
293 uint, ;; A tag
294 ...
295 }
Misha Brukman82873732004-05-12 19:21:57 +0000296</pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000297
Jim Laskeycec12a52006-03-14 18:08:46 +0000298<p>The first field of a descriptor is always an <tt>uint</tt> containing a tag
299value identifying the content of the descriptor. The remaining fields are
300specific to the descriptor. The values of tags are loosely bound to the tag
301values of Dwarf information entries. However, that does not restrict the use of
302the information supplied to Dwarf targets.</p>
303
304<p>The details of the various descriptors follow.</p>
305
306</div>
307
308<!-- ======================================================================= -->
309<div class="doc_subsubsection">
310 <a name="format_anchors">Anchor descriptors</a>
311</div>
312
313<div class="doc_text">
314
315<pre>
316 %<a href="#format_anchors">llvm.dbg.anchor.type</a> = type {
317 uint, ;; Tag = 0
318 uint ;; Tag of descriptors grouped by the anchor
319 }
320</pre>
321
322<p>One important aspect of the LLVM debug representation is that it allows the
323LLVM debugger to efficiently index all of the global objects without having the
324scan the program. To do this, all of the global objects use "anchor"
325descriptors with designated names. All of the global objects of a particular
326type (e.g., compile units) contain a pointer to the anchor. This pointer allows
Jim Laskey3d11bee2006-03-15 19:10:52 +0000327a debugger to use def-use chains to find all global objects of that type.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000328
329<p>The following names are recognized as anchors by LLVM:</p>
330
331<pre>
332 %<a href="#format_compile_units">llvm.dbg.compile_units</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 17 } ;; DW_TAG_compile_unit
333 %<a href="#format_global_variables">llvm.dbg.global_variables</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 52 } ;; DW_TAG_variable
334 %<a href="#format_subprograms">llvm.dbg.subprograms</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 46 } ;; DW_TAG_subprogram
335</pre>
336
337<p>Using anchors in this way (where the compile unit descriptor points to the
338anchors, as opposed to having a list of compile unit descriptors) allows for the
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000339standard dead global elimination and merging passes to automatically remove
340unused debugging information. If the globals were kept track of through lists,
341there would always be an object pointing to the descriptors, thus would never be
Misha Brukman82873732004-05-12 19:21:57 +0000342deleted.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000343
344</div>
345
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000346<!-- ======================================================================= -->
Jim Laskeycec12a52006-03-14 18:08:46 +0000347<div class="doc_subsubsection">
348 <a name="format_compile_units">Compile unit descriptors</a>
349</div>
350
351<div class="doc_text">
352
353<pre>
354 %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = type {
355 uint, ;; Tag = 17 (DW_TAG_compile_unit)
356 { }*, ;; Compile unit anchor = cast = (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_units</a> to { }*)
Jim Laskey383e0092006-03-23 17:54:33 +0000357 uint, ;; LLVM debug version number = 3
Jim Laskeycec12a52006-03-14 18:08:46 +0000358 uint, ;; Dwarf language identifier (ex. DW_LANG_C89)
359 sbyte*, ;; Source file name
360 sbyte*, ;; Source file directory (includes trailing slash)
361 sbyte* ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
362 }
363</pre>
364
365<p>These descriptors contain the version number for the debug info (currently
Jim Laskey383e0092006-03-23 17:54:33 +00003663), a source language ID for the file (we use the Dwarf 3.0 ID numbers, such as
Jim Laskeycec12a52006-03-14 18:08:46 +0000367<tt>DW_LANG_C89</tt>, <tt>DW_LANG_C_plus_plus</tt>, <tt>DW_LANG_Cobol74</tt>,
368etc), three strings describing the filename, working directory of the compiler,
369and an identifier string for the compiler that produced it.</p>
370
371<p> Compile unit descriptors provide the root context for objects declared in a
372specific source file. Global variables and top level functions would be defined
373using this context. Compile unit descriptors also provide context for source
374line correspondence.</p>
375
376</div>
377
378<!-- ======================================================================= -->
379<div class="doc_subsubsection">
380 <a name="format_global_variables">Global variable descriptors</a>
381</div>
382
383<div class="doc_text">
384
385<pre>
386 %<a href="#format_global_variables">llvm.dbg.global_variable.type</a> = type {
387 uint, ;; Tag = 52 (DW_TAG_variable)
388 { }*, ;; Global variable anchor = cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_global_variables">llvm.dbg.global_variables</a> to { }*),
Jim Laskey3d11bee2006-03-15 19:10:52 +0000389 { }*, ;; Reference to context descriptor
Jim Laskeycec12a52006-03-14 18:08:46 +0000390 sbyte*, ;; Name
Jim Laskey3d11bee2006-03-15 19:10:52 +0000391 { }*, ;; Reference to compile unit where defined
Jim Laskey383e0092006-03-23 17:54:33 +0000392 uint, ;; Line number where defined
Jim Laskeycec12a52006-03-14 18:08:46 +0000393 { }*, ;; Reference to type descriptor
394 bool, ;; True if the global is local to compile unit (static)
395 bool, ;; True if the global is defined in the compile unit (not extern)
Jim Laskey3d11bee2006-03-15 19:10:52 +0000396 { }* ;; Reference to the global variable
Jim Laskeycec12a52006-03-14 18:08:46 +0000397 }
398</pre>
399
400<p>These descriptors provide debug information about globals variables. The
401provide details such as name, type and where the variable is defined.</p>
402
403</div>
404
405<!-- ======================================================================= -->
406<div class="doc_subsubsection">
407 <a name="format_subprograms">Subprogram descriptors</a>
408</div>
409
410<div class="doc_text">
411
412<pre>
413 %<a href="#format_subprograms">llvm.dbg.subprogram.type</a> = type {
414 uint, ;; Tag = 46 (DW_TAG_subprogram)
415 { }*, ;; Subprogram anchor = cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_subprograms">llvm.dbg.subprograms</a> to { }*),
Jim Laskey3d11bee2006-03-15 19:10:52 +0000416 { }*, ;; Reference to context descriptor
Jim Laskeycec12a52006-03-14 18:08:46 +0000417 sbyte*, ;; Name
Jim Laskey3d11bee2006-03-15 19:10:52 +0000418 { }*, ;; Reference to compile unit where defined
Jim Laskey383e0092006-03-23 17:54:33 +0000419 uint, ;; Line number where defined
Jim Laskeycec12a52006-03-14 18:08:46 +0000420 { }*, ;; Reference to type descriptor
421 bool, ;; True if the global is local to compile unit (static)
Jim Laskey383e0092006-03-23 17:54:33 +0000422 bool ;; True if the global is defined in the compile unit (not extern)
Jim Laskeycec12a52006-03-14 18:08:46 +0000423 }
Jim Laskeycec12a52006-03-14 18:08:46 +0000424</pre>
425
426<p>These descriptors provide debug information about functions, methods and
Jim Laskey383e0092006-03-23 17:54:33 +0000427subprograms. They provide details such as name, return types and the source
428location where the subprogram is defined.</p>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000429
430</div>
431<!-- ======================================================================= -->
432<div class="doc_subsubsection">
433 <a name="format_blocks">Block descriptors</a>
434</div>
435
436<div class="doc_text">
437
438<pre>
439 %<a href="#format_blocks">llvm.dbg.block</a> = type {
440 uint, ;; Tag = 13 (DW_TAG_lexical_block)
Jim Laskey383e0092006-03-23 17:54:33 +0000441 { }* ;; Reference to context descriptor
Jim Laskey3d11bee2006-03-15 19:10:52 +0000442 }
443</pre>
444
445<p>These descriptors provide debug information about nested blocks within a
446subprogram. The array of member descriptors is used to define local variables
447and deeper nested blocks.</p>
448
Jim Laskeycec12a52006-03-14 18:08:46 +0000449</div>
450
451<!-- ======================================================================= -->
452<div class="doc_subsubsection">
453 <a name="format_basic_type">Basic type descriptors</a>
454</div>
455
456<div class="doc_text">
457
458<pre>
459 %<a href="#format_basic_type">llvm.dbg.basictype.type</a> = type {
460 uint, ;; Tag = 36 (DW_TAG_base_type)
461 { }*, ;; Reference to context (typically a compile unit)
462 sbyte*, ;; Name (may be "" for anonymous types)
463 { }*, ;; Reference to compile unit where defined (may be NULL)
Jim Laskey383e0092006-03-23 17:54:33 +0000464 uint, ;; Line number where defined (may be 0)
Jim Laskeycec12a52006-03-14 18:08:46 +0000465 uint, ;; Size in bits
466 uint, ;; Alignment in bits
467 uint, ;; Offset in bits
468 uint ;; Dwarf type encoding
469 }
470</pre>
471
472<p>These descriptors define primitive types used in the code. Example int, bool
473and float. The context provides the scope of the type, which is usually the top
474level. Since basic types are not usually user defined the compile unit and line
475number can be left as NULL and 0. The size, alignment and offset are expressed
476in bits and can be 64 bit values. The alignment is used to round the offset
477when embedded in a <a href="#format_composite_type">composite type</a>
478(example to keep float doubles on 64 bit boundaries.) The offset is the bit
479offset if embedded in a <a href="#format_composite_type">composite
480type</a>.</p>
481
482<p>The type encoding provides the details of the type. The values are typically
483one of the following;</p>
484
485<pre>
486 DW_ATE_address = 1
487 DW_ATE_boolean = 2
488 DW_ATE_float = 4
489 DW_ATE_signed = 5
490 DW_ATE_signed_char = 6
491 DW_ATE_unsigned = 7
492 DW_ATE_unsigned_char = 8
493</pre>
494
495</div>
496
497<!-- ======================================================================= -->
498<div class="doc_subsubsection">
499 <a name="format_derived_type">Derived type descriptors</a>
500</div>
501
502<div class="doc_text">
503
504<pre>
505 %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> = type {
506 uint, ;; Tag (see below)
507 { }*, ;; Reference to context
508 sbyte*, ;; Name (may be "" for anonymous types)
509 { }*, ;; Reference to compile unit where defined (may be NULL)
Jim Laskey383e0092006-03-23 17:54:33 +0000510 uint, ;; Line number where defined (may be 0)
Jim Laskeycec12a52006-03-14 18:08:46 +0000511 uint, ;; Size in bits
512 uint, ;; Alignment in bits
513 uint, ;; Offset in bits
514 { }* ;; Reference to type derived from
515 }
516</pre>
517
518<p>These descriptors are used to define types derived from other types. The
519value of the tag varies depending on the meaning. The following are possible
520tag values;</p>
521
522<pre>
Jim Laskey3d11bee2006-03-15 19:10:52 +0000523 DW_TAG_formal_parameter = 5
Jim Laskeycec12a52006-03-14 18:08:46 +0000524 DW_TAG_member = 13
525 DW_TAG_pointer_type = 15
526 DW_TAG_reference_type = 16
527 DW_TAG_typedef = 22
528 DW_TAG_const_type = 38
529 DW_TAG_volatile_type = 53
530 DW_TAG_restrict_type = 55
531</pre>
532
533<p> <tt>DW_TAG_member</tt> is used to define a member of a <a
Jim Laskey3d11bee2006-03-15 19:10:52 +0000534href="#format_composite_type">composite type</a> or <a
535href="#format_subprograms">subprogram</a>. The type of the member is the <a
536href="#format_derived_type">derived type</a>. <tt>DW_TAG_formal_parameter</tt>
537is used to define a member which is a formal argument of a subprogram.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000538
539<p><tt>DW_TAG_typedef</tt> is used to
540provide a name for the derived type.</p>
541
542<p><tt>DW_TAG_pointer_type</tt>,
543<tt>DW_TAG_reference_type</tt>, <tt>DW_TAG_const_type</tt>,
544<tt>DW_TAG_volatile_type</tt> and <tt>DW_TAG_restrict_type</tt> are used to
545qualify the <a href="#format_derived_type">derived type</a>. </p>
546
547<p><a href="#format_derived_type">Derived type</a> location can be determined
548from the compile unit and line number. The size, alignment and offset are
549expressed in bits and can be 64 bit values. The alignment is used to round the
550offset when embedded in a <a href="#format_composite_type">composite type</a>
551(example to keep float doubles on 64 bit boundaries.) The offset is the bit
552offset if embedded in a <a href="#format_composite_type">composite
553type</a>.</p>
554
555<p>Note that the <tt>void *</tt> type is expressed as a
556<tt>llvm.dbg.derivedtype.type</tt> with tag of <tt>DW_TAG_pointer_type</tt> and
557NULL derived type.</p>
558
559</div>
560
561<!-- ======================================================================= -->
562<div class="doc_subsubsection">
563 <a name="format_composite_type">Composite type descriptors</a>
564</div>
565
566<div class="doc_text">
567
568<pre>
569 %<a href="#format_composite_type">llvm.dbg.compositetype.type</a> = type {
570 uint, ;; Tag (see below)
571 { }*, ;; Reference to context
572 sbyte*, ;; Name (may be "" for anonymous types)
573 { }*, ;; Reference to compile unit where defined (may be NULL)
Jim Laskey383e0092006-03-23 17:54:33 +0000574 uint, ;; Line number where defined (may be 0)
Jim Laskeycec12a52006-03-14 18:08:46 +0000575 uint, ;; Size in bits
576 uint, ;; Alignment in bits
577 uint, ;; Offset in bits
578 { }* ;; Reference to array of member descriptors
579 }
580</pre>
581
582<p>These descriptors are used to define types that are composed of 0 or more
583elements. The value of the tag varies depending on the meaning. The following
584are possible tag values;</p>
585
586<pre>
587 DW_TAG_array_type = 1
588 DW_TAG_enumeration_type = 4
589 DW_TAG_structure_type = 19
590 DW_TAG_union_type = 23
591</pre>
592
593<p>The members of array types (tag = <tt>DW_TAG_array_type</tt>) are <a
594href="#format_subrange">subrange descriptors</a>, each representing the range of
595subscripts at that level of indexing.</p>
596
597<p>The members of enumeration types (tag = <tt>DW_TAG_enumeration_type</tt>) are
598<a href="#format_enumeration">enumerator descriptors</a>, each representing the
599definition of enumeration value
600for the set.</p>
601
602<p>The members of structure (tag = <tt>DW_TAG_structure_type</tt>) or union (tag
603= <tt>DW_TAG_union_type</tt>) types are any one of the <a
604href="#format_basic_type">basic</a>, <a href="#format_derived_type">derived</a>
605or <a href="#format_composite_type">composite</a> type descriptors, each
606representing a field member of the structure or union.</p>
607
608<p><a href="#format_composite_type">Composite type</a> location can be
609determined from the compile unit and line number. The size, alignment and
610offset are expressed in bits and can be 64 bit values. The alignment is used to
611round the offset when embedded in a <a href="#format_composite_type">composite
612type</a> (as an example, to keep float doubles on 64 bit boundaries.) The offset
613is the bit offset if embedded in a <a href="#format_composite_type">composite
614type</a>.</p>
615
616</div>
617
618<!-- ======================================================================= -->
619<div class="doc_subsubsection">
620 <a name="format_subrange">Subrange descriptors</a>
621</div>
622
623<div class="doc_text">
624
625<pre>
626 %<a href="#format_subrange">llvm.dbg.subrange.type</a> = type {
627 uint, ;; Tag = 33 (DW_TAG_subrange_type)
628 uint, ;; Low value
629 uint ;; High value
630 }
631</pre>
632
633<p>These descriptors are used to define ranges of array subscripts for an array
634<a href="#format_composite_type">composite type</a>. The low value defines the
635lower bounds typically zero for C/C++. The high value is the upper bounds.
636Values are 64 bit. High - low + 1 is the size of the array. If
637low == high the array will be unbounded.</p>
638
639</div>
640
641<!-- ======================================================================= -->
642<div class="doc_subsubsection">
643 <a name="format_enumeration">Enumerator descriptors</a>
644</div>
645
646<div class="doc_text">
647
648<pre>
649 %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> = type {
650 uint, ;; Tag = 40 (DW_TAG_enumerator)
651 sbyte*, ;; Name
652 uint ;; Value
653 }
654</pre>
655
656<p>These descriptors are used to define members of an enumeration <a
657href="#format_composite_type">composite type</a>, it associates the name to the
658value.</p>
659
660</div>
661
662<!-- ======================================================================= -->
Jim Laskey383e0092006-03-23 17:54:33 +0000663<div class="doc_subsubsection">
664 <a name="format_variables">Local variables</a>
665</div>
666
667<div class="doc_text">
668<pre>
669 %<a href="#format_variables">llvm.dbg.variable.type</a> = type {
670 uint, ;; Tag (see below)
671 { }*, ;; Context
672 sbyte*, ;; Name
673 { }*, ;; Reference to compile unit where defined
674 uint, ;; Line number where defined
675 { }* ;; Type descriptor
676 }
677</pre>
678
679<p>These descriptors are used to define variables local to a sub program. The
680value of the tag depends on the usage of the variable;</p>
681
682<pre>
683 DW_TAG_auto_variable = 256
684 DW_TAG_arg_variable = 257
685 DW_TAG_return_variable = 258
686</pre>
687
688<p>An auto variable is any variable declared in the body of the function. An
689argument variable is any variable that appears as a formal argument to the
690function. A return variable is used to track the result of a function and has
691no source correspondent.</p>
692
693<p>The context is eitehr the subprogram or block where the variable is defined.
694Name the source variable name. Compile unit and line indicate where the
695variable was defined. Type descriptor defines the declared type of the
696variable.</p>
697
698</div>
699
700<!-- ======================================================================= -->
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000701<div class="doc_subsection">
Jim Laskeycec12a52006-03-14 18:08:46 +0000702 <a name="format_common_intrinsics">Debugger intrinsic functions</a>
703</div>
704
705<div class="doc_text">
706
707<p>LLVM uses several intrinsic functions (name prefixed with "llvm.dbg") to
708provide debug information at various points in generated code.</p>
709
710</div>
711
712<!-- ======================================================================= -->
713<div class="doc_subsubsection">
714 <a name="format_common_stoppoint">llvm.dbg.stoppoint</a>
715</div>
716
717<div class="doc_text">
718<pre>
Jim Laskey108a6382006-03-23 17:58:46 +0000719 void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint, uint, { }* )
Jim Laskeycec12a52006-03-14 18:08:46 +0000720</pre>
721
722<p>This intrinsic is used to provide correspondence between the source file and
723the generated code. The first argument is the line number (base 1), second
724argument si the column number (0 if unknown) and the third argument the source
Jim Laskey108a6382006-03-23 17:58:46 +0000725<tt>%<a href="#format_compile_units">llvm.dbg.compile_unit</a>*</tt> cast to a
726<tt>{ }*</tt>. Code following a call to this intrinsic will have been defined
727in close proximity of the line, column and file. This information holds until
728the next call to <tt>%<a
Jim Laskey383e0092006-03-23 17:54:33 +0000729href="#format_common_stoppoint">lvm.dbg.stoppoint</a></tt>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000730
731</div>
732
733<!-- ======================================================================= -->
734<div class="doc_subsubsection">
735 <a name="format_common_func_start">llvm.dbg.func.start</a>
736</div>
737
738<div class="doc_text">
739<pre>
Jim Laskey383e0092006-03-23 17:54:33 +0000740 void %<a href="#format_common_func_start">llvm.dbg.func.start</a>( { }* )
Jim Laskeycec12a52006-03-14 18:08:46 +0000741</pre>
742
743<p>This intrinsic is used to link the debug information in <tt>%<a
744href="#format_subprograms">llvm.dbg.subprogram</a></tt> to the function. It also
745defines the beginning of the function's declarative region (scope.) The
746intrinsic should be called early in the function after the all the alloca
Jim Laskey383e0092006-03-23 17:54:33 +0000747instructions. It should be paired off with a closing <tt>%<a
748href="#format_common_region_end">llvm.dbg.region.end</a></tt>. The function's
749single argument is the <tt>%<a
750href="#format_subprograms">llvm.dbg.subprogram.type</a></tt>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000751
752</div>
753
754<!-- ======================================================================= -->
755<div class="doc_subsubsection">
756 <a name="format_common_region_start">llvm.dbg.region.start</a>
757</div>
758
759<div class="doc_text">
760<pre>
Jim Laskey383e0092006-03-23 17:54:33 +0000761 void %<a href="#format_common_region_start">llvm.dbg.region.start</a>( { }* )
Jim Laskeycec12a52006-03-14 18:08:46 +0000762</pre>
763
764<p>This intrinsic is used to define the beginning of a declarative scope (ex.
765block) for local language elements. It should be paired off with a closing
Jim Laskey383e0092006-03-23 17:54:33 +0000766<tt>%<a href="#format_common_region_end">llvm.dbg.region.end</a></tt>. The
767function's single argument is the <tt>%<a
768href="#format_blocks">llvm.dbg.block</a></tt> which is starting.</p>
769
Jim Laskeycec12a52006-03-14 18:08:46 +0000770
771</div>
772
773<!-- ======================================================================= -->
774<div class="doc_subsubsection">
775 <a name="format_common_region_end">llvm.dbg.region.end</a>
776</div>
777
778<div class="doc_text">
779<pre>
Jim Laskey383e0092006-03-23 17:54:33 +0000780 void %<a href="#format_common_region_end">llvm.dbg.region.end</a>( { }* )
Jim Laskeycec12a52006-03-14 18:08:46 +0000781</pre>
782
783<p>This intrinsic is used to define the end of a declarative scope (ex. block)
784for local language elements. It should be paired off with an opening <tt>%<a
785href="#format_common_region_start">llvm.dbg.region.start</a></tt> or <tt>%<a
Jim Laskey383e0092006-03-23 17:54:33 +0000786href="#format_common_func_start">llvm.dbg.func.start</a></tt>. The function's
787single argument is either the <tt>%<a
788href="#format_blocks">llvm.dbg.block</a></tt> or the <tt>%<a
789href="#format_subprograms">llvm.dbg.subprogram.type</a></tt> which is
790ending.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000791
792</div>
793
794<!-- ======================================================================= -->
795<div class="doc_subsubsection">
796 <a name="format_common_declare">llvm.dbg.declare</a>
797</div>
798
799<div class="doc_text">
800<pre>
Jim Laskey383e0092006-03-23 17:54:33 +0000801 void %<a href="#format_common_declare">llvm.dbg.declare</a>( { } *, { }* )
Jim Laskeycec12a52006-03-14 18:08:46 +0000802</pre>
803
804<p>This intrinsic provides information about a local element (ex. variable.)
Jim Laskey383e0092006-03-23 17:54:33 +0000805The first argument as a AllocA for the variable cast to a <tt>{ }*</tt>. The second
806argument is the <tt>%<a href="#format_variables">llvm.dbg.variable</a></tt>
807containing the description of the variable, also cast to a <tt>{ }*</tt>.</p>
Jim Laskeycec12a52006-03-14 18:08:46 +0000808
809</div>
810
811<!-- ======================================================================= -->
812<div class="doc_subsection">
813 <a name="format_common_stoppoints">
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000814 Representing stopping points in the source program
815 </a>
816</div>
817
818<div class="doc_text">
819
820<p>LLVM debugger "stop points" are a key part of the debugging representation
821that allows the LLVM to maintain simple semantics for <a
822href="#debugopt">debugging optimized code</a>. The basic idea is that the
Jim Laskeycec12a52006-03-14 18:08:46 +0000823front-end inserts calls to the <a
824href="#format_common_stoppoint">%<tt>llvm.dbg.stoppoint</tt></a> intrinsic
Jim Laskey3d11bee2006-03-15 19:10:52 +0000825function at every point in the program where a debugger should be able to
826inspect the program (these correspond to places a debugger stops when you
Jim Laskeycec12a52006-03-14 18:08:46 +0000827"<tt>step</tt>" through it). The front-end can choose to place these as
828fine-grained as it would like (for example, before every subexpression
829evaluated), but it is recommended to only put them after every source statement
830that includes executable code.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000831
Misha Brukman82873732004-05-12 19:21:57 +0000832<p>Using calls to this intrinsic function to demark legal points for the
833debugger to inspect the program automatically disables any optimizations that
834could potentially confuse debugging information. To non-debug-information-aware
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000835transformations, these calls simply look like calls to an external function,
836which they must assume to do anything (including reading or writing to any part
837of reachable memory). On the other hand, it does not impact many optimizations,
838such as code motion of non-trapping instructions, nor does it impact
Chris Lattner8ff75902004-01-06 05:31:32 +0000839optimization of subexpressions, code duplication transformations, or basic-block
840reordering transformations.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000841
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000842</div>
843
844
845<!-- ======================================================================= -->
846<div class="doc_subsection">
Chris Lattner8ff75902004-01-06 05:31:32 +0000847 <a name="format_common_lifetime">Object lifetimes and scoping</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000848</div>
849
850<div class="doc_text">
Misha Brukman82873732004-05-12 19:21:57 +0000851<p>In many languages, the local variables in functions can have their lifetime
852or scope limited to a subset of a function. In the C family of languages, for
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000853example, variables are only live (readable and writable) within the source block
854that they are defined in. In functional languages, values are only readable
855after they have been defined. Though this is a very obvious concept, it is also
856non-trivial to model in LLVM, because it has no notion of scoping in this sense,
Misha Brukman82873732004-05-12 19:21:57 +0000857and does not want to be tied to a language's scoping rules.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000858
Misha Brukman82873732004-05-12 19:21:57 +0000859<p>In order to handle this, the LLVM debug format uses the notion of "regions"
860of a function, delineated by calls to intrinsic functions. These intrinsic
861functions define new regions of the program and indicate when the region
862lifetime expires. Consider the following C fragment, for example:</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000863
Misha Brukman82873732004-05-12 19:21:57 +0000864<pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00008651. void foo() {
8662. int X = ...;
8673. int Y = ...;
8684. {
8695. int Z = ...;
8706. ...
8717. }
8728. ...
8739. }
Misha Brukman82873732004-05-12 19:21:57 +0000874</pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000875
Jim Laskeycec12a52006-03-14 18:08:46 +0000876<p>Compiled to LLVM, this function would be represented like this:</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000877
Misha Brukman82873732004-05-12 19:21:57 +0000878<pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000879void %foo() {
Jim Laskeycec12a52006-03-14 18:08:46 +0000880entry:
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000881 %X = alloca int
882 %Y = alloca int
883 %Z = alloca int
Jim Laskeycec12a52006-03-14 18:08:46 +0000884
885 ...
886
887 call void %<a href="#format_common_func_start">llvm.dbg.func.start</a>( %<a href="#format_subprograms">llvm.dbg.subprogram.type</a>* %llvm.dbg.subprogram )
888
889 call void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint 2, uint 2, %<a href="#format_compile_units">llvm.dbg.compile_unit</a>* %llvm.dbg.compile_unit )
890
891 call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %X, ...)
892 call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %Y, ...)
893
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000894 <i>;; Evaluate expression on line 2, assigning to X.</i>
Jim Laskeycec12a52006-03-14 18:08:46 +0000895
896 call void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint 3, uint 2, %<a href="#format_compile_units">llvm.dbg.compile_unit</a>* %llvm.dbg.compile_unit )
897
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000898 <i>;; Evaluate expression on line 3, assigning to Y.</i>
Jim Laskeycec12a52006-03-14 18:08:46 +0000899
900 call void %<a href="#format_common_stoppoint">llvm.region.start</a>()
901 call void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint 5, uint 4, %<a href="#format_compile_units">llvm.dbg.compile_unit</a>* %llvm.dbg.compile_unit )
902 call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %X, ...)
903
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000904 <i>;; Evaluate expression on line 5, assigning to Z.</i>
Jim Laskeycec12a52006-03-14 18:08:46 +0000905
906 call void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint 7, uint 2, %<a href="#format_compile_units">llvm.dbg.compile_unit</a>* %llvm.dbg.compile_unit )
907 call void %<a href="#format_common_region_end">llvm.region.end</a>()
908
909 call void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint 9, uint 2, %<a href="#format_compile_units">llvm.dbg.compile_unit</a>* %llvm.dbg.compile_unit )
910
911 call void %<a href="#format_common_region_end">llvm.region.end</a>()
912
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000913 ret void
914}
Misha Brukman82873732004-05-12 19:21:57 +0000915</pre>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000916
Misha Brukman82873732004-05-12 19:21:57 +0000917<p>This example illustrates a few important details about the LLVM debugging
Jim Laskeycec12a52006-03-14 18:08:46 +0000918information. In particular, it shows how the various intrinsics are applied
919together to allow a debugger to analyze the relationship between statements,
920variable definitions, and the code used to implement the function.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000921
Jim Laskeycec12a52006-03-14 18:08:46 +0000922<p>The first intrinsic <tt>%<a
923href="#format_common_func_start">llvm.dbg.func.start</a></tt> provides
924a link with the <a href="#format_subprograms">subprogram descriptor</a>
925containing the details of this function. This call also defines the beginning
926of the function region, bounded by the <tt>%<a
927href="#format_common_region_end">llvm.region.end</a></tt> at the end of
928the function. This region is used to bracket the lifetime of variables declared
929within. For a function, this outer region defines a new stack frame whose
930lifetime ends when the region is ended.</p>
931
932<p>It is possible to define inner regions for short term variables by using the
933%<a href="#format_common_stoppoint"><tt>llvm.region.start</tt></a> and <a
934href="#format_common_region_end"><tt>%llvm.region.end</tt></a> to bound a
935region. The inner region in this example would be for the block containing the
936declaration of Z.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000937
Misha Brukman82873732004-05-12 19:21:57 +0000938<p>Using regions to represent the boundaries of source-level functions allow
939LLVM interprocedural optimizations to arbitrarily modify LLVM functions without
Chris Lattner8ff75902004-01-06 05:31:32 +0000940having to worry about breaking mapping information between the LLVM code and the
941and source-level program. In particular, the inliner requires no modification
942to support inlining with debugging information: there is no explicit correlation
943drawn between LLVM functions and their source-level counterparts (note however,
944that if the inliner inlines all instances of a non-strong-linkage function into
945its caller that it will not be possible for the user to manually invoke the
Jim Laskey3d11bee2006-03-15 19:10:52 +0000946inlined function from a debugger).</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000947
Misha Brukman82873732004-05-12 19:21:57 +0000948<p>Once the function has been defined, the <a
Jim Laskeycec12a52006-03-14 18:08:46 +0000949href="#format_common_stoppoint"><tt>stopping point</tt></a> corresponding to
950line #2 (column #2) of the function is encountered. At this point in the
951function, <b>no</b> local variables are live. As lines 2 and 3 of the example
952are executed, their variable definitions are introduced into the program using
953%<a href="#format_common_declare"><tt>llvm.dbg.declare</tt></a>, without the
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000954need to specify a new region. These variables do not require new regions to be
955introduced because they go out of scope at the same point in the program: line
Misha Brukman82873732004-05-12 19:21:57 +00009569.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000957
Misha Brukman82873732004-05-12 19:21:57 +0000958<p>In contrast, the <tt>Z</tt> variable goes out of scope at a different time,
Jim Laskeycec12a52006-03-14 18:08:46 +0000959on line 7. For this reason, it is defined within the inner region, which kills
960the availability of <tt>Z</tt> before the code for line 8 is executed. In this
961way, regions can support arbitrary source-language scoping rules, as long as
962they can only be nested (ie, one scope cannot partially overlap with a part of
963another scope).</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000964
Misha Brukman82873732004-05-12 19:21:57 +0000965<p>It is worth noting that this scoping mechanism is used to control scoping of
966all declarations, not just variable declarations. For example, the scope of a
Jim Laskeycec12a52006-03-14 18:08:46 +0000967C++ using declaration is controlled with this couldchange how name lookup is
968performed.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000969
970</div>
971
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000972
973
974<!-- *********************************************************************** -->
975<div class="doc_section">
Chris Lattner8ff75902004-01-06 05:31:32 +0000976 <a name="ccxx_frontend">C/C++ front-end specific debug information</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000977</div>
Misha Brukman94218a72004-12-09 20:27:37 +0000978<!-- *********************************************************************** -->
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000979
980<div class="doc_text">
981
Misha Brukman82873732004-05-12 19:21:57 +0000982<p>The C and C++ front-ends represent information about the program in a format
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000983that is effectively identical to <a
984href="http://www.eagercon.com/dwarf/dwarf3std.htm">Dwarf 3.0</a> in terms of
985information content. This allows code generators to trivially support native
986debuggers by generating standard dwarf information, and contains enough
Chris Lattner8ff75902004-01-06 05:31:32 +0000987information for non-dwarf targets to translate it as needed.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000988
Jim Laskeycec12a52006-03-14 18:08:46 +0000989<p>This section describes the forms used to represent C and C++ programs. Other
990languages could pattern themselves after this (which itself is tuned to
Chris Lattner8ff75902004-01-06 05:31:32 +0000991representing programs in the same way that Dwarf 3 does), or they could choose
Jim Laskeycec12a52006-03-14 18:08:46 +0000992to provide completely different forms if they don't fit into the Dwarf model.
993As support for debugging information gets added to the various LLVM
Misha Brukman82873732004-05-12 19:21:57 +0000994source-language front-ends, the information used should be documented here.</p>
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000995
Jim Laskeycec12a52006-03-14 18:08:46 +0000996<p>The following sections provide examples of various C/C++ constructs and the
997debug information that would best describe those constructs.</p>
998
Chris Lattnerbdfb3392004-01-05 05:06:33 +0000999</div>
1000
1001<!-- ======================================================================= -->
1002<div class="doc_subsection">
Jim Laskeycec12a52006-03-14 18:08:46 +00001003 <a name="ccxx_compile_units">C/C++ source file information</a>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001004</div>
1005
1006<div class="doc_text">
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001007
Jim Laskeycec12a52006-03-14 18:08:46 +00001008<p>Given the source files "MySource.cpp" and "MyHeader.h" located in the
1009directory "/Users/mine/sources", the following code;</p>
Chris Lattner8ff75902004-01-06 05:31:32 +00001010
Jim Laskeycec12a52006-03-14 18:08:46 +00001011<pre>
1012#include "MyHeader.h"
Chris Lattner8ff75902004-01-06 05:31:32 +00001013
Jim Laskeycec12a52006-03-14 18:08:46 +00001014int main(int argc, char *argv[]) {
1015 return 0;
1016}
1017</pre>
Chris Lattner8ff75902004-01-06 05:31:32 +00001018
Jim Laskeycec12a52006-03-14 18:08:46 +00001019<p>a C/C++ front-end would generate the following descriptors;</p>
1020
1021<pre>
1022...
1023;;
1024;; Define types used. In this case we need one for compile unit anchors and one
1025;; for compile units.
1026;;
1027%<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
1028%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = type { uint, { }*, uint, uint, sbyte*, sbyte*, sbyte* }
1029...
1030;;
1031;; Define the anchor for compile units. Note that the second field of the
1032;; anchor is 17, which is the same as the tag for compile units
1033;; (17 = DW_TAG_compile_unit.)
1034;;
1035%<a href="#format_compile_units">llvm.dbg.compile_units</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 17 }, section "llvm.metadata"
1036
1037;;
1038;; Define the compile unit for the source file "/Users/mine/sources/MySource.cpp".
1039;;
1040%<a href="#format_compile_units">llvm.dbg.compile_unit1</a> = internal constant %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> {
1041 uint 17,
1042 { }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_units</a> to { }*),
1043 uint 1,
1044 uint 1,
1045 sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0),
1046 sbyte* getelementptr ([21 x sbyte]* %str2, int 0, int 0),
1047 sbyte* getelementptr ([33 x sbyte]* %str3, int 0, int 0) }, section "llvm.metadata"
1048
1049;;
1050;; Define the compile unit for the header file "/Users/mine/sources/MyHeader.h".
1051;;
1052%<a href="#format_compile_units">llvm.dbg.compile_unit2</a> = internal constant %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> {
1053 uint 17,
1054 { }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_units</a> to { }*),
1055 uint 1,
1056 uint 1,
1057 sbyte* getelementptr ([11 x sbyte]* %str4, int 0, int 0),
1058 sbyte* getelementptr ([21 x sbyte]* %str2, int 0, int 0),
1059 sbyte* getelementptr ([33 x sbyte]* %str3, int 0, int 0) }, section "llvm.metadata"
1060
1061;;
1062;; Define each of the strings used in the compile units.
1063;;
1064%str1 = internal constant [13 x sbyte] c"MySource.cpp\00", section "llvm.metadata";
1065%str2 = internal constant [21 x sbyte] c"/Users/mine/sources/\00", section "llvm.metadata";
1066%str3 = internal constant [33 x sbyte] c"4.0.1 LLVM (LLVM research group)\00", section "llvm.metadata";
1067%str4 = internal constant [11 x sbyte] c"MyHeader.h\00", section "llvm.metadata";
1068...
1069</pre>
1070
Chris Lattner8ff75902004-01-06 05:31:32 +00001071</div>
1072
1073<!-- ======================================================================= -->
1074<div class="doc_subsection">
Jim Laskeycec12a52006-03-14 18:08:46 +00001075 <a name="ccxx_global_variable">C/C++ global variable information</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00001076</div>
1077
1078<div class="doc_text">
Jim Laskeycec12a52006-03-14 18:08:46 +00001079
1080<p>Given an integer global variable declared as follows;</p>
1081
1082<pre>
1083int MyGlobal = 100;
1084</pre>
1085
1086<p>a C/C++ front-end would generate the following descriptors;</p>
1087
1088<pre>
1089;;
1090;; Define types used. One for global variable anchors, one for the global
1091;; variable descriptor, one for the global's basic type and one for the global's
1092;; compile unit.
1093;;
1094%<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
Jim Laskey3d11bee2006-03-15 19:10:52 +00001095%<a href="#format_global_variables">llvm.dbg.global_variable.type</a> = type { uint, { }*, { }*, sbyte*, { }*, uint, { }*, bool, bool, { }*, uint }
Jim Laskeycec12a52006-03-14 18:08:46 +00001096%<a href="#format_basic_type">llvm.dbg.basictype.type</a> = type { uint, { }*, sbyte*, { }*, int, uint, uint, uint, uint }
1097%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = ...
1098...
1099;;
1100;; Define the global itself.
1101;;
1102%MyGlobal = global int 100
1103...
1104;;
1105;; Define the anchor for global variables. Note that the second field of the
1106;; anchor is 52, which is the same as the tag for global variables
1107;; (52 = DW_TAG_variable.)
1108;;
1109%<a href="#format_global_variables">llvm.dbg.global_variables</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 52 }, section "llvm.metadata"
1110
1111;;
1112;; Define the global variable descriptor. Note the reference to the global
1113;; variable anchor and the global variable itself.
1114;;
1115%<a href="#format_global_variables">llvm.dbg.global_variable</a> = internal constant %<a href="#format_global_variables">llvm.dbg.global_variable.type</a> {
1116 uint 52,
1117 { }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_global_variables">llvm.dbg.global_variables</a> to { }*),
1118 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1119 sbyte* getelementptr ([9 x sbyte]* %str1, int 0, int 0),
Jim Laskey3d11bee2006-03-15 19:10:52 +00001120 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1121 uint 1,
Jim Laskeycec12a52006-03-14 18:08:46 +00001122 { }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to { }*),
1123 bool false,
1124 bool true,
Jim Laskey3d11bee2006-03-15 19:10:52 +00001125 { }* cast (int* %MyGlobal to { }*) }, section "llvm.metadata"
Jim Laskeycec12a52006-03-14 18:08:46 +00001126
1127;;
1128;; Define the basic type of 32 bit signed integer. Note that since int is an
1129;; intrinsic type the source file is NULL and line 0.
1130;;
1131%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1132 uint 36,
1133 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1134 sbyte* getelementptr ([4 x sbyte]* %str2, int 0, int 0),
1135 { }* null,
1136 int 0,
1137 uint 32,
1138 uint 32,
1139 uint 0,
1140 uint 5 }, section "llvm.metadata"
1141
1142;;
1143;; Define the names of the global variable and basic type.
1144;;
1145%str1 = internal constant [9 x sbyte] c"MyGlobal\00", section "llvm.metadata"
1146%str2 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
1147</pre>
1148
Chris Lattner8ff75902004-01-06 05:31:32 +00001149</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001150
Jim Laskeycec12a52006-03-14 18:08:46 +00001151<!-- ======================================================================= -->
1152<div class="doc_subsection">
1153 <a name="ccxx_subprogram">C/C++ function information</a>
1154</div>
1155
1156<div class="doc_text">
1157
1158<p>Given a function declared as follows;</p>
1159
1160<pre>
1161int main(int argc, char *argv[]) {
1162 return 0;
1163}
1164</pre>
1165
1166<p>a C/C++ front-end would generate the following descriptors;</p>
1167
1168<pre>
1169;;
1170;; Define types used. One for subprogram anchors, one for the subprogram
1171;; descriptor, one for the global's basic type and one for the subprogram's
1172;; compile unit.
1173;;
Jim Laskey383e0092006-03-23 17:54:33 +00001174%<a href="#format_subprograms">llvm.dbg.subprogram.type</a> = type { uint, { }*, { }*, sbyte*, { }*, bool, bool }
Jim Laskeycec12a52006-03-14 18:08:46 +00001175%<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
1176%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = ...
1177
1178;;
1179;; Define the anchor for subprograms. Note that the second field of the
1180;; anchor is 46, which is the same as the tag for subprograms
1181;; (46 = DW_TAG_subprogram.)
1182;;
1183%<a href="#format_subprograms">llvm.dbg.subprograms</a> = linkonce constant %<a href="#format_anchors">llvm.dbg.anchor.type</a> { uint 0, uint 46 }, section "llvm.metadata"
1184
1185;;
1186;; Define the descriptor for the subprogram. TODO - more details.
1187;;
1188%<a href="#format_subprograms">llvm.dbg.subprogram</a> = internal constant %<a href="#format_subprograms">llvm.dbg.subprogram.type</a> {
1189 uint 46,
1190 { }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_subprograms">llvm.dbg.subprograms</a> to { }*),
1191 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1192 sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0),
Jim Laskey3d11bee2006-03-15 19:10:52 +00001193 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1194 uint 1,
Jim Laskeycec12a52006-03-14 18:08:46 +00001195 { }* null,
1196 bool false,
Jim Laskey383e0092006-03-23 17:54:33 +00001197 bool true }, section "llvm.metadata"
Jim Laskeycec12a52006-03-14 18:08:46 +00001198
1199;;
1200;; Define the name of the subprogram.
1201;;
1202%str1 = internal constant [5 x sbyte] c"main\00", section "llvm.metadata"
1203
1204;;
1205;; Define the subprogram itself.
1206;;
1207int %main(int %argc, sbyte** %argv) {
1208...
1209}
1210</pre>
1211
1212</div>
1213
1214<!-- ======================================================================= -->
1215<div class="doc_subsection">
1216 <a name="ccxx_basic_types">C/C++ basic types</a>
1217</div>
1218
1219<div class="doc_text">
1220
1221<p>The following are the basic type descriptors for C/C++ core types;</p>
1222
1223</div>
1224
1225<!-- ======================================================================= -->
1226<div class="doc_subsubsection">
1227 <a name="ccxx_basic_type_bool">bool</a>
1228</div>
1229
1230<div class="doc_text">
1231
1232<pre>
1233%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1234 uint 36,
1235 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1236 sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0),
1237 { }* null,
1238 int 0,
1239 uint 32,
1240 uint 32,
1241 uint 0,
1242 uint 2 }, section "llvm.metadata"
1243%str1 = internal constant [5 x sbyte] c"bool\00", section "llvm.metadata"
1244</pre>
1245
1246</div>
1247
1248<!-- ======================================================================= -->
1249<div class="doc_subsubsection">
1250 <a name="ccxx_basic_char">char</a>
1251</div>
1252
1253<div class="doc_text">
1254
1255<pre>
1256%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1257 uint 36,
1258 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1259 sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0),
1260 { }* null,
1261 int 0,
1262 uint 8,
1263 uint 8,
1264 uint 0,
1265 uint 6 }, section "llvm.metadata"
1266%str1 = internal constant [5 x sbyte] c"char\00", section "llvm.metadata"
1267</pre>
1268
1269</div>
1270
1271<!-- ======================================================================= -->
1272<div class="doc_subsubsection">
1273 <a name="ccxx_basic_unsigned_char">unsigned char</a>
1274</div>
1275
1276<div class="doc_text">
1277
1278<pre>
1279%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1280 uint 36,
1281 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1282 sbyte* getelementptr ([14 x sbyte]* %str1, int 0, int 0),
1283 { }* null,
1284 int 0,
1285 uint 8,
1286 uint 8,
1287 uint 0,
1288 uint 8 }, section "llvm.metadata"
1289%str1 = internal constant [14 x sbyte] c"unsigned char\00", section "llvm.metadata"
1290</pre>
1291
1292</div>
1293
1294<!-- ======================================================================= -->
1295<div class="doc_subsubsection">
1296 <a name="ccxx_basic_short">short</a>
1297</div>
1298
1299<div class="doc_text">
1300
1301<pre>
1302%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1303 uint 36,
1304 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1305 sbyte* getelementptr ([10 x sbyte]* %str1, int 0, int 0),
1306 { }* null,
1307 int 0,
1308 uint 16,
1309 uint 16,
1310 uint 0,
1311 uint 5 }, section "llvm.metadata"
1312%str1 = internal constant [10 x sbyte] c"short int\00", section "llvm.metadata"
1313</pre>
1314
1315</div>
1316
1317<!-- ======================================================================= -->
1318<div class="doc_subsubsection">
1319 <a name="ccxx_basic_unsigned_short">unsigned short</a>
1320</div>
1321
1322<div class="doc_text">
1323
1324<pre>
1325%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1326 uint 36,
1327 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1328 sbyte* getelementptr ([19 x sbyte]* %str1, int 0, int 0),
1329 { }* null,
1330 int 0,
1331 uint 16,
1332 uint 16,
1333 uint 0,
1334 uint 7 }, section "llvm.metadata"
1335%str1 = internal constant [19 x sbyte] c"short unsigned int\00", section "llvm.metadata"
1336</pre>
1337
1338</div>
1339
1340<!-- ======================================================================= -->
1341<div class="doc_subsubsection">
1342 <a name="ccxx_basic_int">int</a>
1343</div>
1344
1345<div class="doc_text">
1346
1347<pre>
1348%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1349 uint 36,
1350 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1351 sbyte* getelementptr ([4 x sbyte]* %str1, int 0, int 0),
1352 { }* null,
1353 int 0,
1354 uint 32,
1355 uint 32,
1356 uint 0,
1357 uint 5 }, section "llvm.metadata"
1358%str1 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
1359</pre>
1360
1361</div>
1362
1363<!-- ======================================================================= -->
1364<div class="doc_subsubsection">
1365 <a name="ccxx_basic_unsigned_int">unsigned int</a>
1366</div>
1367
1368<div class="doc_text">
1369
1370<pre>
1371%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1372 uint 36,
1373 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1374 sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0),
1375 { }* null,
1376 int 0,
1377 uint 32,
1378 uint 32,
1379 uint 0,
1380 uint 7 }, section "llvm.metadata"
1381%str1 = internal constant [13 x sbyte] c"unsigned int\00", section "llvm.metadata"
1382</pre>
1383
1384</div>
1385
1386<!-- ======================================================================= -->
1387<div class="doc_subsubsection">
1388 <a name="ccxx_basic_long_long">long long</a>
1389</div>
1390
1391<div class="doc_text">
1392
1393<pre>
1394%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1395 uint 36,
1396 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1397 sbyte* getelementptr ([14 x sbyte]* %str1, int 0, int 0),
1398 { }* null,
1399 int 0,
1400 uint 64,
1401 uint 64,
1402 uint 0,
1403 uint 5 }, section "llvm.metadata"
1404%str1 = internal constant [14 x sbyte] c"long long int\00", section "llvm.metadata"
1405</pre>
1406
1407</div>
1408
1409<!-- ======================================================================= -->
1410<div class="doc_subsubsection">
1411 <a name="ccxx_basic_unsigned_long_long">unsigned long long</a>
1412</div>
1413
1414<div class="doc_text">
1415
1416<pre>
1417%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1418 uint 36,
1419 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1420 sbyte* getelementptr ([23 x sbyte]* %str1, int 0, int 0),
1421 { }* null,
1422 int 0,
1423 uint 64,
1424 uint 64,
1425 uint 0,
1426 uint 7 }, section "llvm.metadata"
1427%str1 = internal constant [23 x sbyte] c"long long unsigned int\00", section "llvm.metadata"
1428</pre>
1429
1430</div>
1431
1432<!-- ======================================================================= -->
1433<div class="doc_subsubsection">
1434 <a name="ccxx_basic_float">float</a>
1435</div>
1436
1437<div class="doc_text">
1438
1439<pre>
1440%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1441 uint 36,
1442 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1443 sbyte* getelementptr ([6 x sbyte]* %str1, int 0, int 0),
1444 { }* null,
1445 int 0,
1446 uint 32,
1447 uint 32,
1448 uint 0,
1449 uint 4 }, section "llvm.metadata"
1450%str1 = internal constant [6 x sbyte] c"float\00", section "llvm.metadata"
1451</pre>
1452
1453</div>
1454
1455<!-- ======================================================================= -->
1456<div class="doc_subsubsection">
1457 <a name="ccxx_basic_double">double</a>
1458</div>
1459
1460<div class="doc_text">
1461
1462<pre>
1463%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1464 uint 36,
1465 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1466 sbyte* getelementptr ([7 x sbyte]* %str1, int 0, int 0),
1467 { }* null,
1468 int 0,
1469 uint 64,
1470 uint 64,
1471 uint 0,
1472 uint 4 }, section "llvm.metadata"
1473%str1 = internal constant [7 x sbyte] c"double\00", section "llvm.metadata"
1474</pre>
1475
1476</div>
1477
1478<!-- ======================================================================= -->
1479<div class="doc_subsection">
1480 <a name="ccxx_derived_types">C/C++ derived types</a>
1481</div>
1482
1483<div class="doc_text">
1484
1485<p>Given the following as an example of C/C++ derived type;</p>
1486
1487<pre>
1488typedef const int *IntPtr;
1489</pre>
1490
1491<p>a C/C++ front-end would generate the following descriptors;</p>
1492
1493<pre>
1494;;
1495;; Define the typedef "IntPtr".
1496;;
1497%<a href="#format_derived_type">llvm.dbg.derivedtype1</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1498 uint 22,
1499 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1500 sbyte* getelementptr ([7 x sbyte]* %str1, int 0, int 0),
1501 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1502 int 1,
1503 uint 0,
1504 uint 0,
1505 uint 0,
1506 { }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> to { }*) }, section "llvm.metadata"
1507%str1 = internal constant [7 x sbyte] c"IntPtr\00", section "llvm.metadata"
1508
1509;;
1510;; Define the pointer type.
1511;;
1512%<a href="#format_derived_type">llvm.dbg.derivedtype2</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1513 uint 15,
1514 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
Jim Laskey4d9b10b2006-03-14 18:50:50 +00001515 sbyte* null,
Jim Laskeycec12a52006-03-14 18:08:46 +00001516 { }* null,
1517 int 0,
1518 uint 32,
1519 uint 32,
1520 uint 0,
1521 { }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> to { }*) }, section "llvm.metadata"
Jim Laskeycec12a52006-03-14 18:08:46 +00001522
1523;;
1524;; Define the const type.
1525;;
1526%<a href="#format_derived_type">llvm.dbg.derivedtype3</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1527 uint 38,
1528 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
Jim Laskey4d9b10b2006-03-14 18:50:50 +00001529 sbyte* null,
Jim Laskeycec12a52006-03-14 18:08:46 +00001530 { }* null,
1531 int 0,
1532 uint 0,
1533 uint 0,
1534 uint 0,
1535 { }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype1</a> to { }*) }, section "llvm.metadata"
1536
1537;;
1538;; Define the int type.
1539;;
1540%<a href="#format_basic_type">llvm.dbg.basictype1</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1541 uint 36,
1542 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
Jim Laskey4d9b10b2006-03-14 18:50:50 +00001543 sbyte* getelementptr ([4 x sbyte]* %str2, int 0, int 0),
Jim Laskeycec12a52006-03-14 18:08:46 +00001544 { }* null,
1545 int 0,
1546 uint 32,
1547 uint 32,
1548 uint 0,
1549 uint 5 }, section "llvm.metadata"
Jim Laskey4d9b10b2006-03-14 18:50:50 +00001550%str2 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
Jim Laskeycec12a52006-03-14 18:08:46 +00001551</pre>
1552
1553</div>
1554
1555<!-- ======================================================================= -->
1556<div class="doc_subsection">
1557 <a name="ccxx_composite_types">C/C++ struct/union types</a>
1558</div>
1559
1560<div class="doc_text">
1561
1562<p>Given the following as an example of C/C++ struct type;</p>
1563
1564<pre>
1565struct Color {
1566 unsigned Red;
1567 unsigned Green;
1568 unsigned Blue;
1569};
1570</pre>
1571
1572<p>a C/C++ front-end would generate the following descriptors;</p>
1573
1574<pre>
1575;;
1576;; Define basic type for unsigned int.
1577;;
1578%<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1579 uint 36,
1580 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1581 sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0),
1582 { }* null,
1583 int 0,
1584 uint 32,
1585 uint 32,
1586 uint 0,
1587 uint 7 }, section "llvm.metadata"
1588%str1 = internal constant [13 x sbyte] c"unsigned int\00", section "llvm.metadata"
1589
1590;;
1591;; Define composite type for struct Color.
1592;;
1593%<a href="#format_composite_type">llvm.dbg.compositetype</a> = internal constant %<a href="#format_composite_type">llvm.dbg.compositetype.type</a> {
1594 uint 19,
1595 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1596 sbyte* getelementptr ([6 x sbyte]* %str2, int 0, int 0),
1597 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1598 int 1,
1599 uint 96,
1600 uint 32,
1601 uint 0,
1602 { }* null,
1603 { }* cast ([3 x { }*]* %llvm.dbg.array to { }*) }, section "llvm.metadata"
1604%str2 = internal constant [6 x sbyte] c"Color\00", section "llvm.metadata"
1605
1606;;
1607;; Define the Red field.
1608;;
1609%<a href="#format_derived_type">llvm.dbg.derivedtype1</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1610 uint 13,
1611 { }* null,
1612 sbyte* getelementptr ([4 x sbyte]* %str3, int 0, int 0),
1613 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1614 int 2,
1615 uint 32,
1616 uint 32,
1617 uint 0,
1618 { }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to { }*) }, section "llvm.metadata"
1619%str3 = internal constant [4 x sbyte] c"Red\00", section "llvm.metadata"
1620
1621;;
1622;; Define the Green field.
1623;;
1624%<a href="#format_derived_type">llvm.dbg.derivedtype2</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1625 uint 13,
1626 { }* null,
1627 sbyte* getelementptr ([6 x sbyte]* %str4, int 0, int 0),
1628 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1629 int 3,
1630 uint 32,
1631 uint 32,
1632 uint 32,
1633 { }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to { }*) }, section "llvm.metadata"
1634%str4 = internal constant [6 x sbyte] c"Green\00", section "llvm.metadata"
1635
1636;;
1637;; Define the Blue field.
1638;;
1639%<a href="#format_derived_type">llvm.dbg.derivedtype3</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1640 uint 13,
1641 { }* null,
1642 sbyte* getelementptr ([5 x sbyte]* %str5, int 0, int 0),
1643 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1644 int 4,
1645 uint 32,
1646 uint 32,
1647 uint 64,
1648 { }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to { }*) }, section "llvm.metadata"
1649%str5 = internal constant [5 x sbyte] c"Blue\00", section "llvm.metadata"
1650
1651;;
1652;; Define the array of fields used by the composite type Color.
1653;;
1654%llvm.dbg.array = internal constant [3 x { }*] [
1655 { }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype1</a> to { }*),
1656 { }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> to { }*),
1657 { }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> to { }*) ], section "llvm.metadata"
1658</pre>
1659
1660</div>
1661
1662<!-- ======================================================================= -->
1663<div class="doc_subsection">
1664 <a name="ccxx_enumeration_types">C/C++ enumeration types</a>
1665</div>
1666
1667<div class="doc_text">
1668
1669<p>Given the following as an example of C/C++ enumeration type;</p>
1670
1671<pre>
1672enum Trees {
1673 Spruce = 100,
1674 Oak = 200,
1675 Maple = 300
1676};
1677</pre>
1678
1679<p>a C/C++ front-end would generate the following descriptors;</p>
1680
1681<pre>
1682;;
1683;; Define composite type for enum Trees
1684;;
1685%<a href="#format_composite_type">llvm.dbg.compositetype</a> = internal constant %<a href="#format_composite_type">llvm.dbg.compositetype.type</a> {
1686 uint 4,
1687 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1688 sbyte* getelementptr ([6 x sbyte]* %str1, int 0, int 0),
1689 { }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to { }*),
1690 int 1,
1691 uint 32,
1692 uint 32,
1693 uint 0,
1694 { }* null,
1695 { }* cast ([3 x { }*]* %llvm.dbg.array to { }*) }, section "llvm.metadata"
1696%str1 = internal constant [6 x sbyte] c"Trees\00", section "llvm.metadata"
1697
1698;;
1699;; Define Spruce enumerator.
1700;;
1701%<a href="#format_enumeration">llvm.dbg.enumerator1</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1702 uint 40,
1703 sbyte* getelementptr ([7 x sbyte]* %str2, int 0, int 0),
1704 int 100 }, section "llvm.metadata"
1705%str2 = internal constant [7 x sbyte] c"Spruce\00", section "llvm.metadata"
1706
1707;;
1708;; Define Oak enumerator.
1709;;
1710%<a href="#format_enumeration">llvm.dbg.enumerator2</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1711 uint 40,
1712 sbyte* getelementptr ([4 x sbyte]* %str3, int 0, int 0),
1713 int 200 }, section "llvm.metadata"
1714%str3 = internal constant [4 x sbyte] c"Oak\00", section "llvm.metadata"
1715
1716;;
1717;; Define Maple enumerator.
1718;;
1719%<a href="#format_enumeration">llvm.dbg.enumerator3</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1720 uint 40,
1721 sbyte* getelementptr ([6 x sbyte]* %str4, int 0, int 0),
1722 int 300 }, section "llvm.metadata"
1723%str4 = internal constant [6 x sbyte] c"Maple\00", section "llvm.metadata"
1724
1725;;
1726;; Define the array of enumerators used by composite type Trees.
1727;;
1728%llvm.dbg.array = internal constant [3 x { }*] [
1729 { }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator1</a> to { }*),
1730 { }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator2</a> to { }*),
1731 { }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator3</a> to { }*) ], section "llvm.metadata"
1732</pre>
1733
1734</div>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001735
1736<!-- *********************************************************************** -->
Misha Brukman82873732004-05-12 19:21:57 +00001737
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001738<hr>
Misha Brukman82873732004-05-12 19:21:57 +00001739<address>
1740 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
1741 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
1742 <a href="http://validator.w3.org/check/referer"><img
1743 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
1744
1745 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00001746 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001747 Last modified: $Date$
Misha Brukman82873732004-05-12 19:21:57 +00001748</address>
Chris Lattnerbdfb3392004-01-05 05:06:33 +00001749
1750</body>
1751</html>