[gdb/threads] Fix lin_thread_get_thread_signals for glibc 2.28
authorTom de Vries <tdevries@suse.de>
Fri, 12 Feb 2021 19:12:37 +0000 (20:12 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 12 Feb 2021 19:12:37 +0000 (20:12 +0100)
When running test-case gdb.threads/create-fail.exp on openSUSE Factory
(with glibc version 2.32) I run into:
...
(gdb) continue
Continuing.
[New Thread 0x7ffff7c83700 (LWP 626354)]
[New Thread 0x7ffff7482700 (LWP 626355)]
[Thread 0x7ffff7c83700 (LWP 626354) exited]
[New Thread 0x7ffff6c81700 (LWP 626356)]
[Thread 0x7ffff7482700 (LWP 626355) exited]
[New Thread 0x7ffff6480700 (LWP 626357)]
[Thread 0x7ffff6c81700 (LWP 626356) exited]
[New Thread 0x7ffff5c7f700 (LWP 626358)]
[Thread 0x7ffff6480700 (LWP 626357) exited]
pthread_create: 22: Invalid argument

Thread 6 "create-fail" received signal SIG32, Real-time event 32.
[Switching to Thread 0x7ffff5c7f700 (LWP 626358)]
0x00007ffff7d87695 in clone () from /lib64/libc.so.6
(gdb) FAIL: gdb.threads/create-fail.exp: iteration 1: run till end
...
The problem is that glibc-internal signal SIGCANCEL is not recognized by gdb.

There's code in check_thread_signals that is supposed to take care of that,
but it's not working because this code in lin_thread_get_thread_signals has
stopped working:
...
  /* NPTL reserves the first two RT signals, but does not provide any
     way for the debugger to query the signal numbers - fortunately
     they don't change.  */
  sigaddset (set, __SIGRTMIN);
  sigaddset (set, __SIGRTMIN + 1);
...

Since glibc commit d2dc5467c6 "Filter out NPTL internal signals (BZ #22391)"
(first released as part of glibc 2.28), a sigaddset with a glibc-internal
signal has no other effect than setting errno to EINVALID.

Fix this by eliminating the usage of sigset_t in check_thread_signals and
lin_thread_get_thread_signals.

The same problem was observed on Ubuntu 20.04.

Tested on x86_64-linux, openSUSE Factory.
Tested on aarch64-linux, Ubuntu 20.04 and Ubuntu 18.04.

gdb/ChangeLog:

2021-02-12  Tom de Vries  <tdevries@suse.de>

PR threads/26228
* linux-nat.c (lin_thread_get_thread_signals): Remove.
(lin_thread_signals): New static var.
(lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
New function.
* linux-nat.h (lin_thread_get_thread_signals): Remove.
(lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
Declare.
* linux-thread-db.c (check_thread_signals): Use
lin_thread_get_thread_signal_num and lin_thread_get_thread_signal.

gdb/ChangeLog
gdb/linux-nat.c
gdb/linux-nat.h
gdb/linux-thread-db.c

index c71d779ced88b0c4d6c14f69f4fbc75679d955a3..e79b9535f707833e97f5dc537f568743e6f156f9 100644 (file)
@@ -1,3 +1,16 @@
+2021-02-12  Tom de Vries  <tdevries@suse.de>
+
+       PR threads/26228
+       * linux-nat.c (lin_thread_get_thread_signals): Remove.
+       (lin_thread_signals): New static var.
+       (lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
+       New function.
+       * linux-nat.h (lin_thread_get_thread_signals): Remove.
+       (lin_thread_get_thread_signal_num, lin_thread_get_thread_signal):
+       Declare.
+       * linux-thread-db.c (check_thread_signals): Use
+       lin_thread_get_thread_signal_num and lin_thread_get_thread_signal.
+
 2021-02-12  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * f-exp.y (f77_keywords): Add allocated.
index 10419dc7bb58b5bb589bee59f7d5e37f0b11f047..42dcd77ac450e43f7de2c1e55045089f2942693c 100644 (file)
@@ -4411,16 +4411,24 @@ Enables printf debugging output."),
    the GNU/Linux Threads library and therefore doesn't really belong
    here.  */
 
-/* Return the set of signals used by the threads library in *SET.  */
+/* NPTL reserves the first two RT signals, but does not provide any
+   way for the debugger to query the signal numbers - fortunately
+   they don't change.  */
+static int lin_thread_signals[] = { __SIGRTMIN, __SIGRTMIN + 1 };
 
-void
-lin_thread_get_thread_signals (sigset_t *set)
+/* See linux-nat.h.  */
+
+unsigned int
+lin_thread_get_thread_signal_num (void)
 {
-  sigemptyset (set);
+  return sizeof (lin_thread_signals) / sizeof (lin_thread_signals[0]);
+}
 
-  /* NPTL reserves the first two RT signals, but does not provide any
-     way for the debugger to query the signal numbers - fortunately
-     they don't change.  */
-  sigaddset (set, __SIGRTMIN);
-  sigaddset (set, __SIGRTMIN + 1);
+/* See linux-nat.h.  */
+
+int
+lin_thread_get_thread_signal (unsigned int i)
+{
+  gdb_assert (i < lin_thread_get_thread_signal_num ());
+  return lin_thread_signals[i];
 }
index a5547f282ad411cde943902c3c4798edb0c38a09..ff4d753422dffd246b2828fa8b9bbf058ecf440a 100644 (file)
@@ -304,8 +304,11 @@ void check_for_thread_db (void);
    true on success, false if the process isn't using libpthread.  */
 extern int thread_db_notice_clone (ptid_t parent, ptid_t child);
 
-/* Return the set of signals used by the threads library.  */
-extern void lin_thread_get_thread_signals (sigset_t *mask);
+/* Return the number of signals used by the threads library.  */
+extern unsigned int lin_thread_get_thread_signal_num (void);
+
+/* Return the i-th signal used by the threads library.  */
+extern int lin_thread_get_thread_signal (unsigned int i);
 
 /* Find process PID's pending signal set from /proc/pid/status.  */
 void linux_proc_pending_signals (int pid, sigset_t *pending,
index dce4bd23c1b7df199ee951e4d4861b4481f42a85..4dab64ac34483c82d35f01ac8855c10a8867c40d 100644 (file)
@@ -161,8 +161,6 @@ static thread_db_target the_thread_db_target;
 /* Non-zero if we have determined the signals used by the threads
    library.  */
 static int thread_signals;
-static sigset_t thread_stop_set;
-static sigset_t thread_print_set;
 
 struct thread_db_info
 {
@@ -1225,23 +1223,14 @@ check_thread_signals (void)
 {
   if (!thread_signals)
     {
-      sigset_t mask;
       int i;
 
-      lin_thread_get_thread_signals (&mask);
-      sigemptyset (&thread_stop_set);
-      sigemptyset (&thread_print_set);
-
-      for (i = 1; i < NSIG; i++)
+      for (i = 0; i < lin_thread_get_thread_signal_num (); i++)
        {
-         if (sigismember (&mask, i))
-           {
-             if (signal_stop_update (gdb_signal_from_host (i), 0))
-               sigaddset (&thread_stop_set, i);
-             if (signal_print_update (gdb_signal_from_host (i), 0))
-               sigaddset (&thread_print_set, i);
-             thread_signals = 1;
-           }
+         int sig = lin_thread_get_thread_signal (i);
+         signal_stop_update (gdb_signal_from_host (sig), 0);
+         signal_print_update (gdb_signal_from_host (sig), 0);
+         thread_signals = 1;
        }
     }
 }
This page took 0.031319 seconds and 4 git commands to generate.