From patchwork Wed Jul 29 08:46:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1338197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (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 ozlabs.org (Postfix) with ESMTPS id 4BGnGg698Rz9sRN for ; Wed, 29 Jul 2020 18:47:07 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=w0WHWMHi; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BGnGg5FFzzDqq3 for ; Wed, 29 Jul 2020 18:47:07 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (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 4BGnGb5PCCzDqgd for ; Wed, 29 Jul 2020 18:47:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=w0WHWMHi; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4BGnGb2GHQz9sRK; Wed, 29 Jul 2020 18:47:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1596012423; bh=KpFDa0/Ye7AmxO2OTg9qlvlK0IqeCZNPt3Fb3PWzy84=; h=From:To:Cc:Subject:Date:From; b=w0WHWMHiAVND0kfHbW0I5PFPcWNKjK05u1dblZOjLozaEeSkry8Fih+U2UW19jOHC jyF3EkqHZt//bC9MVscdMqLKSWEQ7kc9+otWEopsA+D5R58hwZkIpLwqoL1b0vn/er LSvBu7yT5U+HAHKtl8ElGKBrpWvERgRL+mOG8kNhNIOKirHI2GuIrr9lAbYfPkXDyp V/GhJtH0Hd5rZ8m8w4LVDle8HU3vd41SxUbKtwWlUPvmyhIDO2qFPZyBxJRvAg5Au1 p6vQoKlGq11DZ69VIGUB7GQA/5qMLei6i/oVmRPN7ZJFkgXORE3NZF10mGaoht5VPZ EMx3Uw4Bsae4A== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 29 Jul 2020 18:46:52 +1000 Message-Id: <20200729084652.932287-1-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [Pdbg] [PATCH] libpdbg: Fix reading register values from sbefifo backend 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: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The function sbefifo_register_get() returns the register values into an allocated buffer, that needs to be freed by caller. It does not store register values in the provided buffer. Signed-off-by: Amitay Isaacs --- libpdbg/sbefifo.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c index 898fd1a..6e45088 100644 --- a/libpdbg/sbefifo.c +++ b/libpdbg/sbefifo.c @@ -352,7 +352,7 @@ static int sbefifo_thread_getregs(struct thread *thread, struct thread_regs *reg struct sbefifo *sbefifo = pib_to_sbefifo(pib); struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo); uint32_t reg_id[34]; - uint64_t value[34]; + uint64_t *value; int ret, i; for (i=0; i<32; i++) @@ -365,10 +365,15 @@ static int sbefifo_thread_getregs(struct thread *thread, struct thread_regs *reg SBEFIFO_REGISTER_TYPE_GPR, reg_id, 32, - (uint64_t **)®s->gprs); + &value); if (ret) return ret; + for (i=0; i<32; i++) + regs->gprs[i] = value[i]; + + free(value); + reg_id[0] = SPR_NIA; reg_id[1] = SPR_MSR; reg_id[2] = SPR_CFAR; @@ -410,7 +415,7 @@ static int sbefifo_thread_getregs(struct thread *thread, struct thread_regs *reg SBEFIFO_REGISTER_TYPE_SPR, reg_id, 34, - (uint64_t **)&value); + &value); if (ret) return ret; @@ -449,6 +454,8 @@ static int sbefifo_thread_getregs(struct thread *thread, struct thread_regs *reg regs->sprg3 = value[32]; regs->ppr = value[33]; + free(value); + return 0; } @@ -458,15 +465,24 @@ static int sbefifo_thread_get_reg(struct thread *thread, uint8_t reg_type, uint3 struct pdbg_target *pib = pdbg_target_require_parent("pib", chiplet); struct sbefifo *sbefifo = pib_to_sbefifo(pib); struct sbefifo_context *sctx = sbefifo->get_sbefifo_context(sbefifo); + uint64_t *v; + int ret; /* This chip-op requires core-id as pervasive (chiplet) id */ - return sbefifo_register_get(sctx, - pdbg_target_index(chiplet), - thread->id, - reg_type, - ®_id, - 1, - &value); + ret = sbefifo_register_get(sctx, + pdbg_target_index(chiplet), + thread->id, + reg_type, + ®_id, + 1, + &v); + if (ret) + return ret; + + *value = *v; + free(v); + + return 0; } static int sbefifo_thread_put_reg(struct thread *thread, uint8_t reg_type, uint32_t reg_id, uint64_t value)