[FYI/pushed,v4,00/25] Step over thread clone and thread exit

Message ID 20231113150427.477431-1-pedro@palves.net
Headers
Series Step over thread clone and thread exit |

Message

Pedro Alves Nov. 13, 2023, 3:04 p.m. UTC
  Here's v4 of the series I previously posted here:

  [PATCH 00/31] Step over thread clone and thread exit
  https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-1-pedro@palves.net/

(That was v3, I had forgotten to update the subject line back then.)

As I mentioned earlier today, I've addressed all the review comments
in the remaining patches in the v3 series, and since none required any
invasive/design change, I've gone ahead with merging this.  If there's
anything that doesn't look right, please don't hesitate to raise it
and I'll try to address it.

New in v4:

  - Patches 1-2, 29-30 from v3 were already merged a while ago.

  - Addressed Andrew's comments throughout.

  - The stepi-over-clone.exp testcase is now merged into the patch
    where the test first works on native GNU/Linux.

  - Patch "[PATCH 25/31] Ignore failure to read PC when resuming" from
    v3 was dropped, for now.

Here's the series description, updated for v4:

This is a new series that replaces two different series from a couple
years ago.

The first is this series Simon and I wrote, here:

  [PATCH 00/10] Step over thread exit (PR gdb/27338)
  https://sourceware.org/pipermail/gdb-patches/2021-July/180567.html

The other is a series that coincidentally, back then, Andrew posted at
about the same time, and that addressed problems in kind of the mirror
scenario.  His patch series was about stepping over clone (creating
new threads), instead of stepping over thread exit:

  [PATCH 0/3] Stepping over clone syscall
  https://sourceware.org/pipermail/gdb-patches/2021-June/180517.html

My & Simon's solution back then involved adding a new contract between
GDB and GDBserver -- if a thread is single stepping, and it exits, the
server was supposed to report back the thread's exit to GDB.  One of
the motivations for this approach was to be able to control the
enablement of thread exit events per thread, to avoid creating
thread-exit event traffic unnecessarily, as done by
target_thread_events()/QThreadEvents.

Andrew's solution involves using the QThreadEvents mechanism, which
tells the server to report thread create and thread exit events for
all threads.  This would conflict with the desire to avoid unnecessary
traffic in the step over thread exit series.

The step over clone fixes back then also weren't yet fully complete,
as Andrew's series only addressed inline step overs.  Fixing displaced
stepping over clone syscall would still remain broken.

This new series fixes all of stepping over thread exit and clone, for
both of displaced stepping and inline step overs.  It:

- Merges both Andrew's and my/Simon's series, and then reworks both
  parts in different ways.

- Introduces clone events at the GDB core and remote protocol level.

- Gets rid of the idea of "reporting thread exit if thread is
  single-stepping", replaces it by a new mechanism GDB can use to
  explicitly enable thread clone and/or thread exit events, and other
  events in the future.  The old mechanism also only worked when the
  remote server supported hardware single-stepping.  This new approach
  has an advantage of also working on software single-step targets.

- Uses the new clone events to fix displaced stepping over clone
  syscalls too.

- Addresses an issue that Andrew alluded to in his series, and that
  coincidentally, we/AMD also ran into with AMDGPU debugging --
  currently, with "set scheduler-locking on", if you step over a
  function that spawns a thread, that thread runs free, for a bit at
  least, and then may stop or not, basically in an unspecified manner.

- Cancels next/step/until/etc. commands on thread exit event, like so:

     (gdb) n
     [Thread 0x7ffff7d89700 (LWP 3961883) exited]
     Command aborted, thread exited.
     (gdb)

- Non-trivial documentation changes have already been approved by Eli.

Tested on x86-64 Ubuntu 20.04, native and gdbserver.

Andrew Burgess (1):
  Add "maint info linux-lwps" command

Pedro Alves (23):
  gdb/linux: Delete all other LWPs immediately on ptrace exec event
  Step over clone syscall w/ breakpoint, TARGET_WAITKIND_THREAD_CLONED
  Support clone events in the remote protocol
  Avoid duplicate QThreadEvents packets
  Thread options & clone events (core + remote)
  Thread options & clone events (native Linux)
  Thread options & clone events (Linux GDBserver)
  gdbserver: Hide and don't detach pending clone children
  Remove gdb/19675 kfails (displaced stepping + clone)
  all-stop/synchronous RSP support thread-exit events
  gdbserver/linux-low.cc: Ignore event_ptid if TARGET_WAITKIND_IGNORE
  Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core
  Introduce GDB_THREAD_OPTION_EXIT thread option, fix
    step-over-thread-exit
  Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver
  Implement GDB_THREAD_OPTION_EXIT support for native Linux
  gdb: clear step over information on thread exit (PR gdb/27338)
  stop_all_threads: (re-)enable async before waiting for stops
  gdbserver: Queue no-resumed event after thread exit
  Don't resume new threads if scheduler-locking is in effect
  Report thread exit event for leader if reporting thread exit events
  gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro
  Document remote clone events, and QThreadOptions packet
  Cancel execution command on thread exit, when stepping, nexting, etc.

