From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by sourceware.org (Postfix) with ESMTPS id BE96F383F1B6 for ; Mon, 13 Nov 2023 15:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE96F383F1B6 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 BE96F383F1B6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887940; cv=none; b=kkaXENcTvjQo5dRzNqgVXWpVNwGdv+xGqKZk4XgMuRllUtbMErU7rYhW/Qv1Jb0rp+6p7qdEAko48O89djOl3i6FuH7suLNhcL7U8rOH/ZkhD3TNfqvitxBznJUTC75Th6lZfqU7mYP4Al1YB1Y/0XMdZA1QdURkYViOln2BhO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699887940; c=relaxed/simple; bh=hm6THtgtPkOfMb26pgb7L0+cXjRyOVUmRvp8XjSgn4M=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=KGgo+DUUo4p57AuNxEJ8OZcS2oSzLtEfM5AzXgZKmN7GuBYSVp9Dpmi+Zw2eBEQSdD9ttAa8xGLTr0W8/UgikntKil/7UQfMrwW6kAnS972yVa8MdHXiqnjRIZjCKi8ZRlLU1zL4V7EmUt14kuRXM9vgPN98JYOzTdA0+lr45MM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-32f7bd27c2aso3105063f8f.2 for ; Mon, 13 Nov 2023 07:05:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699887937; x=1700492737; 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=CLSDX6K7daL7qPn971DC20OZTeJmjECBeISRnPSATAc=; b=gx/Koa51fALLMnw1pZd87kRzwG40FTOBI/3TC/RoiO5R/QzxeTAFDgCeRXaEXe4Skv juDXVbR6dpmPRGB9aUTXa0qGv1vmW8NIJ6tDFC7YAjo9M1xvEPZBzNOh+/cMAIkLKnHb MSZV4Af8b6cV185+bJrbRoDMooxDSYEVO2JQvMtWpHwMTZHpOljAINa7E/Tx8mQ4ryGy hsK1+hCZOAeHr5H0c0cq4dXS5udvtFWX7hJmG0QtHsUfhFTQj7w5BIDhwGRh9c1mBRLU 5w5k+k3BeCyGrnTr0ljjWmcpElOgDnUAMNVT26uyethJoz1gqT+h/YcCWph3thBDka6v tb8g== X-Gm-Message-State: AOJu0Yz8h46Y9Ho4Yh44d/4/OBm5nvNEWbvP6Q3Tx9p5pIG1q2KOi0+A ZL2nVGoc4tVOmoTgEWz4htba4nWBVHM= X-Google-Smtp-Source: AGHT+IE2DEwRxxcUTPiKl6SyPJ18tCANsRpeXvTEEYKI1VyaCpTJN5/XRjoMWGMWmaCLNbXlWxCkbg== X-Received: by 2002:adf:d1eb:0:b0:32f:7c1f:bf73 with SMTP id g11-20020adfd1eb000000b0032f7c1fbf73mr5456519wrd.47.1699887937328; Mon, 13 Nov 2023 07:05:37 -0800 (PST) Received: from localhost (bl21-184-115.dsl.telepac.pt. [2.82.184.115]) by smtp.gmail.com with UTF8SMTPSA id g5-20020a5d46c5000000b0032f7e832cabsm5589027wrs.90.2023.11.13.07.05.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Nov 2023 07:05:36 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [FYI/pushed v4 15/25] Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver Date: Mon, 13 Nov 2023 15:04:17 +0000 Message-Id: <20231113150427.477431-16-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.7 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 Linux GDBserver. Reviewed-By: Andrew Burgess 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 ca2b7aa1e1b..b4a1191b5b4 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_THREAD_OPTION_EXIT) != 0); +} + /* LWP accessors. */ /* See nat/linux-nat.h. */ @@ -2233,7 +2245,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; @@ -2320,7 +2331,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 @@ -2888,13 +2899,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 (); @@ -3037,10 +3055,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 @@ -3607,10 +3622,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. */ @@ -5920,7 +5932,7 @@ linux_process_target::supports_vfork_events () gdb_thread_options linux_process_target::supported_thread_options () { - return GDB_THREAD_OPTION_CLONE; + return GDB_THREAD_OPTION_CLONE | GDB_THREAD_OPTION_EXIT; } /* Check if exec events are supported. */ diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index b5ff9391198..3597e33289c 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -575,10 +575,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.34.1