From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A48713858D32; Fri, 13 Jan 2023 11:25:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A48713858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673609120; bh=FslUXsDI6DwLsZd7SPGyzIMpTXip9Tb5jkjNE3r12Ac=; h=From:To:Subject:Date:From; b=TCwq6zxJIonq444clTJCKHtYYJaSkyjO/PhlKjYW2k0NmQzv8i8dhmPkJUiU28e4f C7co7sRaLNEsBih8yP9pJCSNRsMl6IoYDWHDzctXvW04KFId22fE75POE+kKvz20dt se5BQPhKUozLYGJBwYP5W6wk3GCzAa3bRQHtgxjw= From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug gdb/29996] New: [gdb/reverse] Reverse stepping skips first line in function in optimized code Date: Fri, 13 Jan 2023 11:25:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29996 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 =3D x; 8 j =3D y; 9 k =3D 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=20 Temporary breakpoint 1, main () at test.c:15 15 foo (); (gdb) step foo () at test.c:7 7 i =3D x; (gdb) step 8 j =3D y; (gdb) step 9 k =3D z; (gdb) step 10 } (gdb)=20 ... So far, so good. Now let's try reverse stepping: ... 10 } (gdb) reverse-step 9 k =3D z; (gdb) reverse-step 8 j =3D y; (gdb) reverse-step No more reverse-execution history. main () at test.c:15 15 foo (); (gdb)=20 ... 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 =3D 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=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20 (unless it's the function entry point, in which case=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 keep going back to the call point). */ CORE_ADDR stop_pc =3D ecs->event_thread->stop_pc (); if (stop_pc =3D=3D ecs->event_thread->control.step_range_start && stop_pc !=3D ecs->stop_func_start && execution_direction =3D=3D 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. --=20 You are receiving this mail because: You are on the CC list for the bug.=