From 828737355af1081677090e3c61ff27363a636efc Mon Sep 17 00:00:00 2001
From: Misha Brukman
-The idea of the LLVM debugging information is to capture how the important
+ The idea of the LLVM debugging information is to capture how the important
pieces of the source-language's Abstract Syntax Tree map onto LLVM code.
Several design aspects have shaped the solution that appears here. The
important ones are:
-The approach used by the LLVM implementation is to use a small set of The approach used by the LLVM implementation is to use a small set of intrinsic functions to define a mapping
between LLVM program objects and the source-level objects. The description of
the source-level program is maintained in LLVM global variables in an implementation-defined format (the C/C++ front-end
currently uses working draft 7 of the Dwarf 3 standard).
-When a program is debugged, the debugger interacts with the user and turns the
-stored debug information into source-language specific information. As such,
-the debugger must be aware of the source-language, and is thus tied to a
+ When a program is debugged, the debugger interacts with the user and turns
+the stored debug information into source-language specific information. As
+such, the debugger must be aware of the source-language, and is thus tied to a
specific language of family of languages. The LLVM
-debugger is designed to be modular in its support for source-languages.
-
-An extremely high priority of LLVM debugging information is to make it interact
-well with optimizations and analysis. In particular, the LLVM debug information
-provides the following guarantees: An extremely high priority of LLVM debugging information is to make it
+interact well with optimizations and analysis. In particular, the LLVM debug
+information provides the following guarantees:
-Basically, the debug information allows you to compile a program with "-O0
--g" and get full debug information, allowing you to arbitrarily modify the
-program as it executes from the debugger. Compiling a program with "-O3
--g" gives you full debug information that is always available and accurate
-for reading (e.g., you get accurate stack traces despite tail call elimination
-and inlining), but you might lose the ability to modify the program and call
-functions where were optimized out of the program, or inlined away completely.
- Basically, the debug information allows you to compile a program with
+"-O0 -g" and get full debug information, allowing you to arbitrarily
+modify the program as it executes from the debugger. Compiling a program with
+"-O3 -g" gives you full debug information that is always available and
+accurate for reading (e.g., you get accurate stack traces despite tail call
+elimination and inlining), but you might lose the ability to modify the program
+and call functions where were optimized out of the program, or inlined away
+completely.
-There are several important extensions that could be eventually added to the
+ There are several important extensions that could be eventually added to the
LLVM debugger. The most important extension would be to upgrade the LLVM code
generators to support debugging information. This would also allow, for
example, the X86 code generator to emit native objects that contain debugging
information consumable by traditional source-level debuggers like GDB or
DBX.
-Additionally, LLVM optimizations can be upgraded to incrementally update the
+ Additionally, LLVM optimizations can be upgraded to incrementally update the
debugging information, new commands can be added to the
debugger, and thread support could be added to the debugger.
-The "SourceLanguage" modules provided by llvm-db could be substantially
-improved to provide good support for C++ language features like namespaces and
-scoping rules. The "SourceLanguage" modules provided by llvm-db could be
+substantially improved to provide good support for C++ language features like
+namespaces and scoping rules.
-After working with the debugger for a while, perhaps the nicest improvement
+ After working with the debugger for a while, perhaps the nicest improvement
would be to add some sort of line editor, such as GNU readline (but one that is
compatible with the LLVM license).
-For someone so inclined, it should be straight-forward to write different
+ For someone so inclined, it should be straight-forward to write different
front-ends for the LLVM debugger, as the LLVM debugging engine is cleanly
separated from the llvm-db front-end. A new LLVM GUI debugger or IDE
-would be nice. :)
-
-The llvm-db tool provides a GDB-like interface for source-level
+ The llvm-db tool provides a GDB-like interface for source-level
debugging of programs. This tool provides many standard commands for inspecting
and modifying the program as it executes, loading new programs, single stepping,
-placing breakpoints, etc. This section describes how to use the debugger.
- llvm-db has been designed to be as similar to GDB in its user
interface as possible. This should make it extremely easy to learn
@@ -273,7 +266,7 @@ href="#arch_debugger">debugger backend (implemented in
any cooperation from the code generators. Because it is so simple, it suffers
from the following inherent limitations: That said, the debugger is still quite useful, and all of these limitations
can be eliminated by integrating support for the debugger into the code
@@ -313,7 +306,7 @@ of how to extend the LLVM debugger despite these limitations. TODO: this is obviously lame, when more is implemented, this can be much
better.
-The LLVM debugger is built out of three distinct layers of software. These
+ The LLVM debugger is built out of three distinct layers of software. These
layers provide clients with different interface options depending on what pieces
of they want to implement themselves, and it also promotes code modularity and
good design. The three layers are the Debugger
-interface, the "info" interfaces, and the
-llvm-db tool itself.
-
-The Debugger class (defined in the include/llvm/Debugger/ directory) is
-a low-level class which is used to maintain information about the loaded
+ The Debugger class (defined in the include/llvm/Debugger/ directory)
+is a low-level class which is used to maintain information about the loaded
program, as well as start and stop the program running as necessary. This class
does not provide any high-level analysis or control over the program, only
exposing simple interfaces like load/unloadProgram,
create/killProgram, step/next/finish/contProgram, and
-low-level methods for installing breakpoints.
-
The Debugger class is itself a wrapper around the lowest-level InferiorProcess
@@ -656,17 +644,15 @@ debugging information. It uses a source-language-specific
module to decode the information that represents variables, types,
functions, namespaces, etc: this allows for arbitrary source-language semantics
and type-systems to be used, as long as there is a module written for the
-debugger to interpret the information.
-
-To provide basic functionality, the LLVM debugger does have to make some
+ To provide basic functionality, the LLVM debugger does have to make some
assumptions about the source-level language being debugged, though it keeps
these to a minimum. The only common features that the LLVM debugger assumes
exist are source files, and program objects. These abstract objects are
used by the debugger to form stack traces, show information about local
-variables, etc.
+variables, etc. This section of the documentation first describes the representation aspects
common to any source-language. The next section
@@ -680,38 +666,32 @@ describes the data layout conventions used by the C and C++ front-ends.
-One important aspect of the LLVM debug representation is that it allows the LLVM
-debugger to efficiently index all of the global objects without having the scan
-the program. To do this, all of the global objects use "anchor" globals of type
-"{}", with designated names. These anchor objects obviously do not
-contain any content or meaning by themselves, but all of the global objects of a
-particular type (e.g., source file descriptors) contain a pointer to the anchor.
-This pointer allows the debugger to use def-use chains to find all global
-objects of that type.
-
-So far, the following names are recognized as anchors by the LLVM debugger:
- One important aspect of the LLVM debug representation is that it allows the
+LLVM debugger to efficiently index all of the global objects without having the
+scan the program. To do this, all of the global objects use "anchor" globals of
+type "{}", with designated names. These anchor objects obviously do
+not contain any content or meaning by themselves, but all of the global objects
+of a particular type (e.g., source file descriptors) contain a pointer to the
+anchor. This pointer allows the debugger to use def-use chains to find all
+global objects of that type. So far, the following names are recognized as anchors by the LLVM
+debugger:
-Using anchors in this way (where the source file descriptor points to the
+ Using anchors in this way (where the source file descriptor points to the
anchors, as opposed to having a list of source file descriptors) allows for the
standard dead global elimination and merging passes to automatically remove
unused debugging information. If the globals were kept track of through lists,
there would always be an object pointing to the descriptors, thus would never be
-deleted.
-
-Using calls to this intrinsic function to demark legal points for the debugger
-to inspect the program automatically disables any optimizations that could
-potentially confuse debugging information. To non-debug-information-aware
+ Using calls to this intrinsic function to demark legal points for the
+debugger to inspect the program automatically disables any optimizations that
+could potentially confuse debugging information. To non-debug-information-aware
transformations, these calls simply look like calls to an external function,
which they must assume to do anything (including reading or writing to any part
of reachable memory). On the other hand, it does not impact many optimizations,
@@ -743,12 +722,11 @@ such as code motion of non-trapping instructions, nor does it impact
optimization of subexpressions, code duplication transformations, or basic-block
reordering transformations.
-An important aspect of the calls to the %llvm.dbg.stoppoint intrinsic
-is that the function-local debugging information is woven together with use-def
-chains. This makes it easy for the debugger to, for example, locate the 'next'
-stop point. For a concrete example of stop points, see the example in the next section. An important aspect of the calls to the %llvm.dbg.stoppoint
+intrinsic is that the function-local debugging information is woven together
+with use-def chains. This makes it easy for the debugger to, for example,
+locate the 'next' stop point. For a concrete example of stop points, see the
+example in the next section.
+
-
+
+
-
+
+
+
+
$ llvm-db funccall
llvm-db: The LLVM source-level debugger
Loading program... successfully loaded 'funccall.bc'!
@@ -351,7 +344,7 @@ main at funccall.c:11:2
The program stopped with exit code 0
(llvm-db) quit
$
-
+
+
-
%llvm.dbg.translation_units = linkonce global {} {}
%llvm.dbg.globals = linkonce global {} {}
-
+
-In many languages, the local variables in functions can have their lifetime or -scope limited to a subset of a function. In the C family of languages, for +
In many languages, the local variables in functions can have their lifetime +or scope limited to a subset of a function. In the C family of languages, for example, variables are only live (readable and writable) within the source block that they are defined in. In functional languages, values are only readable after they have been defined. Though this is a very obvious concept, it is also non-trivial to model in LLVM, because it has no notion of scoping in this sense, -and does not want to be tied to a language's scoping rules. -
+and does not want to be tied to a language's scoping rules. --In order to handle this, the LLVM debug format uses the notion of "regions" of a -function, delineated by calls to intrinsic functions. These intrinsic functions -define new regions of the program and indicate when the region lifetime expires. -Consider the following C fragment, for example: -
+In order to handle this, the LLVM debug format uses the notion of "regions" +of a function, delineated by calls to intrinsic functions. These intrinsic +functions define new regions of the program and indicate when the region +lifetime expires. Consider the following C fragment, for example:
-+-1. void foo() { 2. int X = ...; 3. int Y = ...; @@ -786,14 +760,12 @@ Consider the following C fragment, for example: 7. } 8. ... 9. } -+
-Compiled to LLVM, this function would be represented like this (FIXME: CHECK AND -UPDATE THIS): -
+Compiled to LLVM, this function would be represented like this (FIXME: CHECK +AND UPDATE THIS):
-+-void %foo() { %X = alloca int %Y = alloca int @@ -822,18 +794,16 @@ void %foo() { %D12 = call {}* %llvm.region.end({}* %D11) ret void } -+
-This example illustrates a few important details about the LLVM debugging +
This example illustrates a few important details about the LLVM debugging information. In particular, it shows how the various intrinsics used are woven together with def-use and use-def chains, similar to how anchors are used with globals. This allows the -debugger to analyze the relationship between statements, variable definitions, -and the code used to implement the function.
+href="#format_common_anchors">anchors are used with globals. This allows +the debugger to analyze the relationship between statements, variable +definitions, and the code used to implement the function. --In this example, two explicit regions are defined, one with the In this example, two explicit regions are defined, one with the definition of the %D1 variable and one with the definition of %D7. In the case of %D1, the debug information indicates that the function whose descriptor is specified as an argument to the intrinsic. This defines a new stack frame whose lifetime ends when the region is ended by the %D12 call.
--Using regions to represent the boundaries of source-level functions allow LLVM -interprocedural optimizations to arbitrarily modify LLVM functions without +
Using regions to represent the boundaries of source-level functions allow +LLVM interprocedural optimizations to arbitrarily modify LLVM functions without having to worry about breaking mapping information between the LLVM code and the and source-level program. In particular, the inliner requires no modification to support inlining with debugging information: there is no explicit correlation @@ -852,45 +821,37 @@ that if the inliner inlines all instances of a non-strong-linkage function into its caller that it will not be possible for the user to manually invoke the inlined function from the debugger).
--Once the function has been defined, the stopping point corresponding to line #2 of the -function is encountered. At this point in the function, no local +
Once the function has been defined, the stopping point corresponding to line #2 of +the function is encountered. At this point in the function, no local variables are live. As lines 2 and 3 of the example are executed, their variable definitions are automatically introduced into the program, without the need to specify a new region. These variables do not require new regions to be introduced because they go out of scope at the same point in the program: line -9. -
+9. -
-In contrast, the Z variable goes out of scope at a different time, on
-line 7. For this reason, it is defined within the
+ In contrast, the Z variable goes out of scope at a different time,
+on line 7. For this reason, it is defined within the
%D7 region, which kills the availability of Z before the
code for line 8 is executed. In this way, regions can support arbitrary
source-language scoping rules, as long as they can only be nested (ie, one scope
-cannot partially overlap with a part of another scope).
-
-It is worth noting that this scoping mechanism is used to control scoping of all -declarations, not just variable declarations. For example, the scope of a C++ -using declaration is controlled with this, and the llvm-db C++ support -routines could use this to change how name lookup is performed (though this is -not implemented yet). -
+It is worth noting that this scoping mechanism is used to control scoping of +all declarations, not just variable declarations. For example, the scope of a +C++ using declaration is controlled with this, and the llvm-db C++ +support routines could use this to change how name lookup is performed (though +this is not implemented yet).
-The LLVM debugger expects the descriptors for program objects to start in a +
The LLVM debugger expects the descriptors for program objects to start in a canonical format, but the descriptors can include additional information appended at the end that is source-language specific. All LLVM debugging information is versioned, allowing backwards compatibility in the case that the @@ -906,7 +867,7 @@ code, as most other descriptors (sometimes indirectly) refer to them.
+-%lldb.object = type { uint, ;; A tag any*, ;; The context for the object sbyte* ;; The object 'name' } -+
-The first field contains a tag for the descriptor. The second field contains +
The first field contains a tag for the descriptor. The second field contains either a pointer to the descriptor for the containing source file, or it contains a pointer to another program object whose context pointer eventually reaches a source file. Through this context pointer, the LLVM debugger can establish the debug version number of the object.
--The third field contains a string that the debugger can use to identify the +
The third field contains a string that the debugger can use to identify the object if it does not contain explicit support for the source-language in use (ie, the 'unknown' source language handler uses this string). This should be some sort of unmangled string that corresponds to the object, but it is a quality of implementation issue what exactly it contains (it is legal, though -not useful, for all of these strings to be null). -
- --Note again that descriptors can be extended to include source-language-specific -information in addition to the fields required by the LLVM debugger. See the section on the C/C++ front-end for more -information. Also remember that global objects (functions, selectors, global -variables, etc) must contain an anchor to -the llvm.dbg.globals variable. -
+not useful, for all of these strings to be null). + +Note again that descriptors can be extended to include +source-language-specific information in addition to the fields required by the +LLVM debugger. See the section on the C/C++ +front-end for more information. Also remember that global objects +(functions, selectors, global variables, etc) must contain an anchor to the llvm.dbg.globals +variable.
@@ -1021,22 +978,20 @@ the llvm.dbg.globals variable.+Allow source-language specific contexts, use to identify namespaces etc Must end up in a source file descriptor. Debugger core ignores all unknown context objects. -+
+Define each intrinsics, as an extension of the language reference manual. llvm.dbg.stoppoint @@ -1044,11 +999,9 @@ llvm.dbg.region.start llvm.dbg.region.end llvm.dbg.function.start llvm.dbg.declare -+
-Happen to be the same value as the similarly named Dwarf-3 tags, this may change -in the future. -
+Happen to be the same value as the similarly named Dwarf-3 tags, this may +change in the future.
- -+LLVM_COMPILE_UNIT : 17 LLVM_SUBPROGRAM : 46 LLVM_VARIABLE : 52 -+
-The C and C++ front-ends represent information about the program in a format +
The C and C++ front-ends represent information about the program in a format that is effectively identical to Dwarf 3.0 in terms of information content. This allows code generators to trivially support native debuggers by generating standard dwarf information, and contains enough information for non-dwarf targets to translate it as needed.
--The basic debug information required by the debugger is (intentionally) designed -to be as minimal as possible. This basic information is so minimal that it is -unlikely that any source-language could be adequately described by it. -Because of this, the debugger format was designed for extension to support -source-language-specific information. The extended descriptors are read and -interpreted by the language-specific modules in the -debugger if there is support available, otherwise it is ignored. -
+The basic debug information required by the debugger is (intentionally) +designed to be as minimal as possible. This basic information is so minimal +that it is unlikely that any source-language could be adequately +described by it. Because of this, the debugger format was designed for +extension to support source-language-specific information. The extended +descriptors are read and interpreted by the language-specific modules in the debugger if there is +support available, otherwise it is ignored.
--This section describes the extensions used to represent C and C++ programs. +
This section describes the extensions used to represent C and C++ programs. Other languages could pattern themselves after this (which itself is tuned to representing programs in the same way that Dwarf 3 does), or they could choose to provide completely different extensions if they don't fit into the Dwarf model. As support for debugging information gets added to the various LLVM -source-language front-ends, the information used should be documented here. -
+source-language front-ends, the information used should be documented here.- -
+TODO
- -
+TODO
- -
+TODO