[Pdbg] [PATCH 03/10] pdbg: Add getxer & putxer commands

Alistair Popple alistair at popple.id.au
Mon Jun 4 16:26:07 AEST 2018


On Thursday, 31 May 2018 3:29:08 PM AEST Rashmica Gupta wrote:
> diff --git a/src/reg.c b/src/reg.c
> index 002cfe9..416236b 100644
> --- a/src/reg.c
> +++ b/src/reg.c
> @@ -18,11 +18,13 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <debug.h>
>  
>  #include <libpdbg.h>
>  
>  #include "main.h"
>  
> +#define REG_XER -4
>  #define REG_MEM -3
>  #define REG_MSR -2
>  #define REG_NIA -1
> @@ -41,6 +43,8 @@ static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t va
>  		printf("msr: ");
>  	else if (reg == REG_NIA)
>  		printf("nia: ");
> +	else if (reg == REG_XER)
> +		printf("xer: ");
>  	else if (reg > REG_R31)
>  		printf("spr%03" PRIu64 ": ", reg - REG_R31);
>  	else if (reg >= 0 && reg <= 31)
> @@ -62,6 +66,8 @@ static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg,
>  		rc = ram_putmsr(target, *value);
>  	else if (*reg == REG_NIA)
>  		rc = ram_putnia(target, *value);
> +	else if (*reg == REG_XER)
> +		rc = ram_putxer(target, *value);
>  	else if (*reg > REG_R31)
>  		rc = ram_putspr(target, *reg - REG_R31, *value);
>  	else if (*reg >= 0 && *reg <= 31)
> @@ -81,6 +87,8 @@ static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg,
>  		rc = ram_getmsr(target, &value);
>  	else if (*reg == REG_NIA)
>  		rc = ram_getnia(target, &value);
> +	else if (*reg == REG_XER)
> +		rc = ram_getxer(target, &value);
>  	else if (*reg > REG_R31)
>  		rc = ram_getspr(target, *reg - REG_R31, &value);
>  	else if (*reg >= 0 && *reg <= 31)

Most of the above exists for like it does for weird historical reasons, so if
you can see ways of refactoring it feel free to!

> @@ -231,3 +239,32 @@ int handle_msr(int optind, int argc, char *argv[])
>  
>  	return for_each_target("thread", getprocreg, &msr, NULL);
>  }
> +
> +int handle_xer(int optind, int argc, char *argv[])
> +{
> +	uint64_t xer = REG_XER;
> +	char *endptr;
> +
> +	if (strcmp(argv[optind], "putxer") == 0) {
> +		uint64_t data;
> +
> +		if (optind + 1 >= argc) {
> +			printf("%s: command '%s' requires data\n", argv[0], argv[optind]);
> +			return -1;
> +		}
> +
> +		errno = 0;
> +		data = strtoull(argv[optind + 1], &endptr, 0);
> +		if (errno || *endptr != '\0') {
> +			printf("%s: command '%s' couldn't parse data '%s'\n",
> +				argv[0], argv[optind], argv[optind + 1]);
> +			return -1;
> +		}
> +
> +		PR_WARNING("We can only set part of the XER register.\n");

Why? And which part of the XER register? It might be nice if we specified to the
user which bits we can get/set to avoid confusion.

Otherwise everything else looks pretty good! Thanks.

- Alistair

> +		return for_each_target("thread", putprocreg, &xer, &data);
> +	}
> +
> +	PR_WARNING("We can only get part of the XER register.\n");
> +	return for_each_target("thread", getprocreg, &xer, NULL);
> +}
> diff --git a/src/reg.h b/src/reg.h
> index ad41d9d..ca548a6 100644
> --- a/src/reg.h
> +++ b/src/reg.h
> @@ -18,3 +18,4 @@ int handle_gpr(int optind, int argc, char *argv[]);
>  int handle_nia(int optind, int argc, char *argv[]);
>  int handle_spr(int optind, int argc, char *argv[]);
>  int handle_msr(int optind, int argc, char *argv[]);
> +int handle_xer(int optind, int argc, char *argv[]);
> 




More information about the Pdbg mailing list