public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug symtab/21470] gdb producer-sniffs for "clang"
Date: Sun, 29 Jan 2023 10:23:57 +0000	[thread overview]
Message-ID: <bug-21470-4717-nP5bQ2syAL@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-21470-4717@http.sourceware.org/bugzilla/>

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.

       reply	other threads:[~2023-01-29 10:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-21470-4717@http.sourceware.org/bugzilla/>
2023-01-29 10:23 ` vries at gcc dot gnu.org [this message]
2023-01-29 10:30 ` vries at gcc dot gnu.org
2023-01-31 23:34 ` vries at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-21470-4717-nP5bQ2syAL@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).