ia64/xen-unstable
changeset 6971:872cf6ee0594
merge?
line diff
1.1 --- a/.hgignore Mon Sep 19 16:02:32 2005 +0000 1.2 +++ b/.hgignore Mon Sep 19 16:02:54 2005 +0000 1.3 @@ -86,6 +86,9 @@ 1.4 ^tools/check/\..*$ 1.5 ^tools/console/xenconsoled$ 1.6 ^tools/console/xenconsole$ 1.7 +^tools/debugger/gdb/gdb-6\.2\.1\.tar\.bz2$ 1.8 +^tools/debugger/gdb/gdb-6\.2\.1/.*$ 1.9 +^tools/debugger/gdb/gdb-6\.2\.1-linux-i386-xen/.*$ 1.10 ^tools/debugger/pdb/pdb$ 1.11 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$ 1.12 ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$ 1.13 @@ -156,6 +159,7 @@ 1.14 ^tools/xenstore/xs_stress$ 1.15 ^tools/xenstore/xs_test$ 1.16 ^tools/xenstore/xs_watch_stress$ 1.17 +^tools/xentrace/xenctx$ 1.18 ^tools/xentrace/xentrace$ 1.19 ^xen/BLOG$ 1.20 ^xen/TAGS$
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/tools/debugger/gdb/README Mon Sep 19 16:02:54 2005 +0000 14.3 @@ -0,0 +1,29 @@ 14.4 + 14.5 +DomU GDB server for 32-bit (PAE and non-PAE) systems 14.6 +---------------------------------------------------- 14.7 + 14.8 +Lines marked below with [*] are optional, if you want full 14.9 +source-level debugging of your kernel image. 14.10 + 14.11 +To build the GDB server: 14.12 + 1. Run ./gdbbuild from within this directory. 14.13 + 2. Copy ./gdb-6.2.1-linux-i386-xen/gdb/gdbserver/gdbserver-xen 14.14 + to your test machine. 14.15 + 14.16 +To build a debuggable guest kernel image: 14.17 + 1. cd linux-2.6.12-xenU 14.18 + 2. ARCH=xen make menuconfig 14.19 + 3. From within the configurator, enable the following options: 14.20 + # Kernel hacking -> Compile the kernel with debug info [*] 14.21 + -> Compile the kernel with frame pointers 14.22 + 4. (Re)build and (re)install your xenU kernel image. 14.23 + 14.24 +To debug a running guest: 14.25 + 1. Use 'xm list' to discover its domain id ($domid). 14.26 + 2. Run 'gdbserver-xen 127.0.0.1:9999 --attach $domid' 14.27 + 3. Run 'gdb /path/to/vmlinux-syms-2.6.xx-xenU' 14.28 + 4. From within the gdb client session: 14.29 + # directory /path/to/linux-2.6.xx-xenU [*] 14.30 + # target remote 127.0.0.1:9999 14.31 + # bt 14.32 + # disass
15.1 --- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c Mon Sep 19 16:02:32 2005 +0000 15.2 +++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c Mon Sep 19 16:02:54 2005 +0000 15.3 @@ -37,9 +37,10 @@ 15.4 #include <errno.h> 15.5 #include <xenctrl.h> 15.6 #define TRACE_ENTER /* printf("enter %s\n", __FUNCTION__) */ 15.7 -long (*myptrace)(enum __ptrace_request, pid_t, long, long); 15.8 -int (*myxcwait)(int domain, int *status, int options) ; 15.9 15.10 +long (*myptrace)(int xc_handle, enum __ptrace_request, u32, long, long); 15.11 +int (*myxcwait)(int xc_handle, int domain, int *status, int options) ; 15.12 +static int xc_handle; 15.13 15.14 #define DOMFLAGS_DYING (1<<0) /* Domain is scheduled to die. */ 15.15 #define DOMFLAGS_SHUTDOWN (1<<2) /* The guest OS has shut down. */ 15.16 @@ -47,11 +48,7 @@ int (*myxcwait)(int domain, int *status, 15.17 #define DOMFLAGS_BLOCKED (1<<4) /* Currently blocked pending an event. */ 15.18 #define DOMFLAGS_RUNNING (1<<5) /* Domain is currently running. */ 15.19 15.20 - 15.21 - 15.22 struct inferior_list all_processes; 15.23 - 15.24 - 15.25 static int current_domain; 15.26 static int expect_signal = 0; 15.27 static int signal_to_send = 0; 15.28 @@ -150,7 +147,7 @@ linux_attach (int domain) 15.29 { 15.30 struct process_info *new_process; 15.31 current_domain = domain; 15.32 - if (myptrace (PTRACE_ATTACH, domain, 0, 0) != 0) { 15.33 + if (myptrace (xc_handle, PTRACE_ATTACH, domain, 0, 0) != 0) { 15.34 fprintf (stderr, "Cannot attach to domain %d: %s (%d)\n", domain, 15.35 strerror (errno), errno); 15.36 fflush (stderr); 15.37 @@ -173,8 +170,7 @@ linux_kill_one_process (struct inferior_ 15.38 { 15.39 struct thread_info *thread = (struct thread_info *) entry; 15.40 struct process_info *process = get_thread_process (thread); 15.41 - myptrace (PTRACE_KILL, pid_of (process), 0, 0); 15.42 - 15.43 + myptrace (xc_handle, PTRACE_KILL, pid_of (process), 0, 0); 15.44 } 15.45 15.46 static void 15.47 @@ -190,7 +186,7 @@ linux_detach_one_process (struct inferio 15.48 struct thread_info *thread = (struct thread_info *) entry; 15.49 struct process_info *process = get_thread_process (thread); 15.50 15.51 - myptrace (PTRACE_DETACH, pid_of (process), 0, 0); 15.52 + myptrace (xc_handle, PTRACE_DETACH, pid_of (process), 0, 0); 15.53 } 15.54 15.55 15.56 @@ -216,7 +212,7 @@ static unsigned char 15.57 linux_wait (char *status) 15.58 { 15.59 int w; 15.60 - if (myxcwait(current_domain, &w, 0)) 15.61 + if (myxcwait(xc_handle, current_domain, &w, 0)) 15.62 return -1; 15.63 15.64 if (w & (DOMFLAGS_SHUTDOWN|DOMFLAGS_DYING)) { 15.65 @@ -241,7 +237,7 @@ linux_resume (struct thread_resume *resu 15.66 expect_signal = resume_info->sig; 15.67 for_each_inferior(&all_threads, regcache_invalidate_one); 15.68 15.69 - myptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, current_domain, 0, 0); 15.70 + myptrace (xc_handle, step ? PTRACE_SINGLESTEP : PTRACE_CONT, current_domain, 0, 0); 15.71 15.72 } 15.73 15.74 @@ -265,7 +261,7 @@ regsets_fetch_inferior_registers () 15.75 } 15.76 15.77 buf = malloc (regset->size); 15.78 - res = myptrace (regset->get_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf); 15.79 + res = myptrace (xc_handle, regset->get_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf); 15.80 if (res < 0) 15.81 { 15.82 if (errno == EIO) 15.83 @@ -317,7 +313,7 @@ regsets_store_inferior_registers () 15.84 15.85 buf = malloc (regset->size); 15.86 regset->fill_function (buf); 15.87 - res = myptrace (regset->set_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf); 15.88 + res = myptrace (xc_handle, regset->set_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf); 15.89 if (res < 0) 15.90 { 15.91 if (errno == EIO) 15.92 @@ -395,7 +391,7 @@ linux_read_memory (CORE_ADDR memaddr, ch 15.93 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) 15.94 { 15.95 errno = 0; 15.96 - buffer[i] = myptrace (PTRACE_PEEKTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); 15.97 + buffer[i] = myptrace (xc_handle, PTRACE_PEEKTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); 15.98 if (errno) 15.99 return errno; 15.100 } 15.101 @@ -428,13 +424,13 @@ linux_write_memory (CORE_ADDR memaddr, c 15.102 15.103 /* Fill start and end extra bytes of buffer with existing memory data. */ 15.104 15.105 - buffer[0] = myptrace (PTRACE_PEEKTEXT, inferior_pid, 15.106 + buffer[0] = myptrace (xc_handle, PTRACE_PEEKTEXT, inferior_pid, 15.107 (PTRACE_ARG3_TYPE) addr, 0); 15.108 15.109 if (count > 1) 15.110 { 15.111 buffer[count - 1] 15.112 - = myptrace (PTRACE_PEEKTEXT, inferior_pid, 15.113 + = myptrace (xc_handle, PTRACE_PEEKTEXT, inferior_pid, 15.114 (PTRACE_ARG3_TYPE) (addr + (count - 1) 15.115 * sizeof (PTRACE_XFER_TYPE)), 15.116 0); 15.117 @@ -448,7 +444,7 @@ linux_write_memory (CORE_ADDR memaddr, c 15.118 for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE)) 15.119 { 15.120 errno = 0; 15.121 - myptrace (PTRACE_POKETEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]); 15.122 + myptrace (xc_handle, PTRACE_POKETEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]); 15.123 if (errno) 15.124 return errno; 15.125 } 15.126 @@ -539,7 +535,7 @@ linux_init_signals () 15.127 void 15.128 initialize_low (void) 15.129 { 15.130 - 15.131 + xc_handle = xc_interface_open(); 15.132 set_target_ops (&linux_xen_target_ops); 15.133 set_breakpoint_data (the_low_target.breakpoint, 15.134 the_low_target.breakpoint_len);
16.1 --- a/tools/debugger/gdb/gdbbuild Mon Sep 19 16:02:32 2005 +0000 16.2 +++ b/tools/debugger/gdb/gdbbuild Mon Sep 19 16:02:54 2005 +0000 16.3 @@ -1,20 +1,17 @@ 16.4 #!/bin/sh 16.5 16.6 -XENROOT=`hg root` 16.7 -export XENROOT 16.8 - 16.9 -cd $XENROOT/tools/debugger/gdb 16.10 -rm -rf gdb-6.2.1 gdb-6.2.1-linux-i386-xen 16.11 -# FIXME:cw this should be smarter 16.12 -wget -c ftp://ftp.gnu.org/gnu/gdb/gdb-6.2.1.tar.bz2 16.13 +rm -rf gdb-6.2.1 gdb-6.2.1-linux-i386-xen 16.14 +[ -a gdb-6.2.1.tar.bz2 ] || wget -c ftp://ftp.gnu.org/gnu/gdb/gdb-6.2.1.tar.bz2 16.15 tar xjf gdb-6.2.1.tar.bz2 16.16 16.17 -cd $XENROOT/tools/debugger/gdb/gdb-6.2.1-xen-sparse 16.18 +cd gdb-6.2.1-xen-sparse 16.19 ./mkbuildtree ../gdb-6.2.1 16.20 16.21 -mkdir $XENROOT/tools/debugger/gdb/gdb-6.2.1-linux-i386-xen 16.22 -cd $XENROOT/tools/debugger/gdb/gdb-6.2.1-linux-i386-xen 16.23 +cd .. 16.24 +mkdir gdb-6.2.1-linux-i386-xen 16.25 +cd gdb-6.2.1-linux-i386-xen 16.26 ../gdb-6.2.1/configure 16.27 + 16.28 # some people don't have gmake 16.29 if which gmake ; then 16.30 gmake -j4
17.1 --- a/tools/libxc/Makefile Mon Sep 19 16:02:32 2005 +0000 17.2 +++ b/tools/libxc/Makefile Mon Sep 19 16:02:54 2005 +0000 17.3 @@ -30,8 +30,10 @@ BUILD_SRCS += xc_load_elf.c 17.4 ifeq ($(XEN_TARGET_ARCH),ia64) 17.5 BUILD_SRCS += xc_ia64_stubs.c 17.6 else 17.7 +ifeq ($(XEN_TARGET_ARCH),x86_32) 17.8 SRCS += xc_ptrace.c 17.9 SRCS += xc_ptrace_core.c 17.10 +endif 17.11 BUILD_SRCS += xc_load_aout9.c 17.12 BUILD_SRCS += xc_linux_restore.c 17.13 BUILD_SRCS += xc_linux_save.c
18.1 --- a/tools/libxc/xc_ptrace.c Mon Sep 19 16:02:32 2005 +0000 18.2 +++ b/tools/libxc/xc_ptrace.c Mon Sep 19 16:02:54 2005 +0000 18.3 @@ -1,6 +1,7 @@ 18.4 #include <sys/ptrace.h> 18.5 #include <sys/wait.h> 18.6 #include "xc_private.h" 18.7 +#include "xg_private.h" 18.8 #include <time.h> 18.9 18.10 #define X86_CR0_PE 0x00000001 /* Enable Protected Mode (RW) */ 18.11 @@ -10,14 +11,6 @@ 18.12 #define PSL_T 0x00000100 /* trace enable bit */ 18.13 #define VCPU 0 /* XXX */ 18.14 18.15 -/* 18.16 - * long 18.17 - * ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); 18.18 - */ 18.19 - 18.20 - 18.21 -int waitdomain(int domain, int *status, int options); 18.22 - 18.23 char * ptrace_names[] = { 18.24 "PTRACE_TRACEME", 18.25 "PTRACE_PEEKTEXT", 18.26 @@ -122,8 +115,6 @@ struct gdb_regs { 18.27 #define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff) 18.28 18.29 /* XXX application state */ 18.30 - 18.31 -static int xc_handle; 18.32 static long nr_pages = 0; 18.33 unsigned long *page_array = NULL; 18.34 static int regs_valid[MAX_VIRT_CPUS]; 18.35 @@ -133,14 +124,60 @@ static vcpu_guest_context_t ctxt[MAX_VIR 18.36 static inline int paging_enabled(vcpu_guest_context_t *v) 18.37 { 18.38 unsigned long cr0 = v->ctrlreg[0]; 18.39 - 18.40 return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG); 18.41 } 18.42 18.43 /* --------------------- */ 18.44 18.45 static void * 18.46 -map_domain_va(unsigned long domid, int cpu, void * guest_va, int perm) 18.47 +map_domain_va_pae( 18.48 + int xc_handle, 18.49 + unsigned long domid, 18.50 + int cpu, 18.51 + void *guest_va, 18.52 + int perm) 18.53 +{ 18.54 + unsigned long l2p, l1p, p, va = (unsigned long)guest_va; 18.55 + u64 *l3, *l2, *l1; 18.56 + static void *v; 18.57 + 18.58 + FETCH_REGS(cpu); 18.59 + 18.60 + l3 = xc_map_foreign_range( 18.61 + xc_handle, domid, PAGE_SIZE, PROT_READ, cr3[cpu] >> PAGE_SHIFT); 18.62 + if ( l3 == NULL ) 18.63 + goto error_out; 18.64 + 18.65 + l2p = l3[l3_table_offset_pae(va)] >> PAGE_SHIFT; 18.66 + l2 = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, PROT_READ, l2p); 18.67 + if ( l2 == NULL ) 18.68 + goto error_out; 18.69 + 18.70 + l1p = l2[l2_table_offset_pae(va)] >> PAGE_SHIFT; 18.71 + l1 = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, perm, l1p); 18.72 + if ( l1 == NULL ) 18.73 + goto error_out; 18.74 + 18.75 + p = l1[l1_table_offset_pae(va)] >> PAGE_SHIFT; 18.76 + if ( v != NULL ) 18.77 + munmap(v, PAGE_SIZE); 18.78 + v = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, perm, p); 18.79 + if ( v == NULL ) 18.80 + goto error_out; 18.81 + 18.82 + return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1))); 18.83 + 18.84 + error_out: 18.85 + return NULL; 18.86 +} 18.87 + 18.88 +static void * 18.89 +map_domain_va( 18.90 + int xc_handle, 18.91 + unsigned long domid, 18.92 + int cpu, 18.93 + void *guest_va, 18.94 + int perm) 18.95 { 18.96 unsigned long pde, page; 18.97 unsigned long va = (unsigned long)guest_va; 18.98 @@ -151,20 +188,35 @@ map_domain_va(unsigned long domid, int c 18.99 static unsigned long pde_phys[MAX_VIRT_CPUS]; 18.100 static unsigned long *pde_virt[MAX_VIRT_CPUS]; 18.101 static unsigned long page_phys[MAX_VIRT_CPUS]; 18.102 - static unsigned long *page_virt[MAX_VIRT_CPUS]; 18.103 - 18.104 + static unsigned long *page_virt[MAX_VIRT_CPUS]; 18.105 static int prev_perm[MAX_VIRT_CPUS]; 18.106 + static enum { MODE_UNKNOWN, MODE_32, MODE_PAE } mode; 18.107 18.108 - if (nr_pages != npgs) { 18.109 - if (nr_pages > 0) 18.110 + if ( mode == MODE_UNKNOWN ) 18.111 + { 18.112 + xen_capabilities_info_t caps; 18.113 + (void)xc_version(xc_handle, XENVER_capabilities, caps); 18.114 + mode = MODE_32; 18.115 + if ( strstr(caps, "_x86_32p") ) 18.116 + mode = MODE_PAE; 18.117 + } 18.118 + 18.119 + if ( mode == MODE_PAE ) 18.120 + return map_domain_va_pae(xc_handle, domid, cpu, guest_va, perm); 18.121 + 18.122 + if ( nr_pages != npgs ) 18.123 + { 18.124 + if ( nr_pages > 0 ) 18.125 free(page_array); 18.126 nr_pages = npgs; 18.127 - if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) { 18.128 + if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ) 18.129 + { 18.130 printf("Could not allocate memory\n"); 18.131 goto error_out; 18.132 } 18.133 - 18.134 - if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) { 18.135 + if ( xc_get_pfn_list(xc_handle, domid, 18.136 + page_array, nr_pages) != nr_pages ) 18.137 + { 18.138 printf("Could not get the page frame list\n"); 18.139 goto error_out; 18.140 } 18.141 @@ -172,48 +224,52 @@ map_domain_va(unsigned long domid, int c 18.142 18.143 FETCH_REGS(cpu); 18.144 18.145 - if (cr3[cpu] != cr3_phys[cpu]) 18.146 + if ( cr3[cpu] != cr3_phys[cpu] ) 18.147 { 18.148 cr3_phys[cpu] = cr3[cpu]; 18.149 - if (cr3_virt[cpu]) 18.150 + if ( cr3_virt[cpu] ) 18.151 munmap(cr3_virt[cpu], PAGE_SIZE); 18.152 - if ((cr3_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, 18.153 - PROT_READ, 18.154 - cr3_phys[cpu] >> PAGE_SHIFT)) == NULL) 18.155 + cr3_virt[cpu] = xc_map_foreign_range( 18.156 + xc_handle, domid, PAGE_SIZE, PROT_READ, 18.157 + cr3_phys[cpu] >> PAGE_SHIFT); 18.158 + if ( cr3_virt[cpu] == NULL ) 18.159 goto error_out; 18.160 - } 18.161 - if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */ 18.162 + } 18.163 + if ( (pde = cr3_virt[cpu][vtopdi(va)]) == 0 ) 18.164 goto error_out; 18.165 - if ((ctxt[cpu].flags & VGCF_VMX_GUEST) && paging_enabled(&ctxt[cpu])) 18.166 + if ( (ctxt[cpu].flags & VGCF_VMX_GUEST) && paging_enabled(&ctxt[cpu]) ) 18.167 pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT; 18.168 - if (pde != pde_phys[cpu]) 18.169 + if ( pde != pde_phys[cpu] ) 18.170 { 18.171 pde_phys[cpu] = pde; 18.172 - if (pde_virt[cpu]) 18.173 + if ( pde_virt[cpu] ) 18.174 munmap(pde_virt[cpu], PAGE_SIZE); 18.175 - if ((pde_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, 18.176 - PROT_READ, 18.177 - pde_phys[cpu] >> PAGE_SHIFT)) == NULL) 18.178 + pde_virt[cpu] = xc_map_foreign_range( 18.179 + xc_handle, domid, PAGE_SIZE, PROT_READ, 18.180 + pde_phys[cpu] >> PAGE_SHIFT); 18.181 + if ( pde_virt[cpu] == NULL ) 18.182 goto error_out; 18.183 } 18.184 - if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */ 18.185 + if ( (page = pde_virt[cpu][vtopti(va)]) == 0 ) 18.186 goto error_out; 18.187 - if (ctxt[cpu].flags & VGCF_VMX_GUEST && paging_enabled(&ctxt[cpu])) 18.188 + if ( (ctxt[cpu].flags & VGCF_VMX_GUEST) && paging_enabled(&ctxt[cpu]) ) 18.189 page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT; 18.190 - if (page != page_phys[cpu] || perm != prev_perm[cpu]) 18.191 + if ( (page != page_phys[cpu]) || (perm != prev_perm[cpu]) ) 18.192 { 18.193 page_phys[cpu] = page; 18.194 - if (page_virt[cpu]) 18.195 + if ( page_virt[cpu] ) 18.196 munmap(page_virt[cpu], PAGE_SIZE); 18.197 - if ((page_virt[cpu] = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, 18.198 - perm, 18.199 - page_phys[cpu] >> PAGE_SHIFT)) == NULL) { 18.200 - printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va)); 18.201 + page_virt[cpu] = xc_map_foreign_range( 18.202 + xc_handle, domid, PAGE_SIZE, perm, 18.203 + page_phys[cpu] >> PAGE_SHIFT); 18.204 + if ( page_virt[cpu] == NULL ) 18.205 + { 18.206 page_phys[cpu] = 0; 18.207 goto error_out; 18.208 } 18.209 prev_perm[cpu] = perm; 18.210 } 18.211 + 18.212 return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK)); 18.213 18.214 error_out: 18.215 @@ -221,7 +277,11 @@ map_domain_va(unsigned long domid, int c 18.216 } 18.217 18.218 int 18.219 -xc_waitdomain(int domain, int *status, int options) 18.220 +xc_waitdomain( 18.221 + int xc_handle, 18.222 + int domain, 18.223 + int *status, 18.224 + int options) 18.225 { 18.226 dom0_op_t op; 18.227 int retval; 18.228 @@ -229,38 +289,39 @@ xc_waitdomain(int domain, int *status, i 18.229 ts.tv_sec = 0; 18.230 ts.tv_nsec = 10*1000*1000; 18.231 18.232 - if (!xc_handle) 18.233 - if ((xc_handle = xc_interface_open()) < 0) 18.234 - { 18.235 - printf("xc_interface_open failed\n"); 18.236 - return -1; 18.237 - } 18.238 op.cmd = DOM0_GETDOMAININFO; 18.239 op.u.getdomaininfo.domain = domain; 18.240 + 18.241 retry: 18.242 - 18.243 retval = do_dom0_op(xc_handle, &op); 18.244 - if (retval || op.u.getdomaininfo.domain != domain) { 18.245 + if ( retval || (op.u.getdomaininfo.domain != domain) ) 18.246 + { 18.247 printf("getdomaininfo failed\n"); 18.248 goto done; 18.249 } 18.250 *status = op.u.getdomaininfo.flags; 18.251 18.252 - if (options & WNOHANG) 18.253 + if ( options & WNOHANG ) 18.254 goto done; 18.255 - 18.256 18.257 - if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)) { 18.258 + if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) 18.259 + { 18.260 nanosleep(&ts,NULL); 18.261 goto retry; 18.262 } 18.263 + 18.264 done: 18.265 return retval; 18.266 18.267 } 18.268 18.269 long 18.270 -xc_ptrace(enum __ptrace_request request, u32 domid, long eaddr, long edata) 18.271 +xc_ptrace( 18.272 + int xc_handle, 18.273 + enum __ptrace_request request, 18.274 + u32 domid, 18.275 + long eaddr, 18.276 + long edata) 18.277 { 18.278 dom0_op_t op; 18.279 int status = 0; 18.280 @@ -273,44 +334,51 @@ xc_ptrace(enum __ptrace_request request, 18.281 18.282 op.interface_version = DOM0_INTERFACE_VERSION; 18.283 18.284 - if (!xc_handle) 18.285 - if ((xc_handle = xc_interface_open()) < 0) 18.286 - return -1; 18.287 -#if 0 18.288 - printf("%20s %d, %p, %p \n", ptrace_names[request], domid, addr, data); 18.289 -#endif 18.290 - switch (request) { 18.291 + switch ( request ) 18.292 + { 18.293 case PTRACE_PEEKTEXT: 18.294 case PTRACE_PEEKDATA: 18.295 - if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ)) == NULL) { 18.296 + guest_va = (unsigned long *)map_domain_va( 18.297 + xc_handle, domid, cpu, addr, PROT_READ); 18.298 + if ( guest_va == NULL ) 18.299 + { 18.300 status = EFAULT; 18.301 goto error_out; 18.302 } 18.303 - 18.304 retval = *guest_va; 18.305 break; 18.306 + 18.307 case PTRACE_POKETEXT: 18.308 case PTRACE_POKEDATA: 18.309 - if ((guest_va = (unsigned long *)map_domain_va(domid, cpu, addr, PROT_READ|PROT_WRITE)) == NULL) { 18.310 + guest_va = (unsigned long *)map_domain_va( 18.311 + xc_handle, domid, cpu, addr, PROT_READ|PROT_WRITE); 18.312 + if ( guest_va == NULL ) 18.313 + { 18.314 status = EFAULT; 18.315 goto error_out; 18.316 } 18.317 - 18.318 *guest_va = (unsigned long)data; 18.319 break; 18.320 + 18.321 case PTRACE_GETREGS: 18.322 case PTRACE_GETFPREGS: 18.323 case PTRACE_GETFPXREGS: 18.324 FETCH_REGS(cpu); 18.325 - 18.326 - if (request == PTRACE_GETREGS) { 18.327 + if ( request == PTRACE_GETREGS ) 18.328 + { 18.329 SET_PT_REGS(pt, ctxt[cpu].user_regs); 18.330 memcpy(data, &pt, sizeof(struct gdb_regs)); 18.331 - } else if (request == PTRACE_GETFPREGS) 18.332 + } 18.333 + else if (request == PTRACE_GETFPREGS) 18.334 + { 18.335 memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt)); 18.336 + } 18.337 else /*if (request == PTRACE_GETFPXREGS)*/ 18.338 + { 18.339 memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt)); 18.340 + } 18.341 break; 18.342 + 18.343 case PTRACE_SETREGS: 18.344 op.cmd = DOM0_SETDOMAININFO; 18.345 SET_XC_REGS(((struct gdb_regs *)data), ctxt[VCPU].user_regs); 18.346 @@ -321,17 +389,19 @@ xc_ptrace(enum __ptrace_request request, 18.347 retval = do_dom0_op(xc_handle, &op); 18.348 if (retval) 18.349 goto error_out; 18.350 + break; 18.351 18.352 - break; 18.353 case PTRACE_ATTACH: 18.354 op.cmd = DOM0_GETDOMAININFO; 18.355 op.u.getdomaininfo.domain = domid; 18.356 retval = do_dom0_op(xc_handle, &op); 18.357 - if (retval || op.u.getdomaininfo.domain != domid) { 18.358 + if ( retval || (op.u.getdomaininfo.domain != domid) ) 18.359 + { 18.360 perror("dom0 op failed"); 18.361 goto error_out; 18.362 } 18.363 - if (op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) { 18.364 + if ( op.u.getdomaininfo.flags & DOMFLAGS_PAUSED ) 18.365 + { 18.366 printf("domain currently paused\n"); 18.367 goto error_out; 18.368 } 18.369 @@ -340,6 +410,7 @@ xc_ptrace(enum __ptrace_request request, 18.370 op.u.pausedomain.domain = domid; 18.371 retval = do_dom0_op(xc_handle, &op); 18.372 break; 18.373 + 18.374 case PTRACE_SINGLESTEP: 18.375 ctxt[VCPU].user_regs.eflags |= PSL_T; 18.376 op.cmd = DOM0_SETDOMAININFO; 18.377 @@ -347,24 +418,29 @@ xc_ptrace(enum __ptrace_request request, 18.378 op.u.setdomaininfo.vcpu = 0; 18.379 op.u.setdomaininfo.ctxt = &ctxt[cpu]; 18.380 retval = do_dom0_op(xc_handle, &op); 18.381 - if (retval) { 18.382 + if ( retval ) 18.383 + { 18.384 perror("dom0 op failed"); 18.385 goto error_out; 18.386 } 18.387 /* FALLTHROUGH */ 18.388 + 18.389 case PTRACE_CONT: 18.390 case PTRACE_DETACH: 18.391 - if (request != PTRACE_SINGLESTEP) { 18.392 + if ( request != PTRACE_SINGLESTEP ) 18.393 + { 18.394 FETCH_REGS(cpu); 18.395 /* Clear trace flag */ 18.396 - if (ctxt[cpu].user_regs.eflags & PSL_T) { 18.397 + if ( ctxt[cpu].user_regs.eflags & PSL_T ) 18.398 + { 18.399 ctxt[cpu].user_regs.eflags &= ~PSL_T; 18.400 op.cmd = DOM0_SETDOMAININFO; 18.401 op.u.setdomaininfo.domain = domid; 18.402 op.u.setdomaininfo.vcpu = cpu; 18.403 op.u.setdomaininfo.ctxt = &ctxt[cpu]; 18.404 retval = do_dom0_op(xc_handle, &op); 18.405 - if (retval) { 18.406 + if ( retval ) 18.407 + { 18.408 perror("dom0 op failed"); 18.409 goto error_out; 18.410 } 18.411 @@ -375,6 +451,7 @@ xc_ptrace(enum __ptrace_request request, 18.412 op.u.unpausedomain.domain = domid > 0 ? domid : -domid; 18.413 retval = do_dom0_op(xc_handle, &op); 18.414 break; 18.415 + 18.416 case PTRACE_SETFPREGS: 18.417 case PTRACE_SETFPXREGS: 18.418 case PTRACE_PEEKUSER: 18.419 @@ -387,15 +464,18 @@ xc_ptrace(enum __ptrace_request request, 18.420 /* XXX not yet supported */ 18.421 status = ENOSYS; 18.422 break; 18.423 + 18.424 case PTRACE_TRACEME: 18.425 printf("PTRACE_TRACEME is an invalid request under Xen\n"); 18.426 status = EINVAL; 18.427 } 18.428 18.429 - if (status) { 18.430 + if ( status ) 18.431 + { 18.432 errno = status; 18.433 retval = -1; 18.434 } 18.435 + 18.436 error_out: 18.437 return retval; 18.438 }
19.1 --- a/tools/libxc/xc_ptrace_core.c Mon Sep 19 16:02:32 2005 +0000 19.2 +++ b/tools/libxc/xc_ptrace_core.c Mon Sep 19 16:02:54 2005 +0000 19.3 @@ -166,7 +166,11 @@ map_domain_va(unsigned long domfd, int c 19.4 } 19.5 19.6 int 19.7 -xc_waitdomain_core(int domfd, int *status, int options) 19.8 +xc_waitdomain_core( 19.9 + int xc_handle, 19.10 + int domfd, 19.11 + int *status, 19.12 + int options) 19.13 { 19.14 int retval = -1; 19.15 int nr_vcpus; 19.16 @@ -215,7 +219,12 @@ xc_waitdomain_core(int domfd, int *statu 19.17 } 19.18 19.19 long 19.20 -xc_ptrace_core(enum __ptrace_request request, u32 domfd, long eaddr, long edata) 19.21 +xc_ptrace_core( 19.22 + int xc_handle, 19.23 + enum __ptrace_request request, 19.24 + u32 domfd, 19.25 + long eaddr, 19.26 + long edata) 19.27 { 19.28 int status = 0; 19.29 struct gdb_regs pt;
20.1 --- a/tools/libxc/xenctrl.h Mon Sep 19 16:02:32 2005 +0000 20.2 +++ b/tools/libxc/xenctrl.h Mon Sep 19 16:02:54 2005 +0000 20.3 @@ -101,23 +101,31 @@ typedef struct xc_core_header { 20.4 } xc_core_header_t; 20.5 20.6 20.7 -long xc_ptrace(enum __ptrace_request request, 20.8 - u32 domid, 20.9 - long addr, 20.10 - long data); 20.11 +long xc_ptrace( 20.12 + int xc_handle, 20.13 + enum __ptrace_request request, 20.14 + u32 domid, 20.15 + long addr, 20.16 + long data); 20.17 20.18 -long xc_ptrace_core(enum __ptrace_request request, 20.19 - u32 domid, 20.20 - long addr, 20.21 - long data); 20.22 +long xc_ptrace_core( 20.23 + int xc_handle, 20.24 + enum __ptrace_request request, 20.25 + u32 domid, 20.26 + long addr, 20.27 + long data); 20.28 20.29 -int xc_waitdomain(int domain, 20.30 - int *status, 20.31 - int options); 20.32 +int xc_waitdomain( 20.33 + int xc_handle, 20.34 + int domain, 20.35 + int *status, 20.36 + int options); 20.37 20.38 -int xc_waitdomain_core(int domain, 20.39 - int *status, 20.40 - int options); 20.41 +int xc_waitdomain_core( 20.42 + int xc_handle, 20.43 + int domain, 20.44 + int *status, 20.45 + int options); 20.46 20.47 /* 20.48 * DOMAIN MANAGEMENT FUNCTIONS