From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by sourceware.org (Postfix) with ESMTPS id D6A85384E7BB for ; Mon, 12 Dec 2022 20:31:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D6A85384E7BB 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-f46.google.com with SMTP id v7so6631995wmn.0 for ; Mon, 12 Dec 2022 12:31:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f850+jcG0jBotTK630SzAa3vVKTdOVXCwT8W9gIVHzM=; b=YudtmHGItWl1ul7PurHmkQsvveNMuiFypErljH5/mnzC9benKjZ/HwJ2qVrXpcZXsj GoESyRGfGoNiiaPfveeOEzMozyUFCAJV+9w0AvegByOhJkEXNjoVxrs4WZUG1TKVvIyq hOcKXfA6/MrL2ZgJeoeFD0Om1c19Yo/Vtx8E/32ADJ4eakHsz5iDHfJYSdy4q2PWJZDS RZG7F9p02lqTtWwbiVwTQqru2ZkNMo4OZHo6gYpD60o8eejK4LfLITvuZYPToo7Pea+I O+7YlI41Cdgy5+KV9Vz/T4JEykK8ftjhH5xM64wGlrxGytVKjVJ1I/Fc8bbwLdJTGybD Af6g== X-Gm-Message-State: ANoB5pnCemJYetFiJAfs9o3jQsUyj+Cplq8CYM7kVKo75wAzdqJMRjBJ wVRTd5ywvcx6A0vg++lNHBtb7SxVpKx4nw== X-Google-Smtp-Source: AA0mqf71LlPnGcm93G1dmvtmUUEuUjYatx/1RxPmlxEVac3omhQ+d/xoRdvDJMTwlbRDzpEzYmeCLQ== X-Received: by 2002:a05:600c:4f45:b0:3cf:615e:480e with SMTP id m5-20020a05600c4f4500b003cf615e480emr17010703wmq.12.1670877084210; Mon, 12 Dec 2022 12:31:24 -0800 (PST) Received: from localhost ([2001:8a0:f912:6700:afd9:8b6d:223f:6170]) by smtp.gmail.com with ESMTPSA id iz2-20020a05600c554200b003cf78aafdd7sm10446466wmb.39.2022.12.12.12.31.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Dec 2022 12:31:23 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 19/31] Implement GDB_THREAD_OPTION_EXIT support for native Linux Date: Mon, 12 Dec 2022 20:30:49 +0000 Message-Id: <20221212203101.1034916-20-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20221212203101.1034916-1-pedro@palves.net> References: <20221212203101.1034916-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,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: This implements support for the new GDB_THREAD_OPTION_EXIT thread option for native Linux. Change-Id: Ia69fc0b9b96f9af7de7cefc1ddb1fba9bbb0bb90 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338 --- gdb/linux-nat.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index b576ce60b75..75f81edf20a 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -269,6 +269,18 @@ pending_status_str (lwp_info *lp) return status_to_str (lp->status); } +/* Return true if we should report exit events for LP. */ + +static bool +report_exit_events_for (lwp_info *lp) +{ + thread_info *thr = find_thread_ptid (linux_target, lp->ptid); + gdb_assert (thr != nullptr); + + return (report_thread_events + || (thr->thread_options () & GDB_THREAD_OPTION_EXIT) != 0); +} + /* LWP accessors. */ @@ -2131,8 +2143,7 @@ wait_lwp (struct lwp_info *lp) /* Check if the thread has exited. */ if (WIFEXITED (status) || WIFSIGNALED (status)) { - if (report_thread_events - || lp->ptid.pid () == lp->ptid.lwp ()) + if (report_exit_events_for (lp) || is_leader (lp)) { linux_nat_debug_printf ("LWP %d exited.", lp->ptid.pid ()); @@ -2913,7 +2924,7 @@ linux_nat_filter_event (int lwpid, int status) /* Check if the thread has exited. */ if (WIFEXITED (status) || WIFSIGNALED (status)) { - if (!report_thread_events && !is_leader (lp)) + if (!report_exit_events_for (lp) && !is_leader (lp)) { linux_nat_debug_printf ("%s exited.", lp->ptid.to_string ().c_str ()); @@ -3123,10 +3134,11 @@ check_zombie_leaders (void) } } -/* Convenience function that is called when the kernel reports an exit - event. This decides whether to report the event to GDB as a - process exit event, a thread exit event, or to suppress the - event. */ +/* Convenience function that is called when we're about to return an + event to the core. If the event is an exit or signalled event, + then this decides whether to report it as process-wide event, as a + thread exit event, or to suppress it. All other event kinds are + passed through unmodified. */ static ptid_t filter_exit_event (struct lwp_info *event_child, @@ -3134,9 +3146,17 @@ filter_exit_event (struct lwp_info *event_child, { ptid_t ptid = event_child->ptid; + /* Note we must filter TARGET_WAITKIND_SIGNALLED as well, otherwise + if a non-leader thread exits with a signal, we'd report it to the + core which would interpret it as the whole-process exiting. + There is no TARGET_WAITKIND_THREAD_SIGNALLED event kind. */ + if (ourstatus->kind () != TARGET_WAITKIND_EXITED + && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) + return ptid; + if (!is_leader (event_child)) { - if (report_thread_events) + if (report_exit_events_for (event_child)) { ourstatus->set_thread_exited (0); /* Delete lwp, but not thread_info, infrun will need it to @@ -3369,10 +3389,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus, else lp->core = linux_common_core_of_thread (lp->ptid); - if (ourstatus->kind () == TARGET_WAITKIND_EXITED) - return filter_exit_event (lp, ourstatus); - - return lp->ptid; + return filter_exit_event (lp, ourstatus); } /* Resume LWPs that are currently stopped without any pending status @@ -4479,7 +4496,8 @@ linux_nat_target::thread_events (int enable) bool linux_nat_target::supports_set_thread_options (gdb_thread_options options) { - constexpr gdb_thread_options supported_options = GDB_THREAD_OPTION_CLONE; + constexpr gdb_thread_options supported_options + = GDB_THREAD_OPTION_CLONE | GDB_THREAD_OPTION_EXIT; return ((options & supported_options) == options); } -- 2.36.0