[Pdbg] [PATCH 2/2] main: Dump memory on terminal from getmem

Alistair Popple alistair at popple.id.au
Tue Mar 26 11:50:53 AEDT 2019


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.

- 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;




More information about the Pdbg mailing list