public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/21470] gdb producer-sniffs for "clang"
       [not found] <bug-21470-4717@http.sourceware.org/bugzilla/>
@ 2023-01-29 10:23 ` vries at gcc dot gnu.org
  2023-01-29 10:30 ` vries at gcc dot gnu.org
  2023-01-31 23:34 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-29 10:23 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=21470

Tom de Vries <vries at gcc dot gnu.org> changed:

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

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
In commit 154f2735ad4 ("[gdb/testsuite] Fix gdb.ada/access_tagged_param.exp for
aarch64") I did:
...
-if ![runto call_me] then {
+if ![runto pck.adb:20] then {
...
to make the test-case robust against problems in prologue analysis.

Of course problems in prologue analysis need to be fixed, but we don't want to
be exposed to this in lots of unrelated test-cases, which then fail on some but
not on other architectures, hence the fix.

Anyway, let's change this back, and look at what's generated:
...
(gdb) break call_me^M
Breakpoint 1 at 0x401f9a: file
/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb,
line 20.^M
...

So, it looks like gdb decided that the first 3 insns are prologue:
...
0000000000401f92 <pck__call_me>:
  401f92:       55                      push   %rbp
  401f93:       48 89 e5                mov    %rsp,%rbp
  401f96:       48 89 7d f8             mov    %rdi,-0x8(%rbp)
  401f9a:       48 8b 45 f8             mov    -0x8(%rbp),%rax
...

Using additional_flags=-fdump-rtl-all and looking at pck.adb.309r.final we can
confirm that the first 2 insns are prologue:
...
(note 4 1 32 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(insn/f 32 4 33 2 (set (mem:DI (pre_dec:DI (reg/f:DI 7 sp)) [0  S8 A8])
        (reg/f:DI 6 bp))
"/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb":18
57 {*pushdi2_rex64}
     (nil))
(insn/f 33 32 34 2 (set (reg/f:DI 6 bp)
        (reg/f:DI 7 sp))
"/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb":18
81 {*movdi_internal}
     (nil))
(insn 34 33 35 2 (set (mem/v:BLK (scratch:DI) [0  A8])
        (unspec:BLK [
                (mem/v:BLK (scratch:DI) [0  A8])
            ] UNSPEC_MEMORY_BLOCKAGE))
"/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb":18
687 {*memory_blockage}
     (nil))
(note 35 34 2 2 NOTE_INSN_PROLOGUE_END)
(insn 2 35 3 2 (set (mem/f/c:DI (plus:DI (reg/f:DI 6 bp)
                (const_int -8 [0xfffffffffffffff8])) [5 d+0 S8 A64])
        (reg:DI 5 di [ d ]))
"/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb":18
81 {*movdi_internal}
     (nil))
(note 3 2 6 2 NOTE_INSN_FUNCTION_BEG)
...
and the third insn is in the twilight zone between prologue end and function
begin, and depending on your definition of prologue, can be still considered
part of the prologue.

Note that due to compiling at -O0, there's no .debug_loc contribution, so the
DW_AT_location expression for the function parameter 'D' is consider only valid
after the prologue, and in this sense the third insn is certainly part of the
prologue:
...
(gdb) si
pck.call_me (d=...) at pck.adb:18
18         procedure Call_Me (D : in out Data) is
(gdb) p d
$1 = (null)
(gdb) si
0x0000000000401f93      18         procedure Call_Me (D : in out Data) is
(gdb) p d
$2 = (null)
(gdb) si
0x0000000000401f96      18         procedure Call_Me (D : in out Data) is
(gdb) p d
$3 = (null)
(gdb) si
20            if D.One > D.Two then
(gdb) p d
$4 = (one => 1, two => 2, three => 3, four => 4, five => 5, six => 6)
(gdb) 
...

So, say we start to trust the dwarf line table (to be in a certain format that
allows us to determine where the prologue ends).

Let's do that using "maint set skip-prologue line"
(https://sourceware.org/pipermail/gdb-patches/2022-August/191343.html):
...
clean_restart

gdb_test_no_output "maint set skip-prologue line"

gdb_load ${binfile}
...

Now we have the incorrect:
...
(gdb) break call_me^M
Breakpoint 1 at 0x401f92: file
/home/vries/gdb_versions/devel/binutils-gdb.git/gdb/testsuite/gdb.ada/ref_param/pck.adb,
line 18.^M
...

The line table as decoded by readelf is:
...
File name         Line number    Starting address    View    Stmt
pck.adb                    18            0x401f92               x
pck.adb                    18            0x401f92       1       x
pck.adb                    20            0x401f9a               x
pck.adb                    21            0x401fab               x
pck.adb                    23            0x401fb9               x
pck.adb                     -            0x401fbd
...
and the summary of that by gdb is:
...
INDEX  LINE   ADDRESS            IS-STMT PROLOGUE-END 
0      18     0x0000000000401f92 Y                    
1      18     0x0000000000401f92 Y                    
2      20     0x0000000000401f9a Y                    
3      21     0x0000000000401fab Y                    
4      23     0x0000000000401fb9 Y                    
5      END    0x0000000000401fbd Y                    
...

This is with gcc 7.5.0.  With gcc 12.2.1, I get a line table without the entry
at index 1, and things do work as expected.

My hunch at this point is that this is due to gcc commit c029fcb5680 ("Reset
force_source_line in final.c"), which is first present in release 11.1.0.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug symtab/21470] gdb producer-sniffs for "clang"
       [not found] <bug-21470-4717@http.sourceware.org/bugzilla/>
  2023-01-29 10:23 ` [Bug symtab/21470] gdb producer-sniffs for "clang" vries at gcc dot gnu.org
@ 2023-01-29 10:30 ` vries at gcc dot gnu.org
  2023-01-31 23:34 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-29 10:30 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=21470

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom Tromey from comment #3)
> One specific regression is gdb.ada/ref_param.exp, which fails because
> gdb starts believing the DWARF line table.  But I think the line table
> is correct and the test might be wrong.
> 
> CU: /home/tromey/gdb/binutils-gdb/gdb/testsuite/gdb.ada/ref_param/pck.adb:
> File name                            Line number    Starting address
> pck.adb                                       18            0x4012be
> 
> pck.adb                                       18            0x4012be
> 
> pck.adb                                       20            0x4012c6
> pck.adb                                       21            0x4012d7
> pck.adb                                       23            0x4012e5
> 
> 
> With my current patch, the breakpoint is set on line 18.
> Without it, it is set at line 20.
> 
> Doesn't line 18 seem correct though?

From the analysis in the previous comment, I'd say that line 20 is correct, and
line 18 is incorrect.  That is, the line table is incorrect due to a gcc bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug symtab/21470] gdb producer-sniffs for "clang"
       [not found] <bug-21470-4717@http.sourceware.org/bugzilla/>
  2023-01-29 10:23 ` [Bug symtab/21470] gdb producer-sniffs for "clang" vries at gcc dot gnu.org
  2023-01-29 10:30 ` vries at gcc dot gnu.org
@ 2023-01-31 23:34 ` vries at gcc dot gnu.org
  2 siblings, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2023-01-31 23:34 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=21470

--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #4)
> My hunch at this point is that this is due to gcc commit c029fcb5680 ("Reset
> force_source_line in final.c"), which is first present in release 11.1.0.

Confirmed, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108615 .

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2023-01-31 23:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-21470-4717@http.sourceware.org/bugzilla/>
2023-01-29 10:23 ` [Bug symtab/21470] gdb producer-sniffs for "clang" vries at gcc dot gnu.org
2023-01-29 10:30 ` vries at gcc dot gnu.org
2023-01-31 23:34 ` vries at gcc dot gnu.org

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).