[LLVMdev] debugging info questions
Chris Lattner
sabre at nondot.org
Tue Oct 5 07:16:46 PDT 2004
On Mon, 4 Oct 2004, Michael McCracken wrote:
> Hi, It's taking me a while to get familiar with the cfe in order to
> add emitting stop points for debugging. It's a lot to work through, so
> in order to speed things up, I've got a few questions. Any help would
> be appreciated.
Sure, I will do what I can. :)
> I understand the design of the intrinsics once they're in the code,
> but how to generate them is still a little fuzzy, mainly because
> llvm_expand is a little complicated. (I blame C++).
Why blame C++? llvm_expand is a C function :). Also, it's a lot
complicated, not just a little complicated :)
One header that should be useful to you is the llvm-representation.h file,
which defines the important data structures for the C llvm IR.
> - What types are the ones declared as {}* ? It isn't void, but I don't
> see a type declaration for it in llvm* in the cfe.
"{}" is a struct type with zero elements, and "{}*" is a pointer to that
type. To get this type, you would do something like this:
llvm_type *ST, *PST;
ST = llvm_type_create_struct(0, 0);
ST = llvm_type_get_cannonical_struct(ST);
PST = llvm_type_get_pointer(ST);
> - I can see how I would generate the calls to the llvm.dbg.stoppoint
> intrinsic, but it isn't as clear how I'd generate the global anchors,
> string constants, or compile_unit constants.
These are all global variables in the LLVM IR, which that they are
instances of llvm_global in the CFE. To create one, use llvm_global_new
to create the global (given a type and a name), and then fill in the
fields as you need to. Something like this:
llvm_global *newG = llvm_global_new(GlobalType, "myglobalname");
newG->isConstant = 1;
newG->Init = ...;
In general, if you'd like to figure out how to create a global variable or
something like that, grep llvm-expand.c for llvm_global_new, and see how
it is done by other parts of the front-end.
> - I understand how the def-use links work to chain the debug
> statements together, but on a strictly time-saving basis, it seems
> like it'd still be valid to only insert stoppoints and not
> declarations - just less useful. Is that the case, or would it be
> invalid asm?
I'm not sure what you mean here. The C front-end does not maintain full
def-use and use-def chains like the normal LLVM IR does (it just has
use-def chains). In the end, all you need to do is get the correct .ll
file printed from the C Front-end, and the asmparser will reconstruct them
when it parses the result.
If by "declarations" you mean the %llvm.dbg.translation_units and
%lldb.compile_unit globals, I don't think they should be too hard to add,
and they definitely are needed.
> My motivation here is that I need line numbers, but not for use in the
> debugger, so declaration type info is not really important to me right
> now. (Although I'd love to help make the debugger fully useful)
Ok, if by declarations you mean user variables and all of the other fun
stuff that full debug info needs, you're right: you should be able to just
emit %llvm.dbg.stoppoint intrinsics, the translation unit declarations,
and the %llvm.dbg.translation_units anchor.
-Chris
--
http://llvm.org/
http://nondot.org/sabre/
More information about the llvm-dev
mailing list