2002-07-10 06:58:25 +00:00
|
|
|
|
/* Kernel core dump functions below target vector, for GDB.
|
|
|
|
|
Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
|
|
|
|
|
Free Software Foundation, Inc.
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
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
|
2002-07-10 06:58:25 +00:00
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2000-12-09 09:35:55 +00:00
|
|
|
|
/* $FreeBSD$ */
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* This works like "remote" but, you use it like this:
|
|
|
|
|
* target kcore /dev/mem
|
|
|
|
|
* or
|
|
|
|
|
* target kcore /var/crash/host/core.0
|
|
|
|
|
*
|
|
|
|
|
* This way makes it easy to short-circut the whole bfd monster,
|
|
|
|
|
* and direct the inferior stuff to our libkvm implementation.
|
2002-09-18 16:14:36 +00:00
|
|
|
|
*
|
2002-07-10 06:58:25 +00:00
|
|
|
|
*/
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
#include <sys/user.h>
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <kvm.h>
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
#include <paths.h>
|
|
|
|
|
#include <readline/tilde.h>
|
|
|
|
|
#include <machine/frame.h>
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include "gdb_string.h"
|
1997-01-15 22:37:09 +00:00
|
|
|
|
#include "frame.h" /* required by inferior.h */
|
|
|
|
|
#include "inferior.h"
|
|
|
|
|
#include "symtab.h"
|
1998-01-17 17:07:53 +00:00
|
|
|
|
#include "symfile.h"
|
|
|
|
|
#include "objfiles.h"
|
1997-01-15 22:37:09 +00:00
|
|
|
|
#include "command.h"
|
|
|
|
|
#include "bfd.h"
|
|
|
|
|
#include "target.h"
|
|
|
|
|
#include "gdbcore.h"
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kcore_files_info (struct target_ops *);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kcore_close (int);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
get_kcore_registers (int);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
xfer_mem (CORE_ADDR, char *, int, int, struct target_ops *);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
xfer_umem (CORE_ADDR, char *, int, int);
|
2001-01-10 18:15:25 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static char *core_file;
|
|
|
|
|
static kvm_t *core_kd;
|
|
|
|
|
static struct pcb cur_pcb;
|
|
|
|
|
static struct kinfo_proc *cur_proc;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static struct target_ops kcore_ops;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-06-30 04:47:43 +00:00
|
|
|
|
int kernel_debugging;
|
|
|
|
|
int kernel_writablecore;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Read the "thing" at kernel address 'addr' into the space pointed to
|
|
|
|
|
by point. The length of the "thing" is determined by the type of p.
|
|
|
|
|
Result is non-zero if transfer fails. */
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
#define kvread(addr, p) \
|
2002-09-18 16:14:36 +00:00
|
|
|
|
(target_read_memory ((CORE_ADDR) (addr), (char *) (p), sizeof (*(p))))
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
static CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
ksym_kernbase (void)
|
2002-07-10 06:58:25 +00:00
|
|
|
|
{
|
|
|
|
|
static CORE_ADDR kernbase;
|
|
|
|
|
struct minimal_symbol *sym;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (kernbase == 0)
|
|
|
|
|
{
|
|
|
|
|
sym = lookup_minimal_symbol ("kernbase", NULL, NULL);
|
|
|
|
|
if (sym == NULL) {
|
|
|
|
|
kernbase = KERNBASE;
|
|
|
|
|
} else {
|
|
|
|
|
kernbase = SYMBOL_VALUE_ADDRESS (sym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return kernbase;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
#define KERNOFF (ksym_kernbase ())
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#define INKERNEL(x) ((x) >= KERNOFF)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
ksym_lookup(const char *name)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
struct minimal_symbol *sym;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
sym = lookup_minimal_symbol (name, NULL, NULL);
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (sym == NULL)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
error ("kernel symbol `%s' not found.", name);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
return SYMBOL_VALUE_ADDRESS (sym);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Provide the address of an initial PCB to use.
|
|
|
|
|
If this is a crash dump, try for "dumppcb".
|
|
|
|
|
If no "dumppcb" or it's /dev/mem, use proc0.
|
|
|
|
|
Return the core address of the PCB we found. */
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
static CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
initial_pcb (void)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
struct minimal_symbol *sym;
|
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
void *val;
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Make sure things are open... */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (!core_kd || !core_file)
|
|
|
|
|
return (0);
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* If this is NOT /dev/mem try for dumppcb. */
|
|
|
|
|
if (strncmp (core_file, _PATH_DEV, sizeof _PATH_DEV - 1))
|
|
|
|
|
{
|
|
|
|
|
sym = lookup_minimal_symbol ("dumppcb", NULL, NULL);
|
|
|
|
|
if (sym != NULL)
|
|
|
|
|
{
|
|
|
|
|
addr = SYMBOL_VALUE_ADDRESS (sym);
|
|
|
|
|
return (addr);
|
|
|
|
|
}
|
2002-07-10 06:58:25 +00:00
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* OK, just use thread0's pcb. Note that curproc might
|
|
|
|
|
not exist, and if it does, it will point to gdb.
|
|
|
|
|
Therefore, just use proc0 and let the user set
|
|
|
|
|
some other context if they care about it. */
|
|
|
|
|
|
|
|
|
|
addr = ksym_lookup ("thread0");
|
|
|
|
|
if (kvread (addr, &val))
|
|
|
|
|
{
|
|
|
|
|
error ("cannot read thread0 pointer at %x\n", addr);
|
2002-07-10 06:58:25 +00:00
|
|
|
|
val = 0;
|
|
|
|
|
}
|
2002-09-18 16:14:36 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Read the PCB address in thread structure. */
|
|
|
|
|
addr += offsetof (struct thread, td_pcb);
|
|
|
|
|
if (kvread (addr, &val))
|
|
|
|
|
{
|
|
|
|
|
error ("cannot read thread0->td_pcb pointer at %x\n", addr);
|
|
|
|
|
val = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* thread0 is wholly in the kernel and cur_proc is only used for
|
|
|
|
|
reading user mem, so no point in setting this up. */
|
|
|
|
|
cur_proc = 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
return ((CORE_ADDR)val);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Set the current context to that of the PCB struct at the system address
|
|
|
|
|
passed. */
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
set_context (CORE_ADDR addr)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
CORE_ADDR procaddr = 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (kvread (addr, &cur_pcb))
|
|
|
|
|
error ("cannot read pcb at %#x", addr);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Fetch all registers from core file. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
target_fetch_registers (-1);
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Now, set up the frame cache, and print the top of stack. */
|
|
|
|
|
flush_cached_frames ();
|
1997-01-15 22:37:09 +00:00
|
|
|
|
set_current_frame (create_new_frame (read_fp (), read_pc ()));
|
|
|
|
|
select_frame (get_current_frame (), 0);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* Discard all vestiges of any previous core file and mark data and stack
|
|
|
|
|
spaces as empty. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kcore_close (int quitting)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (core_kd)
|
|
|
|
|
{
|
|
|
|
|
kvm_close (core_kd);
|
|
|
|
|
free (core_file);
|
|
|
|
|
core_file = NULL;
|
|
|
|
|
core_kd = NULL;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* This routine opens and sets up the core file bfd. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kcore_open (char *filename /* the core file */, int from_tty)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kvm_t *kd;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
const char *p;
|
|
|
|
|
struct cleanup *old_chain;
|
|
|
|
|
char buf[256], *cp;
|
|
|
|
|
int ontop;
|
|
|
|
|
CORE_ADDR addr;
|
|
|
|
|
|
|
|
|
|
target_preopen (from_tty);
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* The exec file is required for symbols. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (exec_bfd == NULL)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
error ("No kernel exec file specified");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (core_kd)
|
|
|
|
|
{
|
|
|
|
|
error ("No core file specified."
|
|
|
|
|
" (Use `detach' to stop debugging a core file.)");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (!filename)
|
|
|
|
|
{
|
|
|
|
|
error ("No core file specified.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
filename = tilde_expand (filename);
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (filename[0] != '/')
|
|
|
|
|
{
|
|
|
|
|
cp = concat (current_directory, "/", filename, NULL);
|
|
|
|
|
free (filename);
|
|
|
|
|
filename = cp;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
old_chain = make_cleanup (free, filename);
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
kd = kvm_open (bfd_get_filename(exec_bfd), filename, NULL,
|
|
|
|
|
kernel_writablecore ? O_RDWR: O_RDONLY, 0);
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (kd == NULL)
|
|
|
|
|
{
|
|
|
|
|
perror_with_name (filename);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* Looks semi-reasonable. Toss the old core file and work on the new. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
discard_cleanups (old_chain); /* Don't free filename any more. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
core_file = filename;
|
2002-07-10 06:58:25 +00:00
|
|
|
|
unpush_target (&kcore_ops);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
ontop = !push_target (&kcore_ops);
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Note unpush_target (above) calls kcore_close. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
core_kd = kd;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Print out the panic string if there is one. */
|
|
|
|
|
if (kvread (ksym_lookup ("panicstr"), &addr) == 0 &&
|
2002-07-10 06:58:25 +00:00
|
|
|
|
addr != 0 &&
|
2002-09-18 16:14:36 +00:00
|
|
|
|
target_read_memory (addr, buf, sizeof(buf)) == 0)
|
|
|
|
|
{
|
1997-12-19 21:37:18 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
for (cp = buf; cp < &buf[sizeof(buf)] && *cp; cp++)
|
|
|
|
|
if (!isascii (*cp) || (!isprint (*cp) && !isspace (*cp)))
|
|
|
|
|
*cp = '?';
|
|
|
|
|
*cp = '\0';
|
|
|
|
|
if (buf[0] != '\0')
|
|
|
|
|
printf_filtered ("panic: %s\n", buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print all the panic messages if possible. */
|
1998-01-17 17:07:53 +00:00
|
|
|
|
if (symfile_objfile != NULL)
|
|
|
|
|
{
|
1997-12-19 21:37:18 +00:00
|
|
|
|
printf ("panic messages:\n---\n");
|
|
|
|
|
snprintf (buf, sizeof buf,
|
2002-07-10 06:58:25 +00:00
|
|
|
|
"/sbin/dmesg -N %s -M %s | \
|
|
|
|
|
/usr/bin/awk '/^(panic:|Fatal trap) / { printing = 1 } \
|
|
|
|
|
{ if (printing) print $0 }'",
|
|
|
|
|
symfile_objfile->name, filename);
|
2002-09-18 16:14:36 +00:00
|
|
|
|
fflush (stdout);
|
1997-12-19 21:37:18 +00:00
|
|
|
|
system (buf);
|
|
|
|
|
printf ("---\n");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (!ontop)
|
|
|
|
|
{
|
|
|
|
|
warning ("you won't be able to access this core file until you terminate\n"
|
|
|
|
|
"your %s; do ``info files''", target_longname);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Now, set up process context, and print the top of stack. */
|
|
|
|
|
(void)set_context (initial_pcb());
|
1997-01-15 22:37:09 +00:00
|
|
|
|
print_stack_frame (selected_frame, selected_frame_level, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
kcore_detach (char *args, int from_tty)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (args)
|
|
|
|
|
error ("Too many arguments");
|
|
|
|
|
unpush_target (&kcore_ops);
|
|
|
|
|
reinit_frame_cache ();
|
|
|
|
|
if (from_tty)
|
|
|
|
|
printf_filtered ("No kernel core file now.\n");
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#ifdef __alpha__
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#include "alpha/tm-alpha.h"
|
|
|
|
|
#ifndef S0_REGNUM
|
|
|
|
|
#define S0_REGNUM (T7_REGNUM+1)
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
fetch_kcore_registers (struct pcb *pcbp)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* First clear out any garbage. */
|
|
|
|
|
memset (registers, '\0', REGISTER_BYTES);
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
/* SP */
|
|
|
|
|
*(long *) ®isters[REGISTER_BYTE (SP_REGNUM)] =
|
|
|
|
|
pcbp->pcb_hw.apcb_ksp;
|
|
|
|
|
|
|
|
|
|
/* S0 through S6 */
|
|
|
|
|
memcpy (®isters[REGISTER_BYTE (S0_REGNUM)],
|
2002-09-18 16:14:36 +00:00
|
|
|
|
&pcbp->pcb_context[0], 7 * sizeof (long));
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
/* PC */
|
|
|
|
|
*(long *) ®isters[REGISTER_BYTE (PC_REGNUM)] =
|
|
|
|
|
pcbp->pcb_context[7];
|
|
|
|
|
|
|
|
|
|
registers_fetched ();
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
fbsd_kern_frame_saved_pc (struct frame_info *fi)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-09-18 16:14:36 +00:00
|
|
|
|
struct minimal_symbol *sym;
|
|
|
|
|
CORE_ADDR this_saved_pc;
|
|
|
|
|
|
|
|
|
|
this_saved_pc = alpha_frame_saved_pc (fi);
|
|
|
|
|
|
|
|
|
|
sym = lookup_minimal_symbol_by_pc (this_saved_pc);
|
|
|
|
|
|
|
|
|
|
if (sym != NULL &&
|
|
|
|
|
(strcmp (SYMBOL_NAME (sym), "XentArith") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentIF") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentInt") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentMM") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentSys") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentUna") == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), "XentRestart") == 0))
|
|
|
|
|
{
|
|
|
|
|
return (read_memory_integer (fi->frame + 32 * 8, 8));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (this_saved_pc);
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#endif /* __alpha__ */
|
|
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
|
2001-12-11 07:04:48 +00:00
|
|
|
|
static CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
ksym_maxuseraddr (void)
|
2001-12-11 07:04:48 +00:00
|
|
|
|
{
|
|
|
|
|
static CORE_ADDR maxuseraddr;
|
|
|
|
|
struct minimal_symbol *sym;
|
|
|
|
|
|
|
|
|
|
if (maxuseraddr == 0)
|
|
|
|
|
{
|
|
|
|
|
sym = lookup_minimal_symbol ("PTmap", NULL, NULL);
|
|
|
|
|
if (sym == NULL) {
|
|
|
|
|
maxuseraddr = VM_MAXUSER_ADDRESS;
|
|
|
|
|
} else {
|
|
|
|
|
maxuseraddr = SYMBOL_VALUE_ADDRESS (sym);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return maxuseraddr;
|
|
|
|
|
}
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Symbol names of kernel entry points. Use special frames. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#define KSYM_TRAP "calltrap"
|
|
|
|
|
#define KSYM_INTR "Xintr"
|
|
|
|
|
#define KSYM_FASTINTR "Xfastintr"
|
2002-07-28 18:46:49 +00:00
|
|
|
|
#define KSYM_OLDSYSCALL "Xlcall_syscall"
|
|
|
|
|
#define KSYM_SYSCALL "Xint0x80_syscall"
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* The following is FreeBSD-specific hackery to decode special frames
|
|
|
|
|
and elide the assembly-language stub. This could be made faster by
|
|
|
|
|
defining a frame_type field in the machine-dependent frame information,
|
|
|
|
|
but we don't think that's too important right now. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
enum frametype { tf_normal, tf_trap, tf_interrupt, tf_syscall };
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
CORE_ADDR
|
2002-09-18 16:14:36 +00:00
|
|
|
|
fbsd_kern_frame_saved_pc (struct frame_info *fr)
|
2001-08-24 09:12:04 +00:00
|
|
|
|
{
|
2002-09-18 16:14:36 +00:00
|
|
|
|
struct minimal_symbol *sym;
|
|
|
|
|
CORE_ADDR this_saved_pc;
|
|
|
|
|
enum frametype frametype;
|
|
|
|
|
|
|
|
|
|
this_saved_pc = read_memory_integer (fr->frame + 4, 4);
|
|
|
|
|
sym = lookup_minimal_symbol_by_pc (this_saved_pc);
|
|
|
|
|
frametype = tf_normal;
|
|
|
|
|
if (sym != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (SYMBOL_NAME (sym), KSYM_TRAP) == 0)
|
|
|
|
|
frametype = tf_trap;
|
|
|
|
|
else
|
|
|
|
|
if (strncmp (SYMBOL_NAME (sym), KSYM_INTR,
|
|
|
|
|
strlen (KSYM_INTR)) == 0 || strncmp (SYMBOL_NAME(sym),
|
|
|
|
|
KSYM_FASTINTR, strlen (KSYM_FASTINTR)) == 0)
|
|
|
|
|
frametype = tf_interrupt;
|
|
|
|
|
else
|
|
|
|
|
if (strcmp (SYMBOL_NAME (sym), KSYM_SYSCALL) == 0 ||
|
|
|
|
|
strcmp (SYMBOL_NAME (sym), KSYM_OLDSYSCALL) == 0)
|
|
|
|
|
frametype = tf_syscall;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (frametype)
|
|
|
|
|
{
|
|
|
|
|
case tf_normal:
|
|
|
|
|
return (this_saved_pc);
|
|
|
|
|
#define oEIP offsetof (struct trapframe, tf_eip)
|
|
|
|
|
|
|
|
|
|
case tf_trap:
|
|
|
|
|
return (read_memory_integer (fr->frame + 8 + oEIP, 4));
|
|
|
|
|
|
|
|
|
|
case tf_interrupt:
|
|
|
|
|
return (read_memory_integer (fr->frame + 12 + oEIP, 4));
|
|
|
|
|
|
|
|
|
|
case tf_syscall:
|
|
|
|
|
return (read_memory_integer (fr->frame + 8 + oEIP, 4));
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#undef oEIP
|
2002-09-18 16:14:36 +00:00
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static int
|
|
|
|
|
fetch_kcore_registers (struct pcb *pcb)
|
1999-04-28 01:27:55 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
int i;
|
|
|
|
|
int noreg;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Get the register values out of the sys pcb and store them where
|
|
|
|
|
`read_register' will find them. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* XXX many registers aren't available.
|
|
|
|
|
* XXX for the non-core case, the registers are stale - they are for
|
|
|
|
|
* the last context switch to the debugger.
|
|
|
|
|
* XXX gcc's register numbers aren't all #defined in tm-i386.h.
|
|
|
|
|
*/
|
|
|
|
|
noreg = 0;
|
|
|
|
|
for (i = 0; i < 3; ++i) /* eax,ecx,edx */
|
|
|
|
|
supply_register (i, (char *)&noreg);
|
1999-04-28 01:27:55 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
supply_register (3, (char *) &pcb->pcb_ebx);
|
|
|
|
|
supply_register (SP_REGNUM, (char *) &pcb->pcb_esp);
|
|
|
|
|
supply_register (FP_REGNUM, (char *) &pcb->pcb_ebp);
|
|
|
|
|
supply_register (6, (char *) &pcb->pcb_esi);
|
|
|
|
|
supply_register (7, (char *) &pcb->pcb_edi);
|
|
|
|
|
supply_register (PC_REGNUM, (char *) &pcb->pcb_eip);
|
1999-04-28 01:27:55 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
for (i = 9; i < 14; ++i) /* eflags, cs, ss, ds, es, fs */
|
2002-09-18 16:14:36 +00:00
|
|
|
|
supply_register (i, (char *) &noreg);
|
|
|
|
|
supply_register (15, (char *) &pcb->pcb_gs);
|
1999-04-28 01:27:55 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* XXX 80387 registers? */
|
1999-04-28 01:27:55 +00:00
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
#endif /* __i386__ */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
#ifdef __sparc64__
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#include "sparc/tm-sp64.h"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
fetch_kcore_registers (struct pcb *pcbp)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORE_ADDR
|
|
|
|
|
fbsd_kern_frame_saved_pc (struct frame_info *fi)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* __sparc64__ */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* Get the registers out of a core file. This is the machine-
|
|
|
|
|
independent part. Fetch_core_registers is the machine-dependent
|
|
|
|
|
part, typically implemented in the xm-file for each architecture. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* We just get all the registers, so we don't use regno. */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* ARGSUSED */
|
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
get_kcore_registers (int regno)
|
2002-07-10 06:58:25 +00:00
|
|
|
|
{
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* XXX - Only read the pcb when set_context() is called.
|
|
|
|
|
When looking at a live kernel this may be a problem,
|
|
|
|
|
but the user can do another "proc" or "pcb" command to
|
|
|
|
|
grab a new copy of the pcb... */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Zero out register set then fill in the ones we know about. */
|
2002-07-10 06:58:25 +00:00
|
|
|
|
fetch_kcore_registers (&cur_pcb);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static void
|
|
|
|
|
kcore_files_info (t)
|
|
|
|
|
struct target_ops *t;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
printf_filtered ("\t`%s'\n", core_file);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
/* If mourn is being called in all the right places, this could be say
|
2002-09-18 16:14:36 +00:00
|
|
|
|
`gdb internal error' (since generic_mourn calls breakpoint_init_inferior). */
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
ignore (CORE_ADDR addr, char *contents)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
return 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
xfer_kmem (CORE_ADDR memaddr, char *myaddr, int len, int write,
|
|
|
|
|
struct target_ops *target)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
int n;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (!INKERNEL (memaddr))
|
|
|
|
|
return xfer_umem (memaddr, myaddr, len, write);
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (core_kd == NULL)
|
|
|
|
|
return 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (write)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
n = kvm_write (core_kd, memaddr, myaddr, len);
|
2002-07-10 06:58:25 +00:00
|
|
|
|
else
|
|
|
|
|
n = kvm_read (core_kd, memaddr, myaddr, len) ;
|
|
|
|
|
if (n < 0) {
|
|
|
|
|
fprintf_unfiltered (gdb_stderr, "can not access 0x%x, %s\n",
|
2002-09-18 16:14:36 +00:00
|
|
|
|
memaddr, kvm_geterr (core_kd));
|
2002-07-10 06:58:25 +00:00
|
|
|
|
n = 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
return n;
|
2001-01-10 18:15:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
|
|
|
|
static int
|
2002-09-18 16:14:36 +00:00
|
|
|
|
xfer_umem (CORE_ADDR memaddr, char *myaddr, int len, int write /* ignored */)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
int n = 0;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (cur_proc == 0)
|
|
|
|
|
{
|
|
|
|
|
error ("---Can't read userspace from dump, or kernel process---\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (write)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
error ("kvm_uwrite unimplemented\n");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
else
|
2002-09-18 16:14:36 +00:00
|
|
|
|
n = kvm_uread (core_kd, cur_proc, memaddr, myaddr, len) ;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (n < 0)
|
|
|
|
|
return 0;
|
1997-07-27 18:29:04 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
return n;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
static void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
set_proc_cmd (char *arg)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
2002-07-10 06:58:25 +00:00
|
|
|
|
CORE_ADDR addr, pid_addr, first_td;
|
|
|
|
|
void *val;
|
|
|
|
|
struct kinfo_proc *kp;
|
|
|
|
|
int cnt;
|
|
|
|
|
pid_t pid;
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
if (!arg)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
error_no_arg ("proc address for the new context");
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
|
|
|
|
if (core_kd == NULL)
|
2002-09-18 16:14:36 +00:00
|
|
|
|
error ("no kernel core file");
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
addr = (CORE_ADDR) parse_and_eval_address (arg);
|
2002-07-10 06:58:25 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (!INKERNEL (addr))
|
|
|
|
|
{
|
|
|
|
|
kp = kvm_getprocs (core_kd, KERN_PROC_PID, addr, &cnt);
|
|
|
|
|
if (!cnt)
|
|
|
|
|
error ("invalid pid");
|
|
|
|
|
addr = (CORE_ADDR)kp->ki_paddr;
|
|
|
|
|
cur_proc = kp;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Update cur_proc. */
|
|
|
|
|
pid_addr = addr + offsetof (struct proc, p_pid);
|
|
|
|
|
if (kvread (pid_addr, &pid))
|
|
|
|
|
error ("cannot read pid ptr");
|
|
|
|
|
cur_proc = kvm_getprocs (core_kd, KERN_PROC_PID, pid, &cnt);
|
|
|
|
|
if (!cnt)
|
|
|
|
|
error("invalid pid");
|
|
|
|
|
}
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-09-18 16:14:36 +00:00
|
|
|
|
/* Find the first thread in the process. XXXKSE */
|
|
|
|
|
addr += offsetof (struct proc, p_threads.tqh_first);
|
|
|
|
|
if (kvread (addr, &first_td))
|
|
|
|
|
error ("cannot read thread ptr");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* Read the PCB address in thread structure. */
|
2002-09-18 16:14:36 +00:00
|
|
|
|
addr = first_td + offsetof (struct thread, td_pcb);
|
|
|
|
|
if (kvread (addr, &val))
|
2002-07-10 06:58:25 +00:00
|
|
|
|
error("cannot read pcb ptr");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
|
2002-07-10 06:58:25 +00:00
|
|
|
|
/* Read the PCB address in proc structure. */
|
2002-09-18 16:14:36 +00:00
|
|
|
|
if (set_context ((CORE_ADDR) val))
|
|
|
|
|
error ("invalid proc address");
|
1997-01-15 22:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2002-09-18 16:14:36 +00:00
|
|
|
|
_initialize_kcorelow (void)
|
1997-01-15 22:37:09 +00:00
|
|
|
|
{
|
1999-05-02 11:32:14 +00:00
|
|
|
|
kcore_ops.to_shortname = "kcore";
|
|
|
|
|
kcore_ops.to_longname = "Kernel core dump file";
|
|
|
|
|
kcore_ops.to_doc =
|
|
|
|
|
"Use a core file as a target. Specify the filename of the core file.";
|
|
|
|
|
kcore_ops.to_open = kcore_open;
|
|
|
|
|
kcore_ops.to_close = kcore_close;
|
|
|
|
|
kcore_ops.to_attach = find_default_attach;
|
|
|
|
|
kcore_ops.to_detach = kcore_detach;
|
|
|
|
|
kcore_ops.to_fetch_registers = get_kcore_registers;
|
2002-07-10 06:58:25 +00:00
|
|
|
|
kcore_ops.to_xfer_memory = xfer_kmem;
|
1999-05-02 11:32:14 +00:00
|
|
|
|
kcore_ops.to_files_info = kcore_files_info;
|
|
|
|
|
kcore_ops.to_create_inferior = find_default_create_inferior;
|
|
|
|
|
kcore_ops.to_stratum = kcore_stratum;
|
|
|
|
|
kcore_ops.to_has_memory = 1;
|
|
|
|
|
kcore_ops.to_has_stack = 1;
|
|
|
|
|
kcore_ops.to_has_registers = 1;
|
|
|
|
|
kcore_ops.to_magic = OPS_MAGIC;
|
|
|
|
|
|
1997-01-15 22:37:09 +00:00
|
|
|
|
add_target (&kcore_ops);
|
|
|
|
|
add_com ("proc", class_obscure, set_proc_cmd, "Set current process context");
|
|
|
|
|
}
|