From patchwork Tue Mar 29 15:49:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610712 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=QbD06s6y; 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 4KSYtv6TPkz9sFk for ; Wed, 30 Mar 2022 02:50:47 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtv5m1sz2xr9 for ; Wed, 30 Mar 2022 02:50:47 +1100 (AEDT) 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=QbD06s6y; 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::102a; helo=mail-pj1-x102a.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=QbD06s6y; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 4KSYts2NZ9z2yJ9 for ; Wed, 30 Mar 2022 02:50:45 +1100 (AEDT) Received: by mail-pj1-x102a.google.com with SMTP id c15-20020a17090a8d0f00b001c9c81d9648so3301345pjo.2 for ; Tue, 29 Mar 2022 08:50:45 -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=8wAjPBSNENfkBg+ko5FEz/wanvCvKHmRg3z9TEbSaOg=; b=QbD06s6yfr186NXUp6QLaO3F26F3euEQBHbzmz3Wj0jBSXevN9QxVSukwtCqJajwtG btiEIhXiFXaKwMHpPvWqFinl7f2D5xpJA+Wj0o1Eor1bPf+mrkV5XTBVTejfsrLBUaIV THtqxp6clc7C7oTKGYboLYIZ/mgccgsCxg0w9NIsnNYufIxyJ34zoe0/GUeWE8eu6NvN 3EY/vykGFd4o3glZ5nifkqb0GdCl2oTvtA7BZNbutbEg0LgfPCIZ3iik1GlZB+wdf8Kc iFEh7Dk6hg3nMx1E52LLK0wN3E563n5n8tnYUeDxhE56oKgdy58pzmDEBd/NhTlOgwJw YZZQ== 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=8wAjPBSNENfkBg+ko5FEz/wanvCvKHmRg3z9TEbSaOg=; b=EwppL0zw6iGc9f8GDTCx3WvVzYV8+bszEhqQRE/66jxfFYmxOgmghf1M8HMrVhGtLP OLaMwdH0o0JgZtxnUNiMxgberXQ+gEYqH7myx0Lf6MpbYgy3ZQguz24CWJRpuN2accKD 04s5czQe2NdOxwUCHA7kSgVOySECw4x8s9vWGrAsoVE3hiQm82xfhSEqIm+zN/1FbOdK rNUfrfMqefWlB4mTsoyp+eYIjrH5KH/o2UGRlE5qNcnmqFv8vVembHncYYF85ebmLTBy 1XgY2+z5bZ/RbJyM0cabhqOvyIQtfR6F2DMZilxiljt+o+qxsKZuawsQAm8rVvGOpPPQ YYEQ== X-Gm-Message-State: AOAM532pr6o3WPIjMjJMy+J2QXsJZPx4Y0FccgyY9gUYlNNa/FtURg7/ 6UqoBWKu3AybGrvw32lCuq+C2v3imLo= X-Google-Smtp-Source: ABdhPJx6ycoUSPoGCC3BcIdH2VafMtUEiNcCU3FD8yyDOujG5vGABoObP/3FBug9vxFo2Wmu/iydow== X-Received: by 2002:a17:902:c242:b0:154:4f3f:ec6a with SMTP id 2-20020a170902c24200b001544f3fec6amr30476637plg.121.1648569042293; Tue, 29 Mar 2022 08:50:42 -0700 (PDT) Received: from bobo.ibm.com (58-6-255-110.tpgi.com.au. [58.6.255.110]) by smtp.gmail.com with ESMTPSA id s35-20020a056a001c6300b004fb20b5d6c1sm14163564pfw.40.2022.03.29.08.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:42 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:23 +1000 Message-Id: <20220329154931.493851-31-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220329154931.493851-1-npiggin@gmail.com> References: <20220329154931.493851-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 30/38] gdbserver: multi-thread polling and stop-reason 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" Rework poll() and the stop reason code to support multi-threaded debugging. - Make poll() iterate over all target threads to check whether any are stopped. - If any are found stopped, stop the rest. Poll SPATTN for all target threads. This provides the basis for "all-stop" threaded debugging mode, which is what seems to work best for bare metal debugging. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index d34a64e..db80b6a 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -683,60 +683,73 @@ static void stop_all(void) PR_ERROR("Could not quiesce thread\n"); /* How to fix? */ } + + if (thread_check_attn(target)) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread = thread->gdbserver_priv; + uint64_t nia; + + PR_INFO("thread pir=%llx hit attn\n", gdb_thread->pir); + + if (!(status.active)) + PR_ERROR("Error thread inactive after trap\n"); + /* Restore NIA to before break */ + if (thread_getnia(target, &nia)) + PR_ERROR("Error during getnia\n"); + if (thread_putnia(target, nia - 4)) + PR_ERROR("Error during putnia\n"); + } } } static void interrupt(uint64_t *stack, void *priv) { - struct thread_state status; - PR_INFO("Interrupt from gdb client\n"); + if (state != IDLE) { + stop_all(); - stop_all(); - - status = thread_status(thread_target); - if (!(status.quiesced)) { - PR_ERROR("Could not quiesce thread\n"); - return; + state = IDLE; + poll_interval = VCONT_POLL_DELAY; } - state = IDLE; - poll_interval = VCONT_POLL_DELAY; + send_response(fd, TRAP); } -static void poll(void) +static bool poll_threads(void) { - struct thread_state status; + struct pdbg_target *target; + + for_each_path_target_class("thread", target) { + struct thread_state status; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + target->probe(target); + status = thread_status(target); + if (status.quiesced) + return true; + } + return false; +} + +static void poll(void) +{ if (state != SIGNAL_WAIT) return; - thread_target->probe(thread_target); - status = thread_status(thread_target); - - if (!(status.quiesced)) + if (!poll_threads()) return; + /* Something hit a breakpoint */ + + stop_all(); + set_attn(false); state = IDLE; poll_interval = VCONT_POLL_DELAY; - if (thread_check_attn(thread_target)) { - uint64_t nia; - - if (!(status.active)) { - PR_ERROR("Thread inactive after trap\n"); - send_response(fd, ERROR(EPERM)); - return; - } - - /* Restore NIA */ - if (thread_getnia(thread_target, &nia)) - PR_ERROR("Error during getnia\n"); - if (thread_putnia(thread_target, nia - 4)) - PR_ERROR("Error during putnia\n"); - } send_response(fd, TRAP); }