From patchwork Fri Nov 16 01:14:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dW4cQfz9sB5 for ; Fri, 16 Nov 2018 12:14:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="NqcSFyNI"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dW14mJzF3hJ for ; Fri, 16 Nov 2018 12:14:55 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="NqcSFyNI"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dH2NrxzF3fY for ; Fri, 16 Nov 2018 12:14:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="NqcSFyNI"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dG6bdLz9sCQ; Fri, 16 Nov 2018 12:14:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330883; bh=3r1uC1u37OUxE/Xbbrz6u4WN+SYjJ97Kzld+M9hKoMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NqcSFyNIa0PD/iOPkAhLUhgL6Pa9JyvKRVacl2N2cXhhMHco7/IvK8BiKQUjLlI8G vbyHWATUdJc+6zQh/H2yaDStgJZMr7CuzZIL6x7q5dbR1C+/zZfdQJ+6ciQkTDjLj0 KI5VVQVCkBDsW01d9/RiEugv7cEUVyRm9HitfDwII5R5DwoYobA4Rb4hQuf15q5p8X F59s982If4/b77OHJ7FKKDwn+H0TfMvLljGo/rMsNwib8+UYVdrj95MP5K5Zp4NrCP 1ZNJ7GNgGkizOi4k0pieoMPP2RlWOGRHHyvq2BrSBTll6esH8onp8WXFRWMM7fEozn H5UiX/Lu6s+Gw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:16 +1100 Message-Id: <20181116011431.246208-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 01/16] libpdbg: Convert printf to DEBUG statements 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/fake.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libpdbg/fake.c b/libpdbg/fake.c index 58e7e18..a816ff5 100644 --- a/libpdbg/fake.c +++ b/libpdbg/fake.c @@ -13,20 +13,22 @@ * see the license for the specific language governing permissions and * limitations under the license. */ -#include "operations.h" #include #include +#include "libpdbg.h" +#include "operations.h" + static int fake_fsi_read(struct fsi *fsi, uint32_t addr, uint32_t *value) { *value = 0xfeed0cfa; - printf("fake_fsi_read(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, *value); + PR_DEBUG("fake_fsi_read(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, *value); return 0; } static int fake_fsi_write(struct fsi *fsi, uint32_t addr, uint32_t value) { - printf("fake_fsi_write(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, value); + PR_DEBUG("fake_fsi_write(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, value); return 0; } @@ -44,13 +46,13 @@ DECLARE_HW_UNIT(fake_fsi); static int fake_pib_read(struct pib *pib, uint64_t addr, uint64_t *value) { *value = 0xdeadbeef; - printf("fake_pib_read(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, *value); + PR_DEBUG("fake_pib_read(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, *value); return 0; } static int fake_pib_write(struct pib *pib, uint64_t addr, uint64_t value) { - printf("fake_pib_write(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, value); + PR_DEBUG("fake_pib_write(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, value); return 0; } From patchwork Fri Nov 16 01:14:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0db5Y6nz9sB5 for ; Fri, 16 Nov 2018 12:14:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="Q6k13SKW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0db3KJyzF3ff for ; Fri, 16 Nov 2018 12:14:59 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Q6k13SKW"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dH5g1GzF3fW for ; Fri, 16 Nov 2018 12:14:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="Q6k13SKW"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dH2Zsnz9sBQ; Fri, 16 Nov 2018 12:14:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330883; bh=IIo6hPBC9PTuqItr2l+AGwrx/c5ArEyDzIH6NULXwMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6k13SKWHIXH+eApV4IpGtOSRhzi2yILDTkRpTwxdk4E8N239ZVy5c7KC/ZXLRA2u nXdAhFVxd0G4kGDMGowKNHae5QbQlYdiSKukIWsLkE989VS7g4ol3VcvwHWywl6rgD kiL+d9vEDkNCwscIzzYctcfXMSdBHjiFenFgHdUYjUaxKRGa2l5CxRmI1C0l2TB2/Q AaXzgBrl6Kyb7+W8hR7rCCimEzRMeCqgHNC8pJ2M4b8NegSjVpMCaS63KpBg/RUySy ah4467Stv8PnksKf9b7lImuN1i73labqq6WLUvy3XYPVpsu6BYLh8dgrMFLEQBSh8a QjZKMz52ldmXA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:17 +1100 Message-Id: <20181116011431.246208-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 02/16] main: Convert target_selection() to return a boolean 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 5d0c0e3..6ad869d 100644 --- a/src/main.c +++ b/src/main.c @@ -600,7 +600,7 @@ void for_each_target_release(char *class) } } -static int target_selection(void) +static bool target_selection(void) { struct pdbg_target *fsi, *pib, *chip, *thread; @@ -613,7 +613,7 @@ static int target_selection(void) case FSI: if (device_node == NULL) { PR_ERROR("FSI backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_fsi_dtb_o_start); @@ -625,14 +625,14 @@ static int target_selection(void) pdbg_targets_init(&_binary_p9z_fsi_dtb_o_start); else { PR_ERROR("Invalid device type specified\n"); - return -1; + return false; } break; case KERNEL: if (device_node == NULL) { PR_ERROR("kernel backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_kernel_dtb_o_start); @@ -646,7 +646,7 @@ static int target_selection(void) case HOST: if (device_node == NULL) { PR_ERROR("Host backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_host_dtb_o_start); @@ -654,7 +654,7 @@ static int target_selection(void) pdbg_targets_init(&_binary_p9_host_dtb_o_start); else { PR_ERROR("Unsupported device type for host backend\n"); - return -1; + return false; } break; #endif @@ -667,7 +667,7 @@ static int target_selection(void) /* parse_options deals with parsing user input, so it should be * impossible to get here */ assert(0); - return -1; + return false; } /* At this point we should have a device-tree loaded. We want @@ -722,7 +722,7 @@ static int target_selection(void) target_unselect(fsi); } - return 0; + return true; } void print_target(struct pdbg_target *target, int level) @@ -814,7 +814,7 @@ int main(int argc, char *argv[]) device_node = default_target(backend); /* Disable unselected targets */ - if (target_selection()) + if (!target_selection()) return 1; atexit(atexit_release); From patchwork Fri Nov 16 01:14:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dg5w8Vz9sB5 for ; Fri, 16 Nov 2018 12:15:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="OsaZBEhd"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dg3PX5zF3fW for ; Fri, 16 Nov 2018 12:15:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="OsaZBEhd"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dJ2BT2zF3fY for ; Fri, 16 Nov 2018 12:14:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="OsaZBEhd"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dH5vFgz9sBn; Fri, 16 Nov 2018 12:14:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330883; bh=6k8YSK0o3vAL1yz0qeJ17TbGv7WzdPF9cxN5zWjro+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OsaZBEhdk+7T9csM9fjKQjzQXW/hKWpi3d7iVoqf9h7qmqwq3/JWpFkV+SR790NBD CFWeRXEXezELcIPvPCJ5Tujo6O3Y3RDbiLBFkl5jT+Ag2DSL+p6X2u9XBqldKZlW0e IRo8NjhvLT4g0xaE8eb7R87RLDmdIzQykrpRdhRV8jzEhuU3DBTppRdcn/LRpBtfMb k/EZHrR6rMzGYJwuLrPM9YeXt87LXiJ5QhFEUXe99tr0WWWJQu4RWoqtvyvjsZ4jzv 06QTggiqNx2j5yAw2b8OztuvuKFJaXvLwEh2AOlAzPOo1bRTvptCfnwmYhUXi+2b2h KUv391Cb3Ocjw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:18 +1100 Message-Id: <20181116011431.246208-4-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 03/16] util: Move parse_list() into a separate file 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" ... and document the function. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- Makefile.am | 4 ++- src/main.c | 74 +---------------------------------------- src/util.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 34 +++++++++++++++++++ 4 files changed, 133 insertions(+), 74 deletions(-) create mode 100644 src/util.c create mode 100644 src/util.h diff --git a/Makefile.am b/Makefile.am index b8f38ca..c8f100e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,7 +85,9 @@ pdbg_SOURCES = \ src/reg.c \ src/ring.c \ src/scom.c \ - src/thread.c + src/thread.c \ + src/util.c \ + src/util.h if TARGET_ARM pdbg_SOURCES += src/options_arm.c diff --git a/src/main.c b/src/main.c index 6ad869d..fd77f6d 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ #include "optcmd.h" #include "progress.h" #include "pdbgproxy.h" +#include "util.h" #define PR_ERROR(x, args...) \ pdbg_log(PDBG_ERROR, x, ##args) @@ -180,79 +181,6 @@ static void print_usage(char *pname) printf(" %-15s %-27s %s\n", actions[i].name, actions[i].args, actions[i].desc); } -/* Parse argument of the form 0-5,7,9-11,15,17 */ -static bool parse_list(const char *arg, int max, int *list, int *count) -{ - char str[strlen(arg)+1]; - char *tok, *tmp, *saveptr = NULL; - int i; - - assert(max < INT_MAX); - - strcpy(str, arg); - - tmp = str; - while ((tok = strtok_r(tmp, ",", &saveptr)) != NULL) { - char *a, *b, *endptr, *saveptr2 = NULL; - unsigned long int from, to; - - a = strtok_r(tok, "-", &saveptr2); - if (a == NULL) { - return false; - } else { - endptr = NULL; - from = strtoul(a, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid value %s\n", a); - return false; - } - if (from >= max) { - fprintf(stderr, "Value %s larger than max %d\n", a, max-1); - return false; - } - } - - b = strtok_r(NULL, "-", &saveptr2); - if (b == NULL) { - to = from; - } else { - endptr = NULL; - to = strtoul(b, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid value %s\n", b); - return false; - } - if (to >= max) { - fprintf(stderr, "Value %s larger than max %d\n", b, max-1); - return false; - } - } - - if (from > to) { - fprintf(stderr, "Invalid range %s-%s\n", a, b); - return false; - } - - for (i = from; i <= to; i++) - list[i] = 1; - - tmp = NULL; - }; - - if (count != NULL) { - int n = 0; - - for (i = 0; i < max; i++) { - if (list[i] == 1) - n++; - } - - *count = n; - } - - return true; -} - #ifdef TARGET_PPC int get_pir(int linux_cpu) { diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..3a4520d --- /dev/null +++ b/src/util.c @@ -0,0 +1,95 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include + +/* Parse argument of the form 0-5,7,9-11,15,17 */ +bool parse_list(const char *arg, int max, int *list, int *count) +{ + char str[strlen(arg)+1]; + char *tok, *tmp, *saveptr = NULL; + int i; + + assert(max < INT_MAX); + + strcpy(str, arg); + + tmp = str; + while ((tok = strtok_r(tmp, ",", &saveptr)) != NULL) { + char *a, *b, *endptr, *saveptr2 = NULL; + unsigned long int from, to; + + a = strtok_r(tok, "-", &saveptr2); + if (a == NULL) { + return false; + } else { + endptr = NULL; + from = strtoul(a, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr, "Invalid value %s\n", a); + return false; + } + if (from >= max) { + fprintf(stderr, "Value %s larger than max %d\n", a, max-1); + return false; + } + } + + b = strtok_r(NULL, "-", &saveptr2); + if (b == NULL) { + to = from; + } else { + endptr = NULL; + to = strtoul(b, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr, "Invalid value %s\n", b); + return false; + } + if (to >= max) { + fprintf(stderr, "Value %s larger than max %d\n", b, max-1); + return false; + } + } + + if (from > to) { + fprintf(stderr, "Invalid range %s-%s\n", a, b); + return false; + } + + for (i = from; i <= to; i++) + list[i] = 1; + + tmp = NULL; + }; + + if (count != NULL) { + int n = 0; + + for (i = 0; i < max; i++) { + if (list[i] == 1) + n++; + } + + *count = n; + } + + return true; +} + diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..131e3f9 --- /dev/null +++ b/src/util.h @@ -0,0 +1,34 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __UTIL_H +#define __UTIL_H + +/** + * @brief Parse a range or a list of numbers from a string into an array + * + * For each number present in the string, set the corresponding list element + * to 1. The list acts as the index flags. The range of valid numbers varies + * from 0 to sizeof(list)-1. + * + * @param[in] arg String to parse + * @param[in] max The size of the list + * @param[in] list The list of flags + * @param[out] count Optional count of distinct numbers found + * @return true on success, false on error + */ +bool parse_list(const char *arg, int max, int *list, int *count); + +#endif From patchwork Fri Nov 16 01:14:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998651 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dl4Pq6z9sB5 for ; Fri, 16 Nov 2018 12:15:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="RTId3ThW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dl1hFtzF3fd for ; Fri, 16 Nov 2018 12:15:07 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="RTId3ThW"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dJ4zTDzF3fW for ; Fri, 16 Nov 2018 12:14:44 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="RTId3ThW"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dJ2NbYz9sB5; Fri, 16 Nov 2018 12:14:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330884; bh=cOfCkf2jxTLeCiZTxLXmigsLeV+otMwL+y/atMOgMT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RTId3ThW7yLAF3iJ7igMzC87NX4seaL4HF6O3NDGRYswU/wuUgZJ0uN96fw7pdPub MwGxNr71JmKOgOMwDHSOJqIeabTyehhsqU2t4/itNlWq3n4qHsM2qg69U/rE5fXb7k 5QchBOY5xnKEr1RCt4rnEGeuSQYZd4FapaBgaeFHPwwjsMjf6JkRqeiVqfWWqpbk2q JT5gQTAprmzfQuGrwkCRlJ9xTG/BREmoUYLD676MtJB4XieEqXV8q0Arbxkrz7Nlkk 4HQ+vVjwxjpNOup4uU3qJ4ZrWp0XUD5NNrnwOrmDsonkDU0dsusOXn8ickam/uk8HE XeaarqnxdxO8A== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:19 +1100 Message-Id: <20181116011431.246208-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 04/16] path: Add device tree path based targeting 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- Makefile.am | 2 + src/path.c | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/path.h | 103 ++++++++++++++++ 3 files changed, 437 insertions(+) create mode 100644 src/path.c create mode 100644 src/path.h diff --git a/Makefile.am b/Makefile.am index c8f100e..2a687ca 100644 --- a/Makefile.am +++ b/Makefile.am @@ -78,6 +78,8 @@ pdbg_SOURCES = \ src/options.h \ src/parsers.c \ src/parsers.h \ + src/path.c \ + src/path.h \ src/pdbgproxy.c \ src/pdbgproxy.h \ src/progress.c \ diff --git a/src/path.c b/src/path.c new file mode 100644 index 0000000..6b4e29b --- /dev/null +++ b/src/path.c @@ -0,0 +1,332 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "path.h" +#include "util.h" + +#define MAX_PATH_COMP_LEN 32 +#define MAX_PATH_COMPONENTS 16 +#define MAX_PATH_LEN (MAX_PATH_COMP_LEN * MAX_PATH_COMPONENTS) + +/* This is max(MAX_PROCESSORS, MAX_CHIPS, MAX_THREADS) */ +#define MAX_PATH_INDEX 64 + +struct path_pattern { + char prefix[MAX_PATH_COMP_LEN]; + int index[MAX_PATH_INDEX]; + bool match_full; + bool match_index; +}; + +/* Start with max threads, rather than defining arbitrary number */ +#define MAX_TARGETS (64 * 24 * 8) + +static struct pdbg_target *path_target[MAX_TARGETS]; +static unsigned int path_target_count; + +static void safe_strcpy(char *dest, size_t n, const char *src) +{ + assert(strlen(src) + 1 <= n); + + strcpy(dest, src); +} + +/* + * Parse string components of following forms: + * pib0 + * core[1-3,11-13] + * thread* + * adu@123000 + */ +static bool path_pattern_parse(const char *arg, struct path_pattern *pat) +{ + char tmp[strlen(arg)+1]; + char *tok; + bool ok; + + safe_strcpy(tmp, sizeof(tmp), arg); + + memset(pat, 0, sizeof(*pat)); + + if (strchr(tmp, '@')) { + safe_strcpy(pat->prefix, sizeof(pat->prefix), tmp); + pat->match_full = true; + + } else if (strchr(tmp, '*')) { + tok = strtok(tmp, "*"); + if (!tok) + safe_strcpy(pat->prefix, sizeof(pat->prefix), "all"); + else + safe_strcpy(pat->prefix, sizeof(pat->prefix), tok); + + } else if (strchr(tmp, '[')) { + tok = strtok(tmp, "["); + if (tok == NULL) { + fprintf(stderr, "Invalid pattern '%s'\n", arg); + return false; + } + safe_strcpy(pat->prefix, sizeof(pat->prefix), tok); + + tok = strtok(NULL, "]"); + if (!tok) { + fprintf(stderr, "Invalid pattern '%s'\n", arg); + return false; + } + + ok = parse_list(tok, MAX_PATH_INDEX, pat->index, NULL); + if (!ok) + return false; + + pat->match_index = true; + + } else { + size_t n = strlen(tmp) - 1; + while (n >= 0 && isdigit(tmp[n])) + n--; + n++; + + if (n != strlen(tmp)) { + int index; + + index = atoi(&tmp[n]); + if (index < 0 || index >= MAX_PATH_INDEX) { + fprintf(stderr, "Invalid index '%s'\n", &tmp[n]); + return false; + } + tmp[n] = '\0'; + pat->index[index] = 1; + pat->match_index = true; + } + + safe_strcpy(pat->prefix, sizeof(pat->prefix), tmp); + } + + if (!pat->prefix) + return false; + + return true; +} + +static int path_pattern_split(const char *arg, struct path_pattern *pats) +{ + char arg_copy[MAX_PATH_LEN]; + char *tmp, *tok, *saveptr = NULL; + int n; + bool ok; + + safe_strcpy(arg_copy, sizeof(arg_copy), arg); + + tmp = arg_copy; + n = 0; + while ((tok = strtok_r(tmp, "/", &saveptr))) { + size_t len = strlen(tok); + + if (len == 0) + continue; + + if (len >= MAX_PATH_LEN) { + fprintf(stderr, "Pattern component '%s' too long\n", tok); + return -1; + } + + ok = path_pattern_parse(tok, &pats[n]); + if (!ok) + return -1; + + n++; + assert(n <= MAX_PATH_COMPONENTS); + + tmp = NULL; + } + + return n; +} + +static int path_target_find(struct pdbg_target *prev) +{ + int i; + + if (!prev) + return -1; + + for (i=0; i= 0) + return true; + + if (path_target_count == MAX_TARGETS) + return false; + + path_target[path_target_count] = target; + path_target_count++; + return true; +} + +static void path_pattern_match(struct pdbg_target *target, + struct path_pattern *pats, + int max_levels, + int level) +{ + struct pdbg_target *child; + char comp_name[MAX_PATH_COMP_LEN]; + char *tok; + int next = level; + bool found = false; + + if (target == pdbg_target_root()) { + goto end; + } + + if (!strcmp("all", pats[level].prefix)) { + if (!path_target_add(target)) + return; + goto end; + } + + safe_strcpy(comp_name, sizeof(comp_name), pdbg_target_class_name(target)); + if (pats[level].match_full) { + tok = comp_name; + } else { + tok = strtok(comp_name, "@"); + } + + if (!strcmp(tok, pats[level].prefix)) { + found = true; + + if (pats[level].match_index) { + int index = pdbg_target_index(target); + + if (pats[level].index[index] != 1) + found = false; + } + } + + if (found) { + if (level == max_levels-1) { + path_target_add(target); + return; + } else { + next = level + 1; + } + } + +end: + pdbg_for_each_child_target(target, child) { + path_pattern_match(child, pats, max_levels, next); + } +} + +bool path_target_parse(const char **arg, int arg_count) +{ + struct path_pattern pats[MAX_PATH_COMPONENTS]; + int i, n; + + for (i=0; i 0); +} + +bool path_target_selected(struct pdbg_target *target) +{ + int index; + + index = path_target_find(target); + if (index >= 0) + return true; + + return false; +} + +void path_target_dump(void) +{ + struct pdbg_target *target; + char *path; + + for_each_path_target(target) { + path = pdbg_target_path(target); + assert(path); + printf("%s\n", path); + free(path); + } +} + +struct pdbg_target *path_target_next(struct pdbg_target *prev) +{ + int index; + + index = path_target_find(prev); + return path_target_find_next(NULL, index); +} + +struct pdbg_target *path_target_next_class(const char *klass, + struct pdbg_target *prev) +{ + int index; + + index = path_target_find(prev); + return path_target_find_next(klass, index); +} diff --git a/src/path.h b/src/path.h new file mode 100644 index 0000000..c3c20c0 --- /dev/null +++ b/src/path.h @@ -0,0 +1,103 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PDBG_PATH_H +#define __PDBG_PATH_H + +#include + +/** + * @brief Parse a list of path target strings + * + * @param[in] arg An array of strings + * @param[in] arg_count The number of strings + * @return true on success, false on error + */ +bool path_target_parse(const char **arg, int arg_count); + +/** + * @brief Check if there are any path targets + * + * @return true if number of path targets > 0, false otherwise + */ +bool path_target_present(void); + +/** + * @brief Add a target to the list + * + * @param[in] target pdbg target + * @return true on success, false on error + */ +bool path_target_add(struct pdbg_target *target); + +/** + * @brief Check if the specified target is selected + * + * @param[in] target pdbg target + * @return true if the target is selected, false otherwise + */ +bool path_target_selected(struct pdbg_target *target); + +/** + * @brief Print the list of path targets to stdout + */ +void path_target_dump(void); + +/** + * @brief Iterator for list of path targets + * + * @param[in] prev The last pdbg target + * @return the next pdbg target in the list, NULL otherwise + * + * If prev is NULL, then return the first pdbg target in the list. + * If there are no more pdbg targets in the list, NULL is returned. + */ +struct pdbg_target *path_target_next(struct pdbg_target *prev); + +/** + * @brief Iterator for a list of path targets of specified class + * + * @param[in] klass The class of the targets required + * @param[in] prev The last pdbg target + * @return the next matching pdbg target in the list, NULL otherwise + * + * If prev is NULL, then return the first matching pdbg target in the list. + * If there are no more matching pdbg targets, NULL is returned. + */ +struct pdbg_target *path_target_next_class(const char *klass, + struct pdbg_target *prev); + +/** + * @brief Macro for iterating through all path targets + * + * target is of type struct pdbg_target + */ +#define for_each_path_target(target) \ + for (target = path_target_next(NULL); \ + target; \ + target = path_target_next(target)) + +/** + * @brief Macro for iterating through all path targets of specific class + * + * class is of type char * + * target is of type struct pdbg_target + */ +#define for_each_path_target_class(class, target) \ + for (target = path_target_next_class(class, NULL); \ + target; \ + target = path_target_next_class(class, target)) + +#endif From patchwork Fri Nov 16 01:14:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998652 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dr37CYz9sBQ for ; Fri, 16 Nov 2018 12:15:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="ibSIxAEv"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dq208ZzF3fY for ; Fri, 16 Nov 2018 12:15:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="ibSIxAEv"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dK1JjgzF3fW for ; Fri, 16 Nov 2018 12:14:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="ibSIxAEv"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dJ5DWDz9sBQ; Fri, 16 Nov 2018 12:14:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330884; bh=+khe80mifXYHzk5RTiOKTmMjMEUfQKPJldjLcn1pKWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ibSIxAEv6C3+40+qDOAR7MskrTzI1bT0PADGBdrdD9GyoSPvd/vFK8/XatDg2sbV8 454QO/KNsm50aA/1HFbiZexA0AIHKdEMx8oGhHCsJf1klRCZGxITBAZ1sVOGdJZOKU m9M10samcJHo8MRvSekxGxun2/Fp3Z+ND3dcxjG1kFBEQ4B7BLIC7cWRV6U4lU6Bdo 1UAwBqqYiuE5ymblTihUqf8kyANYUar6maYn/Q+YkYn+jGb0B5Sd7aK8gFqDQZUsyg lUzmXnRlL+TME2Z0x0cft2MWinTxJDM6qXFkV+pt30niCJCqvgyX68SmkGSw9svp6D 91aOwuvO0Gm/w== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:20 +1100 Message-Id: <20181116011431.246208-6-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 05/16] main: Add an option for path based targetting 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index fd77f6d..9252eb3 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ #include "progress.h" #include "pdbgproxy.h" #include "util.h" +#include "path.h" #define PR_ERROR(x, args...) \ pdbg_log(PDBG_ERROR, x, ##args) @@ -78,6 +79,11 @@ static int **processorsel[MAX_PROCESSORS]; static int *chipsel[MAX_PROCESSORS][MAX_CHIPS]; static int threadsel[MAX_PROCESSORS][MAX_CHIPS][MAX_THREADS]; +#define MAX_PATH_ARGS 16 + +static const char *pathsel[MAX_PATH_ARGS]; +static int pathsel_count; + static int probe(void); /* TODO: We are repeating ourselves here. A little bit more macro magic could @@ -153,6 +159,7 @@ static void print_usage(char *pname) #ifdef TARGET_PPC printf("\t-l, --cpu=<0-%d>||\n", MAX_PROCESSORS-1); #endif + printf("\t-P, --path=\n"); printf("\t-a, --all\n"); printf("\t\tRun command on all possible processors/chips/threads (default)\n"); printf("\t-b, --backend=backend\n"); @@ -243,6 +250,36 @@ void pir_map(int pir, int *chip, int *core, int *thread) {} #define PPC_OPTS #endif +static bool pathsel_add(char *format, ...) __attribute__((format (printf, 1, 2))); + +static bool pathsel_add(char *format, ...) +{ + va_list ap; + char path[1024]; + int len; + + va_start(ap, format); + + len = vsnprintf(path, sizeof(path), format, ap); + if (len > sizeof(path)) { + va_end(ap); + return false; + } + + va_end(ap); + + if (pathsel_count == MAX_PATH_ARGS) { + fprintf(stderr, "Too many path arguments\n"); + return false; + } + + pathsel[pathsel_count] = strdup(path); + assert(pathsel[pathsel_count]); + pathsel_count++; + + return true; +} + static bool parse_options(int argc, char *argv[]) { int c; @@ -266,6 +303,7 @@ static bool parse_options(int argc, char *argv[]) {"cpu", required_argument, NULL, 'l'}, #endif {"debug", required_argument, NULL, 'D'}, + {"path", required_argument, NULL, 'P'}, {"shutup", no_argument, NULL, 'S'}, {"version", no_argument, NULL, 'V'}, {NULL, 0, NULL, 0} @@ -278,7 +316,7 @@ static bool parse_options(int argc, char *argv[]) memset(l_list, 0, sizeof(l_list)); do { - c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:SV" PPC_OPTS, + c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:P:SV" PPC_OPTS, long_opts, NULL); if (c == -1) break; @@ -364,6 +402,11 @@ static bool parse_options(int argc, char *argv[]) fprintf(stderr, "Invalid slave address '%s'\n", optarg); break; + case 'P': + if (!pathsel_add("%s", optarg)) + opt_error = true; + break; + case 'S': progress_shutup(); break; @@ -650,6 +693,11 @@ static bool target_selection(void) target_unselect(fsi); } + if (pathsel_count) { + if (!path_target_parse(pathsel, pathsel_count)) + return false; + } + return true; } From patchwork Fri Nov 16 01:14:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998653 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dv5Y0Jz9sBn for ; Fri, 16 Nov 2018 12:15:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="Cl6nSIIe"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dv3ShlzF3fd for ; Fri, 16 Nov 2018 12:15:15 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Cl6nSIIe"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dK4CNjzF3fY for ; Fri, 16 Nov 2018 12:14:45 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="Cl6nSIIe"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dK1X49z9sB5; Fri, 16 Nov 2018 12:14:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330885; bh=j/LnJ7Vl7/PrcQySeuamVZHzIdQHpcNHoTYJG/+dd4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cl6nSIIeXT/zcKUyLtW7qMPlQeNsu/tkEgjQm30uQ4ksIUOZwvOPifZcEwikBsxDn HhMjK+c6Mk06sPaLy7/UTikYfYaNH4FLQ4b35vUaQyjBsLqMHkUOkXnQ4vSNaRBPPW saV111YQsaE9T/oKoIr+UiwWI3l1qTxzo7Q48o5YacJ7CGkmZg297bJWmDfUiZPbCC pQzc7ws7zxNoUD0L4rT5ackY/pTi5ixNRL8OwmknChG05k8YTDjdQwaEHnUMcCyzAm gMEXDcZ3CWcM2lqkUb20mDDKp4USWZz70olt51weR0ry7kGV2WoqTIzPIK8SfSsF4t HOEfnL9TkS6QA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:21 +1100 Message-Id: <20181116011431.246208-7-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 06/16] main: Add explicit probing of selected targets 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.c b/src/main.c index 9252eb3..3e3835c 100644 --- a/src/main.c +++ b/src/main.c @@ -775,6 +775,7 @@ int main(int argc, char *argv[]) int i, rc = 0; void **args, **flags; optcmd_cmd_t *cmd; + struct pdbg_target *target; backend = default_backend(); @@ -793,6 +794,11 @@ int main(int argc, char *argv[]) if (!target_selection()) return 1; + /* Probe all selected targets */ + for_each_path_target(target) { + pdbg_target_probe(target); + } + atexit(atexit_release); for (i = 0; i < ARRAY_SIZE(cmds); i++) { From patchwork Fri Nov 16 01:14:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0dy45Tsz9sBn for ; Fri, 16 Nov 2018 12:15:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="pupbhFpn"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0dy2NwCzF3hK for ; Fri, 16 Nov 2018 12:15:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="pupbhFpn"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dL054TzF3fW for ; Fri, 16 Nov 2018 12:14:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="pupbhFpn"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dK4RmJz9sBQ; Fri, 16 Nov 2018 12:14:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330885; bh=fRWiLMyHhKhsqSL0b1Fdc/v14MWsEqzfpGPGXBfdv+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pupbhFpnoghdD8/m5uAsXK9017QdE98RlhGniDv4t/isgnsWF5rc60iBtP4q9sG8R XvGLgZpZ7vPyCWo85nolsY3XdVOeufp5TYRzaahKaLjPPgEun997OvHH8Y1VCUMue9 E7NdxzrPiTodfs4NbQxL6fc4jw9BxKSSgPOvjDj4jqUjpR5o2FEPnPVMZMi8MJifO2 GtLL4lztyKMslkKUDrQdHsTaI731vQAHH757Yr9nVEwmUWWS1nBfttzjJyXXNHTN6L Jb9NXx/kWGzqRck19EnXa4L/jPPfTaYcIBEKtrUtKFH0W2A304wfAq/p+tmudSQlXX ghDKsPlnk3NZA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:22 +1100 Message-Id: <20181116011431.246208-8-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 07/16] main: Convert -p/-c/-t/-a/-l to path based targets 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" To maintain the compatibility with the old selection where -p selected processor, add fsi and pib targets with matching index. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 74 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index 3e3835c..506e0b9 100644 --- a/src/main.c +++ b/src/main.c @@ -280,6 +280,26 @@ static bool pathsel_add(char *format, ...) return true; } +static bool list_to_string(int *list, int max, char *str, size_t len) +{ + char tmp[16]; + int i; + + memset(str, 0, len); + + for (i=0; i len) { + return false; + } + strcat(str, tmp); + } + } + + return true; +} + static bool parse_options(int argc, char *argv[]) { int c; @@ -289,7 +309,7 @@ static bool parse_options(int argc, char *argv[]) int t_list[MAX_THREADS]; int l_list[MAX_LINUX_CPUS]; int p_count = 0, c_count = 0, t_count = 0, l_count = 0; - int i, j, k; + int i; struct option long_opts[] = { {"all", no_argument, NULL, 'a'}, {"backend", required_argument, NULL, 'b'}, @@ -309,6 +329,7 @@ static bool parse_options(int argc, char *argv[]) {NULL, 0, NULL, 0} }; char *endptr; + char p_str[256], c_str[256], t_str[256]; memset(p_list, 0, sizeof(p_list)); memset(c_list, 0, sizeof(c_list)); @@ -437,6 +458,16 @@ static bool parse_options(int argc, char *argv[]) return false; } + if (pathsel_count > 0 && l_count > 0) { + fprintf(stderr, "Can't mix -l with -P\n"); + return false; + } + + if ((c_count > 0 || t_count > 0 || p_count > 0) && (pathsel_count > 0)) { + fprintf(stderr, "Can't mix -P with -p/-c/-t/-a\n"); + return false; + } + if ((c_count > 0 || t_count > 0) && p_count == 0) { fprintf(stderr, "No processor(s) selected\n"); fprintf(stderr, "Use -p or -a to select processor(s)\n"); @@ -449,25 +480,27 @@ static bool parse_options(int argc, char *argv[]) return false; } - for (i = 0; i < MAX_PROCESSORS; i++) { - if (p_list[i] == 0) - continue; - - processorsel[i] = &chipsel[i][0]; - - for (j = 0; j < MAX_CHIPS; j++) { - if (c_list[j] == 0) - continue; - - chipsel[i][j] = &threadsel[i][j][0]; + if (p_count) { + if (!list_to_string(p_list, MAX_PROCESSORS, p_str, sizeof(p_str))) + return false; + if (!pathsel_add("fsi[%s]", p_str)) + return false; + if (!pathsel_add("pib[%s]", p_str)) + return false; + } - for (k = 0; k < MAX_THREADS; k++) { - if (t_list[k] == 0) - continue; + if (c_count) { + if (!list_to_string(c_list, MAX_CHIPS, c_str, sizeof(c_str))) + return false; + if (!pathsel_add("pib[%s]/core[%s]", p_str, c_str)) + return false; + } - threadsel[i][j][k] = 1; - } - } + if (t_count) { + if (!list_to_string(t_list, MAX_THREADS, t_str, sizeof(t_str))) + return false; + if (!pathsel_add("pib[%s]/core[%s]/thread[%s]", p_str, c_str, t_str)) + return false; } if (l_count) { @@ -481,9 +514,8 @@ static bool parse_options(int argc, char *argv[]) pir_map(pir, &chip, &core, &thread); - processorsel[chip] = &chipsel[chip][0]; - chipsel[chip][core] = &threadsel[chip][core][0]; - threadsel[chip][core][thread] = 1; + if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread)) + return false; } } } From patchwork Fri Nov 16 01:14:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0f21TQ5z9sBQ for ; Fri, 16 Nov 2018 12:15:22 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="Qsb9K+KJ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0f16HmbzF3hK for ; Fri, 16 Nov 2018 12:15:21 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Qsb9K+KJ"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dL3KmVzF3fY for ; Fri, 16 Nov 2018 12:14:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="Qsb9K+KJ"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dL0Gvzz9sB5; Fri, 16 Nov 2018 12:14:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330886; bh=404eIX3eUhpVEpTghnwJ2qjitwwHgrkIQCrLQHA0bbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qsb9K+KJNYSY4swfP/33z5sueoZcbwRFccOEiniLV/zy+gpoXZDVBGE5MKvIpeVl1 3umnvviGLBmEFl8Eh2AHnRYLHg4UUyZpp+qJe0XgItshBNI+lfuLIvulVtx1JO4yZB OtVeeuKBNMx9YhoSSNQ0s9688FSPVeEfsffTarHI+212dXomvBwDmVHMwJ+9mnglSx lp57wrV2kAK0goKvDJiaTmgn0Bat6xJBYAyR2LYkYtKaT0cc5ltA/uApuW+ZiBCLui mg2BQrXyNrUMJ+3iRGktf43Xw8uCZPMBBXVQRqPor9OoGu2tjA/SA46snGydZvvsYQ yLqR3s0MsWQ6A== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:23 +1100 Message-Id: <20181116011431.246208-9-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 08/16] main: Switch to path based target selection 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" Drop the old target selection code. Signed-off-by: Amitay Isaacs --- src/main.c | 80 ++++++------------------------------------------------ 1 file changed, 8 insertions(+), 72 deletions(-) diff --git a/src/main.c b/src/main.c index 506e0b9..0a3a8fb 100644 --- a/src/main.c +++ b/src/main.c @@ -75,10 +75,6 @@ static int i2c_addr = 0x50; #define MAX_LINUX_CPUS (MAX_PROCESSORS * MAX_CHIPS * MAX_THREADS) -static int **processorsel[MAX_PROCESSORS]; -static int *chipsel[MAX_PROCESSORS][MAX_CHIPS]; -static int threadsel[MAX_PROCESSORS][MAX_CHIPS][MAX_THREADS]; - #define MAX_PATH_ARGS 16 static const char *pathsel[MAX_PATH_ARGS]; @@ -525,19 +521,12 @@ static bool parse_options(int argc, char *argv[]) void target_select(struct pdbg_target *target) { - /* We abuse the private data pointer atm to indicate the target is - * selected */ - pdbg_target_priv_set(target, (void *) 1); -} - -void target_unselect(struct pdbg_target *target) -{ - pdbg_target_priv_set(target, NULL); + path_target_add(target); } bool target_selected(struct pdbg_target *target) { - return (bool) pdbg_target_priv(target); + return path_target_selected(target); } /* Returns the sum of return codes. This can be used to count how many targets the callback was run on. */ @@ -556,7 +545,6 @@ int for_each_child_target(char *class, struct pdbg_target *parent, index = pdbg_target_index(target); assert(index != -1); - pdbg_target_probe(target); status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) continue; @@ -580,7 +568,6 @@ int for_each_target(char *class, int (*cb)(struct pdbg_target *, uint32_t, uint6 index = pdbg_target_index(target); assert(index != -1); - pdbg_target_probe(target); status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) continue; @@ -605,8 +592,6 @@ void for_each_target_release(char *class) static bool target_selection(void) { - struct pdbg_target *fsi, *pib, *chip, *thread; - switch (backend) { #ifdef TARGET_ARM case I2C: @@ -673,63 +658,17 @@ static bool target_selection(void) return false; } - /* At this point we should have a device-tree loaded. We want - * to walk the tree and disabled nodes we don't care about - * prior to probing. */ - pdbg_for_each_class_target("pib", pib) { - int proc_index = pdbg_target_index(pib); - - if (backend == I2C && device_node) - pdbg_target_set_property(pib, "bus", device_node, strlen(device_node) + 1); - - if (processorsel[proc_index]) { - target_select(pib); - pdbg_for_each_target("core", pib, chip) { - int chip_index = pdbg_target_index(chip); - if (pdbg_parent_index(chip, "pib") != proc_index) - continue; - - if (chipsel[proc_index][chip_index]) { - target_select(chip); - pdbg_for_each_target("thread", chip, thread) { - int thread_index = pdbg_target_index(thread); - if (threadsel[proc_index][chip_index][thread_index]) - target_select(thread); - else - target_unselect(thread); - } - } else - target_unselect(chip); - } - - /* This is kinda broken as we're overloading what '-c' - * means - it's now up to each command to select targets - * based on core/chiplet. We really need a better - * solution to target selection. */ - pdbg_for_each_target("chiplet", pib, chip) { - int chip_index = pdbg_target_index(chip); - if (chipsel[proc_index][chip_index]) { - target_select(chip); - } else - target_unselect(chip); - } - } else - target_unselect(pib); - } - - pdbg_for_each_class_target("fsi", fsi) { - int index = pdbg_target_index(fsi); - if (processorsel[index]) - target_select(fsi); - else - target_unselect(fsi); - } - if (pathsel_count) { if (!path_target_parse(pathsel, pathsel_count)) return false; } + if (!path_target_present()) { + printf("No valid targets found or specified. Try adding -p/-c/-t options to specify a target.\n"); + printf("Alternatively run 'pdbg -a probe' to get a list of all valid targets\n"); + return false; + } + return true; } @@ -862,8 +801,5 @@ found_action: if (rc > 0) return 0; - printf("No valid targets found or specified. Try adding -p/-c/-t options to specify a target.\n"); - printf("Alternatively run '%s -a probe' to get a list of all valid targets\n", - basename(argv[0])); return 1; } From patchwork Fri Nov 16 01:14:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998656 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0f73llSz9sB5 for ; Fri, 16 Nov 2018 12:15:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="K+SA+XlP"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0f71SSMzF3fW for ; Fri, 16 Nov 2018 12:15:27 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="K+SA+XlP"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dM07xnzF3fW for ; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="K+SA+XlP"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dL3WkXz9sBQ; Fri, 16 Nov 2018 12:14:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330886; bh=0UoHQpBEtqYaBgZ2gLWJ+iKO540lVXV1lMN8aGlOmFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K+SA+XlP/3iZJV1nUZzvlAQ4NR1x9EeGEs+502bPbgTXctm+RtN3kR25G+ezFiR8E T46cvNNWilYrdJhS5oUDJHdZ3r2gX8+jxVnJ/cMkYJWi/yXDNvguQxdTNENld9PIXt LK4U3CLwN6TzFfHcsqBGpJPDVbMX7BBqqS7C7tgoQgDDLcngjhXB6NyavnTPdvg/KC fRj8Ce1+ULpBMXO/Qt7p87ZemLob/E6g7JNTbyVdj8oaYhHfkKqC8oyCDvtcZzCWVd UVT/HCpKh55N6WHdoDq5ZQTEsD46xAuBllIGyJjIXQwugqAMFD/eSymi3CqUkIYx9f jTXR4nYg19C5g== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:24 +1100 Message-Id: <20181116011431.246208-10-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 09/16] main: Fix probe() to print targets correctly 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" Signed-off-by: Amitay Isaacs --- src/main.c | 11 ----------- tests/test_selection.sh | 43 +++-------------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/main.c b/src/main.c index 0a3a8fb..3b20bf0 100644 --- a/src/main.c +++ b/src/main.c @@ -678,8 +678,6 @@ void print_target(struct pdbg_target *target, int level) struct pdbg_target *next; enum pdbg_target_status status; - pdbg_target_probe(target); - /* Does this target actually exist? */ status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) @@ -708,9 +706,6 @@ void print_target(struct pdbg_target *target, int level) } pdbg_for_each_child_target(target, next) { - if (!target_selected(next)) - continue; - print_target(next, level + 1); } } @@ -720,15 +715,9 @@ static int probe(void) struct pdbg_target *target; pdbg_for_each_class_target("pib", target) { - if (!target_selected(target)) - continue; - print_target(target, 0); } - printf("\nNote that only selected targets will be shown above. If none are shown\n" - "try adding '-a' to select all targets\n"); - return 1; } OPTCMD_DEFINE_CMD(probe, probe); diff --git a/tests/test_selection.sh b/tests/test_selection.sh index 2b23ec1..8909796 100755 --- a/tests/test_selection.sh +++ b/tests/test_selection.sh @@ -13,10 +13,9 @@ do_skip () fi } -test_result 0 < X-Patchwork-Id: 998657 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fC2ndrz9sB5 for ; Fri, 16 Nov 2018 12:15:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="Ow+KV1MG"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fB6N04zF3fY for ; Fri, 16 Nov 2018 12:15:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Ow+KV1MG"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dM3P25zF3fY for ; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="Ow+KV1MG"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dM0PJ5z9sB5; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330887; bh=z8c/p0cqgKiP9jxdZPcGG+zXLoj1GllZhhJYOlAum8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ow+KV1MGQTVw65swuEl+z2PZ+LRTF2FLwOQzGfbEl9zFRXp6HxO9wnQVvBJYNNVml jBDrMezkvr0ISIYazwvMfbnTeoxUz4o4IFl2Xvugog4jz1F6njvZkF/VzPGy0Xlj8K yUM9BOIlEmdm1J+ZDGiKGv2O64nZjZ9aBYrednKz8oineUahO8L57F3+bLQNf9xt5w eDNqHKZM5T2nLFtfsQa5be8uc01wcYsxgh2mBXyxjjNcFG1g+vPdsXXiADihdblmKc UUFgxjO7q30A+VY+xpBziacocedjgDb3T1CrPNPgnNr9RbZAhaPT24d2Gf3ZNIfcsU tpmHD6KtiQJbQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:25 +1100 Message-Id: <20181116011431.246208-11-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 10/16] tests: Add path based selection tests 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" Signed-off-by: Amitay Isaacs Tested-by: Alistair Popple --- Makefile.am | 1 + tests/test_selection2.sh | 545 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 546 insertions(+) create mode 100755 tests/test_selection2.sh diff --git a/Makefile.am b/Makefile.am index 2a687ca..f1e06f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ check_PROGRAMS = $(libpdbg_tests) optcmd_test PDBG_TESTS = \ tests/test_selection.sh \ + tests/test_selection2.sh \ tests/test_hw_bmc.sh TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS) diff --git a/tests/test_selection2.sh b/tests/test_selection2.sh new file mode 100755 index 0000000..4e7921d --- /dev/null +++ b/tests/test_selection2.sh @@ -0,0 +1,545 @@ +#!/bin/sh + +. $(dirname "$0")/driver.sh + +test_group "path target selection tests" + +arch=$(arch 2>/dev/null) + +do_skip () +{ + if [ "$arch" != "x86_64" ] ; then + test_skip + fi +} + +test_result 0 < X-Patchwork-Id: 998658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fH2XBPz9sBQ for ; Fri, 16 Nov 2018 12:15:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="RYwiKY8G"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fG70dfzF3h6 for ; Fri, 16 Nov 2018 12:15:34 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="RYwiKY8G"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dM6C4xzF3fd for ; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="RYwiKY8G"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dM3d0Cz9sBQ; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330887; bh=x6R0WtGlUY8X2ei57ZvnNu8UOUL2JZMSIN2db2ABEc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RYwiKY8Gxo069jQcXrATGALghzN5sfMGKIa+dVstByP3fVQQOZlRlnrTzP2cA3cUZ Es6ttc3PJHB1BiDdDqiBgSRCZKZVcUHkNW9YrLdNvEr27v2hLsl1pqCyVA+BUGwGrV xeFqz3tDi7tIgi7orFIb4qxheZM+eKqEHIFz3ILe9g3mCjV9RPssbdV4np9gXyQrB3 B0SHDZLEWHsujM/BZIJpb94ZhH3wKH/1LxruC05+LYXs38Dv+P3Ehfz49la3A1x1VU yFI8Zb24+rrGYjDfud6QggfiSY/GFPM/t6Gy8V3DFaCE+Ck5kLz0gYf/9ox/+35C5p PMHHotCZVpT9Q== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:26 +1100 Message-Id: <20181116011431.246208-12-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 11/16] main: Do not use argv[0] for progname 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" When pdbg is built without "--disable-shared" option, libtool creates pdbg as a wrapper around lt-pdbg binary. This causes the tests to fail which try to match the output containing argv[0]. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 3b20bf0..51e39d9 100644 --- a/src/main.c +++ b/src/main.c @@ -143,11 +143,11 @@ static struct action actions[] = { { "gdbserver", "", "Start a gdb server" }, }; -static void print_usage(char *pname) +static void print_usage(void) { int i; - printf("Usage: %s [options] command ...\n\n", pname); + printf("Usage: pdbg [options] command ...\n\n"); printf(" Options:\n"); printf("\t-p, --processor=<0-%d>||\n", MAX_PROCESSORS-1); printf("\t-c, --chip=<0-%d>||\n", MAX_CHIPS-1); @@ -440,7 +440,7 @@ static bool parse_options(int argc, char *argv[]) case '?': case 'h': opt_error = true; - print_usage(basename(argv[0])); + print_usage(); break; } } while (c != EOF && !opt_error); @@ -743,7 +743,7 @@ int main(int argc, char *argv[]) return 1; if (optind >= argc) { - print_usage(basename(argv[0])); + print_usage(); return 1; } From patchwork Fri Nov 16 01:14:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fM1fQ8z9sB5 for ; Fri, 16 Nov 2018 12:15:39 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="H7yjUl2U"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fL6dBGzF3hK for ; Fri, 16 Nov 2018 12:15:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="H7yjUl2U"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dN379DzF3ff for ; Fri, 16 Nov 2018 12:14:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="H7yjUl2U"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dM6WMWz9sB5; Fri, 16 Nov 2018 12:14:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330888; bh=kxe6f9Hucj9PYH20DfhuLsbQIFtXsJNWSXyhK32YjP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H7yjUl2U1k9vD86U4GGTKJvy3JCWMM9p4fYouSh8wtxV2aVORAnvs6lRwCstoW7CT oHUd41swT8rIFAfUuZlRHNaDqUb2PTm5oKPXOf7H+4woaPfyE2cop4GRiwH3400xs2 RljbVOeSNtzf1VKS2L23cq27S9mwkwHPU1S3mTn4old/YLt/oF74j25oYoA6at9Gxu IUi55uT+CTlC09/XeLaw8eL6in8N4vtvPWvyKfObhwdlgbtLnn1/MgDjglW1x0/FoT 220bGLFPMlCj1xhZjl9dJrWul1J7e7OSftRsomNf7GA5lcBdSQyy5KFpxKvWAiHHeD 0IK08oUSXCGNw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:27 +1100 Message-Id: <20181116011431.246208-13-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 12/16] main: Update probe output to display device names 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" With capability of selecting any target in the device tree, probe output should display all the nodes with their device tree names. Signed-off-by: Amitay Isaacs --- src/main.c | 27 +- tests/test_selection.sh | 591 +++++++++++++-------------- tests/test_selection2.sh | 838 ++++++++++++++++++++------------------- 3 files changed, 736 insertions(+), 720 deletions(-) diff --git a/src/main.c b/src/main.c index 51e39d9..961d850 100644 --- a/src/main.c +++ b/src/main.c @@ -677,6 +677,7 @@ void print_target(struct pdbg_target *target, int level) int i; struct pdbg_target *next; enum pdbg_target_status status; + char *classname; /* Does this target actually exist? */ status = pdbg_target_status(target); @@ -686,24 +687,14 @@ void print_target(struct pdbg_target *target, int level) for (i = 0; i < level; i++) printf(" "); - if (target) { - char c = 0; - - if (!pdbg_target_class_name(target)) - return; - - if (!strcmp(pdbg_target_class_name(target), "pib")) - c = 'p'; - else if (!strcmp(pdbg_target_class_name(target), "core")) - c = 'c'; - else if (!strcmp(pdbg_target_class_name(target), "thread")) - c = 't'; + classname = pdbg_target_class_name(target); + if (!classname) + return; - if (c) - printf("%c%d: %s\n", c, pdbg_target_index(target), pdbg_target_name(target)); - else - printf("%s\n", pdbg_target_name(target)); - } + printf("%s%d: %s", classname, pdbg_target_index(target), pdbg_target_name(target)); + if (target_selected(target)) + printf(" (*)"); + printf("\n"); pdbg_for_each_child_target(target, next) { print_target(next, level + 1); @@ -714,7 +705,7 @@ static int probe(void) { struct pdbg_target *target; - pdbg_for_each_class_target("pib", target) { + pdbg_for_each_child_target(pdbg_target_root(), target) { print_target(target, 0); } diff --git a/tests/test_selection.sh b/tests/test_selection.sh index 8909796..50db9e4 100755 --- a/tests/test_selection.sh +++ b/tests/test_selection.sh @@ -23,110 +23,111 @@ test_run pdbg -b fake probe test_result 0 < X-Patchwork-Id: 998660 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fR03kJz9sBQ for ; Fri, 16 Nov 2018 12:15:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="VKGRPepD"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fQ4qhYzF3h6 for ; Fri, 16 Nov 2018 12:15:42 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="VKGRPepD"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dN6l2XzF3gv for ; Fri, 16 Nov 2018 12:14:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="VKGRPepD"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dN3JxTz9sBQ; Fri, 16 Nov 2018 12:14:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330888; bh=gtXzxu8r9yyCNCiTmCVy++Gzcy6nr6QGIGWc9wSfhrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VKGRPepDlMdcm/kq+fPeMBNyRVFXZtIjEYulgQzKIFD8GlvlUerGUis4EmGGfXM/V 98E1o3gUaCkTX5XQSCxQ8csY4TsLdgdiqaZY9KHXXMh1nCXZr5I/DF5ZwHauyA5Ebn L/wPbAwJGuzcGAHbpbnCXKbMh+KeXgYFZBP2afavjoHaU+HGh37U7YAOYSimggTQKx Uwg+PJC4n6GicJ9nkE0qk9ZoYwofhkwhyfqaG2IM9zZYHhatGNuiL1el/dBEjb17Xx p+JvbU1ajVsR8gc41k4lJMi7hrNBbNkqRUge3y3RsNUi7UaFInR3xGqRiDJRtZuttk 0REBopt3BgTcQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:28 +1100 Message-Id: <20181116011431.246208-14-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 13/16] libpdbg: Add an api for address translation 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/libpdbg.h | 4 ++++ libpdbg/target.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index f55acf4..44540e4 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -117,6 +117,10 @@ void pdbg_target_priv_set(struct pdbg_target *target, void *priv); struct pdbg_target *pdbg_target_root(void); bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible); +/* Translate an address offset for a target to absolute address in address + * space of a "base" target. */ +struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr); + /* Procedures */ int fsi_read(struct pdbg_target *target, uint32_t addr, uint32_t *val); int fsi_write(struct pdbg_target *target, uint32_t addr, uint32_t val); diff --git a/libpdbg/target.c b/libpdbg/target.c index 1fc8457..af9199d 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -36,6 +36,11 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con return target; } +struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr) +{ + return get_class_target_addr(target, "pib", addr); +} + /* The indirect access code was largely stolen from hw/xscom.c in skiboot */ #define PIB_IND_MAX_RETRIES 10 #define PIB_IND_READ PPC_BIT(0) From patchwork Fri Nov 16 01:14:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998661 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fV2JLxz9sB5 for ; Fri, 16 Nov 2018 12:15:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="txFscgC5"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fV0Fd7zF3h6 for ; Fri, 16 Nov 2018 12:15:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="txFscgC5"; dkim-atps=neutral X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dP2f1PzF3gv for ; Fri, 16 Nov 2018 12:14:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="txFscgC5"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dN6wbQz9sB5; Fri, 16 Nov 2018 12:14:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330889; bh=d9J6FvQkvwwZ1+lgix1JRYQyNznqo87A4kg4BjCTlaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=txFscgC5+03xBkshMbHm7iacq0XUoKyg8PzB2e3TZnUZmYL7k8Qva2XtTfLUSN2A7 xB0Ul4XqQkiuQ15tkINZQ48VWRpM1Dg5P5X3wUlD+0mbktItES+ESnSpAPqjyqbPyS asz/o/KJf//TVw+ginARrBBpCsWmDIBcN9OcYSTQeNKs4yFy/N4MRvR7N6NJt3S4TT QN3ZktSJpnsJW7JrjZV68T9Uf/yxYsaA6A+AbpwaEBVq4C6QMSWNGkIG9+FhT0JOKF Izx41vlG9EAcj7nU2BMunmm8yxugYmB3CE/ZKDt40gbIq1EzCk6YcAycwGDvH4+q3r tR6xrN0CGlRIw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:29 +1100 Message-Id: <20181116011431.246208-15-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 14/16] main: Convert getcfam/putcfam to use path based targeting 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/cfam.c | 48 ++++++++++++++++++++++++++------------------ tests/test_hw_bmc.sh | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/cfam.c b/src/cfam.c index 6dab388..19c2b07 100644 --- a/src/cfam.c +++ b/src/cfam.c @@ -21,39 +21,49 @@ #include "main.h" #include "optcmd.h" +#include "path.h" -static int _getcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused) +static int getcfam(uint32_t addr) { + struct pdbg_target *target; uint32_t value; + int count = 0; - if (fsi_read(target, *addr, &value)) - return 0; + for_each_path_target_class("fsi", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; - printf("p%d:0x%x = 0x%08x\n", index, (uint32_t) *addr, value); + if (fsi_read(target, addr, &value)) { + printf("p%d: failed\n", pdbg_target_index(target)); + continue; - return 1; -} + } -static int getcfam(uint32_t addr) -{ - uint64_t addr64 = addr; + printf("p%d: 0x%x = 0x%08x\n", pdbg_target_index(target), addr, value); + count++; + } - return for_each_target("fsi", _getcfam, &addr64, NULL); + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(getcfam, getcfam, (ADDRESS32)); -static int _putcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data) +static int putcfam(uint32_t addr, uint32_t data) { - if (fsi_write(target, *addr, *data)) - return 0; + struct pdbg_target *target; + int count = 0; - return 1; -} + for_each_path_target_class("fsi", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; -static int putcfam(uint32_t addr, uint32_t data) -{ - uint64_t addr64 = addr, data64 = data; + if (fsi_write(target, addr, data)) { + printf("p%d: failed\n", pdbg_target_index(target)); + continue; + } + + count++; + } - return for_each_target("fsi", _putcfam, &addr64, &data64); + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(putcfam, putcfam, (ADDRESS32, DATA32)); diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh index c35597b..850afd9 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -84,7 +84,7 @@ result_filter () } test_result 0 < X-Patchwork-Id: 998662 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fZ5Zdyz9sB5 for ; Fri, 16 Nov 2018 12:15:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="uxJa5dav"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fZ2RffzF3h9 for ; Fri, 16 Nov 2018 12:15:50 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="uxJa5dav"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dP6Xc1zF3fW for ; Fri, 16 Nov 2018 12:14:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="uxJa5dav"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dP2rGXz9sBQ; Fri, 16 Nov 2018 12:14:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330889; bh=lpHePoomcgxE5+52pRpkQPYixVyC0Jp8WIgYaXUk8pY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uxJa5davZVdBN7AKYCzT2R0PojV76yXBlH6B3WztT5SOTQjc3lps5TUbvab+Gq+8t cOxZhvc8N91PeUyu2f6xW2AdsxeS5d31zCgBhjAMkV5R2I+eUQzXskdJISYiBzVF9o nm/qx+0J9oXIM75WXAnrT7vPn6O+ay+im4dE5KmGUnoKG4WPtn2GKDtbKupxlq8SHk 4Vpm8afnc8pbE1phgzczxboGk2AZHF7i5v9Y/1WstwcuRoW9jdlXI43qSnG7wmNDO/ c+3By26cpjw4iTUy+lU25QCN8xs2CMCSY/tExwCkR0+ZJuSP7v6Hv0G1oRxOzKG4R8 OfGk8ybXJJYQw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:30 +1100 Message-Id: <20181116011431.246208-16-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 15/16] main: Convert getscom/putscom to use path based targeting 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/scom.c | 95 +++++++++++++++++++++++++++++++++++--------- tests/test_hw_bmc.sh | 7 ++-- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/scom.c b/src/scom.c index 2372e91..1f8e6c7 100644 --- a/src/scom.c +++ b/src/scom.c @@ -18,41 +18,100 @@ #include #include #include +#include #include #include "main.h" #include "optcmd.h" +#include "path.h" -static int _getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused) +/* Check if a target has scom region */ +static bool scommable(struct pdbg_target *target) { - uint64_t value; - - if (pib_read(target, *addr, &value)) - return 0; + char *classname; - printf("p%d:0x%" PRIx64 " = 0x%016" PRIx64 "\n", index, *addr, value); + classname = pdbg_target_class_name(target); + if (!strcmp(classname, "pib") || + !strcmp(classname, "core") || + !strcmp(classname, "thread")) + return true; - return 1; + return false; } - int getscom(uint64_t addr) +int getscom(uint64_t addr) { - return for_each_target("pib", _getscom, &addr, NULL); + struct pdbg_target *target; + char *path; + uint64_t value; + int count = 0; + + for_each_path_target(target) { + struct pdbg_target *addr_base; + uint64_t xlate_addr; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!scommable(target)) { + continue; + } + + path = pdbg_target_path(target); + assert(path); + + xlate_addr = addr; + addr_base = pdbg_address_absolute(target, &xlate_addr); + + if (pib_read(target, addr, &value)) { + printf("p%d: 0x%016" PRIx64 " failed (%s)\n", pdbg_target_index(addr_base), xlate_addr, path); + free(path); + continue; + } + + printf("p%d: 0x%016" PRIx64 " = 0x%016" PRIx64 " (%s)\n", pdbg_target_index(addr_base), xlate_addr, value, path); + free(path); + count++; + } + + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(getscom, getscom, (ADDRESS)); -static int _putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data) +int putscom(uint64_t addr, uint64_t data, uint64_t mask) { - if (pib_write(target, *addr, *data)) - return 0; + struct pdbg_target *target; + char *path; + int count = 0; - return 1; -} + for_each_path_target(target) { + struct pdbg_target *addr_base; + uint64_t xlate_addr; - int putscom(uint64_t addr, uint64_t data, uint64_t mask) -{ - /* TODO: Restore the functionality */ - return for_each_target("pib", _putscom, &addr, &data); + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!scommable(target)) { + continue; + } + + path = pdbg_target_path(target); + assert(path); + + xlate_addr = addr; + addr_base = pdbg_address_absolute(target, &xlate_addr); + + /* TODO: Restore the functionality */ + if (pib_write(target, addr, data)) { + printf("p%d: 0x%016" PRIx64 " failed (%s)\n", pdbg_target_index(addr_base), xlate_addr, path); + free(path); + continue; + } + + count++; + } + + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(putscom, putscom, (ADDRESS, DATA, DEFAULT_DATA("0xffffffffffffffff"))); diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh index 850afd9..ab6af35 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -79,8 +79,9 @@ test_wrapper run_over_ssh result_filter () { - sed -E -e 's#0x[[:xdigit:]]{16}#HEX16#' \ - -E -e 's#0x[[:xdigit:]]{8}#HEX8#' + sed -E -e 's#0x[[:xdigit:]]{16}#HEX16#g' \ + -E -e 's#0x[[:xdigit:]]{8}#HEX8#g' \ + -E -e 's#/.*fsi@0/pib@1000#PIB0PATH#' } test_result 0 < X-Patchwork-Id: 998663 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42x0fd4Vg6z9sBQ for ; Fri, 16 Nov 2018 12:15:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (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.b="DN7jvjuI"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42x0fd2Wk6zF3hK for ; Fri, 16 Nov 2018 12:15:53 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DN7jvjuI"; dkim-atps=neutral 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)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42x0dQ2nkVzF3fW for ; Fri, 16 Nov 2018 12:14:50 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (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.b="DN7jvjuI"; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 42x0dP6kB1z9sCQ; Fri, 16 Nov 2018 12:14:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542330890; bh=t5VaZx4a+SFORDboaQKt+eXn5gKqui0Ly3ib72fVMuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DN7jvjuIEgdGKQaIXSIrb5BFbsCR2ae/2BKM+99/kpYu9mhIgOYRPezdnFU25chIf n05LJ2lJzpsXwBjhqCX009xgcsNYLE4x8FUzUhodPNWBpfklLg9yBMBsNSU0pX8OIF 5YrnMfsLu50/mAuIicFjajDbVPZoKlBj28fJNVeb2T52WRfU0jLXe8HMKFuBKd3g4o sDVKbGTDr89+0A8HISxtqolL21Viz1eYSz/OqHBUKCapU1PGUUjt97mKvEMCePPj+A X4hC0cDSgs2gMZ86Bx/+XJfj/fG0UTE1xHlujBmCl/MDUTn+K8L9dKnn89oKttDFbk x8cjhSQ+Jq9sg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 16 Nov 2018 12:14:31 +1100 Message-Id: <20181116011431.246208-17-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116011431.246208-1-amitay@ozlabs.org> References: <20181116011431.246208-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v4 16/16] main: Convert register functions to path based targeting 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/reg.c | 155 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 60 deletions(-) diff --git a/src/reg.c b/src/reg.c index fcf6f4c..8fdb386 100644 --- a/src/reg.c +++ b/src/reg.c @@ -18,11 +18,13 @@ #include #include #include +#include #include #include "main.h" #include "optcmd.h" +#include "path.h" #define REG_CR -5 #define REG_XER -4 @@ -31,14 +33,14 @@ #define REG_NIA -1 #define REG_R31 31 -static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t value, int rc) +static void print_proc_reg(struct pdbg_target *target, int reg, uint64_t *value, int rc) { int proc_index, chip_index, thread_index; thread_index = pdbg_target_index(target); chip_index = pdbg_parent_index(target, "core"); proc_index = pdbg_parent_index(target, "pib"); - printf("p%d:c%d:t%d:", proc_index, chip_index, thread_index); + printf("p%d:c%d:t%d: ", proc_index, chip_index, thread_index); if (reg == REG_MSR) printf("msr: "); @@ -49,145 +51,178 @@ static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t va else if (reg == REG_CR) printf("cr: "); else if (reg > REG_R31) - printf("spr%03" PRIu64 ": ", reg - REG_R31); + printf("spr%03d: ", reg - REG_R31); else if (reg >= 0 && reg <= 31) - printf("gpr%02" PRIu64 ": ", reg); + printf("gpr%02d: ", reg); if (rc == 1) { printf("Check threadstatus - not all threads on this chiplet are quiesced\n"); } else if (rc == 2) printf("Thread in incorrect state\n"); else - printf("0x%016" PRIx64 "\n", value); + printf("0x%016" PRIx64 "\n", *value); } -static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *value) +static int putprocreg(struct pdbg_target *target, int reg, uint64_t *value) { + uint32_t u32; int rc; - if (*reg == REG_MSR) + if (reg == REG_MSR) rc = ram_putmsr(target, *value); - else if (*reg == REG_NIA) + else if (reg == REG_NIA) rc = ram_putnia(target, *value); - else if (*reg == REG_XER) + else if (reg == REG_XER) rc = ram_putxer(target, *value); - else if (*reg == REG_CR) - rc = ram_putcr(target, *value); - else if (*reg > REG_R31) - rc = ram_putspr(target, *reg - REG_R31, *value); - else if (*reg >= 0 && *reg <= 31) - rc = ram_putgpr(target, *reg, *value); - - print_proc_reg(target, *reg, *value, rc); + else if (reg == REG_CR) { + u32 = *value; + rc = ram_putcr(target, u32); + } else if (reg > REG_R31) + rc = ram_putspr(target, reg - REG_R31, *value); + else if (reg >= 0 && reg <= 31) + rc = ram_putgpr(target, reg, *value); + else + assert(0); - return 0; + return rc; } -static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *unused) +static int getprocreg(struct pdbg_target *target, uint32_t reg, uint64_t *value) { + uint32_t u32 = 0; int rc; - uint64_t value; - if (*reg == REG_MSR) - rc = ram_getmsr(target, &value); - else if (*reg == REG_NIA) - rc = ram_getnia(target, &value); - else if (*reg == REG_XER) - rc = ram_getxer(target, &value); - else if (*reg == REG_CR) - rc = ram_getcr(target, (uint32_t *)&value); - else if (*reg > REG_R31) - rc = ram_getspr(target, *reg - REG_R31, &value); - else if (*reg >= 0 && *reg <= 31) - rc = ram_getgpr(target, *reg, &value); + if (reg == REG_MSR) + rc = ram_getmsr(target, value); + else if (reg == REG_NIA) + rc = ram_getnia(target, value); + else if (reg == REG_XER) + rc = ram_getxer(target, value); + else if (reg == REG_CR) { + rc = ram_getcr(target, &u32); + *value = u32; + } else if (reg > REG_R31) + rc = ram_getspr(target, reg - REG_R31, value); + else if (reg >= 0 && reg <= 31) + rc = ram_getgpr(target, reg, value); + else + assert(0); + + return rc; +} + +static int getreg(int reg) +{ + struct pdbg_target *target; + int count = 0; + + for_each_path_target_class("thread", target) { + uint64_t value = 0; + int rc; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + rc = getprocreg(target, reg, &value); + print_proc_reg(target, reg, &value, rc); + + if (!rc) + count++; + } + + return count; +} + +static int putreg(int reg, uint64_t *value) +{ + struct pdbg_target *target; + int count = 0; + + for_each_path_target_class("thread", target) { + int rc; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + rc = putprocreg(target, reg, value); + print_proc_reg(target, reg, value, rc); - print_proc_reg(target, *reg, value, rc); + if (!rc) + count++; + } - return !rc; + return count; } static int getgpr(int gpr) { - uint64_t reg = gpr; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(gpr); } OPTCMD_DEFINE_CMD_WITH_ARGS(getgpr, getgpr, (GPR)); static int putgpr(int gpr, uint64_t data) { - uint64_t reg = gpr; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(gpr, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putgpr, putgpr, (GPR, DATA)); static int getnia(void) { - uint64_t reg = REG_NIA; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_NIA); } OPTCMD_DEFINE_CMD(getnia, getnia); static int putnia(uint64_t nia) { - uint64_t reg = REG_NIA; - return for_each_target("thread", putprocreg, ®, &nia); + return putreg(REG_NIA, &nia); } OPTCMD_DEFINE_CMD_WITH_ARGS(putnia, putnia, (DATA)); static int getspr(int spr) { - uint64_t reg = spr + REG_R31; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(spr + REG_R31); } OPTCMD_DEFINE_CMD_WITH_ARGS(getspr, getspr, (SPR)); static int putspr(int spr, uint64_t data) { - uint64_t reg = spr + REG_R31; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(spr + REG_R31, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putspr, putspr, (SPR, DATA)); static int getmsr(void) { - uint64_t reg = REG_MSR; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_MSR); } OPTCMD_DEFINE_CMD(getmsr, getmsr); static int putmsr(uint64_t data) { - uint64_t reg = REG_MSR; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(REG_MSR, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putmsr, putmsr, (DATA)); static int getxer(void) { - uint64_t reg = REG_XER; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_XER); } OPTCMD_DEFINE_CMD(getxer, getxer); static int putxer(uint64_t data) { - uint64_t reg = REG_XER; - uint64_t d = data; - return for_each_target("thread", putprocreg, ®, &d); + return putreg(REG_XER, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA)); static int getcr(void) { - uint64_t cr = REG_CR; - return for_each_target("thread", getprocreg, &cr, NULL); + return getreg(REG_CR); } OPTCMD_DEFINE_CMD(getcr, getcr); static int putcr(uint32_t data) { - uint64_t cr = REG_CR; - uint64_t d = data; - return for_each_target("thread", putprocreg, &cr, &d); + uint64_t u64 = data; + return putreg(REG_CR, &u64); } OPTCMD_DEFINE_CMD_WITH_ARGS(putcr, putcr, (DATA32));