From patchwork Tue Mar 29 15:49:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1610707 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=RRe6RKAI; 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 4KSYth3rTtz9sFk for ; Wed, 30 Mar 2022 02:50:36 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KSYth2lz2z2xvS for ; Wed, 30 Mar 2022 02:50:36 +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=RRe6RKAI; 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::62d; helo=mail-pl1-x62d.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=RRe6RKAI; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 4KSYtf6RTnz2xYG for ; Wed, 30 Mar 2022 02:50:34 +1100 (AEDT) Received: by mail-pl1-x62d.google.com with SMTP id f10so7661263plr.6 for ; Tue, 29 Mar 2022 08:50:34 -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=ZOjEwgm7KBQ08m4j6j5gWx/RC4pGprhF2SMRoNtDg10=; b=RRe6RKAIkOviFzs65ncojl2VqOBPp18OP9E7q9ahMSvJW1MgTVSZYSTES4OA9CgQWm H2+5iVpLX7ULjHZJEJcNdUxsY5SDrwtCSxMUYAlZYD+7COVNaPPwiuFrVfCHAEQ9j7Mf Fcik7qqlSpKRrBUIeWaDLlOD082QRjWaw5Zcpxxq4ZiF+pHX/cBUdmzXm7NBiMdXBPWc jtDXJmNTf78435EOQFE08yaGrDbbtx69wpjaL/IMdewfnhAE6RkuPslxWnLNFDH5/62L BFnAyTR8N+Cwo15qQJVI6WcZeiV8Hevcy4OTDX5Rc8stu7Ny7cbrasYB8t2y0RxYIAO/ jPWQ== 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=ZOjEwgm7KBQ08m4j6j5gWx/RC4pGprhF2SMRoNtDg10=; b=iTppq8p71bIdpeXMZjwJMI1x7pAwlamhfI00886yMRGq8W8urn8uCQrVkVthlDI8I5 G6VkJTXoWYpUZnVRhtZ8aEdmaoX6Jim93V5Sh3xeBMttTgLnHANsUJxos92hPZar9vMV e9r/CwTE0pDw+WwNfkJOr+TBUCq8924oaRTqPzmNJ5tEO3hfaRkaBqhPf4dQPU45IfKo G+anhg17iqA+yXyvW8jx135+K8VlfJPwL75kOMRBV0/lcEcEBaGoJ36Bd2hgcTkZ3mw5 jpD1k5PKFejo0sCXck3S4QLq/qm0CsnkUa0BqPyfomAG46IF4Dhu7RwgaRKaFTG0mWfB FCzQ== X-Gm-Message-State: AOAM532jQKDUPvJdQXkCV6R4/WX1X6baD2VDeroKAZQuToSpWJ2MVUTX qxr29Hf6NwkMa0s5gDHEqBTcJ01ghXM= X-Google-Smtp-Source: ABdhPJxwqhhyN35GuOS0DFWwRsLI2Z6r8/v5m5py0z+lkUhqF5UGeL9lv1U3jjGPkgt+iKqwEeK1ow== X-Received: by 2002:a17:90a:8595:b0:1bf:4592:a819 with SMTP id m21-20020a17090a859500b001bf4592a819mr204364pjn.183.1648569032652; Tue, 29 Mar 2022 08:50:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 08:50:32 -0700 (PDT) From: Nicholas Piggin To: pdbg@lists.ozlabs.org Date: Wed, 30 Mar 2022 01:49:18 +1000 Message-Id: <20220329154931.493851-26-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 25/38] 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 --- 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 2ce41db..563b581 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 6fa3c6d..c5e439d 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; }