Skip to contentSkip to conversation

target-i386: gdbserver: Return CS:IP as EIP on 16-bit mode

PATCH In review Ismael Luceno 2 participants 2 messages Jul 14, 2015 – Jul 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-i386: gdbserver: Return CS:IP as EIP on 16-bit mode

While far from ideal, that seems to be what GDB and most other debuggers expect.

---
 target-i386/gdbstub.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target-i386/gdbstub.c +4 -1
index ff99cfb..754ea77 100644
@@ -70,8 +70,11 @@ int x86_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
         case IDX_IP_REG:
             if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) {
                 return gdb_get_reg64(mem_buf, env->eip);
-            } else {
+            } else if (env->hflags & HF_PE_MASK) {
                 return gdb_get_reg32(mem_buf, env->eip);
+            } else {
+                return gdb_get_reg32(mem_buf, (env->segs[R_CS].selector << 4)
+                                              + env->eip);
             }
         case IDX_FLAGS_REG:
             return gdb_get_reg32(mem_buf, env->eflags);
Signature · 1 line
2.4.5
#1 lore raw
Quoted 1 line · Ismael Luceno

While far from ideal, that seems to be what GDB and most other debuggers expect.

If so, you'd surely want a similar change to the write side, then.

r~