All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gdbserver-xen: fix corefile access
@ 2006-03-02  8:28 Horms
  2006-03-02 10:45 ` Keir Fraser
  0 siblings, 1 reply; 10+ messages in thread
From: Horms @ 2006-03-02  8:28 UTC (permalink / raw)
  To: xen-devel

# HG changeset patch
# User Horms <horms@verge.net.au>
# Node ID d15c3e045aa21d0753761121ef3c9a0f73c0e82a
# Parent  48cbeecfa8a4b438f72fbe440f0642344f2f24a4
gdbserver-xen: fix corefile access

This patch fixes corefile access by ensuring that the open fd
to the corefile (current_domid) is passed to the underlying
xc_routines as neccessary. Currently the prevailing pid is passed,
which works fine when attaching to a running domain, but fails
for the corefile case.

This is done by creaating a wrapper for curvcpuid(), called
curvcpuid_or_domfd() which returns current_domid if the
global isfile is set. This assumes that isfile is stable,
if this is not the caes, it could easily be saved at
the time that myptrace is set using this variable.

I did not replace curvcpuid(), as it seems to be needed
elsewhere, though it may be possible to eliminate it.

This patch also relocates curvcpuid() (without modifying it).
This is because curvcpuid_or_domfd() needs to below the
declaration of isfile, and it seems to make sense to put
curvcpuid() and curvcpuid_or_domfd() next to each other.

Signed-Off-By: Horms <horms@verge.net.au>

diff -r 48cbeecfa8a4 -r d15c3e045aa2 tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
--- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Thu Mar  2 09:30:54 2006 +0900
+++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Thu Mar  2 17:18:42 2006 +0900
@@ -45,17 +45,6 @@ int (*myxcwait)(int xc_handle, int domai
 int (*myxcwait)(int xc_handle, int domain, int *status, int options) ;
 static int xc_handle;
 
-static inline int
-curvcpuid()
-{
-  struct process_info *process;
-  if (current_inferior == NULL)
-      return 0;
-  process = get_thread_process(current_inferior);
-  return (process->thread_known ? process->tid : 0);
-
-}
-
 
 #define DOMFLAGS_DYING     (1<<0) /* Domain is scheduled to die.             */
 #define DOMFLAGS_SHUTDOWN  (1<<2) /* The guest OS has shut down.             */
@@ -87,6 +76,23 @@ struct pending_signals
 
 static int use_regsets_p = 1;
 
+static inline int
+curvcpuid()
+{
+  struct process_info *process;
+  if (current_inferior == NULL)
+      return 0;
+  process = get_thread_process(current_inferior);
+  return (process->thread_known ? process->tid : 0);
+}
+
+static inline int
+curvcpuid_or_domfd()
+{
+  if(isfile)
+	  return current_domid;
+  return curvcpuid();
+}
 
 #define pid_of(proc) ((proc)->head.id)
 
@@ -276,7 +282,7 @@ regsets_fetch_inferior_registers ()
 
       buf = malloc (regset->size);
       res = myptrace (xc_handle, regset->get_request, 
-		      curvcpuid(),
+		      curvcpuid_or_domfd(),
 		      0, (PTRACE_XFER_TYPE)buf);
       if (res < 0)
 	{
@@ -329,7 +335,7 @@ regsets_store_inferior_registers ()
 
       buf = malloc (regset->size);
       regset->fill_function (buf);
-      res = myptrace (xc_handle, regset->set_request, curvcpuid(), 0, (PTRACE_XFER_TYPE)buf);
+      res = myptrace (xc_handle, regset->set_request, curvcpuid_or_domfd(), 0, (PTRACE_XFER_TYPE)buf);
       if (res < 0)
 	{
 	  if (errno == EIO)
@@ -407,7 +413,7 @@ linux_read_memory (CORE_ADDR memaddr, ch
   for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
-      buffer[i] = myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(), (PTRACE_ARG3_TYPE) addr, 0);
+      buffer[i] = myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid_or_domfd(), (PTRACE_ARG3_TYPE) addr, 0);
       if (errno)
 	return errno;
     }
@@ -440,13 +446,13 @@ linux_write_memory (CORE_ADDR memaddr, c
 
   /* Fill start and end extra bytes of buffer with existing memory data.  */
 
-  buffer[0] = myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(),
+  buffer[0] = myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid_or_domfd(),
 		      (PTRACE_ARG3_TYPE) addr, 0);
 
   if (count > 1)
     {
       buffer[count - 1]
-	= myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid(),
+	= myptrace (xc_handle, PTRACE_PEEKTEXT, curvcpuid_or_domfd(),
 		  (PTRACE_ARG3_TYPE) (addr + (count - 1)
 				      * sizeof (PTRACE_XFER_TYPE)),
 		  0);
@@ -460,7 +466,7 @@ linux_write_memory (CORE_ADDR memaddr, c
   for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
     {
       errno = 0;
-      myptrace (xc_handle, PTRACE_POKETEXT, curvcpuid(), 
+      myptrace (xc_handle, PTRACE_POKETEXT, current_domid, 
 		(PTRACE_ARG3_TYPE) addr, buffer[i]);
       if (errno)
 	return errno;

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-03-06 10:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-02  8:28 [PATCH] gdbserver-xen: fix corefile access Horms
2006-03-02 10:45 ` Keir Fraser
2006-03-02 12:19   ` Horms
2006-03-02 13:24     ` Keir Fraser
2006-03-03  1:20       ` Horms
2006-03-03  1:28         ` Horms
2006-03-03  8:11           ` Keir Fraser
2006-03-03 11:15           ` Horms
2006-03-03 13:02             ` Keir Fraser
2006-03-06 10:08               ` Horms

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.