[Pdbg] [PATCH v2 15/15] main: Convert register functions to path based targeting
Alistair Popple
alistair at popple.id.au
Tue Nov 13 12:23:52 AEDT 2018
Hi Amitay,
> -static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t
> *reg, uint64_t *value) +static int putprocreg(struct pdbg_target *target,
> int reg, uint64_t *value) {
> + uint32_t u32;
> int rc;
>
> - if (*reg == REG_MSR)
> + if (reg == REG_MSR)
> rc = ram_putmsr(target, *value);
> - else if (*reg == REG_NIA)
> + else if (reg == REG_NIA)
> rc = ram_putnia(target, *value);
> - else if (*reg == REG_XER)
> + else if (reg == REG_XER)
> rc = ram_putxer(target, *value);
> - else if (*reg == REG_CR)
> - rc = ram_putcr(target, *value);
> - else if (*reg > REG_R31)
> - rc = ram_putspr(target, *reg - REG_R31, *value);
> - else if (*reg >= 0 && *reg <= 31)
> - rc = ram_putgpr(target, *reg, *value);
> -
> - print_proc_reg(target, *reg, *value, rc);
> + else if (reg == REG_CR) {
> + u32 = *value;
> + rc = ram_putcr(target, u32);
> + } else if (reg > REG_R31)
> + rc = ram_putspr(target, reg - REG_R31, *value);
> + else if (reg >= 0 && reg <= 31)
> + rc = ram_putgpr(target, reg, *value);
>
> - return 0;
> + return rc;
It appears rc may be returned uninitialised here. This was causing the
somewhat confusing compiler error below:
make --no-print-directory all-am
CC src/pdbg-reg.o
src/reg.c: In function ‘putreg’:
src/reg.c:146:6: error: ‘rc’ may be used uninitialized in this function [-
Werror=maybe-uninitialized]
if (!rc)
^
- Alistair
> }
>
> -static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t
> *reg, uint64_t *unused) +static int getprocreg(struct pdbg_target *target,
> uint32_t reg, uint64_t *value) {
> + uint32_t u32 = 0;
> int rc;
> - uint64_t value;
>
> - if (*reg == REG_MSR)
> - 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_CR)
> - rc = ram_getcr(target, (uint32_t *)&value);
> - else if (*reg > REG_R31)
> - rc = ram_getspr(target, *reg - REG_R31, &value);
> - else if (*reg >= 0 && *reg <= 31)
> - rc = ram_getgpr(target, *reg, &value);
> + if (reg == REG_MSR)
> + 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_CR) {
> + rc = ram_getcr(target, &u32);
> + *value = u32;
> + } else if (reg > REG_R31)
> + rc = ram_getspr(target, reg - REG_R31, value);
> + else if (reg >= 0 && reg <= 31)
> + rc = ram_getgpr(target, reg, value);
> +
> + return rc;
> +}
> +
> +static int getreg(int reg)
> +{
> + struct pdbg_target *target;
> + int count = 0;
> +
> + for_each_path_target_class("thread", target) {
> + uint64_t value = 0;
> + int rc;
> +
> + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
> + continue;
> +
> + rc = getprocreg(target, reg, &value);
> + print_proc_reg(target, reg, &value, rc);
> +
> + if (!rc)
> + count++;
> + }
> +
> + return count;
> +}
> +
> +static int putreg(int reg, uint64_t *value)
> +{
> + struct pdbg_target *target;
> + int count = 0;
> +
> + for_each_path_target_class("thread", target) {
> + int rc;
> +
> + if (pdbg_target_status(target) != PDBG_TARGET_ENABLED)
> + continue;
> +
> + rc = putprocreg(target, reg, value);
> + print_proc_reg(target, reg, value, rc);
>
> - print_proc_reg(target, *reg, value, rc);
> + if (!rc)
> + count++;
> + }
>
> - return !rc;
> + return count;
> }
>
> static int getgpr(int gpr)
> {
> - uint64_t reg = gpr;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(gpr);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(getgpr, getgpr, (GPR));
>
> static int putgpr(int gpr, uint64_t data)
> {
> - uint64_t reg = gpr;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(gpr, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putgpr, putgpr, (GPR, DATA));
>
> static int getnia(void)
> {
> - uint64_t reg = REG_NIA;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_NIA);
> }
> OPTCMD_DEFINE_CMD(getnia, getnia);
>
> static int putnia(uint64_t nia)
> {
> - uint64_t reg = REG_NIA;
> - return for_each_target("thread", putprocreg, ®, &nia);
> + return putreg(REG_NIA, &nia);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putnia, putnia, (DATA));
>
> static int getspr(int spr)
> {
> - uint64_t reg = spr + REG_R31;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(spr + REG_R31);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(getspr, getspr, (SPR));
>
> static int putspr(int spr, uint64_t data)
> {
> - uint64_t reg = spr + REG_R31;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(spr + REG_R31, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putspr, putspr, (SPR, DATA));
>
> static int getmsr(void)
> {
> - uint64_t reg = REG_MSR;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_MSR);
> }
> OPTCMD_DEFINE_CMD(getmsr, getmsr);
>
> static int putmsr(uint64_t data)
> {
> - uint64_t reg = REG_MSR;
> - return for_each_target("thread", putprocreg, ®, &data);
> + return putreg(REG_MSR, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putmsr, putmsr, (DATA));
>
> static int getxer(void)
> {
> - uint64_t reg = REG_XER;
> - return for_each_target("thread", getprocreg, ®, NULL);
> + return getreg(REG_XER);
> }
> OPTCMD_DEFINE_CMD(getxer, getxer);
>
> static int putxer(uint64_t data)
> {
> - uint64_t reg = REG_XER;
> - uint64_t d = data;
> - return for_each_target("thread", putprocreg, ®, &d);
> + return putreg(REG_XER, &data);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA));
>
> static int getcr(void)
> {
> - uint64_t cr = REG_CR;
> - return for_each_target("thread", getprocreg, &cr, NULL);
> + return getreg(REG_CR);
> }
> OPTCMD_DEFINE_CMD(getcr, getcr);
>
> static int putcr(uint32_t data)
> {
> - uint64_t cr = REG_CR;
> - uint64_t d = data;
> - return for_each_target("thread", putprocreg, &cr, &d);
> + uint64_t u64 = data;
> + return putreg(REG_CR, &u64);
> }
> OPTCMD_DEFINE_CMD_WITH_ARGS(putcr, putcr, (DATA32));
More information about the Pdbg
mailing list