It appears that g++ is generating incorrect scope debug information
for inlined functions.  One symptom of this is that addr2line will
generate inconsistent results for the affected address ranges, showing
the correct line information for the inlined function, but showing the
function name as the most outer scope that contains the inlined
function.

For example, it may show a line number in a C++ header file and give
the function name as "main".

Environment:
System: Linux toadfish.ninemoons.com 2.6.9-1.681_FC3.stk16 #1 Mon Nov 22 
16:44:32 EST 2004 i686 i686 i386 GNU/Linux
Architecture: i686

        
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /src/sourceware/gcc/gcc/configure -v 
--prefix=/opt/local/sourceware --enable-languages=c,c++

How-To-Repeat:

Compile and link this code:

  #include <vector>

  using namespace std;

  int main ()
  {
    vector<int> V(10);
    V[10] = 1;
  }

using a command like:

  g++ -ggdb -O2 --save-temps -o t t.cc

Below is an annotated copy of the disassembly of main().

First I removed all the instruction pattern fields since they just
clutter stuff up for our purposes.  Having the instruction name and
args is sufficient to see what the code is doing.

Next I ran addr2line on every address, collected the output function
name and line number info, and inserted that as columns 2 and 3 (after
the instruction address and before the instruction name).

Next I examined the dwarf output and looked for the most outer scopes
of the inlined functions.  I.E. if DW_TAG_subprogram is scope '<1>'
then I looked for the inlined subroutines at scope '<2>' and inserted
lines in the disassembly at the beginning (beg) and ending (end) of
each scope.  This shows the coverage of the function code for inlined
functions.  Code outside these scopes SHOULD belong only to code in
main() itself.

If you look at the function names emitted by addr2line (the second
column) you will note that it associates any code outside the scope of
the beg...end regions as belonging to main.  All of these SHOULD have
filenames from the line number info of "t.cc".  However some of these
ranges identified as code belonging to main are actually code from
inlined functions in the C++ headers, thus there must be some missing
DW_TAG_inlined_subroutine DIES for these sections.  For example:

  0x804896b  main  mt_allocator.h:450  call  80486c4 <[EMAIL PROTECTED]>

where the code at line 450 in mt_allocator.h is:

          static pool_type&
          _S_get_pool()
          {
450->        static pool_type _S_pool;
             return _S_pool;
          }

============================================================================

08048880 <main>:

beg <1><39c1>: Abbrev Number: 111 (DW_TAG_subprogram)

0x8048880       main            t.cc:5                  push   %ebp
0x8048881       main            t.cc:5                  mov    %esp,%ebp
0x8048883       main            t.cc:5                  push   %ebx
0x8048884       main            t.cc:5                  sub    $0x34,%esp
0x8048887       main            t.cc:5                  and    $0xfffffff0,%esp
0x804888a       main            t.cc:5                  sub    $0x10,%esp

beg <2><39e7>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): vector

0x804888d       _S_get_pool     mt_allocator.h:450      cmpb   $0x0,0x804a768
0x8048894       _S_get_pool     mt_allocator.h:450      je     8048964 
<main+0xe4>
0x804889a       _M_allocate     stl_vector.h:117        xor    %eax,%eax
0x804889c       _M_allocate     stl_vector.h:117        lea    
0xffffffe8(%ebp),%ebx
0x804889f       _M_allocate     stl_vector.h:117        mov    %eax,0x8(%esp)
0x80488a3       _M_allocate     stl_vector.h:117        mov    $0xa,%eax
0x80488a8       _Vector_impl    stl_vector.h:85         movl   
$0x0,0xffffffe8(%ebp)
0x80488af       _Vector_impl    stl_vector.h:85         movl   
$0x0,0xffffffec(%ebp)
0x80488b6       _Vector_impl    stl_vector.h:85         movl   
$0x0,0xfffffff0(%ebp)
0x80488bd       _Vector_base    stl_vector.h:117        mov    %eax,0x4(%esp)
0x80488c1       _Vector_base    stl_vector.h:117        mov    %ebx,(%esp)
0x80488c4       _Vector_base    stl_vector.h:117        call   8049140 
<__gnu_cxx::__mt_alloc<int, __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, 
true> >::allocate(unsigned int, void const*)>
0x80488c9       _S_get_pool     mt_allocator.h:450      cmpb   $0x0,0x804a768
0x80488d0       vector          stl_vector.h:103        mov    
%eax,0xffffffe8(%ebp)
0x80488d3       vector          stl_vector.h:104        mov    
%eax,0xffffffec(%ebp)
0x80488d6       vector          stl_vector.h:105        lea    0x28(%eax),%eax
0x80488d9       vector          stl_vector.h:105        mov    
%eax,0xfffffff0(%ebp)
0x80488dc       vector          mt_allocator.h:450      je     8048a50 
<main+0x1d0>
0x80488e2       vector          stl_vector.h:219        lea    
0xfffffffa(%ebp),%eax
0x80488e5       vector          stl_vector.h:219        mov    $0xa,%edx
0x80488ea       vector          stl_vector.h:219        mov    %eax,0xc(%esp)
0x80488ee       vector          stl_vector.h:219        lea    
0xfffffff4(%ebp),%eax
0x80488f1       vector          stl_vector.h:219        mov    %eax,0x8(%esp)
0x80488f5       vector          stl_vector.h:219        mov    
0xffffffe8(%ebp),%eax
0x80488f8       vector          stl_vector.h:219        mov    %edx,0x4(%esp)
0x80488fc       vector          stl_vector.h:219        movl   
$0x0,0xfffffff4(%ebp)
0x8048903       vector          stl_vector.h:219        mov    %eax,(%esp)
0x8048906       vector          stl_vector.h:219        call   8048d40 <void 
std::__uninitialized_fill_n_a<int*, unsigned int, int, int>(int*, unsigned int, 
int const&, std::allocator<int>)>
0x804890b       vector          stl_vector.h:221        mov    
0xffffffe8(%ebp),%edx

