All of lore.kernel.org
 help / color / mirror / Atom feed
From: Horms <horms@verge.net.au>
To: xen-devel@lists.xensource.com
Subject: [PATCH] gdbserver-xen: fix corefile access
Date: Thu, 2 Mar 2006 08:28:43 +0000 (UTC)	[thread overview]
Message-ID: <du6abq$cce$1@sea.gmane.org> (raw)

# 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;

             reply	other threads:[~2006-03-02  8:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02  8:28 Horms [this message]
2006-03-02 10:45 ` [PATCH] gdbserver-xen: fix corefile access 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='du6abq$cce$1@sea.gmane.org' \
    --to=horms@verge.net.au \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.