<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 11, 2014 at 9:22 AM, Robinson, Paul <span dir="ltr"><<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> From: <a href="mailto:cfe-dev-bounces@cs.uiuc.edu">cfe-dev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:cfe-dev-bounces@cs.uiuc.edu">cfe-dev-bounces@cs.uiuc.edu</a>] On Behalf Of David Blaikie<br>
<span class="">> > On Mon, Nov 10, 2014 at 3:41 PM, Christian Convey <<a href="mailto:christian.convey@gmail.com">christian.convey@gmail.com</a>> wrote:<br>
> > Thanks David.  I'm certainly no dwarf expert, but I was wondering if<br>
> > we could just have something like this:<br>
> ><br>
> > foo.c:6:1<br>
> > (various machine instructions)<br>
> > bar.h:20<br>
> > (some machine instruction resulting from a macro call at, for example,<br>
> > line 7 of foo.c)<br>
> > foo.c:8:1<br>
> > (more machine instructions)<br>
><br>
> Yeah, I haven't experimented with that - it's something that could be tried<br>
> (not high enough on my list) but I suspect would be confusing to users,<br>
> because they'd have no context as to where in the actual function they were<br>
> (if the macro was used twice, which macro instantiation were they in, etc).<br>
<br>
</span>If your debugger is showing the equivalent of disassembly with interspersed<br>
source, that's not a problem.  The macro definition shows up twice, each case<br>
attached to the instructions for that use of the macro.  It's not intrinsically<br>
much different from multiple inlined calls to the same function.<br></blockquote><div><br></div><div>Well the major difference is that with inlined call information you can use "bt" to see the context (which call site the inlined subroutine came from).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
><br>
> > Anyway, I'm not proposing a modification.  I was just curious if there<br>
> > was some existing way to get better insight into the object code<br>
> > associated with macro-generated source.<br>
><br>
> I believe the short answer is: no, there is no existing way to get better<br>
> insight into code from macros. (but I could be wrong)<br>
<br>
</span>I suppose you could preprocess the source, filter out the #line directives,<br>
and then build/debug the preprocessed source, but that's probably more work<br>
for less gain than you really want.<br>
--paulr<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> - David<br>
<br>
<br>
On Mon, Nov 10, 2014 at 6:35 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> DWARF doesn't really have a way to describe multiple source locations for a<br>
> single instruction, so far as I know.<br>
><br>
> I imagine we could add something like DW_TAG_inlined_subroutine (though it<br>
> wouldn't be quite as simple, since they're not necessarily strictly nested),<br>
> and/or the new two-level line tables that're being proposed/worked on.<br>
><br>
> DWARF does have a macro section, but I believe this is just to describe the<br>
> original macro templates (so you can use them in debugger expressions, etc)<br>
> not to provide source fidelity for macro uses.<br>
><br>
> - David<br>
><br>
> On Sun, Nov 9, 2014 at 1:53 PM, Christian Convey<br>
> <<a href="mailto:christian.convey@gmail.com">christian.convey@gmail.com</a>> wrote:<br>
>><br>
>> Does anyone know if/how I can get clang to generate dwarf information<br>
>> that lets me trace / debug *into* macro-generated code?<br>
>><br>
>> It seems that when a C program invokes a macro, all of the source code<br>
>> produced by that macro invocation is attributed to the line at which<br>
>> the macro is called.  I've seen this in both dwarfdump and gdb, as<br>
>> described below.  (The exception seems to be when a macro expansion<br>
>> causes the definition of a new function.  That new function shows up<br>
>> in the dwarf info as one might hope.)<br>
>><br>
>> What I'd ideally like is for tracing tools to clearly describe which<br>
>> branches within macro-generated code were taken.  When all of the<br>
>> source code generated by a macro invocation is attributed to the macro<br>
>> *call* site by the dwarf information, that level of precision seems<br>
>> impossible.<br>
>><br>
>> For example, suppose I have this code:<br>
>> >>>> foo.c<br>
>> #define FOO \<br>
>>    if (x == 3) { \<br>
>>    return 1; \<br>
>>    }<br>
>><br>
>> int bar(int x) {<br>
>>    FOO<br>
>>    return 0;<br>
>> }<br>
>> <<<<<<br>
>><br>
>> And I compile it with this command:<br>
>> clang -c -g -Xclang -dwarf-column-info foo.c<br>
>><br>
>> And I look at the dwarf information using the command:<br>
>> objdump -dgls foo.o<br>
>><br>
>> I get this:<br>
>> ...<br>
>> Disassembly of section .text:<br>
>><br>
>> 0000000000000000 <bar>:<br>
>> bar():<br>
>> /tmp/foo.c:6<br>
>>    0:   55                      push   %rbp<br>
>>    1:   48 89 e5                mov    %rsp,%rbp<br>
>>    4:   89 7d f8                mov    %edi,-0x8(%rbp)<br>
>> /tmp/foo.c:7<br>
>>    7:   81 7d f8 03 00 00 00    cmpl   $0x3,-0x8(%rbp)<br>
>>    e:   0f 85 0c 00 00 00       jne    20 <bar+0x20><br>
>>   14:   c7 45 fc 01 00 00 00    movl   $0x1,-0x4(%rbp)<br>
>>   1b:   e9 07 00 00 00          jmpq   27 <bar+0x27><br>
>> /tmp/foo.c:8<br>
>>   20:   c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%rbp)<br>
>> /tmp/foo.c:9<br>
>>   27:   8b 45 fc                mov    -0x4(%rbp),%eax<br>
>>   2a:   5d                      pop    %rbp<br>
>>   2b:   c3                      retq<br>
>> ...<br>
>><br>
>> Note that all of the reported source locations are in lines 6-9;<br>
>> nothing is attributed to lines 1-3.<br>
>><br>
>> To double-check that I really can't get detailed trace information<br>
>> from macro-generated code, I added a main() function and stepped<br>
>> through the code with gdb.  Here's what I got:<br>
>><br>
>> (gdb) list<br>
>> 4          }<br>
>> 5<br>
>> 6       int bar(int x) {<br>
>> 7          FOO<br>
>> 8          return 0;<br>
>> 9       }<br>
>> 10<br>
>> 11      int main(int argc, const char* argv[] )<br>
>> 12      {<br>
>> 13          return bar( argc );<br>
>> (gdb) break main<br>
>> Breakpoint 1 at 0x4004d6: file foo.c, line 13.<br>
>> (gdb) run<br>
>> Starting program: /tmp/a.out<br>
>><br>
>> Breakpoint 1, main (argc=1, argv=0x7fffffffdf98) at foo.c:13<br>
>> 13          return bar( argc );<br>
>> (gdb) step<br>
>> bar (x=1) at foo.c:7<br>
>> 7          FOO<br>
>> (gdb) step<br>
>> 8          return 0;<br>
>> (gdb) step<br>
>> 9       }<br>
>> (gdb) step<br>
>> __libc_start_main (main=0x4004c0 <main>, argc=1, argv=0x7fffffffdf98,<br>
>> init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,<br>
>> stack_end=0x7fffffffdf88) at libc-start.c:321<br>
>> 321     libc-start.c: No such file or directory.<br>
>> (gdb)<br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>