WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1/1] NEW: 32bit gdbserver-xen/libxc to debug 64bit gu

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 1/1] NEW: 32bit gdbserver-xen/libxc to debug 64bit guest
From: Mukesh Rathor <mukesh.rathor@xxxxxxxxxx>
Date: Fri, 02 Nov 2007 16:46:13 -0700
Cc: "Kurt C. Hackel" <kurt.hackel@xxxxxxxxxx>
Delivery-date: Fri, 02 Nov 2007 16:47:00 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: Oracle Corp
Reply-to: mukesh.rathor@xxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.5 (X11/20070719)
files in gdbserver directory.
diff -uNpr 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
--- 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
      2007-09-12 17:43:17.000000000 -0700
+++ 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
       2007-11-02 16:21:26.464696000 -0700
@@ -69,8 +69,13 @@ struct pending_signals
   struct pending_signals *prev;
 };
 
-#define PTRACE_ARG3_TYPE long
-#define PTRACE_XFER_TYPE long
+#ifdef _GDB_CROSS_COMP
+#define PTRACE_ARG3_TYPE unsigned long long
+#define PTRACE_XFER_TYPE unsigned long long
+#else
+#define PTRACE_ARG3_TYPE unsigned long 
+#define PTRACE_XFER_TYPE unsigned long
+#endif
 
 static int use_regsets_p = 1;
 
@@ -157,7 +162,8 @@ linux_attach (int domid)
     add_thread (0, new_process);
     new_process->stop_expected = 0;
 
-    if (xc_ptrace (xc_handle, PTRACE_ATTACH, domid, 0, isfile) != 0) {
+    if (xc_ptrace(xc_handle, PTRACE_ATTACH, domid, 0,(PTRACE_XFER_TYPE)isfile))
+    {
        fprintf (stderr, "Cannot attach to domain %d: %s (%d)\n", domid,
                 strerror (errno), errno);
        fflush (stderr);
@@ -261,8 +267,7 @@ regsets_fetch_inferior_registers ()
 
       buf = malloc (regset->size);
       res = xc_ptrace (xc_handle, regset->get_request, 
-                     curvcpuid(),
-                     0, (PTRACE_XFER_TYPE)buf);
+                     curvcpuid(), 0, (PTRACE_XFER_TYPE)buf);
       if (res < 0)
        {
          if (errno == EIO)
@@ -314,7 +319,8 @@ regsets_store_inferior_registers ()
 
       buf = malloc (regset->size);
       regset->fill_function (buf);
-      res = xc_ptrace (xc_handle, regset->set_request, curvcpuid(), 0, 
(PTRACE_XFER_TYPE)buf);
+      res = xc_ptrace (xc_handle, regset->set_request, curvcpuid(), 
+                       0, (PTRACE_XFER_TYPE)buf);
       if (res < 0)
        {
          if (errno == EIO)
@@ -392,7 +398,8 @@ linux_read_memory (CORE_ADDR memaddr, ch
   for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
-      buffer[i] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), 
(PTRACE_ARG3_TYPE) addr, 0);
+      buffer[i] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), 
+                             (PTRACE_ARG3_TYPE)addr, 0);
       if (errno)
        return errno;
     }
@@ -418,7 +425,7 @@ linux_write_memory (CORE_ADDR memaddr, c
   register int count
   = (((memaddr + len) - addr) + sizeof (PTRACE_XFER_TYPE) - 1) / sizeof 
(PTRACE_XFER_TYPE);
   /* Allocate buffer of that many longwords.  */
-  register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *) alloca (count * 
sizeof (PTRACE_XFER_TYPE));
+  register PTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE*)alloca(count * 
sizeof(PTRACE_XFER_TYPE));
   extern int errno;
 
   TRACE_ENTER;
