public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/51358] New: missing location
@ 2011-11-30 16:49 mark at gcc dot gnu.org
  2011-11-30 21:07 ` [Bug debug/51358] " jan.kratochvil at redhat dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: mark at gcc dot gnu.org @ 2011-11-30 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51358
           Summary: missing location
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mark@gcc.gnu.org
                CC: dodji@gcc.gnu.org, tromey@redhat.com


This is related to the following systemtap bug report:
http://sourceware.org/bugzilla/show_bug.cgi?id=13420

This is using g++ (GCC) 4.7.0 20111130 (experimental), but can be reproduced
with other versions (g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4) in particular).

Compiling the following with g++ -gdwarf-4 -o length length.cxx

#include <string>

size_t
length(const std::string& str)
{
    int res = str.length();
    return res;
}

int
main()
{
    std::string hello = "Hello World!";
    return 12 != length(hello);
}


Produces:

00000000 00000014 00000000 CIE
  Version:               1
  Augmentation:          "zR"
  Code alignment factor: 1
  Data alignment factor: -8
  Return address column: 16
  Augmentation data:     1b

  DW_CFA_def_cfa: r7 (rsp) ofs 8
  DW_CFA_offset: r16 (rip) at cfa-8
  DW_CFA_nop
  DW_CFA_nop

00000018 0000001c 0000001c FDE cie=00000000 pc=0040088c..004008ae
  DW_CFA_advance_loc: 1 to 0040088d
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r6 (rbp) at cfa-16
  DW_CFA_advance_loc: 3 to 00400890
  DW_CFA_def_cfa_register: r6 (rbp)
  DW_CFA_advance_loc: 29 to 004008ad
  DW_CFA_def_cfa: r7 (rsp) ofs 8
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop

and

 <1><a86>: Abbrev Number: 95 (DW_TAG_subprogram)
    <a87>   DW_AT_external    : 1       
    <a87>   DW_AT_name        : (indirect string, offset: 0x1aec): length       
    <a8b>   DW_AT_decl_file   : 1       
    <a8c>   DW_AT_decl_line   : 4       
    <a8d>   DW_AT_linkage_name: (indirect string, offset: 0x293): _Z6lengthRKSs 
    <a91>   DW_AT_type        : <0x2e2> 
    <a95>   DW_AT_low_pc      : 0x40088c        
    <a9d>   DW_AT_high_pc     : 0x4008ae        
    <aa5>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
    <aa7>   Unknown AT value: 2116: 1   
    <aa7>   DW_AT_sibling     : <0xada> 
 <2><aab>: Abbrev Number: 96 (DW_TAG_formal_parameter)
    <aac>   DW_AT_name        : str     
    <ab0>   DW_AT_decl_file   : 1       
    <ab1>   DW_AT_decl_line   : 4       
    <ab2>   DW_AT_type        : <0xada> 
    <ab6>   DW_AT_location    : 2 byte block: 91 58     (DW_OP_fbreg: -40)

Which seems to suggest that the formal_parameter "str" can always be accessed
through fbreg -40. But this isn't true as you can see by looking at the
generated code:

Dump of assembler code for function length(std::string const&):
   0x000000000040088c <+0>:    push   %rbp
   0x000000000040088d <+1>:    mov    %rsp,%rbp
   0x0000000000400890 <+4>:    sub    $0x20,%rsp
   0x0000000000400894 <+8>:    mov    %rdi,-0x18(%rbp)
   0x0000000000400898 <+12>:    mov    -0x18(%rbp),%rax
   0x000000000040089c <+16>:    mov    %rax,%rdi
   0x000000000040089f <+19>:    callq  0x4006c0 <_ZNKSs6lengthEv@plt>
   0x00000000004008a4 <+24>:    mov    %eax,-0x4(%rbp)
   0x00000000004008a7 <+27>:    mov    -0x4(%rbp),%eax
   0x00000000004008aa <+30>:    cltq   
   0x00000000004008ac <+32>:    leaveq 
   0x00000000004008ad <+33>:    retq   
End of assembler dump.

The argument was actually in %rdi, which isn't pushed on the stack till 400894,
so when we probe at the start of the function (40088c) we will see garbage when
trying to extract the str parameter.

Is there a way a dwarf consumer could have known that?

GCC also doesn't seem to produce line table prologue markers, so it also
doesn't help trying to search for the end of prologue.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] missing location
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
@ 2011-11-30 21:07 ` jan.kratochvil at redhat dot com
  2011-12-01 11:08 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jan.kratochvil at redhat dot com @ 2011-11-30 21:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jan Kratochvil <jan.kratochvil at redhat dot com> 2011-11-30 20:46:54 UTC ---
