[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Fix 64-bit HVM guest debug via gdbserver:



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 30ae67d6e5f000d5471377bb658b77bf74c76237
# Parent  4840c3da25219c1163dd65ce5847c414320fe03e
Fix 64-bit HVM guest debug via gdbserver:
 1. gdb_regs for 64bit, and macros to transfer regisers between ptrace
    registers to gdb registers
 2. xc_ptrace code building for 64bit
 3. Implementation of new map_domain_va for 64bit
 4. gdbserver-xen build configuration fixes for 64bit

From: Nitin Kamble
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r 4840c3da2521 -r 30ae67d6e5f0 
tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv
--- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv       
Sun Mar 26 10:45:35 2006
+++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/configure.srv       
Sun Mar 26 10:50:39 2006
@@ -61,7 +61,7 @@
                        srv_linux_thread_db=yes
                        ;;
   x86_64-*-linux*)     srv_regobj=reg-x86-64.o
-                       srv_tgtobj="linux-low.o linux-x86-64-low.o i387-fp.o"
+                       srv_tgtobj="linux-xen-low.o linux-x86-64-low.o 
i387-fp.o"
                        srv_linux_regsets=yes
                        ;;
   xscale*-*-linux*)    srv_regobj=reg-arm.o
diff -r 4840c3da2521 -r 30ae67d6e5f0 tools/libxc/Makefile
--- a/tools/libxc/Makefile      Sun Mar 26 10:45:35 2006
+++ b/tools/libxc/Makefile      Sun Mar 26 10:50:39 2006
@@ -21,13 +21,9 @@
 SRCS       += xc_sedf.c
 SRCS       += xc_tbuf.c
 
-ifeq ($(XEN_TARGET_ARCH),x86_32)
+ifeq ($(patsubst x86%,x86,$(XEN_TARGET_ARCH)),x86)
 SRCS       += xc_ptrace.c
 SRCS       += xc_ptrace_core.c
-SRCS       += xc_pagetab.c
-endif
-
-ifeq ($(XEN_TARGET_ARCH),x86_64)
 SRCS       += xc_pagetab.c
 endif
 
diff -r 4840c3da2521 -r 30ae67d6e5f0 tools/libxc/xc_ptrace.c
--- a/tools/libxc/xc_ptrace.c   Sun Mar 26 10:45:35 2006
+++ b/tools/libxc/xc_ptrace.c   Sun Mar 26 10:50:39 2006
@@ -38,9 +38,6 @@
 };
 #endif
 
-/* XXX application state */
-static long                     nr_pages = 0;
-static unsigned long           *page_array = NULL;
 static int                      current_domid = -1;
 static int                      current_isfile;
 
@@ -196,6 +193,60 @@
     return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
 }
 
+#ifdef __x86_64__
+static void *
+map_domain_va(
+    int xc_handle,
+    int cpu,
+    void *guest_va,
+    int perm)
+{
+    unsigned long l3p, l2p, l1p, p, va = (unsigned long)guest_va;
+    uint64_t *l4, *l3, *l2, *l1;
+    static void *v;
+
+    if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
+        return map_domain_va_pae(xc_handle, cpu, guest_va, perm);
+
+    if (fetch_regs(xc_handle, cpu, NULL))
+        return NULL;
+
+    l4 = xc_map_foreign_range(
+        xc_handle, current_domid, PAGE_SIZE, PROT_READ, ctxt[cpu].ctrlreg[3] 
>> PAGE_SHIFT);
+    if ( l4 == NULL )
+        return NULL;
+
+    l3p = l4[l4_table_offset(va)] >> PAGE_SHIFT;
+    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, 
l3p);
+    if ( l3 == NULL )
+        return NULL;
+
+    l2p = l3[l3_table_offset(va)] >> PAGE_SHIFT;
+    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, 
l2p);
+    if ( l2 == NULL )
+        return NULL;
+
+    l1p = l2[l2_table_offset(va)] >> PAGE_SHIFT;
+    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
+    if ( l1 == NULL )
+        return NULL;
+
+    p = l1[l1_table_offset(va)] >> PAGE_SHIFT;
+    if ( v != NULL )
+        munmap(v, PAGE_SIZE);
+    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
+    if ( v == NULL )
+        return NULL;
+
+    return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1)));
+}
+#endif
+
+#ifdef __i386__
+/* XXX application state */
+static long                     nr_pages = 0;
+static unsigned long           *page_array = NULL;
+
 static void *
 map_domain_va(
     int xc_handle,
@@ -216,15 +267,18 @@
     static unsigned long  page_phys[MAX_VIRT_CPUS];
     static unsigned long *page_virt[MAX_VIRT_CPUS];    
     static int            prev_perm[MAX_VIRT_CPUS];
-    static enum { MODE_UNKNOWN, MODE_32, MODE_PAE } mode;
+    static enum { MODE_UNKNOWN, MODE_32, MODE_PAE, MODE_64 } mode;
 
     if ( mode == MODE_UNKNOWN )
     {
         xen_capabilities_info_t caps;
         (void)xc_version(xc_handle, XENVER_capabilities, caps);
-        mode = MODE_32;
-        if ( strstr(caps, "_x86_32p") )
+        if ( strstr(caps, "-x86_64") )
+            mode = MODE_64;
+        else if ( strstr(caps, "-x86_32p") )
             mode = MODE_PAE;
+        else if ( strstr(caps, "-x86_32") ) 
+            mode = MODE_32;
     }
 
     if ( mode == MODE_PAE )
@@ -303,6 +357,8 @@
 
     return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
 }
