Skip to content

Commit

Permalink
gdbstub: Replace GET_REG*() macros with gdb_get_reg*() functions
Browse files Browse the repository at this point in the history
This avoids polluting the global namespace with a non-prefixed macro and
makes it obvious in the call sites that we return.

Semi-automatic conversion using, e.g.,
 sed -i 's/GET_REGL(/return gdb_get_regl(mem_buf, /g' target-*/gdbstub.c
followed by manual tweaking for sparc's GET_REGA() and Coding Style.

Acked-by: Michael Walle <[email protected]> (for lm32)
Acked-by: Max Filippov <[email protected]> (for xtensa)
Signed-off-by: Andreas Färber <[email protected]>
  • Loading branch information
afaerber committed Jul 26, 2013
1 parent 25d8ac0 commit 986a299
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 164 deletions.
29 changes: 0 additions & 29 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,35 +489,6 @@ static int put_packet(GDBState *s, const char *buf)
return put_packet_binary(s, buf, strlen(buf));
}

/* The GDB remote protocol transfers values in target byte order. This means
we can use the raw memory access routines to access the value buffer.
Conveniently, these also handle the case where the buffer is mis-aligned.
*/
#define GET_REG8(val) do { \
stb_p(mem_buf, val); \
return 1; \
} while(0)
#define GET_REG16(val) do { \
stw_p(mem_buf, val); \
return 2; \
} while(0)
#define GET_REG32(val) do { \
stl_p(mem_buf, val); \
return 4; \
} while(0)
#define GET_REG64(val) do { \
stq_p(mem_buf, val); \
return 8; \
} while(0)

#if TARGET_LONG_BITS == 64
#define GET_REGL(val) GET_REG64(val)
#define ldtul_p(addr) ldq_p(addr)
#else
#define GET_REGL(val) GET_REG32(val)
#define ldtul_p(addr) ldl_p(addr)
#endif

#if defined(TARGET_I386)

#include "target-i386/gdbstub.c"
Expand Down
37 changes: 37 additions & 0 deletions include/exec/gdbstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ static inline int cpu_index(CPUState *cpu)
#endif
}

/* The GDB remote protocol transfers values in target byte order. This means
* we can use the raw memory access routines to access the value buffer.
* Conveniently, these also handle the case where the buffer is mis-aligned.
*/

static inline int gdb_get_reg8(uint8_t *mem_buf, uint8_t val)
{
stb_p(mem_buf, val);
return 1;
}

static inline int gdb_get_reg16(uint8_t *mem_buf, uint16_t val)
{
stw_p(mem_buf, val);
return 2;
}

static inline int gdb_get_reg32(uint8_t *mem_buf, uint32_t val)
{
stl_p(mem_buf, val);
return 4;
}

static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val)
{
stq_p(mem_buf, val);
return 8;
}

#if TARGET_LONG_BITS == 64
#define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
#define ldtul_p(addr) ldq_p(addr)
#else
#define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
#define ldtul_p(addr) ldl_p(addr)
#endif

#endif

#ifdef CONFIG_USER_ONLY
Expand Down
2 changes: 1 addition & 1 deletion target-alpha/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int cpu_gdb_read_register(CPUAlphaState *env, uint8_t *mem_buf, int n)
default:
return 0;
}
GET_REGL(val);
return gdb_get_regl(mem_buf, val);
}

