From patchwork Wed Apr 20 06:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619356 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=ilGjPmab; 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 4Kjrtd2Y9Mz9sG0 for ; Wed, 20 Apr 2022 16:51:37 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtd23LVz2ymS for ; Wed, 20 Apr 2022 16:51:37 +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=ilGjPmab; 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::102f; helo=mail-pj1-x102f.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=ilGjPmab; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 4Kjrtb0vGHz3bWD for ; Wed, 20 Apr 2022 16:51:35 +1000 (AEST) Received: by mail-pj1-x102f.google.com with SMTP id n11-20020a17090a73cb00b001d1d3a7116bso3203291pjk.0 for ; Tue, 19 Apr 2022 23:51:35 -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=chKZfXqK+7phN61hWpaLEBfrcjZ3D/jRKTK542dIDQU=; b=ilGjPmabzuiJdNbvLlAriEnryZT7KFbdyZqQ4ZZAQxrQrWyZqDGj7UUspo8pUsOx2u ktW03BcRkrS6+aT1Rg4QYmWRGhlQThI3Q1lrhRGp5TORkOIpBOx1EwSa0WkPzh2JWECD gB2VJmi6Z6CQrnk8MwXKoQsPPt9g7uL+cJBMSxLSn1qxDhUVIHhThb9XQCBW/Fxygbhb F84QT5H/pqV2ViYKVmmaMQH1xT4eeTOkPHlL/hsZ0GqnSFc7FRLahkJDlNGp793XCU+8 px4QhRgwK/ev2H6j9xroskp1EqnKr/D/pGMi2l760GX0ZmdeHlz+HVbr1LOSvDmQZV0H dugA== 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=chKZfXqK+7phN61hWpaLEBfrcjZ3D/jRKTK542dIDQU=; b=DFnUjTAQLdLv6ymJ/54HJ+zMIk30VIT1fIQBChfdH1ToRvHJ7AQeCpM0I9CozSLJOt ZcL5MAIl9LyRGWsYBHvT3aOPWvGRfJxTjJNowja1w50r+ehuK+Yj7t03EjAKnj0Zmz7o mxxtgiOPLdjH1IvCglcFU64CTy4X7H9bhDHUsfIGtv9H9SnidX/N/RKEp3n1sSlovJZT i3B/5SUU7KW0nk3kCsmufBJ2towugG6Vu8xNstYSPxATbovJWclzJN6UpFcxrokQkqI9 8VHdzW3McEd2PS8vZ751uLNvzd/T7dvn7kReeOH76leqDgSGFlda7GLy/98xPfoj78fI II8A== X-Gm-Message-State: AOAM532kk1/yyn4psgoybZh1CwQDnmbSACeYIF/qeY3vj7oyqHABXOTo 4kWW2E+ZAcCecP4iQyWb/XAF+nQP+5qEEg== X-Google-Smtp-Source: ABdhPJy9yakx4InNrl7gwmCxFXOzpwzl7gsWGl/ufvfDrM3SOuRrpcdN4Z+bzRXGULh/o9pok66w3A== X-Received: by 2002:a17:903:2302:b0:158:cef1:79b9 with SMTP id d2-20020a170903230200b00158cef179b9mr19607859plh.64.1650437493051; Tue, 19 Apr 2022 23:51:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:32 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:03 +1000 Message-Id: <20220420065013.222816-30-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 29/39] gdbserver: add multi-threaded start/stop helper functions 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" Prepare for multi threaded debugging (in gdb's "all-stop" mode) by providing helpers that stop and start all target threads. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- src/pdbgproxy.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 4f30ede2..01419108 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -43,6 +43,7 @@ #define TEST_SKIBOOT_ADDR 0x40000000 +static bool all_stopped = true; /* must be started with targets stopped */ static struct pdbg_target *thread_target = NULL; static struct pdbg_target *adu_target; static struct timeval timeout; @@ -542,10 +543,50 @@ static void v_conts(uint64_t *stack, void *priv) send_response(fd, TRAP); } +static void __start_all(void) +{ + struct pdbg_target *target; + + if (!all_stopped) + PR_ERROR("starting while not all stopped\n"); + + for_each_path_target_class("thread", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (thread_start(target)) { + PR_ERROR("Could not start thread %s\n", + pdbg_target_path(target)); + } + } + + all_stopped = false; +} + +static void start_all(void) +{ + 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) + PR_ERROR("starting thread not quiesced\n"); + } + + __start_all(); +} + #define VCONT_POLL_DELAY 100000 static void v_contc(uint64_t *stack, void *priv) { - thread_start(thread_target); + start_all(); + state = SIGNAL_WAIT; poll_interval = 1; } @@ -603,13 +644,55 @@ static bool thread_check_attn(struct pdbg_target *target) return false; } +static void __stop_all(void) +{ + struct pdbg_target *target; + + if (all_stopped) + PR_ERROR("stopping while all stopped\n"); + + for_each_path_target_class("thread", target) { + 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)); + /* How to fix? */ + } + } + + all_stopped = true; +} + +static void stop_all(void) +{ + struct pdbg_target *target; + + __stop_all(); + + 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) { + PR_ERROR("Could not quiesce thread\n"); + /* How to fix? */ + } + } +} + static void interrupt(uint64_t *stack, void *priv) { struct thread_state status; PR_INFO("Interrupt from gdb client\n"); - thread_stop(thread_target); + stop_all(); status = thread_status(thread_target); if (!(status.quiesced)) {