end <2><39e7>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): vector

0x804890e       main            t.cc:8                  movl   $0x1,0x28(%edx)
0x8048915       main            stl_vector.h:221        lea    0x28(%edx),%eax

beg <2><3aed>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): ~vector

0x8048918       _S_get_pool     mt_allocator.h:450      cmpb   $0x0,0x804a768

end <2><3aed>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): ~vector

0x804891f       main            stl_vector.h:221        mov    
%eax,0xffffffec(%ebp)
0x8048922       main            mt_allocator.h:450      je     8048a30 
<main+0x1b0>
0x8048928       main            stl_vector.h:273        lea    
0xfffffffb(%ebp),%eax
0x804892b       main            stl_vector.h:273        mov    %eax,0x8(%esp)
0x804892f       main            stl_vector.h:273        mov    
0xffffffec(%ebp),%eax
0x8048932       main            stl_vector.h:273        mov    %edx,(%esp)
0x8048935       main            stl_vector.h:273        mov    %eax,0x4(%esp)
0x8048939       main            stl_vector.h:273        call   8048c30 <void 
std::_Destroy<int*, std::allocator<int> >(int*, int*, std::allocator<int>)>

beg <2><3b5b>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): ~_Vector_base

0x804893e       ~_Vector_base   stl_vector.h:109        mov    
0xffffffe8(%ebp),%edx
0x8048941       ~_Vector_base   stl_vector.h:109        mov    
0xfffffff0(%ebp),%eax
0x8048944       ~_Vector_base   stl_vector.h:109        sub    %edx,%eax
0x8048946       ~_Vector_base   stl_vector.h:109        sar    $0x2,%eax
0x8048949       _M_deallocate   stl_vector.h:122        test   %edx,%edx
0x804894b       _M_deallocate   stl_vector.h:122        je     804895d 
<main+0xdd>
0x804894d       _M_deallocate   stl_vector.h:123        mov    %eax,0x8(%esp)
0x8048951       _M_deallocate   stl_vector.h:123        mov    %edx,0x4(%esp)
0x8048955       _M_deallocate   stl_vector.h:123        mov    %ebx,(%esp)
0x8048958       _M_deallocate   stl_vector.h:123        call   8048d50 
<__gnu_cxx::__mt_alloc<int, __gnu_cxx::__common_pool_policy<__gnu_cxx::__pool, 
true> >::deallocate(int*, unsigned int)>

end <2><3b5b>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): ~_Vector_base

0x804895d       main            t.cc:9                  mov    
0xfffffffc(%ebp),%ebx
0x8048960       main            t.cc:9                  xor    %eax,%eax
0x8048962       main            t.cc:9                  leave  
0x8048963       main            t.cc:9                  ret    
0x8048964       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x804896b       main            mt_allocator.h:450      call   80486c4 <[EMAIL 
PROTECTED]>
0x8048970       main            mt_allocator.h:450      test   %eax,%eax
0x8048972       main            mt_allocator.h:450      jne    8048b8a 
<main+0x30a>
0x8048978       main            mt_allocator.h:450      movzbl 0x804a768,%eax