(In reply to comment #0)
> Compiling the following with g++ -gdwarf-4 -o length length.cxx
[...]
>     <aa5>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
[...]
>     <ab6>   DW_AT_location    : 2 byte block: 91 58     (DW_OP_fbreg: -40)
> 
> Which seems to suggest that the formal_parameter "str" can always be accessed
> through fbreg -40. But this isn't true as you can see by looking at the
> generated code:
> 
> Dump of assembler code for function length(std::string const&):
>    0x000000000040088c <+0>:    push   %rbp
>    0x000000000040088d <+1>:    mov    %rsp,%rbp
>    0x0000000000400890 <+4>:    sub    $0x20,%rsp
>    0x0000000000400894 <+8>:    mov    %rdi,-0x18(%rbp)
[...]
> The argument was actually in %rdi, which isn't pushed on the stack till
> 400894, so when we probe at the start of the function (40088c) we will see
> garbage when trying to extract the str parameter.
> 
> Is there a way a dwarf consumer could have known that?

This is AFAIK correct.  With -O0 there is no location tracking and the consumer
must skip the prologue first before considering DW_AT_location content.

See GDB symtab->locations_valid detection so that GDB at least knows the cases
when it does not have to skip the prologue.

locations_valid detection should be further extended by detecting -O>=1 in
DW_AT_producer for some rare cases where the current GDB detection would not
work.  But -grecord-gcc-switches is not default in FSF GCC so the
DW_AT_producer may not be so useful for FSF GCC builds.


> GCC also doesn't seem to produce line table prologue markers, so it also
> doesn't help trying to search for the end of prologue.

(a) GDB reliably detects the prologue end by skipping the first source line.
    GCC even supports this by producing 0-line advance in some cases.
(b) I cannot find the Bug now but my request for DW_LNS_set_prologue_end has
    been declined as the current source-line based detection works correctly
    and DW_LNS_set_prologue_end would just needlessly increase the debug info
    size.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] missing location
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
  2011-11-30 21:07 ` [Bug debug/51358] " jan.kratochvil at redhat dot com
@ 2011-12-01 11:08 ` jakub at gcc dot gnu.org
  2012-08-06 18:36 ` [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-12-01 11:08 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-12-01 11:07:44 UTC ---
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42801#c2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
  2011-11-30 21:07 ` [Bug debug/51358] " jan.kratochvil at redhat dot com
  2011-12-01 11:08 ` jakub at gcc dot gnu.org
@ 2012-08-06 18:36 ` rguenth at gcc dot gnu.org
  2012-08-12 18:38 ` jan.kratochvil at redhat dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-08-06 18:36 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-debug
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-08-06
                 CC|                            |rguenth at gcc dot gnu.org
     Ever Confirmed|0                           |1

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-08-06 18:35:35 UTC ---
I also recently ran into this ... why can't GCC simply provide no location
information for the prologue?  Thus, properly restrict the PC range the
fb-based locations are valid?  At the moment GCC simply lies.

Confirmed.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2012-08-06 18:36 ` [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA rguenth at gcc dot gnu.org
@ 2012-08-12 18:38 ` jan.kratochvil at redhat dot com
  2012-08-12 20:22 ` fche at redhat dot com
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jan.kratochvil at redhat dot com @ 2012-08-12 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jan Kratochvil <jan.kratochvil at redhat dot com> 2012-08-12 18:37:26 UTC ---
It would not be helpful, systemtap would then see no data (just not wrong
data).

Also at that time location list will need to be used and currently GDB when it
sees any location list it thinks it no longer needs to skip the prologue.
OTOH GDB could look at -grecord-gcc-switches first which it currently does not
so I should just finally implement -grecord-gcc-switches in GDB in such case.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2012-08-12 18:38 ` jan.kratochvil at redhat dot com
@ 2012-08-12 20:22 ` fche at redhat dot com
  2012-08-12 20:31 ` mark at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fche at redhat dot com @ 2012-08-12 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Frank Ch. Eigler <fche at redhat dot com> 2012-08-12 20:21:24 UTC ---
(In reply to comment #4)
> It would not be helpful, systemtap would then see no data [...]

Not quite; systemtap can search the PC ranges/line tables for a nearby address
where a corrected location list would cover.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2012-08-12 20:22 ` fche at redhat dot com
@ 2012-08-12 20:31 ` mark at gcc dot gnu.org
  2012-08-13  8:56 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: mark at gcc dot gnu.org @ 2012-08-12 20:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Mark Wielaard <mark at gcc dot gnu.org> 2012-08-12 20:30:36 UTC ---
(In reply to comment #5)
> (In reply to comment #4)
> > It would not be helpful, systemtap would then see no data [...]
> 
> Not quite; systemtap can search the PC ranges/line tables for a nearby address
> where a corrected location list would cover.

And at least systemtap could give an error/warning to the user the data isn't
available instead of providing bogus values...


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2012-08-12 20:31 ` mark at gcc dot gnu.org
@ 2012-08-13  8:56 ` rguenth at gcc dot gnu.org
  2012-11-18  4:13 ` [Bug debug/51358] [4.8 Regression] " pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-08-13  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-08-13 08:55:05 UTC ---
(In reply to comment #4)
> It would not be helpful, systemtap would then see no data (just not wrong
> data).
> 
> Also at that time location list will need to be used and currently GDB when it
> sees any location list it thinks it no longer needs to skip the prologue.
> OTOH GDB could look at -grecord-gcc-switches first which it currently does not
> so I should just finally implement -grecord-gcc-switches in GDB in such case.

I think seeing wrong data, thus, wrong-debug is never superior over "no debug
info / no data".


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] [4.8 Regression] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2012-08-13  8:56 ` rguenth at gcc dot gnu.org
@ 2012-11-18  4:13 ` pinskia at gcc dot gnu.org
  2012-11-19  9:10 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-11-18  4:13 UTC (permalink / raw)
  To: gcc-bugs


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.8.0
            Summary|incorrect/missing location  |[4.8 Regression]
                   |for function arg, -O0,      |incorrect/missing location
                   |without VTA                 |for function arg, -O0,
                   |                            |without VTA

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-11-18 04:13:17 UTC ---
This has now become an user visible regression as dwarf4 is now default.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] [4.8 Regression] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2012-11-18  4:13 ` [Bug debug/51358] [4.8 Regression] " pinskia at gcc dot gnu.org
@ 2012-11-19  9:10 ` jakub at gcc dot gnu.org
  2012-12-06 16:21 ` [Bug debug/51358] " rguenth at gcc dot gnu.org
  2013-12-26  0:21 ` fche at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-19  9:10 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-19 09:09:59 UTC ---
