<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sure.  And if you step into a macro, you can still see what your current frame is, even if it won't tell you what line within the function—big deal.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">#include of function fragments would be a similar case, although that's not a style common in C/C++ (it is in COBOL, which doesn't have a macro facility, and
 I can assure you that in practice it works out okay).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> David Blaikie [mailto:dblaikie@gmail.com]
<br>
<b>Sent:</b> Tuesday, November 11, 2014 9:31 AM<br>
<b>To:</b> Robinson, Paul<br>
<b>Cc:</b> Christian Convey; cfe-dev Developers<br>
<b>Subject:</b> Re: [cfe-dev] Getting clang to give dwarf info for macro expansions?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Nov 11, 2014 at 9:22 AM, Robinson, Paul <<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">> 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>
> > 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>
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.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><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>
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<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><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>
><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>