beg <2><3b8f>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): allocator

0x804897f       _S_get_pool     mt_allocator.h:112      test   %al,%al
0x8048981       _S_get_pool     mt_allocator.h:112      jne    804889a 
<main+0x1a>
0x8048987       _S_get_pool     mt_allocator.h:112      movl   $0x804a768,(%esp)
0x804898e       _S_get_pool     mt_allocator.h:112      call   80486c4 <[EMAIL 
PROTECTED]>
0x8048993       _S_get_pool     mt_allocator.h:112      test   %eax,%eax
0x8048995       _S_get_pool     mt_allocator.h:112      je     804889a 
<main+0x1a>
0x804899b       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x80489a0       _Tune           mt_allocator.h:112      mov    %eax,0x804a780
0x80489a5       _Tune           mt_allocator.h:112      mov    $0x80,%eax
0x80489aa       _Tune           mt_allocator.h:112      mov    %eax,0x804a784
0x80489af       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x80489b4       _Tune           mt_allocator.h:112      mov    %eax,0x804a788
0x80489b9       _Tune           mt_allocator.h:112      mov    $0xff0,%eax
0x80489be       _Tune           mt_allocator.h:112      mov    %eax,0x804a78c
0x80489c3       _Tune           mt_allocator.h:112      mov    $0x1000,%eax
0x80489c8       _Tune           mt_allocator.h:112      mov    %eax,0x804a790
0x80489cd       _Tune           mt_allocator.h:112      mov    $0xa,%eax
0x80489d2       _Tune           mt_allocator.h:112      movl   $0x80494dc,(%esp)
0x80489d9       _Tune           mt_allocator.h:112      mov    %eax,0x804a794
0x80489de       _Tune           mt_allocator.h:112      call   80486d4 <[EMAIL 
PROTECTED]>
0x80489e3       __pool          mt_allocator.h:368      mov    $0x1,%edx
0x80489e8       __pool          mt_allocator.h:368      mov    %edx,0x804a7a8
0x80489ee       _S_get_pool     mt_allocator.h:450      movl   $0x804a768,(%esp)
0x80489f5       _S_get_pool     mt_allocator.h:155      movb   $0x0,0x804a7a0
0x80489fc       _S_get_pool     mt_allocator.h:112      test   %eax,%eax
0x80489fe       _S_get_pool     mt_allocator.h:112      setne  0x804a798
0x8048a05       _S_get_pool     mt_allocator.h:368      xor    %eax,%eax
0x8048a07       _S_get_pool     mt_allocator.h:155      xor    %ebx,%ebx
0x8048a09       _S_get_pool     mt_allocator.h:368      xor    %ecx,%ecx
0x8048a0b       _S_get_pool     mt_allocator.h:368      mov    %eax,0x804a7b0
0x8048a10       _S_get_pool     mt_allocator.h:372      xor    %eax,%eax
0x8048a12       _S_get_pool     mt_allocator.h:155      mov    %ebx,0x804a79c
0x8048a18       _S_get_pool     mt_allocator.h:368      mov    %ecx,0x804a7a4
0x8048a1e       _S_get_pool     mt_allocator.h:372      mov    %eax,0x804a7ac
0x8048a23       _S_get_pool     mt_allocator.h:450      call   8048704 <[EMAIL 
PROTECTED]>
0x8048a28       _S_get_pool     mt_allocator.h:450      jmp    804889a 
<main+0x1a>
0x8048a2d       _S_get_pool     mt_allocator.h:450      lea    0x0(%esi),%esi

end <2><3b8f>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): allocator

0x8048a30       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x8048a37       main            mt_allocator.h:450      call   80486c4 <[EMAIL 
PROTECTED]>
0x8048a3c       main            mt_allocator.h:450      test   %eax,%eax
0x8048a3e       main            mt_allocator.h:450      jne    8048af6 
<main+0x276>
0x8048a44       main            mt_allocator.h:450      mov    
0xffffffe8(%ebp),%edx
0x8048a47       main            mt_allocator.h:450      jmp    8048928 
<main+0xa8>
0x8048a4c       main            mt_allocator.h:450      lea    0x0(%esi),%esi
0x8048a50       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x8048a57       main            mt_allocator.h:450      call   80486c4 <[EMAIL 
PROTECTED]>
0x8048a5c       main            mt_allocator.h:450      test   %eax,%eax
0x8048a5e       main            mt_allocator.h:450      je     80488e2 
<main+0x62>