I don't see the link between the bugreport and dwarf4, why do you think this is
a regression?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2012-11-19  9:10 ` jakub at gcc dot gnu.org
@ 2012-12-06 16:21 ` rguenth at gcc dot gnu.org
  2013-12-26  0:21 ` fche at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-06 16:21 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.8.0                       |---
            Summary|[4.8 Regression]            |incorrect/missing location
                   |incorrect/missing location  |for function arg, -O0,
                   |for function arg, -O0,      |without VTA
                   |without VTA                 |

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> 2012-12-06 16:21:33 UTC ---
Don't see that either.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA
  2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2012-12-06 16:21 ` [Bug debug/51358] " rguenth at gcc dot gnu.org
@ 2013-12-26  0:21 ` fche at redhat dot com
  10 siblings, 0 replies; 12+ messages in thread
From: fche at redhat dot com @ 2013-12-26  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Frank Ch. Eigler <fche at redhat dot com> ---
This problem continues to hit in gcc 4.8.2.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-12-26  0:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-30 16:49 [Bug debug/51358] New: missing location mark at gcc dot gnu.org
2011-11-30 21:07 ` [Bug debug/51358] " jan.kratochvil at redhat dot com
2011-12-01 11:08 ` jakub at gcc dot gnu.org
2012-08-06 18:36 ` [Bug debug/51358] incorrect/missing location for function arg, -O0, without VTA rguenth at gcc dot gnu.org
2012-08-12 18:38 ` jan.kratochvil at redhat dot com
2012-08-12 20:22 ` fche at redhat dot com
2012-08-12 20:31 ` mark at gcc dot gnu.org
2012-08-13  8:56 ` rguenth at gcc dot gnu.org
2012-11-18  4:13 ` [Bug debug/51358] [4.8 Regression] " pinskia at gcc dot gnu.org
2012-11-19  9:10 ` jakub at gcc dot gnu.org
2012-12-06 16:21 ` [Bug debug/51358] " rguenth at gcc dot gnu.org
2013-12-26  0:21 ` fche at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).