<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:x="urn:schemas-microsoft-com:office:excel" 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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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;}
span.EmailStyle17
{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">I've seen these kinds of problems before:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><a href="https://llvm.org/bugs/show_bug.cgi?id=21881">https://llvm.org/bugs/show_bug.cgi?id=21881</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><a href="https://llvm.org/bugs/show_bug.cgi?id=22099">https://llvm.org/bugs/show_bug.cgi?id=22099</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Basically, there are various problems with debug info for optimized code and nobody has yet invested the time and energy to track them down and fix them. I
am more guilty than most, as I make noise about it and then can't manage to get it to bubble up high enough on my priority list.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sorry I can't be more help (at least not right now)…<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""> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Rob Lyerly via llvm-dev<br>
<b>Sent:</b> Wednesday, March 23, 2016 2:58 PM<br>
<b>To:</b> Rob Lyerly via llvm-dev<br>
<b>Subject:</b> [llvm-dev] Clang/LLVM producing incomplete & erroneous debug information<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi everyone,<o:p></o:p></p>
</div>
<p class="MsoNormal">I'm trying to get debug information for a C/pthreads application, but it seems like clang/LLVM are producing limited & erroneous debugging information. I've attached a simple test example to reproduce the problem -- I'm using clang/LLVM
3.7.1 built from source on Ubuntu 14.04.<br>
<br>
I compile the attached file with:<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">$ clang -O1 -g test.c -lpthread<o:p></o:p></p>
</div>
<p class="MsoNormal">If I run:<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">$ readelf --debug-dump=info ./a.out<o:p></o:p></p>
</div>
<p class="MsoNormal">I see the following debugging information in the binary for "main":<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
<1><a7>: Abbrev Number: 7 (DW_TAG_subprogram)<br>
<a8> DW_AT_low_pc : 0x400880 <br>
<b0> DW_AT_high_pc : 0xc9 <br>
<b4> Unknown AT value: 3fe7: 1 <br>
<b4> DW_AT_frame_base : 1 byte block: 57 (DW_OP_reg7 (rsp))<br>
<b6> DW_AT_name : (indirect string, offset: 0xaf): main <br>
<ba> DW_AT_decl_file : 1 <br>
<bb> DW_AT_decl_line : 16 <br>
<bc> DW_AT_prototyped : 1 <br>
<bc> DW_AT_type : <0x3f> <br>
<c0> DW_AT_external : 1 <br>
<c0> Unknown AT value: 3fe1: 1 <br>
<2><c0>: Abbrev Number: 8 (DW_TAG_formal_parameter)<br>
<c1> DW_AT_location : 0x23 (location list)<br>
<c5> DW_AT_name : (indirect string, offset: 0xc2): argc <br>
<c9> DW_AT_decl_file : 1 <br>
<ca> DW_AT_decl_line : 16 <br>
<cb> DW_AT_type : <0x3f> <br>
<2><cf>: Abbrev Number: 8 (DW_TAG_formal_parameter)<br>
<d0> DW_AT_location : 0x48 (location list)<br>
<d4> DW_AT_name : (indirect string, offset: 0xc7): argv <br>
<d8> DW_AT_decl_file : 1 <br>
<d9> DW_AT_decl_line : 16 <br>
<da> DW_AT_type : <0x5e> <br>
<2><de>: Abbrev Number: 10 (DW_TAG_variable)<br>
<df> DW_AT_const_value : 0 <br>
<e0> DW_AT_name : (indirect string, offset: 0xcc): i <br>
<e4> DW_AT_decl_file : 1 <br>
<e5> DW_AT_decl_line : 18 <br>
<e6> DW_AT_type : <0x3f> <br>
<2><ea>: Abbrev Number: 11 (DW_TAG_variable)<br>
<eb> DW_AT_name : (indirect string, offset: 0xce): children <br>
<ef> DW_AT_decl_file : 1 <br>
<f0> DW_AT_decl_line : 19 <br>
<f1> DW_AT_type : <0x47> <br>
<2><f5>: Abbrev Number: 0<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Notice that there are no location lists for local variable "children" (a malloc'd pthread_t pointer), and the information for local variable "i" says it has a constant value, even though it changes in the application!<br clear="all">
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">When I compile with gcc:<br>
$ gcc -O1 -g test.c -lpthread<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">And do a readelf, I get the following information:<br>
<br>
<1><3c3>: Abbrev Number: 21 (DW_TAG_subprogram)<br>
<3c4> DW_AT_external : 1 <br>
<3c4> DW_AT_name : (indirect string, offset: 0x23f): main <br>
<3c8> DW_AT_decl_file : 1 <br>
<3c9> DW_AT_decl_line : 16 <br>
<3ca> DW_AT_prototyped : 1 <br>
<3ca> DW_AT_type : <0x3f> <br>
<3ce> DW_AT_low_pc : 0x4008a0 <br>
<3d6> DW_AT_high_pc : 0xe5 <br>
<3de> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)<br>
<3e0> DW_AT_GNU_all_call_sites: 1 <br>
<3e0> DW_AT_sibling : <0x58b> <br>
<2><3e4>: Abbrev Number: 22 (DW_TAG_formal_parameter)<br>
<3e5> DW_AT_name : (indirect string, offset: 0x138): argc <br>
<3e9> DW_AT_decl_file : 1 <br>
<3ea> DW_AT_decl_line : 16 <br>
<3eb> DW_AT_type : <0x3f> <br>
<3ef> DW_AT_location : 0x6f (location list)<br>
<2><3f3>: Abbrev Number: 22 (DW_TAG_formal_parameter)<br>
<3f4> DW_AT_name : (indirect string, offset: 0x107): argv <br>
<3f8> DW_AT_decl_file : 1 <br>
<3f9> DW_AT_decl_line : 16 <br>
<3fa> DW_AT_type : <0x58b> <br>
<3fe> DW_AT_location : 0xa8 (location list)<br>
<2><402>: Abbrev Number: 23 (DW_TAG_variable)<br>
<403> DW_AT_name : i <br>
<405> DW_AT_decl_file : 1 <br>
<406> DW_AT_decl_line : 18 <br>
<407> DW_AT_type : <0x3f> <br>
<40b> DW_AT_location : 0xe1 (location list)<br>
<2><40f>: Abbrev Number: 28 (DW_TAG_variable)<br>
<410> DW_AT_name : (indirect string, offset: 0xf4): children <br>
<414> DW_AT_decl_file : 1 <br>
<415> DW_AT_decl_line : 19 <br>
<416> DW_AT_type : <0x591> <br>
<41a> DW_AT_location : 0x13f (location list)<br>
<2><41e>: Abbrev Number: 24 (DW_TAG_inlined_subroutine)<br>
<41f> DW_AT_abstract_origin: <0x305> <br>
<423> DW_AT_low_pc : 0x4008ab <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">...(more information for main)...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">The "children" variable has a location list, and "I" is not listed as having a constant value. Note that if I compile with clang using -O0, there's a location list for both "children" and "i".<o:p></o:p></p>
</div>
<p class="MsoNormal">Does anybody know what's going on here? I understand the nature of debugging information -- the compiler provides a best-effort attempt to specify where things are, but optimization make things tricky. However, I would counter with the
fact that this is a very simple program being compiled with basic optimizations. Is the compiler just unable to generate variable locations for this program?<br clear="all">
<br>
-- <o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Rob Lyerly<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Graduate Research Assistant, Systems Software Research Group<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><img border="0" width="140" height="40" id="_x0000_i1025" src="http://www.branding.unirel.vt.edu/images/S_logo-tagline-old.jpg">
<img border="0" width="8" height="36" id="_x0000_i1026" src="http://www.oocities.org/rainforestwind/divider_black_vertical.jpg"><img border="0" width="232" height="47" id="_x0000_i1027" src="http://www.ece.vt.edu/images/inside-top-ecelogo.png"><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>