[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v9 23/27] gdbstub: Implement qemu physical memor
From: |
Alex Bennée |
Subject: |
Re: [Qemu-devel] [PATCH v9 23/27] gdbstub: Implement qemu physical memory mode |
Date: |
Wed, 15 May 2019 16:13:03 +0100 |
User-agent: |
mu4e 1.3.1; emacs 26.1 |
Jon Doron <address@hidden> writes:
> Add a new query/set which changes the memory GDB sees to physical memory
> only.
>
> gdb> maint packet qqemu.PhyMemMode
> will reply the current phy_mem_mode state (1 for enabled, 0 for disabled)
> gdb> maint packet Qqemu.PhyMemMode:1
> Will make GDB read/write only to physical memory, set to 0 to disable
>
> Signed-off-by: Jon Doron <address@hidden>
> ---
> gdbstub.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 55 insertions(+), 3 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 00c07d6ec0..88ff6224e6 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -46,11 +46,23 @@
> #define GDB_ATTACHED "1"
> #endif
>
> +static int phy_memory_mode;
> +
> static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
> uint8_t *buf, int len, bool
> is_write)
> {
> - CPUClass *cc = CPU_GET_CLASS(cpu);
> + CPUClass *cc;
>
> + if (phy_memory_mode) {
> + if (is_write) {
> + cpu_physical_memory_write(addr, buf, len);
> + } else {
> + cpu_physical_memory_read(addr, buf, len);
> + }
> + return 0;
> + }
> +
I think this is the commit that breaks the build. As the gdbstub can run
for both system and linux-user emulation modes you need to take care to
disable the bits that don't make sense for linux-user emulation. You'll
see other places in the code doing that with #if[n]def CONFIG_USER_ONLY.
> + cc = CPU_GET_CLASS(cpu);
> if (cc->memory_rw_debug) {
> return cc->memory_rw_debug(cpu, addr, buf, len, is_write);
> }
> @@ -2129,7 +2141,29 @@ static void handle_query_attached(GdbCmdContext
> *gdb_ctx, void *user_ctx)
>
> static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void
> *user_ctx)
> {
> - put_packet(gdb_ctx->s, "sstepbits;sstep");
> + put_packet(gdb_ctx->s, "sstepbits;sstep;PhyMemMode");
> +}
> +
> +static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx,
> + void *user_ctx)
> +{
> + snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d",
> phy_memory_mode);
> + put_packet(gdb_ctx->s, gdb_ctx->str_buf);
> +}
> +
> +static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void
> *user_ctx)
> +{
> + if (!gdb_ctx->num_params) {
> + put_packet(gdb_ctx->s, "E22");
> + return;
> + }
> +
> + if (!gdb_ctx->params[0].val_ul) {
> + phy_memory_mode = 0;
> + } else {
> + phy_memory_mode = 1;
> + }
> + put_packet(gdb_ctx->s, "OK");
> }
>
> static GdbCmdParseEntry gdb_gen_query_set_common_table[] = {
> @@ -2212,6 +2246,20 @@ static GdbCmdParseEntry gdb_gen_query_table[] = {
> .handler = handle_query_qemu_supported,
> .cmd = "qemu.Supported",
> },
> + {
> + .handler = handle_query_qemu_phy_mem_mode,
> + .cmd = "qemu.PhyMemMode",
> + },
> +};
> +
> +static GdbCmdParseEntry gdb_gen_set_table[] = {
> + /* Order is important if has same prefix */
> + {
> + .handler = handle_set_qemu_phy_mem_mode,
> + .cmd = "qemu.PhyMemMode:",
> + .cmd_startswith = 1,
> + .schema = "l0"
> + },
> };
>
> static void handle_gen_query(GdbCmdContext *gdb_ctx, void *user_ctx)
> @@ -2245,7 +2293,11 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx,
> void *user_ctx)
> return;
> }
>
> - put_packet(gdb_ctx->s, "");
> + if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data,
> + gdb_gen_set_table,
> + ARRAY_SIZE(gdb_gen_set_table))) {
> + put_packet(gdb_ctx->s, "");
> + }
> }
>
> static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx)
--
Alex Bennée
- Re: [Qemu-devel] [PATCH v9 20/27] gdbstub: Implement target halted (? pkt) with new infra, (continued)
- [Qemu-devel] [PATCH v9 12/27] gdbstub: Implement read memory (m pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 16/27] gdbstub: Implement step (s pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 08/27] gdbstub: Implement remove breakpoint (z pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 11/27] gdbstub: Implement write memory (M pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 23/27] gdbstub: Implement qemu physical memory mode, Jon Doron, 2019/05/02
- Re: [Qemu-devel] [PATCH v9 23/27] gdbstub: Implement qemu physical memory mode,
Alex Bennée <=
- [Qemu-devel] [PATCH v9 26/27] gdbstub: Add support to read a MSR for KVM target, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 19/27] gdbstub: Implement generic set (Q pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 18/27] gdbstub: Implement generic query (q pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 05/27] gdbstub: Implement continue with signal (C pkt) with new infra, Jon Doron, 2019/05/02
- [Qemu-devel] [PATCH v9 13/27] gdbstub: Implement write all registers (G pkt) with new infra, Jon Doron, 2019/05/02