beg <2><3c23>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048a64       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x8048a69       _Tune           mt_allocator.h:112      mov    $0x8,%ecx
0x8048a6e       _Tune           mt_allocator.h:112      mov    %eax,0x804a780
0x8048a73       _Tune           mt_allocator.h:112      mov    $0x80,%eax
0x8048a78       _Tune           mt_allocator.h:112      mov    $0xff0,%edx
0x8048a7d       _Tune           mt_allocator.h:112      mov    %eax,0x804a784
0x8048a82       _Tune           mt_allocator.h:112      mov    $0x1000,%eax
0x8048a87       _Tune           mt_allocator.h:112      mov    %eax,0x804a790
0x8048a8c       _Tune           mt_allocator.h:112      mov    $0xa,%eax
0x8048a91       _Tune           mt_allocator.h:112      mov    %ecx,0x804a788
0x8048a97       _Tune           mt_allocator.h:112      mov    %edx,0x804a78c
0x8048a9d       _Tune           mt_allocator.h:112      movl   $0x80494dc,(%esp)
0x8048aa4       _Tune           mt_allocator.h:112      mov    %eax,0x804a794
0x8048aa9       _Tune           mt_allocator.h:112      call   80486d4 <[EMAIL 
PROTECTED]>

end <2><3c23>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048aae       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x8048ab5       main            mt_allocator.h:155      movb   $0x0,0x804a7a0
0x8048abc       main            mt_allocator.h:112      test   %eax,%eax
0x8048abe       main            mt_allocator.h:112      setne  0x804a798
0x8048ac5       main            mt_allocator.h:155      xor    %eax,%eax
0x8048ac7       main            mt_allocator.h:372      xor    %ecx,%ecx
0x8048ac9       main            mt_allocator.h:155      mov    %eax,0x804a79c
0x8048ace       main            mt_allocator.h:368      xor    %eax,%eax
0x8048ad0       main            mt_allocator.h:368      mov    %eax,0x804a7a4
0x8048ad5       main            mt_allocator.h:368      mov    $0x1,%eax
0x8048ada       main            mt_allocator.h:368      mov    %eax,0x804a7a8
0x8048adf       main            mt_allocator.h:368      xor    %eax,%eax
0x8048ae1       main            mt_allocator.h:368      mov    %eax,0x804a7b0
0x8048ae6       main            mt_allocator.h:372      mov    %ecx,0x804a7ac
0x8048aec       main            mt_allocator.h:450      call   8048704 <[EMAIL 
PROTECTED]>
0x8048af1       main            mt_allocator.h:450      jmp    80488e2 
<main+0x62>

beg <2><3c6a>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048af6       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x8048afb       _Tune           mt_allocator.h:112      mov    %eax,0x804a780
0x8048b00       _Tune           mt_allocator.h:112      mov    $0x80,%eax
0x8048b05       _Tune           mt_allocator.h:112      mov    %eax,0x804a784
0x8048b0a       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x8048b0f       _Tune           mt_allocator.h:112      mov    %eax,0x804a788
0x8048b14       _Tune           mt_allocator.h:112      mov    $0xff0,%eax
0x8048b19       _Tune           mt_allocator.h:112      mov    %eax,0x804a78c
0x8048b1e       _Tune           mt_allocator.h:112      mov    $0x1000,%eax
0x8048b23       _Tune           mt_allocator.h:112      mov    %eax,0x804a790
0x8048b28       _Tune           mt_allocator.h:112      mov    $0xa,%eax
0x8048b2d       _Tune           mt_allocator.h:112      mov    %eax,0x804a794
0x8048b32       _Tune           mt_allocator.h:112      movl   $0x80494dc,(%esp)
0x8048b39       _Tune           mt_allocator.h:112      call   80486d4 <[EMAIL 
PROTECTED]>
0x8048b3e       __pool_base     mt_allocator.h:155      movb   $0x0,0x804a7a0

