From patchwork Fri Apr 5 08:17:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1078155 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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44bCPM4GC8z9sPd for ; Fri, 5 Apr 2019 19:18:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="d1R64zec"; 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 44bCPM1XvpzDqPR for ; Fri, 5 Apr 2019 19:18:15 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44bCPB5XG4zDqMk for ; Fri, 5 Apr 2019 19:18:06 +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="d1R64zec"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 44bCPB1J6Wz9sPf; Fri, 5 Apr 2019 19:18:06 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1554452286; bh=tmORS0Sw2bOK9G2i6TADPWULHU7FKdSrnYytppnWxtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1R64zecXPSJO6tC6vLXUpLtJS85UJJduebrw3cUDisKUD0pggidzFiTHLJA5QppB zI/0a4sizCQzbc8prkyfnLFa7eBc3iI+oYAb/fLUKRT0kxVq5isCb/iWtjJywgvDi7 HCosCUps57hon2E+02UYCbZzR+XLXNjeZO1x4v5QJtgEAFjkDruX82tCJNnugk/QoZ 0yF7Ai0UkvpY3yr2HWBqDUzGn9OhKsnLwKyOV8eZijedrrYm7xoFXMtFCLlDoYsYlC 7ZnIG4OiQO8bqHBGY+mvgXP+ujw9fsvqWtc3EDgZ3WQ+WSPGxBzDGktlqed1QrB8T7 e9TRGAbPKTOAQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Fri, 5 Apr 2019 19:17:57 +1100 Message-Id: <20190405081758.43783-3-amitay@ozlabs.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190405081758.43783-1-amitay@ozlabs.org> References: <20190405081758.43783-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 2/3] mem: Dump memory only if mem_read was successful 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" If mem_read() fails, try again with any other adu targets. Since we need to dump memory only once, move dumping of memory outside the loop. Signed-off-by: Amitay Isaacs --- src/mem.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mem.c b/src/mem.c index 408ff11..8045069 100644 --- a/src/mem.c +++ b/src/mem.c @@ -45,7 +45,7 @@ static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size, bool ci) { struct pdbg_target *target; uint8_t *buf; - int rc = 0; + int count = 0; if (size == 0) { PR_ERROR("Size must be > 0\n"); @@ -54,27 +54,33 @@ static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size, bool ci) buf = malloc(size); assert(buf); + pdbg_for_each_class_target("adu", target) { + int rc; + if (pdbg_target_probe(target) != PDBG_TARGET_ENABLED) continue; pdbg_set_progress_tick(progress_tick); progress_init(); rc = mem_read(target, addr, buf, size, block_size, ci); - if (rc) + progress_end(); + if (rc) { PR_ERROR("Unable to read memory.\n"); + continue; + } + count++; + break; + } + + if (count > 0) { if (write(STDOUT_FILENO, buf, size) < 0) PR_ERROR("Unable to write stdout.\n"); - else - rc++; - - progress_end(); - break; } - free(buf); - return rc; + free(buf); + return count; } static int getmem(uint64_t addr, uint64_t size, struct mem_flags flags)