From patchwork Wed Apr 20 06:50:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1619353 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=e87OzjLi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 4KjrtT3mDRz9sG0 for ; Wed, 20 Apr 2022 16:51:29 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjrtT2fdcz2ymg for ; Wed, 20 Apr 2022 16:51:29 +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=e87OzjLi; 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::430; helo=mail-pf1-x430.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=e87OzjLi; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 4KjrtR2Sdmz30Dp for ; Wed, 20 Apr 2022 16:51:27 +1000 (AEST) Received: by mail-pf1-x430.google.com with SMTP id i24so1096226pfa.7 for ; Tue, 19 Apr 2022 23:51:27 -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=yhXjfMDXjOopI6H4+0u4FDFR9/203BdHbQ7yqhKx0Gc=; b=e87OzjLingBbIEIswJ7NytctXcxdEz3KWxZE56lA/20qIN2jYI78kiflrglOxht9Eh fllFXQZUJGluQFei72iotCPBczqGgZ1wL6x3qg03JEscElnSPBgqkcjKi8gcaJSiQTlI XNLdMt5orcd+1nMGGrV5qG1bZA+cgmyhSo99OTjytWqJDF5cKFeTWE65QjE5lYrLund1 aVQsEZ0CoNvpzrFCPVFgy6HpGQ6gIGdkKpruX+NYPLlAXRUHoo3wCr+I41wqOkLV7BMW 7ajMlX3p/BTDUS/KSnXk73OeU7rdLA7SmKiVFEcNpuE86bVMmjUm6neF325tPRONuxwH PX/Q== 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=yhXjfMDXjOopI6H4+0u4FDFR9/203BdHbQ7yqhKx0Gc=; b=Rq0B2zsP+hhygQ6PlvMLumJfvtjEHIpxQbbz+DRxZMSiSccft2ZuMrcWIartUTXSiS 5U6TfkvXsERwq7do1IrMZJoDctkCsK3FMDxLPORCmDLasOu4SYrewaoWPYvm+F+TwIzZ N9FcoWRPzWUF8iZO6iO8Onr0Dw5xI/eNUVs6dOankepvFQL+18ZTqOZrounuaOynwGfu cGK89FVLH0LqEn2bn+jQ51KQx4hr7ZHak4hOhiTRiPGpBtMD8GCvcgOu24oJe8FEIcRe U5lygi+hblR5LQ9Z1mUwlYWFKAbcZJAR8SDjrt3MqRV5MPPQVVnlpCfjQS+X4ZCNMSSu W7bQ== X-Gm-Message-State: AOAM53205qibXPG6FPRBVMJmD5C1CRL7sq/JVdQN6/LU0L8SEVq8vnRv xX4gLNK5jJjOCpMhG4QPV85Srp6xQ2S6vw== X-Google-Smtp-Source: ABdhPJz//zAO9u6tcx5yDtE5M84+soxaSAh2uytOVQot2N/6B86AiJ2gBU5uI1u+q/ILN/HIC8pb4g== X-Received: by 2002:a63:4412:0:b0:3a9:e7e1:81a6 with SMTP id r18-20020a634412000000b003a9e7e181a6mr13125802pga.532.1650437485534; Tue, 19 Apr 2022 23:51:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 23:51:25 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 20 Apr 2022 16:50:00 +1000 Message-Id: <20220420065013.222816-27-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 26/39] gdbserver: initial thread support 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" Add a command-specific pointer to the struct thread that gdbserver can use, so it doesn't have to build its own structure of threads. Initially keep the PIR value in here, as a demonstration. Later PIR will be used to identify threads to the gdb client, and more data will be added to the gdb_thread structure to support debugging multiple threads. Signed-off-by: Nicholas Piggin Reviewed-by: Joel Stanley --- libpdbg/hwunit.h | 1 + src/pdbgproxy.c | 66 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index 2ce41db8..563b5812 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -139,6 +139,7 @@ struct core { struct thread { struct pdbg_target target; struct thread_state status; + void *gdbserver_priv; int id; struct thread_state (*state)(struct thread *); int (*step)(struct thread *, int); diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index 393b37bf..b8ee2a06 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -51,6 +51,11 @@ static int fd = -1; enum client_state {IDLE, SIGNAL_WAIT}; static enum client_state state = IDLE; +/* Attached to thread->gdbserver_priv */ +struct gdb_thread { + uint64_t pir; +}; + static void destroy_client(int dead_fd); static uint8_t gdbcrc(char *data) @@ -666,7 +671,7 @@ static void SIGINT_handler(int sig) gdbserver_running = false; } -static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, uint16_t port) +static int gdbserver_start(struct pdbg_target *adu, uint16_t port) { int sock, i; struct sigaction sa; @@ -682,7 +687,6 @@ static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, } parser_init(callbacks); - thread_target = thread; adu_target = adu; sock = socket(PF_INET, SOCK_STREAM, 0); @@ -767,33 +771,40 @@ static int gdbserver_start(struct pdbg_target *thread, struct pdbg_target *adu, static int gdbserver(uint16_t port) { - struct pdbg_target *target, *adu, *thread = NULL; + struct pdbg_target *target, *adu, *first_target = NULL; for_each_path_target_class("thread", target) { - if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) continue; - if (!thread) { - thread = target; + if (!pdbg_target_compatible(target, "ibm,power8-thread") && + !pdbg_target_compatible(target, "ibm,power9-thread") && + !pdbg_target_compatible(target, "ibm,power10-thread")) { + PR_ERROR("GDBSERVER is only available on POWER8,9,10\n"); + return -1; + } + + gdb_thread = malloc(sizeof(struct gdb_thread)); + memset(gdb_thread, 0, sizeof(*gdb_thread)); + thread->gdbserver_priv = gdb_thread; + + if (!first_target) { + first_target = target; } else { fprintf(stderr, "GDB server cannot be run on multiple threads at once.\n"); return 0; } } - if (!thread) { + if (!first_target) { fprintf(stderr, "No thread selected\n"); return 0; } - if (!pdbg_target_compatible(thread, "ibm,power8-thread") && - !pdbg_target_compatible(thread, "ibm,power9-thread") && - !pdbg_target_compatible(thread, "ibm,power10-thread")) { - PR_ERROR("GDBSERVER is only available on POWER8,9,10\n"); - return -1; - } - - if (pdbg_target_compatible(thread, "ibm,power9-thread")) { + if (pdbg_target_compatible(first_target, "ibm,power9-thread")) { /* * XXX: If we advertise no swbreak support on POWER9 does * that prevent the client using them? @@ -801,6 +812,29 @@ static int gdbserver(uint16_t port) PR_WARNING("Breakpoints may cause host crashes on POWER9 and should not be used\n"); } + thread_target = first_target; + + for_each_path_target_class("thread", target) { + struct thread *thread = target_to_thread(target); + struct gdb_thread *gdb_thread; + + 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; + } + + if (gdb_thread->pir & ~0xffffULL) { + /* This limit is just due to some string array sizes */ + PR_ERROR("PIR exceeds 16-bits."); + return 0; + } + } + /* Select ADU target */ pdbg_for_each_class_target("mem", adu) { if (pdbg_target_probe(adu) == PDBG_TARGET_ENABLED) @@ -812,7 +846,7 @@ static int gdbserver(uint16_t port) return 0; } - gdbserver_start(thread, adu, port); + gdbserver_start(adu, port); return 0; }