From patchwork Thu Nov 15 07:19:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998126 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 42wXmw3fpPz9sCQ for ; Thu, 15 Nov 2018 18:19:44 +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="AzN9sin5"; 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 42wXmw20PXzF3cS for ; Thu, 15 Nov 2018 18:19:44 +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="AzN9sin5"; 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 42wXmn5Hd1zF3bw for ; Thu, 15 Nov 2018 18:19:37 +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="AzN9sin5"; 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 42wXmn2llbz9sCV; Thu, 15 Nov 2018 18:19:37 +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=1542266377; bh=3r1uC1u37OUxE/Xbbrz6u4WN+SYjJ97Kzld+M9hKoMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AzN9sin5BaHJ97g5yz/1r8P+bvzMeuCdjN6G0pdP4OAo9JxpWcJoOuIQ2id3cvI3m 1FvF/k2TBPphY3JxwO529b1QIl08lv0E1aUi88VRQH3cjApgd85GcSyI5at2BnbBTH FLx96VTWEOFWC/Lkz5zHxqNP2R8eZnjPMKUM6XdFRXBTp9ESgiHVxERFkl16iILozd BqRdIs88vs7gkLat05pEWGjEs1wfQd0pM4dGImtjakrmi1N3wXA9Df94Yfx+qFgtti MwiKzXy6JflHWYLUXgVklUvbGpe4uLQvp4rxY/rsPI67smycq6NExuFqk5i0AcEJju +BQ8k3GR3xw3w== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:14 +1100 Message-Id: <20181115071929.206974-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 01/16] libpdbg: Convert printf to DEBUG statements X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/fake.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libpdbg/fake.c b/libpdbg/fake.c index 58e7e18..a816ff5 100644 --- a/libpdbg/fake.c +++ b/libpdbg/fake.c @@ -13,20 +13,22 @@ * see the license for the specific language governing permissions and * limitations under the license. */ -#include "operations.h" #include #include +#include "libpdbg.h" +#include "operations.h" + static int fake_fsi_read(struct fsi *fsi, uint32_t addr, uint32_t *value) { *value = 0xfeed0cfa; - printf("fake_fsi_read(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, *value); + PR_DEBUG("fake_fsi_read(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, *value); return 0; } static int fake_fsi_write(struct fsi *fsi, uint32_t addr, uint32_t value) { - printf("fake_fsi_write(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, value); + PR_DEBUG("fake_fsi_write(0x%04" PRIx32 ", 0x%04" PRIx32 ")\n", addr, value); return 0; } @@ -44,13 +46,13 @@ DECLARE_HW_UNIT(fake_fsi); static int fake_pib_read(struct pib *pib, uint64_t addr, uint64_t *value) { *value = 0xdeadbeef; - printf("fake_pib_read(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, *value); + PR_DEBUG("fake_pib_read(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, *value); return 0; } static int fake_pib_write(struct pib *pib, uint64_t addr, uint64_t value) { - printf("fake_pib_write(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, value); + PR_DEBUG("fake_pib_write(0x%08" PRIx64 ", 0x%08" PRIx64 ")\n", addr, value); return 0; } From patchwork Thu Nov 15 07:19:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998129 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 42wXn82L9rz9sBQ for ; Thu, 15 Nov 2018 18:19: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="KEb5mmE8"; 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 42wXn801SRzF3cT for ; Thu, 15 Nov 2018 18:19:56 +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="KEb5mmE8"; 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 42wXmp2W9zzF3by for ; Thu, 15 Nov 2018 18:19:38 +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="KEb5mmE8"; 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 42wXmn4rXQz9sCm; Thu, 15 Nov 2018 18:19:37 +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=1542266377; bh=IIo6hPBC9PTuqItr2l+AGwrx/c5ArEyDzIH6NULXwMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KEb5mmE81hhM862klLi5HQpgadZ9MhUZ0RMZtwN9Px1V5TfaxqkE9hZJGNog6Lsyz 6RL5R/Bw1n+B17EHkj49PUOYCLXLjk5BvUyWBPOwrfLQnVT+mT4vCPMzw5ici1ru8g 4SBFPnEWJXpFVyLBWdZWIq5I+KnrhFfWfy3lQKXSTCWnr5v8Cr6k1PDKJzoWmKuPt5 vK5+I88pQymz6O7vAPstSkNr5tc0cZhvLO+LQiwzeNCK5v1kzqonEJg//pRelExG9n 3wFygctwm9SFY0+FViY6GAghINH8e2cvoNWT0/LSG3R9TtK3uDUibdIyee2ZTwPl6x jSrs1qcLokSHQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:15 +1100 Message-Id: <20181115071929.206974-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 02/16] main: Convert target_selection() to return a boolean X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 5d0c0e3..6ad869d 100644 --- a/src/main.c +++ b/src/main.c @@ -600,7 +600,7 @@ void for_each_target_release(char *class) } } -static int target_selection(void) +static bool target_selection(void) { struct pdbg_target *fsi, *pib, *chip, *thread; @@ -613,7 +613,7 @@ static int target_selection(void) case FSI: if (device_node == NULL) { PR_ERROR("FSI backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_fsi_dtb_o_start); @@ -625,14 +625,14 @@ static int target_selection(void) pdbg_targets_init(&_binary_p9z_fsi_dtb_o_start); else { PR_ERROR("Invalid device type specified\n"); - return -1; + return false; } break; case KERNEL: if (device_node == NULL) { PR_ERROR("kernel backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_kernel_dtb_o_start); @@ -646,7 +646,7 @@ static int target_selection(void) case HOST: if (device_node == NULL) { PR_ERROR("Host backend requires a device type\n"); - return -1; + return false; } if (!strcmp(device_node, "p8")) pdbg_targets_init(&_binary_p8_host_dtb_o_start); @@ -654,7 +654,7 @@ static int target_selection(void) pdbg_targets_init(&_binary_p9_host_dtb_o_start); else { PR_ERROR("Unsupported device type for host backend\n"); - return -1; + return false; } break; #endif @@ -667,7 +667,7 @@ static int target_selection(void) /* parse_options deals with parsing user input, so it should be * impossible to get here */ assert(0); - return -1; + return false; } /* At this point we should have a device-tree loaded. We want @@ -722,7 +722,7 @@ static int target_selection(void) target_unselect(fsi); } - return 0; + return true; } void print_target(struct pdbg_target *target, int level) @@ -814,7 +814,7 @@ int main(int argc, char *argv[]) device_node = default_target(backend); /* Disable unselected targets */ - if (target_selection()) + if (!target_selection()) return 1; atexit(atexit_release); From patchwork Thu Nov 15 07:19:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998127 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 42wXn05WYJz9sBQ for ; Thu, 15 Nov 2018 18:19:48 +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="EoQO4w8k"; 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 42wXn02gDfzF3bw for ; Thu, 15 Nov 2018 18:19:48 +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="EoQO4w8k"; 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 42wXmp3wzKzF3c2 for ; Thu, 15 Nov 2018 18:19:38 +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="EoQO4w8k"; 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 42wXmp0PtGz9sCw; Thu, 15 Nov 2018 18:19:38 +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=1542266378; bh=6k8YSK0o3vAL1yz0qeJ17TbGv7WzdPF9cxN5zWjro+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EoQO4w8kpED36OpBd5TdT3I3iapfTGiC9O2lYKugteFyaGLSYp+iVgIPzUj8AMqE8 QpRBtCHTibi16xGg2Zsnk9kPFzqaOixCTAxFLQEAtjsZVKQV7KDZTenj/2RPUiNwea UlWMoUqDjqemmAKSsDl8b/6fBIuZcj4ABaHi9igXOc98d4sgvtiranHrh7RJbZv8/e 6PkaMIDU/6AwZy2liGENM1uh+sbqLri8W3ERh9dxedv4y8LEZEkGmzefyBfI7WRs6M onzf/gdbXUWV20CMUfsstMP+yVEomdb7oVIf7MtCwnZeI4ljJRo2wpNFN2lzvNIrjx 1eXl21CVnZCfw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:16 +1100 Message-Id: <20181115071929.206974-4-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 03/16] util: Move parse_list() into a separate file X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" ... and document the function. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- Makefile.am | 4 ++- src/main.c | 74 +---------------------------------------- src/util.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 34 +++++++++++++++++++ 4 files changed, 133 insertions(+), 74 deletions(-) create mode 100644 src/util.c create mode 100644 src/util.h diff --git a/Makefile.am b/Makefile.am index b8f38ca..c8f100e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,7 +85,9 @@ pdbg_SOURCES = \ src/reg.c \ src/ring.c \ src/scom.c \ - src/thread.c + src/thread.c \ + src/util.c \ + src/util.h if TARGET_ARM pdbg_SOURCES += src/options_arm.c diff --git a/src/main.c b/src/main.c index 6ad869d..fd77f6d 100644 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ #include "optcmd.h" #include "progress.h" #include "pdbgproxy.h" +#include "util.h" #define PR_ERROR(x, args...) \ pdbg_log(PDBG_ERROR, x, ##args) @@ -180,79 +181,6 @@ static void print_usage(char *pname) printf(" %-15s %-27s %s\n", actions[i].name, actions[i].args, actions[i].desc); } -/* Parse argument of the form 0-5,7,9-11,15,17 */ -static bool parse_list(const char *arg, int max, int *list, int *count) -{ - char str[strlen(arg)+1]; - char *tok, *tmp, *saveptr = NULL; - int i; - - assert(max < INT_MAX); - - strcpy(str, arg); - - tmp = str; - while ((tok = strtok_r(tmp, ",", &saveptr)) != NULL) { - char *a, *b, *endptr, *saveptr2 = NULL; - unsigned long int from, to; - - a = strtok_r(tok, "-", &saveptr2); - if (a == NULL) { - return false; - } else { - endptr = NULL; - from = strtoul(a, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid value %s\n", a); - return false; - } - if (from >= max) { - fprintf(stderr, "Value %s larger than max %d\n", a, max-1); - return false; - } - } - - b = strtok_r(NULL, "-", &saveptr2); - if (b == NULL) { - to = from; - } else { - endptr = NULL; - to = strtoul(b, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid value %s\n", b); - return false; - } - if (to >= max) { - fprintf(stderr, "Value %s larger than max %d\n", b, max-1); - return false; - } - } - - if (from > to) { - fprintf(stderr, "Invalid range %s-%s\n", a, b); - return false; - } - - for (i = from; i <= to; i++) - list[i] = 1; - - tmp = NULL; - }; - - if (count != NULL) { - int n = 0; - - for (i = 0; i < max; i++) { - if (list[i] == 1) - n++; - } - - *count = n; - } - - return true; -} - #ifdef TARGET_PPC int get_pir(int linux_cpu) { diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..3a4520d --- /dev/null +++ b/src/util.c @@ -0,0 +1,95 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include + +/* Parse argument of the form 0-5,7,9-11,15,17 */ +bool parse_list(const char *arg, int max, int *list, int *count) +{ + char str[strlen(arg)+1]; + char *tok, *tmp, *saveptr = NULL; + int i; + + assert(max < INT_MAX); + + strcpy(str, arg); + + tmp = str; + while ((tok = strtok_r(tmp, ",", &saveptr)) != NULL) { + char *a, *b, *endptr, *saveptr2 = NULL; + unsigned long int from, to; + + a = strtok_r(tok, "-", &saveptr2); + if (a == NULL) { + return false; + } else { + endptr = NULL; + from = strtoul(a, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr, "Invalid value %s\n", a); + return false; + } + if (from >= max) { + fprintf(stderr, "Value %s larger than max %d\n", a, max-1); + return false; + } + } + + b = strtok_r(NULL, "-", &saveptr2); + if (b == NULL) { + to = from; + } else { + endptr = NULL; + to = strtoul(b, &endptr, 0); + if (*endptr != '\0') { + fprintf(stderr, "Invalid value %s\n", b); + return false; + } + if (to >= max) { + fprintf(stderr, "Value %s larger than max %d\n", b, max-1); + return false; + } + } + + if (from > to) { + fprintf(stderr, "Invalid range %s-%s\n", a, b); + return false; + } + + for (i = from; i <= to; i++) + list[i] = 1; + + tmp = NULL; + }; + + if (count != NULL) { + int n = 0; + + for (i = 0; i < max; i++) { + if (list[i] == 1) + n++; + } + + *count = n; + } + + return true; +} + diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000..131e3f9 --- /dev/null +++ b/src/util.h @@ -0,0 +1,34 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __UTIL_H +#define __UTIL_H + +/** + * @brief Parse a range or a list of numbers from a string into an array + * + * For each number present in the string, set the corresponding list element + * to 1. The list acts as the index flags. The range of valid numbers varies + * from 0 to sizeof(list)-1. + * + * @param[in] arg String to parse + * @param[in] max The size of the list + * @param[in] list The list of flags + * @param[out] count Optional count of distinct numbers found + * @return true on success, false on error + */ +bool parse_list(const char *arg, int max, int *list, int *count); + +#endif From patchwork Thu Nov 15 07:19:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998130 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 42wXnD55Swz9sCm for ; Thu, 15 Nov 2018 18:20:00 +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="DiUyfGCq"; 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 42wXnD2vdkzF3cX for ; Thu, 15 Nov 2018 18:20:00 +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="DiUyfGCq"; 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 42wXmp5DkzzF3c9 for ; Thu, 15 Nov 2018 18:19:38 +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="DiUyfGCq"; 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 42wXmp2h4Cz9sDF; Thu, 15 Nov 2018 18:19:38 +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=1542266378; bh=cOfCkf2jxTLeCiZTxLXmigsLeV+otMwL+y/atMOgMT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DiUyfGCqXm3FTIul4z80NtJD8NdEM7VB1O++jJZGZqcfbmuQFqh4jnm0I97t4tGNZ oKcmCP6kwOg+ovDsbNnLVJi+raLIR7SX4j+SDSqzuqkUAYxu3pz7hi7yG0GozC3v8F i0ZN0vJ8VtSbQAOjOFm6I6c0yRxHQuuNUqtK5eQ3OwYd/hal6DiYfg9M8ROpjiKche AOKDfTfPlsyFBOE7A45O8L45izvZWEXzBS9wfrHqFRE33xclB1DseIEkY+tRRfnyoU Z7jJP+mBMae60iODw2BeSJCI7KOatVmet0HrdWkREihGWaTaMsE/m7oa8JkU4Yfy9r al96adlIvyH2g== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:17 +1100 Message-Id: <20181115071929.206974-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 04/16] path: Add device tree path based targeting X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- Makefile.am | 2 + src/path.c | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/path.h | 103 ++++++++++++++++ 3 files changed, 437 insertions(+) create mode 100644 src/path.c create mode 100644 src/path.h diff --git a/Makefile.am b/Makefile.am index c8f100e..2a687ca 100644 --- a/Makefile.am +++ b/Makefile.am @@ -78,6 +78,8 @@ pdbg_SOURCES = \ src/options.h \ src/parsers.c \ src/parsers.h \ + src/path.c \ + src/path.h \ src/pdbgproxy.c \ src/pdbgproxy.h \ src/progress.c \ diff --git a/src/path.c b/src/path.c new file mode 100644 index 0000000..6b4e29b --- /dev/null +++ b/src/path.c @@ -0,0 +1,332 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "path.h" +#include "util.h" + +#define MAX_PATH_COMP_LEN 32 +#define MAX_PATH_COMPONENTS 16 +#define MAX_PATH_LEN (MAX_PATH_COMP_LEN * MAX_PATH_COMPONENTS) + +/* This is max(MAX_PROCESSORS, MAX_CHIPS, MAX_THREADS) */ +#define MAX_PATH_INDEX 64 + +struct path_pattern { + char prefix[MAX_PATH_COMP_LEN]; + int index[MAX_PATH_INDEX]; + bool match_full; + bool match_index; +}; + +/* Start with max threads, rather than defining arbitrary number */ +#define MAX_TARGETS (64 * 24 * 8) + +static struct pdbg_target *path_target[MAX_TARGETS]; +static unsigned int path_target_count; + +static void safe_strcpy(char *dest, size_t n, const char *src) +{ + assert(strlen(src) + 1 <= n); + + strcpy(dest, src); +} + +/* + * Parse string components of following forms: + * pib0 + * core[1-3,11-13] + * thread* + * adu@123000 + */ +static bool path_pattern_parse(const char *arg, struct path_pattern *pat) +{ + char tmp[strlen(arg)+1]; + char *tok; + bool ok; + + safe_strcpy(tmp, sizeof(tmp), arg); + + memset(pat, 0, sizeof(*pat)); + + if (strchr(tmp, '@')) { + safe_strcpy(pat->prefix, sizeof(pat->prefix), tmp); + pat->match_full = true; + + } else if (strchr(tmp, '*')) { + tok = strtok(tmp, "*"); + if (!tok) + safe_strcpy(pat->prefix, sizeof(pat->prefix), "all"); + else + safe_strcpy(pat->prefix, sizeof(pat->prefix), tok); + + } else if (strchr(tmp, '[')) { + tok = strtok(tmp, "["); + if (tok == NULL) { + fprintf(stderr, "Invalid pattern '%s'\n", arg); + return false; + } + safe_strcpy(pat->prefix, sizeof(pat->prefix), tok); + + tok = strtok(NULL, "]"); + if (!tok) { + fprintf(stderr, "Invalid pattern '%s'\n", arg); + return false; + } + + ok = parse_list(tok, MAX_PATH_INDEX, pat->index, NULL); + if (!ok) + return false; + + pat->match_index = true; + + } else { + size_t n = strlen(tmp) - 1; + while (n >= 0 && isdigit(tmp[n])) + n--; + n++; + + if (n != strlen(tmp)) { + int index; + + index = atoi(&tmp[n]); + if (index < 0 || index >= MAX_PATH_INDEX) { + fprintf(stderr, "Invalid index '%s'\n", &tmp[n]); + return false; + } + tmp[n] = '\0'; + pat->index[index] = 1; + pat->match_index = true; + } + + safe_strcpy(pat->prefix, sizeof(pat->prefix), tmp); + } + + if (!pat->prefix) + return false; + + return true; +} + +static int path_pattern_split(const char *arg, struct path_pattern *pats) +{ + char arg_copy[MAX_PATH_LEN]; + char *tmp, *tok, *saveptr = NULL; + int n; + bool ok; + + safe_strcpy(arg_copy, sizeof(arg_copy), arg); + + tmp = arg_copy; + n = 0; + while ((tok = strtok_r(tmp, "/", &saveptr))) { + size_t len = strlen(tok); + + if (len == 0) + continue; + + if (len >= MAX_PATH_LEN) { + fprintf(stderr, "Pattern component '%s' too long\n", tok); + return -1; + } + + ok = path_pattern_parse(tok, &pats[n]); + if (!ok) + return -1; + + n++; + assert(n <= MAX_PATH_COMPONENTS); + + tmp = NULL; + } + + return n; +} + +static int path_target_find(struct pdbg_target *prev) +{ + int i; + + if (!prev) + return -1; + + for (i=0; i= 0) + return true; + + if (path_target_count == MAX_TARGETS) + return false; + + path_target[path_target_count] = target; + path_target_count++; + return true; +} + +static void path_pattern_match(struct pdbg_target *target, + struct path_pattern *pats, + int max_levels, + int level) +{ + struct pdbg_target *child; + char comp_name[MAX_PATH_COMP_LEN]; + char *tok; + int next = level; + bool found = false; + + if (target == pdbg_target_root()) { + goto end; + } + + if (!strcmp("all", pats[level].prefix)) { + if (!path_target_add(target)) + return; + goto end; + } + + safe_strcpy(comp_name, sizeof(comp_name), pdbg_target_class_name(target)); + if (pats[level].match_full) { + tok = comp_name; + } else { + tok = strtok(comp_name, "@"); + } + + if (!strcmp(tok, pats[level].prefix)) { + found = true; + + if (pats[level].match_index) { + int index = pdbg_target_index(target); + + if (pats[level].index[index] != 1) + found = false; + } + } + + if (found) { + if (level == max_levels-1) { + path_target_add(target); + return; + } else { + next = level + 1; + } + } + +end: + pdbg_for_each_child_target(target, child) { + path_pattern_match(child, pats, max_levels, next); + } +} + +bool path_target_parse(const char **arg, int arg_count) +{ + struct path_pattern pats[MAX_PATH_COMPONENTS]; + int i, n; + + for (i=0; i 0); +} + +bool path_target_selected(struct pdbg_target *target) +{ + int index; + + index = path_target_find(target); + if (index >= 0) + return true; + + return false; +} + +void path_target_dump(void) +{ + struct pdbg_target *target; + char *path; + + for_each_path_target(target) { + path = pdbg_target_path(target); + assert(path); + printf("%s\n", path); + free(path); + } +} + +struct pdbg_target *path_target_next(struct pdbg_target *prev) +{ + int index; + + index = path_target_find(prev); + return path_target_find_next(NULL, index); +} + +struct pdbg_target *path_target_next_class(const char *klass, + struct pdbg_target *prev) +{ + int index; + + index = path_target_find(prev); + return path_target_find_next(klass, index); +} diff --git a/src/path.h b/src/path.h new file mode 100644 index 0000000..c3c20c0 --- /dev/null +++ b/src/path.h @@ -0,0 +1,103 @@ +/* Copyright 2018 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __PDBG_PATH_H +#define __PDBG_PATH_H + +#include + +/** + * @brief Parse a list of path target strings + * + * @param[in] arg An array of strings + * @param[in] arg_count The number of strings + * @return true on success, false on error + */ +bool path_target_parse(const char **arg, int arg_count); + +/** + * @brief Check if there are any path targets + * + * @return true if number of path targets > 0, false otherwise + */ +bool path_target_present(void); + +/** + * @brief Add a target to the list + * + * @param[in] target pdbg target + * @return true on success, false on error + */ +bool path_target_add(struct pdbg_target *target); + +/** + * @brief Check if the specified target is selected + * + * @param[in] target pdbg target + * @return true if the target is selected, false otherwise + */ +bool path_target_selected(struct pdbg_target *target); + +/** + * @brief Print the list of path targets to stdout + */ +void path_target_dump(void); + +/** + * @brief Iterator for list of path targets + * + * @param[in] prev The last pdbg target + * @return the next pdbg target in the list, NULL otherwise + * + * If prev is NULL, then return the first pdbg target in the list. + * If there are no more pdbg targets in the list, NULL is returned. + */ +struct pdbg_target *path_target_next(struct pdbg_target *prev); + +/** + * @brief Iterator for a list of path targets of specified class + * + * @param[in] klass The class of the targets required + * @param[in] prev The last pdbg target + * @return the next matching pdbg target in the list, NULL otherwise + * + * If prev is NULL, then return the first matching pdbg target in the list. + * If there are no more matching pdbg targets, NULL is returned. + */ +struct pdbg_target *path_target_next_class(const char *klass, + struct pdbg_target *prev); + +/** + * @brief Macro for iterating through all path targets + * + * target is of type struct pdbg_target + */ +#define for_each_path_target(target) \ + for (target = path_target_next(NULL); \ + target; \ + target = path_target_next(target)) + +/** + * @brief Macro for iterating through all path targets of specific class + * + * class is of type char * + * target is of type struct pdbg_target + */ +#define for_each_path_target_class(class, target) \ + for (target = path_target_next_class(class, NULL); \ + target; \ + target = path_target_next_class(class, target)) + +#endif From patchwork Thu Nov 15 07:19:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998131 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 42wXnJ6bmwz9sCV for ; Thu, 15 Nov 2018 18:20:04 +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="cuU/9emg"; 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 42wXnJ4PYYzF3cX for ; Thu, 15 Nov 2018 18:20: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="cuU/9emg"; 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 42wXmq01v0zF3bw for ; Thu, 15 Nov 2018 18:19:39 +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="cuU/9emg"; 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 42wXmp4cMzz9sDG; Thu, 15 Nov 2018 18:19:38 +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=1542266378; bh=+khe80mifXYHzk5RTiOKTmMjMEUfQKPJldjLcn1pKWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cuU/9emgjls5TgCVG9LCtqRCExyUoGOjY993DFVYrUPM/ZwQ1/CiCKCa/gY/TWkjq fxXkkxGSTTuqY+z35BsUhPKXFY246lgfPSQUcmpbHC6+wl7sTUNnbTtGbkLh9gN7Pd LHYm3FQUmvPLKswrcUQunU2G1RW1G5QvKy8xEk8wlDCooergN/9chGbbQYhjR8abLk LEGMj9mASuzieBJ6RmZyfyQ9wZhmGN/nZnG4c2OzubxyHXO/abwCv1jZx4X3zXxPKP G4YaOaupzM+Z8Wt9LeozvzJJfd4HOgQjLQRGxrftuDo9/jCsp0jwafC355gQ+ECKcn ttMiCPRMhNWAA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:18 +1100 Message-Id: <20181115071929.206974-6-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 05/16] main: Add an option for path based targetting X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index fd77f6d..9252eb3 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ #include "progress.h" #include "pdbgproxy.h" #include "util.h" +#include "path.h" #define PR_ERROR(x, args...) \ pdbg_log(PDBG_ERROR, x, ##args) @@ -78,6 +79,11 @@ static int **processorsel[MAX_PROCESSORS]; static int *chipsel[MAX_PROCESSORS][MAX_CHIPS]; static int threadsel[MAX_PROCESSORS][MAX_CHIPS][MAX_THREADS]; +#define MAX_PATH_ARGS 16 + +static const char *pathsel[MAX_PATH_ARGS]; +static int pathsel_count; + static int probe(void); /* TODO: We are repeating ourselves here. A little bit more macro magic could @@ -153,6 +159,7 @@ static void print_usage(char *pname) #ifdef TARGET_PPC printf("\t-l, --cpu=<0-%d>||\n", MAX_PROCESSORS-1); #endif + printf("\t-P, --path=\n"); printf("\t-a, --all\n"); printf("\t\tRun command on all possible processors/chips/threads (default)\n"); printf("\t-b, --backend=backend\n"); @@ -243,6 +250,36 @@ void pir_map(int pir, int *chip, int *core, int *thread) {} #define PPC_OPTS #endif +static bool pathsel_add(char *format, ...) __attribute__((format (printf, 1, 2))); + +static bool pathsel_add(char *format, ...) +{ + va_list ap; + char path[1024]; + int len; + + va_start(ap, format); + + len = vsnprintf(path, sizeof(path), format, ap); + if (len > sizeof(path)) { + va_end(ap); + return false; + } + + va_end(ap); + + if (pathsel_count == MAX_PATH_ARGS) { + fprintf(stderr, "Too many path arguments\n"); + return false; + } + + pathsel[pathsel_count] = strdup(path); + assert(pathsel[pathsel_count]); + pathsel_count++; + + return true; +} + static bool parse_options(int argc, char *argv[]) { int c; @@ -266,6 +303,7 @@ static bool parse_options(int argc, char *argv[]) {"cpu", required_argument, NULL, 'l'}, #endif {"debug", required_argument, NULL, 'D'}, + {"path", required_argument, NULL, 'P'}, {"shutup", no_argument, NULL, 'S'}, {"version", no_argument, NULL, 'V'}, {NULL, 0, NULL, 0} @@ -278,7 +316,7 @@ static bool parse_options(int argc, char *argv[]) memset(l_list, 0, sizeof(l_list)); do { - c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:SV" PPC_OPTS, + c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:P:SV" PPC_OPTS, long_opts, NULL); if (c == -1) break; @@ -364,6 +402,11 @@ static bool parse_options(int argc, char *argv[]) fprintf(stderr, "Invalid slave address '%s'\n", optarg); break; + case 'P': + if (!pathsel_add("%s", optarg)) + opt_error = true; + break; + case 'S': progress_shutup(); break; @@ -650,6 +693,11 @@ static bool target_selection(void) target_unselect(fsi); } + if (pathsel_count) { + if (!path_target_parse(pathsel, pathsel_count)) + return false; + } + return true; } From patchwork Thu Nov 15 07:19:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998132 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 42wXnP2j0Jz9sCm for ; Thu, 15 Nov 2018 18:20:09 +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="an6sTVnn"; 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 42wXnN6X4SzF3cH for ; Thu, 15 Nov 2018 18:20: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="an6sTVnn"; 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 42wXmq3HTGzF3b3 for ; Thu, 15 Nov 2018 18:19:39 +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="an6sTVnn"; 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 42wXmp6kLnz9sCQ; Thu, 15 Nov 2018 18:19:38 +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=1542266379; bh=j/LnJ7Vl7/PrcQySeuamVZHzIdQHpcNHoTYJG/+dd4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=an6sTVnnr2biQhiL+8ldE1w+3YXkjIGZmlAycOhj6mZA+beD8VvOYLeCK1TfJeuai llm9pLY15WbqfzvALi4FTAgbP1eCRzamWJX5aFVPsYWJw7eqeoQjnLO9gyZCPTDSXl juo50rF+OBFRUcMW5/MaQAhdEl4jADcCynmcOunfRLa1YihBXQ/xs8A3Ku4bk7Pe0/ vasAoTt62wI1Hqm081pidsETgyWFtp0FMWgesec2l8VwAG7ondW38LjIuRocDSNERn g5hBmf1EkMypA1HQZNSaXu434OY1KGziXa9Fu62wmcjsQ6/TsllOHjkefvmhxbmm6o yE4zh5hNyzubw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:19 +1100 Message-Id: <20181115071929.206974-7-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 06/16] main: Add explicit probing of selected targets X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.c b/src/main.c index 9252eb3..3e3835c 100644 --- a/src/main.c +++ b/src/main.c @@ -775,6 +775,7 @@ int main(int argc, char *argv[]) int i, rc = 0; void **args, **flags; optcmd_cmd_t *cmd; + struct pdbg_target *target; backend = default_backend(); @@ -793,6 +794,11 @@ int main(int argc, char *argv[]) if (!target_selection()) return 1; + /* Probe all selected targets */ + for_each_path_target(target) { + pdbg_target_probe(target); + } + atexit(atexit_release); for (i = 0; i < ARRAY_SIZE(cmds); i++) { From patchwork Thu Nov 15 07:19:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998133 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 42wXnS5lFbz9sCQ for ; Thu, 15 Nov 2018 18:20: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="sWd6SQrp"; 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 42wXnS3ZFXzF3ch for ; Thu, 15 Nov 2018 18:20: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="sWd6SQrp"; 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 42wXmq5thczF3bw for ; Thu, 15 Nov 2018 18:19:39 +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="sWd6SQrp"; 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 42wXmq2Yxsz9sCV; Thu, 15 Nov 2018 18:19:39 +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=1542266379; bh=uuMKYGfRvfH42a8KKdC7FuO7XyBnanzph5UryTOCJvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sWd6SQrpVgh1IPvD6JRo1CfiCBqDnwzIQBbBcX1FEPtWSOdxfLvu1TqKSUz9GCICP 8+Y0sYGLVYMzHWLIDcKIofbDmrJ317A2JizK9GsfwPP1dFa2EVNraWygSoNgEgdZw3 5HqyMwVJs3/AK/AY+xUEanS9BUyDaouQfs8MH1FA5ZhBfLgV6WZ2ZMwHmNxE5Vdv2z j4bG/6zr9uC2tsk6O+xvctQ1wQ1Mrm5EtCYj2U1FhYE54oxwK7i3l99w7g1tK5DFBS zfKPpJbc5mvpg19xOAZHFqWstXqj0bucQ0HKDnLTvYbOLvS3THLt98YXNauV1IGVhU 7QwDiSibicSdQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:20 +1100 Message-Id: <20181115071929.206974-8-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 07/16] main: Convert -p/-c/-t/-a/-l to path based targets X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" To maintain the compatibility with the old selection where -p selected processor, add fsi and pib targets with matching index. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 74 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main.c b/src/main.c index 3e3835c..506e0b9 100644 --- a/src/main.c +++ b/src/main.c @@ -280,6 +280,26 @@ static bool pathsel_add(char *format, ...) return true; } +static bool list_to_string(int *list, int max, char *str, size_t len) +{ + char tmp[16]; + int i; + + memset(str, 0, len); + + for (i=0; i len) { + return false; + } + strcat(str, tmp); + } + } + + return true; +} + static bool parse_options(int argc, char *argv[]) { int c; @@ -289,7 +309,7 @@ static bool parse_options(int argc, char *argv[]) int t_list[MAX_THREADS]; int l_list[MAX_LINUX_CPUS]; int p_count = 0, c_count = 0, t_count = 0, l_count = 0; - int i, j, k; + int i; struct option long_opts[] = { {"all", no_argument, NULL, 'a'}, {"backend", required_argument, NULL, 'b'}, @@ -309,6 +329,7 @@ static bool parse_options(int argc, char *argv[]) {NULL, 0, NULL, 0} }; char *endptr; + char p_str[256], c_str[256], t_str[256]; memset(p_list, 0, sizeof(p_list)); memset(c_list, 0, sizeof(c_list)); @@ -437,6 +458,16 @@ static bool parse_options(int argc, char *argv[]) return false; } + if (pathsel_count > 0 && l_count > 0) { + fprintf(stderr, "Can't mix -l with -P\n"); + return false; + } + + if ((c_count > 0 || t_count > 0 || p_count > 0) && (pathsel_count > 0)) { + fprintf(stderr, "Can't mix -P with -p/-c/-t/-a\n"); + return false; + } + if ((c_count > 0 || t_count > 0) && p_count == 0) { fprintf(stderr, "No processor(s) selected\n"); fprintf(stderr, "Use -p or -a to select processor(s)\n"); @@ -449,25 +480,27 @@ static bool parse_options(int argc, char *argv[]) return false; } - for (i = 0; i < MAX_PROCESSORS; i++) { - if (p_list[i] == 0) - continue; - - processorsel[i] = &chipsel[i][0]; - - for (j = 0; j < MAX_CHIPS; j++) { - if (c_list[j] == 0) - continue; - - chipsel[i][j] = &threadsel[i][j][0]; + if (p_count) { + if (!list_to_string(p_list, MAX_PROCESSORS, p_str, sizeof(p_str))) + return false; + if (!pathsel_add("fsi[%s]", p_str)) + return false; + if (!pathsel_add("pib[%s]", p_str)) + return false; + } - for (k = 0; k < MAX_THREADS; k++) { - if (t_list[k] == 0) - continue; + if (c_count) { + if (!list_to_string(c_list, MAX_CHIPS, c_str, sizeof(c_str))) + return false; + if (!pathsel_add("pib[%s]/core[%s]", p_str, c_str)) + return false; + } - threadsel[i][j][k] = 1; - } - } + if (t_count) { + if (!list_to_string(t_list, MAX_THREADS, t_str, sizeof(t_str))) + return false; + if (!pathsel_add("pib[%s]/core[%s]/thread[%s]", p_str, c_str, t_str)) + return false; } if (l_count) { @@ -481,9 +514,8 @@ static bool parse_options(int argc, char *argv[]) pir_map(pir, &chip, &core, &thread); - processorsel[chip] = &chipsel[chip][0]; - chipsel[chip][core] = &threadsel[chip][core][0]; - threadsel[chip][core][thread] = 1; + if (!pathsel_add("pib%d/core%d/thread%d", chip, core, thread)) + return false; } } } From patchwork Thu Nov 15 07:19:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998134 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 42wXnY1Qc7z9sCQ for ; Thu, 15 Nov 2018 18:20:17 +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="yt9kvxD/"; 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 42wXnX6BnHzF3cS for ; Thu, 15 Nov 2018 18:20:16 +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="yt9kvxD/"; 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 42wXmr0WH5zF3b3 for ; Thu, 15 Nov 2018 18:19:40 +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="yt9kvxD/"; 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 42wXmq5Z4Sz9sBQ; Thu, 15 Nov 2018 18:19:39 +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=1542266379; bh=404eIX3eUhpVEpTghnwJ2qjitwwHgrkIQCrLQHA0bbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yt9kvxD/HwBlNPHmpTGQklZnVUvc9MYqLZLZuftv40VixBaWn2fRwJ56kHMvgvvm+ fJ62L2yHxR3bH5DfJh+d1jVlAzakFLps1lEDUuDJUQy4HBcR4KzI5NHNzf8DsULCdu sI6qdAgKZAUFoHhhIIVWT3m+rpRAHl1aVNIYA7koOpo+LnVfoWTgMxloPE389wJ95k RnuYqZnVXls70XdHt2Qm0AThq2PGF/KFaNiS6iG+x/H2mZM5mtyn+OzOizuzZzRxG7 Q0lq4RZbLt6hWaqY9vDMPaXLS3nuCbS55HvHP0D/rOIVxa3Ea9bujM+1bQERGbJEyd AuKPzpqhZmhDw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:21 +1100 Message-Id: <20181115071929.206974-9-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 08/16] main: Switch to path based target selection X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Drop the old target selection code. Signed-off-by: Amitay Isaacs --- src/main.c | 80 ++++++------------------------------------------------ 1 file changed, 8 insertions(+), 72 deletions(-) diff --git a/src/main.c b/src/main.c index 506e0b9..0a3a8fb 100644 --- a/src/main.c +++ b/src/main.c @@ -75,10 +75,6 @@ static int i2c_addr = 0x50; #define MAX_LINUX_CPUS (MAX_PROCESSORS * MAX_CHIPS * MAX_THREADS) -static int **processorsel[MAX_PROCESSORS]; -static int *chipsel[MAX_PROCESSORS][MAX_CHIPS]; -static int threadsel[MAX_PROCESSORS][MAX_CHIPS][MAX_THREADS]; - #define MAX_PATH_ARGS 16 static const char *pathsel[MAX_PATH_ARGS]; @@ -525,19 +521,12 @@ static bool parse_options(int argc, char *argv[]) void target_select(struct pdbg_target *target) { - /* We abuse the private data pointer atm to indicate the target is - * selected */ - pdbg_target_priv_set(target, (void *) 1); -} - -void target_unselect(struct pdbg_target *target) -{ - pdbg_target_priv_set(target, NULL); + path_target_add(target); } bool target_selected(struct pdbg_target *target) { - return (bool) pdbg_target_priv(target); + return path_target_selected(target); } /* Returns the sum of return codes. This can be used to count how many targets the callback was run on. */ @@ -556,7 +545,6 @@ int for_each_child_target(char *class, struct pdbg_target *parent, index = pdbg_target_index(target); assert(index != -1); - pdbg_target_probe(target); status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) continue; @@ -580,7 +568,6 @@ int for_each_target(char *class, int (*cb)(struct pdbg_target *, uint32_t, uint6 index = pdbg_target_index(target); assert(index != -1); - pdbg_target_probe(target); status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) continue; @@ -605,8 +592,6 @@ void for_each_target_release(char *class) static bool target_selection(void) { - struct pdbg_target *fsi, *pib, *chip, *thread; - switch (backend) { #ifdef TARGET_ARM case I2C: @@ -673,63 +658,17 @@ static bool target_selection(void) return false; } - /* At this point we should have a device-tree loaded. We want - * to walk the tree and disabled nodes we don't care about - * prior to probing. */ - pdbg_for_each_class_target("pib", pib) { - int proc_index = pdbg_target_index(pib); - - if (backend == I2C && device_node) - pdbg_target_set_property(pib, "bus", device_node, strlen(device_node) + 1); - - if (processorsel[proc_index]) { - target_select(pib); - pdbg_for_each_target("core", pib, chip) { - int chip_index = pdbg_target_index(chip); - if (pdbg_parent_index(chip, "pib") != proc_index) - continue; - - if (chipsel[proc_index][chip_index]) { - target_select(chip); - pdbg_for_each_target("thread", chip, thread) { - int thread_index = pdbg_target_index(thread); - if (threadsel[proc_index][chip_index][thread_index]) - target_select(thread); - else - target_unselect(thread); - } - } else - target_unselect(chip); - } - - /* This is kinda broken as we're overloading what '-c' - * means - it's now up to each command to select targets - * based on core/chiplet. We really need a better - * solution to target selection. */ - pdbg_for_each_target("chiplet", pib, chip) { - int chip_index = pdbg_target_index(chip); - if (chipsel[proc_index][chip_index]) { - target_select(chip); - } else - target_unselect(chip); - } - } else - target_unselect(pib); - } - - pdbg_for_each_class_target("fsi", fsi) { - int index = pdbg_target_index(fsi); - if (processorsel[index]) - target_select(fsi); - else - target_unselect(fsi); - } - if (pathsel_count) { if (!path_target_parse(pathsel, pathsel_count)) return false; } + if (!path_target_present()) { + printf("No valid targets found or specified. Try adding -p/-c/-t options to specify a target.\n"); + printf("Alternatively run 'pdbg -a probe' to get a list of all valid targets\n"); + return false; + } + return true; } @@ -862,8 +801,5 @@ found_action: if (rc > 0) return 0; - printf("No valid targets found or specified. Try adding -p/-c/-t options to specify a target.\n"); - printf("Alternatively run '%s -a probe' to get a list of all valid targets\n", - basename(argv[0])); return 1; } From patchwork Thu Nov 15 07:19:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998135 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 42wXnf21hCz9sCQ for ; Thu, 15 Nov 2018 18:20: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="Zkh5lCfu"; 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 42wXnd6g06zF3cX for ; Thu, 15 Nov 2018 18:20:21 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Zkh5lCfu"; 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 42wXmr5V7QzF3by for ; Thu, 15 Nov 2018 18:19:40 +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="Zkh5lCfu"; 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 42wXmr0Fcfz9sCQ; Thu, 15 Nov 2018 18:19:40 +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=1542266380; bh=0UoHQpBEtqYaBgZ2gLWJ+iKO540lVXV1lMN8aGlOmFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zkh5lCfucb7hf3EjwB+gAPUiItgpQdQXRob1bdrOOJrZeZWrHD1Y14DGoFzpqcjNy jg0SKRgTjlP6fzE7NPCG1WWVoTI5+xC3qP/D5zrelPaYofYC75MygCagAQAkegghKu 4wV3rvS6D+L/E+m5x9n6yRGnMkts4z5Ad6De9Dk2UNrLAqHVbiPEmIe0VhLnKmp/Zr HxMzy21IlfNHHGoZCmgYNVplQJFp3JjcKKqEG7Jsj87oVol6zsybQgok1klUyP2ugv a33THSHRErBIpa61NwmSJTzI03vq6vce4A60tr4uIxwEzaoUXuuEX7sI39fidOHodq 0Rp8hbffyIuSA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:22 +1100 Message-Id: <20181115071929.206974-10-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 09/16] main: Fix probe() to print targets correctly X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs --- src/main.c | 11 ----------- tests/test_selection.sh | 43 +++-------------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/main.c b/src/main.c index 0a3a8fb..3b20bf0 100644 --- a/src/main.c +++ b/src/main.c @@ -678,8 +678,6 @@ void print_target(struct pdbg_target *target, int level) struct pdbg_target *next; enum pdbg_target_status status; - pdbg_target_probe(target); - /* Does this target actually exist? */ status = pdbg_target_status(target); if (status != PDBG_TARGET_ENABLED) @@ -708,9 +706,6 @@ void print_target(struct pdbg_target *target, int level) } pdbg_for_each_child_target(target, next) { - if (!target_selected(next)) - continue; - print_target(next, level + 1); } } @@ -720,15 +715,9 @@ static int probe(void) struct pdbg_target *target; pdbg_for_each_class_target("pib", target) { - if (!target_selected(target)) - continue; - print_target(target, 0); } - printf("\nNote that only selected targets will be shown above. If none are shown\n" - "try adding '-a' to select all targets\n"); - return 1; } OPTCMD_DEFINE_CMD(probe, probe); diff --git a/tests/test_selection.sh b/tests/test_selection.sh index 2b23ec1..8909796 100755 --- a/tests/test_selection.sh +++ b/tests/test_selection.sh @@ -13,10 +13,9 @@ do_skip () fi } -test_result 0 < X-Patchwork-Id: 998136 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 42wXnj3CcVz9sBQ for ; Thu, 15 Nov 2018 18:20:25 +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="mzFr72dp"; 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 42wXnj15BmzF3cB for ; Thu, 15 Nov 2018 18:20: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="mzFr72dp"; 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 42wXms0vrrzF3b3 for ; Thu, 15 Nov 2018 18:19:41 +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="mzFr72dp"; 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 42wXmr5CsJz9sCV; Thu, 15 Nov 2018 18:19:40 +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=1542266380; bh=z8c/p0cqgKiP9jxdZPcGG+zXLoj1GllZhhJYOlAum8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mzFr72dp8QwpMssYgiR2IacZedsRvEMqcs6gF0F87HL4jqwF+J/8//IiQ0RI4NQRZ QLr3C3vMkEEQzKFKgFYIHr838rmV0o/nRf1NZkKMNqN3yoAPoChNLjdBppTIlswakq SKtVt4hkGA8IYdIRDRCibpx8xiBMCmI2kN7Xo1RWzk4NjJp7dx54XNf5ZKJnocnvVf I3XixAzotL/k6W4HucbTt46bkUbI0WGG3c0wt75e1fBeEWwmd2xFeDOLlh7G7AS/Cv Rz2BnG1vkgz4GrpnepqBDn3suasgHZdoJXp0W4xXpXg4iJPSeWTKMBX2TfH6AwA5Rt DrxcUJatFGLJg== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:23 +1100 Message-Id: <20181115071929.206974-11-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 10/16] tests: Add path based selection tests X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Tested-by: Alistair Popple --- Makefile.am | 1 + tests/test_selection2.sh | 545 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 546 insertions(+) create mode 100755 tests/test_selection2.sh diff --git a/Makefile.am b/Makefile.am index 2a687ca..f1e06f6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ check_PROGRAMS = $(libpdbg_tests) optcmd_test PDBG_TESTS = \ tests/test_selection.sh \ + tests/test_selection2.sh \ tests/test_hw_bmc.sh TESTS = $(libpdbg_tests) optcmd_test $(PDBG_TESTS) diff --git a/tests/test_selection2.sh b/tests/test_selection2.sh new file mode 100755 index 0000000..4e7921d --- /dev/null +++ b/tests/test_selection2.sh @@ -0,0 +1,545 @@ +#!/bin/sh + +. $(dirname "$0")/driver.sh + +test_group "path target selection tests" + +arch=$(arch 2>/dev/null) + +do_skip () +{ + if [ "$arch" != "x86_64" ] ; then + test_skip + fi +} + +test_result 0 < X-Patchwork-Id: 998137 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 42wXnp020Qz9sCQ for ; Thu, 15 Nov 2018 18:20:30 +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="L/0uZdqK"; 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 42wXnn5L0vzF3cH for ; Thu, 15 Nov 2018 18:20:29 +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="L/0uZdqK"; 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 42wXms3RQxzF3bw for ; Thu, 15 Nov 2018 18:19:41 +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="L/0uZdqK"; 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 42wXms0c4Vz9sCm; Thu, 15 Nov 2018 18:19:41 +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=1542266381; bh=x6R0WtGlUY8X2ei57ZvnNu8UOUL2JZMSIN2db2ABEc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L/0uZdqKwQu7aeFXI5KdSydzAaLoDXXyeSSl/wJtddGOaJnutREvgSTthC+k09jSv trjH+jzIQ0x9RylJovKOxmduVqTigFcfpiMA841Fg4a5Pj02wX9PrwQNwy66a4uYSJ M4yxh6xdK+9by/+1mpHuB1VPAQQVqnMW5YfMnGepjo9lHh0yjePFyoP17JRviO2wyP ry0pV7o0O5xFR/MxYHeE4DxzWdsgtWqjY5txwKbxi6+Gn28wuju6vOxoOf2o80+4pW uFVcETvrzADughBAqZJONlr3ySIAFH26ZNItRkgRdmdpp4CDJKUrggzgJz9Tb/JIX9 40hO6CPmj4lWA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:24 +1100 Message-Id: <20181115071929.206974-12-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 11/16] main: Do not use argv[0] for progname X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" When pdbg is built without "--disable-shared" option, libtool creates pdbg as a wrapper around lt-pdbg binary. This causes the tests to fail which try to match the output containing argv[0]. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 3b20bf0..51e39d9 100644 --- a/src/main.c +++ b/src/main.c @@ -143,11 +143,11 @@ static struct action actions[] = { { "gdbserver", "", "Start a gdb server" }, }; -static void print_usage(char *pname) +static void print_usage(void) { int i; - printf("Usage: %s [options] command ...\n\n", pname); + printf("Usage: pdbg [options] command ...\n\n"); printf(" Options:\n"); printf("\t-p, --processor=<0-%d>||\n", MAX_PROCESSORS-1); printf("\t-c, --chip=<0-%d>||\n", MAX_CHIPS-1); @@ -440,7 +440,7 @@ static bool parse_options(int argc, char *argv[]) case '?': case 'h': opt_error = true; - print_usage(basename(argv[0])); + print_usage(); break; } } while (c != EOF && !opt_error); @@ -743,7 +743,7 @@ int main(int argc, char *argv[]) return 1; if (optind >= argc) { - print_usage(basename(argv[0])); + print_usage(); return 1; } From patchwork Thu Nov 15 07:19:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998623 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 42wxsX2xqrz9s9G for ; Fri, 16 Nov 2018 10:10: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="IHgGMefm"; 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 42wxsX0TLBzF3gk for ; Fri, 16 Nov 2018 10:10: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="IHgGMefm"; 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 42wXms5qhvzF3b3 for ; Thu, 15 Nov 2018 18:19:41 +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="IHgGMefm"; 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 42wXms36nNz9sBQ; Thu, 15 Nov 2018 18:19:41 +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=1542266381; bh=kQW4+QqfP1lBYxdUiUH45YZCq3SbnGCOsVP6/ChflXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IHgGMefmXgglUvbj0pZJ4IqkEQtAhk0O8590qL3is+UdAfyhiS2zQ3KqulDy3l6+z tcUhnTFGsSYbSJcxBbtY1rywb6koN0txBc3BzDaxmb/0dWjgfgb/LEXmQsIq6c1LGW ruwGmUxvJ6gg3I9lSjGmV3PCbwYbhRB8JjDkXEe907J8Gdd/5WUZVn0NKqJ6Trv6Qx 5R4Uki5JC05OxZZByVcpSSGp7BHJMwuQn8o3YMgIsIxophhdj8wUM2GUipxeit/qMX UF3+BFDnHo+0FVLTir5MitHZ+Rd7hAEMgqoHGWT9WkbOvKdH1Lmy/mdKZHfDe7tzkU GSByko8A60WvQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:25 +1100 Message-Id: <20181115071929.206974-13-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 16 Nov 2018 10:10:03 +1100 Subject: [Pdbg] [PATCH v3 12/16] main: Update probe output to display device names X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" With capability of selecting any target in the device tree, probe output should display all the nodes with their device tree names. Signed-off-by: Amitay Isaacs --- src/main.c | 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 51e39d9..0dfc334 100644 --- a/src/main.c +++ b/src/main.c @@ -672,38 +672,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); @@ -714,7 +719,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..50db9e4 100755 --- a/tests/test_selection.sh +++ b/tests/test_selection.sh @@ -23,110 +23,111 @@ test_run pdbg -b fake probe test_result 0 < X-Patchwork-Id: 998138 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 42wXns1cyYz9sCQ for ; Thu, 15 Nov 2018 18:20: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="UWhOoQx7"; 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 42wXnr5ZfgzF3c9 for ; Thu, 15 Nov 2018 18:20: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="UWhOoQx7"; 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 42wXmt0TgFzF3bw for ; Thu, 15 Nov 2018 18:19:42 +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="UWhOoQx7"; 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 42wXms5WXVz9sCQ; Thu, 15 Nov 2018 18:19:41 +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=1542266381; bh=ydxJ8IDu7Y0cY0fv07c/rJKO1sjC+FuFEIqUl2Oln3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWhOoQx7YdG4GjoW7nnMtr+VC44NTFGyUH6ovumewUzvaOZEAMsvShbA8Iyq68QEn XsFqrPqkcdUcdyEthcTWp7PioIbtQpvD5KgSQM7HmkhrzWmrE1Xxy2oAlkM+Z7rWbw ms4+bTiGIo9PIwU0cWVr3NATyD69LT3GBE47cRkZm2h7Hlr+gbAcX+t492jXw7MOOa PxWBUoxFxn4Gg2OpVZAWR3KZWcEiH5U2roUae/hCbYsClMvc+RKzlkEvhjcYoavUoy ZlQaDQhDe51MRwC/Zsos21C287iiW6uUX2DPKGpkyiYNO42FvNvsLUMkr7gczHjJtJ SFKp1h44CnGnA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:26 +1100 Message-Id: <20181115071929.206974-14-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 13/16] libpdbg: Add an api for address translation X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/libpdbg.h | 4 ++++ libpdbg/target.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index f55acf4..44540e4 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -117,6 +117,10 @@ void pdbg_target_priv_set(struct pdbg_target *target, void *priv); struct pdbg_target *pdbg_target_root(void); bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible); +/* Translate an address offset for a target to absolute address in address + * space of a "base" target. */ +struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr); + /* Procedures */ int fsi_read(struct pdbg_target *target, uint32_t addr, uint32_t *val); int fsi_write(struct pdbg_target *target, uint32_t addr, uint32_t val); diff --git a/libpdbg/target.c b/libpdbg/target.c index 1fc8457..af9199d 100644 --- a/libpdbg/target.c +++ b/libpdbg/target.c @@ -36,6 +36,11 @@ static struct pdbg_target *get_class_target_addr(struct pdbg_target *target, con return target; } +struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr) +{ + return get_class_target_addr(target, "pib", addr); +} + /* The indirect access code was largely stolen from hw/xscom.c in skiboot */ #define PIB_IND_MAX_RETRIES 10 #define PIB_IND_READ PPC_BIT(0) From patchwork Thu Nov 15 07:19:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 998139 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 42wXnx2gTdz9sCQ for ; Thu, 15 Nov 2018 18:20:37 +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="nK8eHEkI"; 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 42wXnx0H9SzF3cH for ; Thu, 15 Nov 2018 18:20: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="nK8eHEkI"; 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 42wXmt2MYFzF3b3 for ; Thu, 15 Nov 2018 18:19:42 +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="nK8eHEkI"; 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 42wXmt08y7z9sCV; Thu, 15 Nov 2018 18:19:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542266382; bh=ji8M8Lc8A+aimdfMvH3vGswOYjjH6rNzrZXDbqhVCWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nK8eHEkI2TPN+uc2550175DpzExYD+q/l8HwZ+GEardCFWkVWgNmeI+AHLUJ2hi5/ gnpp/iBOgEmGLVjAAyrrtZRKV3pFX7rVL5babbUOxqMaQV+NRCkLDsdfpOgETIUuu4 ez2dgJO+8xQfH/xsfr+ln/Vxmc7i2gp17LbRM6oQ5Ze4NRfJOsb2gQWRGJ5Hk8uEeV z25Pfo36U3GLnYVcA/igq6o7Rk9Z1JwtsS3A28BdTt6dazk33vQ/Fn9ZtO9/4he40e ha/99jQBcL799O75o+AiTszQFmVXIucCQGlT1EEiGZ+BYk+G47VVpMnGnf+t7xgJBa DjMpB7bERtLaQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:27 +1100 Message-Id: <20181115071929.206974-15-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 14/16] main: Convert getcfam/putcfam to use path based targeting X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/cfam.c | 48 ++++++++++++++++++++++++++------------------ tests/test_hw_bmc.sh | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/cfam.c b/src/cfam.c index 6dab388..19c2b07 100644 --- a/src/cfam.c +++ b/src/cfam.c @@ -21,39 +21,49 @@ #include "main.h" #include "optcmd.h" +#include "path.h" -static int _getcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused) +static int getcfam(uint32_t addr) { + struct pdbg_target *target; uint32_t value; + int count = 0; - if (fsi_read(target, *addr, &value)) - return 0; + for_each_path_target_class("fsi", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; - printf("p%d:0x%x = 0x%08x\n", index, (uint32_t) *addr, value); + if (fsi_read(target, addr, &value)) { + printf("p%d: failed\n", pdbg_target_index(target)); + continue; - return 1; -} + } -static int getcfam(uint32_t addr) -{ - uint64_t addr64 = addr; + printf("p%d: 0x%x = 0x%08x\n", pdbg_target_index(target), addr, value); + count++; + } - return for_each_target("fsi", _getcfam, &addr64, NULL); + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(getcfam, getcfam, (ADDRESS32)); -static int _putcfam(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data) +static int putcfam(uint32_t addr, uint32_t data) { - if (fsi_write(target, *addr, *data)) - return 0; + struct pdbg_target *target; + int count = 0; - return 1; -} + for_each_path_target_class("fsi", target) { + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; -static int putcfam(uint32_t addr, uint32_t data) -{ - uint64_t addr64 = addr, data64 = data; + if (fsi_write(target, addr, data)) { + printf("p%d: failed\n", pdbg_target_index(target)); + continue; + } + + count++; + } - return for_each_target("fsi", _putcfam, &addr64, &data64); + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(putcfam, putcfam, (ADDRESS32, DATA32)); diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh index c35597b..850afd9 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -84,7 +84,7 @@ result_filter () } test_result 0 < X-Patchwork-Id: 998140 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 42wXp142RVz9sCQ for ; Thu, 15 Nov 2018 18:20:41 +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="wTSUjG1a"; 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 42wXp11rxCzF3c9 for ; Thu, 15 Nov 2018 18:20:41 +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="wTSUjG1a"; 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 42wXmt5R80zF3bw for ; Thu, 15 Nov 2018 18:19:42 +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="wTSUjG1a"; 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 42wXmt230tz9sBQ; Thu, 15 Nov 2018 18:19:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542266382; bh=MfSYqtplggzvvEFjSHAImI1FZhW1cd+hUnvP3tAAKmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wTSUjG1awF+fFwMRMZKcL51mClX7jRcr3uidFy8oY1uuHAaZ6rUbs3mFAL6UmNmAV cnUh6pbLMzs0VGUz0D78+EQ7X8iQK4R24M2S9UPdlsMSgEKSx8JpoZlzgXYSbIZPCk vzzHdVTuXPRr0wWM54P/PxH5CvDOPp+B3ZhPFECGRDdf8Am/OK0ceiSYZ0N9v5/hWd eigI+gbZeJHAwrPWfS76tcpjVCrWYozARuM8IzHBBTvVI2e690TNY2Lnd8Jx18m2Ku UFhyTPcdrqC9dgGIaMENwCwEs3Qdl0FPMjcT8v548oIUcciEAGTxtY6O+Huy7qBdMr 6gRWURXKrE7+A== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:28 +1100 Message-Id: <20181115071929.206974-16-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 15/16] main: Convert getscom/putscom to use path based targeting X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/scom.c | 95 +++++++++++++++++++++++++++++++++++--------- tests/test_hw_bmc.sh | 7 ++-- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/scom.c b/src/scom.c index 2372e91..1f8e6c7 100644 --- a/src/scom.c +++ b/src/scom.c @@ -18,41 +18,100 @@ #include #include #include +#include #include #include "main.h" #include "optcmd.h" +#include "path.h" -static int _getscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *unused) +/* Check if a target has scom region */ +static bool scommable(struct pdbg_target *target) { - uint64_t value; - - if (pib_read(target, *addr, &value)) - return 0; + char *classname; - printf("p%d:0x%" PRIx64 " = 0x%016" PRIx64 "\n", index, *addr, value); + classname = pdbg_target_class_name(target); + if (!strcmp(classname, "pib") || + !strcmp(classname, "core") || + !strcmp(classname, "thread")) + return true; - return 1; + return false; } - int getscom(uint64_t addr) +int getscom(uint64_t addr) { - return for_each_target("pib", _getscom, &addr, NULL); + struct pdbg_target *target; + char *path; + uint64_t value; + int count = 0; + + for_each_path_target(target) { + struct pdbg_target *addr_base; + uint64_t xlate_addr; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!scommable(target)) { + continue; + } + + path = pdbg_target_path(target); + assert(path); + + xlate_addr = addr; + addr_base = pdbg_address_absolute(target, &xlate_addr); + + if (pib_read(target, addr, &value)) { + printf("p%d: 0x%016" PRIx64 " failed (%s)\n", pdbg_target_index(addr_base), xlate_addr, path); + free(path); + continue; + } + + printf("p%d: 0x%016" PRIx64 " = 0x%016" PRIx64 " (%s)\n", pdbg_target_index(addr_base), xlate_addr, value, path); + free(path); + count++; + } + + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(getscom, getscom, (ADDRESS)); -static int _putscom(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *data) +int putscom(uint64_t addr, uint64_t data, uint64_t mask) { - if (pib_write(target, *addr, *data)) - return 0; + struct pdbg_target *target; + char *path; + int count = 0; - return 1; -} + for_each_path_target(target) { + struct pdbg_target *addr_base; + uint64_t xlate_addr; - int putscom(uint64_t addr, uint64_t data, uint64_t mask) -{ - /* TODO: Restore the functionality */ - return for_each_target("pib", _putscom, &addr, &data); + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + if (!scommable(target)) { + continue; + } + + path = pdbg_target_path(target); + assert(path); + + xlate_addr = addr; + addr_base = pdbg_address_absolute(target, &xlate_addr); + + /* TODO: Restore the functionality */ + if (pib_write(target, addr, data)) { + printf("p%d: 0x%016" PRIx64 " failed (%s)\n", pdbg_target_index(addr_base), xlate_addr, path); + free(path); + continue; + } + + count++; + } + + return count; } OPTCMD_DEFINE_CMD_WITH_ARGS(putscom, putscom, (ADDRESS, DATA, DEFAULT_DATA("0xffffffffffffffff"))); diff --git a/tests/test_hw_bmc.sh b/tests/test_hw_bmc.sh index 850afd9..ab6af35 100755 --- a/tests/test_hw_bmc.sh +++ b/tests/test_hw_bmc.sh @@ -79,8 +79,9 @@ test_wrapper run_over_ssh result_filter () { - sed -E -e 's#0x[[:xdigit:]]{16}#HEX16#' \ - -E -e 's#0x[[:xdigit:]]{8}#HEX8#' + sed -E -e 's#0x[[:xdigit:]]{16}#HEX16#g' \ + -E -e 's#0x[[:xdigit:]]{8}#HEX8#g' \ + -E -e 's#/.*fsi@0/pib@1000#PIB0PATH#' } test_result 0 < X-Patchwork-Id: 998141 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 42wXp43rcdz9sBQ for ; Thu, 15 Nov 2018 18:20:44 +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="kztnJh2O"; 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 42wXp41qf8zF3ch for ; Thu, 15 Nov 2018 18:20:44 +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="kztnJh2O"; 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 42wXmv0Jp0zF3c9 for ; Thu, 15 Nov 2018 18:19:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="kztnJh2O"; 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 42wXmt58GDz9sCQ; Thu, 15 Nov 2018 18:19:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1542266382; bh=nVltuJ9CNSYVupcexVjmd2Ho/0e3l7+AjyeMXT3BcqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kztnJh2OFfnVgfgCzj+hAcjOYgCziWcfXm7hW9n/yK1OPTdrSJNjZwq7sjVo/pYgb Dxu/336ILxkTLYcA+fylnn8TJjXW7LicX7sOoJ9s4z6F2+onVMWwlVHMNphKTKsV6/ 1Yw+/Fv/Dpqqdfq1uDejVZ7Y2SwXD4Ny+fWHu3R62TmVEdLYj3xNI0HZyoWdk4tNB2 BdWKOgzQD4H4v/NxXksV1nI69+89OBIid6PgfQTrpSNOq91Y9ZucpgU7sv1DFEcJ88 MHOhQotqY0cwsUIteMSIy0V19YzRTSm0w8Ck0x1I6aBlC8VEJ+B8ygVEEzk5j1ODH4 oTnisK5r2ODfw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Thu, 15 Nov 2018 18:19:29 +1100 Message-Id: <20181115071929.206974-17-amitay@ozlabs.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115071929.206974-1-amitay@ozlabs.org> References: <20181115071929.206974-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 16/16] main: Convert register functions to path based targeting X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- src/reg.c | 155 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 95 insertions(+), 60 deletions(-) diff --git a/src/reg.c b/src/reg.c index fcf6f4c..8fdb386 100644 --- a/src/reg.c +++ b/src/reg.c @@ -18,11 +18,13 @@ #include #include #include +#include #include #include "main.h" #include "optcmd.h" +#include "path.h" #define REG_CR -5 #define REG_XER -4 @@ -31,14 +33,14 @@ #define REG_NIA -1 #define REG_R31 31 -static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t value, int rc) +static void print_proc_reg(struct pdbg_target *target, int reg, uint64_t *value, int rc) { int proc_index, chip_index, thread_index; thread_index = pdbg_target_index(target); chip_index = pdbg_parent_index(target, "core"); proc_index = pdbg_parent_index(target, "pib"); - printf("p%d:c%d:t%d:", proc_index, chip_index, thread_index); + printf("p%d:c%d:t%d: ", proc_index, chip_index, thread_index); if (reg == REG_MSR) printf("msr: "); @@ -49,145 +51,178 @@ static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t va else if (reg == REG_CR) printf("cr: "); else if (reg > REG_R31) - printf("spr%03" PRIu64 ": ", reg - REG_R31); + printf("spr%03d: ", reg - REG_R31); else if (reg >= 0 && reg <= 31) - printf("gpr%02" PRIu64 ": ", reg); + printf("gpr%02d: ", reg); if (rc == 1) { printf("Check threadstatus - not all threads on this chiplet are quiesced\n"); } else if (rc == 2) printf("Thread in incorrect state\n"); else - printf("0x%016" PRIx64 "\n", value); + printf("0x%016" PRIx64 "\n", *value); } -static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *value) +static int putprocreg(struct pdbg_target *target, int reg, uint64_t *value) { + uint32_t u32; int rc; - if (*reg == REG_MSR) + if (reg == REG_MSR) rc = ram_putmsr(target, *value); - else if (*reg == REG_NIA) + else if (reg == REG_NIA) rc = ram_putnia(target, *value); - else if (*reg == REG_XER) + else if (reg == REG_XER) rc = ram_putxer(target, *value); - else if (*reg == REG_CR) - rc = ram_putcr(target, *value); - else if (*reg > REG_R31) - rc = ram_putspr(target, *reg - REG_R31, *value); - else if (*reg >= 0 && *reg <= 31) - rc = ram_putgpr(target, *reg, *value); - - print_proc_reg(target, *reg, *value, rc); + else if (reg == REG_CR) { + u32 = *value; + rc = ram_putcr(target, u32); + } else if (reg > REG_R31) + rc = ram_putspr(target, reg - REG_R31, *value); + else if (reg >= 0 && reg <= 31) + rc = ram_putgpr(target, reg, *value); + else + assert(0); - return 0; + return rc; } -static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *unused) +static int getprocreg(struct pdbg_target *target, uint32_t reg, uint64_t *value) { + uint32_t u32 = 0; int rc; - uint64_t value; - if (*reg == REG_MSR) - rc = ram_getmsr(target, &value); - else if (*reg == REG_NIA) - rc = ram_getnia(target, &value); - else if (*reg == REG_XER) - rc = ram_getxer(target, &value); - else if (*reg == REG_CR) - rc = ram_getcr(target, (uint32_t *)&value); - else if (*reg > REG_R31) - rc = ram_getspr(target, *reg - REG_R31, &value); - else if (*reg >= 0 && *reg <= 31) - rc = ram_getgpr(target, *reg, &value); + if (reg == REG_MSR) + rc = ram_getmsr(target, value); + else if (reg == REG_NIA) + rc = ram_getnia(target, value); + else if (reg == REG_XER) + rc = ram_getxer(target, value); + else if (reg == REG_CR) { + rc = ram_getcr(target, &u32); + *value = u32; + } else if (reg > REG_R31) + rc = ram_getspr(target, reg - REG_R31, value); + else if (reg >= 0 && reg <= 31) + rc = ram_getgpr(target, reg, value); + else + assert(0); + + return rc; +} + +static int getreg(int reg) +{ + struct pdbg_target *target; + int count = 0; + + for_each_path_target_class("thread", target) { + uint64_t value = 0; + int rc; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + rc = getprocreg(target, reg, &value); + print_proc_reg(target, reg, &value, rc); + + if (!rc) + count++; + } + + return count; +} + +static int putreg(int reg, uint64_t *value) +{ + struct pdbg_target *target; + int count = 0; + + for_each_path_target_class("thread", target) { + int rc; + + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED) + continue; + + rc = putprocreg(target, reg, value); + print_proc_reg(target, reg, value, rc); - print_proc_reg(target, *reg, value, rc); + if (!rc) + count++; + } - return !rc; + return count; } static int getgpr(int gpr) { - uint64_t reg = gpr; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(gpr); } OPTCMD_DEFINE_CMD_WITH_ARGS(getgpr, getgpr, (GPR)); static int putgpr(int gpr, uint64_t data) { - uint64_t reg = gpr; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(gpr, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putgpr, putgpr, (GPR, DATA)); static int getnia(void) { - uint64_t reg = REG_NIA; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_NIA); } OPTCMD_DEFINE_CMD(getnia, getnia); static int putnia(uint64_t nia) { - uint64_t reg = REG_NIA; - return for_each_target("thread", putprocreg, ®, &nia); + return putreg(REG_NIA, &nia); } OPTCMD_DEFINE_CMD_WITH_ARGS(putnia, putnia, (DATA)); static int getspr(int spr) { - uint64_t reg = spr + REG_R31; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(spr + REG_R31); } OPTCMD_DEFINE_CMD_WITH_ARGS(getspr, getspr, (SPR)); static int putspr(int spr, uint64_t data) { - uint64_t reg = spr + REG_R31; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(spr + REG_R31, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putspr, putspr, (SPR, DATA)); static int getmsr(void) { - uint64_t reg = REG_MSR; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_MSR); } OPTCMD_DEFINE_CMD(getmsr, getmsr); static int putmsr(uint64_t data) { - uint64_t reg = REG_MSR; - return for_each_target("thread", putprocreg, ®, &data); + return putreg(REG_MSR, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putmsr, putmsr, (DATA)); static int getxer(void) { - uint64_t reg = REG_XER; - return for_each_target("thread", getprocreg, ®, NULL); + return getreg(REG_XER); } OPTCMD_DEFINE_CMD(getxer, getxer); static int putxer(uint64_t data) { - uint64_t reg = REG_XER; - uint64_t d = data; - return for_each_target("thread", putprocreg, ®, &d); + return putreg(REG_XER, &data); } OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA)); static int getcr(void) { - uint64_t cr = REG_CR; - return for_each_target("thread", getprocreg, &cr, NULL); + return getreg(REG_CR); } OPTCMD_DEFINE_CMD(getcr, getcr); static int putcr(uint32_t data) { - uint64_t cr = REG_CR; - uint64_t d = data; - return for_each_target("thread", putprocreg, &cr, &d); + uint64_t u64 = data; + return putreg(REG_CR, &u64); } OPTCMD_DEFINE_CMD_WITH_ARGS(putcr, putcr, (DATA32));