Few minor improvements of monitor disas command (v3)
cover Few minor improvements of monitor disas command (v3)
I finaly managed to move the target depend code in 'target-*/'.
Fabien Chouteau (4):
Fix coding style
Improve Monitor disas with symbol lookup Refactoring MonitorDef array
Add ARM registers definitions for Monitor commands
disas.c | 19 ++- include/monitor/monitor.h | 16 ++ include/qemu/typedefs.h | 1 + include/qom/cpu.h | 3 + monitor.c | 399 +------------------------------------------ target-arm/Makefile.objs | 2 +- target-arm/cpu.c | 5 + target-arm/monitor.c | 40 +++++ target-i386/Makefile.objs | 2 +- target-i386/cpu.c | 6 +- target-i386/monitor.c | 63 +++++++ target-ppc/Makefile.objs | 2 +- target-ppc/monitor.c | 234 +++++++++++++++++++++++++ target-ppc/translate_init.c | 5 + target-sparc/Makefile.objs | 2 +- target-sparc/cpu.c | 5 + target-sparc/monitor.c | 138 +++++++++++++++ 17 files changed, 542 insertions(+), 400 deletions(-) create mode 100644 target-arm/monitor.c create mode 100644 target-i386/monitor.c create mode 100644 target-ppc/monitor.c create mode 100644 target-sparc/monitor.c
Signature · 1 line
1.7.9.5
PATCH 1/4 Fix coding style
--- disas.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
disas.c +6 -5
@@ -506,12 +506,13 @@ void monitor_disas(Monitor *mon, CPUArchState *env,return ;#endif -for (i =0 ; i < nb_insn; i++) { -monitor_printf (mon,"0x" TARGET_FMT_lx": " , pc); +for (i =0 ; i < nb_insn; i++) { +monitor_printf (mon,"0x" TARGET_FMT_lx": " , pc); count =print_insn (pc, &s.info); -monitor_printf (mon,"\n" ); -if (count <0 ) -break ; +monitor_printf (mon,"\n" ); +if (count <0 ) { +break ; + } pc += count; } }
Signature · 1 line
1.7.9.5
PATCH 2/4 Improve Monitor disas with symbol lookup
In reply to Fabien Chouteau--- disas.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
disas.c +9 -1
@@ -507,7 +507,15 @@ void monitor_disas(Monitor *mon, CPUArchState *env,#endif for (i =0 ; i < nb_insn; i++) { -monitor_printf (mon,"0x" TARGET_FMT_lx": " , pc); +const char *sym =lookup_symbol (pc); + +monitor_printf (mon,"0x" TARGET_FMT_lx, pc); +if (sym[0 ] !='\0' ) { +monitor_printf (mon," <%s>: " , sym); + }else { +monitor_printf (mon,": " ); + } + count =print_insn (pc, &s.info);monitor_printf (mon,"\n" );if (count <0 ) {
Signature · 1 line
1.7.9.5
PATCH 3/4 Refactoring MonitorDef array
In reply to Fabien ChouteauEverything has been moved to cpu specific directories (SPARC, PPC, i386).
--- include/monitor/monitor.h | 16 ++ include/qemu/typedefs.h | 1 + include/qom/cpu.h | 3 + monitor.c | 399 +------------------------------------------ target-i386/Makefile.objs | 2 +- target-i386/cpu.c | 6 +- target-i386/monitor.c | 63 +++++++ target-ppc/Makefile.objs | 2 +- target-ppc/monitor.c | 234 +++++++++++++++++++++++++ target-ppc/translate_init.c | 5 + target-sparc/Makefile.objs | 2 +- target-sparc/cpu.c | 5 + target-sparc/monitor.c | 138 +++++++++++++++ 13 files changed, 482 insertions(+), 394 deletions(-) create mode 100644 target-i386/monitor.c create mode 100644 target-ppc/monitor.c create mode 100644 target-sparc/monitor.c
include/monitor/monitor.h +16 -0
@@ -7,6 +7,22 @@#include "block/block.h" #include "monitor/readline.h" +#ifdef NEED_CPU_H +CPUArchState *mon_get_cpu (void ); +#endif + +#define MD_I64 0 +#define MD_I32 1 + +typedef struct MonitorDef { +const char *name; +int offset; +uint64_t (*get_value)(const struct MonitorDef *md,int val); +int type; +}MonitorDef ; + +extern const MonitorDef arch_monitor_defs[]; +extern Monitor *cur_mon;extern Monitor *default_mon;
include/qemu/typedefs.h +1 -0
@@ -13,6 +13,7 @@ typedef struct AioContext AioContext;struct Monitor ;typedef struct Monitor Monitor ;typedef struct MigrationParams MigrationParams ; +typedef struct MonitorDef MonitorDef ;typedef struct Property Property ;typedef struct PropertyInfo PropertyInfo ;
include/qom/cpu.h +3 -0
@@ -156,6 +156,7 @@ struct kvm_run;* @gdb_num_g_regs: Number of registers in GDB 'g' packets. * @next_cpu: Next CPU sharing TB cache. * @kvm_fd: vCPU file descriptor for KVM. +* @monitor_defs array of register definitions for monitor functions * * State of one CPU core or thread. */
@@ -198,6 +199,8 @@ struct CPUState {struct KVMState *kvm_state;struct kvm_run *kvm_run; +const MonitorDef *monitor_defs; +/* TODO Move common fields from CPUArchState here. */ int cpu_index;/* used by alpha TCG */ uint32_t halted;/* used by alpha, cris, ppc TCG */
monitor.c +9 -390
426 lines not on this page · raw message
target-i386/Makefile.objs +1 -1
@@ -2,7 +2,7 @@ obj-y += translate.o helper.o cpu.o obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o obj-y += gdbstub.o -obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o +obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o obj-$(CONFIG_KVM) += kvm.o obj-$(CONFIG_NO_KVM) += kvm-stub.o obj-$(CONFIG_LINUX_USER) += ioport-user.o
target-i386/cpu.c +5 -1
@@ -47,7 +47,7 @@#include "hw/xen/xen.h" #include "hw/i386/apic_internal.h" #endif - +#include "monitor/monitor.h" /* Cache topology CPUID constants: */
@@ -2645,6 +2645,10 @@ static void x86_cpu_initfn(Object *obj)cpu_set_debug_excp_handler (breakpoint_handler);#endif } + +#ifndef CONFIG_USER_ONLY + cs->monitor_defs = arch_monitor_defs; +#endif }static int64_t x86_cpu_get_arch_id (CPUState *cs)
target-i386/monitor.c new file +63 -0
63 lines not on this page · raw message
target-ppc/Makefile.objs +1 -1
@@ -1,7 +1,7 @@ obj-y += cpu-models.o obj-y += translate.o ifeq ($(CONFIG_SOFTMMU),y) -obj-y += machine.o mmu_helper.o mmu-hash32.o +obj-y += machine.o mmu_helper.o mmu-hash32.o monitor.o obj-$(TARGET_PPC64) += mmu-hash64.o endif obj-$(CONFIG_KVM) += kvm.o kvm_ppc.o
target-ppc/monitor.c new file +234 -0
234 lines not on this page · raw message
target-ppc/translate_init.c +5 -0
@@ -28,6 +28,7 @@#include "mmu-hash32.h" #include "mmu-hash64.h" #include "qemu/error-report.h" +#include "monitor/monitor.h" //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR
@@ -8542,6 +8543,10 @@ static void ppc_cpu_initfn(Object *obj) }#endif /* defined(TARGET_PPC64) */ +#if !defined(CONFIG_USER_ONLY ) + cs->monitor_defs = arch_monitor_defs; +#endif +if (tcg_enabled ()) {ppc_translate_init (); }
target-sparc/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -obj-$(CONFIG_SOFTMMU) += machine.o +obj-$(CONFIG_SOFTMMU) += machine.o monitor.o obj-y += translate.o helper.o cpu.o obj-y += fop_helper.o cc_helper.o win_helper.o mmu_helper.o ldst_helper.o obj-$(TARGET_SPARC) += int32_helper.o
target-sparc/cpu.c +5 -0
@@ -18,6 +18,7 @@*/ #include "cpu.h" +#include "monitor/monitor.h" //#define DEBUG_FEATURES
@@ -757,6 +758,10 @@ static void sparc_cpu_initfn(Object *obj) cs->env_ptr = env;cpu_exec_init (env); +#if !defined(CONFIG_USER_ONLY ) + cs->monitor_defs = arch_monitor_defs; +#endif +if (tcg_enabled ()) {gen_intermediate_code_init (env); }
target-sparc/monitor.c new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Review
Quoted 11 lines · Fabien Chouteau
(quoted diff) +4
-4+#define MD_I64 0 +#define MD_I32 1 -#define MD_TLONG 0 -#define MD_I32 1 - { "eax", offsetof(CPUX86State, regs[0]) }, - { "ecx", offsetof(CPUX86State, regs[1]) }, + { "eax", offsetof(CPUX86State, regs[0]) }, + { "ecx", offsetof(CPUX86State, regs[1]) },
I like this generally, but this detail is wrong. These changes mean that these registers (and many others) are now described as being int64_t wide rather than target_long wide, so you'll find that on 32 bit x86 they will read/write incorrectly. This is why I suggested that you need to have target-i386/monitor.c do an
#if TARGET_LONG_BITS == 32
#define MD_TLONG MD_I32
#else
#define MD_TLONG MD_I64
#endif
and then specifically mark these fields as MD_TLONG.
(We could also get rid of that awkward mon_get_cpu() which is the only thing in monitor.h that has to be guarded by NEED_CPU_H, by having the function prototype for the callback functions just take a CPUState* (nb: not a CPUArchState*) rather than having them all call mon_get_cpu. But we can do that in another patch
I guess.)
-- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 26 lines · Peter Maydell
Review
Quoted 11 lines · Fabien Chouteau
(quoted diff) +4
-4+#define MD_I64 0 +#define MD_I32 1 -#define MD_TLONG 0 -#define MD_I32 1 - { "eax", offsetof(CPUX86State, regs[0]) }, - { "ecx", offsetof(CPUX86State, regs[1]) }, + { "eax", offsetof(CPUX86State, regs[0]) }, + { "ecx", offsetof(CPUX86State, regs[1]) },I like this generally, but this detail is wrong. These changes mean that these registers (and many others) are now described as being
int64_twide rather thantarget_longwide, so you'll find that on 32 bit x86 they will read/write incorrectly. This is why I suggested that you need to havetarget-i386/monitor.cdo an
#ifTARGET_LONG_BITS== 32
#defineMD_TLONGMD_I32
#else
#defineMD_TLONGMD_I64
#endif
Quoted 1 line
and then specifically mark these fields as
MD_TLONG.
This seems complicated. Is there a way to use target_long in monitor.h?
Signature · 1 line
Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 13 lines · Fabien Chouteau
Quoted 12 lines · Peter Maydell
I like this generally, but this detail is wrong. These changes mean that these registers (and many others) are now described as being
int64_twide rather thantarget_longwide, so you'll find that on 32 bit x86 they will read/write incorrectly. This is why I suggested that you need to havetarget-i386/monitor.cdo an
#ifTARGET_LONG_BITS== 32
#defineMD_TLONGMD_I32
#else
#defineMD_TLONGMD_I64
#endif
Quoted 3 lines
Quoted 1 line
and then specifically mark these fields as
MD_TLONG.This seems complicated. Is there a way to use
target_longinmonitor.h?
I would prefer it if we didn't, because the monitor should not depend on target-specifics. So the monitor's interface to the CPU dependent parts should expose basic "always the same" types, and if a particular CPU happens to have CPU struct fields which are sometimes 32 bit and sometimes 64 bit then it has to deal with them itself. (Not every CPU has that kind of field.)
-- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
In reply to Fabien ChouteauQuoted 1 line · Fabien Chouteau
+extern const MonitorDef arch_monitor_defs[];
This is supplied by target-foo/monitor.c, right?
Why in the world is it declared in generic code?
Especially if it's only ever accessed via thecpu->monitor_defs member?
r~
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 6 lines · Richard Henderson
Quoted 1 line · Fabien Chouteau
+extern const MonitorDef arch_monitor_defs[];
This is supplied by
target-foo/monitor.c, right?
Why in the world is it declared in generic code?
Yes, why?
Quoted 3 lines
Especially if it's only ever accessed via the
cpu->monitor_defsmember?
To begin with, I though I'd put in in each target-*/cpu.c, then having it at only one place seemed more clean. I'm open to any suggestion.
Signature · 1 line
Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 8 lines · Fabien Chouteau
Quoted 6 lines · Richard Henderson
Quoted 1 line · Fabien Chouteau
+extern const MonitorDef arch_monitor_defs[];
This is supplied by
target-foo/monitor.c, right?
Why in the world is it declared in generic code?
Quoted 9 lines
Yes, why?
Quoted 3 lines
Especially if it's only ever accessed via the
cpu->monitor_defsmember?To begin with, I though I'd put in in each
target-*/cpu.c, then having it at only one place seemed more clean. I'm open to any suggestion.
If you put it in a global header like that, it looks like the array is part of the generic interface. But it isn't -- only the monitor_defs member is.
If it's declared in any header at all, as opposed to static and local to cpu.c (why was a new monitor.c file chosen?), it should go into target-foo/cpu.h, where most of the other cpu-specific declarations go.
r~
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 19 lines · Richard Henderson
Quoted 8 lines · Fabien Chouteau
Quoted 6 lines · Richard Henderson
Quoted 1 line · Fabien Chouteau
+extern const MonitorDef arch_monitor_defs[];
This is supplied by
target-foo/monitor.c, right?
Why in the world is it declared in generic code?Quoted 9 lines
Yes, why?
Quoted 3 lines
Especially if it's only ever accessed via the
cpu->monitor_defsmember?To begin with, I though I'd put in in each
target-*/cpu.c, then having it at only one place seemed more clean. I'm open to any suggestion.
Quoted 6 lines
If you put it in a global header like that, it looks like the array is part of the generic interface. But it isn't -- only the
monitor_defsmember is.If it's declared in any header at all, as opposed to static and local to
cpu.c(why was a newmonitor.cfile chosen?)
Keeps monitor specific stuff in one file for the target and avoids cpu.c gradually bloating into something enormous. Compare use of gdbstub.c for the gdb stub related target specific functions.
The declaration should go in cpu-qom.h (again, compare the gdb stuff), and it should be called "arm_monitor_defs", "ppc_monitor_defs" etc, not arch_monitor_defs. (This avoids issues if we ever manage to compile more than one target CPU into a single qemu binary, and again, it follows existing conventions).
-- PMM
Re: [Qemu-devel] [PATCH 3/4] Refactoring MonitorDef array
Quoted 7 lines · Peter Maydell
The declaration should go in
cpu-qom.h(again, compare the gdb stuff), and it should be called "arm_monitor_defs", "ppc_monitor_defs" etc, notarch_monitor_defs. (This avoids issues if we ever manage to compile more than one target CPU into a single qemu binary, and again, it follows existing conventions).
monitor.h drag a lot of thing...
In file included from /home/chouteau/src/qemu-main/include/monitor/monitor.h:7:0,
from /home/chouteau/src/qemu-main/target-i386/cpu-qom.h:26,
from /home/chouteau/src/qemu-main/target-i386/cpu.h:917,
from /home/chouteau/src/qemu-main/include/qemu-common.h:116,
from /home/chouteau/src/qemu-main/exec.c:27:/home/chouteau/src/qemu-main/include/block/block.h:187:59: error: unknown type name ‘QEMUIOVector’
Maybe MonitorDef can be in a specific file include/monitor/monitordef.h? included by monitor.c target-*/monitor.c and target-*/cpu.c
Signature · 1 line
Fabien Chouteau
PATCH 4/4 Add ARM registers definitions for Monitor commands
In reply to Fabien Chouteau--- target-arm/Makefile.objs | 2 +- target-arm/cpu.c | 5 +++++ target-arm/monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 target-arm/monitor.c
target-arm/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ obj-y += arm-semi.o -obj-$(CONFIG_SOFTMMU) += machine.o +obj-$(CONFIG_SOFTMMU) += machine.o monitor.o obj-$(CONFIG_KVM) += kvm.o obj-$(CONFIG_NO_KVM) += kvm-stub.o obj-y += translate.o op_helper.o helper.o cpu.o
target-arm/cpu.c +5 -0
@@ -26,6 +26,7 @@#include "hw/arm/arm.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "monitor/monitor.h" static void arm_cpu_set_pc (CPUState *cs,vaddr value) {
@@ -217,6 +218,10 @@ static void arm_cpu_initfn(Object *obj) ARRAY_SIZE(cpu->gt_timer_outputs));#endif +#if !defined(CONFIG_USER_ONLY ) + cs->monitor_defs = arch_monitor_defs; +#endif +if (tcg_enabled () && !inited) { inited = true;arm_translate_init ();
target-arm/monitor.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* ARM MonitorDef +* +* Copyright (c) 2013 AdaCore +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "monitor/monitor.h" + +const MonitorDef arch_monitor_defs[] = { + { "r0", offsetof(CPUARMState, regs[0]) }, + { "r1", offsetof(CPUARMState, regs[1]) }, + { "r2", offsetof(CPUARMState, regs[2]) }, + { "r3", offsetof(CPUARMState, regs[3]) }, + { "r4", offsetof(CPUARMState, regs[4]) }, + { "r5", offsetof(CPUARMState, regs[5]) }, + { "r6", offsetof(CPUARMState, regs[6]) }, + { "r7", offsetof(CPUARMState, regs[7]) }, + { "r8", offsetof(CPUARMState, regs[8]) }, + { "r9", offsetof(CPUARMState, regs[9]) }, + { "r10", offsetof(CPUARMState, regs[10]) }, + { "r11", offsetof(CPUARMState, regs[11]) }, + { "r12", offsetof(CPUARMState, regs[12]) }, + { "r13|sp", offsetof(CPUARMState, regs[13]) }, + { "r14|lr", offsetof(CPUARMState, regs[14]) }, + { "r15|pc", offsetof(CPUARMState, regs[15]) }, + {NULL }, +};
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH 4/4] Add ARM registers definitions for Monitor commands
Quoted 63 lines · Fabien Chouteau
Signed-off-by Fabien Chouteau <[email protected]>--- target-arm/Makefile.objs | 2 +- target-arm/cpu.c | 5 +++++ target-arm/monitor.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 target-arm/monitor.ctarget-arm/Makefile.objs +1
-1@@ -1,5 +1,5 @@ obj-y += arm-semi.o -obj-$(CONFIG_SOFTMMU) += machine.o +obj-$(CONFIG_SOFTMMU) += machine.o monitor.o obj-$(CONFIG_KVM) += kvm.o obj-$(CONFIG_NO_KVM) += kvm-stub.o obj-y += translate.o op_helper.o helper.o cpu.otarget-arm/cpu.c +5
-0@@ -26,6 +26,7 @@#include "hw/arm/arm.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "monitor/monitor.h" static void arm_cpu_set_pc (CPUState *cs,vaddr value) {@@ -217,6 +218,10 @@ static void arm_cpu_initfn(Object *obj) ARRAY_SIZE(cpu->gt_timer_outputs));#endif +#if !defined(CONFIG_USER_ONLY ) + cs->monitor_defs = arch_monitor_defs; +#endif +if (tcg_enabled () && !inited) { inited = true;arm_translate_init ();target-arm/monitor.c new file +14
-0@@ -0,0 +1,40 @@ +/* +* ARM MonitorDef +* +* Copyright (c) 2013 AdaCore +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details.
target-arm/monitor.c line 24
Quoted 10 lines
target-arm/monitor.c new file +10
-0+* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "monitor/monitor.h" + +const MonitorDef arch_monitor_defs[] = { + { "r0", offsetof(CPUARMState, regs[0]) }, + { "r1", offsetof(CPUARMState, regs[1]) },
None of these are 64 bit registers, so this looks wrong.
-- PMM