Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC PATCH 0/8] breakpoint handling
@ 2026-10-01 10:28 Markus Metzger
  2026-10-01 10:28 ` [RFC PATCH 1/8] gdb, infrun: do not discard a step-completed pending waitstatus Markus Metzger
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Markus Metzger @ 2026-10-01 10:28 UTC (permalink / raw)
  To: gdb-patches

This RFC consists of three parts.  The first part

  gdb, infrun: do not discard a step-completed pending waitstatus

was submitted as patch[1].  It fixes a bug[2] with breakpoints on adjacent
instructions getting skipped during step-over.

Discussion[3] on the patch and further investigation revealed an issue
with stepping over newly inserted breakpoints at the current location
after switching to a thread that just completed a step-over, e.g.

    (gdb) thread <other thread that completed a step-over>
    (gdb) break
    (gdb) continue

would now hit the breakpoint, whereas GDB's normal behavior is to step the
current thread over breakpoints at the current location.  The issue is the
extra step completed event that we're no longer discarding, which is
mis-interpreted as having completed the step-over at the current location.

Thread A completed a step-over, but GDB chose to present another event at
thread B to the user.  Thread A's event used to be discarded, but is now
saved as pending event.  When the user switches to thread A, inserts a
breakpoint, and continues, proceed() finds the breakpoint at the current
location and starts a step-over.  When it resumes thread A, it is not
resumed on the target and the pending event is reported instead.  We're
still at the same location and the breakpoint is still there, and GDB now
reports that we hit that breakpoint.

GDBs behavior is inconsistent in that regard, because

    (gdb) break
    (gdb) thread <some other thread>
    (gdb) continue

will make the thread we switched away from hit the breakpoint, whereas

    (gdb) break
    (gdb) continue

will skip the breakpoint (at least for the current thread).

The second part

  gdb, infrun: track last waitstatus per thread
  gdb, infrun: simplify print_stop_location()
  gdb, thread: simplify print_selected_thread_frame()
  gdb, interp: repeat stop event when switching threads
  gdb, infrun: handle stop event when selecting a thread

tries to perserve the current behavior, i.e. step the current thread over
a newly inserted breakpoint at the current location, by handling pending
events already when selecting a thread.  It also prints the last stop
notification for the selected thread, which could be considered an
improvement on its own.

In the above scenario, the pending step completed event would already be
handled when switching to that thread.  Any breakpoint that is already
inserted at that location would be reported, including any breakpoints
that were added between the thread stopping and switching to it.

When we now insert a breakpoint and continue, there is no pending event
and the step-over succeeds (unless the step completes without making
progress for some other reason, of course).

The third part

  gdb, infrun: inline init_thread_stepping_state()
  gdb, infrun: only step over breakpoints that were hit

makes GDB's breakpoint behavior more consistent.  It only steps over
breakoints that were actually hit.  This makes

    (gdb) set $pc = 0xf00
    (gdb) continue

behave similar to

    (gdb) jump 0xf00

and it will hit the breakpoint inserted by

    (gdb) break

With respect to the latter, while the second part tries to preserve the
current behavior, the thrid part intentionally changes it, so we would
probably pick one or the other direction.  Or an entirely different one.


[1]: https://sourceware.org/pipermail/gdb-patches/2026-September/230359.html
[2]: https://sourceware.org/bugzilla/show_bug.cgi?id=34380
[3]: https://sourceware.org/pipermail/gdb-patches/2026-September/230527.html

Markus Metzger (8):
  gdb, infrun: do not discard a step-completed pending waitstatus
  gdb, infrun: track last waitstatus per thread
  gdb, infrun: simplify print_stop_location()
  gdb, thread: simplify print_selected_thread_frame()
  gdb, interp: repeat stop event when switching threads
  gdb, infrun: handle stop event when selecting a thread
  gdb, infrun: inline init_thread_stepping_state()
  gdb, infrun: only step over breakpoints that were hit

 gdb/cli/cli-interp.c                      |  29 +++++-
 gdb/gdbthread.h                           |   3 +
 gdb/infcmd.c                              |  10 +-
 gdb/infrun.c                              | 111 +++++++++-------------
 gdb/infrun.h                              |   4 +
 gdb/mi/mi-interp.c                        |  42 ++++++--
 gdb/testsuite/gdb.threads/adjacent-bp.c   |  48 ++++++++++
 gdb/testsuite/gdb.threads/adjacent-bp.exp |  86 +++++++++++++++++
 gdb/thread.c                              |  27 ++++--
 9 files changed, 269 insertions(+), 91 deletions(-)
 create mode 100644 gdb/testsuite/gdb.threads/adjacent-bp.c
 create mode 100644 gdb/testsuite/gdb.threads/adjacent-bp.exp

-- 
2.53.0

________________________________________
Intel Deutschland GmbH 

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany 

Tel: +49 (89) 99143-0 

www.intel.de 

Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman

Chairperson of the Supervisory Board: Sonja Pierer

Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


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

end of thread, other threads:[~2026-10-01 10:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-01 10:28 [RFC PATCH 0/8] breakpoint handling Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 1/8] gdb, infrun: do not discard a step-completed pending waitstatus Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 2/8] gdb, infrun: track last waitstatus per thread Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 3/8] gdb, infrun: simplify print_stop_location() Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 4/8] gdb, thread: simplify print_selected_thread_frame() Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 5/8] gdb, interp: repeat stop event when switching threads Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 6/8] gdb, infrun: handle stop event when selecting a thread Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 7/8] gdb, infrun: inline init_thread_stepping_state() Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 8/8] gdb, infrun: only step over breakpoints that were hit Markus Metzger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox