Few minor improvements of monitor disas command (v2)
cover Few minor improvements of monitor disas command (v2)
1. Fix coding style (missing space and tab indentation)
2. Add symbole lookup (when possible)
3. Add ARM registers definitions
I tried to abstract monitor_defs in a CPU field, but I got lost in the dependencies maze. I still think this patch is a step forward.
Fabien Chouteau (3):
Fix coding style
Improve Monitor disas with symbol lookup Add ARM registers definitions in Monitor commands
disas.c | 19 ++++++++++++++----- monitor.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/3 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
Re: [Qemu-devel] [PATCH 1/3] Fix coding style
Am 24.09.2013 18:45, schrieb Fabien Chouteau:
Quoted 4 lines
Signed-off-by Fabien Chouteau <[email protected]>--- disas.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
PATCH 2/3 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/3 Add ARM registers definitions in Monitor commands
In reply to Fabien Chouteau--- monitor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
monitor.c +17 -0
@@ -3351,6 +3351,23 @@ static const MonitorDef monitor_defs[] = { { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, { "fprs", offsetof(CPUSPARCState, fprs) }, #endif +#elif defined(TARGET_ARM) + { "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]) }, #endif { NULL }, };
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 14 lines · Fabien Chouteau
monitor.c +8
-0@@ -3351,6 +3351,23 @@ static const MonitorDef monitor_defs[] = { { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, { "fprs", offsetof(CPUSPARCState, fprs) }, #endif +#elif defined(TARGET_ARM) + { "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]) },
monitor.c static const MonitorDef monitor_defs[] = { · line 3371
Quoted 10 lines
monitor.c +9
-0+ { "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]) }, #endif
No, I really don't want to see another target #ifdef ladder, please. Put a 'static const MonitorDef *monitor_defs;' into CPUClass, and initialize it in each target's class init function, please. (You'll need to move the appropriate sections of the current static array in monitor.c plus the per-target functions that it references into target-*/cpu.c.) Look at gdb_num_core_regs as an example of where we made this kind of abstraction.
-- PMM
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 9 lines · Peter Maydell
No, I really don't want to see another target #ifdef ladder, please. Put a 'static const MonitorDef
*monitor_defs;' into CPUClass, and initialize it in each target's class init function, please. (You'll need to move the appropriate sections of the current static array inmonitor.cplus the per-target functions that it references intotarget-*/cpu.c.) Look atgdb_num_core_regsas an example of where we made this kind of abstraction.
I tried already. Where whould you put the declaration of MonitorDef type?
Signature · 1 line
Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 11 lines · Fabien Chouteau
Quoted 9 lines · Peter Maydell
No, I really don't want to see another target #ifdef ladder, please. Put a 'static const MonitorDef
*monitor_defs;' into CPUClass, and initialize it in each target's class init function, please. (You'll need to move the appropriate sections of the current static array inmonitor.cplus the per-target functions that it references intotarget-*/cpu.c.) Look atgdb_num_core_regsas an example of where we made this kind of abstraction.
Quoted 1 line
I tried already. Where whould you put the declaration of MonitorDef type?
It doesn't matter very much, but monitor.h seems the obvious place. You probably don't want qom/cpu.h to have to drag in monitor.h so a 'struct MonitorDef;' forward declaration in cpu.h will let you avoid that (we do that already for a few other structs).
-- PMM
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 12 lines · Peter Maydell
Quoted 11 lines · Fabien Chouteau
Quoted 9 lines · Peter Maydell
No, I really don't want to see another target #ifdef ladder, please. Put a 'static const MonitorDef
*monitor_defs;' into CPUClass, and initialize it in each target's class init function, please. (You'll need to move the appropriate sections of the current static array inmonitor.cplus the per-target functions that it references intotarget-*/cpu.c.) Look atgdb_num_core_regsas an example of where we made this kind of abstraction.
Quoted 7 lines
Quoted 1 line
I tried already. Where whould you put the declaration of MonitorDef type?
It doesn't matter very much, but
monitor.hseems the obvious place. You probably don't wantqom/cpu.hto have to drag inmonitor.hso a 'struct MonitorDef;' forward declaration incpu.hwill let you avoid that (we do that already for a few other structs).
I think that's what I did. I think the problem was to include 'monitor.h' in 'target-*/cpu.c'.
Signature · 1 line
Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 9 lines · Fabien Chouteau
Quoted 5 lines · Peter Maydell
On 26 September 2013 00:38, Fabien Chouteau <[email protected]> wrote:
It doesn't matter very much, butmonitor.hseems the obvious place. You probably don't wantqom/cpu.hto have to drag inmonitor.hso a 'struct MonitorDef;' forward declaration incpu.hwill let you avoid that (we do that already for a few other structs).I think that's what I did. I think the problem was to include '
monitor.h' in 'target-*/cpu.c'.
Why doesn't that work?
In any case, you just need to disentangle stuff so you can get the right definitions and function prototypes available to the target specific code. We could have a target-*/monitor.c if that's an easier approach -- we already have a gdbstub.c, for example.
-- PMM
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 8 lines · Peter Maydell
Quoted 7 lines · Fabien Chouteau
Quoted 5 lines · Peter Maydell
On 26 September 2013 00:38, Fabien Chouteau <[email protected]> wrote:
It doesn't matter very much, butmonitor.hseems the obvious place. You probably don't wantqom/cpu.hto have to drag inmonitor.hso a 'struct MonitorDef;' forward declaration incpu.hwill let you avoid that (we do that already for a few other structs).
Quoted 5 lines
Quoted 2 lines
I think that's what I did. I think the problem was to include '
monitor.h' in 'target-*/cpu.c'.Why doesn't that work?
The problem is use of 'target_long' in 'monitor.h'.
Signature · 1 line
Fabien Chouteau
Re: [Qemu-devel] [PATCH 3/3] Add ARM registers definitions in Monitor commands
Quoted 8 lines · Fabien Chouteau
Quoted 5 lines · Peter Maydell
Quoted 2 lines · Fabien Chouteau
I think that's what I did. I think the problem was to include '
monitor.h' in 'target-*/cpu.c'.Why doesn't that work?
The problem is use of '
target_long' in 'monitor.h'.
Oh, right, the problem isn't including monitor.h from cpu.c, it's that some target-independent source files include monitor.h so you can't put target-dependent types like target_long in it. There are two fixes for this that spring to mind:
(1) lazy approach, wrap the MonitorDef structure definition in #ifdef NEED_CPU_H/#endif.
(2) the "remove target-specificisms from what should be generic code" approach:
* make MonitorDef use uint64_t rather than target_long for the getter function return type
* propagate that type change into functions like get_monitor_def and its callsite in expr_unary
* make the types recognized by get_monitor_def be MD_I32 or MD_I64, and not MD_TLONG
* make the per-target MonitorDef array entries which currently implicitly use MD_TLONG instead either
(a) use MD_I32 or MD_I64 if they're targets which really only have one width or (b) use a locally #defined MD_TLONG if they're accessing CPU struct fields which really are target_long and the CPU comes in both 32 and 64 bit variants.
-- PMM