From: Davidson Francis <davidsondfgl@gmail.com>
To: qemu-devel@nongnu.org
Cc: davidsondfgl@gmail.com, Paolo Bonzini <pbonzini@redhat.com>,
Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH] target/i386: Improve 16-bit/real mode debug support in GDB
Date: Sat, 21 Dec 2024 02:45:49 -0300 [thread overview]
Message-ID: <20241221054549.21883-1-davidsondfgl@gmail.com> (raw)
In-Reply-To: <20241219013535.GB4298@darkstar>
Debugging 16-bit/real mode code in QEMU+GDB is challenging due to
incorrect architecture detection and segmented memory addressing issues.
This patch improves the debugging experience by reporting i8086
architecture to GDB when in real mode and converting segmented addresses
(CS:EIP, SS:ESP) to their physical equivalents when reporting to GDB.
This enables proper instruction disassembly and stack inspection without
complex workarounds.
Note: Mode switches after GDB attachment still require manual
architecture change, as GDB RSP does not support runtime architecture
switches.
Signed-off-by: Davidson Francis <davidsondfgl@gmail.com>
---
target/i386/cpu.c | 8 +++++++-
target/i386/gdbstub.c | 15 +++++++++++++--
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 5253399459..65bdc48cc0 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6404,7 +6404,13 @@ static const gchar *x86_gdb_arch_name(CPUState *cs)
#ifdef TARGET_X86_64
return "i386:x86-64";
#else
- return "i386";
+ X86CPU *cpu = X86_CPU(cs);
+ CPUX86State *env = &cpu->env;
+ if (env->cr[0] & 1) {
+ return "i386";
+ } else {
+ return "i8086";
+ }
#endif
}
diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index 04c49e802d..d600aee953 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -136,7 +136,13 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
return gdb_get_regl(mem_buf, 0);
}
} else {
- return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]);
+ if (n != R_ESP || (env->cr[0] & 1)) {
+ return gdb_get_reg32(mem_buf, env->regs[gpr_map32[n]]);
+ } else {
+ return gdb_get_reg32(mem_buf,
+ (env->segs[R_SS].selector << 4) +
+ env->regs[gpr_map32[n]]);
+ }
}
} else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
int st_index = n - IDX_FP_REGS;
@@ -155,7 +161,12 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
} else {
switch (n) {
case IDX_IP_REG:
- return gdb_get_reg(env, mem_buf, env->eip);
+ if (TARGET_LONG_BITS != 32 || (env->cr[0] & 1)) {
+ return gdb_get_reg(env, mem_buf, env->eip);
+ } else {
+ return gdb_get_reg(env, mem_buf,
+ (env->segs[R_CS].selector << 4) + env->eip);
+ }
case IDX_FLAGS_REG:
return gdb_get_reg32(mem_buf, env->eflags);
--
2.37.3
next prev parent reply other threads:[~2024-12-21 5:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 1:35 Ideas to Improve GDB Stub in Qemu for i8086 Davidson Francis
2024-12-19 16:51 ` Warner Losh
2024-12-20 0:34 ` Davidson Francis
2024-12-20 11:14 ` Bernhard Beschow
2024-12-21 5:45 ` Davidson Francis [this message]
2025-03-07 19:26 ` [PATCH] target/i386: Improve 16-bit/real mode debug support in GDB Bernhard Beschow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241221054549.21883-1-davidsondfgl@gmail.com \
--to=davidsondfgl@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.