<div dir="ltr">Easiest way is to look at how clang generates debug info. See clang/lib/CodeGen/CGDebugInfo.cpp.<div><br></div><div>-eric</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Dec 28, 2012 at 9:33 AM, Mario de Sousa <span dir="ltr"><<a href="mailto:msousa@fe.up.pt" target="_blank">msousa@fe.up.pt</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Hello all,<br>
<br>
<br>
Summary & Context:<br>
-------------------------------<br>
I am starting to write a front-end for some domain specific programming<br>
languages. Code generation seems to be working fine.<br>
<br>
However, I am having trouble generating debug info, to be used by gdb.<br>
<br>
<br>
The problem:<br>
--------------------<br>
I generate a foo.ll file, that is later compiled into an executable foo.<br>
<br>
The foo.ll file I generate already contains metadata for datatypes, compile<br>
unit, subprograms, etc...<br>
<br>
When debuging foo with ddd, I get the message that the file<br>
<root_path>/sysdeps/i386/elf/start.S<br>
does not exist. In other words, the debugger does not seem to know about the<br>
existence of foo.xx, the original source file.<br>
<br>
I have compiled a small helloworld.c program, and compared the debug info in<br>
helloworld and foo, using 'readelf --debug-dump'.<br>
<br>
I have noticed that in helloworld, the .debug_aranges section has 2 address<br>
ranges,<br>
- one pointing to a DW_TAG_compile_unit referencing the<br>
/sysdeps/i386/elf/start.S file<br>
- the other pointing to a DW_TAG_compile_unit with the helloworld,c file.<br>
<br>
However, in the foo program, the .debug_aranges section has only 1 address<br>
range, pointing to a DW_TAG_compile_unit referencing the<br>
/sysdeps/i386/elf/start.S file.<br>
The second DW_TAG_compile_unit referencing the foo.xx file is present in the<br>
.debug_info section, but is not being referenced!<br>
<br>
Strangely, some information that seems to be an address range referencing the<br>
foo.xx DW_TAG_compile_unit, is present in the .debug_pubtypes section. Why is<br>
this in the wrong section??<br>
<br>
<br>
<br>
The question:<br>
=========<br>
<br>
Does anybody have any idea what it is I am doing wrong?<br>
<br>
The issue seems to be related to generating the info for a CompileUnit.<br>
Currently, I am doing this:<br>
dibuilder = new DIBuilder(themodule);<br>
dibuilder->createCompileUnit(Lang,<br>
StringRef("foo.xx")), /*finename*/<br>
StringRef(".") /*Dir*/,<br>
StringRef("XXX") /*Producer*/,<br>
false /*isOptimized*/,<br>
StringRef("") /*Flags*/,<br>
0 /*RV: Runtime Version?*/);<br>
DIFile file = dibuilder->createFile(StringRef("foo.x"), StringRef("."));<br>
DICompileUnit compile_unit = DICompileUnit(file);<br>
dibuilder->createFunction(compile_unit /*Scope*/,<br>
StringRef(function_name), StringRef(function_name),<br>
file,<br>
42 /* line number*/,<br>
di_func_type,<br>
false /*isLocalToUnit*/, true /*isDefinition*/,<br>
42 /*ScopeLine*/<br>
);<br>
...<br>
...<br>
dibuilder->finalize();<br>
module->dump();<br>
<br>
<br>
To me, it seems wrong to create two compile units, one with<br>
dibuilder->createCompileUnit()<br>
and the other directly<br>
DICompileUnit compile_unit = DICompileUnit(file);<br>
<br>
However, I could not figure out how to get a handle to the compile unit<br>
generated by dibuilder->createCompileUnit(), in order to pass it to<br>
dibuilder->createFunction().<br>
<br>
<br>
<br>
<br>
I can provide a lot more detail, but I do not want to bore you with this.<br>
If there is any info you need in order to help me out, please just ask, and I<br>
will do my best to provide it.<br>
<br>
<br>
<br>
Cheers,<br>
<br>
Mario.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>