[LLVMdev] Newbie question(?): How to correctly create debug info, when generating IR

Mario de Sousa msousa at fe.up.pt
Fri Dec 28 09:33:28 PST 2012



 Hello all,


Summary & Context:
-------------------------------
 I am starting to write a front-end for some domain specific programming 
languages. Code generation seems to be working fine.

 However, I am having trouble generating debug info, to be used by gdb.


 The problem:
 --------------------
 I generate a foo.ll file, that is later compiled into an executable foo.

 The foo.ll file I generate already contains metadata for datatypes, compile 
unit, subprograms, etc...

 When debuging foo with ddd, I get the message that the file
 <root_path>/sysdeps/i386/elf/start.S
 does not exist. In other words, the debugger does not seem to know about the 
existence of foo.xx, the original source file.

 I have compiled a small helloworld.c program, and compared the debug info in 
helloworld and foo, using 'readelf --debug-dump'.

 I have noticed that in helloworld, the .debug_aranges section has 2 address 
ranges, 
  - one pointing to a DW_TAG_compile_unit referencing the 
/sysdeps/i386/elf/start.S file
  - the other pointing to a DW_TAG_compile_unit with the helloworld,c file.

 However, in the foo program, the .debug_aranges section has only 1 address 
range, pointing to a DW_TAG_compile_unit referencing the 
/sysdeps/i386/elf/start.S file.
 The second DW_TAG_compile_unit referencing the foo.xx file is present in the  
.debug_info section, but is not being referenced!

 Strangely, some information that seems to be an address range referencing the 
foo.xx DW_TAG_compile_unit, is present in the .debug_pubtypes section. Why is 
this in the wrong section??



The question:
=========

 Does anybody have any idea what it is I am doing wrong?

 The issue seems to be related to generating the info for a CompileUnit. 
Currently, I am doing this:
  dibuilder = new DIBuilder(themodule); 
  dibuilder->createCompileUnit(Lang, 
              StringRef("foo.xx")), /*finename*/
              StringRef(".") /*Dir*/, 
              StringRef("XXX") /*Producer*/, 
              false /*isOptimized*/, 
              StringRef("") /*Flags*/, 
              0 /*RV: Runtime Version?*/); 
  DIFile file = dibuilder->createFile(StringRef("foo.x"), StringRef("."));
  DICompileUnit compile_unit = DICompileUnit(file);
  dibuilder->createFunction(compile_unit /*Scope*/, 
                 StringRef(function_name), StringRef(function_name), 
                 file, 
                 42 /* line number*/, 
                 di_func_type, 
                 false /*isLocalToUnit*/, true /*isDefinition*/, 
                 42 /*ScopeLine*/
                ); 
  ...
  ...
  dibuilder->finalize();
  module->dump();   


  To me, it seems wrong to create two compile units, one with
  dibuilder->createCompileUnit()
and the other directly
  DICompileUnit compile_unit = DICompileUnit(file);

 However, I could not figure out how to get a handle to the compile unit 
generated by   dibuilder->createCompileUnit(), in order to pass it to   
dibuilder->createFunction().




   I can provide a lot more detail, but I do not want to bore you with this. 
If there is any info you need in order to help me out, please just ask, and I 
will do my best to provide it.



  Cheers,

          Mario.



More information about the llvm-dev mailing list