Mailing List Archive

coredump.patch
ChangeSet 1.1405, 2005/04/30 09:45:02+01:00, kaf24@firebug.cl.cam.ac.uk

coredump.patch
Extend libxc and gdb server to coredump a domain.
Signed-off-by: Kip Macy <kmacy@fsmware.com>



gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in | 2
gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c | 40 -
gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c | 639 +++++++++++++++++
libxc/Makefile | 2
libxc/xc.h | 39 +
libxc/xc_core.c | 99 ++
libxc/xc_ptrace.c | 9
libxc/xc_ptrace_core.c | 287 +++++++
python/xen/lowlevel/xc/xc.c | 35
9 files changed, 1131 insertions(+), 21 deletions(-)


diff -Nru a/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in
--- a/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in 2005-04-30 05:02:45 -04:00
+++ b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/Makefile.in 2005-04-30 05:02:45 -04:00
@@ -83,7 +83,7 @@
# -I. for config files.
# -I${srcdir} for our headers.
# -I$(srcdir)/../regformats for regdef.h.
-INCLUDE_CFLAGS = -I. -I${srcdir} -I$(srcdir)/../regformats -I$(INCLUDE_DIR)
+INCLUDE_CFLAGS = -I. -I${srcdir} -I$(srcdir)/../regformats -I$(INCLUDE_DIR) -I../../../../libxc/ -I../../../../libxutil/

# M{H,T}_CFLAGS, if defined, has host- and target-dependent CFLAGS
# from the config/ directory.
diff -Nru a/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c
--- a/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c 2005-04-30 05:02:45 -04:00
+++ b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c 2005-04-30 05:02:45 -04:00
@@ -35,12 +35,11 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
-
+#include <xc.h>
#define TRACE_ENTER /* printf("enter %s\n", __FUNCTION__) */
-#define ptrace xc_ptrace
-long xc_ptrace(enum __ptrace_request request, ...);
+long (*myptrace)(enum __ptrace_request, pid_t, long, long);
+int (*myxcwait)(int domain, int *status, int options) ;

-int waitdomain(int domain, int *status, int options);

#define DOMFLAGS_DYING (1<<0) /* Domain is scheduled to die. */
#define DOMFLAGS_CRASHED (1<<1) /* Crashed domain; frozen for postmortem. */
@@ -61,6 +60,8 @@

