From patchwork Wed Apr 20 06:50:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619358 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=AkEe2wkB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 4Kjrtk375jz9sG0 for ; Wed, 20 Apr 2022 16:51:42 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtk2HyNz2ypZ for ; Wed, 20 Apr 2022 16:51:42 +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=AkEe2wkB; 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::635; helo=mail-pl1-x635.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=AkEe2wkB; dkim-atps=neutral Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 4Kjrtg6DzMz2ymS for ; Wed, 20 Apr 2022 16:51:39 +1000 (AEST) Received: by mail-pl1-x635.google.com with SMTP id n8so992096plh.1 for ; Tue, 19 Apr 2022 23:51:39 -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=Dai1NOCkH03lRB7FKGaxe8ZEgUrVEVxXdzx28mpJ44k=; b=AkEe2wkBpgnN6iQ67RyxmMlEBeQicFLRd6Una1NfZSghGZTgOO7Xe71V/hOkNW2BEl 4gFiLbsocSrP2PA237XJdepHN/Af0PvCpk7ylAfStli9MXhAYDxzIA/VnUz+Nj325kum YKSQz7tstcOn2mwenEyzCARio60SqX7gz+FCmvRIof/RfQU14yswWoMDDv00lkla3HOe /rDM+wF/6iU4RLQFvqKEwvUhhdGrlOUtGKjnLb8qrba+A7EQwJc1uUjxwCV8TNlgXivp fv/3NdUU4ZuVTzdKP9lP+zP1N9POYQiR3lix910KznWAQHDuL4CTT6Wh9IASuCEC0grb S/eg== 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=Dai1NOCkH03lRB7FKGaxe8ZEgUrVEVxXdzx28mpJ44k=; b=qmphaui8HBoBNlBd+8VZde6BqakhLgJs5eg4dUTp0Ism1sVXppKxWPd5y1ApBGcA+e 63J8IvmXcCa8vD7B5XkWKPva8rp5Uk67YKdpAPiEv1mH28O01SBB3VoCRqbeCEAlAya4 8S1HFAP3tIYyrUCmTJk079e53d2mHv5emxYLS3PX/gBghuqdTDz1CJMhE7b6P9BZLzUR EKWnMrOQT8kuoO1d5Oz31WSsc2MS0d7dEZFEJAdThVyZDTb5wgha3QnxJ23mSXSEWX9S k5JmiXV37OPNrHMHThy0e9exabQdy3lJ+Og+Qp7s3lOT+i/V+KMkWI7RzUw/NTNbIUAu /wyw== X-Gm-Message-State: AOAM532CcmsZgYnhOELCYc5NiOuh2h4z0SQm15GysYQOvcrOML7CMk+3 1A9DOkMqA4IL/cN9Rm5Z7GulM5p215z7Ng== X-Google-Smtp-Source: ABdhPJzD/OOYXlQTCrR2EZzpzdpCPjIXJ7uoUeW9YQrK2hcLmpYP03GXpWTBm2EgpbPqMWfnahgAAA== X-Received: by 2002:a17:902:8487:b0:158:f82d:e39e with SMTP id c7-20020a170902848700b00158f82de39emr14533435plo.52.1650437497543; Tue, 19 Apr 2022 23:51:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:37 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:05 +1000 Message-Id: <20220420065013.222816-32-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 31/39] 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 Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index c5870091..735615c6 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=%"PRIx64" 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); }