From: Caz Yokoyama Subject: [PATCH] fix the bug of gdb which debugs xen. Date: Tue, 11 Aug 2009 19:15:24 -0700 Message-ID: <65A1F38D1CBF4B3E9F262F4FD3D01A91@xpjpn> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_03FD_01CA1AB8.15516180" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. ------=_NextPart_000_03FD_01CA1AB8.15516180 Content-Type: multipart/alternative; boundary="----=_NextPart_001_03FE_01CA1AB8.15516180" ------=_NextPart_001_03FE_01CA1AB8.15516180 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Hello, This patch fixes the bug of gdb which debugs Xen hypervisor, i.e. not domU. As Emre Can Sezer reported in http://lists.xensource.com/archives/html/xen-devel/2009-01/msg00885.html, once break point is hit, continue command produces SIGTRAP at restore_all_xen(). This patch makes continue command resume Xen running. I still see other bugs like backtrace command does not show function name. But I hope this helps your debug. FYI, related postings. http://lists.xensource.com/archives/html/xen-devel/2007-12/msg00678.html http://www.filewatcher.com/p/xen_2.0.6.orig.tar.gz.2456215/xen-2.0/docs/misc /XenDebugger-HOWTO.html connect gdb on step command --- a/xen/arch/x86/traps.c Thu Aug 06 13:27:53 2009 +0100 +++ b/xen/arch/x86/traps.c Tue Aug 11 18:15:25 2009 -0700 @@ -2977,13 +2977,7 @@ if ( regs->eflags & EF_TF ) { #ifdef __x86_64__ - void sysenter_entry(void); - void sysenter_eflags_saved(void); - /* In SYSENTER entry path we can't zap TF until EFLAGS is saved. */ - if ( (regs->rip >= (unsigned long)sysenter_entry) && - (regs->rip < (unsigned long)sysenter_eflags_saved) ) - goto out; - WARN_ON(regs->rip != (unsigned long)sysenter_eflags_saved); + debugger_trap_fatal(TRAP_debug, regs); #else WARN_ON(1); #endif Value of gdb command is little endian. diff -r 13fe7f07df15 xen/common/gdbstub.c --- a/xen/common/gdbstub.c Thu Aug 06 13:27:53 2009 +0100 +++ b/xen/common/gdbstub.c Tue Aug 11 18:15:25 2009 -0700 @@ -53,6 +53,10 @@ #define GDB_RETRY_MAX 10 +#define swap16(_v) ((((u16)(_v)>>8)&0xff)|(((u16)(_v)&0xff)<<8)) +#define swap32(_v) (((u32)swap16((u16)(_v))<<16)|(u32)swap16((u32)((_v)>>16))) +#define swap64(_v) (((u64)swap32((u32)(_v))<<32)|(u64)swap32((u32)((_v)>>32))) + struct gdb_cpu_info { atomic_t paused; @@ -489,6 +493,7 @@ } ptr++; val = str2ulong(ptr, sizeof(unsigned long)); + val = swap64(val); gdb_arch_write_reg(addr, val, regs, ctx); break; case 'D': Thank you. -Caz Yokoyama, caz at caztech dot com. 503-804-1028(m). ------=_NextPart_001_03FE_01CA1AB8.15516180 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

Hello,

This patch fixes the bug of gdb which debugs = Xen hypervisor, i.e. not domU. As Emre Can Sezer = reported in http://lists.xensource.com/archives/html/xen-devel/2009-01/msg00= 885.html, once break point is hit, continue command produces SIGTRAP at restore_all_xen(). This patch = makes continue command resume Xen running. I still see other bugs like = backtrace command does not show function name. But I hope this helps your = debug.

FYI, related = postings.

http://lists.xensource.com/archives/html/xen-devel/2007-12/msg00= 678.html

http://www.filewatcher.com/p/xen_2.0.= 6.orig.tar.gz.2456215/xen-2.0/docs/misc/XenDebugger-HOWTO.html

 

connect gdb on step command

--- a/xen/arch/x86/traps.c      Thu Aug 06 13:27:53 = 2009 +0100

+++ b/xen/arch/x86/traps.c      Tue Aug 11 18:15:25 = 2009 -0700

