GDB serial port debugging: Changes to add SMP pausing, x86_64 register mappings for serial port GDB, and others.
PATCH 1/1 GDB serial port debugging: Changes to add SMP pausing, x86_64 register mappings for serial port GDB, and others.
Hello,
This patch contains a number of changes to allow serial port debugging of Xen with GDB.
Highlights:
- Removed panics and smp stop calls in favour of an smp pause mechanism.
- Added x86_64 register mapping for gdb serial protocol support.
% diffstat gdb_patch
arch/x86/gdbstub.c | 170 ++++++++++++++++++++++++++++++---------------- arch/x86/traps.c | 7 - arch/x86/x86_32/gdbstub.c | 75 ++++++++++++++++++++ arch/x86/x86_64/Makefile | 1 arch/x86/x86_64/gdbstub.c | 164 ++++++++++++++++++++++++++++++++++++++++++++ common/gdbstub.c | 46 +++++++----- common/keyhandler.c | 2 include/xen/gdbstub.h | 3 8 files changed, 386 insertions(+), 82 deletions(-)
Dan.
xen/arch/x86/gdbstub.c +112 -58
@@ -20,55 +20,26 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <asm/debugger.h> +#include <xen/delay.h> -u16 -gdb_arch_signal_num (struct cpu_user_regs *regs,unsigned long cookie) -{ -/* XXX */ -return 1 ; -} -void -gdb_arch_read_reg_array (struct cpu_user_regs *regs,struct gdb_context *ctx) +struct gdb_cpu_info { -#define GDB_REG (r) gdb_write_to_packet_hex(r, sizeof(r), ctx); -GDB_REG (regs->eax); -GDB_REG (regs->ecx); -GDB_REG (regs->edx); -GDB_REG (regs->ebx); -GDB_REG (regs->esp); -GDB_REG (regs->ebp); -GDB_REG (regs->esi); -GDB_REG (regs->edi); -GDB_REG (regs->eip); -GDB_REG (regs->eflags); -#undef GDB_REG -#define GDB_SEG_REG (s) gdb_write_to_packet_hex(s, sizeof(u32), ctx); -/* sizeof(segment) = 16bit */ -/* but gdb requires its return value as 32bit value */ -GDB_SEG_REG (regs->cs); -GDB_SEG_REG (regs->ss); -GDB_SEG_REG (regs->ds); -GDB_SEG_REG (regs->es); -GDB_SEG_REG (regs->fs); -GDB_SEG_REG (regs->gs); -#undef GDB_SEG_REG -gdb_send_packet (ctx); -} - -void -gdb_arch_write_reg_array (struct cpu_user_regs *regs,const char * buf, -struct gdb_context *ctx) -{ -/* XXX TODO */ -gdb_send_reply ("E02" , ctx); -} - -void -gdb_arch_read_reg (unsigned long regnum,struct cpu_user_regs *regs, -struct gdb_context *ctx) +atomic_t paused; +atomic_t ack; +}; + +static struct gdb_cpu_info gdb_cpu[NR_CPUS ]; +static atomic_t gdb_smp_paused_count; + +static void gdb_smp_pause (void ); +static void gdb_smp_resume (void ); + + +u16 +gdb_arch_signal_num (struct cpu_user_regs *regs,unsigned long cookie) { -gdb_send_reply ("" , ctx); +return 5 ;/* TRAP signal. see include/gdb/signals.h */ }/*
@@ -87,17 +58,6 @@return __copy_to_user (dest, src, len); } -void -gdb_arch_resume (struct cpu_user_regs *regs, -unsigned long addr,unsigned long type, -struct gdb_context *ctx) -{ -/* XXX */ -if (type ==GDB_STEP ) { -gdb_send_reply ("S01" , ctx); - } -} -void gdb_arch_print_state (struct cpu_user_regs *regs) {
@@ -107,13 +67,107 @@void gdb_arch_enter (struct cpu_user_regs *regs) { -/* nothing */ +/* +* We must pause all other CPUs. +*/ +gdb_smp_pause (); }void gdb_arch_exit (struct cpu_user_regs *regs) { -/* nothing */ +/* +* Resume all CPUs. +*/ +gdb_smp_resume (); +} + +static void gdb_pause_this_cpu (void *unused) +{ +unsigned long flags; + +local_irq_save (flags); + +atomic_set (&gdb_cpu[smp_processor_id ()].ack,1 ); +atomic_inc (&gdb_smp_paused_count); + +while (atomic_read (&gdb_cpu[smp_processor_id ()].paused)) +mdelay (1 ); + +atomic_dec (&gdb_smp_paused_count); +atomic_set (&gdb_cpu[smp_processor_id ()].ack,0 ); + +/* Restore interrupts */ +local_irq_restore (flags); +} + +static void gdb_smp_pause (void ) +{ +int timeout =100 ; +int cpu; + +for_each_online_cpu (cpu) + { +atomic_set (&gdb_cpu[cpu].ack,0 ); +atomic_set (&gdb_cpu[cpu].paused,1 ); + } + +atomic_set (&gdb_smp_paused_count,0 ); + +smp_call_function (gdb_pause_this_cpu,NULL ,/* dont wait! */ 0 ,0 ); + +/* Wait 100ms for all other CPUs to enter pause loop */ +while ( (atomic_read (&gdb_smp_paused_count) < (num_online_cpus () -1 )) + && (timeout-- >0 ) ) +mdelay (1 ); + +if (atomic_read (&gdb_smp_paused_count) < (num_online_cpus () -1 ) ) + { +printk ("GDB: Not all CPUs have paused, missing CPUs " ); +for_each_online_cpu (cpu) + { +if ( cpu ==smp_processor_id () ) +continue ; + +if ( !atomic_read (&gdb_cpu[cpu].ack) ) + { +printk ("%d " , cpu); + } + } +printk ("\n" ); + } +} + +static void gdb_smp_resume (void ) +{ +int cpu; +int timeout =100 ; + +for_each_online_cpu (cpu) + { +atomic_set (&gdb_cpu[cpu].paused,0 ); + } + +/* Make sure all CPUs resume */ +while ( (atomic_read (&gdb_smp_paused_count) >0 ) + && (timeout-- >0 ) ) +mdelay (1 ); + +if (atomic_read (&gdb_smp_paused_count) >0 ) + { +printk ("GDB: Not all CPUs have resumed execution, missing CPUs " ); +for_each_online_cpu (cpu) + { +if ( cpu ==smp_processor_id () ) +continue ; + +if ( !atomic_read (&gdb_cpu[cpu].ack) ) + { +printk ("%d " , cpu); + } + } +printk ("\n" ); + } }/*
xen/arch/x86/traps.c +3 -4
@@ -800,9 +800,8 @@if ( !guest_mode (regs) ) { -DEBUGGER_trap_fatal (TRAP_int3, regs); -show_execution_state (regs); -panic ("FATAL TRAP: vector = 3 (Int3)\n" ); +debugger_trap_fatal (TRAP_int3, regs); +return ; }do_guest_trap (TRAP_int3, regs,0 );
@@ -2753,7 +2752,7 @@set_intr_gate (TRAP_divide_error,÷_error);set_intr_gate (TRAP_debug,&debug);set_intr_gate (TRAP_nmi,&nmi); -set_system_gate (TRAP_int3,&int3);/* usable from all privileges */ +set_intr_gate (TRAP_int3,&int3);/* usable from all privileges */ set_system_gate (TRAP_overflow,&overflow);/* usable from all privileges */ set_intr_gate (TRAP_bounds,&bounds);set_intr_gate (TRAP_invalid_op,&invalid_op);
xen/arch/x86/x86_32/gdbstub.c +75 -0
75 lines not on this page · raw message
xen/arch/x86/x86_64/gdbstub.c +164 -0
164 lines not on this page · raw message
xen/arch/x86/x86_64/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y += mm.o obj-y += traps.o +obj-$(crash_debug) += gdbstub.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_COMPAT) += compat_kexec.o obj-$(CONFIG_COMPAT) += domain.o
xen/common/gdbstub.c +27 -19
82 lines not on this page · raw message
xen/common/keyhandler.c +1 -1
@@ -276,7 +276,7 @@static void do_debug_key (unsigned char key,struct cpu_user_regs *regs) {printk ("'%c' pressed -> trapping into debugger\n" , key); - (void )debugger_trap_fatal (0xf001 , regs); + (void )debugger_trap_fatal (TRAP_int3, regs);nop ();/* Prevent the compiler doing tail call optimisation, as that confuses xendbg a bit. */
xen/include/xen/gdbstub.h +3 -0
@@ -69,6 +69,9 @@ struct cpu_user_regs *regs, const char* buf, struct gdb_context *ctx);void gdb_arch_read_reg (unsigned long regnum,struct cpu_user_regs *regs,struct gdb_context *ctx); +void gdb_arch_write_reg ( +unsigned long regnum,unsigned long val,struct cpu_user_regs *regs, +struct gdb_context *ctx);unsigned int gdb_arch_copy_from_user (void *dest,const void *src,unsigned len); unsigned int gdb_arch_copy_to_user(
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 1 line · Dan Doucette
Hello,
Hi.
Quoted 3 lines
diff -Nur --exclude=setup.c --exclude=nmi.c --exclude='*.o' --exclude='*.s' --exclude='*.swp' --exclude=compile.h --exclude=serial.c
xen-unstable.hg/xen/arch/x86/gdbstub.cxen-unstable.hg.new/xen/arch/x86/gdbstub.cxen/arch/x86/gdbstub.c +0
-0
...
Quoted 98 lines
xen/arch/x86/gdbstub.c +87
-2@@ -107,13 +67,107 @@void gdb_arch_enter (struct cpu_user_regs *regs) { -/* nothing */ +/* +* We must pause all other CPUs. +*/ +gdb_smp_pause (); }void gdb_arch_exit (struct cpu_user_regs *regs) { -/* nothing */ +/* +* Resume all CPUs. +*/ +gdb_smp_resume (); +} + +static void gdb_pause_this_cpu (void *unused) +{ +unsigned long flags; + +local_irq_save (flags); + +atomic_set (&gdb_cpu[smp_processor_id ()].ack,1 ); +atomic_inc (&gdb_smp_paused_count); + +while (atomic_read (&gdb_cpu[smp_processor_id ()].paused)) +mdelay (1 ); + +atomic_dec (&gdb_smp_paused_count); +atomic_set (&gdb_cpu[smp_processor_id ()].ack,0 ); + +/* Restore interrupts */ +local_irq_restore (flags); +} + +static void gdb_smp_pause (void ) +{ +int timeout =100 ; +int cpu; + +for_each_online_cpu (cpu) + { +atomic_set (&gdb_cpu[cpu].ack,0 ); +atomic_set (&gdb_cpu[cpu].paused,1 ); + } + +atomic_set (&gdb_smp_paused_count,0 ); + +smp_call_function (gdb_pause_this_cpu,NULL ,/* dont wait! */ 0 ,0 ); + +/* Wait 100ms for all other CPUs to enter pause loop */ +while ( (atomic_read (&gdb_smp_paused_count) < (num_online_cpus () -1 )) + && (timeout-- >0 ) ) +mdelay (1 ); + +if (atomic_read (&gdb_smp_paused_count) < (num_online_cpus () -1 ) ) + { +printk ("GDB: Not all CPUs have paused, missing CPUs " ); +for_each_online_cpu (cpu) + { +if ( cpu ==smp_processor_id () ) +continue ; + +if ( !atomic_read (&gdb_cpu[cpu].ack) ) + { +printk ("%d " , cpu); + } + } +printk ("\n" ); + } +} + +static void gdb_smp_resume (void ) +{ +int cpu; +int timeout =100 ; + +for_each_online_cpu (cpu) + { +atomic_set (&gdb_cpu[cpu].paused,0 ); + } + +/* Make sure all CPUs resume */ +while ( (atomic_read (&gdb_smp_paused_count) >0 ) + && (timeout-- >0 ) ) +mdelay (1 ); + +if (atomic_read (&gdb_smp_paused_count) >0 ) + { +printk ("GDB: Not all CPUs have resumed execution, missing CPUs " ); +for_each_online_cpu (cpu) + { +if ( cpu ==smp_processor_id () )
xen/arch/x86/gdbstub.c line 171
Quoted 10 lines
xen/arch/x86/gdbstub.c +9
-0+continue ; + +if ( !atomic_read (&gdb_cpu[cpu].ack) ) + { +printk ("%d " , cpu); + } + } +printk ("\n" ); + } }
Pausing/resuming cpus looks like arch generic.
Could you move them to the common code?
xen/common/keyhandler.c line 282
Quoted 12 lines
diff -Nur --exclude=setup.c --exclude=nmi.c --exclude='*.o' --exclude='*.s' --exclude='*.swp' --exclude=compile.h --exclude=serial.c
xen-unstable.hg/xen/common/keyhandler.cxen-unstable.hg.new/xen/common/keyhandler.cxen/common/keyhandler.c +1
-1@@ -276,7 +276,7 @@static void do_debug_key (unsigned char key,struct cpu_user_regs *regs) {printk ("'%c' pressed -> trapping into debugger\n" , key); - (void )debugger_trap_fatal (0xf001 , regs); + (void )debugger_trap_fatal (TRAP_int3, regs);nop ();/* Prevent the compiler doing tail call optimisation, as that confuses xendbg a bit. */
TRAP_int3 is x86 specific.
Please define a constant like TRAP_gdbstab in the arch header and use it.
xen/include/xen/gdbstub.h line 77
Quoted 13 lines
diff -Nur --exclude=setup.c --exclude=nmi.c --exclude='*.o' --exclude='*.s' --exclude='*.swp' --exclude=compile.h --exclude=serial.c
xen-unstable.hg/xen/include/xen/gdbstub.hxen-unstable.hg.new/xen/include/xen/gdbstub.hxen/include/xen/gdbstub.h +3
-0@@ -69,6 +69,9 @@ struct cpu_user_regs *regs, const char* buf, struct gdb_context *ctx);void gdb_arch_read_reg (unsigned long regnum,struct cpu_user_regs *regs,struct gdb_context *ctx); +void gdb_arch_write_reg ( +unsigned long regnum,unsigned long val,struct cpu_user_regs *regs, +struct gdb_context *ctx);unsigned int gdb_arch_copy_from_user (void *dest,const void *src,unsigned len); unsigned int gdb_arch_copy_to_user(
Adding gdb_arch_write_reg() breaks other arch (IA64 and power). How about adding the default definition which just returns as a weak symbol?
Signature · 1 line
yamahata
Quoted 3 lines · Isaku Yamahata
Adding
gdb_arch_write_reg()breaks other arch (IA64 and power). How about adding the default definition which just returns as a weak symbol?
Just add the no-op implementation to arch/{ia64,powerpc}/gdbstub.c.
-- Keir
Hello,
Quoted 2 lines
Quoted 2 lines
Pausing/resuming cpus looks like arch generic.
Could you move them to the common code?
Yes. Moved to common/gdbstub.c.
Quoted 2 lines
Quoted 2 lines
TRAP_int3is x86 specific.
Please define a constant likeTRAP_gdbstabin the arch header and use it.
The value of the vector is not used, yet. I just removed this change from the patch.
Quoted 5 lines
Quoted 5 lines
Adding
gdb_arch_write_reg()breaks other arch (IA64 and power). How about adding the default definition which just returns as a weak symbol?Quoted 1 line
Just add the no-op implementation to
arch/{ia64,powerpc}/gdbstub.c.
I added the no-op implementations to ia64 and powerpc.
Dan.
Quoted 5 lines · Keir Fraser
On 20/12/07 01:36, "Isaku Yamahata" <[email protected]> wrote:
Quoted 10 lines
Quoted 3 lines
Adding
gdb_arch_write_reg()breaks other arch (IA64 and power). How about adding the default definition which just returns as a weak symbol?Just add the no-op implementation to
arch/{ia64,powerpc}/gdbstub.c.-- Keir
xen/arch/ia64/xen/gdbstub.c +7 -0
@@ -62,6 +62,13 @@ }void +gdb_arch_write_reg (unsigned long regnum,unsigned long val, +struct cpu_user_regs *regs,struct gdb_context *ctx) +{ +gdb_send_reply ("" , ctx); +} + +void gdb_arch_write_reg_array (struct cpu_user_regs *regs,const char * buf,struct gdb_context *ctx) {
xen/arch/powerpc/gdbstub.c +8 -0
@@ -132,6 +132,14 @@gdb_send_packet (ctx); } +void +gdb_arch_write_reg (unsigned long regnum,unsigned long val, +struct cpu_user_regs *regs,struct gdb_context *ctx) +{ +unimplemented (); +gdb_send_reply ("" , ctx); +} +void gdb_arch_write_reg_array (struct cpu_user_regs *regs,const char *buf,struct gdb_context *ctx)
xen/arch/x86/gdbstub.c +1 -56
69 lines not on this page · raw message
xen/arch/x86/traps.c +3 -4
@@ -800,9 +800,8 @@if ( !guest_mode (regs) ) { -DEBUGGER_trap_fatal (TRAP_int3, regs); -show_execution_state (regs); -panic ("FATAL TRAP: vector = 3 (Int3)\n" ); +debugger_trap_fatal (TRAP_int3, regs); +return ; }do_guest_trap (TRAP_int3, regs,0 );
@@ -2753,7 +2752,7 @@set_intr_gate (TRAP_divide_error,÷_error);set_intr_gate (TRAP_debug,&debug);set_intr_gate (TRAP_nmi,&nmi); -set_system_gate (TRAP_int3,&int3);/* usable from all privileges */ +set_intr_gate (TRAP_int3,&int3);/* usable from all privileges */ set_system_gate (TRAP_overflow,&overflow);/* usable from all privileges */ set_intr_gate (TRAP_bounds,&bounds);set_intr_gate (TRAP_invalid_op,&invalid_op);
xen/arch/x86/x86_32/gdbstub.c +75 -0
75 lines not on this page · raw message
xen/arch/x86/x86_64/gdbstub.c +164 -0
164 lines not on this page · raw message
xen/arch/x86/x86_64/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y += mm.o obj-y += traps.o +obj-$(crash_debug) += gdbstub.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_COMPAT) += compat_kexec.o obj-$(CONFIG_COMPAT) += domain.o
xen/common/gdbstub.c +132 -18
204 lines not on this page · raw message
xen/include/xen/gdbstub.h +3 -0
@@ -69,6 +69,9 @@ struct cpu_user_regs *regs, const char* buf, struct gdb_context *ctx);void gdb_arch_read_reg (unsigned long regnum,struct cpu_user_regs *regs,struct gdb_context *ctx); +void gdb_arch_write_reg ( +unsigned long regnum,unsigned long val,struct cpu_user_regs *regs, +struct gdb_context *ctx);unsigned int gdb_arch_copy_from_user (void *dest,const void *src,unsigned len); unsigned int gdb_arch_copy_to_user(
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel