From 8ff759072f5dd1fd4158944c90d1f1c93cc2f047 Mon Sep 17 00:00:00 2001
From: Chris Lattner
See the variable argument processing section.
+ +LLVM supports the notion of an "intrinsic function". These functions have well known names and semantics, and are required to @@ -1609,9 +1612,12 @@ required that they all be documented here if any are added.
lowering pass to eliminate the intrinsic or all backends must support the intrinsic function.Variable argument support is defined in LLVM with the vanext instruction and these three @@ -1631,9 +1637,13 @@ used.
href="#i_va_end">llvm.va_end(sbyte* %aq)call va_list ()* %llvm.va_start()@@ -1650,9 +1660,12 @@ last argument of the function, the compiler can figure that out.
Note that this intrinsic function is only legal to be called from within the body of a variable argument function.
call void (va_list)* %llvm.va_end(va_list <arglist>)@@ -1669,9 +1682,12 @@ Calls to llvm.va_start and llvm.va_copy must be matched exactly with calls to llvm.va_end.
call va_list (va_list)* %llvm.va_copy(va_list <destarglist>)@@ -1687,6 +1703,23 @@ element into the returned list. This intrinsic is necessary because the llvm.va_start intrinsic may be arbitrarily complex and require memory allocation, for example.
+The LLVM debugger intrinsics (which all start with llvm.dbg. prefix), +are described in the LLVM Source Level +Debugging document. +
+llvm-db is the first LLVM debugger, and as such was designed to be -quick to prototype and build, and simple to extend. It is missing many many -features, though they should be easy to add over time (patches welcomed!). -Because the (currently only) debugger backend (implemented in -"lib/Debugger/UnixLocalInferiorProcess.cpp") was designed to work without any -cooperation from the code generators, it suffers from the following inherent -limitations:
+llvm-db is designed to be modular and easy to extend. This +extensibility was key to getting the debugger up-and-running quickly, because we +can start with simple-but-unsophisicated implementations of various components. +Because of this, it is currently missing many features, though they should be +easy to add over time (patches welcomed!). The biggest inherent limitations of +llvm-db are currently due to extremely simple debugger backend (implemented in +"lib/Debugger/UnixLocalInferiorProcess.cpp") which is designed to work without +any cooperation from the code generators. Because it is so simple, it suffers +from the following inherent limitations:
That said, it is still quite useful, and all of these limitations can be -eliminated by integrating support for the debugger into the code generators. -See the future work section for ideas of how to extend -the LLVM debugger despite these 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 +generators, and writing a new InferiorProcess +subclass to use it. See the future work section for ideas +of how to extend the LLVM debugger despite these limitations.
-TODO -
+TODO: this is obviously lame, when more is implemented, this can be much +better.
+ ++$ llvm-db funccall +llvm-db: The LLVM source-level debugger +Loading program... successfully loaded 'funccall.bc'! +(llvm-db) create +Starting program: funccall.bc +main at funccall.c:9:2 +9 -> q = 0; +(llvm-db) list main +4 void foo() { +5 int t = q; +6 q = t + 1; +7 } +8 int main() { +9 -> q = 0; +10 foo(); +11 q = q - 1; +12 +13 return q; +(llvm-db) list +14 } +(llvm-db) step +10 -> foo(); +(llvm-db) s +foo at funccall.c:5:2 +5 -> int t = q; +(llvm-db) bt +#0 -> 0x85ffba0 in foo at funccall.c:5:2 +#1 0x85ffd98 in main at funccall.c:10:2 +(llvm-db) finish +main at funccall.c:11:2 +11 -> q = q - 1; +(llvm-db) s +13 -> return q; +(llvm-db) s +The program stopped with exit code 0 +(llvm-db) quit +$ +
-lib/Debugger - - UnixLocalInferiorProcess.cpp ++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 +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 +class. This class is used to represent an instance of the program running under +debugger control. The InferiorProcess class can be implemented in different +ways for different targets and execution scenarios (e.g., remote debugging). +The InferiorProcess class exposes a small and simple collection of interfaces +which are useful for inspecting the current state of the program (such as +collecting stack trace information, reading the memory image of the process, +etc). The interfaces in this class are designed to be as low-level and simple +as possible, to make it easy to create new instances of the class. +
+ ++The Debugger class exposes the currently active instance of InferiorProcess +through the Debugger::getRunningProcess method, which returns a +const reference to the class. This means that clients of the Debugger +class can only inspect the running instance of the program directly. To +change the executing process in some way, they must use the interces exposed by +the Debugger class. +
++The next-highest level of debugger abstraction is provided through the +ProgramInfo, RuntimeInfo, SourceLanguage and related classes (also defined in +the include/llvm/Debugger/ directory). These classes efficiently +decode the debugging information and low-level interfaces exposed by +InferiorProcess into a higher-level representation, suitable for analysis by the +debugger. +
+ ++The ProgramInfo class exposes a variety of different kinds of information about +the program objects in the source-level-language. The SourceFileInfo class +represents a source-file in the program (e.g. a .cpp or .h file). The +SourceFileInfo class captures information such as which SourceLanguage was used +to compile the file, where the debugger can get access to the actual file text +(which is lazily loaded on demand), etc. The SourceFunctionInfo class +represents a... FIXME: finish. The ProgramInfo class provides interfaces +to lazily find and decode the information needed to create the Source*Info +classes requested by the debugger. +
+ ++The RuntimeInfo class exposes information about the currently executed program, +by decoding information from the InferiorProcess and ProgramInfo classes. It +provides a StackFrame class which provides an easy-to-use interface for +inspecting the current and suspended stack frames in the program. +
+ ++The SourceLanguage class is an abstract interface used by the debugger to +perform all source-language-specific tasks. For example, this interface is used +by the ProgramInfo class to decode language-specific types and functions and by +the debugger front-end (such as llvm-db to +evaluate source-langauge expressions typed into the debugger. This class uses +the RuntimeInfo & ProgramInfo classes to get information about the current +execution context and the loaded program, respectively. +
+The llvm-db is designed to be a debugger providing an interface as similar to GDB as reasonable, but no more so than that. +Because the Debugger and info classes implement all of the heavy lifting and +analysis, llvm-db (which lives in llvm/tools/llvm-db) consists +mainly of of code to interact with the user and parse commands. The CLIDebugger +constructor registers all of the builtin commands for the debugger, and each +command is implemented as a CLIDebugger::[name]Command method. +
+-run (with args) & set args: These need to be implemented. -Currently run doesn't support setting arguments as part of the command. The -only tricky thing is handling quotes right and stuff.
-UnixLocalInferiorProcess.cpp speedup: There is no reason for the debugged process to code gen the globals corresponding to debug information. The @@ -468,11 +618,16 @@ casts of the constant address of the LLVM objects for the descriptors. This would also allow us to eliminate the mapping back and forth between physical addresses that must be done.
++Process deaths: The InferiorProcessDead exception should be extended to +know "how" a process died, i.e., it was killed by a signal. This is easy to +collect in the UnixLocalInferiorProcess, we just need to represent it.
+The debugger is designed to be agnostic about the contents of most of the -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. +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 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, global objects (aka methods, messages, global -variables, etc), and local variables. -These abstract objects are used by the debugger to form stack traces, show -information about local variables, etc. +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.
This section of the documentation first describes the representation aspects -common to any source-language. The next section -describes the data layout conventions used by the C and C++ -front-ends.
+common to any source-language. The next section +describes the data layout conventions used by the C and C++ front-ends.- %llvm.dbg.translation_units = linkonce global {} {} - %llvm.dbg.globals = linkonce global {} {} + %llvm.dbg.translation_units = linkonce global {} {} + %llvm.dbg.globals = linkonce global {} {}
@@ -560,7 +714,7 @@ deleted.
@@ -574,8 +728,9 @@ front-end inserts calls to the %llvm.dbg.stoppoint intrinsic function at every point in the program where the debugger should be able to inspect the program (these correspond to places the debugger stops when you "step" through it). The front-end can choose to place these as fine-grained as it -would like (for example, before every subexpression was evaluated), but it is -recommended to only put them after every source statement. +would like (for example, before every subexpression evaluated), but it is +recommended to only put them after every source statement that includes +executable code.Using calls to this intrinsic function to demark legal points for the debugger @@ -585,21 +740,22 @@ 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, such as code motion of non-trapping instructions, nor does it impact -optimization of subexpressions, or any other code between the stop points.
+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 next section.
+stop point. For a concrete example of stop points, see the example in the next section.-Representing the boundaries of functions with regions allows normal LLVM -interprocedural optimizations to change the boundaries of functions without -having to worry about breaking mapping information between LLVM and source-level -functions. In particular, the inlining optimization requires no modification to -support inlining with debugging information: there is no correlation drawn -between LLVM functions and their source-level counterparts.
+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 +drawn between LLVM functions and their source-level counterparts (note however, +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 +href="#format_common_stoppoint">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 @@ -708,10 +867,9 @@ introduced because they go out of scope at the same point in the program: line 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. Through the use of LLVM debugger regions, -arbitrary source-language scoping rules can be supported, as long as they can -only be nested (ie, one scope cannot partially overlap with a part of another -scope). +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).
@@ -719,7 +877,7 @@ 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 yet implemented). +not implemented yet).
-The LLVM debugger expects the descriptors for global 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. All LLVM debugging information is versioned, allowing -backwards compatibility in the case that the core structures need to change in -some way. The lowest-level descriptor are those describing the files containing the program source -code, all other descriptors refer to them. +appended at the end that is source-language specific. All LLVM debugging +information is versioned, allowing backwards compatibility in the case that the +core structures need to change in some way. Also, all debugging information +objects start with a tag to indicate what type +of object it is. The source-language is allows to define its own objects, by +using unreserved tag numbers.
+ +The lowest-level descriptor are those describing the files containing the program source +code, as most other descriptors (sometimes indirectly) refer to them.
-Source file descriptors were roughly patterned after the Dwarf "compile_unit" -object. The descriptor currently is defined to have the following LLVM -type:
+Source file descriptors are patterned after the Dwarf "compile_unit" object. +The descriptor currently is defined to have at least the following LLVM +type entries:%lldb.compile_unit = type { + uint, ;; Tag: LLVM_COMPILE_UNIT ushort, ;; LLVM debug version number ushort, ;; Dwarf language identifier sbyte*, ;; Filename sbyte*, ;; Working directory when compiled - sbyte*, ;; Producer of the debug information - {}* ;; Anchor for llvm.dbg.translation_units + sbyte* ;; Producer of the debug information }@@ -770,13 +933,16 @@ These descriptors contain the version number for the debug info, a source language ID for the file (we use the Dwarf 3.0 ID numbers, such as DW_LANG_C89, DW_LANG_C_plus_plus, DW_LANG_Cobol74, etc), three strings describing the filename, working directory of the compiler, -and an identifier string for the compiler that produced it, and the anchor for the descriptor. Here is an example +and an identifier string for the compiler that produced it. Note that actual +compile_unit declarations must also include an anchor to llvm.dbg.translation_units, +but it is not specified where the anchor is to be located. Here is an example descriptor:
%arraytest_source_file = internal constant %lldb.compile_unit { + uint 17, ; Tag value ushort 0, ; Version #0 ushort 1, ; DW_LANG_C89 sbyte* getelementptr ([12 x sbyte]* %.str_1, long 0, long 0), ; filename @@ -789,78 +955,126 @@ descriptor: %.str_3 = internal constant [12 x sbyte] c"llvmgcc 3.4\00"+
+Note that the LLVM constant merging pass should eliminate duplicate copies of +the strings that get emitted to each translation unit, such as the producer. +
-The LLVM debugger needs to know what the source-language global objects, in -order to build stack traces and other related activities. Because -source-languages have widly varying forms of global objects, the LLVM debugger -only expects the following fields in the descriptor for each global: +The LLVM debugger needs to know about some source-language program objects, in +order to build stack traces, print information about local variables, and other +related activities. The LLVM debugger differentiates between three different +types of program objects: subprograms (functions, messages, methods, etc), +variables (locals and globals), and others. Because source-languages have +widely varying forms of these objects, the LLVM debugger expects only a few +fields in the descriptor for each object:
-%lldb.global = type { - %lldb.compile_unit*, ;; The translation unit containing the global - sbyte*, ;; The global object 'name' - [type]*, ;; Source-language type descriptor for global - {}* ;; The anchor for llvm.dbg.globals +%lldb.object = type { + uint, ;; A tag + any*, ;; The context for the object + sbyte* ;; The object 'name' }
-The first field contains a pointer to the translation unit the function is -defined in. This pointer allows the debugger to find out which version of debug -information the function corresponds to. The second field contains a string -that the debugger can use to identify the subprogram if it does not contain -explicit support for the source-language in use. This should be some sort of -unmangled string that corresponds to the function somehow. +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 +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. +href="#ccxx_descriptors">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.
+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 +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. +
++ LLVM_COMPILE_UNIT : 17 + LLVM_SUBPROGRAM : 46 + LLVM_VARIABLE : 52 + +
+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. +
-TODO: document extensions to standard debugging objects, document how we -represent source types, etc. +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.
+Translation units do not add any information over the standard source file representation already +expected by the debugger. As such, it uses descriptors of the type specified, +with a trailing anchor. +
++ +
++ +
+