+
+#endif
 
 static int 
 __xc_waitdomain(
diff -r 4840c3da2521 -r 30ae67d6e5f0 tools/libxc/xc_ptrace.h
--- a/tools/libxc/xc_ptrace.h   Sun Mar 26 10:45:35 2006
+++ b/tools/libxc/xc_ptrace.h   Sun Mar 26 10:50:39 2006
@@ -9,6 +9,96 @@
 #define BSD_PAGE_MASK (PAGE_SIZE-1)
 #define PDRSHIFT        22
 #define PSL_T  0x00000100 /* trace enable bit */
+
+#ifdef __x86_64__
+struct gdb_regs
+{
+  unsigned long r15;
+  unsigned long r14;
+  unsigned long r13;
+  unsigned long r12;
+  unsigned long rbp;
+  unsigned long rbx;
+  unsigned long r11;
+  unsigned long r10;
+  unsigned long r9;
+  unsigned long r8;
+  unsigned long rax;
+  unsigned long rcx;
+  unsigned long rdx;
+  unsigned long rsi;
+  unsigned long rdi;
+  unsigned long orig_rax;
+  unsigned long rip;
+  unsigned long xcs;
+  unsigned long eflags;
+  unsigned long rsp;
+  unsigned long xss;
+  unsigned long fs_base;
+  unsigned long gs_base;
+  unsigned long xds;
+  unsigned long xes;
+  unsigned long xfs;
+  unsigned long xgs;
+};
+
+#define SET_PT_REGS(pt, xc)                     \
+{                                               \
+    pt.r8 = xc.r8;                              \
+    pt.r9 = xc.r9;                              \
+    pt.r10 = xc.r10;                            \
+    pt.r11 = xc.r11;                            \
+    pt.r12 = xc.r12;                            \
+    pt.r13 = xc.r13;                            \
+    pt.r14 = xc.r14;                            \
+    pt.r15 = xc.r15;                            \
+    pt.rbx = xc.rbx;                            \
+    pt.rcx = xc.rcx;                            \
+    pt.rdx = xc.rdx;                            \
+    pt.rsi = xc.rsi;                            \
+    pt.rdi = xc.rdi;                            \
+    pt.rbp = xc.rbp;                            \
+    pt.rax = xc.rax;                            \
+    pt.rip = xc.rip;                            \
+    pt.xcs = xc.cs;                             \
+    pt.eflags = xc.eflags;                      \
+    pt.rsp = xc.rsp;                            \
+    pt.xss = xc.ss;                             \
+    pt.xes = xc.es;                             \
+    pt.xds = xc.ds;                             \
+    pt.xfs = xc.fs;                             \
+    pt.xgs = xc.gs;                             \
+}
+
+#define SET_XC_REGS(pt, xc)                     \
+{                                               \
+    xc.r8 = pt->r8;                             \
+    xc.r9 = pt->r9;                             \
+    xc.r10 = pt->r10;                           \
+    xc.r11 = pt->r11;                           \
+    xc.r12 = pt->r12;                           \
+    xc.r13 = pt->r13;                           \
+    xc.r14 = pt->r14;                           \
+    xc.r15 = pt->r15;                           \
+    xc.rbx = pt->rbx;                           \
+    xc.rcx = pt->rcx;                           \
+    xc.rdx = pt->rdx;                           \
+    xc.rsi = pt->rsi;                           \
+    xc.rdi = pt->rdi;                           \
+    xc.rbp = pt->rbp;                           \
+    xc.rax = pt->rax;                           \
+    xc.rip = pt->rip;                           \
+    xc.cs = pt->xcs;                            \
+    xc.eflags = pt->eflags;                     \
+    xc.rsp = pt->rsp;                           \
+    xc.ss = pt->xss;                            \
+    xc.es = pt->xes;                            \
+    xc.ds = pt->xds;                            \
+    xc.fs = pt->xfs;                            \
+    xc.gs = pt->xgs;                            \
+}
+
+#elif __i386__
 
 struct gdb_regs {
     long ebx; /* 0 */
@@ -30,8 +120,6 @@
     int  xss;    /* 64 */
 };
 
-
-#define printval(x) printf("%s = %lx\n", #x, (long)x);
 #define SET_PT_REGS(pt, xc)                     \
 {                                               \
     pt.ebx = xc.ebx;                            \
@@ -71,7 +159,9 @@
     xc.fs = pt->xfs;                            \
     xc.gs = pt->xgs;                            \
 }
+#endif
 
+#define printval(x) printf("%s = %lx\n", #x, (long)x);
 #define vtopdi(va) ((va) >> PDRSHIFT)
 #define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
 #endif

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.