@@ -426,15 +433,13 @@ linux_write_memory (CORE_ADDR memaddr, c
   /* Fill start and end extra bytes of buffer with existing memory data.  */
 
   buffer[0] = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(),
-                     (PTRACE_ARG3_TYPE) addr, 0);
+                        (PTRACE_ARG3_TYPE)addr, 0);
 
   if (count > 1)
     {
       buffer[count - 1]
        = xc_ptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(),
-                 (PTRACE_ARG3_TYPE) (addr + (count - 1)
-                                     * sizeof (PTRACE_XFER_TYPE)),
-                 0);
+                    (PTRACE_ARG3_TYPE)(addr + (count - 1) * 
sizeof(PTRACE_ARG3_TYPE)), 0);
     }
 
   /* Copy data to be written over corresponding part of buffer */
@@ -446,7 +451,7 @@ linux_write_memory (CORE_ADDR memaddr, c
     {
       errno = 0;
       xc_ptrace (xc_handle, PTRACE_POKETEXT, curvcpuid(), 
-               (PTRACE_ARG3_TYPE) addr, buffer[i]);
+                (PTRACE_ARG3_TYPE) addr, buffer[i]);
       if (errno)
        return errno;
     }
diff -uNpr 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in
 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in
--- 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in
  2007-09-12 17:43:17.000000000 -0700
+++ 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in
   2007-11-02 16:21:26.459696000 -0700
@@ -135,6 +135,14 @@ OBS = inferiors.o regcache.o remote-util
        $(DEPFILES)
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
 
+# if cross compiling to get a 32binary on a 64bit system, we statically link
+# the xenctrl lib, so as not to break anything
+ifneq "$(findstring _GDB_CROSS_COMP, $(CFLAGS))" ""
+        STATIC_LNK=-Wl,-Bstatic
+        STATIC_UNLNK=-Wl,-Bdynamic
+endif
+
+
 # Prevent Sun make from putting in the machine type.  Setting
 # TARGET_ARCH to nothing works for SunOS 3, 4.0, but not for 4.1.
 .c.o:
@@ -172,7 +180,7 @@ clean-info:
 gdbserver-xen: $(OBS) ${ADD_DEPS} ${CDEPS}
        rm -f gdbserver-xen
        ${CC-LD} $(GLOBAL_CFLAGS) $(LDFLAGS) -o gdbserver-xen $(OBS) \
-         $(GDBSERVER_LIBS) $(XM_CLIBS)
+         $(STATIC_LNK) $(GDBSERVER_LIBS) $(STATIC_UNLNK) $(XM_CLIBS)
 
 gdbreplay: gdbreplay.o
        rm -f gdbreplay
diff -uNpr 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/include/sys/user.h
 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/include/sys/user.h
--- 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/include/sys/user.h
 1969-12-31 16:00:00.000000000 -0800
+++ 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/include/sys/user.h
  2007-11-02 16:21:26.469696000 -0700