@@ = -2977,13 +2977,7 @@

         if ( regs->eflags & EF_TF )

         {

 #ifdef __x86_64__

-          &nb= sp; void sysenter_entry(void);

-          &nb= sp; void sysenter_eflags_saved(void);

-          &nb= sp; /* In SYSENTER entry path we can't zap TF until EFLAGS is saved. = */

-          &nb= sp; if ( (regs->rip >=3D (unsigned long)sysenter_entry) = &&

-          &nb= sp;      (regs->rip < (unsigned long)sysenter_eflags_saved) = )

-          &nb= sp;     goto out;

-          &nb= sp; WARN_ON(regs->rip !=3D (unsigned = long)sysenter_eflags_saved);

+          &nb= sp; debugger_trap_fatal(TRAP_debug, regs);

 #else

          &nbs= p;  WARN_ON(1);

 #endif

 

Value of gdb command is little endian.

diff -r = 13fe7f07df15 xen/common/gdbstub.c

--- a/xen/common/gdbstub.c      Thu Aug 06 13:27:53 = 2009 +0100

+++ b/xen/common/gdbstub.c      Tue Aug 11 18:15:25 = 2009 -0700

@@ -53,6 = +53,10 @@

 

 #define GDB_RETRY_MAX   10

 

+#define = swap16(_v) ((((u16)(_v)>>8)&0xff)|(((u16)(_v)&0xff)<<8))

+#define = swap32(_v) (((u32)swap16((u16)(_v))<<16)|(u32)swap16((u32)((_v)>>16)))

+#define = swap64(_v) (((u64)swap32((u32)(_v))<<32)|(u64)swap32((u32)((_v)>>32)))

+

 struct gdb_cpu_info

 {

     atomic_t paused;

@@ = -489,6 +493,7 @@

         }

         ptr++;

         val =3D str2ulong(ptr, sizeof(unsigned = long));

+        val =3D swap64(val);

         gdb_arch_write_reg(addr, val, regs, ctx);

         break;

     case 'D':

 

Thank you.

-Caz Yokoyama, caz at caztech dot com. = 503-804-1028(m).

 

------=_NextPart_001_03FE_01CA1AB8.15516180-- ------=_NextPart_000_03FD_01CA1AB8.15516180 Content-Type: application/octet-stream; name="XenGdb.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="XenGdb.patch" --- a/xen/arch/x86/traps.c Thu Aug 06 13:27:53 2009 +0100=0A= +++ b/xen/arch/x86/traps.c Tue Aug 11 18:15:25 2009 -0700=0A= @@ -2977,13 +2977,7 @@=0A= if ( regs->eflags & EF_TF )=0A= {=0A= #ifdef __x86_64__=0A= - void sysenter_entry(void);=0A= - void sysenter_eflags_saved(void);=0A= - /* In SYSENTER entry path we can't zap TF until EFLAGS is = saved. */=0A= - if ( (regs->rip >=3D (unsigned long)sysenter_entry) &&=0A= - (regs->rip < (unsigned long)sysenter_eflags_saved) )=0A= - goto out;=0A= - WARN_ON(regs->rip !=3D (unsigned = long)sysenter_eflags_saved);=0A= + debugger_trap_fatal(TRAP_debug, regs);=0A= #else=0A= WARN_ON(1);=0A= #endif=0A= diff -r 13fe7f07df15 xen/common/gdbstub.c=0A= --- a/xen/common/gdbstub.c Thu Aug 06 13:27:53 2009 +0100=0A= +++ b/xen/common/gdbstub.c Tue Aug 11 18:15:25 2009 -0700=0A= @@ -53,6 +53,10 @@=0A= =0A= #define GDB_RETRY_MAX 10=0A= =0A= +#define swap16(_v) ((((u16)(_v)>>8)&0xff)|(((u16)(_v)&0xff)<<8))=0A= +#define swap32(_v) = (((u32)swap16((u16)(_v))<<16)|(u32)swap16((u32)((_v)>>16)))=0A= +#define swap64(_v) = (((u64)swap32((u32)(_v))<<32)|(u64)swap32((u32)((_v)>>32)))=0A= +=0A= struct gdb_cpu_info=0A= {=0A= atomic_t paused;=0A= @@ -489,6 +493,7 @@=0A= }=0A= ptr++;=0A= val =3D str2ulong(ptr, sizeof(unsigned long));=0A= + val =3D swap64(val);=0A= gdb_arch_write_reg(addr, val, regs, ctx);=0A= break;=0A= case 'D':=0A= ------=_NextPart_000_03FD_01CA1AB8.15516180 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel ------=_NextPart_000_03FD_01CA1AB8.15516180--