[Pdbg] [PATCH 2/2] main: Dump memory on terminal from getmem
Amitay Isaacs
amitay at ozlabs.org
Wed Mar 27 11:47:39 AEDT 2019
On Tue, 2019-03-26 at 11:50 +1100, Alistair Popple wrote:
> This should be enabled by an option as there are reasons to not
> always want a
> hexdump when using stdout.
>
> eg. when dumping the OPAL console or piping into od for a
> differently
> formatted hexdump.
If stdout is a pipe, then you will get expected behaviour.
I didn't realize you could be dumping text. May be hexdump() function
should print the ascii chars similar to hexdump tool. Or you can
always pipe through cat if you know you are dumping text! :-)
I didn't want add yet another option. As this option would be for
getmem (and related) commands and not a global option. That would make
parsing more complicated.
>
> - Alistair
>
> On Thursday, 21 February 2019 11:08:51 AM AEDT Amitay Isaacs wrote:
> > Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> > ---
> > src/mem.c | 12 +++++++++---
> > 1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/mem.c b/src/mem.c
> > index 6454739..53bf39e 100644
> > --- a/src/mem.c
> > +++ b/src/mem.c
> > @@ -28,6 +28,7 @@
> > #include "progress.h"
> > #include "optcmd.h"
> > #include "parsers.h"
> > +#include "util.h"
> >
> > #define PR_ERROR(x, args...) \
> > pdbg_log(PDBG_ERROR, x, ##args)
> > @@ -68,10 +69,15 @@ static int _getmem(uint64_t addr, uint64_t
> > size, uint8_t
> > block_size) if (rc)
> > PR_ERROR("Unable to read memory.\n");
> >
> > - if (write(STDOUT_FILENO, buf, size) < 0)
> > - PR_ERROR("Unable to write stdout.\n");
> > - else
> > + if (isatty(STDOUT_FILENO)) {
> > + hexdump(addr, buf, size, 1);
> > + rc++;
> > + } else {
> > + if (write(STDOUT_FILENO, buf, size) < 0)
> > + PR_ERROR("Unable to write stdout.\n");
> > + else
> > rc++;
> > + }
> >
> > progress_end();
> > break;
>
>
Amitay.
--
You never get a second chance to make a good first impression.
More information about the Pdbg
mailing list