[4390] Add x86_64 gdb stub for qemu (Jason Wessel).
Revision: 4390
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4390 Author: edgar_igl Date: 2008-05-09 08:23:19 +0000 (Fri, 09 May 2008)
Log Message:
-----------
Add x86_64 gdb stub for qemu (Jason Wessel).
Modified Paths:
--------------
trunk/gdbstub.c
Modified: trunk/gdbstub.c
===================================================================
gdbstub.c +133 -1
@@ -233,9 +233,141 @@ }return 0 ; } +#if defined(TARGET_X86_64 ) -#if defined(TARGET_I386 ) +static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) +{ +uint8_t *p = mem_buf; +int i, fpus; +#define PUTREG (x) do { \ + target_ulong reg = tswapl(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREG32 (x) do { \ + uint32_t reg = tswap32(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREGF (x) do { \ + memcpy(p, &(x), 10); \ + p += sizeof (x); \ + } while (0) + +PUTREG (env->regs[R_EAX ]); +PUTREG (env->regs[R_EBX ]); +PUTREG (env->regs[R_ECX ]); +PUTREG (env->regs[R_EDX ]); +PUTREG (env->regs[R_ESI ]); +PUTREG (env->regs[R_EDI ]); +PUTREG (env->regs[R_EBP ]); +PUTREG (env->regs[R_ESP ]); +PUTREG (env->regs[8 ]); +PUTREG (env->regs[9 ]); +PUTREG (env->regs[10 ]); +PUTREG (env->regs[11 ]); +PUTREG (env->regs[12 ]); +PUTREG (env->regs[13 ]); +PUTREG (env->regs[14 ]); +PUTREG (env->regs[15 ]); + +PUTREG (env->eip); +PUTREG32 (env->eflags); +PUTREG32 (env->segs[R_CS ].selector); +PUTREG32 (env->segs[R_SS ].selector); +PUTREG32 (env->segs[R_DS ].selector); +PUTREG32 (env->segs[R_ES ].selector); +PUTREG32 (env->segs[R_FS ].selector); +PUTREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +PUTREGF (env->fpregs[i]); + } +PUTREG32 (env->fpuc); + fpus = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; +PUTREG32 (fpus); +PUTREG32 (0 );/* XXX: convert tags */ +PUTREG32 (0 );/* fiseg */ +PUTREG32 (0 );/* fioff */ +PUTREG32 (0 );/* foseg */ +PUTREG32 (0 );/* fooff */ +PUTREG32 (0 );/* fop */ + +#undef PUTREG +#undef PUTREG32 +#undef PUTREGF + +return p - mem_buf; +} + +static void cpu_gdb_write_registers (CPUState *env,uint8_t *mem_buf,int size) +{ +uint8_t *p = mem_buf; +uint32_t junk; +int i, fpus; + +#define GETREG (x) do { \ + target_ulong reg; \ + memcpy(®, p, sizeof reg); \ + x = tswapl(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREG32 (x) do { \ + uint32_t reg; \ + memcpy(®, p, sizeof reg); \ + x = tswap32(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREGF (x) do { \ + memcpy(&(x), p, 10); \ + p += 10; \ + } while (0) + +GETREG (env->regs[R_EAX ]); +GETREG (env->regs[R_EBX ]); +GETREG (env->regs[R_ECX ]); +GETREG (env->regs[R_EDX ]); +GETREG (env->regs[R_ESI ]); +GETREG (env->regs[R_EDI ]); +GETREG (env->regs[R_EBP ]); +GETREG (env->regs[R_ESP ]); +GETREG (env->regs[8 ]); +GETREG (env->regs[9 ]); +GETREG (env->regs[10 ]); +GETREG (env->regs[11 ]); +GETREG (env->regs[12 ]); +GETREG (env->regs[13 ]); +GETREG (env->regs[14 ]); +GETREG (env->regs[15 ]); + +GETREG (env->eip); +GETREG32 (env->eflags); +GETREG32 (env->segs[R_CS ].selector); +GETREG32 (env->segs[R_SS ].selector); +GETREG32 (env->segs[R_DS ].selector); +GETREG32 (env->segs[R_ES ].selector); +GETREG32 (env->segs[R_FS ].selector); +GETREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +GETREGF (env->fpregs[i]); + } +GETREG32 (env->fpuc); +GETREG32 (fpus);/* XXX: convert fpus */ +GETREG32 (junk);/* XXX: convert tags */ +GETREG32 (junk);/* fiseg */ +GETREG32 (junk);/* fioff */ +GETREG32 (junk);/* foseg */ +GETREG32 (junk);/* fooff */ +GETREG32 (junk);/* fop */ + +#undef GETREG +#undef GETREG32 +#undef GETREGF +} + +#elif defined(TARGET_I386 )static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) {int i, fpus;
Quoted 8 lines · Edgar E. Iglesias
Revision: 4390
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4390 Author: edgar_igl Date: 2008-05-09 08:23:19 +0000 (Fri, 09 May 2008)Log Message:
-----------
Addx86_64gdb stub for qemu (Jason Wessel).
Actually, that used to be my old patch :). But it is redundant now (x86-64 debugging works like charm). Please revert.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 6 lines · Jan Kiszka
Quoted 5 lines · Edgar E. Iglesias
Revision: 4390
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4390 Author: edgar_igl Date: 2008-05-09 08:23:19 +0000 (Fri, 09 May 2008)
Quoted 6 lines
Quoted 3 lines
Log Message:
-----------
Addx86_64gdb stub for qemu (Jason Wessel).Actually, that used to be my old patch :). But it is redundant now (x86-64 debugging works like charm). Please revert.
Right, I see now those part are already taken care of. Sorry.
Signature · 2 lines
Edgar E. Iglesias Axis Communications AB
This patch is not correct as it breaks 32 bit support for x86_64. The correct solution is to add 64 bit support in the i386 case.
Moreover, it would be better not to use macros when inline functions could do the same.
Regards,
Fabrice.
Quoted 165 lines · Edgar E. Iglesias
Revision: 4390
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4390 Author: edgar_igl Date: 2008-05-09 08:23:19 +0000 (Fri, 09 May 2008)Log Message:
-----------
Addx86_64gdb stub for qemu (Jason Wessel).Modified Paths:
--------------
trunk/gdbstub.cModified:
trunk/gdbstub.c
===================================================================gdbstub.c +133
-1@@ -233,9 +233,141 @@ }return 0 ; } +#if defined(TARGET_X86_64 ) -#if defined(TARGET_I386 ) +static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) +{ +uint8_t *p = mem_buf; +int i, fpus; +#define PUTREG (x) do { \ + target_ulong reg = tswapl(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREG32 (x) do { \ + uint32_t reg = tswap32(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREGF (x) do { \ + memcpy(p, &(x), 10); \ + p += sizeof (x); \ + } while (0) + +PUTREG (env->regs[R_EAX ]); +PUTREG (env->regs[R_EBX ]); +PUTREG (env->regs[R_ECX ]); +PUTREG (env->regs[R_EDX ]); +PUTREG (env->regs[R_ESI ]); +PUTREG (env->regs[R_EDI ]); +PUTREG (env->regs[R_EBP ]); +PUTREG (env->regs[R_ESP ]); +PUTREG (env->regs[8 ]); +PUTREG (env->regs[9 ]); +PUTREG (env->regs[10 ]); +PUTREG (env->regs[11 ]); +PUTREG (env->regs[12 ]); +PUTREG (env->regs[13 ]); +PUTREG (env->regs[14 ]); +PUTREG (env->regs[15 ]); + +PUTREG (env->eip); +PUTREG32 (env->eflags); +PUTREG32 (env->segs[R_CS ].selector); +PUTREG32 (env->segs[R_SS ].selector); +PUTREG32 (env->segs[R_DS ].selector); +PUTREG32 (env->segs[R_ES ].selector); +PUTREG32 (env->segs[R_FS ].selector); +PUTREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +PUTREGF (env->fpregs[i]); + } +PUTREG32 (env->fpuc); + fpus = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; +PUTREG32 (fpus); +PUTREG32 (0 );/* XXX: convert tags */ +PUTREG32 (0 );/* fiseg */ +PUTREG32 (0 );/* fioff */ +PUTREG32 (0 );/* foseg */ +PUTREG32 (0 );/* fooff */ +PUTREG32 (0 );/* fop */ + +#undef PUTREG +#undef PUTREG32 +#undef PUTREGF + +return p - mem_buf; +} + +static void cpu_gdb_write_registers (CPUState *env,uint8_t *mem_buf,int size) +{ +uint8_t *p = mem_buf; +uint32_t junk; +int i, fpus; + +#define GETREG (x) do { \ + target_ulong reg; \ + memcpy(®, p, sizeof reg); \ + x = tswapl(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREG32 (x) do { \ + uint32_t reg; \ + memcpy(®, p, sizeof reg); \ + x = tswap32(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREGF (x) do { \ + memcpy(&(x), p, 10); \ + p += 10; \ + } while (0) + +GETREG (env->regs[R_EAX ]); +GETREG (env->regs[R_EBX ]); +GETREG (env->regs[R_ECX ]); +GETREG (env->regs[R_EDX ]); +GETREG (env->regs[R_ESI ]); +GETREG (env->regs[R_EDI ]); +GETREG (env->regs[R_EBP ]); +GETREG (env->regs[R_ESP ]); +GETREG (env->regs[8 ]); +GETREG (env->regs[9 ]); +GETREG (env->regs[10 ]); +GETREG (env->regs[11 ]); +GETREG (env->regs[12 ]); +GETREG (env->regs[13 ]); +GETREG (env->regs[14 ]); +GETREG (env->regs[15 ]); + +GETREG (env->eip); +GETREG32 (env->eflags); +GETREG32 (env->segs[R_CS ].selector); +GETREG32 (env->segs[R_SS ].selector); +GETREG32 (env->segs[R_DS ].selector); +GETREG32 (env->segs[R_ES ].selector); +GETREG32 (env->segs[R_FS ].selector); +GETREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +GETREGF (env->fpregs[i]); + } +GETREG32 (env->fpuc); +GETREG32 (fpus);/* XXX: convert fpus */ +GETREG32 (junk);/* XXX: convert tags */ +GETREG32 (junk);/* fiseg */ +GETREG32 (junk);/* fioff */ +GETREG32 (junk);/* foseg */ +GETREG32 (junk);/* fooff */ +GETREG32 (junk);/* fop */ + +#undef GETREG +#undef GETREG32 +#undef GETREGF +} + +#elif defined(TARGET_I386 )static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) {int i, fpus;
I see this is already reverted :-)
It was not my intention when I followed up to the original post to have this one committed, it is from an older branch in the 0.9.0 era.
The single stepping patch however would have been fine as it was "carry forward work" against the SVN HEAD.
Thanks,
Jason.
Quoted 165 lines · Edgar E. Iglesias
Revision: 4390
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4390 Author: edgar_igl Date: 2008-05-09 08:23:19 +0000 (Fri, 09 May 2008)Log Message:
-----------
Addx86_64gdb stub for qemu (Jason Wessel).Modified Paths:
--------------
trunk/gdbstub.cModified:
trunk/gdbstub.c
===================================================================gdbstub.c +133
-1@@ -233,9 +233,141 @@ }return 0 ; } +#if defined(TARGET_X86_64 ) -#if defined(TARGET_I386 ) +static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) +{ +uint8_t *p = mem_buf; +int i, fpus; +#define PUTREG (x) do { \ + target_ulong reg = tswapl(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREG32 (x) do { \ + uint32_t reg = tswap32(x); \ + memcpy(p, ®, sizeof reg); \ + p += sizeof reg; \ + } while (0) +#define PUTREGF (x) do { \ + memcpy(p, &(x), 10); \ + p += sizeof (x); \ + } while (0) + +PUTREG (env->regs[R_EAX ]); +PUTREG (env->regs[R_EBX ]); +PUTREG (env->regs[R_ECX ]); +PUTREG (env->regs[R_EDX ]); +PUTREG (env->regs[R_ESI ]); +PUTREG (env->regs[R_EDI ]); +PUTREG (env->regs[R_EBP ]); +PUTREG (env->regs[R_ESP ]); +PUTREG (env->regs[8 ]); +PUTREG (env->regs[9 ]); +PUTREG (env->regs[10 ]); +PUTREG (env->regs[11 ]); +PUTREG (env->regs[12 ]); +PUTREG (env->regs[13 ]); +PUTREG (env->regs[14 ]); +PUTREG (env->regs[15 ]); + +PUTREG (env->eip); +PUTREG32 (env->eflags); +PUTREG32 (env->segs[R_CS ].selector); +PUTREG32 (env->segs[R_SS ].selector); +PUTREG32 (env->segs[R_DS ].selector); +PUTREG32 (env->segs[R_ES ].selector); +PUTREG32 (env->segs[R_FS ].selector); +PUTREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +PUTREGF (env->fpregs[i]); + } +PUTREG32 (env->fpuc); + fpus = (env->fpus & ~0x3800 ) | (env->fpstt &0x7 ) <<11 ; +PUTREG32 (fpus); +PUTREG32 (0 );/* XXX: convert tags */ +PUTREG32 (0 );/* fiseg */ +PUTREG32 (0 );/* fioff */ +PUTREG32 (0 );/* foseg */ +PUTREG32 (0 );/* fooff */ +PUTREG32 (0 );/* fop */ + +#undef PUTREG +#undef PUTREG32 +#undef PUTREGF + +return p - mem_buf; +} + +static void cpu_gdb_write_registers (CPUState *env,uint8_t *mem_buf,int size) +{ +uint8_t *p = mem_buf; +uint32_t junk; +int i, fpus; + +#define GETREG (x) do { \ + target_ulong reg; \ + memcpy(®, p, sizeof reg); \ + x = tswapl(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREG32 (x) do { \ + uint32_t reg; \ + memcpy(®, p, sizeof reg); \ + x = tswap32(reg); \ + p += sizeof reg; \ + } while (0) +#define GETREGF (x) do { \ + memcpy(&(x), p, 10); \ + p += 10; \ + } while (0) + +GETREG (env->regs[R_EAX ]); +GETREG (env->regs[R_EBX ]); +GETREG (env->regs[R_ECX ]); +GETREG (env->regs[R_EDX ]); +GETREG (env->regs[R_ESI ]); +GETREG (env->regs[R_EDI ]); +GETREG (env->regs[R_EBP ]); +GETREG (env->regs[R_ESP ]); +GETREG (env->regs[8 ]); +GETREG (env->regs[9 ]); +GETREG (env->regs[10 ]); +GETREG (env->regs[11 ]); +GETREG (env->regs[12 ]); +GETREG (env->regs[13 ]); +GETREG (env->regs[14 ]); +GETREG (env->regs[15 ]); + +GETREG (env->eip); +GETREG32 (env->eflags); +GETREG32 (env->segs[R_CS ].selector); +GETREG32 (env->segs[R_SS ].selector); +GETREG32 (env->segs[R_DS ].selector); +GETREG32 (env->segs[R_ES ].selector); +GETREG32 (env->segs[R_FS ].selector); +GETREG32 (env->segs[R_GS ].selector); +/* XXX: convert floats */ +for (i =0 ; i <8 ; i++) { +GETREGF (env->fpregs[i]); + } +GETREG32 (env->fpuc); +GETREG32 (fpus);/* XXX: convert fpus */ +GETREG32 (junk);/* XXX: convert tags */ +GETREG32 (junk);/* fiseg */ +GETREG32 (junk);/* fioff */ +GETREG32 (junk);/* foseg */ +GETREG32 (junk);/* fooff */ +GETREG32 (junk);/* fop */ + +#undef GETREG +#undef GETREG32 +#undef GETREGF +} + +#elif defined(TARGET_I386 )static int cpu_gdb_read_registers (CPUState *env,uint8_t *mem_buf) {int i, fpus;
Quoted 4 lines · Jason Wessel
I see this is already reverted :-)
It was not my intention when I followed up to the original post to have this one committed, it is from an older branch in the 0.9.0 era.
My fault sorry, I got confused.
Quoted 2 lines
The single stepping patch however would have been fine as it was "carry forward work" against the SVN HEAD.
Yes, I only reverted the x86-64 part. The singelstepping should still be there.
Best regards
Signature · 2 lines
Edgar E. Iglesias Axis Communications AB
Quoted 1 line · Jason Wessel
I see this is already reverted :-)
I am writing a new version.
Fabrice.