32bit gdbserver-xen/libxc to debug 64bit guest
PATCH 1/2 32bit gdbserver-xen/libxc to debug 64bit guest
part 1 : files changed in gdbserver xen-sparse tree.
tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c +22 -13
@@ -22,6 +22,10 @@#include "server.h" #include "linux-low.h" +#ifdef _GDB_CROSS_COMP +#include "user.h" +#endif +#include <sys/wait.h> #include <stdio.h> #include <sys/param.h>
@@ -69,8 +73,13 @@ struct pending_signalsstruct 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 +166,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 +271,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 +323,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 +402,8 @@ linux_read_memory (CORE_ADDR memaddr, chfor (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 +429,7 @@ linux_write_memory (CORE_ADDR memaddr, c registerint count = (((memaddr + len) - addr) +sizeof (PTRACE_XFER_TYPE ) -1 ) /sizeof (PTRACE_XFER_TYPE );/* Allocate buffer of that many longwords. */ - registerPTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *)alloca (count *sizeof (PTRACE_XFER_TYPE )); + registerPTRACE_XFER_TYPE *buffer = (PTRACE_XFER_TYPE *)alloca (count *sizeof (PTRACE_XFER_TYPE ));extern int errno;TRACE_ENTER ;
@@ -426,15 +437,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 +455,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; }
tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in +9 -1
@@ -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
tools/debugger/gdb/gdb-6.2.1-xen-sparse/mkbuildtree +1 -1
@@ -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 )
tools/debugger/gdb/gdbbuild +9 -2
@@ -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
tools/debugger/gdb/README +33 -5
@@ -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
[email protected]
http://lists.xensource.com/xen-devel