[Pdbg] [PATCH v5 3/5] mem: Dump memory only if mem_read was successful
Amitay Isaacs
amitay at ozlabs.org
Thu Apr 11 12:45:13 AEST 2019
On Thu, 2019-04-11 at 02:38 +0000, Joel Stanley wrote:
> 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?
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 at lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/pdbg
Amitay.
--
Throw your dreams into space like a kite, and you do not know what it will
bring back, a new life, a new friend, a new love, a new country.
- Anais Nin
More information about the Pdbg
mailing list