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>
Josh Matthews
2011-Dec-07 02:06 UTC
[LLVMdev] Generating DWARF information that pretends an outparam is the return value
Unfortunately this is what I'm already doing, and it's not working. I drew inspiration from a disassembly of a program that showed that struct foo { int a; float b; char buf[80]; } struct foo get_foo(void) { foo f = { 5, 2.5 }; return f; } would turn into define void @get_foo(%struct.foo* sret %agg.result) nounwind ssp { ... call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 88, i32 4, i1 false), !dbg !24 ret void, !dbg !25 } with similar metadata to what you wrote. I tried adding the sret attribute to my generated functions, but there was no change - maybe it doesn't work for non-structural types. Cheers, Josh On 6 December 2011 19:18, Devang Patel <dpatel at apple.com> wrote:> > 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 > >
Devang Patel
2011-Dec-07 17:29 UTC
[LLVMdev] Generating DWARF information that pretends an outparam is the return value
Hi Josh, On Dec 6, 2011, at 6:06 PM, Josh Matthews wrote:> Unfortunately this is what I'm already doing, and it's not working.In that case, you may want to engage lldb (or gdb) developers and figure out how to represent what you want in DWARF. Once you know that, we can figure out how to encode it in llvm IR. - Devang> I > drew inspiration from a disassembly of a program that showed that > > struct foo { > int a; float b; char buf[80]; > } > > struct foo get_foo(void) { > foo f = { 5, 2.5 }; > return f; > } > > would turn into > > define void @get_foo(%struct.foo* sret %agg.result) nounwind ssp { > ... > call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 88, i32 4, > i1 false), !dbg !24 > ret void, !dbg !25 > } > > with similar metadata to what you wrote. I tried adding the sret > attribute to my generated functions, but there was no change - maybe > it doesn't work for non-structural types. > > Cheers, > Josh > > On 6 December 2011 19:18, Devang Patel <dpatel at apple.com> wrote: >> >> 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 >> >>
Maybe Matching 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
- API survey results & update
- [LLVMdev] DWARF not being generated for local variable, though MD looks right(?)