447a659dec03cc362b4562b664f7c5681d2c68bb
[oota-llvm.git] / docs / SourceLevelDebugging.html
1 <!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
12 <table class="layout" style="width:100%">
13   <tr class="layout">
14     <td class="left">
15 <ul>
16   <li><a href="#introduction">Introduction</a>
17   <ol>
18     <li><a href="#phil">Philosophy behind LLVM debugging information</a></li>
19     <li><a href="#consumers">Debug information consumers</a></li>
20     <li><a href="#debugopt">Debugging optimized code</a></li>
21   </ol></li>
22   <li><a href="#format">Debugging information format</a>
23   <ol>
24     <li><a href="#debug_info_descriptors">Debug information descriptors</a>
25     <ul>
26       <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>
30       <li><a href="#format_blocks">Block descriptors</a></li>
31       <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>
36       <li><a href="#format_variables">Local variables</a></li>
37     </ul></li>
38     <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>
48   </ol></li>
49   <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a>
50   <ol>
51     <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>
58   </ol></li>
59 </ul>
60 </td>
61 <td class="right">
62 <img src="img/venusflytrap.jpg" alt="A leafy and green bug eater" width="247"
63 height="369">
64 </td>
65 </tr></table>
66
67 <div class="doc_author">
68   <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
69             and <a href="mailto:jlaskey@apple.com">Jim Laskey</a></p>
70 </div>
71
72
73 <!-- *********************************************************************** -->
74 <div class="doc_section"><a name="introduction">Introduction</a></div> 
75 <!-- *********************************************************************** -->
76
77 <div class="doc_text">
78
79 <p>This document is the central repository for all information pertaining to
80 debug information in LLVM.  It describes the <a href="#format">actual format
81 that the LLVM debug information</a> takes, which is useful for those interested
82 in creating front-ends or dealing directly with the information.  Further, this
83 document provides specifc examples of what debug information for C/C++.</p>
84
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
94 <p>The idea of the LLVM debugging information is to capture how the important
95 pieces of the source-language's Abstract Syntax Tree map onto LLVM code.
96 Several design aspects have shaped the solution that appears here.  The
97 important ones are:</p>
98
99 <ul>
100 <li>Debugging information should have very little impact on the rest of the
101 compiler.  No transformations, analyses, or code generators should need to be
102 modified because of debugging information.</li>
103
104 <li>LLVM optimizations should interact in <a href="#debugopt">well-defined and
105 easily described ways</a> with the debugging information.</li>
106
107 <li>Because LLVM is designed to support arbitrary programming languages,
108 LLVM-to-LLVM tools should not need to know anything about the semantics of the
109 source-level-language.</li>
110
111 <li>Source-level languages are often <b>widely</b> different from one another.
112 LLVM should not put any restrictions of the flavor of the source-language, and
113 the debugging information should work with any language.</li>
114
115 <li>With code generator support, it should be possible to use an LLVM compiler
116 to compile a program to native machine code and standard debugging formats.
117 This allows compatibility with traditional machine-code level debuggers, like
118 GDB or DBX.</li>
119
120 </ul>
121
122 <p>The approach used by the LLVM implementation is to use a small set of <a
123 href="#format_common_intrinsics">intrinsic functions</a> to define a mapping
124 between LLVM program objects and the source-level objects.  The description of
125 the source-level program is maintained in LLVM global variables in an <a
126 href="#ccxx_frontend">implementation-defined format</a> (the C/C++ front-end
127 currently uses working draft 7 of the <a
128 href="http://www.eagercon.com/dwarf/dwarf3std.htm">Dwarf 3 standard</a>).</p>
129
130 <p>When a program is being debugged, a debugger interacts with the user and
131 turns the stored debug information into source-language specific information. 
132 As such, a debugger must be aware of the source-language, and is thus tied to
133 a specific language of family of languages.</p>
134
135 </div>
136
137 <!-- ======================================================================= -->
138 <div class="doc_subsection">
139   <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
144 stripped away during the compilation process.  This meta information provides an
145 llvm user a relationship between generated code and the original program source
146 code.</p>
147
148 <p>Currently, debug information is consumed by the DwarfWriter to produce dwarf
149 information used by the gdb debugger.  Other targets could use the same
150 information to produce stabs or other debug forms.</p>
151
152 <p>It would also be reasonable to use debug information to feed profiling tools
153 for analysis of generated code, or, tools for reconstructing the original source
154 from generated code.</p>
155
156 <p>TODO - expound a bit more.</p>
157
158 </div>
159
160 <!-- ======================================================================= -->
161 <div class="doc_subsection">
162   <a name="debugopt">Debugging optimized code</a>
163 </div>
164
165 <div class="doc_text">
166
167 <p>An extremely high priority of LLVM debugging information is to make it
168 interact well with optimizations and analysis.  In particular, the LLVM debug
169 information provides the following guarantees:</p>
170
171 <ul>
172
173 <li>LLVM debug information <b>always provides information to accurately read the
174 source-level state of the program</b>, regardless of which LLVM optimizations
175 have been run, and without any modification to the optimizations themselves.
176 However, some optimizations may impact the ability to modify the current state
177 of the program with a debugger, such as setting program variables, or calling
178 function that have been deleted.</li>
179
180 <li>LLVM optimizations gracefully interact with debugging information.  If they
181 are not aware of debug information, they are automatically disabled as necessary
182 in the cases that would invalidate the debug info.  This retains the LLVM
183 features making it easy to write new transformations.</li>
184
185 <li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM
186 debugging information, allowing them to update the debugging information as they
187 perform aggressive optimizations.  This means that, with effort, the LLVM
188 optimizers 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
191 happening (for example inlining, basic block reordering/merging/cleanup, tail
192 duplication, etc), further reducing the amount of the compiler that eventually
193 is "aware" of debugging information.</li>
194
195 <li>LLVM debug information is automatically optimized along with the rest of the
196 program, using existing facilities.  For example, duplicate information is
197 automatically merged by the linker, and unused information is automatically
198 removed.</li>
199
200 </ul>
201
202 <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
204 modify the program as it executes from a debugger.  Compiling a program with
205 "<tt>-O3 -g</tt>" gives you full debug information that is always available and
206 accurate for reading (e.g., you get accurate stack traces despite tail call
207 elimination and inlining), but you might lose the ability to modify the program
208 and call functions where were optimized out of the program, or inlined away
209 completely.</p>
210
211 </div>
212
213 <!-- *********************************************************************** -->
214 <div class="doc_section">
215   <a name="format">Debugging information format</a>
216 </div>
217 <!-- *********************************************************************** -->
218
219 <div class="doc_text">
220
221 <p>LLVM debugging information has been carefully designed to make it possible
222 for the optimizer to optimize the program and debugging information without
223 necessarily having to know anything about debugging information.  In particular,
224 the global constant merging pass automatically eliminates duplicated debugging
225 information (often caused by header files), the global dead code elimination
226 pass automatically deletes debugging information for a function if it decides to
227 delete 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,
231 variables, functions, source files, etc) is inserted by the language front-end
232 in the form of LLVM global variables.  These LLVM global variables are no
233 different from any other global variables, except that they have a web of LLVM
234 intrinsic functions that point to them.  If the last references to a particular
235 piece of debugging information are deleted (for example, by the
236 <tt>-globaldce</tt> pass), the extraneous debug information will automatically
237 become dead and be removed by the optimizer.</p>
238
239 <p>Debug information is designed to be agnostic about the target debugger and
240 debugging information representation (e.g. DWARF/Stabs/etc).  It uses a generic
241 machine debug information pass to decode the information that represents
242 variables, types, functions, namespaces, etc: this allows for arbitrary
243 source-language semantics and type-systems to be used, as long as there is a
244 module written for the target debugger to interpret the information. In
245 addition, debug global variables are declared in the <tt>"llvm.metadata"</tt>
246 section.  All values declared in this section are stripped away after target
247 debug information is constructed and before the program object is emitted.</p>
248
249 <p>To provide basic functionality, the LLVM debugger does have to make some
250 assumptions about the source-level language being debugged, though it keeps
251 these to a minimum.  The only common features that the LLVM debugger assumes
252 exist are <a href="#format_compile_units">source files</a>, and <a
253 href="#format_global_variables">program objects</a>.  These abstract objects are
254 used by a debugger to form stack traces, show information about local
255 variables, etc.</p>
256
257 <p>This section of the documentation first describes the representation aspects
258 common to any source-language.  The <a href="#ccxx_frontend">next section</a>
259 describes the data layout conventions used by the C and C++ front-ends.</p>
260
261 </div>
262
263 <!-- ======================================================================= -->
264 <div class="doc_subsection">
265   <a name="debug_info_descriptors">Debug information descriptors</a>
266 </div>
267
268 <div class="doc_text">
269 <p>In consideration of the complexity and volume of debug information, LLVM
270 provides a specification for well formed debug global variables.  The constant
271 value of each of these globals is one of a limited set of structures, known as
272 debug descriptors.</p>
273
274 <p>Consumers of LLVM debug information expect the descriptors for program
275 objects to start in a canonical format, but the descriptors can include
276 additional information appended at the end that is source-language specific. All
277 LLVM debugging information is versioned, allowing backwards compatibility in the
278 case that the core structures need to change in some way.  Also, all debugging
279 information objects start with a tag to indicate what type of object it is.  The
280 source-language is allowed to define its own objects, by using unreserved tag
281 numbers.  We recommend using with tags in the range 0x1000 thru 0x2000 (there is
282 a defined enum DW_TAG_user_base = 0x1000.)</p>
283
284 <p>The fields of debug descriptors used internally by LLVM (MachineDebugInfo)
285 are 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
288 cast to <tt> { }* </tt> expression; typically references to other field
289 descriptors, arrays of descriptors or global variables.</p>
290
291 <pre>
292   %llvm.dbg.object.type = type {
293     uint,   ;; A tag
294     ...
295   }
296 </pre>
297
298 <p>The first field of a descriptor is always an <tt>uint</tt> containing a tag
299 value identifying the content of the descriptor. The remaining fields are
300 specific to the descriptor.  The values of tags are loosely bound to the tag
301 values of Dwarf information entries.  However, that does not restrict the use of
302 the 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
323 LLVM debugger to efficiently index all of the global objects without having the
324 scan the program.  To do this, all of the global objects use "anchor"
325 descriptors with designated names.  All of the global objects of a particular
326 type (e.g., compile units) contain a pointer to the anchor.  This pointer allows
327 a debugger to use def-use chains to find all global objects of that type.</p>
328
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
338 anchors, as opposed to having a list of compile unit descriptors) allows for the
339 standard dead global elimination and merging passes to automatically remove
340 unused debugging information.  If the globals were kept track of through lists,
341 there would always be an object pointing to the descriptors, thus would never be
342 deleted.</p>
343
344 </div>
345
346 <!-- ======================================================================= -->
347 <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 {  }*)
357     uint,   ;; LLVM debug version number = 3
358     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
366 3), a source language ID for the file (we use the Dwarf 3.0 ID numbers, such as
367 <tt>DW_LANG_C89</tt>, <tt>DW_LANG_C_plus_plus</tt>, <tt>DW_LANG_Cobol74</tt>,
368 etc), three strings describing the filename, working directory of the compiler,
369 and 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
372 specific source file.  Global variables and top level functions would be defined
373 using this context.  Compile unit descriptors also provide context for source
374 line 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 {  }*),  
389     {  }*,  ;; Reference to context descriptor
390     sbyte*, ;; Name
391     {  }*,  ;; Reference to compile unit where defined
392     uint,   ;; Line number where defined
393     {  }*,  ;; 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)
396     {  }*   ;; Reference to the global variable
397   }
398 </pre>
399
400 <p>These descriptors provide debug information about globals variables.  The
401 provide 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 {  }*),  
416     {  }*,  ;; Reference to context descriptor
417     sbyte*, ;; Name
418     {  }*,  ;; Reference to compile unit where defined
419     uint,   ;; Line number where defined
420     {  }*,  ;; Reference to type descriptor
421     bool,   ;; True if the global is local to compile unit (static)
422     bool    ;; True if the global is defined in the compile unit (not extern)
423   }
424 </pre>
425
426 <p>These descriptors provide debug information about functions, methods and
427 subprograms.  They provide details such as name, return types and the source
428 location where the subprogram is defined.</p>
429
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)
441     {  }*   ;; Reference to context descriptor
442   }
443 </pre>
444
445 <p>These descriptors provide debug information about nested blocks within a
446 subprogram.  The array of member descriptors is used to define local variables
447 and deeper nested blocks.</p>
448
449 </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)
464     uint,   ;; Line number where defined (may be 0)
465     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
473 and float.  The context provides the scope of the type, which is usually the top
474 level.  Since basic types are not usually user defined the compile unit and line
475 number can be left as NULL and 0.  The size, alignment and offset are expressed
476 in bits and can be 64 bit values.  The alignment is used to round the offset
477 when 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
479 offset if embedded in a <a href="#format_composite_type">composite
480 type</a>.</p>
481
482 <p>The type encoding provides the details of the type.  The values are typically
483 one 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)
510     uint,   ;; Line number where defined (may be 0)
511     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
519 value of the tag varies depending on the meaning.  The following are possible
520 tag values;</p>
521
522 <pre>
523   DW_TAG_formal_parameter = 5
524   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
534 href="#format_composite_type">composite type</a> or <a
535 href="#format_subprograms">subprogram</a>.  The type of the member is the <a
536 href="#format_derived_type">derived type</a>. <tt>DW_TAG_formal_parameter</tt>
537 is used to define a member which is a formal argument of a subprogram.</p>
538
539 <p><tt>DW_TAG_typedef</tt> is used to
540 provide 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
545 qualify 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
548 from the compile unit and line number.  The size, alignment and offset are
549 expressed in bits and can be 64 bit values.  The alignment is used to round the
550 offset 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
552 offset if embedded in a <a href="#format_composite_type">composite
553 type</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
557 NULL 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)
574     uint,   ;; Line number where defined (may be 0)
575     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
583 elements.  The value of the tag varies depending on the meaning.  The following
584 are 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
594 href="#format_subrange">subrange descriptors</a>, each representing the range of
595 subscripts 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
599 definition of enumeration value
600 for 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
604 href="#format_basic_type">basic</a>, <a href="#format_derived_type">derived</a>
605 or <a href="#format_composite_type">composite</a> type descriptors, each
606 representing a field member of the structure or union.</p>
607
608 <p><a href="#format_composite_type">Composite type</a> location can be
609 determined from the compile unit and line number.  The size, alignment and
610 offset are expressed in bits and can be 64 bit values.  The alignment is used to
611 round the offset when embedded in a <a href="#format_composite_type">composite
612 type</a> (as an example, to keep float doubles on 64 bit boundaries.) The offset
613 is the bit offset if embedded in a <a href="#format_composite_type">composite
614 type</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
635 lower bounds typically zero for C/C++.  The high value is the upper bounds. 
636 Values are 64 bit.  High - low + 1 is the size of the array.  If
637 low == 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
657 href="#format_composite_type">composite type</a>, it associates the name to the
658 value.</p>
659
660 </div>
661
662 <!-- ======================================================================= -->
663 <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
680 value 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
689 argument variable is any variable that appears as a formal argument to the
690 function.  A return variable is used to track the result of a function and has
691 no source correspondent.</p>
692
693 <p>The context is either the subprogram or block where the variable is defined.
694 Name the source variable name.  Compile unit and line indicate where the
695 variable was defined. Type descriptor defines the declared type of the
696 variable.</p>
697
698 </div>
699
700 <!-- ======================================================================= -->
701 <div class="doc_subsection">
702   <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
708 provide 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>
719   void %<a href="#format_common_stoppoint">llvm.dbg.stoppoint</a>( uint, uint, { }* )
720 </pre>
721
722 <p>This intrinsic is used to provide correspondence between the source file and
723 the generated code.  The first argument is the line number (base 1), second
724 argument si the column number (0 if unknown) and the third argument the source
725 <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
727 in close proximity of the line, column and file.  This information holds until
728 the next call to <tt>%<a
729 href="#format_common_stoppoint">lvm.dbg.stoppoint</a></tt>.</p>
730
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>
740   void %<a href="#format_common_func_start">llvm.dbg.func.start</a>( { }* )
741 </pre>
742
743 <p>This intrinsic is used to link the debug information in <tt>%<a
744 href="#format_subprograms">llvm.dbg.subprogram</a></tt> to the function. It also
745 defines the beginning of the function's declarative region (scope.)  The
746 intrinsic should be called early in the function after the all the alloca
747 instructions.  It should be paired off with a closing <tt>%<a
748 href="#format_common_region_end">llvm.dbg.region.end</a></tt>.  The function's
749 single argument is the <tt>%<a
750 href="#format_subprograms">llvm.dbg.subprogram.type</a></tt>.</p>
751
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>
761   void %<a href="#format_common_region_start">llvm.dbg.region.start</a>( { }* )
762 </pre>
763
764 <p>This intrinsic is used to define the beginning of a declarative scope (ex.
765 block) for local language elements.  It should be paired off with a closing
766 <tt>%<a href="#format_common_region_end">llvm.dbg.region.end</a></tt>.  The
767 function's single argument is the <tt>%<a
768 href="#format_blocks">llvm.dbg.block</a></tt> which is starting.</p>
769
770
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>
780   void %<a href="#format_common_region_end">llvm.dbg.region.end</a>( { }* )
781 </pre>
782
783 <p>This intrinsic is used to define the end of a declarative scope (ex. block)
784 for local language elements.  It should be paired off with an opening <tt>%<a
785 href="#format_common_region_start">llvm.dbg.region.start</a></tt> or <tt>%<a
786 href="#format_common_func_start">llvm.dbg.func.start</a></tt>.  The function's
787 single argument is either the <tt>%<a
788 href="#format_blocks">llvm.dbg.block</a></tt> or the <tt>%<a
789 href="#format_subprograms">llvm.dbg.subprogram.type</a></tt> which is
790 ending.</p>
791
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>
801   void %<a href="#format_common_declare">llvm.dbg.declare</a>( { } *, { }* )
802 </pre>
803
804 <p>This intrinsic provides information about a local element (ex. variable.) The
805 first argument is the alloca for the variable, cast to a <tt>{ }*</tt>. The
806 second argument is the <tt>%<a
807 href="#format_variables">llvm.dbg.variable</a></tt> containing the description
808 of the variable, also cast to a <tt>{ }*</tt>.</p>
809
810 </div>
811
812 <!-- ======================================================================= -->
813 <div class="doc_subsection">
814   <a name="format_common_stoppoints">
815      Representing stopping points in the source program
816   </a>
817 </div>
818
819 <div class="doc_text">
820
821 <p>LLVM debugger "stop points" are a key part of the debugging representation
822 that allows the LLVM to maintain simple semantics for <a
823 href="#debugopt">debugging optimized code</a>.  The basic idea is that the
824 front-end inserts calls to the <a
825 href="#format_common_stoppoint">%<tt>llvm.dbg.stoppoint</tt></a> intrinsic
826 function at every point in the program where a debugger should be able to
827 inspect the program (these correspond to places a debugger stops when you
828 "<tt>step</tt>" through it).  The front-end can choose to place these as
829 fine-grained as it would like (for example, before every subexpression
830 evaluated), but it is recommended to only put them after every source statement
831 that includes executable code.</p>
832
833 <p>Using calls to this intrinsic function to demark legal points for the
834 debugger to inspect the program automatically disables any optimizations that
835 could potentially confuse debugging information.  To non-debug-information-aware
836 transformations, these calls simply look like calls to an external function,
837 which they must assume to do anything (including reading or writing to any part
838 of reachable memory).  On the other hand, it does not impact many optimizations,
839 such as code motion of non-trapping instructions, nor does it impact
840 optimization of subexpressions, code duplication transformations, or basic-block
841 reordering transformations.</p>
842
843 </div>
844
845
846 <!-- ======================================================================= -->
847 <div class="doc_subsection">
848   <a name="format_common_lifetime">Object lifetimes and scoping</a>
849 </div>
850
851 <div class="doc_text">
852 <p>In many languages, the local variables in functions can have their lifetime
853 or scope limited to a subset of a function.  In the C family of languages, for
854 example, variables are only live (readable and writable) within the source block
855 that they are defined in.  In functional languages, values are only readable
856 after they have been defined.  Though this is a very obvious concept, it is also
857 non-trivial to model in LLVM, because it has no notion of scoping in this sense,
858 and does not want to be tied to a language's scoping rules.</p>
859
860 <p>In order to handle this, the LLVM debug format uses the notion of "regions"
861 of a function, delineated by calls to intrinsic functions.  These intrinsic
862 functions define new regions of the program and indicate when the region
863 lifetime expires.  Consider the following C fragment, for example:</p>
864
865 <pre>
866 1.  void foo() {
867 2.    int X = ...;
868 3.    int Y = ...;
869 4.    {
870 5.      int Z = ...;
871 6.      ...
872 7.    }
873 8.    ...
874 9.  }
875 </pre>
876
877 <p>Compiled to LLVM, this function would be represented like this:</p>
878
879 <pre>
880 void %foo() {
881 entry:
882     %X = alloca int
883     %Y = alloca int
884     %Z = alloca int
885     
886     ...
887     
888     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 )
889     
890     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 )
891     
892     call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %X, ...)
893     call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %Y, ...)
894     
895     <i>;; Evaluate expression on line 2, assigning to X.</i>
896     
897     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 )
898     
899     <i>;; Evaluate expression on line 3, assigning to Y.</i>
900     
901     call void %<a href="#format_common_stoppoint">llvm.region.start</a>()
902     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 )
903     call void %<a href="#format_common_declare">llvm.dbg.declare</a>({}* %X, ...)
904     
905     <i>;; Evaluate expression on line 5, assigning to Z.</i>
906     
907     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 )
908     call void %<a href="#format_common_region_end">llvm.region.end</a>()
909     
910     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 )
911     
912     call void %<a href="#format_common_region_end">llvm.region.end</a>()
913     
914     ret void
915 }
916 </pre>
917
918 <p>This example illustrates a few important details about the LLVM debugging
919 information.  In particular, it shows how the various intrinsics are applied
920 together to allow a debugger to analyze the relationship between statements,
921 variable definitions, and the code used to implement the function.</p>
922
923 <p>The first intrinsic <tt>%<a
924 href="#format_common_func_start">llvm.dbg.func.start</a></tt> provides
925 a link with the <a href="#format_subprograms">subprogram descriptor</a>
926 containing the details of this function.  This call also defines the beginning
927 of the function region, bounded by the <tt>%<a
928 href="#format_common_region_end">llvm.region.end</a></tt> at the end of
929 the function.  This region is used to bracket the lifetime of variables declared
930 within.  For a function, this outer region defines a new stack frame whose
931 lifetime ends when the region is ended.</p>
932
933 <p>It is possible to define inner regions for short term variables by using the
934 %<a href="#format_common_stoppoint"><tt>llvm.region.start</tt></a> and <a
935 href="#format_common_region_end"><tt>%llvm.region.end</tt></a> to bound a
936 region.  The inner region in this example would be for the block containing the
937 declaration of Z.</p>
938
939 <p>Using regions to represent the boundaries of source-level functions allow
940 LLVM interprocedural optimizations to arbitrarily modify LLVM functions without
941 having to worry about breaking mapping information between the LLVM code and the
942 and source-level program.  In particular, the inliner requires no modification
943 to support inlining with debugging information: there is no explicit correlation
944 drawn between LLVM functions and their source-level counterparts (note however,
945 that if the inliner inlines all instances of a non-strong-linkage function into
946 its caller that it will not be possible for the user to manually invoke the
947 inlined function from a debugger).</p>
948
949 <p>Once the function has been defined, the <a
950 href="#format_common_stoppoint"><tt>stopping point</tt></a> corresponding to
951 line #2 (column #2) of the function is encountered.  At this point in the
952 function, <b>no</b> local variables are live.  As lines 2 and 3 of the example
953 are executed, their variable definitions are introduced into the program using
954 %<a href="#format_common_declare"><tt>llvm.dbg.declare</tt></a>, without the
955 need to specify a new region.  These variables do not require new regions to be
956 introduced because they go out of scope at the same point in the program: line
957 9.</p>
958
959 <p>In contrast, the <tt>Z</tt> variable goes out of scope at a different time,
960 on line 7.  For this reason, it is defined within the inner region, which kills
961 the availability of <tt>Z</tt> before the code for line 8 is executed.  In this
962 way, regions can support arbitrary source-language scoping rules, as long as
963 they can only be nested (ie, one scope cannot partially overlap with a part of
964 another scope).</p>
965
966 <p>It is worth noting that this scoping mechanism is used to control scoping of
967 all declarations, not just variable declarations.  For example, the scope of a
968 C++ using declaration is controlled with this couldchange how name lookup is
969 performed.</p>
970
971 </div>
972
973
974
975 <!-- *********************************************************************** -->
976 <div class="doc_section">
977   <a name="ccxx_frontend">C/C++ front-end specific debug information</a>
978 </div>
979 <!-- *********************************************************************** -->
980
981 <div class="doc_text">
982
983 <p>The C and C++ front-ends represent information about the program in a format
984 that is effectively identical to <a
985 href="http://www.eagercon.com/dwarf/dwarf3std.htm">Dwarf 3.0</a> in terms of
986 information content.  This allows code generators to trivially support native
987 debuggers by generating standard dwarf information, and contains enough
988 information for non-dwarf targets to translate it as needed.</p>
989
990 <p>This section describes the forms used to represent C and C++ programs. Other
991 languages could pattern themselves after this (which itself is tuned to
992 representing programs in the same way that Dwarf 3 does), or they could choose
993 to provide completely different forms if they don't fit into the Dwarf model. 
994 As support for debugging information gets added to the various LLVM
995 source-language front-ends, the information used should be documented here.</p>
996
997 <p>The following sections provide examples of various C/C++ constructs and the
998 debug information that would best describe those constructs.</p>
999
1000 </div>
1001
1002 <!-- ======================================================================= -->
1003 <div class="doc_subsection">
1004   <a name="ccxx_compile_units">C/C++ source file information</a>
1005 </div>
1006
1007 <div class="doc_text">
1008
1009 <p>Given the source files "MySource.cpp" and "MyHeader.h" located in the
1010 directory "/Users/mine/sources", the following code;</p>
1011
1012 <pre>
1013 #include "MyHeader.h"
1014
1015 int main(int argc, char *argv[]) {
1016   return 0;
1017 }
1018 </pre>
1019
1020 <p>a C/C++ front-end would generate the following descriptors;</p>
1021
1022 <pre>
1023 ...
1024 ;;
1025 ;; Define types used.  In this case we need one for compile unit anchors and one
1026 ;; for compile units.
1027 ;;
1028 %<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
1029 %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = type { uint, {  }*, uint, uint, sbyte*, sbyte*, sbyte* }
1030 ...
1031 ;;
1032 ;; Define the anchor for compile units.  Note that the second field of the
1033 ;; anchor is 17, which is the same as the tag for compile units
1034 ;; (17 = DW_TAG_compile_unit.)
1035 ;;
1036 %<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"
1037
1038 ;;
1039 ;; Define the compile unit for the source file "/Users/mine/sources/MySource.cpp".
1040 ;;
1041 %<a href="#format_compile_units">llvm.dbg.compile_unit1</a> = internal constant %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> {
1042     uint 17, 
1043     {  }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_units</a> to {  }*), 
1044     uint 1, 
1045     uint 1, 
1046     sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0), 
1047     sbyte* getelementptr ([21 x sbyte]* %str2, int 0, int 0), 
1048     sbyte* getelementptr ([33 x sbyte]* %str3, int 0, int 0) }, section "llvm.metadata"
1049     
1050 ;;
1051 ;; Define the compile unit for the header file "/Users/mine/sources/MyHeader.h".
1052 ;;
1053 %<a href="#format_compile_units">llvm.dbg.compile_unit2</a> = internal constant %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> {
1054     uint 17, 
1055     {  }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_units</a> to {  }*), 
1056     uint 1, 
1057     uint 1, 
1058     sbyte* getelementptr ([11 x sbyte]* %str4, int 0, int 0), 
1059     sbyte* getelementptr ([21 x sbyte]* %str2, int 0, int 0), 
1060     sbyte* getelementptr ([33 x sbyte]* %str3, int 0, int 0) }, section "llvm.metadata"
1061
1062 ;;
1063 ;; Define each of the strings used in the compile units.
1064 ;;
1065 %str1 = internal constant [13 x sbyte] c"MySource.cpp\00", section "llvm.metadata";
1066 %str2 = internal constant [21 x sbyte] c"/Users/mine/sources/\00", section "llvm.metadata";
1067 %str3 = internal constant [33 x sbyte] c"4.0.1 LLVM (LLVM research group)\00", section "llvm.metadata";
1068 %str4 = internal constant [11 x sbyte] c"MyHeader.h\00", section "llvm.metadata";
1069 ...
1070 </pre>
1071
1072 </div>
1073
1074 <!-- ======================================================================= -->
1075 <div class="doc_subsection">
1076   <a name="ccxx_global_variable">C/C++ global variable information</a>
1077 </div>
1078
1079 <div class="doc_text">
1080
1081 <p>Given an integer global variable declared as follows;</p>
1082
1083 <pre>
1084 int MyGlobal = 100;
1085 </pre>
1086
1087 <p>a C/C++ front-end would generate the following descriptors;</p>
1088
1089 <pre>
1090 ;;
1091 ;; Define types used. One for global variable anchors, one for the global
1092 ;; variable descriptor, one for the global's basic type and one for the global's
1093 ;; compile unit.
1094 ;;
1095 %<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
1096 %<a href="#format_global_variables">llvm.dbg.global_variable.type</a> = type { uint, {  }*, {  }*, sbyte*, {  }*, uint, {  }*, bool, bool, {  }*, uint }
1097 %<a href="#format_basic_type">llvm.dbg.basictype.type</a> = type { uint, {  }*, sbyte*, {  }*, int, uint, uint, uint, uint }
1098 %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = ...
1099 ...
1100 ;;
1101 ;; Define the global itself.
1102 ;;
1103 %MyGlobal = global int 100
1104 ...
1105 ;;
1106 ;; Define the anchor for global variables.  Note that the second field of the
1107 ;; anchor is 52, which is the same as the tag for global variables
1108 ;; (52 = DW_TAG_variable.)
1109 ;;
1110 %<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"
1111
1112 ;;
1113 ;; Define the global variable descriptor.  Note the reference to the global
1114 ;; variable anchor and the global variable itself.
1115 ;;
1116 %<a href="#format_global_variables">llvm.dbg.global_variable</a> = internal constant %<a href="#format_global_variables">llvm.dbg.global_variable.type</a> {
1117     uint 52, 
1118     {  }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_global_variables">llvm.dbg.global_variables</a> to {  }*), 
1119     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1120     sbyte* getelementptr ([9 x sbyte]* %str1, int 0, int 0), 
1121     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1122     uint 1,
1123     {  }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to {  }*), 
1124     bool false, 
1125     bool true, 
1126     {  }* cast (int* %MyGlobal to {  }*) }, section "llvm.metadata"
1127     
1128 ;;
1129 ;; Define the basic type of 32 bit signed integer.  Note that since int is an
1130 ;; intrinsic type the source file is NULL and line 0.
1131 ;;    
1132 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1133     uint 36, 
1134     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1135     sbyte* getelementptr ([4 x sbyte]* %str2, int 0, int 0), 
1136     {  }* null, 
1137     int 0, 
1138     uint 32, 
1139     uint 32, 
1140     uint 0, 
1141     uint 5 }, section "llvm.metadata"
1142
1143 ;;
1144 ;; Define the names of the global variable and basic type.
1145 ;;
1146 %str1 = internal constant [9 x sbyte] c"MyGlobal\00", section "llvm.metadata"
1147 %str2 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
1148 </pre>
1149
1150 </div>
1151
1152 <!-- ======================================================================= -->
1153 <div class="doc_subsection">
1154   <a name="ccxx_subprogram">C/C++ function information</a>
1155 </div>
1156
1157 <div class="doc_text">
1158
1159 <p>Given a function declared as follows;</p>
1160
1161 <pre>
1162 int main(int argc, char *argv[]) {
1163   return 0;
1164 }
1165 </pre>
1166
1167 <p>a C/C++ front-end would generate the following descriptors;</p>
1168
1169 <pre>
1170 ;;
1171 ;; Define types used. One for subprogram anchors, one for the subprogram
1172 ;; descriptor, one for the global's basic type and one for the subprogram's
1173 ;; compile unit.
1174 ;;
1175 %<a href="#format_subprograms">llvm.dbg.subprogram.type</a> = type { uint, {  }*, {  }*, sbyte*, {  }*, bool, bool }
1176 %<a href="#format_anchors">llvm.dbg.anchor.type</a> = type { uint, uint }
1177 %<a href="#format_compile_units">llvm.dbg.compile_unit.type</a> = ...
1178         
1179 ;;
1180 ;; Define the anchor for subprograms.  Note that the second field of the
1181 ;; anchor is 46, which is the same as the tag for subprograms
1182 ;; (46 = DW_TAG_subprogram.)
1183 ;;
1184 %<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"
1185
1186 ;;
1187 ;; Define the descriptor for the subprogram.  TODO - more details.
1188 ;;
1189 %<a href="#format_subprograms">llvm.dbg.subprogram</a> = internal constant %<a href="#format_subprograms">llvm.dbg.subprogram.type</a> {
1190     uint 46, 
1191     {  }* cast (%<a href="#format_anchors">llvm.dbg.anchor.type</a>* %<a href="#format_subprograms">llvm.dbg.subprograms</a> to {  }*), 
1192     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1193     sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0), 
1194     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*),
1195     uint 1,
1196     {  }* null, 
1197     bool false, 
1198     bool true }, section "llvm.metadata"
1199
1200 ;;
1201 ;; Define the name of the subprogram.
1202 ;;
1203 %str1 = internal constant [5 x sbyte] c"main\00", section "llvm.metadata"
1204
1205 ;;
1206 ;; Define the subprogram itself.
1207 ;;
1208 int %main(int %argc, sbyte** %argv) {
1209 ...
1210 }
1211 </pre>
1212
1213 </div>
1214
1215 <!-- ======================================================================= -->
1216 <div class="doc_subsection">
1217   <a name="ccxx_basic_types">C/C++ basic types</a>
1218 </div>
1219
1220 <div class="doc_text">
1221
1222 <p>The following are the basic type descriptors for C/C++ core types;</p>
1223
1224 </div>
1225
1226 <!-- ======================================================================= -->
1227 <div class="doc_subsubsection">
1228   <a name="ccxx_basic_type_bool">bool</a>
1229 </div>
1230
1231 <div class="doc_text">
1232
1233 <pre>
1234 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1235     uint 36, 
1236     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1237     sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0), 
1238     {  }* null, 
1239     int 0, 
1240     uint 32, 
1241     uint 32, 
1242     uint 0, 
1243     uint 2 }, section "llvm.metadata"
1244 %str1 = internal constant [5 x sbyte] c"bool\00", section "llvm.metadata"
1245 </pre>
1246
1247 </div>
1248
1249 <!-- ======================================================================= -->
1250 <div class="doc_subsubsection">
1251   <a name="ccxx_basic_char">char</a>
1252 </div>
1253
1254 <div class="doc_text">
1255
1256 <pre>
1257 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1258     uint 36, 
1259     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1260     sbyte* getelementptr ([5 x sbyte]* %str1, int 0, int 0), 
1261     {  }* null, 
1262     int 0, 
1263     uint 8, 
1264     uint 8, 
1265     uint 0, 
1266     uint 6 }, section "llvm.metadata"
1267 %str1 = internal constant [5 x sbyte] c"char\00", section "llvm.metadata"
1268 </pre>
1269
1270 </div>
1271
1272 <!-- ======================================================================= -->
1273 <div class="doc_subsubsection">
1274   <a name="ccxx_basic_unsigned_char">unsigned char</a>
1275 </div>
1276
1277 <div class="doc_text">
1278
1279 <pre>
1280 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1281     uint 36, 
1282     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1283     sbyte* getelementptr ([14 x sbyte]* %str1, int 0, int 0), 
1284     {  }* null, 
1285     int 0, 
1286     uint 8, 
1287     uint 8, 
1288     uint 0, 
1289     uint 8 }, section "llvm.metadata"
1290 %str1 = internal constant [14 x sbyte] c"unsigned char\00", section "llvm.metadata"
1291 </pre>
1292
1293 </div>
1294
1295 <!-- ======================================================================= -->
1296 <div class="doc_subsubsection">
1297   <a name="ccxx_basic_short">short</a>
1298 </div>
1299
1300 <div class="doc_text">
1301
1302 <pre>
1303 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1304     uint 36, 
1305     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1306     sbyte* getelementptr ([10 x sbyte]* %str1, int 0, int 0), 
1307     {  }* null, 
1308     int 0, 
1309     uint 16, 
1310     uint 16, 
1311     uint 0, 
1312     uint 5 }, section "llvm.metadata"
1313 %str1 = internal constant [10 x sbyte] c"short int\00", section "llvm.metadata"
1314 </pre>
1315
1316 </div>
1317
1318 <!-- ======================================================================= -->
1319 <div class="doc_subsubsection">
1320   <a name="ccxx_basic_unsigned_short">unsigned short</a>
1321 </div>
1322
1323 <div class="doc_text">
1324
1325 <pre>
1326 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1327     uint 36, 
1328     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1329     sbyte* getelementptr ([19 x sbyte]* %str1, int 0, int 0), 
1330     {  }* null, 
1331     int 0, 
1332     uint 16, 
1333     uint 16, 
1334     uint 0, 
1335     uint 7 }, section "llvm.metadata"
1336 %str1 = internal constant [19 x sbyte] c"short unsigned int\00", section "llvm.metadata"
1337 </pre>
1338
1339 </div>
1340
1341 <!-- ======================================================================= -->
1342 <div class="doc_subsubsection">
1343   <a name="ccxx_basic_int">int</a>
1344 </div>
1345
1346 <div class="doc_text">
1347
1348 <pre>
1349 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1350     uint 36, 
1351     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1352     sbyte* getelementptr ([4 x sbyte]* %str1, int 0, int 0), 
1353     {  }* null, 
1354     int 0, 
1355     uint 32, 
1356     uint 32, 
1357     uint 0, 
1358     uint 5 }, section "llvm.metadata"
1359 %str1 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
1360 </pre>
1361
1362 </div>
1363
1364 <!-- ======================================================================= -->
1365 <div class="doc_subsubsection">
1366   <a name="ccxx_basic_unsigned_int">unsigned int</a>
1367 </div>
1368
1369 <div class="doc_text">
1370
1371 <pre>
1372 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1373     uint 36, 
1374     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1375     sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0), 
1376     {  }* null, 
1377     int 0, 
1378     uint 32, 
1379     uint 32, 
1380     uint 0, 
1381     uint 7 }, section "llvm.metadata"
1382 %str1 = internal constant [13 x sbyte] c"unsigned int\00", section "llvm.metadata"
1383 </pre>
1384
1385 </div>
1386
1387 <!-- ======================================================================= -->
1388 <div class="doc_subsubsection">
1389   <a name="ccxx_basic_long_long">long long</a>
1390 </div>
1391
1392 <div class="doc_text">
1393
1394 <pre>
1395 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1396     uint 36, 
1397     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1398     sbyte* getelementptr ([14 x sbyte]* %str1, int 0, int 0), 
1399     {  }* null, 
1400     int 0, 
1401     uint 64, 
1402     uint 64, 
1403     uint 0, 
1404     uint 5 }, section "llvm.metadata"
1405 %str1 = internal constant [14 x sbyte] c"long long int\00", section "llvm.metadata"
1406 </pre>
1407
1408 </div>
1409
1410 <!-- ======================================================================= -->
1411 <div class="doc_subsubsection">
1412   <a name="ccxx_basic_unsigned_long_long">unsigned long long</a>
1413 </div>
1414
1415 <div class="doc_text">
1416
1417 <pre>
1418 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1419     uint 36, 
1420     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1421     sbyte* getelementptr ([23 x sbyte]* %str1, int 0, int 0), 
1422     {  }* null, 
1423     int 0, 
1424     uint 64, 
1425     uint 64, 
1426     uint 0, 
1427     uint 7 }, section "llvm.metadata"
1428 %str1 = internal constant [23 x sbyte] c"long long unsigned int\00", section "llvm.metadata"
1429 </pre>
1430
1431 </div>
1432
1433 <!-- ======================================================================= -->
1434 <div class="doc_subsubsection">
1435   <a name="ccxx_basic_float">float</a>
1436 </div>
1437
1438 <div class="doc_text">
1439
1440 <pre>
1441 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1442     uint 36, 
1443     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1444     sbyte* getelementptr ([6 x sbyte]* %str1, int 0, int 0), 
1445     {  }* null, 
1446     int 0, 
1447     uint 32, 
1448     uint 32, 
1449     uint 0, 
1450     uint 4 }, section "llvm.metadata"
1451 %str1 = internal constant [6 x sbyte] c"float\00", section "llvm.metadata"
1452 </pre>
1453
1454 </div>
1455
1456 <!-- ======================================================================= -->
1457 <div class="doc_subsubsection">
1458   <a name="ccxx_basic_double">double</a>
1459 </div>
1460
1461 <div class="doc_text">
1462
1463 <pre>
1464 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1465     uint 36, 
1466     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1467     sbyte* getelementptr ([7 x sbyte]* %str1, int 0, int 0), 
1468     {  }* null, 
1469     int 0, 
1470     uint 64, 
1471     uint 64, 
1472     uint 0, 
1473     uint 4 }, section "llvm.metadata"
1474 %str1 = internal constant [7 x sbyte] c"double\00", section "llvm.metadata"
1475 </pre>
1476
1477 </div>
1478
1479 <!-- ======================================================================= -->
1480 <div class="doc_subsection">
1481   <a name="ccxx_derived_types">C/C++ derived types</a>
1482 </div>
1483
1484 <div class="doc_text">
1485
1486 <p>Given the following as an example of C/C++ derived type;</p>
1487
1488 <pre>
1489 typedef const int *IntPtr;
1490 </pre>
1491
1492 <p>a C/C++ front-end would generate the following descriptors;</p>
1493
1494 <pre>
1495 ;;
1496 ;; Define the typedef "IntPtr".
1497 ;;
1498 %<a href="#format_derived_type">llvm.dbg.derivedtype1</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1499     uint 22, 
1500     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1501     sbyte* getelementptr ([7 x sbyte]* %str1, int 0, int 0), 
1502     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1503     int 1, 
1504     uint 0, 
1505     uint 0, 
1506     uint 0, 
1507     {  }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> to {  }*) }, section "llvm.metadata"
1508 %str1 = internal constant [7 x sbyte] c"IntPtr\00", section "llvm.metadata"
1509
1510 ;;
1511 ;; Define the pointer type.
1512 ;;
1513 %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1514     uint 15, 
1515     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1516     sbyte* null, 
1517     {  }* null, 
1518     int 0, 
1519     uint 32, 
1520     uint 32, 
1521     uint 0, 
1522     {  }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> to {  }*) }, section "llvm.metadata"
1523
1524 ;;
1525 ;; Define the const type.
1526 ;;
1527 %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1528     uint 38, 
1529     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1530     sbyte* null, 
1531     {  }* null, 
1532     int 0, 
1533     uint 0, 
1534     uint 0, 
1535     uint 0, 
1536     {  }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype1</a> to {  }*) }, section "llvm.metadata"   
1537
1538 ;;
1539 ;; Define the int type.
1540 ;;
1541 %<a href="#format_basic_type">llvm.dbg.basictype1</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1542     uint 36, 
1543     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1544     sbyte* getelementptr ([4 x sbyte]* %str2, int 0, int 0), 
1545     {  }* null, 
1546     int 0, 
1547     uint 32, 
1548     uint 32, 
1549     uint 0, 
1550     uint 5 }, section "llvm.metadata"
1551 %str2 = internal constant [4 x sbyte] c"int\00", section "llvm.metadata"
1552 </pre>
1553
1554 </div>
1555
1556 <!-- ======================================================================= -->
1557 <div class="doc_subsection">
1558   <a name="ccxx_composite_types">C/C++ struct/union types</a>
1559 </div>
1560
1561 <div class="doc_text">
1562
1563 <p>Given the following as an example of C/C++ struct type;</p>
1564
1565 <pre>
1566 struct Color {
1567   unsigned Red;
1568   unsigned Green;
1569   unsigned Blue;
1570 };
1571 </pre>
1572
1573 <p>a C/C++ front-end would generate the following descriptors;</p>
1574
1575 <pre>
1576 ;;
1577 ;; Define basic type for unsigned int.
1578 ;;
1579 %<a href="#format_basic_type">llvm.dbg.basictype</a> = internal constant %<a href="#format_basic_type">llvm.dbg.basictype.type</a> {
1580     uint 36, 
1581     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1582     sbyte* getelementptr ([13 x sbyte]* %str1, int 0, int 0), 
1583     {  }* null, 
1584     int 0, 
1585     uint 32, 
1586     uint 32, 
1587     uint 0, 
1588     uint 7 }, section "llvm.metadata"
1589 %str1 = internal constant [13 x sbyte] c"unsigned int\00", section "llvm.metadata"
1590
1591 ;;
1592 ;; Define composite type for struct Color.
1593 ;;
1594 %<a href="#format_composite_type">llvm.dbg.compositetype</a> = internal constant %<a href="#format_composite_type">llvm.dbg.compositetype.type</a> {
1595     uint 19, 
1596     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1597     sbyte* getelementptr ([6 x sbyte]* %str2, int 0, int 0), 
1598     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1599     int 1, 
1600     uint 96, 
1601     uint 32, 
1602     uint 0, 
1603     {  }* null, 
1604     {  }* cast ([3 x {  }*]* %llvm.dbg.array to {  }*) }, section "llvm.metadata"
1605 %str2 = internal constant [6 x sbyte] c"Color\00", section "llvm.metadata"
1606
1607 ;;
1608 ;; Define the Red field.
1609 ;;
1610 %<a href="#format_derived_type">llvm.dbg.derivedtype1</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1611     uint 13, 
1612     {  }* null, 
1613     sbyte* getelementptr ([4 x sbyte]* %str3, int 0, int 0), 
1614     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1615     int 2, 
1616     uint 32, 
1617     uint 32, 
1618     uint 0, 
1619     {  }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to {  }*) }, section "llvm.metadata"
1620 %str3 = internal constant [4 x sbyte] c"Red\00", section "llvm.metadata"
1621
1622 ;;
1623 ;; Define the Green field.
1624 ;;
1625 %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1626     uint 13, 
1627     {  }* null, 
1628     sbyte* getelementptr ([6 x sbyte]* %str4, int 0, int 0), 
1629     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1630     int 3, 
1631     uint 32, 
1632     uint 32, 
1633     uint 32, 
1634     {  }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to {  }*) }, section "llvm.metadata"
1635 %str4 = internal constant [6 x sbyte] c"Green\00", section "llvm.metadata"
1636
1637 ;;
1638 ;; Define the Blue field.
1639 ;;
1640 %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> = internal constant %<a href="#format_derived_type">llvm.dbg.derivedtype.type</a> {
1641     uint 13, 
1642     {  }* null, 
1643     sbyte* getelementptr ([5 x sbyte]* %str5, int 0, int 0), 
1644     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1645     int 4, 
1646     uint 32, 
1647     uint 32, 
1648     uint 64, 
1649     {  }* cast (%<a href="#format_basic_type">llvm.dbg.basictype.type</a>* %<a href="#format_basic_type">llvm.dbg.basictype</a> to {  }*) }, section "llvm.metadata"
1650 %str5 = internal constant [5 x sbyte] c"Blue\00", section "llvm.metadata"
1651
1652 ;;
1653 ;; Define the array of fields used by the composite type Color.
1654 ;;
1655 %llvm.dbg.array = internal constant [3 x {  }*] [
1656       {  }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype1</a> to {  }*),
1657       {  }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype2</a> to {  }*),
1658       {  }* cast (%<a href="#format_derived_type">llvm.dbg.derivedtype.type</a>* %<a href="#format_derived_type">llvm.dbg.derivedtype3</a> to {  }*) ], section "llvm.metadata"
1659 </pre>
1660
1661 </div>
1662
1663 <!-- ======================================================================= -->
1664 <div class="doc_subsection">
1665   <a name="ccxx_enumeration_types">C/C++ enumeration types</a>
1666 </div>
1667
1668 <div class="doc_text">
1669
1670 <p>Given the following as an example of C/C++ enumeration type;</p>
1671
1672 <pre>
1673 enum Trees {
1674   Spruce = 100,
1675   Oak = 200,
1676   Maple = 300
1677 };
1678 </pre>
1679
1680 <p>a C/C++ front-end would generate the following descriptors;</p>
1681
1682 <pre>
1683 ;;
1684 ;; Define composite type for enum Trees
1685 ;;
1686 %<a href="#format_composite_type">llvm.dbg.compositetype</a> = internal constant %<a href="#format_composite_type">llvm.dbg.compositetype.type</a> {
1687     uint 4, 
1688     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1689     sbyte* getelementptr ([6 x sbyte]* %str1, int 0, int 0), 
1690     {  }* cast (%<a href="#format_compile_units">llvm.dbg.compile_unit.type</a>* %<a href="#format_compile_units">llvm.dbg.compile_unit</a> to {  }*), 
1691     int 1, 
1692     uint 32, 
1693     uint 32, 
1694     uint 0, 
1695     {  }* null, 
1696     {  }* cast ([3 x {  }*]* %llvm.dbg.array to {  }*) }, section "llvm.metadata"
1697 %str1 = internal constant [6 x sbyte] c"Trees\00", section "llvm.metadata"
1698
1699 ;;
1700 ;; Define Spruce enumerator.
1701 ;;
1702 %<a href="#format_enumeration">llvm.dbg.enumerator1</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1703     uint 40, 
1704     sbyte* getelementptr ([7 x sbyte]* %str2, int 0, int 0), 
1705     int 100 }, section "llvm.metadata"
1706 %str2 = internal constant [7 x sbyte] c"Spruce\00", section "llvm.metadata"
1707
1708 ;;
1709 ;; Define Oak enumerator.
1710 ;;
1711 %<a href="#format_enumeration">llvm.dbg.enumerator2</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1712     uint 40, 
1713     sbyte* getelementptr ([4 x sbyte]* %str3, int 0, int 0), 
1714     int 200 }, section "llvm.metadata"
1715 %str3 = internal constant [4 x sbyte] c"Oak\00", section "llvm.metadata"
1716
1717 ;;
1718 ;; Define Maple enumerator.
1719 ;;
1720 %<a href="#format_enumeration">llvm.dbg.enumerator3</a> = internal constant %<a href="#format_enumeration">llvm.dbg.enumerator.type</a> {
1721     uint 40, 
1722     sbyte* getelementptr ([6 x sbyte]* %str4, int 0, int 0), 
1723     int 300 }, section "llvm.metadata"
1724 %str4 = internal constant [6 x sbyte] c"Maple\00", section "llvm.metadata"
1725
1726 ;;
1727 ;; Define the array of enumerators used by composite type Trees.
1728 ;;
1729 %llvm.dbg.array = internal constant [3 x {  }*] [
1730   {  }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator1</a> to {  }*),
1731   {  }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator2</a> to {  }*),
1732   {  }* cast (%<a href="#format_enumeration">llvm.dbg.enumerator.type</a>* %<a href="#format_enumeration">llvm.dbg.enumerator3</a> to {  }*) ], section "llvm.metadata"
1733 </pre>
1734
1735 </div>
1736
1737 <!-- *********************************************************************** -->
1738
1739 <hr>
1740 <address>
1741   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
1742   src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
1743   <a href="http://validator.w3.org/check/referer"><img
1744   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
1745
1746   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
1747   <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
1748   Last modified: $Date$
1749 </address>
1750
1751 </body>
1752 </html>