From patchwork Tue Mar 29 15:49:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610715 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=HdWzV1kI; 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 4KSYv14QpKz9sFk for ; Wed, 30 Mar 2022 02:50:53 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYv10ffYz2yKQ for ; Wed, 30 Mar 2022 02:50:53 +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=HdWzV1kI; 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::42b; helo=mail-pf1-x42b.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=HdWzV1kI; dkim-atps=neutral Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (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 4KSYty2N8kz2yHB for ; Wed, 30 Mar 2022 02:50:50 +1100 (AEDT) Received: by mail-pf1-x42b.google.com with SMTP id b13so14376496pfv.0 for ; Tue, 29 Mar 2022 08:50:50 -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=pW+C0DqPNyhiIMu8OVzT9y1XjksrY7jLAHeJOiPFCtA=; b=HdWzV1kIqM1QJHkiZVAPw3YKTxjhK76mLBR6kP0tx4XdfNQum/nOxu896dOAuaxiqi n6H2LtNWIWPq2T4eNF5QA+8jnemG1rrUR+BgA8oj1cDtxSmpAQv026JFR1s16GnGw+L+ 0ojRJENYo5ZMRNw3BXjz98HJnOOENR7UHoCl8tvzbl4IRKU9qtdSM8EJaeG16agQi+lq 2qhPvQFpVzmtVHeNSc/IrpmtkH+ke8yTYe9x97e2xkOxE7gca6xHRLO805jaPtfNTr+Q oCz9dlk+UOMv4c0/63KA5ib6swYpT5kDjB1pEljgxUUbg/m+X7zT5ro3RHvSR+kQ0hld h/iA== 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=pW+C0DqPNyhiIMu8OVzT9y1XjksrY7jLAHeJOiPFCtA=; b=V4GHaRJEG2dGmCBBdU/W8gUrAvi1Ar1bbVcDDm4eITe/c4YBnuo8ilTfsjnAwTW7hb pfM+8k9QPOhO+k/f30IEUVF3IXtZdJ1aE5XqhsXOSNd6YdC8ugxrqwkTITLWHytJ2yF5 b5c4cHMILzdglLsXq9jZmGcyRzmX9c2914g33bWwQU6e6xOtOCgmhiuCXXutjeaqE6yB E6xNcVYSGrJ5Mg7FiNZ3ibkI0JwjhLP0JMSLYDJbxToMeoftBIhW4lTt0OBlXzqaBMUT J1kwvGCt0Wlvgfu36TMwRNer/3bfS7iOR5uDaGK9hG82q2W3up6EQHmWO4PmvKrtNvTz J+HA== X-Gm-Message-State: AOAM531N9PcZJr9/lxQXm9ENbl2llBn+9CpdKx0EJZZFcD3h2uDW54HV fTh+gnWHo17ttWYiZwWMuwg/GBZqtyY= X-Google-Smtp-Source: ABdhPJyKqEcHWQY8OzjiSfZBqpqrFYT+AOfvaOYPDeUhZfkYbmDFNsTOEdxFfzSPCOEqb4m+DI536Q== X-Received: by 2002:a63:f412:0:b0:381:28f:85dd with SMTP id g18-20020a63f412000000b00381028f85ddmr2467675pgi.319.1648569048252; Tue, 29 Mar 2022 08:50:48 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:47 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:26 +1000 Message-Id: <20220329154931.493851-34-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 33/38] 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 e9d11af..3ffa9e2 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