Josh Matthews
2011-Dec-05 05:33 UTC
[LLVMdev] Generating DWARF information that pretends an outparam is the return value
The Rust compiler defines all functions as returning void, with the first parameter being an outparam of the declared return type, ie. fn foo2() -> int { ret 5; } becomes define void @_ZN4foo217_5cb557d30658848cE(i64*, { i64, { %tydesc*, i1, {} } }*) uwtable { store i64 5, i64* %0 ret void } I'm working on generating debug information for Rust, and I'm currently stumped on how to generate DWARF output via LLVM that will correctly represent this (eg. when exiting from foo2(), I'd like to see "Value returns is $1 = 5"). I'm generating debug metadata nodes directly instead of using DIBuilder since it doesn't seem to encapsulate situations like this. Any thoughts? Apologies if this is too esoteric for the general LLVM community, but there's a seeming dearth of information about things like DW_TAG_return_variable on the wider internet. Cheers, Josh
Devang Patel
2011-Dec-07 00:13 UTC
[LLVMdev] Generating DWARF information that pretends an outparam is the return value
Hi Josh, On Dec 4, 2011, at 9:33 PM, Josh Matthews wrote:> I'm working on generating debug information for Rust, and I'm > currently stumped on how to generate DWARF output via LLVM that will > correctly represent this (eg. when exiting from foo2(), I'd like to > see "Value returns is $1 = 5"). I'm generating debug metadata nodes > directly instead of using DIBuilder since it doesn't seem to > encapsulate situations like this.So, I assume you figured out how to create metadata nodes for TAG_subprogram and corresponding TAG_subroutine_type. If yes, then the zero'th element of array of types you supply (subroutine_type is encoded as composite type, see http://llvm.org/docs/SourceLevelDebugging.html#format_composite_type) is return type. Let's say you have 1 2 int foo() { 3 char c = 'a'; 4 return 42; 5 } Try generating following metadata nodes (I am not including all of them here) to describe 'char' as the return type of function 'foo'. !1 = metadata !{i32 589870, i32 0, metadata !2, metadata !"foo", metadata !"foo", metadata !"", metadata !2, i32 2, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 0, i1 f\ alse, i32 ()* @foo, null, null} ; [ DW_TAG_subprogram ] !3 = metadata !{i32 589845, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] !8 = metadata !{i32 589860, metadata !0, metadata !"char", null, i32 0, i64 8, i64 8, i64 0, i32 0, i32 6} ; [ DW_TAG_base_type ] Next, when you generate metadata nodes for arguments, slide argument numbers by 1. (http://llvm.org/docs/SourceLevelDebugging.html#format_variables) I have not tried this myself, but I hope it helps. - Devang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111206/bae2fdf8/attachment.html>
Devang Patel
2011-Dec-07 00:18 UTC
[LLVMdev] Generating DWARF information that pretends an outparam is the return value
On Dec 6, 2011, at 4:13 PM, Devang Patel wrote:> Hi Josh, > > On Dec 4, 2011, at 9:33 PM, Josh Matthews wrote: > >> I'm working on generating debug information for Rust, and I'm >> currently stumped on how to generate DWARF output via LLVM that will >> correctly represent this (eg. when exiting from foo2(), I'd like to >> see "Value returns is $1 = 5"). I'm generating debug metadata nodes >> directly instead of using DIBuilder since it doesn't seem to >> encapsulate situations like this. > > So, I assume you figured out how to create metadata nodes for TAG_subprogram and corresponding TAG_subroutine_type. If yes, then the zero'th element of array of types you supply (subroutine_type is encoded as composite type, see http://llvm.org/docs/SourceLevelDebugging.html#format_composite_type) is return type. > > Let's say you have > > 1 > 2 int foo() { > 3 char c = 'a'; > 4 return 42; > 5 } > > Try generating following metadata nodes (I am not including all of them here) to describe 'char' as the return type of function 'foo'. > > !1 = metadata !{i32 589870, i32 0, metadata !2, metadata !"foo", metadata !"foo", metadata !"", metadata !2, i32 2, metadata !3, i1 false, i1 true, i32 0, i32 0, i32 0, i32 0, i1 f\ > alse, i32 ()* @foo, null, null} ; [ DW_TAG_subprogram ] > > !3 = metadata !{i32 589845, metadata !2, metadata !"", metadata !2, i32 0, i64 0, i64 0, i32 0, i32 0, i32 0, metadata !4, i32 0, i32 0} ; [ DW_TAG_subroutine_type ]!4 = metadata !{metadata !8}> > > !8 = metadata !{i32 589860, metadata !0, metadata !"char", null, i32 0, i64 8, i64 8, i64 0, i32 0, i32 6} ; [ DW_TAG_base_type ] > > Next, when you generate metadata nodes for arguments, slide argument numbers by 1. (http://llvm.org/docs/SourceLevelDebugging.html#format_variables) > > I have not tried this myself, but I hope it helps. > - > Devang > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111206/40fb522f/attachment.html>
Apparently Analagous Threads
- [LLVMdev] Generating DWARF information that pretends an outparam is the return value
- [LLVMdev] Generating DWARF information that pretends an outparam is the return value
- [LLVMdev] Generating DWARF information that pretends an outparam is the return value
- [LLVMdev] LLVM 2.9 metadata
- [LLVMdev] LLVM 2.9 metadata