Message ID | 20190410080151.429876-4-amitay@ozlabs.org |
---|---|
State | Superseded |
Headers | show |
Series | hexdump bytes from getmem | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | success | Successfully applied on branch master (854c4c5facff43af9e0fe5d7062b58f631987b0b) |
snowpatch_ozlabs/build-multiarch | success | Test build-multiarch on branch master |
On Wed, 10 Apr 2019 at 08:03, Amitay Isaacs <amitay@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@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@lists.ozlabs.org > https://lists.ozlabs.org/listinfo/pdbg
On Thu, 2019-04-11 at 02:38 +0000, Joel Stanley wrote: > On Wed, 10 Apr 2019 at 08:03, Amitay Isaacs <amitay@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@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? Not really. In the main code, we translate rc=0 means the function did not get executed on any target. In effect we are calculating how many targets did the function get executed on. We are doing a single read. Either it succeeds or fails. Since this is the front-end, we just need to know the status of the operation. > > > + 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@lists.ozlabs.org > > https://lists.ozlabs.org/listinfo/pdbg Amitay.
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)
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@ozlabs.org> --- src/mem.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)