From patchwork Wed Apr 20 06:50:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mIVIVPUd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kjrtx3HK7z9sG0 for ; Wed, 20 Apr 2022 16:51:53 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtx1pmvz3bXg for ; Wed, 20 Apr 2022 16:51:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mIVIVPUd; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::636; helo=mail-pl1-x636.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mIVIVPUd; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Kjrts4TpCz2xKT for ; Wed, 20 Apr 2022 16:51:49 +1000 (AEST) Received: by mail-pl1-x636.google.com with SMTP id j8so956708pll.11 for ; Tue, 19 Apr 2022 23:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pn/jdyaR2D+3+0upBW7MJGbVbirVz3dwzMZ9CHgIjVA=; b=mIVIVPUdl1Yt3P19JslJmvgUBi76tUzKGXubrX5Zjvqp1M3MRJGm+2WpDa3cxE54D9 mLqzG0A9Dq7dKNpzRs4aseIlqdaz/RkBz0aNO7z+v34amVgvdi/4W+cCbEUUE4GJgvL+ jNv2UqdxMeC6S6atnnhQjEsWKOFkPRfQj/+EbyTg63i+Cpp5HX1QXB0Zd7gJcd2GpUzC bidMd9u1EKPNooDD8WndNNQEAEFqBuGffxEVhsfQ+LQTDQH7ZX1wSXJD/zkK2aRWZtdd mKXNq83ocVW4se8xNIewb4oD44P/n+0eznm4x3PddUmdFWyNqO3DgwozhsNaWhiZQoUj NLWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pn/jdyaR2D+3+0upBW7MJGbVbirVz3dwzMZ9CHgIjVA=; b=JJoZKG86irb0/ZsM/FoPc24Uq+ornEVpZfVuT3x9et9jNExhUoS6jpd18Gh9XqSq2B nDnpjXpRZjAjKNuu3d6tW4EdiAPNo4fbYLqGhtBpin43+ZYGNf55Pt3+o31kRZpLeotX OEubXcVD+Te/xAoVj1wnNVKbdmgZYIhtXojoVRBeZkhOHLZ88rUcDxZ2VM+fK5n7Qs/A N/oGF+tF6qj20XJDjqGCpV1htepEscwfumosdwMALJeXpOrPmOZrYKD3iNHJQZFFWPGt pghPX0YGl49ToIIeJYwY8fdeSVg8vaeLE3oiD7qbjLeBH+mtFVylH40FnOWiDG5A40c4 rlEQ== X-Gm-Message-State: AOAM5308f44xRjlPoXDnVtjD1U2h21h76G4hPr8wZzJNLLqmmS6r0mNQ aCQlH92ugYiQT8MRVp/1G0Uxa2oxhvpblw== X-Google-Smtp-Source: ABdhPJwl38l/V7QdJ+ccOsXb/nHeJvY4ryWe0RivEBcRPvKpdlYf9IHZgqOa00Mikt9FjG1fuzfXgw== X-Received: by 2002:a17:902:d488:b0:158:e7d1:fc16 with SMTP id c8-20020a170902d48800b00158e7d1fc16mr19196200plg.171.1650437506834; Tue, 19 Apr 2022 23:51:46 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([203.221.203.144]) by smtp.gmail.com with ESMTPSA id x20-20020aa79574000000b005061f4782c5sm18481235pfq.183.2022.04.19.23.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:46 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:09 +1000 Message-Id: <20220420065013.222816-36-npiggin@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420065013.222816-1-npiggin@gmail.com> References: <20220420065013.222816-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 35/39] gdbserver: better deal with threads initially stopped X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Better deal with threads that are quiesced when gdbserver starts. Record and clear SPATTN register to determine whether any had hit attn, and prevent subsequent stop from getting a false positive on SPATTN. Switch target thread to the first one that had hit an attn or been stopped when gdbserver starts up, if any. Don't resume initially-stopped threads unless a client attaches and directs them to. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 90 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 642cbe61..6b9bdf90 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -64,6 +64,7 @@ static enum client_state state = IDLE; struct gdb_thread { uint64_t pir; bool attn_set; + bool initial_stopped; bool stop_attn; bool stop_ctrlc; }; @@ -1058,11 +1059,15 @@ static int gdbserver_start(struct pdbg_target *adu, uint16_t port) static int gdbserver(uint16_t port) { - struct pdbg_target *target, *adu, *first_target = NULL; + struct pdbg_target *target, *adu; + struct pdbg_target *first_target = NULL; + struct pdbg_target *first_stopped_target = NULL; + struct pdbg_target *first_attn_target = NULL; for_each_path_target_class("thread", target) { struct thread *thread = target_to_thread(target); struct gdb_thread *gdb_thread; + struct thread_state status; if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; @@ -1080,6 +1085,13 @@ static int gdbserver(uint16_t port) if (!first_target) first_target = target; + + status = thread_status(target); + if (status.quiesced) { + if (!first_stopped_target) + first_stopped_target = target; + gdb_thread->initial_stopped = true; + } } if (!first_target) { @@ -1099,16 +1111,19 @@ static int gdbserver(uint16_t port) PR_WARNING("GDBSERVER works best when targeting all threads (-a)\n"); } - thread_target = first_target; - for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - if (thread_stop(target)) { - PR_ERROR("Could not stop thread %s\n", - pdbg_target_path(target)); - return -1; + if (!gdb_thread->initial_stopped) { + if (thread_stop(target)) { + PR_ERROR("Could not stop thread %s\n", + pdbg_target_path(target)); + return -1; + } } } @@ -1129,9 +1144,46 @@ static int gdbserver(uint16_t port) PR_ERROR("PIR exceeds 16-bits."); goto out; } + + if (thread_check_attn(target)) { + PR_INFO("thread pir=%"PRIx64" hit attn\n", gdb_thread->pir); + + if (!first_attn_target) + first_attn_target = target; + gdb_thread->stop_attn = true; + if (!gdb_thread->initial_stopped) { + PR_WARNING("thread pir=%"PRIx64" hit attn but was not stopped\n", gdb_thread->pir); + gdb_thread->initial_stopped = true; + } + } } - start_all(); + /* Target attn as a priority, then any stopped, then first */ + if (first_attn_target) + thread_target = first_target; + else if (first_stopped_target) + thread_target = first_stopped_target; + else + thread_target = first_target; + + /* + * Resume threads now, except those that were initially stopped, + * leave them so the client can inspect them. + */ + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!gdb_thread->initial_stopped) { + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + } /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { @@ -1147,8 +1199,26 @@ static int gdbserver(uint16_t port) gdbserver_start(adu, port); out: - if (all_stopped) - __start_all(); + if (!all_stopped) + stop_all(); + + /* + * Only resume those which were not initially stopped + */ + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!gdb_thread->initial_stopped) { + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + } return 0; }