|
Line 0
Link Here
|
|
|
1 |
/* Kernel core dump functions below target vector, for GDB. |
| 2 |
Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995 |
| 3 |
Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This file is part of GDB. |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
/* $FreeBSD: ports/devel/gdb53-act/files/patch-gdb_kvm-fbsd.c,v 1.1 2003/09/27 07:38:23 edwin Exp $ */ |
| 23 |
|
| 24 |
/* |
| 25 |
* This works like "remote" but, you use it like this: |
| 26 |
* target kcore /dev/mem |
| 27 |
* or |
| 28 |
* target kcore /var/crash/host/core.0 |
| 29 |
* |
| 30 |
* This way makes it easy to short-circut the whole bfd monster, |
| 31 |
* and direct the inferior stuff to our libkvm implementation. |
| 32 |
* |
| 33 |
*/ |
| 34 |
|
| 35 |
#include <sys/param.h> |
| 36 |
#include <sys/time.h> |
| 37 |
#include <sys/proc.h> |
| 38 |
#include <sys/user.h> |
| 39 |
#include <ctype.h> |
| 40 |
#include <errno.h> |
| 41 |
#include <signal.h> |
| 42 |
#include <fcntl.h> |
| 43 |
#include <kvm.h> |
| 44 |
#include <sys/sysctl.h> |
| 45 |
#include <paths.h> |
| 46 |
#include <readline/tilde.h> |
| 47 |
#include <machine/frame.h> |
| 48 |
|
| 49 |
#include "defs.h" |
| 50 |
#include "gdb_string.h" |
| 51 |
#include "frame.h" /* required by inferior.h */ |
| 52 |
#include "inferior.h" |
| 53 |
#include "symtab.h" |
| 54 |
#include "symfile.h" |
| 55 |
#include "objfiles.h" |
| 56 |
#include "command.h" |
| 57 |
#include "bfd.h" |
| 58 |
#include "target.h" |
| 59 |
#include "gdbcore.h" |
| 60 |
#include "regcache.h" |
| 61 |
|
| 62 |
#if __FreeBSD_version >= 500032 |
| 63 |
static void |
| 64 |
kcore_files_info (struct target_ops *); |
| 65 |
|
| 66 |
static void |
| 67 |
kcore_close (int); |
| 68 |
|
| 69 |
static void |
| 70 |
get_kcore_registers (int); |
| 71 |
|
| 72 |
static int |
| 73 |
xfer_mem (CORE_ADDR, char *, int, int, struct mem_attrib *, |
| 74 |
struct target_ops *); |
| 75 |
|
| 76 |
static int |
| 77 |
xfer_umem (CORE_ADDR, char *, int, int); |
| 78 |
|
| 79 |
static char *core_file; |
| 80 |
static kvm_t *core_kd; |
| 81 |
static struct pcb cur_pcb; |
| 82 |
static struct kinfo_proc *cur_proc; |
| 83 |
|
| 84 |
static struct target_ops kcore_ops; |
| 85 |
|
| 86 |
int kernel_debugging; |
| 87 |
int kernel_writablecore; |
| 88 |
|
| 89 |
/* Read the "thing" at kernel address 'addr' into the space pointed to |
| 90 |
by point. The length of the "thing" is determined by the type of p. |
| 91 |
Result is non-zero if transfer fails. */ |
| 92 |
|
| 93 |
#define kvread(addr, p) \ |
| 94 |
(target_read_memory ((CORE_ADDR) (addr), (char *) (p), sizeof (*(p)))) |
| 95 |
|
| 96 |
static CORE_ADDR |
| 97 |
ksym_kernbase (void) |
| 98 |
{ |
| 99 |
static CORE_ADDR kernbase; |
| 100 |
struct minimal_symbol *sym; |
| 101 |
|
| 102 |
if (kernbase == 0) |
| 103 |
{ |
| 104 |
sym = lookup_minimal_symbol ("kernbase", NULL, NULL); |
| 105 |
if (sym == NULL) { |
| 106 |
kernbase = KERNBASE; |
| 107 |
} else { |
| 108 |
kernbase = SYMBOL_VALUE_ADDRESS (sym); |
| 109 |
} |
| 110 |
} |
| 111 |
return kernbase; |
| 112 |
} |
| 113 |
|
| 114 |
#define KERNOFF (ksym_kernbase ()) |
| 115 |
#define INKERNEL(x) ((x) >= KERNOFF) |
| 116 |
|
| 117 |
CORE_ADDR |
| 118 |
ksym_lookup(const char *name) |
| 119 |
{ |
| 120 |
struct minimal_symbol *sym; |
| 121 |
|
| 122 |
sym = lookup_minimal_symbol (name, NULL, NULL); |
| 123 |
if (sym == NULL) |
| 124 |
error ("kernel symbol `%s' not found.", name); |
| 125 |
|
| 126 |
return SYMBOL_VALUE_ADDRESS (sym); |
| 127 |
} |
| 128 |
|
| 129 |
/* Provide the address of an initial PCB to use. |
| 130 |
If this is a crash dump, try for "dumppcb". |
| 131 |
If no "dumppcb" or it's /dev/mem, use proc0. |
| 132 |
Return the core address of the PCB we found. */ |
| 133 |
|
| 134 |
static CORE_ADDR |
| 135 |
initial_pcb (void) |
| 136 |
{ |
| 137 |
struct minimal_symbol *sym; |
| 138 |
CORE_ADDR addr; |
| 139 |
void *val; |
| 140 |
|
| 141 |
/* Make sure things are open... */ |
| 142 |
if (!core_kd || !core_file) |
| 143 |
return (0); |
| 144 |
|
| 145 |
/* If this is NOT /dev/mem try for dumppcb. */ |
| 146 |
if (strncmp (core_file, _PATH_DEV, sizeof _PATH_DEV - 1)) |
| 147 |
{ |
| 148 |
sym = lookup_minimal_symbol ("dumppcb", NULL, NULL); |
| 149 |
if (sym != NULL) |
| 150 |
{ |
| 151 |
addr = SYMBOL_VALUE_ADDRESS (sym); |
| 152 |
return (addr); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
/* OK, just use thread0's pcb. Note that curproc might |
| 157 |
not exist, and if it does, it will point to gdb. |
| 158 |
Therefore, just use proc0 and let the user set |
| 159 |
some other context if they care about it. */ |
| 160 |
|
| 161 |
addr = ksym_lookup ("thread0"); |
| 162 |
if (kvread (addr, &val)) |
| 163 |
{ |
| 164 |
error ("cannot read thread0 pointer at %x\n", addr); |
| 165 |
val = 0; |
| 166 |
} |
| 167 |
else |
| 168 |
{ |
| 169 |
/* Read the PCB address in thread structure. */ |
| 170 |
addr += offsetof (struct thread, td_pcb); |
| 171 |
if (kvread (addr, &val)) |
| 172 |
{ |
| 173 |
error ("cannot read thread0->td_pcb pointer at %x\n", addr); |
| 174 |
val = 0; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
/* thread0 is wholly in the kernel and cur_proc is only used for |
| 179 |
reading user mem, so no point in setting this up. */ |
| 180 |
cur_proc = 0; |
| 181 |
|
| 182 |
return ((CORE_ADDR)val); |
| 183 |
} |
| 184 |
|
| 185 |
/* Set the current context to that of the PCB struct at the system address |
| 186 |
passed. */ |
| 187 |
|
| 188 |
static int |
| 189 |
set_context (CORE_ADDR addr) |
| 190 |
{ |
| 191 |
CORE_ADDR procaddr = 0; |
| 192 |
|
| 193 |
if (kvread (addr, &cur_pcb)) |
| 194 |
error ("cannot read pcb at %#x", addr); |
| 195 |
|
| 196 |
/* Fetch all registers from core file. */ |
| 197 |
target_fetch_registers (-1); |
| 198 |
|
| 199 |
/* Now, set up the frame cache, and print the top of stack. */ |
| 200 |
flush_cached_frames (); |
| 201 |
set_current_frame (create_new_frame (read_fp (), read_pc ())); |
| 202 |
select_frame (get_current_frame ()); |
| 203 |
return (0); |
| 204 |
} |
| 205 |
|
| 206 |
/* Discard all vestiges of any previous core file and mark data and stack |
| 207 |
spaces as empty. */ |
| 208 |
|
| 209 |
/* ARGSUSED */ |
| 210 |
static void |
| 211 |
kcore_close (int quitting) |
| 212 |
{ |
| 213 |
|
| 214 |
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */ |
| 215 |
|
| 216 |
if (core_kd) |
| 217 |
{ |
| 218 |
kvm_close (core_kd); |
| 219 |
free (core_file); |
| 220 |
core_file = NULL; |
| 221 |
core_kd = NULL; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
/* This routine opens and sets up the core file bfd. */ |
| 226 |
|
| 227 |
static void |
| 228 |
kcore_open (char *filename /* the core file */, int from_tty) |
| 229 |
{ |
| 230 |
kvm_t *kd; |
| 231 |
const char *p; |
| 232 |
struct cleanup *old_chain; |
| 233 |
char buf[256], *cp; |
| 234 |
int ontop; |
| 235 |
CORE_ADDR addr; |
| 236 |
|
| 237 |
target_preopen (from_tty); |
| 238 |
|
| 239 |
/* The exec file is required for symbols. */ |
| 240 |
if (exec_bfd == NULL) |
| 241 |
error ("No kernel exec file specified"); |
| 242 |
|
| 243 |
if (core_kd) |
| 244 |
{ |
| 245 |
error ("No core file specified." |
| 246 |
" (Use `detach' to stop debugging a core file.)"); |
| 247 |
return; |
| 248 |
} |
| 249 |
|
| 250 |
if (!filename) |
| 251 |
{ |
| 252 |
error ("No core file specified."); |
| 253 |
return; |
| 254 |
} |
| 255 |
|
| 256 |
filename = tilde_expand (filename); |
| 257 |
if (filename[0] != '/') |
| 258 |
{ |
| 259 |
cp = concat (current_directory, "/", filename, NULL); |
| 260 |
free (filename); |
| 261 |
filename = cp; |
| 262 |
} |
| 263 |
|
| 264 |
old_chain = make_cleanup (free, filename); |
| 265 |
|
| 266 |
kd = kvm_open (bfd_get_filename(exec_bfd), filename, NULL, |
| 267 |
kernel_writablecore ? O_RDWR: O_RDONLY, 0); |
| 268 |
if (kd == NULL) |
| 269 |
{ |
| 270 |
perror_with_name (filename); |
| 271 |
return; |
| 272 |
} |
| 273 |
|
| 274 |
/* Looks semi-reasonable. Toss the old core file and work on the new. */ |
| 275 |
|
| 276 |
discard_cleanups (old_chain); /* Don't free filename any more. */ |
| 277 |
core_file = filename; |
| 278 |
unpush_target (&kcore_ops); |
| 279 |
ontop = !push_target (&kcore_ops); |
| 280 |
|
| 281 |
/* Note unpush_target (above) calls kcore_close. */ |
| 282 |
core_kd = kd; |
| 283 |
|
| 284 |
/* Print out the panic string if there is one. */ |
| 285 |
if (kvread (ksym_lookup ("panicstr"), &addr) == 0 && |
| 286 |
addr != 0 && |
| 287 |
target_read_memory (addr, buf, sizeof(buf)) == 0) |
| 288 |
{ |
| 289 |
|
| 290 |
for (cp = buf; cp < &buf[sizeof(buf)] && *cp; cp++) |
| 291 |
if (!isascii (*cp) || (!isprint (*cp) && !isspace (*cp))) |
| 292 |
*cp = '?'; |
| 293 |
*cp = '\0'; |
| 294 |
if (buf[0] != '\0') |
| 295 |
printf_filtered ("panic: %s\n", buf); |
| 296 |
} |
| 297 |
|
| 298 |
/* Print all the panic messages if possible. */ |
| 299 |
if (symfile_objfile != NULL) |
| 300 |
{ |
| 301 |
printf ("panic messages:\n---\n"); |
| 302 |
snprintf (buf, sizeof buf, |
| 303 |
"/sbin/dmesg -N %s -M %s | \ |
| 304 |
/usr/bin/awk '/^(panic:|Fatal trap) / { printing = 1 } \ |
| 305 |
{ if (printing) print $0 }'", |
| 306 |
symfile_objfile->name, filename); |
| 307 |
fflush (stdout); |
| 308 |
system (buf); |
| 309 |
printf ("---\n"); |
| 310 |
} |
| 311 |
|
| 312 |
if (!ontop) |
| 313 |
{ |
| 314 |
warning ("you won't be able to access this core file until you terminate\n" |
| 315 |
"your %s; do ``info files''", target_longname); |
| 316 |
return; |
| 317 |
} |
| 318 |
|
| 319 |
/* Now, set up process context, and print the top of stack. */ |
| 320 |
(void)set_context (initial_pcb()); |
| 321 |
print_stack_frame (selected_frame, frame_relative_level(selected_frame), 1); |
| 322 |
} |
| 323 |
|
| 324 |
static void |
| 325 |
kcore_detach (char *args, int from_tty) |
| 326 |
{ |
| 327 |
if (args) |
| 328 |
error ("Too many arguments"); |
| 329 |
unpush_target (&kcore_ops); |
| 330 |
reinit_frame_cache (); |
| 331 |
if (from_tty) |
| 332 |
printf_filtered ("No kernel core file now.\n"); |
| 333 |
} |
| 334 |
|
| 335 |
#ifdef __alpha__ |
| 336 |
|
| 337 |
#include "alpha/tm-alpha.h" |
| 338 |
#include "alpha-tdep.h" |
| 339 |
|
| 340 |
#ifndef S0_REGNUM |
| 341 |
#define S0_REGNUM (ALPHA_T7_REGNUM+1) |
| 342 |
#endif |
| 343 |
|
| 344 |
fetch_kcore_registers (struct pcb *pcbp) |
| 345 |
{ |
| 346 |
|
| 347 |
/* First clear out any garbage. */ |
| 348 |
memset (registers, '\0', REGISTER_BYTES); |
| 349 |
|
| 350 |
/* SP */ |
| 351 |
*(long *) ®isters[REGISTER_BYTE (SP_REGNUM)] = |
| 352 |
pcbp->pcb_hw.apcb_ksp; |
| 353 |
|
| 354 |
/* S0 through S6 */ |
| 355 |
memcpy (®isters[REGISTER_BYTE (S0_REGNUM)], |
| 356 |
&pcbp->pcb_context[0], 7 * sizeof (long)); |
| 357 |
|
| 358 |
/* PC */ |
| 359 |
*(long *) ®isters[REGISTER_BYTE (PC_REGNUM)] = |
| 360 |
pcbp->pcb_context[7]; |
| 361 |
|
| 362 |
registers_fetched (); |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
CORE_ADDR |
| 367 |
fbsd_kern_frame_saved_pc (struct frame_info *fi) |
| 368 |
{ |
| 369 |
struct minimal_symbol *sym; |
| 370 |
CORE_ADDR this_saved_pc; |
| 371 |
|
| 372 |
this_saved_pc = FRAME_SAVED_PC(fi); |
| 373 |
|
| 374 |
sym = lookup_minimal_symbol_by_pc (this_saved_pc); |
| 375 |
|
| 376 |
if (sym != NULL && |
| 377 |
(strcmp (SYMBOL_NAME (sym), "XentArith") == 0 || |
| 378 |
strcmp (SYMBOL_NAME (sym), "XentIF") == 0 || |
| 379 |
strcmp (SYMBOL_NAME (sym), "XentInt") == 0 || |
| 380 |
strcmp (SYMBOL_NAME (sym), "XentMM") == 0 || |
| 381 |
strcmp (SYMBOL_NAME (sym), "XentSys") == 0 || |
| 382 |
strcmp (SYMBOL_NAME (sym), "XentUna") == 0 || |
| 383 |
strcmp (SYMBOL_NAME (sym), "XentRestart") == 0)) |
| 384 |
{ |
| 385 |
return (read_memory_integer (fi->frame + 32 * 8, 8)); |
| 386 |
} |
| 387 |
else |
| 388 |
{ |
| 389 |
return (this_saved_pc); |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
#endif /* __alpha__ */ |
| 394 |
|
| 395 |
#ifdef __i386__ |
| 396 |
|
| 397 |
static CORE_ADDR |
| 398 |
ksym_maxuseraddr (void) |
| 399 |
{ |
| 400 |
static CORE_ADDR maxuseraddr; |
| 401 |
struct minimal_symbol *sym; |
| 402 |
|
| 403 |
if (maxuseraddr == 0) |
| 404 |
{ |
| 405 |
sym = lookup_minimal_symbol ("PTmap", NULL, NULL); |
| 406 |
if (sym == NULL) { |
| 407 |
maxuseraddr = VM_MAXUSER_ADDRESS; |
| 408 |
} else { |
| 409 |
maxuseraddr = SYMBOL_VALUE_ADDRESS (sym); |
| 410 |
} |
| 411 |
} |
| 412 |
return maxuseraddr; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
/* Symbol names of kernel entry points. Use special frames. */ |
| 417 |
#define KSYM_TRAP "calltrap" |
| 418 |
#define KSYM_INTR "Xintr" |
| 419 |
#define KSYM_FASTINTR "Xfastintr" |
| 420 |
#define KSYM_OLDSYSCALL "Xlcall_syscall" |
| 421 |
#define KSYM_SYSCALL "Xint0x80_syscall" |
| 422 |
|
| 423 |
/* The following is FreeBSD-specific hackery to decode special frames |
| 424 |
and elide the assembly-language stub. This could be made faster by |
| 425 |
defining a frame_type field in the machine-dependent frame information, |
| 426 |
but we don't think that's too important right now. */ |
| 427 |
enum frametype { tf_normal, tf_trap, tf_interrupt, tf_syscall }; |
| 428 |
|
| 429 |
CORE_ADDR |
| 430 |
fbsd_kern_frame_saved_pc (struct frame_info *fr) |
| 431 |
{ |
| 432 |
struct minimal_symbol *sym; |
| 433 |
CORE_ADDR this_saved_pc; |
| 434 |
enum frametype frametype; |
| 435 |
|
| 436 |
this_saved_pc = read_memory_integer (fr->frame + 4, 4); |
| 437 |
sym = lookup_minimal_symbol_by_pc (this_saved_pc); |
| 438 |
frametype = tf_normal; |
| 439 |
if (sym != NULL) |
| 440 |
{ |
| 441 |
if (strcmp (SYMBOL_NAME (sym), KSYM_TRAP) == 0) |
| 442 |
frametype = tf_trap; |
| 443 |
else |
| 444 |
if (strncmp (SYMBOL_NAME (sym), KSYM_INTR, |
| 445 |
strlen (KSYM_INTR)) == 0 || strncmp (SYMBOL_NAME(sym), |
| 446 |
KSYM_FASTINTR, strlen (KSYM_FASTINTR)) == 0) |
| 447 |
frametype = tf_interrupt; |
| 448 |
else |
| 449 |
if (strcmp (SYMBOL_NAME (sym), KSYM_SYSCALL) == 0 || |
| 450 |
strcmp (SYMBOL_NAME (sym), KSYM_OLDSYSCALL) == 0) |
| 451 |
frametype = tf_syscall; |
| 452 |
} |
| 453 |
|
| 454 |
switch (frametype) |
| 455 |
{ |
| 456 |
default: |
| 457 |
case tf_normal: |
| 458 |
return (this_saved_pc); |
| 459 |
#define oEIP offsetof (struct trapframe, tf_eip) |
| 460 |
|
| 461 |
case tf_trap: |
| 462 |
return (read_memory_integer (fr->frame + 8 + oEIP, 4)); |
| 463 |
|
| 464 |
case tf_interrupt: |
| 465 |
return (read_memory_integer (fr->frame + 12 + oEIP, 4)); |
| 466 |
|
| 467 |
case tf_syscall: |
| 468 |
return (read_memory_integer (fr->frame + 8 + oEIP, 4)); |
| 469 |
#undef oEIP |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
static void |
| 474 |
fetch_kcore_registers (struct pcb *pcb) |
| 475 |
{ |
| 476 |
int i; |
| 477 |
int noreg; |
| 478 |
|
| 479 |
/* Get the register values out of the sys pcb and store them where |
| 480 |
`read_register' will find them. */ |
| 481 |
/* |
| 482 |
* XXX many registers aren't available. |
| 483 |
* XXX for the non-core case, the registers are stale - they are for |
| 484 |
* the last context switch to the debugger. |
| 485 |
* XXX gcc's register numbers aren't all #defined in tm-i386.h. |
| 486 |
*/ |
| 487 |
noreg = 0; |
| 488 |
for (i = 0; i < 3; ++i) /* eax,ecx,edx */ |
| 489 |
supply_register (i, (char *)&noreg); |
| 490 |
|
| 491 |
supply_register (3, (char *) &pcb->pcb_ebx); |
| 492 |
supply_register (SP_REGNUM, (char *) &pcb->pcb_esp); |
| 493 |
supply_register (FP_REGNUM, (char *) &pcb->pcb_ebp); |
| 494 |
supply_register (6, (char *) &pcb->pcb_esi); |
| 495 |
supply_register (7, (char *) &pcb->pcb_edi); |
| 496 |
supply_register (PC_REGNUM, (char *) &pcb->pcb_eip); |
| 497 |
|
| 498 |
for (i = 9; i < 14; ++i) /* eflags, cs, ss, ds, es, fs */ |
| 499 |
supply_register (i, (char *) &noreg); |
| 500 |
supply_register (15, (char *) &pcb->pcb_gs); |
| 501 |
|
| 502 |
/* XXX 80387 registers? */ |
| 503 |
} |
| 504 |
|
| 505 |
#endif /* __i386__ */ |
| 506 |
|
| 507 |
#ifdef __sparc64__ |
| 508 |
|
| 509 |
#define SPARC_INTREG_SIZE 8 |
| 510 |
|
| 511 |
static void |
| 512 |
fetch_kcore_registers (struct pcb *pcbp) |
| 513 |
{ |
| 514 |
static struct frame top; |
| 515 |
CORE_ADDR f_addr; |
| 516 |
int i; |
| 517 |
|
| 518 |
/* Get the register values out of the sys pcb and store them where |
| 519 |
`read_register' will find them. */ |
| 520 |
/* |
| 521 |
* XXX many registers aren't available. |
| 522 |
* XXX for the non-core case, the registers are stale - they are for |
| 523 |
* the last context switch to the debugger. |
| 524 |
* XXX do something with the floating-point registers? |
| 525 |
*/ |
| 526 |
supply_register (SP_REGNUM, &pcbp->pcb_sp); |
| 527 |
supply_register (PC_REGNUM, &pcbp->pcb_pc); |
| 528 |
f_addr = extract_address (&pcbp->pcb_sp, SPARC_INTREG_SIZE); |
| 529 |
/* Load the previous frame by hand (XXX) and supply it. */ |
| 530 |
read_memory (f_addr + SPOFF, (char *)&top, sizeof (top)); |
| 531 |
for (i = 0; i < 8; i++) |
| 532 |
supply_register (i + L0_REGNUM, &top.fr_local[i]); |
| 533 |
for (i = 0; i < 8; i++) |
| 534 |
supply_register (i + I0_REGNUM, &top.fr_in[i]); |
| 535 |
} |
| 536 |
|
| 537 |
CORE_ADDR |
| 538 |
fbsd_kern_frame_saved_pc (struct frame_info *fi) |
| 539 |
{ |
| 540 |
struct minimal_symbol *sym; |
| 541 |
CORE_ADDR frame, pc_addr, pc; |
| 542 |
char *buf; |
| 543 |
|
| 544 |
buf = alloca (MAX_REGISTER_RAW_SIZE); |
| 545 |
/* XXX: duplicates fi->extra_info->bottom. */ |
| 546 |
frame = (fi->next != NULL) ? fi->next->frame : read_sp (); |
| 547 |
pc_addr = frame + offsetof (struct frame, fr_in[7]); |
| 548 |
|
| 549 |
#define READ_PC(pc, a, b) do { \ |
| 550 |
read_memory (a, b, SPARC_INTREG_SIZE); \ |
| 551 |
pc = extract_address (b, SPARC_INTREG_SIZE); \ |
| 552 |
} while (0) |
| 553 |
|
| 554 |
READ_PC (pc, pc_addr, buf); |
| 555 |
|
| 556 |
sym = lookup_minimal_symbol_by_pc (pc); |
| 557 |
if (sym != NULL) |
| 558 |
{ |
| 559 |
if (strncmp (SYMBOL_NAME (sym), "tl0_", 4) == 0 || |
| 560 |
strcmp (SYMBOL_NAME (sym), "btext") == 0 || |
| 561 |
strcmp (SYMBOL_NAME (sym), "mp_startup") == 0 || |
| 562 |
strcmp (SYMBOL_NAME (sym), "fork_trampoline") == 0) |
| 563 |
{ |
| 564 |
/* |
| 565 |
* Ugly kluge: user space addresses aren't separated from kernel |
| 566 |
* ones by range; if encountering a trap from user space, just |
| 567 |
* return a 0 to stop the trace. |
| 568 |
* Do the same for entry points of kernel processes to avoid |
| 569 |
* printing garbage. |
| 570 |
*/ |
| 571 |
pc = 0; |
| 572 |
} |
| 573 |
if (strncmp (SYMBOL_NAME (sym), "tl1_", 4) == 0) |
| 574 |
{ |
| 575 |
pc_addr = fi->frame + sizeof (struct frame) + |
| 576 |
offsetof (struct trapframe, tf_tpc); |
| 577 |
READ_PC (pc, pc_addr, buf); |
| 578 |
} |
| 579 |
} |
| 580 |
return (pc); |
| 581 |
} |
| 582 |
|
| 583 |
#endif /* __sparc64__ */ |
| 584 |
|
| 585 |
/* Get the registers out of a core file. This is the machine- |
| 586 |
independent part. Fetch_core_registers is the machine-dependent |
| 587 |
part, typically implemented in the xm-file for each architecture. */ |
| 588 |
|
| 589 |
/* We just get all the registers, so we don't use regno. */ |
| 590 |
|
| 591 |
/* ARGSUSED */ |
| 592 |
static void |
| 593 |
get_kcore_registers (int regno) |
| 594 |
{ |
| 595 |
|
| 596 |
/* XXX - Only read the pcb when set_context() is called. |
| 597 |
When looking at a live kernel this may be a problem, |
| 598 |
but the user can do another "proc" or "pcb" command to |
| 599 |
grab a new copy of the pcb... */ |
| 600 |
|
| 601 |
/* Zero out register set then fill in the ones we know about. */ |
| 602 |
fetch_kcore_registers (&cur_pcb); |
| 603 |
} |
| 604 |
|
| 605 |
static void |
| 606 |
kcore_files_info (t) |
| 607 |
struct target_ops *t; |
| 608 |
{ |
| 609 |
printf_filtered ("\t`%s'\n", core_file); |
| 610 |
} |
| 611 |
|
| 612 |
/* If mourn is being called in all the right places, this could be say |
| 613 |
`gdb internal error' (since generic_mourn calls breakpoint_init_inferior). */ |
| 614 |
|
| 615 |
static int |
| 616 |
ignore (CORE_ADDR addr, char *contents) |
| 617 |
{ |
| 618 |
return 0; |
| 619 |
} |
| 620 |
|
| 621 |
static int |
| 622 |
xfer_kmem (CORE_ADDR memaddr, char *myaddr, int len, int write, |
| 623 |
struct mem_attrib *attrib, struct target_ops *target) |
| 624 |
{ |
| 625 |
int n; |
| 626 |
|
| 627 |
|
| 628 |
if (!INKERNEL (memaddr)) |
| 629 |
return xfer_umem (memaddr, myaddr, len, write); |
| 630 |
|
| 631 |
if (core_kd == NULL) |
| 632 |
return 0; |
| 633 |
|
| 634 |
if (write) |
| 635 |
n = kvm_write (core_kd, memaddr, myaddr, len); |
| 636 |
else |
| 637 |
n = kvm_read (core_kd, memaddr, myaddr, len) ; |
| 638 |
if (n < 0) { |
| 639 |
fprintf_unfiltered (gdb_stderr, "can not access 0x%x, %s\n", |
| 640 |
memaddr, kvm_geterr (core_kd)); |
| 641 |
n = 0; |
| 642 |
} |
| 643 |
|
| 644 |
return n; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
static int |
| 649 |
xfer_umem (CORE_ADDR memaddr, char *myaddr, int len, int write /* ignored */) |
| 650 |
{ |
| 651 |
int n = 0; |
| 652 |
|
| 653 |
if (cur_proc == 0) |
| 654 |
{ |
| 655 |
error ("---Can't read userspace from dump, or kernel process---\n"); |
| 656 |
return 0; |
| 657 |
} |
| 658 |
|
| 659 |
if (write) |
| 660 |
error ("kvm_uwrite unimplemented\n"); |
| 661 |
else |
| 662 |
n = kvm_uread (core_kd, cur_proc, memaddr, myaddr, len) ; |
| 663 |
|
| 664 |
if (n < 0) |
| 665 |
return 0; |
| 666 |
|
| 667 |
return n; |
| 668 |
} |
| 669 |
|
| 670 |
static void |
| 671 |
set_proc_cmd (char *arg, int from_tty) |
| 672 |
{ |
| 673 |
CORE_ADDR addr, pid_addr, first_td; |
| 674 |
void *val; |
| 675 |
struct kinfo_proc *kp; |
| 676 |
int cnt; |
| 677 |
pid_t pid; |
| 678 |
|
| 679 |
if (!arg) |
| 680 |
error_no_arg ("proc address for the new context"); |
| 681 |
|
| 682 |
if (core_kd == NULL) |
| 683 |
error ("no kernel core file"); |
| 684 |
|
| 685 |
addr = (CORE_ADDR) parse_and_eval_address (arg); |
| 686 |
|
| 687 |
if (!INKERNEL (addr)) |
| 688 |
{ |
| 689 |
kp = kvm_getprocs (core_kd, KERN_PROC_PID, addr, &cnt); |
| 690 |
if (!cnt) |
| 691 |
error ("invalid pid"); |
| 692 |
addr = (CORE_ADDR)kp->ki_paddr; |
| 693 |
cur_proc = kp; |
| 694 |
} |
| 695 |
else |
| 696 |
{ |
| 697 |
/* Update cur_proc. */ |
| 698 |
pid_addr = addr + offsetof (struct proc, p_pid); |
| 699 |
if (kvread (pid_addr, &pid)) |
| 700 |
error ("cannot read pid ptr"); |
| 701 |
cur_proc = kvm_getprocs (core_kd, KERN_PROC_PID, pid, &cnt); |
| 702 |
if (!cnt) |
| 703 |
error("invalid pid"); |
| 704 |
} |
| 705 |
|
| 706 |
/* Find the first thread in the process. XXXKSE */ |
| 707 |
addr += offsetof (struct proc, p_threads.tqh_first); |
| 708 |
if (kvread (addr, &first_td)) |
| 709 |
error ("cannot read thread ptr"); |
| 710 |
|
| 711 |
/* Read the PCB address in thread structure. */ |
| 712 |
addr = first_td + offsetof (struct thread, td_pcb); |
| 713 |
if (kvread (addr, &val)) |
| 714 |
error("cannot read pcb ptr"); |
| 715 |
|
| 716 |
/* Read the PCB address in proc structure. */ |
| 717 |
if (set_context ((CORE_ADDR) val)) |
| 718 |
error ("invalid proc address"); |
| 719 |
} |
| 720 |
#else |
| 721 |
int kernel_debugging = 0; |
| 722 |
int kernel_writablecore = 0; |
| 723 |
|
| 724 |
CORE_ADDR |
| 725 |
fbsd_kern_frame_saved_pc (struct frame_info *fi) |
| 726 |
{ |
| 727 |
return 0; |
| 728 |
} |
| 729 |
#endif |
| 730 |
|
| 731 |
void |
| 732 |
_initialize_kcorelow (void) |
| 733 |
{ |
| 734 |
#if __FreeBSD_version >= 500032 |
| 735 |
kcore_ops.to_shortname = "kcore"; |
| 736 |
kcore_ops.to_longname = "Kernel core dump file"; |
| 737 |
kcore_ops.to_doc = |
| 738 |
"Use a core file as a target. Specify the filename of the core file."; |
| 739 |
kcore_ops.to_open = kcore_open; |
| 740 |
kcore_ops.to_close = kcore_close; |
| 741 |
kcore_ops.to_attach = find_default_attach; |
| 742 |
kcore_ops.to_detach = kcore_detach; |
| 743 |
kcore_ops.to_fetch_registers = get_kcore_registers; |
| 744 |
kcore_ops.to_xfer_memory = xfer_kmem; |
| 745 |
kcore_ops.to_files_info = kcore_files_info; |
| 746 |
kcore_ops.to_create_inferior = find_default_create_inferior; |
| 747 |
kcore_ops.to_stratum = kcore_stratum; |
| 748 |
kcore_ops.to_has_memory = 1; |
| 749 |
kcore_ops.to_has_stack = 1; |
| 750 |
kcore_ops.to_has_registers = 1; |
| 751 |
kcore_ops.to_magic = OPS_MAGIC; |
| 752 |
|
| 753 |
add_target (&kcore_ops); |
| 754 |
add_com ("proc", class_obscure, set_proc_cmd, "Set current process context"); |
| 755 |
#endif |
| 756 |
} |