[llvm-dev] Clang/LLVM producing incomplete & erroneous debug information

Robinson, Paul via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 23 17:31:40 PDT 2016


I've seen these kinds of problems before:
https://llvm.org/bugs/show_bug.cgi?id=21881
https://llvm.org/bugs/show_bug.cgi?id=22099

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.

Sorry I can't be more help (at least not right now)…
--paulr

From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Rob Lyerly via llvm-dev
Sent: Wednesday, March 23, 2016 2:58 PM
To: Rob Lyerly via llvm-dev
Subject: [llvm-dev] Clang/LLVM producing incomplete & erroneous debug information

Hi everyone,
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.

I compile the attached file with:
$ clang -O1 -g test.c -lpthread
If I run:
$ readelf --debug-dump=info ./a.out
I see the following debugging information in the binary for "main":

 <1><a7>: Abbrev Number: 7 (DW_TAG_subprogram)
    <a8>   DW_AT_low_pc      : 0x400880
    <b0>   DW_AT_high_pc     : 0xc9
    <b4>   Unknown AT value: 3fe7: 1
    <b4>   DW_AT_frame_base  : 1 byte block: 57         (DW_OP_reg7 (rsp))
    <b6>   DW_AT_name        : (indirect string, offset: 0xaf): main
    <ba>   DW_AT_decl_file   : 1
    <bb>   DW_AT_decl_line   : 16
    <bc>   DW_AT_prototyped  : 1
    <bc>   DW_AT_type        : <0x3f>
    <c0>   DW_AT_external    : 1
    <c0>   Unknown AT value: 3fe1: 1
 <2><c0>: Abbrev Number: 8 (DW_TAG_formal_parameter)
    <c1>   DW_AT_location    : 0x23     (location list)
    <c5>   DW_AT_name        : (indirect string, offset: 0xc2): argc
    <c9>   DW_AT_decl_file   : 1
    <ca>   DW_AT_decl_line   : 16
    <cb>   DW_AT_type        : <0x3f>
 <2><cf>: Abbrev Number: 8 (DW_TAG_formal_parameter)
    <d0>   DW_AT_location    : 0x48     (location list)
    <d4>   DW_AT_name        : (indirect string, offset: 0xc7): argv
    <d8>   DW_AT_decl_file   : 1
    <d9>   DW_AT_decl_line   : 16
    <da>   DW_AT_type        : <0x5e>
 <2><de>: Abbrev Number: 10 (DW_TAG_variable)
    <df>   DW_AT_const_value : 0
    <e0>   DW_AT_name        : (indirect string, offset: 0xcc): i
    <e4>   DW_AT_decl_file   : 1
    <e5>   DW_AT_decl_line   : 18
    <e6>   DW_AT_type        : <0x3f>
 <2><ea>: Abbrev Number: 11 (DW_TAG_variable)
    <eb>   DW_AT_name        : (indirect string, offset: 0xce): children
    <ef>   DW_AT_decl_file   : 1
    <f0>   DW_AT_decl_line   : 19
    <f1>   DW_AT_type        : <0x47>
 <2><f5>: Abbrev Number: 0
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!

When I compile with gcc:
$ gcc -O1 -g test.c -lpthread
And do a readelf, I get the following information:

 <1><3c3>: Abbrev Number: 21 (DW_TAG_subprogram)
    <3c4>   DW_AT_external    : 1
    <3c4>   DW_AT_name        : (indirect string, offset: 0x23f): main
    <3c8>   DW_AT_decl_file   : 1
    <3c9>   DW_AT_decl_line   : 16
    <3ca>   DW_AT_prototyped  : 1
    <3ca>   DW_AT_type        : <0x3f>
    <3ce>   DW_AT_low_pc      : 0x4008a0
    <3d6>   DW_AT_high_pc     : 0xe5
    <3de>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
    <3e0>   DW_AT_GNU_all_call_sites: 1
    <3e0>   DW_AT_sibling     : <0x58b>
 <2><3e4>: Abbrev Number: 22 (DW_TAG_formal_parameter)
    <3e5>   DW_AT_name        : (indirect string, offset: 0x138): argc
    <3e9>   DW_AT_decl_file   : 1
    <3ea>   DW_AT_decl_line   : 16
    <3eb>   DW_AT_type        : <0x3f>
    <3ef>   DW_AT_location    : 0x6f    (location list)
 <2><3f3>: Abbrev Number: 22 (DW_TAG_formal_parameter)
    <3f4>   DW_AT_name        : (indirect string, offset: 0x107): argv
    <3f8>   DW_AT_decl_file   : 1
    <3f9>   DW_AT_decl_line   : 16
    <3fa>   DW_AT_type        : <0x58b>
    <3fe>   DW_AT_location    : 0xa8    (location list)
 <2><402>: Abbrev Number: 23 (DW_TAG_variable)
    <403>   DW_AT_name        : i
    <405>   DW_AT_decl_file   : 1
    <406>   DW_AT_decl_line   : 18
    <407>   DW_AT_type        : <0x3f>
    <40b>   DW_AT_location    : 0xe1    (location list)
 <2><40f>: Abbrev Number: 28 (DW_TAG_variable)
    <410>   DW_AT_name        : (indirect string, offset: 0xf4): children
    <414>   DW_AT_decl_file   : 1
    <415>   DW_AT_decl_line   : 19
    <416>   DW_AT_type        : <0x591>
    <41a>   DW_AT_location    : 0x13f   (location list)
 <2><41e>: Abbrev Number: 24 (DW_TAG_inlined_subroutine)
    <41f>   DW_AT_abstract_origin: <0x305>
    <423>   DW_AT_low_pc      : 0x4008ab
...(more information for main)...

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".
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?

--
Rob Lyerly
Graduate Research Assistant, Systems Software Research Group
[http://www.branding.unirel.vt.edu/images/S_logo-tagline-old.jpg]   [http://www.oocities.org/rainforestwind/divider_black_vertical.jpg] [http://www.ece.vt.edu/images/inside-top-ecelogo.png]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160324/8b9ad35c/attachment.html>


More information about the llvm-dev mailing list