<div dir="ltr"><div><div><div><div><div>Hi everyone,<br><br></div>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:<br></div>$ clang -O1 -g test.c -lpthread<br><br></div>If I run:<br></div>$ readelf --debug-dump=info ./a.out<br><br></div>I see the following debugging information in the binary for "main":<br><div><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<br><br></div><div>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"></div><div><br></div><div>When I compile with gcc:<br>$ gcc -O1 -g test.c -lpthread<br><br></div><div>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 <br></div><div>...(more information for main)...<br></div><div><br></div><div>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".<br><br></div>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>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><span>Rob Lyerly</span><br></div><div>Graduate Research Assistant, Systems Software Research Group<br><br></div><div><img src="http://www.branding.unirel.vt.edu/images/S_logo-tagline-old.jpg" height="40" width="140"> <img src="http://www.oocities.org/rainforestwind/divider_black_vertical.jpg" height="36" width="8"><img src="http://www.ece.vt.edu/images/inside-top-ecelogo.png" height="47" width="232"></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>