From patchwork Wed Apr 20 06:50:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619361 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=poTovAQV; 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 4Kjrtw3481z9sG0 for ; Wed, 20 Apr 2022 16:51:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Kjrtw2HRKz301s for ; Wed, 20 Apr 2022 16:51:52 +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=poTovAQV; 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::634; helo=mail-pl1-x634.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=poTovAQV; dkim-atps=neutral Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) (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 4Kjrtq1LSYz2xKT for ; Wed, 20 Apr 2022 16:51:47 +1000 (AEST) Received: by mail-pl1-x634.google.com with SMTP id b7so989756plh.2 for ; Tue, 19 Apr 2022 23:51:46 -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=HfKdVkf5c24tbhHrApJ8CYiIZZe9981/R7Oj8NEyens=; b=poTovAQV+DogORp7j7Y778IHrdKjab68DtqSkELL0pQrC4oDwFiYLQojxaIP7fO3Pk R74xQcD2RwzGq1Md6d+TP20kL4Ss3XxMpX2SUO2ZIT77ZYS4I5kXOejlEOhonzn1qAAq WD2lkpdnDn9wPkj4hlrVeuOM3FzCcXV66LCBlDcHU9PsCHoaMpXRlU5JFWnrM/OYb6AL hAoPUP0itBhdllbnE8zcn1ainRbBjj07qZxucYIwb4GyevA8xD+zVpB8PIERh5yacdgK 5VOkkEV1RgAN/i5PbHjpyeda1Lqn3J5C0leiwJw5O3UakXtmcmuFcTu9+S+MBXg/TqhV BCtw== 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=HfKdVkf5c24tbhHrApJ8CYiIZZe9981/R7Oj8NEyens=; b=zJBmS0Zv2igwzQUyJlk2bDIxL1la92MR/ujAMVrcj52ZPJ9ocDS5oerbfk8HCdgzkq HnXncx9mEx3dOYuh/lECKu4P8oRZL9qaqbZepGf+zHZOt/W14pRmq+fJxFUEVHJnE7SN 6U0u2SP5q5Vrci/VDXO8ZIC0mPXLlACPch+jSikzR3z1ROyyVjtZSlhGCmC+tVHjHEgX i8lCSQw8aZwlYdy4zNQ0jnmTWIWvhqh0ShI415esxTPaUW4IFwpMcW5ZCLTYSPynlxKy s9SGzFiUkdbnpyDhvWthzROu1oFCtBr8l5Igh1FaJgRmxLL5E6AW77j0McIGUPyJ58WC pTUg== X-Gm-Message-State: AOAM532cuPtZ00uLtsG5GCaBDPxQMSSxtCnLVla2C/DaGhMsUCCGoffd gYiPRBk0OFzX4l6Fsf9nIknD7uO9Sn6miA== X-Google-Smtp-Source: ABdhPJxdJ7U1hX+xOehcC0IMfyzMv1ubA1mSAhwyuxZ9tODd4uVqISE0k0HWeoY82sK2cs0u59nRmA== X-Received: by 2002:a17:902:7244:b0:158:41d3:b79b with SMTP id c4-20020a170902724400b0015841d3b79bmr19573149pll.50.1650437504526; Tue, 19 Apr 2022 23:51:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:44 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:08 +1000 Message-Id: <20220420065013.222816-35-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 34/39] gdbserver: allow gdbserver to start with targets running 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" Rather than having to stop and start threads independently, allow gdbserver to stop and start its targets as necessary. Manually quiesced targets may still be debugged. This just makes it a bit more user friendly. Signed-off-by: Nicholas Piggin --- src/pdbgproxy.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 1d24e68a..642cbe61 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -51,7 +51,7 @@ #define TEST_SKIBOOT_ADDR 0x40000000 -static bool all_stopped = true; /* must be started with targets stopped */ +static bool all_stopped = false; static struct pdbg_target *thread_target = NULL; static struct pdbg_target *adu_target; static struct timeval timeout; @@ -222,9 +222,13 @@ static void stop_reason(uint64_t *stack, void *priv) send_stop_for_thread(thread_target); } +static void start_all(void); + static void detach(uint64_t *stack, void *priv) { PR_INFO("Detach debug session with client. pid %16" PRIi64 "\n", stack[0]); + start_all(); + send_response(fd, OK); } @@ -891,6 +895,8 @@ static void create_client(int new_fd) { PR_INFO("Client connected\n"); fd = new_fd; + if (!all_stopped) + stop_all(); } static void destroy_client(int dead_fd) @@ -1095,27 +1101,38 @@ static int gdbserver(uint16_t port) thread_target = first_target; + 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)); + return -1; + } + } + for_each_path_target_class("thread", target) { struct thread *thread = target_to_thread(target); - struct gdb_thread *gdb_thread; + struct gdb_thread *gdb_thread = thread->gdbserver_priv; if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - gdb_thread = thread->gdbserver_priv; - if (thread_getspr(target, SPR_PIR, &gdb_thread->pir)) { PR_ERROR("Error reading PIR. Are all thread in the target cores quiesced?\n"); - return 0; + goto out; } if (gdb_thread->pir & ~0xffffULL) { /* This limit is just due to some string array sizes */ PR_ERROR("PIR exceeds 16-bits."); - return 0; + goto out; } } + start_all(); + /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) @@ -1124,11 +1141,15 @@ static int gdbserver(uint16_t port) if (!adu) { fprintf(stderr, "No ADU found\n"); - return 0; + goto out; } gdbserver_start(adu, port); +out: + if (all_stopped) + __start_all(); + return 0; } #else