@@ -0,0 +1,181 @@
+/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C 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.1 of the License, or (at your option) any later version.
+
+   The GNU C 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 the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _SYS_USER_H
+#define _SYS_USER_H    1
+
+/* The whole purpose of this file is for GDB and GDB only.  Don't read
+   too much into it.  Don't use it for anything other than GDB unless
+   you know what you are doing.  */
+
+#include <bits/wordsize.h>
+
+#if defined(_GDB_CROSS_COMP)
+#define cross_reg_t unsigned long long
+#elif __WORDSIZE == 64
+#define cross_reg_t unsigned long
+#endif
+
+#if __WORDSIZE == 64
+
+struct user_fpregs_struct
+{
+  __uint16_t           cwd;
+  __uint16_t           swd;
+  __uint16_t           ftw;
+  __uint16_t           fop;
+  __uint64_t           rip;
+  __uint64_t           rdp;
+  __uint32_t           mxcsr;
+  __uint32_t           mxcr_mask;
+  __uint32_t           st_space[32];   /* 8*16 bytes for each FP-reg = 128 
bytes */
+  __uint32_t           xmm_space[64];  /* 16*16 bytes for each XMM-reg = 256 
bytes */
+  __uint32_t           padding[24];
+};
+
+struct user_regs_struct
+{
+  cross_reg_t r15;
+  cross_reg_t r14;
+  cross_reg_t r13;
+  cross_reg_t r12;
+  cross_reg_t rbp;
+  cross_reg_t rbx;
+  cross_reg_t r11;
+  cross_reg_t r10;
+  cross_reg_t r9;
+  cross_reg_t r8;
+  cross_reg_t rax;
+  cross_reg_t rcx;
+  cross_reg_t rdx;
+  cross_reg_t rsi;
+  cross_reg_t rdi;
+  cross_reg_t orig_rax;
+  cross_reg_t rip;
+  cross_reg_t cs;
+  cross_reg_t eflags;
+  cross_reg_t rsp;
+  cross_reg_t ss;
+  cross_reg_t fs_base;
+  cross_reg_t gs_base;
+  cross_reg_t ds;
+  cross_reg_t es;
+  cross_reg_t fs;
+  cross_reg_t gs;
+};
+
+struct user
+{
+  struct user_regs_struct      regs;
+  int                          u_fpvalid;
+  struct user_fpregs_struct    i387;
+  cross_reg_t int              u_tsize;
+  cross_reg_t int              u_dsize;
+  cross_reg_t int              u_ssize;
+  cross_reg_t                  start_code;
+  cross_reg_t                  start_stack;
+  cross_reg_t                  signal;
+  int                          reserved;
+  struct user_regs_struct*     u_ar0;
+  struct user_fpregs_struct*   u_fpstate;
+  cross_reg_t                  magic;
+  char                         u_comm [32];
+  cross_reg_t                  u_debugreg [8];
+};
+
+#else
+/* These are the 32-bit x86 structures.  */
+struct user_fpregs_struct
+{
+  long int cwd;
+  long int swd;
+  long int twd;
+  long int fip;
+  long int fcs;
+  long int foo;
+  long int fos;
+  long int st_space [20];
+};
+
+struct user_fpxregs_struct
+{
+  unsigned short int cwd;
+  unsigned short int swd;
+  unsigned short int twd;
+  unsigned short int fop;
+  long int fip;
+  long int fcs;
+  long int foo;
+  long int fos;
+  long int mxcsr;
+  long int reserved;
+  long int st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
+  long int xmm_space[32];  /* 8*16 bytes for each XMM-reg = 128 bytes */
+  long int padding[56];
+};
+
+struct user_regs_struct
+{
+  long int ebx;
+  long int ecx;
+  long int edx;
+  long int esi;
+  long int edi;
+  long int ebp;
+  long int eax;
+  long int xds;
+  long int xes;
+  long int xfs;
+  long int xgs;
+  long int orig_eax;
+  long int eip;
+  long int xcs;
+  long int eflags;
+  long int esp;
+  long int xss;
+};
+
+struct user
+{
+  struct user_regs_struct      regs;
+  int                          u_fpvalid;
+  struct user_fpregs_struct    i387;
+  unsigned long int            u_tsize;
+  unsigned long int            u_dsize;
+  unsigned long int            u_ssize;
+  unsigned long                        start_code;
+  unsigned long                        start_stack;
+  long int                     signal;
+  int                          reserved;
+  struct user_regs_struct*     u_ar0;
+  struct user_fpregs_struct*   u_fpstate;
+  unsigned long int            magic;
+  char                         u_comm [32];
+  int                          u_debugreg [8];
+};
+#endif  /* __WORDSIZE */
+
+#define PAGE_SHIFT             12
+#define PAGE_SIZE              (1UL << PAGE_SHIFT)
+#define PAGE_MASK              (~(PAGE_SIZE-1))
+#define NBPG                   PAGE_SIZE
+#define UPAGES                 1
+#define HOST_TEXT_START_ADDR   (u.start_code)
+#define HOST_STACK_END_ADDR    (u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _SYS_USER_H */
diff -uNpr 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree
--- 
orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree    
    2007-09-12 17:43:17.000000000 -0700
