<div dir="ltr">DWARF doesn't really have a way to describe multiple source locations for a single instruction, so far as I know.<br><br>I imagine we could add something like DW_TAG_inlined_subroutine (though it wouldn't be quite as simple, since they're not necessarily strictly nested), 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 original macro templates (so you can use them in debugger expressions, etc) not to provide source fidelity for macro uses.<br><br>- David</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 9, 2014 at 1:53 PM, Christian Convey <span dir="ltr"><<a href="mailto:christian.convey@gmail.com" target="_blank">christian.convey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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>
</blockquote></div><br></div>