question on generating dwarf metadata

I am writing a front end for a new language and am having trouble generating the DWARF debugging information. I'm outputting llvm assembly source so I'm trying to generate the "!metadata" stuff.

I have found the document <http://llvm.org/docs/SourceLevelDebugging.html&gt; a helpful start, as far as it goes. However, it doesn't quite match what I see clang produce when I use the flags "clang -g -S -emit-llvm ..." in all cases. And it is incomplete, for example, how does one deal with a function that returns multiple values?

I seem to get different results when I feed the .ll file to llc than when I feed it the clang, clang gives error messages when it doesn't like the metadata structure, llc appears not to do so.

Is there another document I should look at?

Should I be looking at source code? Where are the structures that start with DW_TAG's parsed?

In general, what's resources does a front end implementer have in order to understand how to generate the DWARF stuff via llvm assembly source?

thanks, bagel

We are working on a document. Here is current draft:
  http://wiki.llvm.org/Debug_Information

Hi Devang,

Do you think we should keep updating the wiki or in the HTML? Do we
need this doc to be in the release docs?

cheers,
--renato

While this is great news, it doesn't completely satisfy my needs. Your documentation assumes one is going to use the LLVM provided functions (such as DIFactory::). My front-end can't use them because it is not written in C or C++. I need to know the exact layouts of the LLVM assembly metadata -- the textual form -- and what the fields mean. The comments in your examples are close.

Perhaps you can add another section just on the textual format?

thanks, bagel

Oh, perhaps you're looking for this:

http://llvm.org/docs/SourceLevelDebugging.html

cheers,
--renato

If you look at my original posting in this thread, you'll see that I had already found that. I'm just looking for something more up-to-date, more complete, and more in depth.

thanks, bagel

As I understand, you are not interested in ‘how to use DIFactory’. Do you want to know what are the fields of metadata to encode debug info for a local variable ?
That’d be

!7 = metadata !{
  i32,      ;; Tag (see below)
  metadata, ;; Context
  metadata, ;; Name
  metadata, ;; Reference to file where defined
  i32,      ;; Line number where defined
  metadata  ;; Type descriptor
}

Eventually, this will become a html document "Writing an LLVM Pass".

Correct: I'm not interested in 'how to use DIFactory', and yes, I do want to know what the fields of metadata encode in somewhat more detail.

For example, I am struggling with the 'DW_TAG_subroutine_type' now. There is a field that is labeled:
     metadata, ;; Reference to array of member descriptors
Now I figured out that this array contains the types of the formal parameters, but it also appears the first (and only the first) in the array is the returned value type of the function. Since LLVM supports functions that return multiple values (as does my language), and DW_TAG_subroutine_type implementation currently supports, at most, a single returned value, this might be a bug. Looking at the code in lib/CodeGen/AsmPrinter/DwarfDebug.cpp around line 1035, this does appear to be the case.

thanks, bagel

As I understand, you are not interested in ‘how to use DIFactory’. Do you want
to know what are the fields of metadata to encode debug info for a local variable ?
That’d be

!7 = metadata !{
i32, ;; Tag (see below)
metadata, ;; Context
metadata, ;; Name
metadata, ;; Reference to file where defined
i32, ;; Line number where defined
metadata ;; Type descriptor
}

Devang

Correct: I’m not interested in ‘how to use DIFactory’, and yes, I do want to
know what the fields of metadata encode in somewhat more detail.

For example, I am struggling with the ‘DW_TAG_subroutine_type’ now. There is a
field that is labeled:
metadata, ;; Reference to array of member descriptors
Now I figured out that this array contains the types of the formal parameters,
but it also appears the first (and only the first) in the array is the returned
value type of the function. Since LLVM supports functions that return multiple
values (as does my language), and DW_TAG_subroutine_type implementation
currently supports, at most, a single returned value, this might be a bug.
Looking at the code in lib/CodeGen/AsmPrinter/DwarfDebug.cpp around line 1035,
this does appear to be the case.

If you haven’t already read the DWARF specification documents, then I recommend looking at them if you’re not going to be using DIFactory. You can find them here: http://dwarfstd.org/Download.php

I have 'looked' at them. I fear that probably the only people that understand them are the people that wrote them :slight_smile:

And that still leaves the 'magic' that maps the metadata structures into DWARF information to be learned.

Bagel

Indeed, it is a bug/missing feature. Please file a bugzilla PR to track this. One approach to solve this would be to use DIArray as return type in case of multiple return values.

Done. http://llvm.org/bugs/show_bug.cgi?id=8772

Bagel