From patchwork Tue Mar 29 15:49:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610710 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=DBRVe348; 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 4KSYtp5jNZz9sFk for ; Wed, 30 Mar 2022 02:50:42 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYtp5JYSz2xvv for ; Wed, 30 Mar 2022 02:50:42 +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=DBRVe348; 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::1030; helo=mail-pj1-x1030.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=DBRVe348; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 4KSYtm1xd6z2xYG for ; Wed, 30 Mar 2022 02:50:40 +1100 (AEDT) Received: by mail-pj1-x1030.google.com with SMTP id c15-20020a17090a8d0f00b001c9c81d9648so3301075pjo.2 for ; Tue, 29 Mar 2022 08:50:40 -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=Ysa/KajnIhWbb/5x6hOkJWcBzofCOl4nfc6EudIC/H0=; b=DBRVe348O9Je0EQE+tu8s0KICu0QtxKnzjY+SUKF3yagOn146BPq1fZ/tkBTaX6gr/ 0PWfLWd4qfrbI7cgh8EWzbHGizMqDNomypHN/NU2L12ZzfcZ/PWxzQoTvFbSmCBhGCIa YK2kP93zL92HZzcRUxLLPdZOj/BjkVANufD5DwfpzkDqoh4khJlQFHm0ZrexfbQTjWBv Au4oL/N2M347o9fgurXLXS3kaVQQyBl904MJ3fY0f16BW4jvHhX1WlE1ajrZtRLNVU9j pxCM3pKsO5B5HFxquTO9Bv65bEWR02MOaEK7hz2Jad/V0ynq2Og1tMQheLnAY39jtnI3 FDzA== 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=Ysa/KajnIhWbb/5x6hOkJWcBzofCOl4nfc6EudIC/H0=; b=GAEtFsKk4aSXTx3q3CQLNTs2t8TK9FxVzkc1sEHYzgAXuY0yVL8WEu6y4kq8dFnlfb EDU0uGybjj3vSyCIFxaOKsqlVYy/BlfwD9VKfKXhHNcJxSgyH4Kyid82tfdUfhUoEmWh ETP1qBdZ8cD72vt0dD9wmnUngrdidBcqvlpF/ARwslkwaPhnF/kRNS8oeYxDpuuuNUTR luo+2vUHCqLzAiM9PVC+Y9QzTXMSjhajF55xugMw/lXEy7C0WD7Cr5qvBB2TQ71JN+UO WkdnbJwjGpjwPieF+rF35QDatpYA0HXqF+k0asX+6P5VdcHA5zLW3fZBJJD0AXKm/cKi p0DQ== X-Gm-Message-State: AOAM532/riFjlpm4lpRFoW97J1/pl4iA9K6Hh8bhF4lIOxdzFn7jJ7MJ hPxSDkciqX9sQd3tqEhhdPLWp5YcY4o= X-Google-Smtp-Source: ABdhPJyZh31iufvukPM8D3wX0AFyKG5deKRm+0XFjZtr4yVmvWwggff1ymQNmSuwGlWzT9hLpHT6eg== X-Received: by 2002:a17:902:e551:b0:154:48d5:4210 with SMTP id n17-20020a170902e55100b0015448d54210mr31123722plf.2.1648569038440; Tue, 29 Mar 2022 08:50:38 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:38 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:21 +1000 Message-Id: <20220329154931.493851-29-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 28/38] 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 --- src/pdbgproxy.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1d33352..139b29e 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)) {