[Pdbg] [PATCH v5 3/5] mem: Dump memory only if mem_read was successful
Joel Stanley
joel at jms.id.au
Thu Apr 11 12:38:14 AEST 2019
On Wed, 10 Apr 2019 at 08:03, Amitay Isaacs <amitay at ozlabs.org> wrote:
>
> 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 <amitay at ozlabs.org>
> ---
> 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++;
Shouldn't count be incremented by size?
> + 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)
> --
> 2.20.1
>
> --
> Pdbg mailing list
> Pdbg at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg
More information about the Pdbg
mailing list