From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id 76756383414E for ; Mon, 13 Nov 2023 15:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76756383414E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 76756383414E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887943; cv=none; b=SWfVFxgh8kF98jj15miDc2kDzkZB6f7atgkK+svk2UKiXuHa5nNw/njbSiCoAN4XlYlY1MCmnnFpos5DGaB/DlX5S1FLhN5ScQTsCIH5eiFCEK4mKMv/UZ+jKirsdgSvt5kUUKkmTepHkpp5ME9YDRuxHL8/rCynTcd08tvCozE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887943; c=relaxed/simple; bh=LTH1v931xzMGxRT5QVvwUDU/DTgLycDDb+UEHgaybes=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=F7wh1fLANlrOc4f3W3IZtN4ig3vimUmLhQTBHWbvAkBMJXHjsVsLKeWJBeDjr1/oqOqhnv1jcsazWm+gPiRm43Iin7m7ALcJwGRpByVEAi66E3apjgwxVLWA1/9fJogpXOqBBqej8RzYl/02Uw3ATESpmG8snrsnZjTy3my/JAI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-32da7ac5c4fso2864464f8f.1 for ; Mon, 13 Nov 2023 07:05:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887940; x=1700492740; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UlHnTmoVuAUxG8AFrjtY7SOjfbdiZo0szfxJnswjwc0=; b=JHltet14q2j6n6xhdmHywNl/g2rwojjLyk4m0cZF8gpFJ3VNycW9sgSm6ssIyubgSs Rc/xLjttdFFKSdcCi6JC7MYgOhqgT4/iGyoHMJ6pdoIcAYd1sBoEfCmzm3Ev/gfKDdcN 3XFXPbRmmH0+sctt9Nri/RtWSwXFAOLU4J3yya7rVH0CvD2nHAGXB5CWDxm4O8UPM9na ZiXoLJIrmRkfZ828jgXLweVgKZjR3d4+4ut7z/SA2tzMFTtOhJmYdbRRKXkLAO23+ygy cxD5VcIJwAick4HatPbkrN4OkC6IIv87LqH4YQyhbZt6aPe3oibbRe55cOTMQGdj/Lfa wniA== X-Gm-Message-State: AOJu0Yy44XDhTJA2tlpaX2O5ddrLuEpKgmzVUFEWUtEYXZRKSrCUJqg9 dz8M2uMZ53olaPcFrF8QmvZpZADl36s= X-Google-Smtp-Source: AGHT+IE6mtkvKnvcHyQGyQDcuElaZ4HqMyt7cAe4c7i9jEljQc9UXAObseLzyq3GSys/RB3CoNwjkA== X-Received: by 2002:adf:b31c:0:b0:32f:a5b1:47e8 with SMTP id j28-20020adfb31c000000b0032fa5b147e8mr3313044wrd.27.1699887939967; Mon, 13 Nov 2023 07:05:39 -0800 (PST) Received: from localhost ([2001:8a0:f91e:1a00:8060:1e54:fb28:9635]) by smtp.gmail.com with UTF8SMTPSA id n16-20020a5d67d0000000b0032da49e18fasm5581212wrw.23.2023.11.13.07.05.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:05:39 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [FYI/pushed v4 16/25] Implement GDB_THREAD_OPTION_EXIT support for native Linux Date: Mon, 13 Nov 2023 15:04:18 +0000 Message-Id: <20231113150427.477431-17-pedro@palves.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231113150427.477431-1-pedro@palves.net> References: <20231113150427.477431-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.0 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,T_SCC_BODY_TEXT_LINE 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. Reviewed-By: Andrew Burgess 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 1e224e03ecb..8951b34e192 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -268,6 +268,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 = linux_target->find_thread (lp->ptid); + gdb_assert (thr != nullptr); + + return (report_thread_events + || (thr->thread_options () & GDB_THREAD_OPTION_EXIT) != 0); +} + /* LWP accessors. */ @@ -2148,8 +2160,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 ()); @@ -2932,7 +2943,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 ()); @@ -3142,10 +3153,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, @@ -3153,9 +3165,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 @@ -3388,10 +3408,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 @@ -4513,7 +4530,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.34.1