end <2><3c6a>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048b45       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x8048b4c       main            mt_allocator.h:112      test   %eax,%eax
0x8048b4e       main            mt_allocator.h:368      mov    $0x1,%eax
0x8048b53       main            mt_allocator.h:112      setne  0x804a798
0x8048b5a       main            mt_allocator.h:368      xor    %edx,%edx
0x8048b5c       main            mt_allocator.h:155      xor    %ecx,%ecx
0x8048b5e       main            mt_allocator.h:368      mov    %eax,0x804a7a8
0x8048b63       main            mt_allocator.h:368      xor    %eax,%eax
0x8048b65       main            mt_allocator.h:368      mov    %eax,0x804a7b0
0x8048b6a       main            mt_allocator.h:372      xor    %eax,%eax
0x8048b6c       main            mt_allocator.h:368      mov    %edx,0x804a7a4
0x8048b72       main            mt_allocator.h:155      mov    %ecx,0x804a79c
0x8048b78       main            mt_allocator.h:372      mov    %eax,0x804a7ac
0x8048b7d       main            mt_allocator.h:450      call   8048704 <[EMAIL 
PROTECTED]>
0x8048b82       main            mt_allocator.h:450      mov    
0xffffffe8(%ebp),%edx
0x8048b85       main            mt_allocator.h:450      jmp    8048928 
<main+0xa8>

beg <2><3cb1>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048b8a       _Tune           mt_allocator.h:112      mov    $0x8,%eax
0x8048b8f       _Tune           mt_allocator.h:112      mov    $0x8,%ecx
0x8048b94       _Tune           mt_allocator.h:112      mov    %eax,0x804a788
0x8048b99       _Tune           mt_allocator.h:112      mov    $0xff0,%eax
0x8048b9e       _Tune           mt_allocator.h:112      mov    $0x80,%edx
0x8048ba3       _Tune           mt_allocator.h:112      mov    %eax,0x804a78c
0x8048ba8       _Tune           mt_allocator.h:112      mov    $0x1000,%eax
0x8048bad       __pool          mt_allocator.h:368      mov    $0x1,%ebx
0x8048bb2       __pool          mt_allocator.h:112      mov    %eax,0x804a790
0x8048bb7       __pool          mt_allocator.h:112      mov    $0xa,%eax
0x8048bbc       __pool          mt_allocator.h:112      mov    %ecx,0x804a780
0x8048bc2       __pool          mt_allocator.h:112      mov    %edx,0x804a784
0x8048bc8       __pool          mt_allocator.h:112      mov    %eax,0x804a794
0x8048bcd       __pool          mt_allocator.h:112      movl   $0x80494dc,(%esp)
0x8048bd4       __pool          mt_allocator.h:112      call   80486d4 <[EMAIL 
PROTECTED]>
0x8048bd9       __pool          mt_allocator.h:155      movb   $0x0,0x804a7a0

end <2><3cb1>: Abbrev Number: 92 (DW_TAG_inlined_subroutine): __pool

0x8048be0       __pool          mt_allocator.h:368      mov    %ebx,0x804a7a8
0x8048be6       main            mt_allocator.h:450      movl   $0x804a768,(%esp)
0x8048bed       main            mt_allocator.h:112      test   %eax,%eax
0x8048bef       main            mt_allocator.h:112      setne  0x804a798
0x8048bf6       main            mt_allocator.h:155      xor    %eax,%eax
0x8048bf8       main            mt_allocator.h:368      xor    %ecx,%ecx
0x8048bfa       main            mt_allocator.h:372      xor    %edx,%edx
0x8048bfc       main            mt_allocator.h:155      mov    %eax,0x804a79c
0x8048c01       main            mt_allocator.h:368      xor    %eax,%eax
0x8048c03       main            mt_allocator.h:368      mov    %eax,0x804a7a4
0x8048c08       main            mt_allocator.h:368      mov    %ecx,0x804a7b0
0x8048c0e       main            mt_allocator.h:372      mov    %edx,0x804a7ac
0x8048c14       main            mt_allocator.h:450      call   8048704 <[EMAIL 
PROTECTED]>
0x8048c19       main            mt_allocator.h:450      movzbl 0x804a768,%eax
0x8048c20       main            mt_allocator.h:450      jmp    804897f 
<main+0xff>

beg <2><3cf8>: Abbrev Number: 91 (DW_TAG_inlined_subroutine): ~_Vector_impl

0x8048c25       ~_Vector_impl   stl_vector.h:101        mov    %eax,(%esp)
0x8048c28       ~_Vector_impl   stl_vector.h:101        call   8048774 <[EMAIL 
PROTECTED]>

end <2><3cf8>: Abbrev Number: 91 (DW_TAG_inlined_subroutine): ~_Vector_impl
end <1><39c1>: Abbrev Number: 111 (DW_TAG_subprogram)

0x8048c2d       main            stl_vector.h:101        nop    
0x8048c2e       main            ??:0                    nop    
0x8048c2f       main            ??:0                    nop

-- 
           Summary: g++ generates incomplete debug information for given
                    testcase
           Product: gcc
           Version: 1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fnf at specifixinc dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20268

Reply via email to