From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by sourceware.org (Postfix) with ESMTPS id 2ED3C386F41B for ; Mon, 20 Jun 2022 22:54:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2ED3C386F41B 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-wr1-f48.google.com with SMTP id g4so16475044wrh.11 for ; Mon, 20 Jun 2022 15:54:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rl5lw3PeofPZ6/fbF6JuNAHGUIkkIh8vCrQrlSj7snk=; b=vnVpB0HjCd95Le8Hn7LrhyPsdNXiMMDBlqBnwW9f6aHA3Vqtbe18O5M9Dg1h7iR6R2 DQtlCPUbQgdNRsGCIFlH0yo2J1niIJ9GVNrjdXYEXgZwl8KzNu7RX+NJw/bcbnLiqygY /DpLzxDp0oYlgApFupO3JwXgDyJPDfsEt2JTZgUxV8uqreiacJqiIXqN05AjNztO50S9 cRkyYIfz6VA6V5r7rKIlZTHcCGhQ7lfng6KW1ESRf1tvvx3z0MnM68reUAcCywzDsm6L ggF7y/FoDePNeQkJHDvpmwol1gyQsQzA/YEhh1E6zkY417V5J/0cBKBzZh3ZEDGNK+Yf 3SUA== X-Gm-Message-State: AJIora8h3BBxLYn9nE0NY4ltJ7nAg4FOMNVO/7DKt7TGNd5JJVD6rRK8 uU71xQOUjEJQTtr0BSL6pw56LuxkZII= X-Google-Smtp-Source: AGRyM1vJs7z49t4ZaXtWH3JC1AKSmUcO1etbAFkl/rEMQqtq8rIUUfO8XVcwIlHfgDmci0JLH64CNw== X-Received: by 2002:a05:6000:104f:b0:21a:3d3a:4d3d with SMTP id c15-20020a056000104f00b0021a3d3a4d3dmr20171137wrx.528.1655765693209; Mon, 20 Jun 2022 15:54:53 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id c9-20020a056000104900b002185631adf0sm6946171wrx.23.2022.06.20.15.54.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jun 2022 15:54:52 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 14/25] Implement GDB_TO_EXIT support for Linux GDBserver Date: Mon, 20 Jun 2022 23:54:08 +0100 Message-Id: <20220620225419.382221-15-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220620225419.382221-1-pedro@palves.net> References: <20220620225419.382221-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 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 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: , X-List-Received-Date: Mon, 20 Jun 2022 22:54:56 -0000 This implements support for the new GDB_TO_EXIT thread option for Linux GDBserver. Change-Id: I96b719fdf7fee94709e98bb3a90751d8134f3a38 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27338 --- gdbserver/linux-low.cc | 38 +++++++++++++++++++++++++------------- gdbserver/linux-low.h | 9 +++++---- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 8bfcd5bf740..8154d8088c1 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -144,6 +144,18 @@ is_leader (thread_info *thread) return ptid.pid () == ptid.lwp (); } +/* Return true if we should report thread exit events to GDB, for + THR. */ + +static bool +report_exit_events_for (thread_info *thr) +{ + client_state &cs = get_client_state (); + + return (cs.report_thread_events + || (thr->thread_options & GDB_TO_EXIT) != 0); +} + /* LWP accessors. */ /* See nat/linux-nat.h. */ @@ -2226,7 +2238,6 @@ linux_low_ptrace_options (int attached) void linux_process_target::filter_event (int lwpid, int wstat) { - client_state &cs = get_client_state (); struct lwp_info *child; struct thread_info *thread; int have_stop_pc = 0; @@ -2313,7 +2324,7 @@ linux_process_target::filter_event (int lwpid, int wstat) /* If this is not the leader LWP, then the exit signal was not the end of the debugged application and should be ignored, unless GDB wants to hear about thread exits. */ - if (cs.report_thread_events || is_leader (thread)) + if (report_exit_events_for (thread) || is_leader (thread)) { /* Since events are serialized to GDB core, and we can't report this one right now. Leave the status pending for @@ -2876,13 +2887,20 @@ ptid_t linux_process_target::filter_exit_event (lwp_info *event_child, target_waitstatus *ourstatus) { - client_state &cs = get_client_state (); struct thread_info *thread = get_lwp_thread (event_child); ptid_t ptid = ptid_of (thread); + /* 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 (thread)) { - if (cs.report_thread_events) + if (report_exit_events_for (thread)) ourstatus->set_thread_exited (0); else ourstatus->set_ignore (); @@ -3025,10 +3043,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, WTERMSIG (w)); } - if (ourstatus->kind () == TARGET_WAITKIND_EXITED) - return filter_exit_event (event_child, ourstatus); - - return ptid_of (current_thread); + return filter_exit_event (event_child, ourstatus); } /* If step-over executes a breakpoint instruction, in the case of a @@ -3597,10 +3612,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus, target_pid_to_str (ptid_of (current_thread)).c_str (), ourstatus->to_string ().c_str ()); - if (ourstatus->kind () == TARGET_WAITKIND_EXITED) - return filter_exit_event (event_child, ourstatus); - - return ptid_of (current_thread); + return filter_exit_event (event_child, ourstatus); } /* Get rid of any pending event in the pipe. */ @@ -5911,7 +5923,7 @@ bool linux_process_target::supports_set_thread_options (gdb_thread_options *supported_options) { - *supported_options = GDB_TO_CLONE; + *supported_options = GDB_TO_CLONE | GDB_TO_EXIT; return true; } diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index e7237bba3b3..051a7196ef7 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -573,10 +573,11 @@ class linux_process_target : public process_stratum_target exited. */ void check_zombie_leaders (); - /* 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. */ ptid_t filter_exit_event (lwp_info *event_child, target_waitstatus *ourstatus); -- 2.36.0