From patchwork Fri Nov 9 07:09:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995369 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 42rrsC667Nz9s1x for ; Fri, 9 Nov 2018 18:10: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="dULL5Dkg"; 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 42rrs95sx0zF3ZV for ; Fri, 9 Nov 2018 18:10:37 +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="dULL5Dkg"; 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 42rrrv3CcfzF3ZM for ; Fri, 9 Nov 2018 18:10:23 +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="dULL5Dkg"; 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 42rrrv00D2z9sBZ; Fri, 9 Nov 2018 18:10:22 +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=1541747423; bh=9IW6fCIo0FTkyF83Qv/Pdvg07xg9ltbp3PrIF97silw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dULL5Dkgk/4k+JlUYI2y+izHcoh/SV95dx5jL23cfjuag6p0lib5Ece+REjAAxBqI 6x+XBw22FtZVmMyVIQqj2FUs/ZdaKeQ1KTMuBTvb0G7V6lRtyegToKIYo2u9Y06TXW 7/IrAmBcVc+5JTCqMp5AbkFQZ9jEHQ+QJ2HM7P6MJgnspHNUoqG1MnCygyRzHvyRzR hdubZ7+Bu9DOvNnNdegsU4rL9dQvpqvbfC5Ih/Vn6yNPwbiM9FoezejsBT49HEn4+C 6w6ONCQ7M7KUegOuoDekTn939OPEh2l5qUt6hRAFTsz3AtZjTQ9+e5SbNgNWp6srZg w1ojnRF4zmIaw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:09:57 +1100 Message-Id: <20181109071011.253734-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 01/15] 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 9 07:09:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995372 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 42rrsS55V4z9sBZ for ; Fri, 9 Nov 2018 18:10:52 +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="qH9D13FQ"; 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 42rrsS0DpdzF3Zq for ; Fri, 9 Nov 2018 18:10:52 +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="qH9D13FQ"; 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 42rrrv5Gx7zF3ZV for ; Fri, 9 Nov 2018 18:10:23 +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="qH9D13FQ"; 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 42rrrv2rVJz9sBh; Fri, 9 Nov 2018 18:10:23 +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=1541747423; bh=IIo6hPBC9PTuqItr2l+AGwrx/c5ArEyDzIH6NULXwMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qH9D13FQehk6TmCT3iCevJIjJSYjsHvLoALsUDdJqwQWZrcjbf6mWn9TANWIYrs5/ C2yu/Tlr7So1LMyZTrBbZRIz6I/m0kmnZfGhEOxXRRens4AIcsvsVH+7GqukUbaA0g XPmsHCyA43Cp0QeN7w+JYh3BHJINYJ0g7w2v3keOSZgRybzRw0g9zy2+B12J5gSn6O k16rRB8xchPdxVZqZZq217fmNXXLMm2egB6WQ8aeTlgk+IuIO7wODT1z/kFYyXTgfb foc5jBM+fyRgrxMZQORegaHfPB73Gas/nD2P/4sxj9F7tK8D7HpxZOa6TkUgaTY565 DGFAfGB7MYgLw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:09:58 +1100 Message-Id: <20181109071011.253734-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 02/15] 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 9 07:09:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995370 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 42rrsH3Cd2z9sBZ for ; Fri, 9 Nov 2018 18:10: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="vFtsJhca"; 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 42rrsH1B4zzF3bN for ; Fri, 9 Nov 2018 18:10:43 +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="vFtsJhca"; 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 42rrrw2H7HzF3Zb for ; Fri, 9 Nov 2018 18:10:24 +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="vFtsJhca"; 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 42rrrv4lkHz9sC7; Fri, 9 Nov 2018 18:10:23 +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=1541747423; bh=6k8YSK0o3vAL1yz0qeJ17TbGv7WzdPF9cxN5zWjro+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vFtsJhcaRWHkFXxb/Wh5mwQd0kpsqohHyduei800aGupF2FiaOj8VQsI6qlEfToab er1ezHfHK2Xgn6aJYnXr8w6xXkYcWNSyw8WGKlLdfdQdfIKskbNvNJ7hYARQy0KKXG BcFVmJqXycbFFYQNrYvbcu+WGo6uY4FJ4VCgnzoglMiH0mnHjCzLItpMknTUwamV2C 21xjZxydAMR5OHF6sVPry+l9xjaTqYK751+9KSgl/yynbI/AorBZfuzFKqd7nmf98r NdyWWxk9YMP94FzWIrUqAD2VyyXa1xlOYXr9shoG5cV7BX7nJBSAadcjMbzfVWzHga IJUowmzjKzejA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:09:59 +1100 Message-Id: <20181109071011.253734-4-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 03/15] 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 9 07:10:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995368 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 42rrs52Nz5z9sBZ for ; Fri, 9 Nov 2018 18:10:33 +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="HK3+VR3q"; 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 42rrs45WFyzF3Zq for ; Fri, 9 Nov 2018 18:10:32 +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="HK3+VR3q"; 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 42rrrw2hQ1zF3Zc for ; Fri, 9 Nov 2018 18:10:24 +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="HK3+VR3q"; 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 42rrrv6h79z9sCX; Fri, 9 Nov 2018 18:10:23 +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=1541747423; bh=mrWgXav+uddVLDPvRFNawqt982+BZdBD+lI/nw/wbAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HK3+VR3qVOKuzjE+DIOZXur04sbs1BOmivYvi4/hAaMzcmsTiGDOyxbiXBiV7Y9Q6 LUkS3zR34dximO/KygwknVs0Q4fFHEbd0+h9xY3zrMC7ORYJ87k8DF105Tj9BlwUPf soQq7Bk2mXO1ojGuitok0eEG8jHaC8yO88xkehNgAlczp1ZhrUBoAM24rsZ8CAtLVr nBDFJUjg0CUCi3ET/j4sW4TlSb9uFPnoffR9j2PyW/ygxiIqqvU/egGczDcPN1B0/q 0Ti+WvaXTjcyiSJw1qPlY1vPSJqpOBrEc7XU69+fh6uOEeXsMATTPKzk9pJqctQbn7 mGkeiVindCxUw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:00 +1100 Message-Id: <20181109071011.253734-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 04/15] 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 | 109 +++++++++++++++++ 3 files changed, 443 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..c1bdb39 --- /dev/null +++ b/src/path.h @@ -0,0 +1,109 @@ +/* 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 + * + * If only_enabled is true, iterate through targets that are enabled; + * otherwise iterate through all targets + */ +#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 + * + * If only_enabled is true, iterate through targets that are enabled; + * otherwise iterate through all targets + */ +#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 9 07:10:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995373 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 42rrsX0XqVz9s1x for ; Fri, 9 Nov 2018 18:10:56 +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="ZHk/oE5s"; 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 42rrsW5GG8zF3Zq for ; Fri, 9 Nov 2018 18:10: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="ZHk/oE5s"; 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 42rrrx07vgzF3Zd for ; Fri, 9 Nov 2018 18:10:25 +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="ZHk/oE5s"; 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 42rrrw1cd2z9sCm; Fri, 9 Nov 2018 18:10:24 +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=1541747424; bh=ivLuobiU14+uUpUfLx4MbFiaZ4Mbxu/3Sboh5rWBXik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZHk/oE5sCjG2vH7rl5HwZwGYn6LZYJR/n32hr3Z2hRx5Y8AD+5YIzGe5x6EGsu9ep JOQUZEWcjUeODh4sPPxfJjdWZSAQwyOtXp27+gXrOfRPCYIE0H8hdZjdtKnIXoIq8X gfy3njlY91W4KGRnXhh+IW5bOK0QwGfdObexkNlvchZXW7cN4BW1wIKK5L+Q7clJil BvAml+j4sMNrKRI91DUOgTXrh7BJfweWetEvHfvhONHpkTjiTzzPLUDSgMCfefPEbQ DLv/BzApIwUQ9NI3fSB+yH3QOTnoVjRezFFpQTEosreEO8f2JmHATUeO2hxdMuncMF WYy8bQvGqyD+w== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:01 +1100 Message-Id: <20181109071011.253734-6-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 05/15] 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 9 07:10:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995374 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 42rrsb1FbRz9s1x for ; Fri, 9 Nov 2018 18:10: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="kfHfU7k6"; 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 42rrsZ6PkrzF3bR for ; Fri, 9 Nov 2018 18:10:58 +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="kfHfU7k6"; 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 42rrrx08KLzF3Zm for ; Fri, 9 Nov 2018 18:10:25 +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="kfHfU7k6"; 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 42rrrw3ZdSz9sCs; Fri, 9 Nov 2018 18:10:24 +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=1541747424; bh=BTcT4VlO7iZNFP3AVQAxr+Fu9/kMbtEnolJwrdlPn+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kfHfU7k67qMyW03q2ETwXL970bDMKTwsKGlfGrhOKgq9/edHWrqf3iP11YVc781Uz NciSE/FuwupSnYeIkjb5xCohVcM5kgWDbR96Ou2gF2BhBXvlaF7GtUSrmyC7QmaVzT xgLJg6mhWeUwdE2S2mTNgKhl6Fo7cLLCRWOt+G4/F2XkZ2+RTaZxgcGwfp53bFxG+X /QbZfIE3LpZunSM4rG6tVYn93LY8rdTxyruXIOWkDecxe/fhW4g5wfPX21G2zu3xx5 uUqJV43bELIGvJvsPXeNrGIkHsrvhJW+3rzeiN7TpaKdsvPc5y9CFkVgSscT+npQ1R ygMDCJMeBUnNw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:02 +1100 Message-Id: <20181109071011.253734-7-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 06/15] 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 9 07:10:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995375 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 42rrsf0ywgz9sBh for ; Fri, 9 Nov 2018 18:11:02 +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="RUsOgOoi"; 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 42rrsd4tB1zF3Zq for ; Fri, 9 Nov 2018 18:11:01 +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="RUsOgOoi"; 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 42rrrx0FgxzF3Zq for ; Fri, 9 Nov 2018 18:10:25 +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="RUsOgOoi"; 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 42rrrw4sQcz9sCw; Fri, 9 Nov 2018 18:10:24 +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=1541747424; bh=sTLsWbiLUFJ8d/fklwQT8ap6l51kKqA7Q2/La5h+Qes=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RUsOgOoi2Nx2WOrTxUAgzfigpKg5xbiHbiheXT/P3cqJ1YJqWNkRgXmuOXxIEtORI Ef0XN5aEfwLoNe37ipjKZ4EMfEYuI4CzxDHc1iQuUkNUCKr9+NV1IIpsIPrsQFKU7W VEorQgTN2xWfC62rkifdpGXrrvtRAhhZgtKTnYvQfIZAzGJHSfGQ02BMDEhBnENGGl 8V9jjcgrtc9GF7KSC5F3YQUWi1cqkh6mj/225yZyxsflq3yNTXfY7lrE1nkagXc+HW yBRq3pkddyOqoniUZtKl18EKiPahcI6u5iQWibB1JdpbN65lXgD5EfTTGLnjSNnnC8 9c5ONpFD3Zo9w== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:03 +1100 Message-Id: <20181109071011.253734-8-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 07/15] 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" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 72 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index 3e3835c..c72cb73 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,25 @@ 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("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 +512,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 9 07:10:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995376 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 42rrsj0Qd6z9sBh for ; Fri, 9 Nov 2018 18:11:05 +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="OKoJW6ae"; 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 42rrsh5THVzF3Zc for ; Fri, 9 Nov 2018 18:11:04 +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="OKoJW6ae"; 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 42rrrx25vTzF3ZM for ; Fri, 9 Nov 2018 18:10:25 +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="OKoJW6ae"; 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 42rrrw6yH1z9s1x; Fri, 9 Nov 2018 18:10:24 +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=1541747425; bh=5QUfHdTHOuBHnnFvzKJup362/zMooUGchnhyy8Qk20A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OKoJW6aepW/tBZuJFBRk73XA46gsY16BHI9L3zhm8A1kjTnAggEtlzZ53Go7dZ5F4 Kv4FzsBCPhz8E85idubQQrvJKv47vbVmwC4LDnUjSR5Cs8nUYt/K30Hduz6VHVLKEO JcPEBQlPiTZ/m8kzIXyLhFmPoHY7SCy9E4anQZghJ2jAFeIWK4VNoHXHZQ3m0ccqkC CZMyCzCv17Gg3vTefDx/tZFMLldxK28qCnnNWJ8ZTib0lGReBy1LkKzty7EXFDzlFZ MDJlyTi/YI/iqsrLXG+DeldC0S5DT0LUSBDIceRyBnEpxB8Thsy/I2wMxh8pVuiF+K MDF8618SxhjPg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:04 +1100 Message-Id: <20181109071011.253734-9-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 08/15] 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 c72cb73..1a7d610 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]; @@ -523,19 +519,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. */ @@ -554,7 +543,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; @@ -578,7 +566,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; @@ -603,8 +590,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: @@ -671,63 +656,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; } @@ -860,8 +799,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 9 07:10:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 995377 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 42rrsm6W7Hz9sBh for ; Fri, 9 Nov 2018 18:11:08 +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="MSmfSb0j"; 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 42rrsm4Vw8zF3ZV for ; Fri, 9 Nov 2018 18:11:08 +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="MSmfSb0j"; 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 42rrrx3n7YzF3Z3 for ; Fri, 9 Nov 2018 18:10:25 +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="MSmfSb0j"; 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 42rrrx1nshz9sBZ; Fri, 9 Nov 2018 18:10:25 +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=1541747425; bh=TU9zJgPDBZLWrXqh8zP/vhEe7avZcBqgJs2vAIniSh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MSmfSb0jqmvd1WSNdJ/HhhRRueVRZnAEnYoVmZnqJRyDOtFHRdGlY17JpsiSPDFNx xmeB9Q2ZbgWVwg3ZbqRB2XUuXGtnK4fHX4cMsVgCWMCVoMesZLftgZ5FMeCveukflD R5XzVE4cRMM01G1lggknakdlmtYwZvVnrRYM2hb2GowrReWE+EbB73+SUiJcnstJ/L 3kzaWO4Lnkt0XZr/kw4Mb9rnF8piEOxAZvEgR0bqa+DEgQoOlabIJlrc19J11/Xbq3 tsxqFs81Y8RekCfKtcn5yr0s/yKbSFj90XyMFmxQacql32WkhWsSMDq/R5RUygDXtQ 9JxXcZkN7pTbA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:05 +1100 Message-Id: <20181109071011.253734-10-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 09/15] 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 1a7d610..2a11687 100644 --- a/src/main.c +++ b/src/main.c @@ -676,8 +676,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) @@ -706,9 +704,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); } } @@ -718,15 +713,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: 995378 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 42rrsr3gQ5z9s1x for ; Fri, 9 Nov 2018 18:11: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="R+cf4t8s"; 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 42rrsr1YD4zF3bS for ; Fri, 9 Nov 2018 18:11:12 +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="R+cf4t8s"; 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 42rrrx6ysMzF3ZV for ; Fri, 9 Nov 2018 18:10:25 +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="R+cf4t8s"; 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 42rrrx3TpYz9sBh; Fri, 9 Nov 2018 18:10:25 +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=1541747425; bh=vYMkdYRs3ccldd+9eb06ElttIuamgEY1hWm9Yh/AxF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R+cf4t8siveFubeqi9mgYELbhkXqQNr0N/gV0CE6KdIxD8tn3zsmQJ9RM6sgGDDWh Qx320pE4LbmSADRyK6z0LSQBucBln16oTfFzG7CmIyYBxjgLYAk8oYQeeuce4mW/QH iAdQi0iP9Vyrg5bKrYxk3sQ55CzXb6nTCVmpVYf+mnls5LyhPvZcQwM5FuWDqZAC54 J3rxYnsy6kkljyZM8JaDa12Ne4593yFEeRmorXY8kBvsZCFSnUQNNfQOsyMLhWykn2 GAX3bH8YheaHvyKOSrxB1eVun/rC8J3SSmbqeUhTnWPLKhiPtKI/4TPfLqQFBsyCu8 Th+EEiQRh/bRQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:06 +1100 Message-Id: <20181109071011.253734-11-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 10/15] 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: 995379 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 42rrsw0fS6z9s1x for ; Fri, 9 Nov 2018 18:11:16 +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="FriJZ9B2"; 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 42rrsv5qk2zF3ZV for ; Fri, 9 Nov 2018 18:11: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="FriJZ9B2"; 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 42rrry2JD6zF3Z3 for ; Fri, 9 Nov 2018 18:10:26 +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="FriJZ9B2"; 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 42rrrx6fl0z9s1x; Fri, 9 Nov 2018 18:10:25 +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=1541747425; bh=j9pz08qnfWaGDmQDwPwOVeXqDi3s+IuzZx2Z3QqoObk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FriJZ9B2og6/FoBrrv9O9R1S7a8XIBaGPLQFmhTKPlrshG0RbbrpbCpHBBaqJYJgl zfiV628zMzQBxJGQZ+bM9WMXW+DXRURk9HxunV8XYgSiGzsjqRyyKVJgVdNBSPWBYL RW9I74HWCfXl1j7ml4MqtzHLsjrwtwNoC3XYxyMzh/ZEscAPugptM7K9QE1JOGb2+m rx9/7iAC1NGnLKxVHtKUmG70/7Ad7Gpt6bpGq8inptsgjMmlhTNr8TuaK7Y7FNiifF QiK4mozc6uAU1ec4e6FkeVOpiYwjwhMSNYuZ/SVoQybdVa0BBYLg6ijNBFNUCjk0cE h+F3Zt6DtxdtQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:07 +1100 Message-Id: <20181109071011.253734-12-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 11/15] 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 2a11687..77db48e 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); @@ -741,7 +741,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 9 07:10:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 996221 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 42tWdL0RT3z9s7h for ; Mon, 12 Nov 2018 11:21:10 +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="NXz6sdr0"; 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 42tWdK47lYzF3Ql for ; Mon, 12 Nov 2018 11:21:09 +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="NXz6sdr0"; 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 42rrry4SdNzF3ZM for ; Fri, 9 Nov 2018 18:10:26 +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="NXz6sdr0"; 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 42rrry21BSz9sBZ; Fri, 9 Nov 2018 18:10:26 +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=1541747426; bh=2Mfubnr3I4PBzASjkaqbmnyuJtK8imoL8a/hxQUz7O8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NXz6sdr0heIUnBdS04P7QQZhxGTtdX8TbbkN7qqzuUpuigS1iItdrulmvDKefXuxU f6UIBrr7o03ZkrnR/U89TLePPYconobjaXNBFTEWYXWck2bJ4E94KQWxqUFSs+Gzz/ p4iC7faBHJaBNu7vIWBQ2CGIzZLkNBWE2C3h2lXszMIPzApufMlV6QGZfwBzLpo1Rf d8MjWNFQTiJ3a9Dk2+IKUfRoXWfNe8PIO6Qc5aRk5Pwg21/dzrqNIAED79le/fnH3M +qE2/OZF7JfWYn2+nR2uhpcn0Sj3aT3KKGuBc4wHnUwgMH7X+Hiy3fkyDPtK64HWW/ yCV0BBoqF2pEw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:08 +1100 Message-Id: <20181109071011.253734-13-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 12 Nov 2018 11:21:06 +1100 Subject: [Pdbg] [PATCH v2 12/15] 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 | 46 ++- tests/test_selection.sh | 591 +++++++++++++-------------- tests/test_selection2.sh | 838 ++++++++++++++++++++------------------- 3 files changed, 755 insertions(+), 720 deletions(-) diff --git a/src/main.c b/src/main.c index 77db48e..4654f71 100644 --- a/src/main.c +++ b/src/main.c @@ -670,38 +670,43 @@ static bool target_selection(void) return true; } +static void mark_target(struct pdbg_target *target) +{ + while (target && target != pdbg_target_root()) { + pdbg_target_priv_set(target, (void *)1); + target = pdbg_target_parent(NULL, target); + } +} + void print_target(struct pdbg_target *target, int level) { int i; struct pdbg_target *next; enum pdbg_target_status status; + char *classname; + void *priv; /* Does this target actually exist? */ status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) return; + /* Is this target marked for printing */ + priv = pdbg_target_priv(target); + if (!priv) + return; + 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); @@ -712,7 +717,12 @@ static int probe(void) { struct pdbg_target *target; - pdbg_for_each_class_target("pib", target) { + /* Mark all targets and their parents which are selected */ + for_each_path_target(target) { + mark_target(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..8a24a12 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: 995380 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 42rrsz3cG6z9s1x for ; Fri, 9 Nov 2018 18:11:19 +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="IQC5r2z0"; 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 42rrsz1cMszF3Zc for ; Fri, 9 Nov 2018 18:11:19 +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="IQC5r2z0"; 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 42rrry6d4DzF3Z3 for ; Fri, 9 Nov 2018 18:10:26 +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="IQC5r2z0"; 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 42rrry48SSz9sBh; Fri, 9 Nov 2018 18:10:26 +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=1541747426; bh=SmdLib5jOzQx4N7gOg8wJbwszW3ILFzwAPl3iG30T+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQC5r2z0smvbmKc2JCVZVPQqgShWkGP0o614JezYKjLvNGuIstL1CkaYRSGy7Trm3 r6OnvUN/KXUGqd/DmPbl8yTR16RScyBRZ9Ob6HQ0YlLvQDYJAoIyyegifAKrScUJz6 eyGn6FtqwdrPLPpaJoPwuNN7rAK8lcC/b9Oa8BoVHZpWncMRbspYsEge5rKEDLSeX+ rgssUYR8l9+V+kao2gOFOmEMTOvJSPMasD+fiTrAVhl1KPZJt1CKnbJMjplyPENGmG 29K++3G5Xm8x59m4186GavnTNII5sff8Wjos7hEg0P/YA57tErGSqJTE4vurEXgYND STBdCdVPRQ95g== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:09 +1100 Message-Id: <20181109071011.253734-14-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 13/15] 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 --- src/cfam.c | 60 ++++++++++++++++++++++++++++++-------------- tests/test_hw_bmc.sh | 4 +-- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/cfam.c b/src/cfam.c index 6dab388..69b21a4 100644 --- a/src/cfam.c +++ b/src/cfam.c @@ -18,42 +18,64 @@ #include #include #include +#include #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; + char *path; 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); + path = pdbg_target_path(target); + assert(path); - return 1; -} + if (fsi_read(target, addr, &value)) { + printf("%s: failed\n", path); + free(path); + continue; -static int getcfam(uint32_t addr) -{ - uint64_t addr64 = addr; + } + + printf("%s: 0x%x = 0x%08x\n", path, addr, value); + free(path); + 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; + char *path; + 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; + path = pdbg_target_path(target); + assert(path); + + if (fsi_write(target, addr, data)) { + printf("%s: failed\n", path); + free(path); + 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..9bc1deb 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -84,11 +84,11 @@ result_filter () } test_result 0 < X-Patchwork-Id: 995381 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 42rrt23B5bz9s1x for ; Fri, 9 Nov 2018 18:11: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="LcTIgcUH"; 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 42rrt21C5tzF3bS for ; Fri, 9 Nov 2018 18:11:22 +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="LcTIgcUH"; 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 42rrrz1bCrzF3ZM for ; Fri, 9 Nov 2018 18:10:27 +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="LcTIgcUH"; 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 42rrry6LT9z9s1x; Fri, 9 Nov 2018 18:10:26 +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=1541747426; bh=d1qRh74MYhSPKvq08clRKorQzn1EnA5BucC8Jh4n1f8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LcTIgcUHIOC82w+GWPurgeGq39Fcqlvwu3BiSg8NP8QT9Zijj3CquOHm4/+FHvsOe d5UEGTZd8IjC1WHWqwL46BZxKb1t9UhRdJGLMTTx5y1DxTsm1BbFkCrFZD3jz5QQpT BnhfoBKPz2pxJX/DlvVqYXakiMguSiNr57XSxCmNvDyF4MnzTCvqRdPGWIGJqGWKCB yKBo31qgk0M8kjU7w/ibO0YOH1aTh7fkNPyOhWQp8n7JGALJSYp0Diz4Kfnr4oQ92I 4ApiCZmcIjCYCum2gr192CiwWRe+sjaStagJrXVwydMwcFfRYaqewVcmWlQkrPtwfW ziY7dBLdwDQyA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:10 +1100 Message-Id: <20181109071011.253734-15-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 14/15] 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 --- src/scom.c | 87 +++++++++++++++++++++++++++++++++++--------- tests/test_hw_bmc.sh | 2 +- 2 files changed, 70 insertions(+), 19 deletions(-) diff --git a/src/scom.c b/src/scom.c index 2372e91..ad70523 100644 --- a/src/scom.c +++ b/src/scom.c @@ -18,41 +18,92 @@ #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) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + path = pdbg_target_path(target); + assert(path); + + if (!scommable(target)) { + printf("%s: invalid target\n", path); + free(path); + continue; + } + + if (pib_read(target, addr, &value)) { + printf("%s: failed\n", path); + free(path); + continue; + } + + printf("%s: 0x%" PRIx64 " = 0x%016" PRIx64 "\n", path, addr, value); + 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) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; - int putscom(uint64_t addr, uint64_t data, uint64_t mask) -{ - /* TODO: Restore the functionality */ - return for_each_target("pib", _putscom, &addr, &data); + path = pdbg_target_path(target); + assert(path); + + if (!scommable(target)) { + printf("%s: invalid target\n", path); + free(path); + continue; + } + + /* TODO: Restore the functionality */ + if (pib_write(target, addr, data)) { + printf("%s: failed\n", 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 9bc1deb..d656a3f 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -91,7 +91,7 @@ do_skip test_run $PDBG -P fsi getcfam 0xc09 test_result 0 < X-Patchwork-Id: 995382 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 42rrt600PGz9sBZ for ; Fri, 9 Nov 2018 18:11:26 +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="klA4tG3L"; 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 42rrt54pLwzF3c3 for ; Fri, 9 Nov 2018 18:11:25 +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="klA4tG3L"; 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 42rrrz3T68zF3Z3 for ; Fri, 9 Nov 2018 18:10:27 +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="klA4tG3L"; 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 42rrrz1S8fz9sBZ; Fri, 9 Nov 2018 18:10:27 +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=1541747427; bh=nqACUf496TQlYqTh2GF4vYVqRlzgC2i6GdT0fMWZa+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=klA4tG3Lgsa9VHxz1yZOKCxmDNIbYWbdrPO006qglDstPYIUz8SZ9RDXPYx6qln8H DLo3jgJBQoLZMWyu7jbxUQi1aVcUzvxq/UTKuH+oSCGu3o37JFxVpWAVKUW4hhMRGl 4FJvXARD5dQT/srRblyDDBJPDHLJXiStzqoLDwPticJgJ94EUeKklZuAshqZocQ8QN S1oeYj7Vq4uQSXtOqVb7pmZwNhVwMOh0Q9J//mxnDBRXK/Ejv9Pc0h+lqr87BFEdxN +4qoARO06d5X+YOItA9aiAM9GsDRpjN7uujB++QEVEIHg/qAMtF+0bGeJ25XDbCeDI EHNJNkaJumivw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 9 Nov 2018 18:10:11 +1100 Message-Id: <20181109071011.253734-16-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181109071011.253734-1-amitay@ozlabs.org> References: <20181109071011.253734-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 15/15] 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 --- src/reg.c | 151 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 60 deletions(-) diff --git a/src/reg.c b/src/reg.c index fcf6f4c..95f2491 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,174 @@ 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); - 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); + + 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));