From 9d7d58e7262eff313be6a1e66b8b026e3e7fed0d Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 12 Dec 2022 20:31:00 +0000 Subject: gdb: centralize "[Thread ...exited]" notifications Currently, each target backend is responsible for printing "[Thread ...exited]" before deleting a thread. This leads to unnecessary differences between targets, like e.g. with the remote target, we never print such messages, even though we do print "[New Thread ...]". E.g., debugging the gdb.threads/attach-many-short-lived-threads.exp with gdbserver, letting it run for a bit, and then pressing Ctrl-C, we currently see: (gdb) c Continuing. ^C[New Thread 3850398.3887449] [New Thread 3850398.3887500] [New Thread 3850398.3887551] [New Thread 3850398.3887602] [New Thread 3850398.3887653] ... Thread 1 "attach-many-sho" received signal SIGINT, Interrupt. 0x00007ffff7e6a23f in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7fffffffda80, rem=rem@entry=0x7fffffffda80) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 78 in ../sysdeps/unix/sysv/linux/clock_nanosleep.c (gdb) Above, we only see "New Thread" notifications, even though threads were deleted. After this patch, we'll see: (gdb) c Continuing. ^C[Thread 3558643.3577053 exited] [Thread 3558643.3577104 exited] [Thread 3558643.3577155 exited] [Thread 3558643.3579603 exited] ... [New Thread 3558643.3597415] [New Thread 3558643.3600015] [New Thread 3558643.3599965] ... Thread 1 "attach-many-sho" received signal SIGINT, Interrupt. 0x00007ffff7e6a23f in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7fffffffda80, rem=rem@entry=0x7fffffffda80) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 78 in ../sysdeps/unix/sysv/linux/clock_nanosleep.c (gdb) q This commit fixes this by moving the thread exit printing to common code instead, triggered from within delete_thread (or rather, set_thread_exited). There's one wrinkle, though. While most targest want to print: [Thread ... exited] the Windows target wants to print: [Thread ... exited with code ] ... and sometimes wants to suppress the notification for the main thread. To address that, this commits adds a delete_thread_with_code function, only used by that target (so far). This fix was originally posted as part of a larger series: https://inbox.sourceware.org/gdb-patches/20221212203101.1034916-1-pedro@palves.net/ But didn't really need to be part of that series. In order to get this fix merged sooner, I (Andrew Burgess) have rebased this commit outside of the original series. Any bugs introduced while splitting this patch out and rebasing, are entirely my own. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30129 Co-Authored-By: Andrew Burgess --- gdb/interps.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gdb/interps.h') diff --git a/gdb/interps.h b/gdb/interps.h index 3a0e837..c041d0d 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -122,7 +122,9 @@ public: virtual void on_new_thread (thread_info *t) {} /* Notify the interpreter that thread T has exited. */ - virtual void on_thread_exited (thread_info *, int silent) {} + virtual void on_thread_exited (thread_info *, + gdb::optional exit_code, + int silent) {} /* Notify the interpreter that inferior INF was added. */ virtual void on_inferior_added (inferior *inf) {} @@ -297,7 +299,9 @@ extern void interps_notify_user_selected_context_changed extern void interps_notify_new_thread (thread_info *t); /* Notify all interpreters that thread T has exited. */ -extern void interps_notify_thread_exited (thread_info *t, int silent); +extern void interps_notify_thread_exited (thread_info *t, + gdb::optional exit_code, + int silent); /* Notify all interpreters that inferior INF was added. */ extern void interps_notify_inferior_added (inferior *inf); -- cgit v1.1