[LLVMdev] Associating types directly with debug metadata?

Pekka Nikander pekka.nikander at nomadiclab.com
Wed Sep 29 04:30:14 PDT 2010


We would need to access the LLVM debug metadata type information directly from LLVM types.  It looks like the current clang and llvm-gcc don't support such an association, nor appears the LLVM itself do.   (We are tracking TOT, but only once a month or so.)

In terms of LLVM IR, apparantly this would simply mean optionally adding another metadata value to each type.  For example, let us have a C type

  struct T { int a };

In LLVM IR (with no name conflicts), this get presented as 

  %struct.T = type { i32 }

Now, we would like to annotate this with a piece of metadata, something like this:

  %struct.T = type { i32 }, !dbg !11

with the associated metadata being something like the following:

!1 = metadata !{i32 524329, metadata !"foo.c", metadata !"/tmp", metadata !2} ; [ DW_TAG_file_type ]
!2 = metadata !{i32 524305, i32 0, i32 12, metadata !"foo.c", metadata !"/tmp", metadata !"clang version 2.9 ($URL$)", i1 true, i1 false, metadata !"", i32 0} ; [ DW_TAG_compile_unit ]
!5 = metadata !{i32 524324, metadata !1, metadata !"int", metadata !1, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
!11 = metadata !{i32 524307, metadata !1, metadata !"T", metadata !1, i32 2, i64 32, i64 32, i64 0, i32 0, null, metadata !12, i32 0, null} ; [ DW_TAG_structure_type ]
!12 = metadata !{metadata !13}
!13 = metadata !{i32 524301, metadata !1, metadata !"a", metadata !1, i32 2, i64 32, i64 32, i64 0, i32 0, metadata !5} ; [ DW_TAG_member ]

Then the type would probably need to be added to a new named metadata tag as well, maybe !llvm.dbg.ty?

Would the right starting point be to simply add an MDNode pointer to the Type class?  That should be then convertible to a DIType?  

The next step apparently would be to support to LLParser to read in such associations, and to AsmPrinter to print it out.  But how about the bitcode?  Would this require a new LLVMBitCode?  

With that, would LLVM be able to deal with the type-associated metadata, or is there something in the LLVM side that I'm missing?

Once that works, I guess I need to ask how to extend clang to emit the information, but the right place for that would be cfe-dev, wouldn't it?

--Pekka Nikander





More information about the llvm-dev mailing list