From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by sourceware.org (Postfix) with ESMTPS id 461DB385842A for ; Fri, 10 Mar 2023 17:15:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 461DB385842A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f50.google.com with SMTP id m25-20020a7bcb99000000b003e7842b75f2so3910219wmi.3 for ; Fri, 10 Mar 2023 09:15:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678468521; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:subject:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mR4jXHKiN+KDWakZtrWqi4oVbCut3BzYSVhtK1FgrNw=; b=seclvXzvYq+/xIQGtpNf/xXiNfHjTxlmLFCaP4CUfqJ25BlrzI4UcacRODSXpPbz3k FLAl9/Edvy4OR87C5nsHSjXNXmmmCxa3pUDbGMN+ZuNxkZUmxDm15SkTv8bCXB44MxhX AzoOmsWUWod0JnE926ea++oNqsGmcg2L/agRq9x01GPm/kawIscJCIriGWfcX0XgvxHW 9SAf2x/trb1utGM/JG4wK2bTiERV1/8+JZj2b+en+gXLDwjJTXgiXWpqGuiVjE4v/1zk 4iom6q7ECEmAcE7/jg998qUMBoKXsNeWsB+z1+QQwXsgJwtKqIiKC4fRfBkpZMYqMgV2 SAWA== X-Gm-Message-State: AO0yUKXwIKrxaUtS3htFwcyv8ZPqGokEyjkbyW29O2ZDddVfdkjyC7gQ 9mOCTOK2L9jYs9n86V6jFuUuv3wX3OA= X-Google-Smtp-Source: AK7set8phpdPRqwsPMYUJsdgmVjHPV7ehrunlOZ8I4T38PN+1UY+ZUkFfTw2ZsiQPTdIPkXeia/YzA== X-Received: by 2002:a05:600c:540a:b0:3ea:e582:48dd with SMTP id he10-20020a05600c540a00b003eae58248ddmr3510607wmb.34.1678468521039; Fri, 10 Mar 2023 09:15:21 -0800 (PST) Received: from ?IPv6:2001:8a0:f93c:5900::1fe? ([2001:8a0:f93c:5900::1fe]) by smtp.gmail.com with ESMTPSA id o13-20020a05600c510d00b003e20970175dsm519005wms.32.2023.03.10.09.15.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Mar 2023 09:15:20 -0800 (PST) From: Pedro Alves Subject: Re: [PATCH 02/31] linux-nat: introduce pending_status_str To: Andrew Burgess , gdb-patches@sourceware.org References: <20221212203101.1034916-1-pedro@palves.net> <20221212203101.1034916-3-pedro@palves.net> <87cz6rrma6.fsf@redhat.com> Message-ID: Date: Fri, 10 Mar 2023 17:15:18 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <87cz6rrma6.fsf@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-02-03 12:00 p.m., Andrew Burgess wrote: > Pedro Alves writes: > >> I noticed that some debug log output printing an lwp's pending status >> wasn't considering lp->waitstatus. This fixes it, by introducing a >> new pending_status_str function. > > This patch looks fine. I had one slightly related question: I took a > look at the comment on lwp_info::waitstatus in linux-nat.h, which says: > > /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus > for this LWP's last event. This may correspond to STATUS above, > or to a local variable in lin_lwp_wait. */ > struct target_waitstatus waitstatus; > > Am I right in thinking that this comment is wrong; it should say > TARGET_WAITKIND_IGNORE, not TARGET_WAITKIND_SPURIOUS, right? You're right. I tweaked the comments in linux-nat.h in this new version. Let me know what you think. >From 10f88baff2e25fb87f37d1665bf283206171dd42 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 12 Nov 2021 20:50:29 +0000 Subject: [PATCH] linux-nat: introduce pending_status_str I noticed that some debug log output printing an lwp's pending status wasn't considering lp->waitstatus. This fixes it, by introducing a new pending_status_str function. Also fix the comment in gdb/linux-nat.h describing lwp_info::waitstatus and details the description of lwp_info::status while at it. Change-Id: I66e5c7a363d30a925b093b195d72925ce5b6b980 --- gdb/linux-nat.c | 19 ++++++++++++++++--- gdb/linux-nat.h | 11 +++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index e5391b9ce35..9d811bbf3ff 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -255,6 +255,19 @@ is_leader (lwp_info *lp) return lp->ptid.pid () == lp->ptid.lwp (); } +/* Convert an LWP's pending status to a std::string. */ + +static std::string +pending_status_str (lwp_info *lp) +{ + gdb_assert (lwp_status_pending_p (lp)); + + if (lp->waitstatus.kind () != TARGET_WAITKIND_IGNORE) + return lp->waitstatus.to_string (); + else + return status_to_str (lp->status); +} + /* LWP accessors. */ @@ -1647,8 +1660,8 @@ linux_nat_target::resume (ptid_t scope_ptid, int step, enum gdb_signal signo) this thread with a signal? */ gdb_assert (signo == GDB_SIGNAL_0); - linux_nat_debug_printf ("Short circuiting for status 0x%x", - lp->status); + linux_nat_debug_printf ("Short circuiting for status %s", + pending_status_str (lp).c_str ()); if (target_can_async_p ()) { @@ -3137,7 +3150,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus, if (lp != NULL) { linux_nat_debug_printf ("Using pending wait status %s for %s.", - status_to_str (lp->status).c_str (), + pending_status_str (lp).c_str (), lp->ptid.to_string ().c_str ()); } diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 45534c92386..770fe924427 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -232,7 +232,9 @@ struct lwp_info : intrusive_list_node /* The last resume GDB requested on this thread. */ resume_kind last_resume_kind = resume_continue; - /* If non-zero, a pending wait status. */ + /* If non-zero, a pending wait status. A pending process exit is + recorded in WAITSTATUS, because W_EXITCODE(0,0) happens to be + 0. */ int status = 0; /* When 'stopped' is set, this is where the lwp last stopped, with @@ -260,9 +262,10 @@ struct lwp_info : intrusive_list_node /* Non-zero if we expect a duplicated SIGINT. */ int ignore_sigint = 0; - /* If WAITSTATUS->KIND != TARGET_WAITKIND_SPURIOUS, the waitstatus - for this LWP's last event. This may correspond to STATUS above, - or to a local variable in lin_lwp_wait. */ + /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for + this LWP's last event. This usually corresponds to STATUS above, + however because W_EXITCODE(0,0) happens to be 0, a process exit + will be recorded here, while 'status == 0' is ambiguous. */ struct target_waitstatus waitstatus; /* Signal whether we are in a SYSCALL_ENTRY or base-commit: 2562954ede66f32bff7d985e752b8052c2ae5775 prerequisite-patch-id: bbc9918ac5f79de07a29f34ec072794d270f942d -- 2.36.0