+++ new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree 
2007-11-02 16:21:26.473697000 -0700
@@ -66,7 +66,7 @@ relative_lndir ()
     (
     cd $i
     pref=`echo $i | sed -e 's#/[^/]*#../#g' -e 's#^\.##'`
-    for j in `find . -type f -o -type l -maxdepth 1`; do
+    for j in `find . -maxdepth 1 -type f -o -type l`; do
       ln -sf ${pref}${REAL_DIR}/$i/$j ${SYMLINK_DIR}/$i/$j
     done
     )
diff -uNpr orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdbbuild 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdbbuild
--- orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdbbuild        2007-09-12 
17:43:17.000000000 -0700
+++ new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/gdbbuild 2007-11-02 
16:21:26.477698000 -0700
@@ -22,7 +22,14 @@ cd gdb-$GDB_VERSION-linux-i386-xen
 if [ "$MAKE" ]; then
     $MAKE
 elif which gmake ; then
-    gmake -j4
+    MAKE="gmake -j4"
 else
-    make -j4
+    MAKE="make -j4"
+fi
+
+if [[ $1 == _GDB_CROSS_COMP ]]
+then
+       $MAKE CFLAGS="-m32 -D_GDB_CROSS_COMP -D __x86_64__" LDFLAGS="-m32"
+else
+       $MAKE
 fi
diff -uNpr orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/README 
new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/README
--- orig/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/README  2007-09-12 
17:43:17.000000000 -0700
+++ new/BUILD/xen-3.1.1-ovs/tools/debugger/gdb/README   2007-11-02 
16:21:26.481697000 -0700
@@ -5,11 +5,37 @@ DomU & HVM GDB server for 32-bit (PAE an
 Lines marked below with [*] are optional, if you want full
 source-level debugging of your kernel image.
 
-To build the GDB server:
- 0. Build rest of the Xen first from the base directory
- 1. Run ./gdbbuild from within this directory.
- 2. Copy ./gdb-6.2.1-linux-i386-xen/gdb/gdbserver/gdbserver-xen
-    to your test machine.
+gdbserver can run on 32bit or 64bit dom0. It can attach to a 32 bit non-PAE,
+a 32bit PAE, or an x86_64 guest:
+
+            32 non-PAE        32 PAE        x86_64
+32 dom0:        Y               Y             Y
+64 dom0:        ?               ?             Y
+
+
+TO BUILD: Involves two steps, building libxc and gdbserver-xen. After building,
+          copy gdbserver-xen, and possibly libxc to dom0:
+
+32 non-PAE (build on 32bit box) or x86_64 (build on x86_64 box) :
+    1. Build libxc first by running >make
+    2. Build gdbserver-xen by running >gdbbuild
+    3. copy ./gdb-6.2.1-linux-i386-xen/gdb/gdbserver/gdbserver-xen to dom0
+
+32 PAE (build on 32bit box) :
+    1. Build libxc first by running 
+        >CFLAGS="-D_CROSS_COMP_PAE" make
+    2. Build gdbserver-xen by running 
+        >gdbbuild
+    3. copy gdbserver-xen  and libxenctrl.so.3.0.0 to dom0
+
+x86_64 (build on x86_64 box to run on 32 domU) :
+    1. Build libxc first by running 
+        >CFLAGS="-m32 -D_GDB_CROSS_COMP" make
+    2. Build gdbserver-xen by running 
+        >gdbbuild  _GDB_CROSS_COMP
+    3. copy gdbserver-xen to dom0 (libxenctrl is statically linked in this 
case)
+
+
 
 To build a debuggable guest domU kernel image:
  1. cd linux-2.6.xx-xenU
@@ -28,6 +54,8 @@ To debug a running guest:
     # target remote 127.0.0.1:9999
     # bt
     # disass
+ 5. gdb could be running on a different host, in which case:
+    # target remote 127.11.11.11:9999 where 127.11.11.11 is the xen host.
 
 To debug a crashed domU guest:
  1. Add '(enable-dump yes)' to /etc/xen/xend-config.sxp before
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH 1/1] NEW: 32bit gdbserver-xen/libxc to debug 64bit guest, Mukesh Rathor <=