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 gdb/31070] Abnormal Jump in Execution for builtin function using 'stepi' Command in GDB
Date: Thu, 16 Nov 2023 11:36:19 +0000	[thread overview]
Message-ID: <bug-31070-4717-KjqRw30v0h@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-31070-4717@http.sourceware.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |NOTABUG
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
I can reproduce this:
...
Temporary breakpoint 1, main () at small.c:10
10        __builtin_prefetch (glob_int_arr, 0, 0);
(gdb) si
0x0000000000401044 in simple_global () at small.c:11
11        __builtin_prefetch (glob_ptr_int, 0, 0);
(gdb) si
0x000000000040104b in main () at small.c:19
19        exit (0);
(gdb) si
0x000000000040104d in simple_global () at small.c:10
10        __builtin_prefetch (glob_int_arr, 0, 0);
(gdb) si
11        __builtin_prefetch (glob_ptr_int, 0, 0);
...

When decoding the line numbers I see:
...
small.c                                       11            0x401044        
small.c                                       19            0x40104b        
small.c                                       10            0x40104d        
small.c                                       11            0x401054           
   ...
which perfectly matches the progression we see.

So gdb doesn't do anything wrong, it accurately show the line info as generated
by gcc.

So why does the insn at 0x40104b have line number 19?

The disassembly is:
...
0000000000401040 <main>:
  401040:       48 83 ec 08             sub    $0x8,%rsp
  401044:       48 8b 05 cd 2f 00 00    mov    0x2fcd(%rip),%rax        #
404018 <glob_ptr_int>
  40104b:       31 ff                   xor    %edi,%edi
  40104d:       0f 18 05 ec 2f 00 00    prefetchnta 0x2fec(%rip)        #
404040 <glob_int_arr>
  401054:       0f 18 00                prefetchnta (%rax)
  401057:       e8 d4 ff ff ff          call   401030 <exit@plt>
  40105c:       0f 1f 40 00             nopl   0x0(%rax)
...
and the call to exit is represented by these two insns:
...
  40104b:       31 ff                   xor    %edi,%edi
  401057:       e8 d4 ff ff ff          call   401030 <exit@plt>
...

Optimization separated the two insns and that causes the "jumping" through the
lines.

AFAICT, this falls in the range of expected behaviour when debugging optimized
code.

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

  parent reply	other threads:[~2023-11-16 11:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-16  7:24 [Bug gdb/31070] New: " iamanonymous.cs at gmail dot com
2023-11-16  7:25 ` [Bug gdb/31070] " iamanonymous.cs at gmail dot com
2023-11-16  7:27 ` iamanonymous.cs at gmail dot com
2023-11-16  7:28 ` iamanonymous.cs at gmail dot com
2023-11-16  8:26 ` iamanonymous.cs at gmail dot com
2023-11-16  8:33 ` iamanonymous.cs at gmail dot com
2023-11-16 11:36 ` vries at gcc dot gnu.org [this message]
2023-11-16 11:54 ` iamanonymous.cs at gmail dot com
2023-11-16 11:56 ` vries at gcc dot gnu.org
2023-11-16 11:59 ` iamanonymous.cs at gmail dot com

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-31070-4717-KjqRw30v0h@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).