From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ztkDFvcxHWDzHQAAWB0awg (envelope-from ) for ; Fri, 05 Feb 2021 06:54:31 -0500 Received: by simark.ca (Postfix, from userid 112) id 4B9D91EFCB; Fri, 5 Feb 2021 06:54:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E31F61E590 for ; Fri, 5 Feb 2021 06:54:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D33339F0828; Fri, 5 Feb 2021 11:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D33339F0828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612526070; bh=+y5m72JpTEvMMIxxwASfxwF0TXeGSolPzPo0ukIl2M4=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uI10GmspgRP5tKh4EfkifpsDDdC9GPI+UlwCPJ0w82yqMw46lBqVCg8kiPNzlCGZH MPGihcJ4reGT9I5xpoOFgJYxhqTOdUaHbUq149Mhf/2RnPdQYF4S24OJHNzzj9IiwJ QavdE9SGvbQRIyoIG9tfoeenbrP8SOrA3pDX5JIE= Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id 186343857C7E for ; Fri, 5 Feb 2021 11:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 186343857C7E Received: by mail-qv1-xf2f.google.com with SMTP id ew18so3270391qvb.4 for ; Fri, 05 Feb 2021 03:54:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+y5m72JpTEvMMIxxwASfxwF0TXeGSolPzPo0ukIl2M4=; b=CipycYKMaNcjlx0GjL/nTwlfqK5dGK8ivCAsAqJld66UgQjpHUugynIUfOoMLvc7Iy Dl1K2bz0C18vYOjqcXlZOP9rFRN2UpDLjuXIDKnMBb4VuJlphdfE3YRAgeaJqlFlZ6LL zKSlwbar2PtbNakxrSEsTofOSuW2QXUeHMdefexmEPAMXRVRwa9tmEl+p0zsq7jLKgAE GqCP2S1qxOdSwOI2zGIFPxl3FQMwWzRadS7B6QFpc9TxOVOgchTeCheQM+3PEfFCRPa6 OanjrGOVIDsXuWjrRGq72aSTbT7Ta8iSdA2FRm4p/q8fxDl40G/OfKH0taOqULnbLAti ck0Q== X-Gm-Message-State: AOAM531s1RDjUt1NX/tTVQIOm4/OazmM4Zv1V6HudTI1E/QAIxWyWkEH sNCITIsyYpwCEr3CQmJe80TDOpyqmGE7Xg== X-Google-Smtp-Source: ABdhPJzBq4mOiDN2u3m8Xtc09/y711H4o2SOX0dz8m4OolZekPU27agD9z0N3yFXEI4W8LC7iW/qLw== X-Received: by 2002:a0c:ec83:: with SMTP id u3mr3931651qvo.55.1612526066636; Fri, 05 Feb 2021 03:54:26 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:848d:48d0:224b:b76:8a76? ([2804:7f0:8284:848d:48d0:224b:b76:8a76]) by smtp.gmail.com with ESMTPSA id u7sm7185292qta.75.2021.02.05.03.54.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Feb 2021 03:54:25 -0800 (PST) Subject: Re: [PATCH][gdb/threads] Fix lin_thread_get_thread_signals for glibc 2.28 To: Tom de Vries , gdb-patches@sourceware.org References: <20210205111502.GA1510@delia> Message-ID: Date: Fri, 5 Feb 2021 08:54:23 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210205111502.GA1510@delia> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2/5/21 8:15 AM, Tom de Vries wrote: > Hi, > > When running test-case gdb.threads/create-fail.exp on openSUSE Factory > (with glibc version 2.32) I run into: I'd mention Ubuntu 20.04 as well. > ... > (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. > > Tested on x86_64-linux. Also validated on aarch64-linux/Ubuntu 20.04 and Ubuntu 18.04. > > Any comments? > > Thanks, > - Tom > > [gdb/threads] Fix lin_thread_get_thread_signals for glibc 2.28 > > gdb/ChangeLog: > > 2021-02-05 Tom de Vries > > 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/linux-nat.c | 26 +++++++++++++++++--------- > gdb/linux-nat.h | 7 +++++-- > gdb/linux-thread-db.c | 21 +++++---------------- > 3 files changed, 27 insertions(+), 27 deletions(-) > > diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c > index 10419dc7bb5..42dcd77ac45 100644 > --- a/gdb/linux-nat.c > +++ b/gdb/linux-nat.c > @@ -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]; > } > diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h > index a5547f282ad..ff4d753422d 100644 > --- a/gdb/linux-nat.h > +++ b/gdb/linux-nat.h > @@ -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, > diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c > index dce4bd23c1b..4dab64ac344 100644 > --- a/gdb/linux-thread-db.c > +++ b/gdb/linux-thread-db.c > @@ -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; > } > } > } >