static int cpu_gdb_write_register(CPUAlphaState *env, uint8_t *mem_buf, int n)
Expand Down
6 changes: 3 additions & 3 deletions target-arm/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static int cpu_gdb_read_register(CPUARMState *env, uint8_t *mem_buf, int n)
{
if (n < 16) {
/* Core integer register. */
GET_REG32(env->regs[n]);
return gdb_get_reg32(mem_buf, env->regs[n]);
}
if (n < 24) {
/* FPA registers. */
Expand All @@ -44,10 +44,10 @@ static int cpu_gdb_read_register(CPUARMState *env, uint8_t *mem_buf, int n)
if (gdb_has_xml) {
return 0;
}
GET_REG32(0);
return gdb_get_reg32(mem_buf, 0);
case 25:
/* CPSR */
GET_REG32(cpsr_read(env));
return gdb_get_reg32(mem_buf, cpsr_read(env));
}
/* Unknown register. */
return 0;
Expand Down
30 changes: 15 additions & 15 deletions target-cris/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ static int
read_register_crisv10(CPUCRISState *env, uint8_t *mem_buf, int n)
{
if (n < 15) {
GET_REG32(env->regs[n]);
return gdb_get_reg32(mem_buf, env->regs[n]);
}

if (n == 15) {
GET_REG32(env->pc);
return gdb_get_reg32(mem_buf, env->pc);
}

if (n < 32) {
switch (n) {
case 16:
GET_REG8(env->pregs[n - 16]);
return gdb_get_reg8(mem_buf, env->pregs[n - 16]);
case 17:
GET_REG8(env->pregs[n - 16]);
return gdb_get_reg8(mem_buf, env->pregs[n - 16]);
case 20:
case 21:
GET_REG16(env->pregs[n - 16]);
return gdb_get_reg16(mem_buf, env->pregs[n - 16]);
default:
if (n >= 23) {
GET_REG32(env->pregs[n - 16]);
return gdb_get_reg32(mem_buf, env->pregs[n - 16]);
}
break;
}
Expand All @@ -58,28 +58,28 @@ static int cpu_gdb_read_register(CPUCRISState *env, uint8_t *mem_buf, int n)

srs = env->pregs[PR_SRS];
if (n < 16) {
GET_REG32(env->regs[n]);
return gdb_get_reg32(mem_buf, env->regs[n]);
}

if (n >= 21 && n < 32) {
GET_REG32(env->pregs[n - 16]);
return gdb_get_reg32(mem_buf, env->pregs[n - 16]);
}
if (n >= 33 && n < 49) {
GET_REG32(env->sregs[srs][n - 33]);
return gdb_get_reg32(mem_buf, env->sregs[srs][n - 33]);
}
switch (n) {
case 16:
GET_REG8(env->pregs[0]);
return gdb_get_reg8(mem_buf, env->pregs[0]);
case 17:
GET_REG8(env->pregs[1]);
return gdb_get_reg8(mem_buf, env->pregs[1]);
case 18:
GET_REG32(env->pregs[2]);
return gdb_get_reg32(mem_buf, env->pregs[2]);
case 19:
GET_REG8(srs);
return gdb_get_reg8(mem_buf, srs);
case 20:
GET_REG16(env->pregs[4]);
return gdb_get_reg16(mem_buf, env->pregs[4]);
case 32:
GET_REG32(env->pc);
return gdb_get_reg32(mem_buf, env->pc);
}

return 0;
Expand Down
42 changes: 21 additions & 21 deletions target-i386/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static int cpu_gdb_read_register(CPUX86State *env, uint8_t *mem_buf, int n)
{
if (n < CPU_NB_REGS) {
if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) {
GET_REG64(env->regs[gpr_map[n]]);
return gdb_get_reg64(mem_buf, env->regs[gpr_map[n]]);
} else if (n < CPU_NB_REGS32) {
GET_REG32(env->regs[gpr_map32[n]]);
return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]);
}
} else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
#ifdef USE_X86LDOUBLE
Expand All @@ -63,46 +63,46 @@ static int cpu_gdb_read_register(CPUX86State *env, uint8_t *mem_buf, int n)
switch (n) {
case IDX_IP_REG:
if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) {
GET_REG64(env->eip);
return gdb_get_reg64(mem_buf, env->eip);
} else {
GET_REG32(env->eip);
return gdb_get_reg32(mem_buf, env->eip);
}
case IDX_FLAGS_REG:
GET_REG32(env->eflags);
return gdb_get_reg32(mem_buf, env->eflags);

case IDX_SEG_REGS:
GET_REG32(env->segs[R_CS].selector);
return gdb_get_reg32(mem_buf, env->segs[R_CS].selector);
case IDX_SEG_REGS + 1:
GET_REG32(env->segs[R_SS].selector);
return gdb_get_reg32(mem_buf, env->segs[R_SS].selector);
case IDX_SEG_REGS + 2:
GET_REG32(env->segs[R_DS].selector);
return gdb_get_reg32(mem_buf, env->segs[R_DS].selector);
case IDX_SEG_REGS + 3:
GET_REG32(env->segs[R_ES].selector);
return gdb_get_reg32(mem_buf, env->segs[R_ES].selector);
case IDX_SEG_REGS + 4:
GET_REG32(env->segs[R_FS].selector);
return gdb_get_reg32(mem_buf, env->segs[R_FS].selector);
case IDX_SEG_REGS + 5:
GET_REG32(env->segs[R_GS].selector);
return gdb_get_reg32(mem_buf, env->segs[R_GS].selector);

case IDX_FP_REGS + 8:
GET_REG32(env->fpuc);
return gdb_get_reg32(mem_buf, env->fpuc);
case IDX_FP_REGS + 9:
GET_REG32((env->fpus & ~0x3800) |
(env->fpstt & 0x7) << 11);
return gdb_get_reg32(mem_buf, (env->fpus & ~0x3800) |
(env->fpstt & 0x7) << 11);
case IDX_FP_REGS + 10:
GET_REG32(0); /* ftag */
return gdb_get_reg32(mem_buf, 0); /* ftag */
case IDX_FP_REGS + 11:
GET_REG32(0); /* fiseg */
return gdb_get_reg32(mem_buf, 0); /* fiseg */
case IDX_FP_REGS + 12:
GET_REG32(0); /* fioff */
return gdb_get_reg32(mem_buf, 0); /* fioff */
case IDX_FP_REGS + 13:
GET_REG32(0); /* foseg */
return gdb_get_reg32(mem_buf, 0); /* foseg */
case IDX_FP_REGS + 14:
GET_REG32(0); /* fooff */
return gdb_get_reg32(mem_buf, 0); /* fooff */
case IDX_FP_REGS + 15:
GET_REG32(0); /* fop */
return gdb_get_reg32(mem_buf, 0); /* fop */

case IDX_MXCSR_REG:
GET_REG32(env->mxcsr);
return gdb_get_reg32(mem_buf, env->mxcsr);
}
}
return 0;
Expand Down
16 changes: 8 additions & 8 deletions target-lm32/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
static int cpu_gdb_read_register(CPULM32State *env, uint8_t *mem_buf, int n)
{
if (n < 32) {
GET_REG32(env->regs[n]);
return gdb_get_reg32(mem_buf, env->regs[n]);
} else {
switch (n) {
case 32:
GET_REG32(env->pc);
return gdb_get_reg32(mem_buf, env->pc);
/* FIXME: put in right exception ID */
case 33:
GET_REG32(0);
return gdb_get_reg32(mem_buf, 0);
case 34:
GET_REG32(env->eba);
return gdb_get_reg32(mem_buf, env->eba);
case 35:
GET_REG32(env->deba);
return gdb_get_reg32(mem_buf, env->deba);
case 36:
GET_REG32(env->ie);
return gdb_get_reg32(mem_buf, env->ie);
case 37:
GET_REG32(lm32_pic_get_im(env->pic_state));
return gdb_get_reg32(mem_buf, lm32_pic_get_im(env->pic_state));
case 38:
GET_REG32(lm32_pic_get_ip(env->pic_state));
return gdb_get_reg32(mem_buf, lm32_pic_get_ip(env->pic_state));
}
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions target-m68k/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ static int cpu_gdb_read_register(CPUM68KState *env, uint8_t *mem_buf, int n)
{
if (n < 8) {
/* D0-D7 */
GET_REG32(env->dregs[n]);
return gdb_get_reg32(mem_buf, env->dregs[n]);
} else if (n < 16) {
/* A0-A7 */
GET_REG32(env->aregs[n - 8]);
return gdb_get_reg32(mem_buf, env->aregs[n - 8]);
} else {
switch (n) {
case 16:
GET_REG32(env->sr);
return gdb_get_reg32(mem_buf, env->sr);
case 17:
GET_REG32(env->pc);
return gdb_get_reg32(mem_buf, env->pc);
}
}
/* FP registers not included here because they vary between
Expand Down
4 changes: 2 additions & 2 deletions target-microblaze/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
static int cpu_gdb_read_register(CPUMBState *env, uint8_t *mem_buf, int n)
{
if (n < 32) {
GET_REG32(env->regs[n]);
return gdb_get_reg32(mem_buf, env->regs[n]);
} else {
GET_REG32(env->sregs[n - 32]);
return gdb_get_reg32(mem_buf, env->sregs[n - 32]);
}
return 0;
}
Expand Down
31 changes: 17 additions & 14 deletions target-mips/gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,47 @@
static int cpu_gdb_read_register(CPUMIPSState *env, uint8_t *mem_buf, int n)
{
if (n < 32) {
GET_REGL(env->active_tc.gpr[n]);
return gdb_get_regl(mem_buf, env->active_tc.gpr[n]);
}
if (env->CP0_Config1 & (1 << CP0C1_FP)) {
if (n >= 38 && n < 70) {
if (env->CP0_Status & (1 << CP0St_FR)) {
GET_REGL(env->active_fpu.fpr[n - 38].d);
return gdb_get_regl(mem_buf,
env->active_fpu.fpr[n - 38].d);
} else {
GET_REGL(env->active_fpu.fpr[n - 38].w[FP_ENDIAN_IDX]);
return gdb_get_regl(mem_buf,
env->active_fpu.fpr[n - 38].w[FP_ENDIAN_IDX]);
}
}
switch (n) {
case 70:
GET_REGL((int32_t)env->active_fpu.fcr31);
return gdb_get_regl(mem_buf, (int32_t)env->active_fpu.fcr31);
case 71:
GET_REGL((int32_t)env->active_fpu.fcr0);
return gdb_get_regl(mem_buf, (int32_t)env->active_fpu.fcr0);
}
}
switch (n) {
case 32:
GET_REGL((int32_t)env->CP0_Status);
return gdb_get_regl(mem_buf, (int32_t)env->CP0_Status);
case 33:
GET_REGL(env->active_tc.LO[0]);
return gdb_get_regl(mem_buf, env->active_tc.LO[0]);
case 34:
GET_REGL(env->active_tc.HI[0]);
return gdb_get_regl(mem_buf, env->active_tc.HI[0]);
case 35:
GET_REGL(env->CP0_BadVAddr);
return gdb_get_regl(mem_buf, env->CP0_BadVAddr);
case 36:
GET_REGL((int32_t)env->CP0_Cause);
return gdb_get_regl(mem_buf, (int32_t)env->CP0_Cause);
case 37:
GET_REGL(env->active_tc.PC | !!(env->hflags & MIPS_HFLAG_M16));
return gdb_get_regl(mem_buf, env->active_tc.PC |
!!(env->hflags & MIPS_HFLAG_M16));
case 72:
GET_REGL(0); /* fp */
return gdb_get_regl(mem_buf, 0); /* fp */
case 89:
GET_REGL((int32_t)env->CP0_PRid);
return gdb_get_regl(mem_buf, (int32_t)env->CP0_PRid);
}
if (n >= 73 && n <= 88) {
/* 16 embedded regs. */
GET_REGL(0);
return gdb_get_regl(mem_buf, 0);
}

return 0;
Expand Down
Loading

0 comments on commit 986a299

Please sign in to comment.