Simon Marchi (1):
  Testcases for stepping over thread exit syscall (PR gdb/27338)

 gdb/NEWS                                      |  32 +
 gdb/displaced-stepping.c                      |   7 +
 gdb/doc/gdb.texinfo                           | 136 +++-
 gdb/gdbarch-gen.h                             |   6 +-
 gdb/gdbarch_components.py                     |   4 +
 gdb/gdbthread.h                               |  16 +
 gdb/infrun.c                                  | 588 +++++++++++++++---
 gdb/linux-nat.c                               | 383 +++++++-----
 gdb/linux-nat.h                               |   4 +
 gdb/remote.c                                  | 304 +++++++--
 gdb/target-debug.h                            |   2 +
 gdb/target-delegates.c                        |  52 ++
 gdb/target.c                                  |  16 +
 gdb/target.h                                  |  15 +
 gdb/target/target.c                           |  12 +
 gdb/target/target.h                           |  20 +
 gdb/target/waitstatus.c                       |   1 +
 gdb/target/waitstatus.h                       |  31 +-
 gdb/testsuite/gdb.base/step-over-syscall.exp  |  44 +-
 .../gdb.threads/schedlock-new-thread.c        |  54 ++
 .../gdb.threads/schedlock-new-thread.exp      |  67 ++
 ...-over-thread-exit-while-stop-all-threads.c |  77 +++
 ...ver-thread-exit-while-stop-all-threads.exp |  69 ++
 .../gdb.threads/step-over-thread-exit.c       |  52 ++
 .../gdb.threads/step-over-thread-exit.exp     | 155 +++++
 gdb/testsuite/gdb.threads/stepi-over-clone.c  |  90 +++
 .../gdb.threads/stepi-over-clone.exp          | 389 ++++++++++++
 .../gdb.threads/threads-after-exec.c          |  56 ++
 .../gdb.threads/threads-after-exec.exp        |  57 ++
 gdb/testsuite/lib/my-syscalls.S               |  54 +-
 gdb/testsuite/lib/my-syscalls.h               |   5 +
 gdb/thread.c                                  |  18 +
 gdbserver/gdbthread.h                         |   3 +
 gdbserver/linux-low.cc                        | 417 ++++++++-----
 gdbserver/linux-low.h                         |  78 ++-
 gdbserver/remote-utils.cc                     |  26 +-
 gdbserver/server.cc                           | 158 ++++-
 gdbserver/target.cc                           |  15 +-
 gdbserver/target.h                            |  28 +-
 39 files changed, 2994 insertions(+), 547 deletions(-)
 create mode 100644 gdb/testsuite/gdb.threads/schedlock-new-thread.c
 create mode 100644 gdb/testsuite/gdb.threads/schedlock-new-thread.exp
 create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit-while-stop-all-threads.c
 create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit-while-stop-all-threads.exp
 create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit.c
 create mode 100644 gdb/testsuite/gdb.threads/step-over-thread-exit.exp
 create mode 100644 gdb/testsuite/gdb.threads/stepi-over-clone.c
 create mode 100644 gdb/testsuite/gdb.threads/stepi-over-clone.exp
 create mode 100644 gdb/testsuite/gdb.threads/threads-after-exec.c
 create mode 100644 gdb/testsuite/gdb.threads/threads-after-exec.exp


base-commit: 6b682bbf86f37982ce1d270fb47f363413490bda
  

Comments

Tom de Vries Nov. 13, 2023, 7:28 p.m. UTC | #1
On 11/13/23 16:04, Pedro Alves wrote:
> Here's v4 of the series I previously posted here:

I'm seeing new FAILs:
...
FAIL: gdb.threads/stepi-over-clone.exp: continue
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=off: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: 
displaced=on: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=off: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: 
non-stop=off: displaced=on: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=0: stepi (timeout)
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=0: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=1: stepi (timeout)
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=1: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=off: i=2: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=0: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=1: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=on: 
displaced=on: i=2: $bad_threads == 0
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=off: i=2: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=0: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=0: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=1: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=1: $thread_count == 2
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=2: stepi
FAIL: gdb.threads/stepi-over-clone.exp: third_thread=true: non-stop=off: 
displaced=on: i=2: $thread_count == 2
...