int debug_threads;
int using_threads;
+extern int isfile;
+
struct pending_signals
{
int signal;
@@ -150,7 +151,7 @@
{
struct process_info *new_process;
current_domain = domain;
- if (ptrace (PTRACE_ATTACH, domain, 0, 0) != 0) {
+ if (myptrace (PTRACE_ATTACH, domain, 0, 0) != 0) {
fprintf (stderr, "Cannot attach to domain %d: %s (%d)\n", domain,
strerror (errno), errno);
fflush (stderr);
@@ -173,7 +174,7 @@
{
struct thread_info *thread = (struct thread_info *) entry;
struct process_info *process = get_thread_process (thread);
- ptrace (PTRACE_KILL, pid_of (process), 0, 0);
+ myptrace (PTRACE_KILL, pid_of (process), 0, 0);

}

@@ -190,7 +191,7 @@
struct thread_info *thread = (struct thread_info *) entry;
struct process_info *process = get_thread_process (thread);

- ptrace (PTRACE_DETACH, pid_of (process), 0, 0);
+ myptrace (PTRACE_DETACH, pid_of (process), 0, 0);
}


@@ -216,8 +217,7 @@
linux_wait (char *status)
{
int w;
- TRACE_ENTER;
- if (waitdomain(current_domain, &w, 0))
+ if (myxcwait(current_domain, &w, 0))
return -1;

if (w & (DOMFLAGS_CRASHED|DOMFLAGS_DYING)) {
@@ -242,7 +242,7 @@
expect_signal = resume_info->sig;
for_each_inferior(&all_threads, regcache_invalidate_one);

- ptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, current_domain, 0, 0);
+ myptrace (step ? PTRACE_SINGLESTEP : PTRACE_CONT, current_domain, 0, 0);

}

@@ -266,7 +266,7 @@
}

buf = malloc (regset->size);
- res = ptrace (regset->get_request, inferior_pid, 0, buf);
+ res = myptrace (regset->get_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf);
if (res < 0)
{
if (errno == EIO)
@@ -318,7 +318,7 @@

buf = malloc (regset->size);
regset->fill_function (buf);
- res = ptrace (regset->set_request, inferior_pid, 0, buf);
+ res = myptrace (regset->set_request, inferior_pid, 0, (PTRACE_XFER_TYPE)buf);
if (res < 0)
{
if (errno == EIO)
@@ -395,7 +395,7 @@
for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
- buffer[i] = ptrace (PTRACE_PEEKTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
+ buffer[i] = myptrace (PTRACE_PEEKTEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0);
if (errno)
return errno;
}
@@ -428,13 +428,13 @@

/* Fill start and end extra bytes of buffer with existing memory data. */

- buffer[0] = ptrace (PTRACE_PEEKTEXT, inferior_pid,
+ buffer[0] = myptrace (PTRACE_PEEKTEXT, inferior_pid,
(PTRACE_ARG3_TYPE) addr, 0);

if (count > 1)
{
buffer[count - 1]
- = ptrace (PTRACE_PEEKTEXT, inferior_pid,
+ = myptrace (PTRACE_PEEKTEXT, inferior_pid,
(PTRACE_ARG3_TYPE) (addr + (count - 1)
* sizeof (PTRACE_XFER_TYPE)),
0);
@@ -448,7 +448,7 @@
for (i = 0; i < count; i++, addr += sizeof (PTRACE_XFER_TYPE))
{
errno = 0;
- ptrace (PTRACE_POKETEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]);
+ myptrace (PTRACE_POKETEXT, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]);
if (errno)
return errno;
}
@@ -545,4 +545,12 @@
the_low_target.breakpoint_len);
init_registers ();
linux_init_signals ();
+ if (isfile) {
+ myptrace = xc_ptrace_core;
+ myxcwait = xc_waitdomain_core;
+ } else {
+ myptrace = xc_ptrace;
+ myxcwait = xc_waitdomain;
+ }
+
}
diff -Nru a/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/tools/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/server.c 2005-04-30 05:02:45 -04:00
@@ -0,0 +1,639 @@
+/* Main code for remote server for GDB.
+ Copyright 1989, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2002, 2003, 2004
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "server.h"
+
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int cont_thread;
+int general_thread;
+int step_thread;
+int thread_from_wait;
+int old_thread_from_wait;
+int extended_protocol;
+int server_waiting;
+int isfile = 0;
+
+jmp_buf toplevel;
+
+/* The PID of the originally created or attached inferior. Used to
+ send signals to the process when GDB sends us an asynchronous interrupt
+ (user hitting Control-C in the client), and to wait for the child to exit
+ when no longer debugging it. */
+
+int signal_pid;
+
+static unsigned char
+start_inferior (char *argv[], char *statusptr)
+{
+ signal (SIGTTOU, SIG_DFL);
+ signal (SIGTTIN, SIG_DFL);
+
+ signal_pid = create_inferior (argv[0], argv);
+
+ fprintf (stderr, "Process %s created; pid = %d\n", argv[0],
+ signal_pid);
+
+ signal (SIGTTOU, SIG_IGN);
+ signal (SIGTTIN, SIG_IGN);
+ tcsetpgrp (fileno (stderr), signal_pid);
+
+ /* Wait till we are at 1st instruction in program, return signal number. */
+ return mywait (statusptr, 0);
+}
+
+static int
+attach_inferior (int pid, char *statusptr, unsigned char *sigptr)
+{
+ /* myattach should return -1 if attaching is unsupported,
+ 0 if it succeeded, and call error() otherwise. */
+
+ if (myattach (pid) != 0)
+ return -1;
+
+ fprintf (stderr, "Attached; pid = %d\n", pid);
+
+ /* FIXME - It may be that we should get the SIGNAL_PID from the
+ attach function, so that it can be the main thread instead of
+ whichever we were told to attach to. */
+ signal_pid = pid;
+
+ *sigptr = mywait (statusptr, 0);
+
+ return 0;
+}
+
+extern int remote_debug;
+
+/* Handle all of the extended 'q' packets. */
+void
+handle_query (char *own_buf)
+{
+ static struct inferior_list_entry *thread_ptr;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@lists.xensource.com
http://lists.xensource.com/xen-changelog