public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/29996] New: [gdb/reverse] Reverse stepping skips first line in function in optimized code
@ 2023-01-13 11:25 vries at gcc dot gnu.org
0 siblings, 0 replies; only message in thread
From: vries at gcc dot gnu.org @ 2023-01-13 11:25 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=29996
Bug ID: 29996
Summary: [gdb/reverse] Reverse stepping skips first line in
function in optimized code
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: gdb
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
Consider test-case test.c:
...
$ cat -n test.c
1 int i, j, k;
2 int x, y, z;
3
4 void __attribute__((noinline, noclone))
5 foo (void)
6 {
7 i = x;
8 j = y;
9 k = z;
10 }
11
12 int
13 main (void)
14 {
15 foo ();
16 return 0;
17 }
...
Compiled with -O2 (using gcc 7.5.0):
...
$ gcc -g -O2 test.c
...
Let's step through the program, while recording:
...
$ gdb -q a.out -ex start -ex record
Reading symbols from a.out...
Temporary breakpoint 1 at 0x4003c0: file test.c, line 15.
Starting program: a.out
Temporary breakpoint 1, main () at test.c:15
15 foo ();
(gdb) step
foo () at test.c:7
7 i = x;
(gdb) step
8 j = y;
(gdb) step
9 k = z;
(gdb) step
10 }
(gdb)
...
So far, so good.
Now let's try reverse stepping:
...
10 }
(gdb) reverse-step
9 k = z;
(gdb) reverse-step
8 j = y;
(gdb) reverse-step
No more reverse-execution history.
main () at test.c:15
15 foo ();
(gdb)
...
Hmm, why did we skip over line 7?
Minimal reproducer:
...
$ gdb -q -batch a.out -ex start -ex record -ex "break 8" -ex continue \
-ex reverse-step
Temporary breakpoint 1 at 0x4003c0: file test.c, line 15.
Temporary breakpoint 1, main () at test.c:15
15 foo ();
Breakpoint 2 at 0x4004bc: file test.c, line 8.
Breakpoint 2, foo () at test.c:8
8 j = y;
No more reverse-execution history.
main () at test.c:15
15 foo ();
...
It's because of this piece of code:
...
/* When stepping backward, stop at beginning of line range
(unless it's the function entry point, in which case
keep going back to the call point). */
CORE_ADDR stop_pc = ecs->event_thread->stop_pc ();
if (stop_pc == ecs->event_thread->control.step_range_start
&& stop_pc != ecs->stop_func_start
&& execution_direction == EXEC_REVERSE)
end_stepping_range (ecs);
else
keep_going (ecs);
...
which does the wrong thing for optimized code.
For forward execution, the relevant logic is in skip_prologue_sal, see the
locations_valid () test.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-13 11:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 11:25 [Bug gdb/29996] New: [gdb/reverse] Reverse stepping skips first line in function in optimized code 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).