First in more detail:
...
(gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls
continue^M
Continuing.^M
^M
Catchpoint 2 (call to syscall clone), clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M
warning: 78     ../sysdeps/unix/sysv/linux/x86_64/clone.S: No such file 
or directory^M
(gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue
...

Thanks,
- Tom
  
Pedro Alves Nov. 14, 2023, 10:51 a.m. UTC | #2
Hi Tom,

On 2023-11-13 19:28, Tom de Vries wrote:

> I'm seeing new FAILs:
> ...
> FAIL: gdb.threads/stepi-over-clone.exp: continue
> FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: displaced=off: i=0: stepi
> FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: displaced=off: i=0: $thread_count == 2

...

> ...
> 
> First in more detail:
> ...
> (gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls
> continue^M
> Continuing.^M
> ^M
> Catchpoint 2 (call to syscall clone), clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M
> warning: 78     ../sysdeps/unix/sysv/linux/x86_64/clone.S: No such file or directory^M
> (gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue
> ...
> 

Thanks.  I think the patch below would fix this one.  The others are hopefully something similar,
but I wasn't able to spot anything wrong by inspection.  I'd have to see the relevant part of the
gdb.log to hazard a better guess.


--- 8< ---
From: Pedro Alves <pedro@palves.net>
Subject: [PATCH] Fix gdb.threads/stepi-over-clone.exp regexp

Tom de Vries reported this FAIL:

 (gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls
 continue^M
 Continuing.^M
 ^M
 Catchpoint 2 (call to syscall clone), clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M
 warning: 78     ../sysdeps/unix/sysv/linux/x86_64/clone.S: No such file or directory^M
 (gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue

All but one regexps in the .exp file use "clone\[23\]?" with "?" to
also accept "clone", except the failing case.  This commit fixes that
case to also use "?".

Change-Id: I74ca9e7d4cfe6af294fd50e8c509fcbad289b78c
---
 gdb/testsuite/gdb.threads/stepi-over-clone.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.threads/stepi-over-clone.exp b/gdb/testsuite/gdb.threads/stepi-over-clone.exp
index 4c496429632..18cfec19ffa 100644
--- a/gdb/testsuite/gdb.threads/stepi-over-clone.exp
+++ b/gdb/testsuite/gdb.threads/stepi-over-clone.exp
@@ -45,7 +45,7 @@ gdb_test_multiple "catch syscall group:process" "catch process syscalls" {
 }
 
 gdb_test "continue" \
-    "Catchpoint $decimal \\(call to syscall clone\[23\]\\), .*"
+    "Catchpoint $decimal \\(call to syscall clone\[23\]?\\), .*"
 
 # Return true if INSN is a syscall instruction.
 

base-commit: 319b460545dc79280e2904dcc280057cf71fb753
  
Tom de Vries Nov. 14, 2023, 1:39 p.m. UTC | #3
On 11/14/23 11:51, Pedro Alves wrote:
> Hi Tom,
> 
> On 2023-11-13 19:28, Tom de Vries wrote:
> 
>> I'm seeing new FAILs:
>> ...
>> FAIL: gdb.threads/stepi-over-clone.exp: continue
>> FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: displaced=off: i=0: stepi
>> FAIL: gdb.threads/stepi-over-clone.exp: third_thread=false: non-stop=on: displaced=off: i=0: $thread_count == 2
> 
> ...
> 
>> ...
>>
>> First in more detail:
>> ...
>> (gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls
>> continue^M
>> Continuing.^M
>> ^M
>> Catchpoint 2 (call to syscall clone), clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M
>> warning: 78     ../sysdeps/unix/sysv/linux/x86_64/clone.S: No such file or directory^M
>> (gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue
>> ...
>>
> 
> Thanks.  I think the patch below would fix this one.  

It does, thanks.

> The others are hopefully something similar,
> but I wasn't able to spot anything wrong by inspection.  I'd have to see the relevant part of the
> gdb.log to hazard a better guess.
> 
> 

I've managed to fix those as wel.  Posted here ( 
https://sourceware.org/pipermail/gdb-patches/2023-November/204118.html ).

[ I've submitted it as regular patch rather than attaching it here to 
make sure git-pw will pick it up. ]

Thanks,
- Tom

> --- 8< ---
> From: Pedro Alves <pedro@palves.net>
> Subject: [PATCH] Fix gdb.threads/stepi-over-clone.exp regexp
> 
> Tom de Vries reported this FAIL:
> 
>   (gdb) PASS: gdb.threads/stepi-over-clone.exp: catch process syscalls
>   continue^M
>   Continuing.^M
>   ^M
>   Catchpoint 2 (call to syscall clone), clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:78^M
>   warning: 78     ../sysdeps/unix/sysv/linux/x86_64/clone.S: No such file or directory^M
>   (gdb) FAIL: gdb.threads/stepi-over-clone.exp: continue
> 
> All but one regexps in the .exp file use "clone\[23\]?" with "?" to
> also accept "clone", except the failing case.  This commit fixes that
> case to also use "?".
> 
> Change-Id: I74ca9e7d4cfe6af294fd50e8c509fcbad289b78c
> ---
>   gdb/testsuite/gdb.threads/stepi-over-clone.exp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/gdb.threads/stepi-over-clone.exp b/gdb/testsuite/gdb.threads/stepi-over-clone.exp
> index 4c496429632..18cfec19ffa 100644
> --- a/gdb/testsuite/gdb.threads/stepi-over-clone.exp
> +++ b/gdb/testsuite/gdb.threads/stepi-over-clone.exp
> @@ -45,7 +45,7 @@ gdb_test_multiple "catch syscall group:process" "catch process syscalls" {
>   }
>   
>   gdb_test "continue" \
> -    "Catchpoint $decimal \\(call to syscall clone\[23\]\\), .*"
> +    "Catchpoint $decimal \\(call to syscall clone\[23\]?\\), .*"
>   
>   # Return true if INSN is a syscall instruction.
>   
> 
> base-commit: 319b460545dc79280e2904dcc280057cf71fb753