Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 6 | <title>Source Level Debugging with LLVM</title> |
Daniel Dunbar | adea497 | 2012-04-19 20:20:34 +0000 | [diff] [blame] | 7 | <link rel="stylesheet" href="_static/llvm.css" type="text/css"> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 8 | </head> |
| 9 | <body> |
| 10 | |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 11 | <h1>Source Level Debugging with LLVM</h1> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 12 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 13 | <table class="layout" style="width:100%"> |
| 14 | <tr class="layout"> |
| 15 | <td class="left"> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 16 | <ul> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 17 | <li><a href="#introduction">Introduction</a> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 18 | <ol> |
| 19 | <li><a href="#phil">Philosophy behind LLVM debugging information</a></li> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 20 | <li><a href="#consumers">Debug information consumers</a></li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 21 | <li><a href="#debugopt">Debugging optimized code</a></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 22 | </ol></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 23 | <li><a href="#format">Debugging information format</a> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 24 | <ol> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 25 | <li><a href="#debug_info_descriptors">Debug information descriptors</a> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 26 | <ul> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 27 | <li><a href="#format_compile_units">Compile unit descriptors</a></li> |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 28 | <li><a href="#format_files">File descriptors</a></li> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 29 | <li><a href="#format_global_variables">Global variable descriptors</a></li> |
| 30 | <li><a href="#format_subprograms">Subprogram descriptors</a></li> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 31 | <li><a href="#format_blocks">Block descriptors</a></li> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 32 | <li><a href="#format_basic_type">Basic type descriptors</a></li> |
| 33 | <li><a href="#format_derived_type">Derived type descriptors</a></li> |
| 34 | <li><a href="#format_composite_type">Composite type descriptors</a></li> |
| 35 | <li><a href="#format_subrange">Subrange descriptors</a></li> |
| 36 | <li><a href="#format_enumeration">Enumerator descriptors</a></li> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 37 | <li><a href="#format_variables">Local variables</a></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 38 | </ul></li> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 39 | <li><a href="#format_common_intrinsics">Debugger intrinsic functions</a> |
| 40 | <ul> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 41 | <li><a href="#format_common_declare">llvm.dbg.declare</a></li> |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 42 | <li><a href="#format_common_value">llvm.dbg.value</a></li> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 43 | </ul></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 44 | </ol></li> |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 45 | <li><a href="#format_common_lifetime">Object lifetimes and scoping</a></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 46 | <li><a href="#ccxx_frontend">C/C++ front-end specific debug information</a> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 47 | <ol> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 48 | <li><a href="#ccxx_compile_units">C/C++ source file information</a></li> |
| 49 | <li><a href="#ccxx_global_variable">C/C++ global variable information</a></li> |
| 50 | <li><a href="#ccxx_subprogram">C/C++ function information</a></li> |
| 51 | <li><a href="#ccxx_basic_types">C/C++ basic types</a></li> |
| 52 | <li><a href="#ccxx_derived_types">C/C++ derived types</a></li> |
| 53 | <li><a href="#ccxx_composite_types">C/C++ struct/union types</a></li> |
| 54 | <li><a href="#ccxx_enumeration_types">C/C++ enumeration types</a></li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 55 | </ol></li> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 56 | <li><a href="#llvmdwarfextension">LLVM Dwarf Extensions</a> |
| 57 | <ol> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 58 | <li><a href="#objcproperty">Debugging Information Extension |
Bill Wendling | 0eb5914 | 2012-03-06 09:17:39 +0000 | [diff] [blame] | 59 | for Objective C Properties</a> |
| 60 | <ul> |
| 61 | <li><a href="#objcpropertyintroduction">Introduction</a></li> |
| 62 | <li><a href="#objcpropertyproposal">Proposal</a></li> |
| 63 | <li><a href="#objcpropertynewattributes">New DWARF Attributes</a></li> |
| 64 | <li><a href="#objcpropertynewconstants">New DWARF Constants</a></li> |
| 65 | </ul> |
| 66 | </li> |
| 67 | <li><a href="#acceltable">Name Accelerator Tables</a> |
| 68 | <ul> |
| 69 | <li><a href="#acceltableintroduction">Introduction</a></li> |
| 70 | <li><a href="#acceltablehashes">Hash Tables</a></li> |
| 71 | <li><a href="#acceltabledetails">Details</a></li> |
| 72 | <li><a href="#acceltablecontents">Contents</a></li> |
| 73 | <li><a href="#acceltableextensions">Language Extensions and File Format Changes</a></li> |
| 74 | </ul> |
| 75 | </li> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 76 | </ol> |
| 77 | </li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 78 | </ul> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 79 | </td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 80 | </tr></table> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 81 | |
Chris Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 82 | <div class="doc_author"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 83 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
Jim Laskey | c760a92 | 2007-03-14 19:32:21 +0000 | [diff] [blame] | 84 | and <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p> |
Chris Lattner | 7911ce2 | 2004-05-23 21:07:27 +0000 | [diff] [blame] | 85 | </div> |
| 86 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 87 | |
| 88 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 89 | <h2><a name="introduction">Introduction</a></h2> |
Misha Brukman | 94218a7 | 2004-12-09 20:27:37 +0000 | [diff] [blame] | 90 | <!-- *********************************************************************** --> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 91 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 92 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 93 | |
| 94 | <p>This document is the central repository for all information pertaining to |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 95 | debug information in LLVM. It describes the <a href="#format">actual format |
| 96 | that the LLVM debug information</a> takes, which is useful for those |
| 97 | interested in creating front-ends or dealing directly with the information. |
Chris Lattner | 8ad2f98 | 2009-07-18 21:47:15 +0000 | [diff] [blame] | 98 | Further, this document provides specific examples of what debug information |
Chris Lattner | 8994075 | 2011-01-18 06:12:10 +0000 | [diff] [blame] | 99 | for C/C++ looks like.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 100 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 101 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 102 | <h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 103 | <a name="phil">Philosophy behind LLVM debugging information</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 104 | </h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 105 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 106 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 107 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 108 | <p>The idea of the LLVM debugging information is to capture how the important |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 109 | pieces of the source-language's Abstract Syntax Tree map onto LLVM code. |
| 110 | Several design aspects have shaped the solution that appears here. The |
| 111 | important ones are:</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 112 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 113 | <ul> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 114 | <li>Debugging information should have very little impact on the rest of the |
| 115 | compiler. No transformations, analyses, or code generators should need to |
| 116 | be modified because of debugging information.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 117 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 118 | <li>LLVM optimizations should interact in <a href="#debugopt">well-defined and |
| 119 | easily described ways</a> with the debugging information.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 120 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 121 | <li>Because LLVM is designed to support arbitrary programming languages, |
| 122 | LLVM-to-LLVM tools should not need to know anything about the semantics of |
| 123 | the source-level-language.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 124 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 125 | <li>Source-level languages are often <b>widely</b> different from one another. |
| 126 | LLVM should not put any restrictions of the flavor of the source-language, |
| 127 | and the debugging information should work with any language.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 128 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 129 | <li>With code generator support, it should be possible to use an LLVM compiler |
| 130 | to compile a program to native machine code and standard debugging |
| 131 | formats. This allows compatibility with traditional machine-code level |
| 132 | debuggers, like GDB or DBX.</li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 133 | </ul> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 134 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 135 | <p>The approach used by the LLVM implementation is to use a small set |
| 136 | of <a href="#format_common_intrinsics">intrinsic functions</a> to define a |
| 137 | mapping between LLVM program objects and the source-level objects. The |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 138 | description of the source-level program is maintained in LLVM metadata |
| 139 | in an <a href="#ccxx_frontend">implementation-defined format</a> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 140 | (the C/C++ front-end currently uses working draft 7 of |
| 141 | the <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3 |
| 142 | standard</a>).</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 143 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 144 | <p>When a program is being debugged, a debugger interacts with the user and |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 145 | turns the stored debug information into source-language specific information. |
| 146 | As such, a debugger must be aware of the source-language, and is thus tied to |
| 147 | a specific language or family of languages.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 148 | |
| 149 | </div> |
| 150 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 151 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 152 | <h3> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 153 | <a name="consumers">Debug information consumers</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 154 | </h3> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 155 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 156 | <div> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 157 | |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 158 | <p>The role of debug information is to provide meta information normally |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 159 | stripped away during the compilation process. This meta information provides |
| 160 | an LLVM user a relationship between generated code and the original program |
| 161 | source code.</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 162 | |
Chris Lattner | c310778 | 2010-04-05 04:11:11 +0000 | [diff] [blame] | 163 | <p>Currently, debug information is consumed by DwarfDebug to produce dwarf |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 164 | information used by the gdb debugger. Other targets could use the same |
| 165 | information to produce stabs or other debug forms.</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 166 | |
| 167 | <p>It would also be reasonable to use debug information to feed profiling tools |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 168 | for analysis of generated code, or, tools for reconstructing the original |
| 169 | source from generated code.</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 170 | |
| 171 | <p>TODO - expound a bit more.</p> |
| 172 | |
| 173 | </div> |
| 174 | |
| 175 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 176 | <h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 177 | <a name="debugopt">Debugging optimized code</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 178 | </h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 179 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 180 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 181 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 182 | <p>An extremely high priority of LLVM debugging information is to make it |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 183 | interact well with optimizations and analysis. In particular, the LLVM debug |
| 184 | information provides the following guarantees:</p> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 185 | |
| 186 | <ul> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 187 | <li>LLVM debug information <b>always provides information to accurately read |
| 188 | the source-level state of the program</b>, regardless of which LLVM |
| 189 | optimizations have been run, and without any modification to the |
| 190 | optimizations themselves. However, some optimizations may impact the |
| 191 | ability to modify the current state of the program with a debugger, such |
| 192 | as setting program variables, or calling functions that have been |
| 193 | deleted.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 194 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 195 | <li>As desired, LLVM optimizations can be upgraded to be aware of the LLVM |
| 196 | debugging information, allowing them to update the debugging information |
| 197 | as they perform aggressive optimizations. This means that, with effort, |
| 198 | the LLVM optimizers could optimize debug code just as well as non-debug |
| 199 | code.</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 200 | |
Devang Patel | e0bdc59 | 2011-05-31 17:45:27 +0000 | [diff] [blame] | 201 | <li>LLVM debug information does not prevent optimizations from |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 202 | happening (for example inlining, basic block reordering/merging/cleanup, |
Devang Patel | f729e91 | 2011-05-31 18:06:14 +0000 | [diff] [blame] | 203 | tail duplication, etc).</li> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 204 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 205 | <li>LLVM debug information is automatically optimized along with the rest of |
| 206 | the program, using existing facilities. For example, duplicate |
| 207 | information is automatically merged by the linker, and unused information |
| 208 | is automatically removed.</li> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 209 | </ul> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 210 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 211 | <p>Basically, the debug information allows you to compile a program with |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 212 | "<tt>-O0 -g</tt>" and get full debug information, allowing you to arbitrarily |
| 213 | modify the program as it executes from a debugger. Compiling a program with |
| 214 | "<tt>-O3 -g</tt>" gives you full debug information that is always available |
| 215 | and accurate for reading (e.g., you get accurate stack traces despite tail |
| 216 | call elimination and inlining), but you might lose the ability to modify the |
| 217 | program and call functions where were optimized out of the program, or |
| 218 | inlined away completely.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 219 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 220 | <p><a href="TestingGuide.html#quicktestsuite">LLVM test suite</a> provides a |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 221 | framework to test optimizer's handling of debugging information. It can be |
| 222 | run like this:</p> |
Devang Patel | a5c05aa | 2008-11-21 19:35:57 +0000 | [diff] [blame] | 223 | |
| 224 | <div class="doc_code"> |
| 225 | <pre> |
| 226 | % cd llvm/projects/test-suite/MultiSource/Benchmarks # or some other level |
| 227 | % make TEST=dbgopt |
| 228 | </pre> |
| 229 | </div> |
| 230 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 231 | <p>This will test impact of debugging information on optimization passes. If |
| 232 | debugging information influences optimization passes then it will be reported |
| 233 | as a failure. See <a href="TestingGuide.html">TestingGuide</a> for more |
| 234 | information on LLVM test infrastructure and how to run various tests.</p> |
Devang Patel | a5c05aa | 2008-11-21 19:35:57 +0000 | [diff] [blame] | 235 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 236 | </div> |
| 237 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 238 | </div> |
| 239 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 240 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 241 | <h2> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 242 | <a name="format">Debugging information format</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 243 | </h2> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 244 | <!-- *********************************************************************** --> |
| 245 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 246 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 247 | |
| 248 | <p>LLVM debugging information has been carefully designed to make it possible |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 249 | for the optimizer to optimize the program and debugging information without |
| 250 | necessarily having to know anything about debugging information. In |
John Criswell | b34500f | 2010-03-17 15:01:50 +0000 | [diff] [blame] | 251 | particular, the use of metadata avoids duplicated debugging information from |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 252 | the beginning, and the global dead code elimination pass automatically |
| 253 | deletes debugging information for a function if it decides to delete the |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 254 | function. </p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 255 | |
| 256 | <p>To do this, most of the debugging information (descriptors for types, |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 257 | variables, functions, source files, etc) is inserted by the language |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 258 | front-end in the form of LLVM metadata. </p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 259 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 260 | <p>Debug information is designed to be agnostic about the target debugger and |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 261 | debugging information representation (e.g. DWARF/Stabs/etc). It uses a |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 262 | generic pass to decode the information that represents variables, types, |
| 263 | functions, namespaces, etc: this allows for arbitrary source-language |
| 264 | semantics and type-systems to be used, as long as there is a module |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 265 | written for the target debugger to interpret the information. </p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 266 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 267 | <p>To provide basic functionality, the LLVM debugger does have to make some |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 268 | assumptions about the source-level language being debugged, though it keeps |
| 269 | these to a minimum. The only common features that the LLVM debugger assumes |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 270 | exist are <a href="#format_files">source files</a>, |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 271 | and <a href="#format_global_variables">program objects</a>. These abstract |
| 272 | objects are used by a debugger to form stack traces, show information about |
| 273 | local variables, etc.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 274 | |
| 275 | <p>This section of the documentation first describes the representation aspects |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 276 | common to any source-language. The <a href="#ccxx_frontend">next section</a> |
| 277 | describes the data layout conventions used by the C and C++ front-ends.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 278 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 279 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 280 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 281 | <a name="debug_info_descriptors">Debug information descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 282 | </h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 283 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 284 | <div> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 285 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 286 | <p>In consideration of the complexity and volume of debug information, LLVM |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 287 | provides a specification for well formed debug descriptors. </p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 288 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 289 | <p>Consumers of LLVM debug information expect the descriptors for program |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 290 | objects to start in a canonical format, but the descriptors can include |
| 291 | additional information appended at the end that is source-language |
| 292 | specific. All LLVM debugging information is versioned, allowing backwards |
| 293 | compatibility in the case that the core structures need to change in some |
| 294 | way. Also, all debugging information objects start with a tag to indicate |
| 295 | what type of object it is. The source-language is allowed to define its own |
| 296 | objects, by using unreserved tag numbers. We recommend using with tags in |
Benjamin Kramer | 8040cd3 | 2009-10-12 14:46:08 +0000 | [diff] [blame] | 297 | the range 0x1000 through 0x2000 (there is a defined enum DW_TAG_user_base = |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 298 | 0x1000.)</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 299 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 300 | <p>The fields of debug descriptors used internally by LLVM |
Nick Lewycky | 655fd03 | 2010-03-31 07:50:17 +0000 | [diff] [blame] | 301 | are restricted to only the simple data types <tt>i32</tt>, <tt>i1</tt>, |
| 302 | <tt>float</tt>, <tt>double</tt>, <tt>mdstring</tt> and <tt>mdnode</tt>. </p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 303 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 304 | <div class="doc_code"> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 305 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 306 | !1 = metadata !{ |
Nick Lewycky | 655fd03 | 2010-03-31 07:50:17 +0000 | [diff] [blame] | 307 | i32, ;; A tag |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 308 | ... |
| 309 | } |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 310 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 311 | </div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 312 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 313 | <p><a name="LLVMDebugVersion">The first field of a descriptor is always an |
Nick Lewycky | 655fd03 | 2010-03-31 07:50:17 +0000 | [diff] [blame] | 314 | <tt>i32</tt> containing a tag value identifying the content of the |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 315 | descriptor. The remaining fields are specific to the descriptor. The values |
| 316 | of tags are loosely bound to the tag values of DWARF information entries. |
| 317 | However, that does not restrict the use of the information supplied to DWARF |
| 318 | targets. To facilitate versioning of debug information, the tag is augmented |
Nick Lewycky | f3379da | 2011-07-25 21:13:23 +0000 | [diff] [blame] | 319 | with the current debug version (LLVMDebugVersion = 8 << 16 or |
| 320 | 0x80000 or 524288.)</a></p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 321 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 322 | <p>The details of the various descriptors follow.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 323 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 324 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 325 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 326 | <a name="format_compile_units">Compile unit descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 327 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 328 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 329 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 330 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 331 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 332 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 333 | !0 = metadata !{ |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 334 | i32, ;; Tag = 17 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 335 | ;; (DW_TAG_compile_unit) |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 336 | i32, ;; Unused field. |
| 337 | i32, ;; DWARF language identifier (ex. DW_LANG_C89) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 338 | metadata, ;; Source file name |
| 339 | metadata, ;; Source file directory (includes trailing slash) |
| 340 | metadata ;; Producer (ex. "4.0.1 LLVM (LLVM research group)") |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 341 | i1, ;; True if this is a main compile unit. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 342 | i1, ;; True if this is optimized. |
| 343 | metadata, ;; Flags |
| 344 | i32 ;; Runtime version |
Devang Patel | 9b4a2ac | 2011-09-09 17:07:15 +0000 | [diff] [blame] | 345 | metadata ;; List of enums types |
| 346 | metadata ;; List of retained types |
| 347 | metadata ;; List of subprograms |
| 348 | metadata ;; List of global variables |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 349 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 350 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 351 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 352 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 353 | <p>These descriptors contain a source language ID for the file (we use the DWARF |
| 354 | 3.0 ID numbers, such as <tt>DW_LANG_C89</tt>, <tt>DW_LANG_C_plus_plus</tt>, |
| 355 | <tt>DW_LANG_Cobol74</tt>, etc), three strings describing the filename, |
| 356 | working directory of the compiler, and an identifier string for the compiler |
| 357 | that produced it.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 358 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 359 | <p>Compile unit descriptors provide the root context for objects declared in a |
Devang Patel | 464f4ef | 2011-05-03 16:18:28 +0000 | [diff] [blame] | 360 | specific compilation unit. File descriptors are defined using this context. |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 361 | These descriptors are collected by a named metadata |
Devang Patel | 9b4a2ac | 2011-09-09 17:07:15 +0000 | [diff] [blame] | 362 | <tt>!llvm.dbg.cu</tt>. Compile unit descriptor keeps track of subprograms, |
| 363 | global variables and type information. |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 364 | |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 365 | </div> |
| 366 | |
| 367 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 368 | <h4> |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 369 | <a name="format_files">File descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 370 | </h4> |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 371 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 372 | <div> |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 373 | |
| 374 | <div class="doc_code"> |
| 375 | <pre> |
| 376 | !0 = metadata !{ |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 377 | i32, ;; Tag = 41 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 378 | ;; (DW_TAG_file_type) |
| 379 | metadata, ;; Source file name |
| 380 | metadata, ;; Source file directory (includes trailing slash) |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 381 | metadata ;; Unused |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 382 | } |
| 383 | </pre> |
| 384 | </div> |
| 385 | |
John Criswell | b34500f | 2010-03-17 15:01:50 +0000 | [diff] [blame] | 386 | <p>These descriptors contain information for a file. Global variables and top |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 387 | level functions would be defined using this context.k File descriptors also |
| 388 | provide context for source line correspondence. </p> |
| 389 | |
| 390 | <p>Each input file is encoded as a separate file descriptor in LLVM debugging |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 391 | information output. </p> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 392 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 393 | </div> |
| 394 | |
| 395 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 396 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 397 | <a name="format_global_variables">Global variable descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 398 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 399 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 400 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 401 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 402 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 403 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 404 | !1 = metadata !{ |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 405 | i32, ;; Tag = 52 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 406 | ;; (DW_TAG_variable) |
| 407 | i32, ;; Unused field. |
| 408 | metadata, ;; Reference to context descriptor |
| 409 | metadata, ;; Name |
| 410 | metadata, ;; Display name (fully qualified C++ name) |
| 411 | metadata, ;; MIPS linkage name (for C++) |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 412 | metadata, ;; Reference to file where defined |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 413 | i32, ;; Line number where defined |
| 414 | metadata, ;; Reference to type descriptor |
| 415 | i1, ;; True if the global is local to compile unit (static) |
| 416 | i1, ;; True if the global is defined in the compile unit (not extern) |
Dan Gohman | fe47aae | 2010-05-28 17:13:49 +0000 | [diff] [blame] | 417 | {}* ;; Reference to the global variable |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 418 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 419 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 420 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 421 | |
| 422 | <p>These descriptors provide debug information about globals variables. The |
Devang Patel | da6eed3 | 2011-03-29 17:27:08 +0000 | [diff] [blame] | 423 | provide details such as name, type and where the variable is defined. All |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 424 | global variables are collected inside the named metadata |
| 425 | <tt>!llvm.dbg.cu</tt>.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 426 | |
| 427 | </div> |
| 428 | |
| 429 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 430 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 431 | <a name="format_subprograms">Subprogram descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 432 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 433 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 434 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 435 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 436 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 437 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 438 | !2 = metadata !{ |
| 439 | i32, ;; Tag = 46 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
| 440 | ;; (DW_TAG_subprogram) |
| 441 | i32, ;; Unused field. |
| 442 | metadata, ;; Reference to context descriptor |
| 443 | metadata, ;; Name |
| 444 | metadata, ;; Display name (fully qualified C++ name) |
| 445 | metadata, ;; MIPS linkage name (for C++) |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 446 | metadata, ;; Reference to file where defined |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 447 | i32, ;; Line number where defined |
| 448 | metadata, ;; Reference to type descriptor |
| 449 | i1, ;; True if the global is local to compile unit (static) |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 450 | i1, ;; True if the global is defined in the compile unit (not extern) |
Eric Christopher | 6126a1e | 2012-04-03 00:43:49 +0000 | [diff] [blame] | 451 | i32, ;; Line number where the scope of the subprogram begins |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 452 | i32, ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual |
| 453 | i32, ;; Index into a virtual function |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 454 | metadata, ;; indicates which base type contains the vtable pointer for the |
Devang Patel | 80ecc15 | 2010-06-04 22:49:55 +0000 | [diff] [blame] | 455 | ;; derived class |
Devang Patel | 473f95f | 2011-12-16 17:50:04 +0000 | [diff] [blame] | 456 | i32, ;; Flags - Artifical, Private, Protected, Explicit, Prototyped. |
Devang Patel | 5e06bb8 | 2011-04-22 23:10:17 +0000 | [diff] [blame] | 457 | i1, ;; isOptimized |
| 458 | Function *,;; Pointer to LLVM function |
| 459 | metadata, ;; Lists function template parameters |
| 460 | metadata ;; Function declaration descriptor |
Devang Patel | 93d39be | 2011-08-19 23:28:12 +0000 | [diff] [blame] | 461 | metadata ;; List of function variables |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 462 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 463 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 464 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 465 | |
| 466 | <p>These descriptors provide debug information about functions, methods and |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 467 | subprograms. They provide details such as name, return types and the source |
Devang Patel | da6eed3 | 2011-03-29 17:27:08 +0000 | [diff] [blame] | 468 | location where the subprogram is defined. |
Devang Patel | da6eed3 | 2011-03-29 17:27:08 +0000 | [diff] [blame] | 469 | </p> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 470 | |
| 471 | </div> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 472 | |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 473 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 474 | <h4> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 475 | <a name="format_blocks">Block descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 476 | </h4> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 477 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 478 | <div> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 479 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 480 | <div class="doc_code"> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 481 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 482 | !3 = metadata !{ |
Devang Patel | c79dda2 | 2010-10-04 16:51:59 +0000 | [diff] [blame] | 483 | i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block) |
Devang Patel | 7f271fc | 2010-10-01 22:45:00 +0000 | [diff] [blame] | 484 | metadata,;; Reference to context descriptor |
| 485 | i32, ;; Line number |
Devang Patel | 90d81f1 | 2011-03-08 16:25:29 +0000 | [diff] [blame] | 486 | i32, ;; Column number |
| 487 | metadata,;; Reference to source file |
| 488 | i32 ;; Unique ID to identify blocks from a template function |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 489 | } |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 490 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 491 | </div> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 492 | |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 493 | <p>This descriptor provides debug information about nested blocks within a |
Devang Patel | 7f271fc | 2010-10-01 22:45:00 +0000 | [diff] [blame] | 494 | subprogram. The line number and column numbers are used to dinstinguish |
| 495 | two lexical blocks at same depth. </p> |
Jim Laskey | 3d11bee | 2006-03-15 19:10:52 +0000 | [diff] [blame] | 496 | |
Eric Christopher | 6618a24 | 2011-10-11 22:59:11 +0000 | [diff] [blame] | 497 | <div class="doc_code"> |
| 498 | <pre> |
| 499 | !3 = metadata !{ |
| 500 | i32, ;; Tag = 11 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_lexical_block) |
| 501 | metadata ;; Reference to the scope we're annotating with a file change |
| 502 | metadata,;; Reference to the file the scope is enclosed in. |
| 503 | } |
| 504 | </pre> |
| 505 | </div> |
| 506 | |
| 507 | <p>This descriptor provides a wrapper around a lexical scope to handle file |
| 508 | changes in the middle of a lexical block.</p> |
| 509 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 510 | </div> |
| 511 | |
| 512 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 513 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 514 | <a name="format_basic_type">Basic type descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 515 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 516 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 517 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 518 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 519 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 520 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 521 | !4 = metadata !{ |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 522 | i32, ;; Tag = 36 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 523 | ;; (DW_TAG_base_type) |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 524 | metadata, ;; Reference to context |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 525 | metadata, ;; Name (may be "" for anonymous types) |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 526 | metadata, ;; Reference to file where defined (may be NULL) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 527 | i32, ;; Line number where defined (may be 0) |
| 528 | i64, ;; Size in bits |
| 529 | i64, ;; Alignment in bits |
| 530 | i64, ;; Offset in bits |
| 531 | i32, ;; Flags |
| 532 | i32 ;; DWARF type encoding |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 533 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 534 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 535 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 536 | |
| 537 | <p>These descriptors define primitive types used in the code. Example int, bool |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 538 | and float. The context provides the scope of the type, which is usually the |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 539 | top level. Since basic types are not usually user defined the context |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 540 | and line number can be left as NULL and 0. The size, alignment and offset |
| 541 | are expressed in bits and can be 64 bit values. The alignment is used to |
| 542 | round the offset when embedded in a |
| 543 | <a href="#format_composite_type">composite type</a> (example to keep float |
| 544 | doubles on 64 bit boundaries.) The offset is the bit offset if embedded in |
| 545 | a <a href="#format_composite_type">composite type</a>.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 546 | |
| 547 | <p>The type encoding provides the details of the type. The values are typically |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 548 | one of the following:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 549 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 550 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 551 | <pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 552 | DW_ATE_address = 1 |
| 553 | DW_ATE_boolean = 2 |
| 554 | DW_ATE_float = 4 |
| 555 | DW_ATE_signed = 5 |
| 556 | DW_ATE_signed_char = 6 |
| 557 | DW_ATE_unsigned = 7 |
| 558 | DW_ATE_unsigned_char = 8 |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 559 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 560 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 561 | |
| 562 | </div> |
| 563 | |
| 564 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 565 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 566 | <a name="format_derived_type">Derived type descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 567 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 568 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 569 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 570 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 571 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 572 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 573 | !5 = metadata !{ |
| 574 | i32, ;; Tag (see below) |
| 575 | metadata, ;; Reference to context |
| 576 | metadata, ;; Name (may be "" for anonymous types) |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 577 | metadata, ;; Reference to file where defined (may be NULL) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 578 | i32, ;; Line number where defined (may be 0) |
Devang Patel | 0ffd10b | 2010-10-01 19:19:30 +0000 | [diff] [blame] | 579 | i64, ;; Size in bits |
| 580 | i64, ;; Alignment in bits |
| 581 | i64, ;; Offset in bits |
Eric Christopher | 402e12a | 2011-12-16 23:42:33 +0000 | [diff] [blame] | 582 | i32, ;; Flags to encode attributes, e.g. private |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 583 | metadata, ;; Reference to type derived from |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 584 | metadata, ;; (optional) Name of the Objective C property associated with |
| 585 | ;; Objective-C an ivar |
Devang Patel | e9db5e2 | 2011-04-16 00:11:51 +0000 | [diff] [blame] | 586 | metadata, ;; (optional) Name of the Objective C property getter selector. |
| 587 | metadata, ;; (optional) Name of the Objective C property setter selector. |
| 588 | i32 ;; (optional) Objective C property attributes. |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 589 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 590 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 591 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 592 | |
| 593 | <p>These descriptors are used to define types derived from other types. The |
| 594 | value of the tag varies depending on the meaning. The following are possible |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 595 | tag values:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 596 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 597 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 598 | <pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 599 | DW_TAG_formal_parameter = 5 |
| 600 | DW_TAG_member = 13 |
| 601 | DW_TAG_pointer_type = 15 |
| 602 | DW_TAG_reference_type = 16 |
| 603 | DW_TAG_typedef = 22 |
| 604 | DW_TAG_const_type = 38 |
| 605 | DW_TAG_volatile_type = 53 |
| 606 | DW_TAG_restrict_type = 55 |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 607 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 608 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 609 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 610 | <p><tt>DW_TAG_member</tt> is used to define a member of |
| 611 | a <a href="#format_composite_type">composite type</a> |
| 612 | or <a href="#format_subprograms">subprogram</a>. The type of the member is |
| 613 | the <a href="#format_derived_type">derived |
| 614 | type</a>. <tt>DW_TAG_formal_parameter</tt> is used to define a member which |
| 615 | is a formal argument of a subprogram.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 616 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 617 | <p><tt>DW_TAG_typedef</tt> is used to provide a name for the derived type.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 618 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 619 | <p><tt>DW_TAG_pointer_type</tt>, <tt>DW_TAG_reference_type</tt>, |
| 620 | <tt>DW_TAG_const_type</tt>, <tt>DW_TAG_volatile_type</tt> and |
Eric Christopher | adfc1ef | 2011-12-16 23:42:35 +0000 | [diff] [blame] | 621 | <tt>DW_TAG_restrict_type</tt> are used to qualify |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 622 | the <a href="#format_derived_type">derived type</a>. </p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 623 | |
| 624 | <p><a href="#format_derived_type">Derived type</a> location can be determined |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 625 | from the context and line number. The size, alignment and offset are |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 626 | expressed in bits and can be 64 bit values. The alignment is used to round |
| 627 | the offset when embedded in a <a href="#format_composite_type">composite |
| 628 | type</a> (example to keep float doubles on 64 bit boundaries.) The offset is |
| 629 | the bit offset if embedded in a <a href="#format_composite_type">composite |
| 630 | type</a>.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 631 | |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 632 | <p>Note that the <tt>void *</tt> type is expressed as a type derived from NULL. |
| 633 | </p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 634 | |
| 635 | </div> |
| 636 | |
| 637 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 638 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 639 | <a name="format_composite_type">Composite type descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 640 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 641 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 642 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 643 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 644 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 645 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 646 | !6 = metadata !{ |
| 647 | i32, ;; Tag (see below) |
| 648 | metadata, ;; Reference to context |
| 649 | metadata, ;; Name (may be "" for anonymous types) |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 650 | metadata, ;; Reference to file where defined (may be NULL) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 651 | i32, ;; Line number where defined (may be 0) |
| 652 | i64, ;; Size in bits |
| 653 | i64, ;; Alignment in bits |
| 654 | i64, ;; Offset in bits |
| 655 | i32, ;; Flags |
| 656 | metadata, ;; Reference to type derived from |
| 657 | metadata, ;; Reference to array of member descriptors |
| 658 | i32 ;; Runtime languages |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 659 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 660 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 661 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 662 | |
| 663 | <p>These descriptors are used to define types that are composed of 0 or more |
| 664 | elements. The value of the tag varies depending on the meaning. The following |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 665 | are possible tag values:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 666 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 667 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 668 | <pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 669 | DW_TAG_array_type = 1 |
| 670 | DW_TAG_enumeration_type = 4 |
| 671 | DW_TAG_structure_type = 19 |
| 672 | DW_TAG_union_type = 23 |
| 673 | DW_TAG_vector_type = 259 |
Bruno Cardoso Lopes | d80ddc0 | 2009-05-29 17:08:57 +0000 | [diff] [blame] | 674 | DW_TAG_subroutine_type = 21 |
| 675 | DW_TAG_inheritance = 28 |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 676 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 677 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 678 | |
Jim Laskey | f8a01a9 | 2006-06-15 20:51:43 +0000 | [diff] [blame] | 679 | <p>The vector flag indicates that an array type is a native packed vector.</p> |
| 680 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 681 | <p>The members of array types (tag = <tt>DW_TAG_array_type</tt>) or vector types |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 682 | (tag = <tt>DW_TAG_vector_type</tt>) are <a href="#format_subrange">subrange |
| 683 | descriptors</a>, each representing the range of subscripts at that level of |
| 684 | indexing.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 685 | |
| 686 | <p>The members of enumeration types (tag = <tt>DW_TAG_enumeration_type</tt>) are |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 687 | <a href="#format_enumeration">enumerator descriptors</a>, each representing |
Devang Patel | da6eed3 | 2011-03-29 17:27:08 +0000 | [diff] [blame] | 688 | the definition of enumeration value for the set. All enumeration type |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 689 | descriptors are collected inside the named metadata |
| 690 | <tt>!llvm.dbg.cu</tt>.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 691 | |
| 692 | <p>The members of structure (tag = <tt>DW_TAG_structure_type</tt>) or union (tag |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 693 | = <tt>DW_TAG_union_type</tt>) types are any one of |
| 694 | the <a href="#format_basic_type">basic</a>, |
| 695 | <a href="#format_derived_type">derived</a> |
| 696 | or <a href="#format_composite_type">composite</a> type descriptors, each |
| 697 | representing a field member of the structure or union.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 698 | |
Jim Laskey | 4a9df24 | 2006-08-21 21:21:06 +0000 | [diff] [blame] | 699 | <p>For C++ classes (tag = <tt>DW_TAG_structure_type</tt>), member descriptors |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 700 | provide information about base classes, static members and member |
| 701 | functions. If a member is a <a href="#format_derived_type">derived type |
| 702 | descriptor</a> and has a tag of <tt>DW_TAG_inheritance</tt>, then the type |
| 703 | represents a base class. If the member of is |
| 704 | a <a href="#format_global_variables">global variable descriptor</a> then it |
| 705 | represents a static member. And, if the member is |
| 706 | a <a href="#format_subprograms">subprogram descriptor</a> then it represents |
| 707 | a member function. For static members and member |
| 708 | functions, <tt>getName()</tt> returns the members link or the C++ mangled |
| 709 | name. <tt>getDisplayName()</tt> the simplied version of the name.</p> |
Jim Laskey | 4a9df24 | 2006-08-21 21:21:06 +0000 | [diff] [blame] | 710 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 711 | <p>The first member of subroutine (tag = <tt>DW_TAG_subroutine_type</tt>) type |
| 712 | elements is the return type for the subroutine. The remaining elements are |
| 713 | the formal arguments to the subroutine.</p> |
Jim Laskey | 094ee72 | 2006-06-20 21:13:20 +0000 | [diff] [blame] | 714 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 715 | <p><a href="#format_composite_type">Composite type</a> location can be |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 716 | determined from the context and line number. The size, alignment and |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 717 | offset are expressed in bits and can be 64 bit values. The alignment is used |
| 718 | to round the offset when embedded in |
| 719 | a <a href="#format_composite_type">composite type</a> (as an example, to keep |
| 720 | float doubles on 64 bit boundaries.) The offset is the bit offset if embedded |
| 721 | in a <a href="#format_composite_type">composite type</a>.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 722 | |
| 723 | </div> |
| 724 | |
| 725 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 726 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 727 | <a name="format_subrange">Subrange descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 728 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 729 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 730 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 731 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 732 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 733 | <pre> |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 734 | !42 = metadata !{ |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 735 | i32, ;; Tag = 33 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> (DW_TAG_subrange_type) |
| 736 | i64, ;; Low value |
| 737 | i64 ;; High value |
| 738 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 739 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 740 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 741 | |
| 742 | <p>These descriptors are used to define ranges of array subscripts for an array |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 743 | <a href="#format_composite_type">composite type</a>. The low value defines |
| 744 | the lower bounds typically zero for C/C++. The high value is the upper |
| 745 | bounds. Values are 64 bit. High - low + 1 is the size of the array. If low |
Devang Patel | 3f932a7 | 2011-04-08 23:39:38 +0000 | [diff] [blame] | 746 | > high the array bounds are not included in generated debugging information. |
| 747 | </p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 748 | |
| 749 | </div> |
| 750 | |
| 751 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 752 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 753 | <a name="format_enumeration">Enumerator descriptors</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 754 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 755 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 756 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 757 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 758 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 759 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 760 | !6 = metadata !{ |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 761 | i32, ;; Tag = 40 + <a href="#LLVMDebugVersion">LLVMDebugVersion</a> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 762 | ;; (DW_TAG_enumerator) |
| 763 | metadata, ;; Name |
| 764 | i64 ;; Value |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 765 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 766 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 767 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 768 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 769 | <p>These descriptors are used to define members of an |
| 770 | enumeration <a href="#format_composite_type">composite type</a>, it |
| 771 | associates the name to the value.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 772 | |
| 773 | </div> |
| 774 | |
| 775 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 776 | <h4> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 777 | <a name="format_variables">Local variables</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 778 | </h4> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 779 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 780 | <div> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 781 | |
| 782 | <div class="doc_code"> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 783 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 784 | !7 = metadata !{ |
| 785 | i32, ;; Tag (see below) |
| 786 | metadata, ;; Context |
| 787 | metadata, ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 788 | metadata, ;; Reference to file where defined |
Devang Patel | a83688f | 2011-03-08 16:29:40 +0000 | [diff] [blame] | 789 | i32, ;; 24 bit - Line number where defined |
| 790 | ;; 8 bit - Argument number. 1 indicates 1st argument. |
Devang Patel | 0a2a306 | 2011-07-27 18:14:50 +0000 | [diff] [blame] | 791 | metadata, ;; Type descriptor |
| 792 | i32, ;; flags |
| 793 | metadata ;; (optional) Reference to inline location |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 794 | } |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 795 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 796 | </div> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 797 | |
| 798 | <p>These descriptors are used to define variables local to a sub program. The |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 799 | value of the tag depends on the usage of the variable:</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 800 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 801 | <div class="doc_code"> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 802 | <pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 803 | DW_TAG_auto_variable = 256 |
| 804 | DW_TAG_arg_variable = 257 |
| 805 | DW_TAG_return_variable = 258 |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 806 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 807 | </div> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 808 | |
| 809 | <p>An auto variable is any variable declared in the body of the function. An |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 810 | argument variable is any variable that appears as a formal argument to the |
| 811 | function. A return variable is used to track the result of a function and |
| 812 | has no source correspondent.</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 813 | |
Jim Laskey | 2d395d9 | 2006-03-24 09:20:27 +0000 | [diff] [blame] | 814 | <p>The context is either the subprogram or block where the variable is defined. |
Devang Patel | 94c7ddb | 2011-08-16 22:09:43 +0000 | [diff] [blame] | 815 | Name the source variable name. Context and line indicate where the |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 816 | variable was defined. Type descriptor defines the declared type of the |
| 817 | variable.</p> |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 818 | |
| 819 | </div> |
| 820 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 821 | </div> |
| 822 | |
Jim Laskey | 383e009 | 2006-03-23 17:54:33 +0000 | [diff] [blame] | 823 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 824 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 825 | <a name="format_common_intrinsics">Debugger intrinsic functions</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 826 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 827 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 828 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 829 | |
| 830 | <p>LLVM uses several intrinsic functions (name prefixed with "llvm.dbg") to |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 831 | provide debug information at various points in generated code.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 832 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 833 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 834 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 835 | <a name="format_common_declare">llvm.dbg.declare</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 836 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 837 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 838 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 839 | <pre> |
Devang Patel | 4c7c0c6 | 2010-10-01 19:22:16 +0000 | [diff] [blame] | 840 | void %<a href="#format_common_declare">llvm.dbg.declare</a>(metadata, metadata) |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 841 | </pre> |
| 842 | |
Chad Rosier | 5bfd969 | 2012-02-18 01:38:41 +0000 | [diff] [blame] | 843 | <p>This intrinsic provides information about a local element (e.g., variable). The |
| 844 | first argument is metadata holding the alloca for the variable. The |
| 845 | second argument is metadata containing a description of the variable.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 846 | </div> |
| 847 | |
| 848 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 849 | <h4> |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 850 | <a name="format_common_value">llvm.dbg.value</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 851 | </h4> |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 852 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 853 | <div> |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 854 | <pre> |
Dan Gohman | 3dfb3cf | 2010-05-28 17:07:41 +0000 | [diff] [blame] | 855 | void %<a href="#format_common_value">llvm.dbg.value</a>(metadata, i64, metadata) |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 856 | </pre> |
| 857 | |
| 858 | <p>This intrinsic provides information when a user source variable is set to a |
| 859 | new value. The first argument is the new value (wrapped as metadata). The |
| 860 | second argument is the offset in the user source variable where the new value |
Chad Rosier | 5bfd969 | 2012-02-18 01:38:41 +0000 | [diff] [blame] | 861 | is written. The third argument is metadata containing a description of the |
| 862 | user source variable.</p> |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 863 | </div> |
| 864 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 865 | </div> |
| 866 | |
Victor Hernandez | 67a1a54 | 2010-01-11 22:53:48 +0000 | [diff] [blame] | 867 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 868 | <h3> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 869 | <a name="format_common_lifetime">Object lifetimes and scoping</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 870 | </h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 871 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 872 | <div> |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 873 | <p>In many languages, the local variables in functions can have their lifetimes |
| 874 | or scopes limited to a subset of a function. In the C family of languages, |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 875 | for example, variables are only live (readable and writable) within the |
| 876 | source block that they are defined in. In functional languages, values are |
| 877 | only readable after they have been defined. Though this is a very obvious |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 878 | concept, it is non-trivial to model in LLVM, because it has no notion of |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 879 | scoping in this sense, and does not want to be tied to a language's scoping |
| 880 | rules.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 881 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 882 | <p>In order to handle this, the LLVM debug format uses the metadata attached to |
Nick Lewycky | 655fd03 | 2010-03-31 07:50:17 +0000 | [diff] [blame] | 883 | llvm instructions to encode line number and scoping information. Consider |
| 884 | the following C fragment, for example:</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 885 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 886 | <div class="doc_code"> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 887 | <pre> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 888 | 1. void foo() { |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 889 | 2. int X = 21; |
| 890 | 3. int Y = 22; |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 891 | 4. { |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 892 | 5. int Z = 23; |
| 893 | 6. Z = X; |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 894 | 7. } |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 895 | 8. X = Y; |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 896 | 9. } |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 897 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 898 | </div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 899 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 900 | <p>Compiled to LLVM, this function would be represented like this:</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 901 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 902 | <div class="doc_code"> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 903 | <pre> |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 904 | define void @foo() nounwind ssp { |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 905 | entry: |
Bill Wendling | 02216ff | 2009-12-01 00:59:58 +0000 | [diff] [blame] | 906 | %X = alloca i32, align 4 ; <i32*> [#uses=4] |
| 907 | %Y = alloca i32, align 4 ; <i32*> [#uses=4] |
| 908 | %Z = alloca i32, align 4 ; <i32*> [#uses=3] |
Dan Gohman | fe47aae | 2010-05-28 17:13:49 +0000 | [diff] [blame] | 909 | %0 = bitcast i32* %X to {}* ; <{}*> [#uses=1] |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 910 | call void @llvm.dbg.declare(metadata !{i32 * %X}, metadata !0), !dbg !7 |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 911 | store i32 21, i32* %X, !dbg !8 |
Dan Gohman | fe47aae | 2010-05-28 17:13:49 +0000 | [diff] [blame] | 912 | %1 = bitcast i32* %Y to {}* ; <{}*> [#uses=1] |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 913 | call void @llvm.dbg.declare(metadata !{i32 * %Y}, metadata !9), !dbg !10 |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 914 | store i32 22, i32* %Y, !dbg !11 |
Dan Gohman | fe47aae | 2010-05-28 17:13:49 +0000 | [diff] [blame] | 915 | %2 = bitcast i32* %Z to {}* ; <{}*> [#uses=1] |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 916 | call void @llvm.dbg.declare(metadata !{i32 * %Z}, metadata !12), !dbg !14 |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 917 | store i32 23, i32* %Z, !dbg !15 |
Bill Wendling | 02216ff | 2009-12-01 00:59:58 +0000 | [diff] [blame] | 918 | %tmp = load i32* %X, !dbg !16 ; <i32> [#uses=1] |
| 919 | %tmp1 = load i32* %Y, !dbg !16 ; <i32> [#uses=1] |
| 920 | %add = add nsw i32 %tmp, %tmp1, !dbg !16 ; <i32> [#uses=1] |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 921 | store i32 %add, i32* %Z, !dbg !16 |
Bill Wendling | 02216ff | 2009-12-01 00:59:58 +0000 | [diff] [blame] | 922 | %tmp2 = load i32* %Y, !dbg !17 ; <i32> [#uses=1] |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 923 | store i32 %tmp2, i32* %X, !dbg !17 |
| 924 | ret void, !dbg !18 |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 925 | } |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 926 | |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 927 | declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 928 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 929 | !0 = metadata !{i32 459008, metadata !1, metadata !"X", |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 930 | metadata !3, i32 2, metadata !6}; [ DW_TAG_auto_variable ] |
| 931 | !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ] |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 932 | !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", metadata !"foo", |
| 933 | metadata !"foo", metadata !3, i32 1, metadata !4, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 934 | i1 false, i1 true}; [DW_TAG_subprogram ] |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 935 | !3 = metadata !{i32 458769, i32 0, i32 12, metadata !"foo.c", |
| 936 | metadata !"/private/tmp", metadata !"clang 1.1", i1 true, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 937 | i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ] |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 938 | !4 = metadata !{i32 458773, metadata !3, metadata !"", null, i32 0, i64 0, i64 0, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 939 | i64 0, i32 0, null, metadata !5, i32 0}; [DW_TAG_subroutine_type ] |
| 940 | !5 = metadata !{null} |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 941 | !6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 942 | i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ] |
| 943 | !7 = metadata !{i32 2, i32 7, metadata !1, null} |
| 944 | !8 = metadata !{i32 2, i32 3, metadata !1, null} |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 945 | !9 = metadata !{i32 459008, metadata !1, metadata !"Y", metadata !3, i32 3, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 946 | metadata !6}; [ DW_TAG_auto_variable ] |
| 947 | !10 = metadata !{i32 3, i32 7, metadata !1, null} |
| 948 | !11 = metadata !{i32 3, i32 3, metadata !1, null} |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 949 | !12 = metadata !{i32 459008, metadata !13, metadata !"Z", metadata !3, i32 5, |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 950 | metadata !6}; [ DW_TAG_auto_variable ] |
| 951 | !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ] |
| 952 | !14 = metadata !{i32 5, i32 9, metadata !13, null} |
| 953 | !15 = metadata !{i32 5, i32 5, metadata !13, null} |
| 954 | !16 = metadata !{i32 6, i32 5, metadata !13, null} |
| 955 | !17 = metadata !{i32 8, i32 3, metadata !1, null} |
| 956 | !18 = metadata !{i32 9, i32 1, metadata !2, null} |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 957 | </pre> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 958 | </div> |
| 959 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 960 | <p>This example illustrates a few important details about LLVM debugging |
| 961 | information. In particular, it shows how the <tt>llvm.dbg.declare</tt> |
| 962 | intrinsic and location information, which are attached to an instruction, |
| 963 | are applied together to allow a debugger to analyze the relationship between |
| 964 | statements, variable definitions, and the code used to implement the |
| 965 | function.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 966 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 967 | <div class="doc_code"> |
Bill Wendling | 02216ff | 2009-12-01 00:59:58 +0000 | [diff] [blame] | 968 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 969 | call void @llvm.dbg.declare(metadata, metadata !0), !dbg !7 |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 970 | </pre> |
| 971 | </div> |
| 972 | |
| 973 | <p>The first intrinsic |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 974 | <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt> |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 975 | encodes debugging information for the variable <tt>X</tt>. The metadata |
| 976 | <tt>!dbg !7</tt> attached to the intrinsic provides scope information for the |
| 977 | variable <tt>X</tt>.</p> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 978 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 979 | <div class="doc_code"> |
| 980 | <pre> |
| 981 | !7 = metadata !{i32 2, i32 7, metadata !1, null} |
| 982 | !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ] |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 983 | !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", |
| 984 | metadata !"foo", metadata !"foo", metadata !3, i32 1, |
| 985 | metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ] |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 986 | </pre> |
| 987 | </div> |
| 988 | |
| 989 | <p>Here <tt>!7</tt> is metadata providing location information. It has four |
| 990 | fields: line number, column number, scope, and original scope. The original |
| 991 | scope represents inline location if this instruction is inlined inside a |
| 992 | caller, and is null otherwise. In this example, scope is encoded by |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 993 | <tt>!1</tt>. <tt>!1</tt> represents a lexical block inside the scope |
| 994 | <tt>!2</tt>, where <tt>!2</tt> is a |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 995 | <a href="#format_subprograms">subprogram descriptor</a>. This way the |
| 996 | location information attached to the intrinsics indicates that the |
| 997 | variable <tt>X</tt> is declared at line number 2 at a function level scope in |
| 998 | function <tt>foo</tt>.</p> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 999 | |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 1000 | <p>Now lets take another example.</p> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1001 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 1002 | <div class="doc_code"> |
Bill Wendling | 02216ff | 2009-12-01 00:59:58 +0000 | [diff] [blame] | 1003 | <pre> |
Devang Patel | 3728078 | 2011-02-03 00:22:17 +0000 | [diff] [blame] | 1004 | call void @llvm.dbg.declare(metadata, metadata !12), !dbg !14 |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 1005 | </pre> |
| 1006 | </div> |
| 1007 | |
| 1008 | <p>The second intrinsic |
Devang Patel | 744950d | 2009-11-25 23:28:01 +0000 | [diff] [blame] | 1009 | <tt>%<a href="#format_common_declare">llvm.dbg.declare</a></tt> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1010 | encodes debugging information for variable <tt>Z</tt>. The metadata |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 1011 | <tt>!dbg !14</tt> attached to the intrinsic provides scope information for |
| 1012 | the variable <tt>Z</tt>.</p> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1013 | |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 1014 | <div class="doc_code"> |
| 1015 | <pre> |
| 1016 | !13 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ] |
| 1017 | !14 = metadata !{i32 5, i32 9, metadata !13, null} |
| 1018 | </pre> |
| 1019 | </div> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1020 | |
John Criswell | b34500f | 2010-03-17 15:01:50 +0000 | [diff] [blame] | 1021 | <p>Here <tt>!14</tt> indicates that <tt>Z</tt> is declared at line number 5 and |
Bill Wendling | cf493b8 | 2009-12-01 00:53:11 +0000 | [diff] [blame] | 1022 | column number 9 inside of lexical scope <tt>!13</tt>. The lexical scope |
| 1023 | itself resides inside of lexical scope <tt>!1</tt> described above.</p> |
| 1024 | |
| 1025 | <p>The scope information attached with each instruction provides a |
| 1026 | straightforward way to find instructions covered by a scope.</p> |
| 1027 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1028 | </div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1029 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1030 | </div> |
| 1031 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1032 | <!-- *********************************************************************** --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1033 | <h2> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1034 | <a name="ccxx_frontend">C/C++ front-end specific debug information</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1035 | </h2> |
Misha Brukman | 94218a7 | 2004-12-09 20:27:37 +0000 | [diff] [blame] | 1036 | <!-- *********************************************************************** --> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1037 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1038 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1039 | |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 1040 | <p>The C and C++ front-ends represent information about the program in a format |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1041 | that is effectively identical |
| 1042 | to <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3.0</a> in |
| 1043 | terms of information content. This allows code generators to trivially |
| 1044 | support native debuggers by generating standard dwarf information, and |
| 1045 | contains enough information for non-dwarf targets to translate it as |
| 1046 | needed.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1047 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1048 | <p>This section describes the forms used to represent C and C++ programs. Other |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1049 | languages could pattern themselves after this (which itself is tuned to |
| 1050 | representing programs in the same way that DWARF 3 does), or they could |
| 1051 | choose to provide completely different forms if they don't fit into the DWARF |
| 1052 | model. As support for debugging information gets added to the various LLVM |
| 1053 | source-language front-ends, the information used should be documented |
| 1054 | here.</p> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1055 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1056 | <p>The following sections provide examples of various C/C++ constructs and the |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1057 | debug information that would best describe those constructs.</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1058 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1059 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1060 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1061 | <a name="ccxx_compile_units">C/C++ source file information</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1062 | </h3> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1063 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1064 | <div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1065 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1066 | <p>Given the source files <tt>MySource.cpp</tt> and <tt>MyHeader.h</tt> located |
| 1067 | in the directory <tt>/Users/mine/sources</tt>, the following code:</p> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1068 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1069 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1070 | <pre> |
| 1071 | #include "MyHeader.h" |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1072 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1073 | int main(int argc, char *argv[]) { |
| 1074 | return 0; |
| 1075 | } |
| 1076 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1077 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1078 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1079 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1080 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1081 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1082 | <pre> |
| 1083 | ... |
| 1084 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1085 | ;; Define the compile unit for the main source file "/Users/mine/sources/MySource.cpp". |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1086 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1087 | !2 = metadata !{ |
| 1088 | i32 524305, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1089 | i32 0, ;; Unused |
| 1090 | i32 4, ;; Language Id |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1091 | metadata !"MySource.cpp", |
| 1092 | metadata !"/Users/mine/sources", |
| 1093 | metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)", |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1094 | i1 true, ;; Main Compile Unit |
| 1095 | i1 false, ;; Optimized compile unit |
| 1096 | metadata !"", ;; Compiler flags |
| 1097 | i32 0} ;; Runtime version |
| 1098 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1099 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1100 | ;; Define the file for the file "/Users/mine/sources/MySource.cpp". |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1101 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1102 | !1 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1103 | i32 524329, ;; Tag |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1104 | metadata !"MySource.cpp", |
| 1105 | metadata !"/Users/mine/sources", |
Devang Patel | 9fea9c2 | 2010-07-13 16:53:20 +0000 | [diff] [blame] | 1106 | metadata !2 ;; Compile unit |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | ;; |
| 1110 | ;; Define the file for the file "/Users/mine/sources/Myheader.h" |
| 1111 | ;; |
| 1112 | !3 = metadata !{ |
| 1113 | i32 524329, ;; Tag |
| 1114 | metadata !"Myheader.h" |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1115 | metadata !"/Users/mine/sources", |
Devang Patel | 9fea9c2 | 2010-07-13 16:53:20 +0000 | [diff] [blame] | 1116 | metadata !2 ;; Compile unit |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1117 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1118 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1119 | ... |
| 1120 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1121 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1122 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1123 | <p>llvm::Instruction provides easy access to metadata attached with an |
Devang Patel | d98ec5f | 2010-03-26 19:08:36 +0000 | [diff] [blame] | 1124 | instruction. One can extract line number information encoded in LLVM IR |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1125 | using <tt>Instruction::getMetadata()</tt> and |
Devang Patel | d98ec5f | 2010-03-26 19:08:36 +0000 | [diff] [blame] | 1126 | <tt>DILocation::getLineNumber()</tt>. |
| 1127 | <pre> |
| 1128 | if (MDNode *N = I->getMetadata("dbg")) { // Here I is an LLVM instruction |
| 1129 | DILocation Loc(N); // DILocation is in DebugInfo.h |
| 1130 | unsigned Line = Loc.getLineNumber(); |
| 1131 | StringRef File = Loc.getFilename(); |
| 1132 | StringRef Dir = Loc.getDirectory(); |
| 1133 | } |
| 1134 | </pre> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1135 | </div> |
| 1136 | |
| 1137 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1138 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1139 | <a name="ccxx_global_variable">C/C++ global variable information</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1140 | </h3> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1141 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1142 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1143 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1144 | <p>Given an integer global variable declared as follows:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1145 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1146 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1147 | <pre> |
| 1148 | int MyGlobal = 100; |
| 1149 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1150 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1151 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1152 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1153 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1154 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1155 | <pre> |
| 1156 | ;; |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1157 | ;; Define the global itself. |
| 1158 | ;; |
| 1159 | %MyGlobal = global int 100 |
| 1160 | ... |
| 1161 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1162 | ;; List of debug info of globals |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1163 | ;; |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 1164 | !llvm.dbg.cu = !{!0} |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1165 | |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 1166 | ;; Define the compile unit. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1167 | !0 = metadata !{ |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 1168 | i32 786449, ;; Tag |
| 1169 | i32 0, ;; Context |
| 1170 | i32 4, ;; Language |
| 1171 | metadata !"foo.cpp", ;; File |
| 1172 | metadata !"/Volumes/Data/tmp", ;; Directory |
| 1173 | metadata !"clang version 3.1 ", ;; Producer |
| 1174 | i1 true, ;; Deprecated field |
| 1175 | i1 false, ;; "isOptimized"? |
| 1176 | metadata !"", ;; Flags |
| 1177 | i32 0, ;; Runtime Version |
| 1178 | metadata !1, ;; Enum Types |
| 1179 | metadata !1, ;; Retained Types |
| 1180 | metadata !1, ;; Subprograms |
| 1181 | metadata !3 ;; Global Variables |
| 1182 | } ; [ DW_TAG_compile_unit ] |
| 1183 | |
| 1184 | ;; The Array of Global Variables |
| 1185 | !3 = metadata !{ |
| 1186 | metadata !4 |
| 1187 | } |
| 1188 | |
| 1189 | !4 = metadata !{ |
| 1190 | metadata !5 |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1193 | ;; |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 1194 | ;; Define the global variable itself. |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1195 | ;; |
Eric Christopher | 4787cc4 | 2012-03-26 01:56:34 +0000 | [diff] [blame] | 1196 | !5 = metadata !{ |
| 1197 | i32 786484, ;; Tag |
| 1198 | i32 0, ;; Unused |
| 1199 | null, ;; Unused |
| 1200 | metadata !"MyGlobal", ;; Name |
| 1201 | metadata !"MyGlobal", ;; Display Name |
| 1202 | metadata !"", ;; Linkage Name |
| 1203 | metadata !6, ;; File |
| 1204 | i32 1, ;; Line |
| 1205 | metadata !7, ;; Type |
| 1206 | i32 0, ;; IsLocalToUnit |
| 1207 | i32 1, ;; IsDefinition |
| 1208 | i32* @MyGlobal ;; LLVM-IR Value |
| 1209 | } ; [ DW_TAG_variable ] |
| 1210 | |
| 1211 | ;; |
| 1212 | ;; Define the file |
| 1213 | ;; |
| 1214 | !6 = metadata !{ |
| 1215 | i32 786473, ;; Tag |
| 1216 | metadata !"foo.cpp", ;; File |
| 1217 | metadata !"/Volumes/Data/tmp", ;; Directory |
| 1218 | null ;; Unused |
| 1219 | } ; [ DW_TAG_file_type ] |
| 1220 | |
| 1221 | ;; |
| 1222 | ;; Define the type |
| 1223 | ;; |
| 1224 | !7 = metadata !{ |
| 1225 | i32 786468, ;; Tag |
| 1226 | null, ;; Unused |
| 1227 | metadata !"int", ;; Name |
| 1228 | null, ;; Unused |
| 1229 | i32 0, ;; Line |
| 1230 | i64 32, ;; Size in Bits |
| 1231 | i64 32, ;; Align in Bits |
| 1232 | i64 0, ;; Offset |
| 1233 | i32 0, ;; Flags |
| 1234 | i32 5 ;; Encoding |
| 1235 | } ; [ DW_TAG_base_type ] |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1236 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1237 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1238 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1239 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1240 | </div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1241 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1242 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1243 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1244 | <a name="ccxx_subprogram">C/C++ function information</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1245 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1246 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1247 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1248 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1249 | <p>Given a function declared as follows:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1250 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1251 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1252 | <pre> |
| 1253 | int main(int argc, char *argv[]) { |
| 1254 | return 0; |
| 1255 | } |
| 1256 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1257 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1258 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1259 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1260 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1261 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1262 | <pre> |
| 1263 | ;; |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1264 | ;; Define the anchor for subprograms. Note that the second field of the |
| 1265 | ;; anchor is 46, which is the same as the tag for subprograms |
| 1266 | ;; (46 = DW_TAG_subprogram.) |
| 1267 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1268 | !6 = metadata !{ |
| 1269 | i32 524334, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1270 | i32 0, ;; Unused |
| 1271 | metadata !1, ;; Context |
| 1272 | metadata !"main", ;; Name |
| 1273 | metadata !"main", ;; Display name |
| 1274 | metadata !"main", ;; Linkage name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1275 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1276 | i32 1, ;; Line number |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1277 | metadata !4, ;; Type |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1278 | i1 false, ;; Is local |
Devang Patel | da19475 | 2011-04-05 22:52:06 +0000 | [diff] [blame] | 1279 | i1 true, ;; Is definition |
| 1280 | i32 0, ;; Virtuality attribute, e.g. pure virtual function |
| 1281 | i32 0, ;; Index into virtual table for C++ methods |
| 1282 | i32 0, ;; Type that holds virtual table. |
| 1283 | i32 0, ;; Flags |
| 1284 | i1 false, ;; True if this function is optimized |
| 1285 | Function *, ;; Pointer to llvm::Function |
| 1286 | null ;; Function template parameters |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1287 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1288 | ;; |
| 1289 | ;; Define the subprogram itself. |
| 1290 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1291 | define i32 @main(i32 %argc, i8** %argv) { |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1292 | ... |
| 1293 | } |
| 1294 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1295 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1296 | |
| 1297 | </div> |
| 1298 | |
| 1299 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1300 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1301 | <a name="ccxx_basic_types">C/C++ basic types</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1302 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1303 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1304 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1305 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1306 | <p>The following are the basic type descriptors for C/C++ core types:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1307 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1308 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1309 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1310 | <a name="ccxx_basic_type_bool">bool</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1311 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1312 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1313 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1314 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1315 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1316 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1317 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1318 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1319 | metadata !1, ;; Context |
| 1320 | metadata !"bool", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1321 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1322 | i32 0, ;; Line number |
| 1323 | i64 8, ;; Size in Bits |
| 1324 | i64 8, ;; Align in Bits |
| 1325 | i64 0, ;; Offset in Bits |
| 1326 | i32 0, ;; Flags |
| 1327 | i32 2 ;; Encoding |
| 1328 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1329 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1330 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1331 | |
| 1332 | </div> |
| 1333 | |
| 1334 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1335 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1336 | <a name="ccxx_basic_char">char</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1337 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1338 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1339 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1340 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1341 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1342 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1343 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1344 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1345 | metadata !1, ;; Context |
| 1346 | metadata !"char", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1347 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1348 | i32 0, ;; Line number |
| 1349 | i64 8, ;; Size in Bits |
| 1350 | i64 8, ;; Align in Bits |
| 1351 | i64 0, ;; Offset in Bits |
| 1352 | i32 0, ;; Flags |
| 1353 | i32 6 ;; Encoding |
| 1354 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1355 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1356 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1357 | |
| 1358 | </div> |
| 1359 | |
| 1360 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1361 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1362 | <a name="ccxx_basic_unsigned_char">unsigned char</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1363 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1364 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1365 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1366 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1367 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1368 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1369 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1370 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1371 | metadata !1, ;; Context |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1372 | metadata !"unsigned char", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1373 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1374 | i32 0, ;; Line number |
| 1375 | i64 8, ;; Size in Bits |
| 1376 | i64 8, ;; Align in Bits |
| 1377 | i64 0, ;; Offset in Bits |
| 1378 | i32 0, ;; Flags |
| 1379 | i32 8 ;; Encoding |
| 1380 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1381 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1382 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1383 | |
| 1384 | </div> |
| 1385 | |
| 1386 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1387 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1388 | <a name="ccxx_basic_short">short</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1389 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1390 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1391 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1392 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1393 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1394 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1395 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1396 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1397 | metadata !1, ;; Context |
| 1398 | metadata !"short int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1399 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1400 | i32 0, ;; Line number |
| 1401 | i64 16, ;; Size in Bits |
| 1402 | i64 16, ;; Align in Bits |
| 1403 | i64 0, ;; Offset in Bits |
| 1404 | i32 0, ;; Flags |
| 1405 | i32 5 ;; Encoding |
| 1406 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1407 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1408 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1409 | |
| 1410 | </div> |
| 1411 | |
| 1412 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1413 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1414 | <a name="ccxx_basic_unsigned_short">unsigned short</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1415 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1416 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1417 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1418 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1419 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1420 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1421 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1422 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1423 | metadata !1, ;; Context |
| 1424 | metadata !"short unsigned int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1425 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1426 | i32 0, ;; Line number |
| 1427 | i64 16, ;; Size in Bits |
| 1428 | i64 16, ;; Align in Bits |
| 1429 | i64 0, ;; Offset in Bits |
| 1430 | i32 0, ;; Flags |
| 1431 | i32 7 ;; Encoding |
| 1432 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1433 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1434 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1435 | |
| 1436 | </div> |
| 1437 | |
| 1438 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1439 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1440 | <a name="ccxx_basic_int">int</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1441 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1442 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1443 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1444 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1445 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1446 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1447 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1448 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1449 | metadata !1, ;; Context |
| 1450 | metadata !"int", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1451 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1452 | i32 0, ;; Line number |
| 1453 | i64 32, ;; Size in Bits |
| 1454 | i64 32, ;; Align in Bits |
| 1455 | i64 0, ;; Offset in Bits |
| 1456 | i32 0, ;; Flags |
| 1457 | i32 5 ;; Encoding |
| 1458 | } |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1459 | </pre></div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1460 | |
| 1461 | </div> |
| 1462 | |
| 1463 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1464 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1465 | <a name="ccxx_basic_unsigned_int">unsigned int</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1466 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1467 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1468 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1469 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1470 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1471 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1472 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1473 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1474 | metadata !1, ;; Context |
| 1475 | metadata !"unsigned int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1476 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1477 | i32 0, ;; Line number |
| 1478 | i64 32, ;; Size in Bits |
| 1479 | i64 32, ;; Align in Bits |
| 1480 | i64 0, ;; Offset in Bits |
| 1481 | i32 0, ;; Flags |
| 1482 | i32 7 ;; Encoding |
| 1483 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1484 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1485 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1486 | |
| 1487 | </div> |
| 1488 | |
| 1489 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1490 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1491 | <a name="ccxx_basic_long_long">long long</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1492 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1493 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1494 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1495 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1496 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1497 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1498 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1499 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1500 | metadata !1, ;; Context |
| 1501 | metadata !"long long int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1502 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1503 | i32 0, ;; Line number |
| 1504 | i64 64, ;; Size in Bits |
| 1505 | i64 64, ;; Align in Bits |
| 1506 | i64 0, ;; Offset in Bits |
| 1507 | i32 0, ;; Flags |
| 1508 | i32 5 ;; Encoding |
| 1509 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1510 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1511 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1512 | |
| 1513 | </div> |
| 1514 | |
| 1515 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1516 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1517 | <a name="ccxx_basic_unsigned_long_long">unsigned long long</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1518 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1519 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1520 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1521 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1522 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1523 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1524 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1525 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1526 | metadata !1, ;; Context |
| 1527 | metadata !"long long unsigned int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1528 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1529 | i32 0, ;; Line number |
| 1530 | i64 64, ;; Size in Bits |
| 1531 | i64 64, ;; Align in Bits |
| 1532 | i64 0, ;; Offset in Bits |
| 1533 | i32 0, ;; Flags |
| 1534 | i32 7 ;; Encoding |
| 1535 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1536 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1537 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1538 | |
| 1539 | </div> |
| 1540 | |
| 1541 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1542 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1543 | <a name="ccxx_basic_float">float</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1544 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1545 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1546 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1547 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1548 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1549 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1550 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1551 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1552 | metadata !1, ;; Context |
| 1553 | metadata !"float", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1554 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1555 | i32 0, ;; Line number |
| 1556 | i64 32, ;; Size in Bits |
| 1557 | i64 32, ;; Align in Bits |
| 1558 | i64 0, ;; Offset in Bits |
| 1559 | i32 0, ;; Flags |
| 1560 | i32 4 ;; Encoding |
| 1561 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1562 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1563 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1564 | |
| 1565 | </div> |
| 1566 | |
| 1567 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1568 | <h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1569 | <a name="ccxx_basic_double">double</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1570 | </h4> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1571 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1572 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1573 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1574 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1575 | <pre> |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1576 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1577 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1578 | metadata !1, ;; Context |
| 1579 | metadata !"double",;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1580 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1581 | i32 0, ;; Line number |
| 1582 | i64 64, ;; Size in Bits |
| 1583 | i64 64, ;; Align in Bits |
| 1584 | i64 0, ;; Offset in Bits |
| 1585 | i32 0, ;; Flags |
| 1586 | i32 4 ;; Encoding |
| 1587 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1588 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1589 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1590 | |
| 1591 | </div> |
| 1592 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1593 | </div> |
| 1594 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1595 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1596 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1597 | <a name="ccxx_derived_types">C/C++ derived types</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1598 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1599 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1600 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1601 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1602 | <p>Given the following as an example of C/C++ derived type:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1603 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1604 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1605 | <pre> |
| 1606 | typedef const int *IntPtr; |
| 1607 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1608 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1609 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1610 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1611 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1612 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1613 | <pre> |
| 1614 | ;; |
| 1615 | ;; Define the typedef "IntPtr". |
| 1616 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1617 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1618 | i32 524310, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1619 | metadata !1, ;; Context |
| 1620 | metadata !"IntPtr", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1621 | metadata !3, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1622 | i32 0, ;; Line number |
| 1623 | i64 0, ;; Size in bits |
| 1624 | i64 0, ;; Align in bits |
| 1625 | i64 0, ;; Offset in bits |
| 1626 | i32 0, ;; Flags |
| 1627 | metadata !4 ;; Derived From type |
| 1628 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1629 | |
| 1630 | ;; |
| 1631 | ;; Define the pointer type. |
| 1632 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1633 | !4 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1634 | i32 524303, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1635 | metadata !1, ;; Context |
| 1636 | metadata !"", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1637 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1638 | i32 0, ;; Line number |
| 1639 | i64 64, ;; Size in bits |
| 1640 | i64 64, ;; Align in bits |
| 1641 | i64 0, ;; Offset in bits |
| 1642 | i32 0, ;; Flags |
| 1643 | metadata !5 ;; Derived From type |
| 1644 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1645 | ;; |
| 1646 | ;; Define the const type. |
| 1647 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1648 | !5 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1649 | i32 524326, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1650 | metadata !1, ;; Context |
| 1651 | metadata !"", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1652 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1653 | i32 0, ;; Line number |
| 1654 | i64 32, ;; Size in bits |
| 1655 | i64 32, ;; Align in bits |
| 1656 | i64 0, ;; Offset in bits |
| 1657 | i32 0, ;; Flags |
| 1658 | metadata !6 ;; Derived From type |
| 1659 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1660 | ;; |
| 1661 | ;; Define the int type. |
| 1662 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1663 | !6 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1664 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1665 | metadata !1, ;; Context |
| 1666 | metadata !"int", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1667 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1668 | i32 0, ;; Line number |
| 1669 | i64 32, ;; Size in bits |
| 1670 | i64 32, ;; Align in bits |
| 1671 | i64 0, ;; Offset in bits |
| 1672 | i32 0, ;; Flags |
| 1673 | 5 ;; Encoding |
| 1674 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1675 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1676 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1677 | |
| 1678 | </div> |
| 1679 | |
| 1680 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1681 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1682 | <a name="ccxx_composite_types">C/C++ struct/union types</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1683 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1684 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1685 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1686 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1687 | <p>Given the following as an example of C/C++ struct type:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1688 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1689 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1690 | <pre> |
| 1691 | struct Color { |
| 1692 | unsigned Red; |
| 1693 | unsigned Green; |
| 1694 | unsigned Blue; |
| 1695 | }; |
| 1696 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1697 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1698 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1699 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1700 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1701 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1702 | <pre> |
| 1703 | ;; |
| 1704 | ;; Define basic type for unsigned int. |
| 1705 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1706 | !5 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1707 | i32 524324, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1708 | metadata !1, ;; Context |
| 1709 | metadata !"unsigned int", |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1710 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1711 | i32 0, ;; Line number |
| 1712 | i64 32, ;; Size in Bits |
| 1713 | i64 32, ;; Align in Bits |
| 1714 | i64 0, ;; Offset in Bits |
| 1715 | i32 0, ;; Flags |
| 1716 | i32 7 ;; Encoding |
| 1717 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1718 | ;; |
| 1719 | ;; Define composite type for struct Color. |
| 1720 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1721 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1722 | i32 524307, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1723 | metadata !1, ;; Context |
| 1724 | metadata !"Color", ;; Name |
| 1725 | metadata !1, ;; Compile unit |
| 1726 | i32 1, ;; Line number |
| 1727 | i64 96, ;; Size in bits |
| 1728 | i64 32, ;; Align in bits |
| 1729 | i64 0, ;; Offset in bits |
| 1730 | i32 0, ;; Flags |
| 1731 | null, ;; Derived From |
| 1732 | metadata !3, ;; Elements |
| 1733 | i32 0 ;; Runtime Language |
| 1734 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1735 | |
| 1736 | ;; |
| 1737 | ;; Define the Red field. |
| 1738 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1739 | !4 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1740 | i32 524301, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1741 | metadata !1, ;; Context |
| 1742 | metadata !"Red", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1743 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1744 | i32 2, ;; Line number |
| 1745 | i64 32, ;; Size in bits |
| 1746 | i64 32, ;; Align in bits |
| 1747 | i64 0, ;; Offset in bits |
| 1748 | i32 0, ;; Flags |
| 1749 | metadata !5 ;; Derived From type |
| 1750 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1751 | |
| 1752 | ;; |
| 1753 | ;; Define the Green field. |
| 1754 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1755 | !6 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1756 | i32 524301, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1757 | metadata !1, ;; Context |
| 1758 | metadata !"Green", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1759 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1760 | i32 3, ;; Line number |
| 1761 | i64 32, ;; Size in bits |
| 1762 | i64 32, ;; Align in bits |
| 1763 | i64 32, ;; Offset in bits |
| 1764 | i32 0, ;; Flags |
| 1765 | metadata !5 ;; Derived From type |
| 1766 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1767 | |
| 1768 | ;; |
| 1769 | ;; Define the Blue field. |
| 1770 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1771 | !7 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1772 | i32 524301, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1773 | metadata !1, ;; Context |
| 1774 | metadata !"Blue", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1775 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1776 | i32 4, ;; Line number |
| 1777 | i64 32, ;; Size in bits |
| 1778 | i64 32, ;; Align in bits |
| 1779 | i64 64, ;; Offset in bits |
| 1780 | i32 0, ;; Flags |
| 1781 | metadata !5 ;; Derived From type |
| 1782 | } |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1783 | |
| 1784 | ;; |
| 1785 | ;; Define the array of fields used by the composite type Color. |
| 1786 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1787 | !3 = metadata !{metadata !4, metadata !6, metadata !7} |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1788 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1789 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1790 | |
| 1791 | </div> |
| 1792 | |
| 1793 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1794 | <h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1795 | <a name="ccxx_enumeration_types">C/C++ enumeration types</a> |
NAKAMURA Takumi | 05d0265 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 1796 | </h3> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1797 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1798 | <div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1799 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1800 | <p>Given the following as an example of C/C++ enumeration type:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1801 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1802 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1803 | <pre> |
| 1804 | enum Trees { |
| 1805 | Spruce = 100, |
| 1806 | Oak = 200, |
| 1807 | Maple = 300 |
| 1808 | }; |
| 1809 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1810 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1811 | |
Misha Brukman | 96e0081 | 2008-12-16 02:54:22 +0000 | [diff] [blame] | 1812 | <p>a C/C++ front-end would generate the following descriptors:</p> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1813 | |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1814 | <div class="doc_code"> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1815 | <pre> |
| 1816 | ;; |
| 1817 | ;; Define composite type for enum Trees |
| 1818 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1819 | !2 = metadata !{ |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1820 | i32 524292, ;; Tag |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1821 | metadata !1, ;; Context |
| 1822 | metadata !"Trees", ;; Name |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1823 | metadata !1, ;; File |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1824 | i32 1, ;; Line number |
| 1825 | i64 32, ;; Size in bits |
| 1826 | i64 32, ;; Align in bits |
| 1827 | i64 0, ;; Offset in bits |
| 1828 | i32 0, ;; Flags |
| 1829 | null, ;; Derived From type |
| 1830 | metadata !3, ;; Elements |
| 1831 | i32 0 ;; Runtime language |
| 1832 | } |
Devang Patel | 2a610c7 | 2009-08-25 05:24:07 +0000 | [diff] [blame] | 1833 | |
Devang Patel | 8245988 | 2009-08-26 05:01:18 +0000 | [diff] [blame] | 1834 | ;; |
| 1835 | ;; Define the array of enumerators used by composite type Trees. |
| 1836 | ;; |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1837 | !3 = metadata !{metadata !4, metadata !5, metadata !6} |
| 1838 | |
| 1839 | ;; |
| 1840 | ;; Define Spruce enumerator. |
| 1841 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1842 | !4 = metadata !{i32 524328, metadata !"Spruce", i64 100} |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1843 | |
| 1844 | ;; |
| 1845 | ;; Define Oak enumerator. |
| 1846 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1847 | !5 = metadata !{i32 524328, metadata !"Oak", i64 200} |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1848 | |
| 1849 | ;; |
| 1850 | ;; Define Maple enumerator. |
| 1851 | ;; |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 1852 | !6 = metadata !{i32 524328, metadata !"Maple", i64 300} |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 1853 | |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1854 | </pre> |
Bill Wendling | 48839d9 | 2009-05-17 05:52:39 +0000 | [diff] [blame] | 1855 | </div> |
Jim Laskey | cec12a5 | 2006-03-14 18:08:46 +0000 | [diff] [blame] | 1856 | |
| 1857 | </div> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 1858 | |
NAKAMURA Takumi | f5af6ad | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 1859 | </div> |
| 1860 | |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1861 | |
| 1862 | <!-- *********************************************************************** --> |
| 1863 | <h2> |
| 1864 | <a name="llvmdwarfextension">Debugging information format</a> |
| 1865 | </h2> |
| 1866 | <!-- *********************************************************************** --> |
| 1867 | <div> |
| 1868 | <!-- ======================================================================= --> |
| 1869 | <h3> |
Bill Wendling | 0eb5914 | 2012-03-06 09:17:39 +0000 | [diff] [blame] | 1870 | <a name="objcproperty">Debugging Information Extension for Objective C Properties</a> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1871 | </h3> |
| 1872 | <div> |
| 1873 | <!-- *********************************************************************** --> |
| 1874 | <h4> |
| 1875 | <a name="objcpropertyintroduction">Introduction</a> |
| 1876 | </h4> |
| 1877 | <!-- *********************************************************************** --> |
| 1878 | |
| 1879 | <div> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1880 | <p>Objective C provides a simpler way to declare and define accessor methods |
| 1881 | using declared properties. The language provides features to declare a |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1882 | property and to let compiler synthesize accessor methods. |
| 1883 | </p> |
| 1884 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1885 | <p>The debugger lets developer inspect Objective C interfaces and their |
| 1886 | instance variables and class variables. However, the debugger does not know |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1887 | anything about the properties defined in Objective C interfaces. The debugger |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1888 | consumes information generated by compiler in DWARF format. The format does |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1889 | not support encoding of Objective C properties. This proposal describes DWARF |
| 1890 | extensions to encode Objective C properties, which the debugger can use to let |
| 1891 | developers inspect Objective C properties. |
| 1892 | </p> |
| 1893 | |
| 1894 | </div> |
| 1895 | |
| 1896 | |
| 1897 | <!-- *********************************************************************** --> |
| 1898 | <h4> |
| 1899 | <a name="objcpropertyproposal">Proposal</a> |
| 1900 | </h4> |
| 1901 | <!-- *********************************************************************** --> |
| 1902 | |
| 1903 | <div> |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1904 | <p>Objective C properties exist separately from class members. A property |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1905 | can be defined only by "setter" and "getter" selectors, and |
| 1906 | be calculated anew on each access. Or a property can just be a direct access |
| 1907 | to some declared ivar. Finally it can have an ivar "automatically |
| 1908 | synthesized" for it by the compiler, in which case the property can be |
| 1909 | referred to in user code directly using the standard C dereference syntax as |
| 1910 | well as through the property "dot" syntax, but there is no entry in |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1911 | the @interface declaration corresponding to this ivar. |
| 1912 | </p> |
| 1913 | <p> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1914 | To facilitate debugging, these properties we will add a new DWARF TAG into the |
| 1915 | DW_TAG_structure_type definition for the class to hold the description of a |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1916 | given property, and a set of DWARF attributes that provide said description. |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1917 | The property tag will also contain the name and declared type of the property. |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1918 | </p> |
| 1919 | <p> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1920 | If there is a related ivar, there will also be a DWARF property attribute placed |
| 1921 | in the DW_TAG_member DIE for that ivar referring back to the property TAG for |
| 1922 | that property. And in the case where the compiler synthesizes the ivar directly, |
| 1923 | the compiler is expected to generate a DW_TAG_member for that ivar (with the |
| 1924 | DW_AT_artificial set to 1), whose name will be the name used to access this |
| 1925 | ivar directly in code, and with the property attribute pointing back to the |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1926 | property it is backing. |
| 1927 | </p> |
| 1928 | <p> |
| 1929 | The following examples will serve as illustration for our discussion: |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1930 | </p> |
| 1931 | |
| 1932 | <div class="doc_code"> |
| 1933 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1934 | @interface I1 { |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1935 | int n2; |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1936 | } |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1937 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1938 | @property int p1; |
| 1939 | @property int p2; |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1940 | @end |
| 1941 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1942 | @implementation I1 |
| 1943 | @synthesize p1; |
| 1944 | @synthesize p2 = n2; |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1945 | @end |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1946 | </pre> |
| 1947 | </div> |
| 1948 | |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1949 | <p> |
| 1950 | This produces the following DWARF (this is a "pseudo dwarfdump" output): |
| 1951 | </p> |
| 1952 | <div class="doc_code"> |
| 1953 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1954 | 0x00000100: TAG_structure_type [7] * |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1955 | AT_APPLE_runtime_class( 0x10 ) |
| 1956 | AT_name( "I1" ) |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1957 | AT_decl_file( "Objc_Property.m" ) |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1958 | AT_decl_line( 3 ) |
| 1959 | |
| 1960 | 0x00000110 TAG_APPLE_property |
| 1961 | AT_name ( "p1" ) |
| 1962 | AT_type ( {0x00000150} ( int ) ) |
| 1963 | |
| 1964 | 0x00000120: TAG_APPLE_property |
| 1965 | AT_name ( "p2" ) |
| 1966 | AT_type ( {0x00000150} ( int ) ) |
| 1967 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1968 | 0x00000130: TAG_member [8] |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1969 | AT_name( "_p1" ) |
| 1970 | AT_APPLE_property ( {0x00000110} "p1" ) |
| 1971 | AT_type( {0x00000150} ( int ) ) |
| 1972 | AT_artificial ( 0x1 ) |
| 1973 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1974 | 0x00000140: TAG_member [8] |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1975 | AT_name( "n2" ) |
| 1976 | AT_APPLE_property ( {0x00000120} "p2" ) |
| 1977 | AT_type( {0x00000150} ( int ) ) |
| 1978 | |
| 1979 | 0x00000150: AT_type( ( int ) ) |
| 1980 | </pre> |
| 1981 | </div> |
| 1982 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1983 | <p> Note, the current convention is that the name of the ivar for an |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1984 | auto-synthesized property is the name of the property from which it derives with |
| 1985 | an underscore prepended, as is shown in the example. |
| 1986 | But we actually don't need to know this convention, since we are given the name |
| 1987 | of the ivar directly. |
| 1988 | </p> |
| 1989 | |
| 1990 | <p> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1991 | Also, it is common practice in ObjC to have different property declarations in |
| 1992 | the @interface and @implementation - e.g. to provide a read-only property in |
| 1993 | the interface,and a read-write interface in the implementation. In that case, |
| 1994 | the compiler should emit whichever property declaration will be in force in the |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 1995 | current translation unit. |
| 1996 | </p> |
| 1997 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 1998 | <p> Developers can decorate a property with attributes which are encoded using |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 1999 | DW_AT_APPLE_property_attribute. |
| 2000 | </p> |
| 2001 | |
| 2002 | <div class="doc_code"> |
| 2003 | <pre> |
| 2004 | @property (readonly, nonatomic) int pr; |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2005 | </pre> |
| 2006 | </div> |
| 2007 | <p> |
| 2008 | Which produces a property tag: |
| 2009 | <p> |
| 2010 | <div class="doc_code"> |
| 2011 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2012 | TAG_APPLE_property [8] |
| 2013 | AT_name( "pr" ) |
| 2014 | AT_type ( {0x00000147} (int) ) |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2015 | AT_APPLE_property_attribute (DW_APPLE_PROPERTY_readonly, DW_APPLE_PROPERTY_nonatomic) |
| 2016 | </pre> |
| 2017 | </div> |
| 2018 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2019 | <p> The setter and getter method names are attached to the property using |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2020 | DW_AT_APPLE_property_setter and DW_AT_APPLE_property_getter attributes. |
| 2021 | </p> |
| 2022 | <div class="doc_code"> |
| 2023 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2024 | @interface I1 |
| 2025 | @property (setter=myOwnP3Setter:) int p3; |
| 2026 | -(void)myOwnP3Setter:(int)a; |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2027 | @end |
| 2028 | |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2029 | @implementation I1 |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2030 | @synthesize p3; |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2031 | -(void)myOwnP3Setter:(int)a{ } |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2032 | @end |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2033 | </pre> |
| 2034 | </div> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2035 | |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2036 | <p> |
| 2037 | The DWARF for this would be: |
| 2038 | </p> |
| 2039 | <div class="doc_code"> |
| 2040 | <pre> |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2041 | 0x000003bd: TAG_structure_type [7] * |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2042 | AT_APPLE_runtime_class( 0x10 ) |
| 2043 | AT_name( "I1" ) |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2044 | AT_decl_file( "Objc_Property.m" ) |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2045 | AT_decl_line( 3 ) |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2046 | |
| 2047 | 0x000003cd TAG_APPLE_property |
| 2048 | AT_name ( "p3" ) |
| 2049 | AT_APPLE_property_setter ( "myOwnP3Setter:" ) |
| 2050 | AT_type( {0x00000147} ( int ) ) |
Eric Christopher | fc7243a | 2012-03-06 02:25:36 +0000 | [diff] [blame] | 2051 | |
| 2052 | 0x000003f3: TAG_member [8] |
| 2053 | AT_name( "_p3" ) |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2054 | AT_type ( {0x00000147} ( int ) ) |
| 2055 | AT_APPLE_property ( {0x000003cd} ) |
| 2056 | AT_artificial ( 0x1 ) |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2057 | </pre> |
| 2058 | </div> |
| 2059 | |
| 2060 | </div> |
| 2061 | |
| 2062 | <!-- *********************************************************************** --> |
| 2063 | <h4> |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2064 | <a name="objcpropertynewtags">New DWARF Tags</a> |
| 2065 | </h4> |
| 2066 | <!-- *********************************************************************** --> |
| 2067 | |
| 2068 | <div> |
| 2069 | <table border="1" cellspacing="0"> |
Bill Wendling | cf1f6c8 | 2012-03-06 09:22:03 +0000 | [diff] [blame] | 2070 | <col width="200"> |
| 2071 | <col width="200"> |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2072 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2073 | <th>TAG</th> |
| 2074 | <th>Value</th> |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2075 | </tr> |
| 2076 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2077 | <td>DW_TAG_APPLE_property</td> |
| 2078 | <td>0x4200</td> |
Devang Patel | ba98b6b | 2012-02-06 18:18:25 +0000 | [diff] [blame] | 2079 | </tr> |
| 2080 | </table> |
| 2081 | |
| 2082 | </div> |
| 2083 | |
| 2084 | <!-- *********************************************************************** --> |
| 2085 | <h4> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2086 | <a name="objcpropertynewattributes">New DWARF Attributes</a> |
| 2087 | </h4> |
| 2088 | <!-- *********************************************************************** --> |
| 2089 | |
| 2090 | <div> |
| 2091 | <table border="1" cellspacing="0"> |
Bill Wendling | cf1f6c8 | 2012-03-06 09:22:03 +0000 | [diff] [blame] | 2092 | <col width="200"> |
| 2093 | <col width="200"> |
| 2094 | <col width="200"> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2095 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2096 | <th>Attribute</th> |
| 2097 | <th>Value</th> |
| 2098 | <th>Classes</th> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2099 | </tr> |
| 2100 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2101 | <td>DW_AT_APPLE_property</td> |
| 2102 | <td>0x3fed</td> |
| 2103 | <td>Reference</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2104 | </tr> |
| 2105 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2106 | <td>DW_AT_APPLE_property_getter</td> |
| 2107 | <td>0x3fe9</td> |
| 2108 | <td>String</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2109 | </tr> |
| 2110 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2111 | <td>DW_AT_APPLE_property_setter</td> |
| 2112 | <td>0x3fea</td> |
| 2113 | <td>String</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2114 | </tr> |
| 2115 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2116 | <td>DW_AT_APPLE_property_attribute</td> |
| 2117 | <td>0x3feb</td> |
| 2118 | <td>Constant</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2119 | </tr> |
| 2120 | </table> |
| 2121 | |
| 2122 | </div> |
| 2123 | |
| 2124 | <!-- *********************************************************************** --> |
| 2125 | <h4> |
| 2126 | <a name="objcpropertynewconstants">New DWARF Constants</a> |
| 2127 | </h4> |
| 2128 | <!-- *********************************************************************** --> |
| 2129 | |
| 2130 | <div> |
| 2131 | <table border="1" cellspacing="0"> |
Bill Wendling | cf1f6c8 | 2012-03-06 09:22:03 +0000 | [diff] [blame] | 2132 | <col width="200"> |
| 2133 | <col width="200"> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2134 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2135 | <th>Name</th> |
| 2136 | <th>Value</th> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2137 | </tr> |
| 2138 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2139 | <td>DW_AT_APPLE_PROPERTY_readonly</td> |
| 2140 | <td>0x1</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2141 | </tr> |
| 2142 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2143 | <td>DW_AT_APPLE_PROPERTY_readwrite</td> |
| 2144 | <td>0x2</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2145 | </tr> |
| 2146 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2147 | <td>DW_AT_APPLE_PROPERTY_assign</td> |
| 2148 | <td>0x4</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2149 | </tr> |
| 2150 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2151 | <td>DW_AT_APPLE_PROPERTY_retain</td> |
| 2152 | <td>0x8</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2153 | </tr> |
| 2154 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2155 | <td>DW_AT_APPLE_PROPERTY_copy</td> |
| 2156 | <td>0x10</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2157 | </tr> |
| 2158 | <tr> |
Bill Wendling | 63f5a1f | 2012-03-06 09:20:59 +0000 | [diff] [blame] | 2159 | <td>DW_AT_APPLE_PROPERTY_nonatomic</td> |
| 2160 | <td>0x20</td> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2161 | </tr> |
| 2162 | </table> |
| 2163 | |
| 2164 | </div> |
| 2165 | </div> |
Devang Patel | 6ac5b16 | 2011-11-15 22:59:54 +0000 | [diff] [blame] | 2166 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2167 | <!-- ======================================================================= --> |
| 2168 | <h3> |
| 2169 | <a name="acceltable">Name Accelerator Tables</a> |
| 2170 | </h3> |
| 2171 | <!-- ======================================================================= --> |
NAKAMURA Takumi | 9c55f59 | 2012-03-27 11:25:16 +0000 | [diff] [blame] | 2172 | <div> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2173 | <!-- ======================================================================= --> |
| 2174 | <h4> |
Eric Christopher | 5b7634f | 2012-03-06 02:25:41 +0000 | [diff] [blame] | 2175 | <a name="acceltableintroduction">Introduction</a> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2176 | </h4> |
| 2177 | <!-- ======================================================================= --> |
| 2178 | <div> |
| 2179 | <p>The .debug_pubnames and .debug_pubtypes formats are not what a debugger |
| 2180 | needs. The "pub" in the section name indicates that the entries in the |
| 2181 | table are publicly visible names only. This means no static or hidden |
| 2182 | functions show up in the .debug_pubnames. No static variables or private class |
| 2183 | variables are in the .debug_pubtypes. Many compilers add different things to |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2184 | these tables, so we can't rely upon the contents between gcc, icc, or clang.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2185 | |
| 2186 | <p>The typical query given by users tends not to match up with the contents of |
| 2187 | these tables. For example, the DWARF spec states that "In the case of the |
| 2188 | name of a function member or static data member of a C++ structure, class or |
| 2189 | union, the name presented in the .debug_pubnames section is not the simple |
| 2190 | name given by the DW_AT_name attribute of the referenced debugging information |
| 2191 | entry, but rather the fully qualified name of the data or function member." |
| 2192 | So the only names in these tables for complex C++ entries is a fully |
| 2193 | qualified name. Debugger users tend not to enter their search strings as |
| 2194 | "a::b::c(int,const Foo&) const", but rather as "c", "b::c" , or "a::b::c". So |
| 2195 | the name entered in the name table must be demangled in order to chop it up |
| 2196 | appropriately and additional names must be manually entered into the table |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2197 | to make it effective as a name lookup table for debuggers to use.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2198 | |
| 2199 | <p>All debuggers currently ignore the .debug_pubnames table as a result of |
| 2200 | its inconsistent and useless public-only name content making it a waste of |
| 2201 | space in the object file. These tables, when they are written to disk, are |
| 2202 | not sorted in any way, leaving every debugger to do its own parsing |
| 2203 | and sorting. These tables also include an inlined copy of the string values |
| 2204 | in the table itself making the tables much larger than they need to be on |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2205 | disk, especially for large C++ programs.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2206 | |
| 2207 | <p>Can't we just fix the sections by adding all of the names we need to this |
| 2208 | table? No, because that is not what the tables are defined to contain and we |
| 2209 | won't know the difference between the old bad tables and the new good tables. |
| 2210 | At best we could make our own renamed sections that contain all of the data |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2211 | we need.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2212 | |
| 2213 | <p>These tables are also insufficient for what a debugger like LLDB needs. |
| 2214 | LLDB uses clang for its expression parsing where LLDB acts as a PCH. LLDB is |
| 2215 | then often asked to look for type "foo" or namespace "bar", or list items in |
| 2216 | namespace "baz". Namespaces are not included in the pubnames or pubtypes |
| 2217 | tables. Since clang asks a lot of questions when it is parsing an expression, |
| 2218 | we need to be very fast when looking up names, as it happens a lot. Having new |
| 2219 | accelerator tables that are optimized for very quick lookups will benefit |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2220 | this type of debugging experience greatly.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2221 | |
| 2222 | <p>We would like to generate name lookup tables that can be mapped into |
| 2223 | memory from disk, and used as is, with little or no up-front parsing. We would |
| 2224 | also be able to control the exact content of these different tables so they |
| 2225 | contain exactly what we need. The Name Accelerator Tables were designed |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2226 | to fix these issues. In order to solve these issues we need to:</p> |
| 2227 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2228 | <ul> |
| 2229 | <li>Have a format that can be mapped into memory from disk and used as is</li> |
| 2230 | <li>Lookups should be very fast</li> |
| 2231 | <li>Extensible table format so these tables can be made by many producers</li> |
| 2232 | <li>Contain all of the names needed for typical lookups out of the box</li> |
| 2233 | <li>Strict rules for the contents of tables</li> |
| 2234 | </ul> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2235 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2236 | <p>Table size is important and the accelerator table format should allow the |
| 2237 | reuse of strings from common string tables so the strings for the names are |
| 2238 | not duplicated. We also want to make sure the table is ready to be used as-is |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2239 | by simply mapping the table into memory with minimal header parsing.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2240 | |
| 2241 | <p>The name lookups need to be fast and optimized for the kinds of lookups |
| 2242 | that debuggers tend to do. Optimally we would like to touch as few parts of |
| 2243 | the mapped table as possible when doing a name lookup and be able to quickly |
| 2244 | find the name entry we are looking for, or discover there are no matches. In |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2245 | the case of debuggers we optimized for lookups that fail most of the time.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2246 | |
| 2247 | <p>Each table that is defined should have strict rules on exactly what is in |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2248 | the accelerator tables and documented so clients can rely on the content.</p> |
| 2249 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2250 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2251 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2252 | <!-- ======================================================================= --> |
| 2253 | <h4> |
| 2254 | <a name="acceltablehashes">Hash Tables</a> |
| 2255 | </h4> |
| 2256 | <!-- ======================================================================= --> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2257 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2258 | <div> |
| 2259 | <h5>Standard Hash Tables</h5> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2260 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2261 | <p>Typical hash tables have a header, buckets, and each bucket points to the |
| 2262 | bucket contents: |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2263 | </p> |
| 2264 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2265 | <div class="doc_code"> |
| 2266 | <pre> |
| 2267 | .------------. |
| 2268 | | HEADER | |
| 2269 | |------------| |
| 2270 | | BUCKETS | |
| 2271 | |------------| |
| 2272 | | DATA | |
| 2273 | `------------' |
| 2274 | </pre> |
| 2275 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2276 | |
| 2277 | <p>The BUCKETS are an array of offsets to DATA for each hash:</p> |
| 2278 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2279 | <div class="doc_code"> |
| 2280 | <pre> |
| 2281 | .------------. |
| 2282 | | 0x00001000 | BUCKETS[0] |
| 2283 | | 0x00002000 | BUCKETS[1] |
| 2284 | | 0x00002200 | BUCKETS[2] |
| 2285 | | 0x000034f0 | BUCKETS[3] |
| 2286 | | | ... |
| 2287 | | 0xXXXXXXXX | BUCKETS[n_buckets] |
| 2288 | '------------' |
| 2289 | </pre> |
| 2290 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2291 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2292 | <p>So for bucket[3] in the example above, we have an offset into the table |
| 2293 | 0x000034f0 which points to a chain of entries for the bucket. Each bucket |
| 2294 | must contain a next pointer, full 32 bit hash value, the string itself, |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2295 | and the data for the current string value.</p> |
| 2296 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2297 | <div class="doc_code"> |
| 2298 | <pre> |
| 2299 | .------------. |
| 2300 | 0x000034f0: | 0x00003500 | next pointer |
| 2301 | | 0x12345678 | 32 bit hash |
| 2302 | | "erase" | string value |
| 2303 | | data[n] | HashData for this bucket |
| 2304 | |------------| |
| 2305 | 0x00003500: | 0x00003550 | next pointer |
| 2306 | | 0x29273623 | 32 bit hash |
| 2307 | | "dump" | string value |
| 2308 | | data[n] | HashData for this bucket |
| 2309 | |------------| |
| 2310 | 0x00003550: | 0x00000000 | next pointer |
| 2311 | | 0x82638293 | 32 bit hash |
| 2312 | | "main" | string value |
| 2313 | | data[n] | HashData for this bucket |
| 2314 | `------------' |
| 2315 | </pre> |
| 2316 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2317 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2318 | <p>The problem with this layout for debuggers is that we need to optimize for |
| 2319 | the negative lookup case where the symbol we're searching for is not present. |
| 2320 | So if we were to lookup "printf" in the table above, we would make a 32 hash |
| 2321 | for "printf", it might match bucket[3]. We would need to go to the offset |
| 2322 | 0x000034f0 and start looking to see if our 32 bit hash matches. To do so, we |
| 2323 | need to read the next pointer, then read the hash, compare it, and skip to |
| 2324 | the next bucket. Each time we are skipping many bytes in memory and touching |
| 2325 | new cache pages just to do the compare on the full 32 bit hash. All of these |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2326 | accesses then tell us that we didn't have a match.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2327 | |
| 2328 | <h5>Name Hash Tables</h5> |
| 2329 | |
| 2330 | <p>To solve the issues mentioned above we have structured the hash tables |
| 2331 | a bit differently: a header, buckets, an array of all unique 32 bit hash |
| 2332 | values, followed by an array of hash value data offsets, one for each hash |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2333 | value, then the data for all hash values:</p> |
| 2334 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2335 | <div class="doc_code"> |
| 2336 | <pre> |
| 2337 | .-------------. |
| 2338 | | HEADER | |
| 2339 | |-------------| |
| 2340 | | BUCKETS | |
| 2341 | |-------------| |
| 2342 | | HASHES | |
| 2343 | |-------------| |
| 2344 | | OFFSETS | |
| 2345 | |-------------| |
| 2346 | | DATA | |
| 2347 | `-------------' |
| 2348 | </pre> |
| 2349 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2350 | |
Eric Christopher | 5b7634f | 2012-03-06 02:25:41 +0000 | [diff] [blame] | 2351 | <p>The BUCKETS in the name tables are an index into the HASHES array. By |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2352 | making all of the full 32 bit hash values contiguous in memory, we allow |
| 2353 | ourselves to efficiently check for a match while touching as little |
Eric Christopher | 5b7634f | 2012-03-06 02:25:41 +0000 | [diff] [blame] | 2354 | memory as possible. Most often checking the 32 bit hash values is as far as |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2355 | the lookup goes. If it does match, it usually is a match with no collisions. |
| 2356 | So for a table with "n_buckets" buckets, and "n_hashes" unique 32 bit hash |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2357 | values, we can clarify the contents of the BUCKETS, HASHES and OFFSETS as:</p> |
| 2358 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2359 | <div class="doc_code"> |
| 2360 | <pre> |
| 2361 | .-------------------------. |
| 2362 | | HEADER.magic | uint32_t |
| 2363 | | HEADER.version | uint16_t |
| 2364 | | HEADER.hash_function | uint16_t |
| 2365 | | HEADER.bucket_count | uint32_t |
| 2366 | | HEADER.hashes_count | uint32_t |
| 2367 | | HEADER.header_data_len | uint32_t |
| 2368 | | HEADER_DATA | HeaderData |
| 2369 | |-------------------------| |
| 2370 | | BUCKETS | uint32_t[n_buckets] // 32 bit hash indexes |
| 2371 | |-------------------------| |
| 2372 | | HASHES | uint32_t[n_buckets] // 32 bit hash values |
| 2373 | |-------------------------| |
| 2374 | | OFFSETS | uint32_t[n_buckets] // 32 bit offsets to hash value data |
| 2375 | |-------------------------| |
| 2376 | | ALL HASH DATA | |
| 2377 | `-------------------------' |
| 2378 | </pre> |
| 2379 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2380 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2381 | <p>So taking the exact same data from the standard hash example above we end up |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2382 | with:</p> |
| 2383 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2384 | <div class="doc_code"> |
| 2385 | <pre> |
| 2386 | .------------. |
| 2387 | | HEADER | |
| 2388 | |------------| |
| 2389 | | 0 | BUCKETS[0] |
| 2390 | | 2 | BUCKETS[1] |
| 2391 | | 5 | BUCKETS[2] |
| 2392 | | 6 | BUCKETS[3] |
| 2393 | | | ... |
| 2394 | | ... | BUCKETS[n_buckets] |
| 2395 | |------------| |
| 2396 | | 0x........ | HASHES[0] |
| 2397 | | 0x........ | HASHES[1] |
| 2398 | | 0x........ | HASHES[2] |
| 2399 | | 0x........ | HASHES[3] |
| 2400 | | 0x........ | HASHES[4] |
| 2401 | | 0x........ | HASHES[5] |
| 2402 | | 0x12345678 | HASHES[6] hash for BUCKETS[3] |
| 2403 | | 0x29273623 | HASHES[7] hash for BUCKETS[3] |
| 2404 | | 0x82638293 | HASHES[8] hash for BUCKETS[3] |
| 2405 | | 0x........ | HASHES[9] |
| 2406 | | 0x........ | HASHES[10] |
| 2407 | | 0x........ | HASHES[11] |
| 2408 | | 0x........ | HASHES[12] |
| 2409 | | 0x........ | HASHES[13] |
| 2410 | | 0x........ | HASHES[n_hashes] |
| 2411 | |------------| |
| 2412 | | 0x........ | OFFSETS[0] |
| 2413 | | 0x........ | OFFSETS[1] |
| 2414 | | 0x........ | OFFSETS[2] |
| 2415 | | 0x........ | OFFSETS[3] |
| 2416 | | 0x........ | OFFSETS[4] |
| 2417 | | 0x........ | OFFSETS[5] |
| 2418 | | 0x000034f0 | OFFSETS[6] offset for BUCKETS[3] |
| 2419 | | 0x00003500 | OFFSETS[7] offset for BUCKETS[3] |
| 2420 | | 0x00003550 | OFFSETS[8] offset for BUCKETS[3] |
| 2421 | | 0x........ | OFFSETS[9] |
| 2422 | | 0x........ | OFFSETS[10] |
| 2423 | | 0x........ | OFFSETS[11] |
| 2424 | | 0x........ | OFFSETS[12] |
| 2425 | | 0x........ | OFFSETS[13] |
| 2426 | | 0x........ | OFFSETS[n_hashes] |
| 2427 | |------------| |
| 2428 | | | |
| 2429 | | | |
| 2430 | | | |
| 2431 | | | |
| 2432 | | | |
| 2433 | |------------| |
| 2434 | 0x000034f0: | 0x00001203 | .debug_str ("erase") |
| 2435 | | 0x00000004 | A 32 bit array count - number of HashData with name "erase" |
| 2436 | | 0x........ | HashData[0] |
| 2437 | | 0x........ | HashData[1] |
| 2438 | | 0x........ | HashData[2] |
| 2439 | | 0x........ | HashData[3] |
| 2440 | | 0x00000000 | String offset into .debug_str (terminate data for hash) |
| 2441 | |------------| |
| 2442 | 0x00003500: | 0x00001203 | String offset into .debug_str ("collision") |
| 2443 | | 0x00000002 | A 32 bit array count - number of HashData with name "collision" |
| 2444 | | 0x........ | HashData[0] |
| 2445 | | 0x........ | HashData[1] |
| 2446 | | 0x00001203 | String offset into .debug_str ("dump") |
| 2447 | | 0x00000003 | A 32 bit array count - number of HashData with name "dump" |
| 2448 | | 0x........ | HashData[0] |
| 2449 | | 0x........ | HashData[1] |
| 2450 | | 0x........ | HashData[2] |
| 2451 | | 0x00000000 | String offset into .debug_str (terminate data for hash) |
| 2452 | |------------| |
| 2453 | 0x00003550: | 0x00001203 | String offset into .debug_str ("main") |
| 2454 | | 0x00000009 | A 32 bit array count - number of HashData with name "main" |
| 2455 | | 0x........ | HashData[0] |
| 2456 | | 0x........ | HashData[1] |
| 2457 | | 0x........ | HashData[2] |
| 2458 | | 0x........ | HashData[3] |
| 2459 | | 0x........ | HashData[4] |
| 2460 | | 0x........ | HashData[5] |
| 2461 | | 0x........ | HashData[6] |
| 2462 | | 0x........ | HashData[7] |
| 2463 | | 0x........ | HashData[8] |
| 2464 | | 0x00000000 | String offset into .debug_str (terminate data for hash) |
| 2465 | `------------' |
| 2466 | </pre> |
| 2467 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2468 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2469 | <p>So we still have all of the same data, we just organize it more efficiently |
| 2470 | for debugger lookup. If we repeat the same "printf" lookup from above, we |
| 2471 | would hash "printf" and find it matches BUCKETS[3] by taking the 32 bit hash |
| 2472 | value and modulo it by n_buckets. BUCKETS[3] contains "6" which is the index |
| 2473 | into the HASHES table. We would then compare any consecutive 32 bit hashes |
| 2474 | values in the HASHES array as long as the hashes would be in BUCKETS[3]. We |
| 2475 | do this by verifying that each subsequent hash value modulo n_buckets is still |
| 2476 | 3. In the case of a failed lookup we would access the memory for BUCKETS[3], and |
| 2477 | then compare a few consecutive 32 bit hashes before we know that we have no match. |
| 2478 | We don't end up marching through multiple words of memory and we really keep the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2479 | number of processor data cache lines being accessed as small as possible.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2480 | |
| 2481 | <p>The string hash that is used for these lookup tables is the Daniel J. |
| 2482 | Bernstein hash which is also used in the ELF GNU_HASH sections. It is a very |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2483 | good hash for all kinds of names in programs with very few hash collisions.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2484 | |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2485 | <p>Empty buckets are designated by using an invalid hash index of UINT32_MAX.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2486 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2487 | |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2488 | <!-- ======================================================================= --> |
| 2489 | <h4> |
| 2490 | <a name="acceltabledetails">Details</a> |
| 2491 | </h4> |
| 2492 | <!-- ======================================================================= --> |
| 2493 | <div> |
| 2494 | <p>These name hash tables are designed to be generic where specializations of |
| 2495 | the table get to define additional data that goes into the header |
| 2496 | ("HeaderData"), how the string value is stored ("KeyType") and the content |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2497 | of the data for each hash value.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2498 | |
| 2499 | <h5>Header Layout</h5> |
| 2500 | <p>The header has a fixed part, and the specialized part. The exact format of |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2501 | the header is:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2502 | <div class="doc_code"> |
| 2503 | <pre> |
| 2504 | struct Header |
| 2505 | { |
| 2506 | uint32_t magic; // 'HASH' magic value to allow endian detection |
| 2507 | uint16_t version; // Version number |
| 2508 | uint16_t hash_function; // The hash function enumeration that was used |
| 2509 | uint32_t bucket_count; // The number of buckets in this hash table |
| 2510 | uint32_t hashes_count; // The total number of unique hash values and hash data offsets in this table |
| 2511 | uint32_t header_data_len; // The bytes to skip to get to the hash indexes (buckets) for correct alignment |
| 2512 | // Specifically the length of the following HeaderData field - this does not |
| 2513 | // include the size of the preceding fields |
| 2514 | HeaderData header_data; // Implementation specific header data |
| 2515 | }; |
| 2516 | </pre> |
| 2517 | </div> |
| 2518 | <p>The header starts with a 32 bit "magic" value which must be 'HASH' encoded as |
| 2519 | an ASCII integer. This allows the detection of the start of the hash table and |
| 2520 | also allows the table's byte order to be determined so the table can be |
| 2521 | correctly extracted. The "magic" value is followed by a 16 bit version number |
| 2522 | which allows the table to be revised and modified in the future. The current |
| 2523 | version number is 1. "hash_function" is a uint16_t enumeration that specifies |
| 2524 | which hash function was used to produce this table. The current values for the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2525 | hash function enumerations include:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2526 | <div class="doc_code"> |
| 2527 | <pre> |
| 2528 | enum HashFunctionType |
| 2529 | { |
| 2530 | eHashFunctionDJB = 0u, // Daniel J Bernstein hash function |
| 2531 | }; |
| 2532 | </pre> |
| 2533 | </div> |
| 2534 | <p>"bucket_count" is a 32 bit unsigned integer that represents how many buckets |
| 2535 | are in the BUCKETS array. "hashes_count" is the number of unique 32 bit hash |
| 2536 | values that are in the HASHES array, and is the same number of offsets are |
| 2537 | contained in the OFFSETS array. "header_data_len" specifies the size in |
| 2538 | bytes of the HeaderData that is filled in by specialized versions of this |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2539 | table.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2540 | |
| 2541 | <h5>Fixed Lookup</h5> |
| 2542 | <p>The header is followed by the buckets, hashes, offsets, and hash value |
| 2543 | data. |
| 2544 | <div class="doc_code"> |
| 2545 | <pre> |
| 2546 | struct FixedTable |
| 2547 | { |
| 2548 | uint32_t buckets[Header.bucket_count]; // An array of hash indexes into the "hashes[]" array below |
| 2549 | uint32_t hashes [Header.hashes_count]; // Every unique 32 bit hash for the entire table is in this table |
| 2550 | uint32_t offsets[Header.hashes_count]; // An offset that corresponds to each item in the "hashes[]" array above |
| 2551 | }; |
| 2552 | </pre> |
| 2553 | </div> |
| 2554 | <p>"buckets" is an array of 32 bit indexes into the "hashes" array. The |
| 2555 | "hashes" array contains all of the 32 bit hash values for all names in the |
| 2556 | hash table. Each hash in the "hashes" table has an offset in the "offsets" |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2557 | array that points to the data for the hash value.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2558 | |
| 2559 | <p>This table setup makes it very easy to repurpose these tables to contain |
| 2560 | different data, while keeping the lookup mechanism the same for all tables. |
| 2561 | This layout also makes it possible to save the table to disk and map it in |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2562 | later and do very efficient name lookups with little or no parsing.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2563 | |
| 2564 | <p>DWARF lookup tables can be implemented in a variety of ways and can store |
| 2565 | a lot of information for each name. We want to make the DWARF tables |
| 2566 | extensible and able to store the data efficiently so we have used some of the |
| 2567 | DWARF features that enable efficient data storage to define exactly what kind |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2568 | of data we store for each name.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2569 | |
| 2570 | <p>The "HeaderData" contains a definition of the contents of each HashData |
| 2571 | chunk. We might want to store an offset to all of the debug information |
| 2572 | entries (DIEs) for each name. To keep things extensible, we create a list of |
| 2573 | items, or Atoms, that are contained in the data for each name. First comes the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2574 | type of the data in each atom:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2575 | <div class="doc_code"> |
| 2576 | <pre> |
| 2577 | enum AtomType |
| 2578 | { |
| 2579 | eAtomTypeNULL = 0u, |
| 2580 | eAtomTypeDIEOffset = 1u, // DIE offset, check form for encoding |
| 2581 | eAtomTypeCUOffset = 2u, // DIE offset of the compiler unit header that contains the item in question |
| 2582 | eAtomTypeTag = 3u, // DW_TAG_xxx value, should be encoded as DW_FORM_data1 (if no tags exceed 255) or DW_FORM_data2 |
| 2583 | eAtomTypeNameFlags = 4u, // Flags from enum NameFlags |
| 2584 | eAtomTypeTypeFlags = 5u, // Flags from enum TypeFlags |
| 2585 | }; |
| 2586 | </pre> |
| 2587 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2588 | <p>The enumeration values and their meanings are:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2589 | <div class="doc_code"> |
| 2590 | <pre> |
| 2591 | eAtomTypeNULL - a termination atom that specifies the end of the atom list |
| 2592 | eAtomTypeDIEOffset - an offset into the .debug_info section for the DWARF DIE for this name |
| 2593 | eAtomTypeCUOffset - an offset into the .debug_info section for the CU that contains the DIE |
| 2594 | eAtomTypeDIETag - The DW_TAG_XXX enumeration value so you don't have to parse the DWARF to see what it is |
| 2595 | eAtomTypeNameFlags - Flags for functions and global variables (isFunction, isInlined, isExternal...) |
| 2596 | eAtomTypeTypeFlags - Flags for types (isCXXClass, isObjCClass, ...) |
| 2597 | </pre> |
| 2598 | </div> |
| 2599 | <p>Then we allow each atom type to define the atom type and how the data for |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2600 | each atom type data is encoded:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2601 | <div class="doc_code"> |
| 2602 | <pre> |
| 2603 | struct Atom |
| 2604 | { |
| 2605 | uint16_t type; // AtomType enum value |
| 2606 | uint16_t form; // DWARF DW_FORM_XXX defines |
| 2607 | }; |
| 2608 | </pre> |
| 2609 | </div> |
| 2610 | <p>The "form" type above is from the DWARF specification and defines the |
| 2611 | exact encoding of the data for the Atom type. See the DWARF specification for |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2612 | the DW_FORM_ definitions.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2613 | <div class="doc_code"> |
| 2614 | <pre> |
| 2615 | struct HeaderData |
| 2616 | { |
| 2617 | uint32_t die_offset_base; |
| 2618 | uint32_t atom_count; |
| 2619 | Atoms atoms[atom_count0]; |
| 2620 | }; |
| 2621 | </pre> |
| 2622 | </div> |
| 2623 | <p>"HeaderData" defines the base DIE offset that should be added to any atoms |
| 2624 | that are encoded using the DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, |
| 2625 | DW_FORM_ref8 or DW_FORM_ref_udata. It also defines what is contained in |
| 2626 | each "HashData" object -- Atom.form tells us how large each field will be in |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2627 | the HashData and the Atom.type tells us how this data should be interpreted.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2628 | |
| 2629 | <p>For the current implementations of the ".apple_names" (all functions + globals), |
| 2630 | the ".apple_types" (names of all types that are defined), and the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2631 | ".apple_namespaces" (all namespaces), we currently set the Atom array to be:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2632 | <div class="doc_code"> |
| 2633 | <pre> |
| 2634 | HeaderData.atom_count = 1; |
| 2635 | HeaderData.atoms[0].type = eAtomTypeDIEOffset; |
| 2636 | HeaderData.atoms[0].form = DW_FORM_data4; |
| 2637 | </pre> |
| 2638 | </div> |
| 2639 | <p>This defines the contents to be the DIE offset (eAtomTypeDIEOffset) that is |
| 2640 | encoded as a 32 bit value (DW_FORM_data4). This allows a single name to have |
| 2641 | multiple matching DIEs in a single file, which could come up with an inlined |
| 2642 | function for instance. Future tables could include more information about the |
| 2643 | DIE such as flags indicating if the DIE is a function, method, block, |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2644 | or inlined.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2645 | |
| 2646 | <p>The KeyType for the DWARF table is a 32 bit string table offset into the |
| 2647 | ".debug_str" table. The ".debug_str" is the string table for the DWARF which |
| 2648 | may already contain copies of all of the strings. This helps make sure, with |
| 2649 | help from the compiler, that we reuse the strings between all of the DWARF |
| 2650 | sections and keeps the hash table size down. Another benefit to having the |
| 2651 | compiler generate all strings as DW_FORM_strp in the debug info, is that |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2652 | DWARF parsing can be made much faster.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2653 | |
| 2654 | <p>After a lookup is made, we get an offset into the hash data. The hash data |
| 2655 | needs to be able to deal with 32 bit hash collisions, so the chunk of data |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2656 | at the offset in the hash data consists of a triple:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2657 | <div class="doc_code"> |
| 2658 | <pre> |
| 2659 | uint32_t str_offset |
| 2660 | uint32_t hash_data_count |
| 2661 | HashData[hash_data_count] |
| 2662 | </pre> |
| 2663 | </div> |
| 2664 | <p>If "str_offset" is zero, then the bucket contents are done. 99.9% of the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2665 | hash data chunks contain a single item (no 32 bit hash collision):</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2666 | <div class="doc_code"> |
| 2667 | <pre> |
| 2668 | .------------. |
| 2669 | | 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main") |
| 2670 | | 0x00000004 | uint32_t HashData count |
| 2671 | | 0x........ | uint32_t HashData[0] DIE offset |
| 2672 | | 0x........ | uint32_t HashData[1] DIE offset |
| 2673 | | 0x........ | uint32_t HashData[2] DIE offset |
| 2674 | | 0x........ | uint32_t HashData[3] DIE offset |
| 2675 | | 0x00000000 | uint32_t KeyType (end of hash chain) |
| 2676 | `------------' |
| 2677 | </pre> |
| 2678 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2679 | <p>If there are collisions, you will have multiple valid string offsets:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2680 | <div class="doc_code"> |
| 2681 | <pre> |
| 2682 | .------------. |
| 2683 | | 0x00001023 | uint32_t KeyType (.debug_str[0x0001023] => "main") |
| 2684 | | 0x00000004 | uint32_t HashData count |
| 2685 | | 0x........ | uint32_t HashData[0] DIE offset |
| 2686 | | 0x........ | uint32_t HashData[1] DIE offset |
| 2687 | | 0x........ | uint32_t HashData[2] DIE offset |
| 2688 | | 0x........ | uint32_t HashData[3] DIE offset |
| 2689 | | 0x00002023 | uint32_t KeyType (.debug_str[0x0002023] => "print") |
| 2690 | | 0x00000002 | uint32_t HashData count |
| 2691 | | 0x........ | uint32_t HashData[0] DIE offset |
| 2692 | | 0x........ | uint32_t HashData[1] DIE offset |
| 2693 | | 0x00000000 | uint32_t KeyType (end of hash chain) |
| 2694 | `------------' |
| 2695 | </pre> |
| 2696 | </div> |
| 2697 | <p>Current testing with real world C++ binaries has shown that there is around 1 |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2698 | 32 bit hash collision per 100,000 name entries.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2699 | </div> |
| 2700 | <!-- ======================================================================= --> |
| 2701 | <h4> |
| 2702 | <a name="acceltablecontents">Contents</a> |
| 2703 | </h4> |
| 2704 | <!-- ======================================================================= --> |
| 2705 | <div> |
| 2706 | <p>As we said, we want to strictly define exactly what is included in the |
| 2707 | different tables. For DWARF, we have 3 tables: ".apple_names", ".apple_types", |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2708 | and ".apple_namespaces".</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2709 | |
| 2710 | <p>".apple_names" sections should contain an entry for each DWARF DIE whose |
| 2711 | DW_TAG is a DW_TAG_label, DW_TAG_inlined_subroutine, or DW_TAG_subprogram that |
| 2712 | has address attributes: DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges or |
| 2713 | DW_AT_entry_pc. It also contains DW_TAG_variable DIEs that have a DW_OP_addr |
| 2714 | in the location (global and static variables). All global and static variables |
Benjamin Kramer | d9b0b02 | 2012-06-02 10:20:22 +0000 | [diff] [blame^] | 2715 | should be included, including those scoped within functions and classes. For |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2716 | example using the following code:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2717 | <div class="doc_code"> |
| 2718 | <pre> |
| 2719 | static int var = 0; |
| 2720 | |
| 2721 | void f () |
| 2722 | { |
| 2723 | static int var = 0; |
| 2724 | } |
| 2725 | </pre> |
| 2726 | </div> |
| 2727 | <p>Both of the static "var" variables would be included in the table. All |
| 2728 | functions should emit both their full names and their basenames. For C or C++, |
| 2729 | the full name is the mangled name (if available) which is usually in the |
| 2730 | DW_AT_MIPS_linkage_name attribute, and the DW_AT_name contains the function |
| 2731 | basename. If global or static variables have a mangled name in a |
| 2732 | DW_AT_MIPS_linkage_name attribute, this should be emitted along with the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2733 | simple name found in the DW_AT_name attribute.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2734 | |
| 2735 | <p>".apple_types" sections should contain an entry for each DWARF DIE whose |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2736 | tag is one of:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2737 | <ul> |
| 2738 | <li>DW_TAG_array_type</li> |
| 2739 | <li>DW_TAG_class_type</li> |
| 2740 | <li>DW_TAG_enumeration_type</li> |
| 2741 | <li>DW_TAG_pointer_type</li> |
| 2742 | <li>DW_TAG_reference_type</li> |
| 2743 | <li>DW_TAG_string_type</li> |
| 2744 | <li>DW_TAG_structure_type</li> |
| 2745 | <li>DW_TAG_subroutine_type</li> |
| 2746 | <li>DW_TAG_typedef</li> |
| 2747 | <li>DW_TAG_union_type</li> |
| 2748 | <li>DW_TAG_ptr_to_member_type</li> |
| 2749 | <li>DW_TAG_set_type</li> |
| 2750 | <li>DW_TAG_subrange_type</li> |
| 2751 | <li>DW_TAG_base_type</li> |
| 2752 | <li>DW_TAG_const_type</li> |
| 2753 | <li>DW_TAG_constant</li> |
| 2754 | <li>DW_TAG_file_type</li> |
| 2755 | <li>DW_TAG_namelist</li> |
| 2756 | <li>DW_TAG_packed_type</li> |
| 2757 | <li>DW_TAG_volatile_type</li> |
| 2758 | <li>DW_TAG_restrict_type</li> |
| 2759 | <li>DW_TAG_interface_type</li> |
| 2760 | <li>DW_TAG_unspecified_type</li> |
| 2761 | <li>DW_TAG_shared_type</li> |
| 2762 | </ul> |
| 2763 | <p>Only entries with a DW_AT_name attribute are included, and the entry must |
| 2764 | not be a forward declaration (DW_AT_declaration attribute with a non-zero value). |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2765 | For example, using the following code:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2766 | <div class="doc_code"> |
| 2767 | <pre> |
| 2768 | int main () |
| 2769 | { |
| 2770 | int *b = 0; |
| 2771 | return *b; |
| 2772 | } |
| 2773 | </pre> |
| 2774 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2775 | <p>We get a few type DIEs:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2776 | <div class="doc_code"> |
| 2777 | <pre> |
| 2778 | 0x00000067: TAG_base_type [5] |
| 2779 | AT_encoding( DW_ATE_signed ) |
| 2780 | AT_name( "int" ) |
| 2781 | AT_byte_size( 0x04 ) |
| 2782 | |
| 2783 | 0x0000006e: TAG_pointer_type [6] |
| 2784 | AT_type( {0x00000067} ( int ) ) |
| 2785 | AT_byte_size( 0x08 ) |
| 2786 | </pre> |
| 2787 | </div> |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2788 | <p>The DW_TAG_pointer_type is not included because it does not have a DW_AT_name.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2789 | |
| 2790 | <p>".apple_namespaces" section should contain all DW_TAG_namespace DIEs. If |
| 2791 | we run into a namespace that has no name this is an anonymous namespace, |
| 2792 | and the name should be output as "(anonymous namespace)" (without the quotes). |
| 2793 | Why? This matches the output of the abi::cxa_demangle() that is in the standard |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2794 | C++ library that demangles mangled names.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2795 | </div> |
| 2796 | |
| 2797 | <!-- ======================================================================= --> |
| 2798 | <h4> |
| 2799 | <a name="acceltableextensions">Language Extensions and File Format Changes</a> |
| 2800 | </h4> |
| 2801 | <!-- ======================================================================= --> |
| 2802 | <div> |
| 2803 | <h5>Objective-C Extensions</h5> |
| 2804 | <p>".apple_objc" section should contain all DW_TAG_subprogram DIEs for an |
| 2805 | Objective-C class. The name used in the hash table is the name of the |
| 2806 | Objective-C class itself. If the Objective-C class has a category, then an |
| 2807 | entry is made for both the class name without the category, and for the class |
| 2808 | name with the category. So if we have a DIE at offset 0x1234 with a name |
| 2809 | of method "-[NSString(my_additions) stringWithSpecialString:]", we would add |
| 2810 | an entry for "NSString" that points to DIE 0x1234, and an entry for |
| 2811 | "NSString(my_additions)" that points to 0x1234. This allows us to quickly |
| 2812 | track down all Objective-C methods for an Objective-C class when doing |
| 2813 | expressions. It is needed because of the dynamic nature of Objective-C where |
| 2814 | anyone can add methods to a class. The DWARF for Objective-C methods is also |
| 2815 | emitted differently from C++ classes where the methods are not usually |
| 2816 | contained in the class definition, they are scattered about across one or more |
| 2817 | compile units. Categories can also be defined in different shared libraries. |
| 2818 | So we need to be able to quickly find all of the methods and class functions |
| 2819 | given the Objective-C class name, or quickly find all methods and class |
| 2820 | functions for a class + category name. This table does not contain any selector |
| 2821 | names, it just maps Objective-C class names (or class names + category) to all |
| 2822 | of the methods and class functions. The selectors are added as function |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2823 | basenames in the .debug_names section.</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2824 | |
| 2825 | <p>In the ".apple_names" section for Objective-C functions, the full name is the |
| 2826 | entire function name with the brackets ("-[NSString stringWithCString:]") and the |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2827 | basename is the selector only ("stringWithCString:").</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2828 | |
| 2829 | <h5>Mach-O Changes</h5> |
| 2830 | <p>The sections names for the apple hash tables are for non mach-o files. For |
| 2831 | mach-o files, the sections should be contained in the "__DWARF" segment with |
Bill Wendling | 88a6808 | 2012-03-06 08:59:13 +0000 | [diff] [blame] | 2832 | names as follows:</p> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2833 | <ul> |
| 2834 | <li>".apple_names" -> "__apple_names"</li> |
| 2835 | <li>".apple_types" -> "__apple_types"</li> |
| 2836 | <li>".apple_namespaces" -> "__apple_namespac" (16 character limit)</li> |
| 2837 | <li> ".apple_objc" -> "__apple_objc"</li> |
| 2838 | </ul> |
| 2839 | </div> |
| 2840 | </div> |
NAKAMURA Takumi | 9c55f59 | 2012-03-27 11:25:16 +0000 | [diff] [blame] | 2841 | </div> |
Eric Christopher | 25e6329 | 2012-03-06 02:25:38 +0000 | [diff] [blame] | 2842 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 2843 | <!-- *********************************************************************** --> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 2844 | |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 2845 | <hr> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 2846 | <address> |
| 2847 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 2848 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 2849 | <a href="http://validator.w3.org/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 2850 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 2851 | |
| 2852 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
NAKAMURA Takumi | b9a3363 | 2011-04-09 02:13:37 +0000 | [diff] [blame] | 2853 | <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 2854 | Last modified: $Date$ |
Misha Brukman | 8287373 | 2004-05-12 19:21:57 +0000 | [diff] [blame] | 2855 | </address> |
Chris Lattner | bdfb339 | 2004-01-05 05:06:33 +0000 | [diff] [blame] | 2856 | |
| 2857 | </body> |
| 2858 | </html> |