diff options
Diffstat (limited to 'gnu/usr.bin/binutils/gdb/kvm-fbsd.c')
-rw-r--r-- | gnu/usr.bin/binutils/gdb/kvm-fbsd.c | 281 |
1 files changed, 8 insertions, 273 deletions
diff --git a/gnu/usr.bin/binutils/gdb/kvm-fbsd.c b/gnu/usr.bin/binutils/gdb/kvm-fbsd.c index da6435e..93395a7 100644 --- a/gnu/usr.bin/binutils/gdb/kvm-fbsd.c +++ b/gnu/usr.bin/binutils/gdb/kvm-fbsd.c @@ -19,7 +19,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $FreeBSD$ */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * This works like "remote" but, you use it like this: @@ -33,31 +34,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <sys/param.h> -#include <sys/time.h> -#include <sys/proc.h> #include <sys/user.h> -#include <errno.h> -#include <signal.h> +#include <ctype.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 <readline/tilde.h> #include "gdb_string.h" #include "frame.h" /* required by inferior.h */ #include "inferior.h" -#include "symtab.h" #include "symfile.h" #include "objfiles.h" #include "command.h" #include "bfd.h" -#include "target.h" #include "gdbcore.h" #include "solist.h" +#include "kvm-fbsd-machine.h" + static void kcore_files_info (struct target_ops *); @@ -68,10 +65,6 @@ static void get_kcore_registers (int); static int -xfer_mem (CORE_ADDR, char *, int, int, struct mem_attrib *, - struct target_ops *); - -static int xfer_umem (CORE_ADDR, char *, int, int); #ifdef SOLIB_ADD @@ -116,7 +109,7 @@ ksym_kernbase (void) #define KERNOFF (ksym_kernbase ()) #define INKERNEL(x) ((x) >= KERNOFF) -CORE_ADDR +static CORE_ADDR ksym_lookup(const char *name) { struct minimal_symbol *sym; @@ -190,8 +183,6 @@ initial_pcb (void) static int set_context (CORE_ADDR addr) { - CORE_ADDR procaddr = 0; - if (kvread (addr, &cur_pcb)) error ("cannot read pcb at %#x", addr); @@ -349,253 +340,6 @@ kcore_detach (char *args, int from_tty) printf_filtered ("No kernel core file now.\n"); } -#ifdef __alpha__ - -#include "alpha/tm-alpha.h" -#ifndef S0_REGNUM -#define S0_REGNUM (T7_REGNUM+1) -#endif - -fetch_kcore_registers (struct pcb *pcbp) -{ - - /* First clear out any garbage. */ - memset (registers, '\0', REGISTER_BYTES); - - /* SP */ - *(long *) ®isters[REGISTER_BYTE (SP_REGNUM)] = - pcbp->pcb_hw.apcb_ksp; - - /* S0 through S6 */ - memcpy (®isters[REGISTER_BYTE (S0_REGNUM)], - &pcbp->pcb_context[0], 7 * sizeof (long)); - - /* PC */ - *(long *) ®isters[REGISTER_BYTE (PC_REGNUM)] = - pcbp->pcb_context[7]; - - registers_fetched (); -} - - -CORE_ADDR -fbsd_kern_frame_saved_pc (struct frame_info *fi) -{ - 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); - } -} - -#endif /* __alpha__ */ - -#ifdef __i386__ - -static CORE_ADDR -ksym_maxuseraddr (void) -{ - 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; -} - - -/* Symbol names of kernel entry points. Use special frames. */ -#define KSYM_TRAP "calltrap" -#define KSYM_INTR "Xintr" -#define KSYM_FASTINTR "Xfastintr" -#define KSYM_OLDSYSCALL "Xlcall_syscall" -#define KSYM_SYSCALL "Xint0x80_syscall" - -/* 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. */ -enum frametype { tf_normal, tf_trap, tf_interrupt, tf_syscall }; - -CORE_ADDR -fbsd_kern_frame_saved_pc (struct frame_info *fi) -{ - struct minimal_symbol *sym; - CORE_ADDR this_saved_pc; - enum frametype frametype; - - this_saved_pc = read_memory_integer (fi->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 (fi->frame + 8 + oEIP, 4)); - - case tf_interrupt: - return (read_memory_integer (fi->frame + 12 + oEIP, 4)); - - case tf_syscall: - return (read_memory_integer (fi->frame + 8 + oEIP, 4)); -#undef oEIP - } -} - -static int -fetch_kcore_registers (struct pcb *pcb) -{ - int i; - int noreg; - - /* Get the register values out of the sys pcb and store them where - `read_register' will find them. */ - /* - * 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); - - 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); - - for (i = 9; i < 14; ++i) /* eflags, cs, ss, ds, es, fs */ - supply_register (i, (char *) &noreg); - supply_register (15, (char *) &pcb->pcb_gs); - - /* XXX 80387 registers? */ -} - -#endif /* __i386__ */ - -#ifdef __sparc64__ - -#define SPARC_INTREG_SIZE 8 - -static void -fetch_kcore_registers (struct pcb *pcbp) -{ - static struct frame top; - CORE_ADDR f_addr; - int i; - - /* Get the register values out of the sys pcb and store them where - `read_register' will find them. */ - /* - * 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 do something with the floating-point registers? - */ - supply_register (SP_REGNUM, (char *)&pcbp->pcb_ufp); - supply_register (PC_REGNUM, (char *)&pcbp->pcb_pc); - f_addr = extract_address (&pcbp->pcb_ufp, SPARC_INTREG_SIZE); - /* Load the previous frame by hand (XXX) and supply it. */ - read_memory (f_addr + SPOFF, (char *)&top, sizeof (top)); - for (i = 0; i < 8; i++) - supply_register (i + L0_REGNUM, (char *)&top.fr_local[i]); - for (i = 0; i < 8; i++) - supply_register (i + I0_REGNUM, (char *)&top.fr_in[i]); -} - -CORE_ADDR -fbsd_kern_frame_saved_pc (struct frame_info *fi) -{ - struct minimal_symbol *sym; - CORE_ADDR frame, pc_addr, pc; - char *buf; - - buf = alloca (MAX_REGISTER_RAW_SIZE); - /* XXX: duplicates fi->extra_info->bottom. */ - frame = (fi->next != NULL) ? fi->next->frame : read_sp (); - pc_addr = frame + offsetof (struct frame, fr_in[7]); - -#define READ_PC(pc, a, b) do { \ - read_memory (a, b, SPARC_INTREG_SIZE); \ - pc = extract_address (b, SPARC_INTREG_SIZE); \ -} while (0) - - READ_PC (pc, pc_addr, buf); - - sym = lookup_minimal_symbol_by_pc (pc); - if (sym != NULL) - { - if (strncmp (SYMBOL_NAME (sym), "tl0_", 4) == 0 || - strcmp (SYMBOL_NAME (sym), "btext") == 0 || - strcmp (SYMBOL_NAME (sym), "mp_startup") == 0 || - strcmp (SYMBOL_NAME (sym), "fork_trampoline") == 0) - { - /* - * Ugly kluge: user space addresses aren't separated from kernel - * ones by range; if encountering a trap from user space, just - * return a 0 to stop the trace. - * Do the same for entry points of kernel processes to avoid - * printing garbage. - */ - pc = 0; - } - if (strncmp (SYMBOL_NAME (sym), "tl1_", 4) == 0) - { - pc_addr = fi->frame + sizeof (struct frame) + - offsetof (struct trapframe, tf_tpc); - READ_PC (pc, pc_addr, buf); - } - } - return (pc); -} - -#endif /* __sparc64__ */ - /* 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. */ @@ -623,15 +367,6 @@ kcore_files_info (t) printf_filtered ("\t`%s'\n", core_file); } -/* If mourn is being called in all the right places, this could be say - `gdb internal error' (since generic_mourn calls breakpoint_init_inferior). */ - -static int -ignore (CORE_ADDR addr, char *contents) -{ - return 0; -} - static int xfer_kmem (CORE_ADDR memaddr, char *myaddr, int len, int write, struct mem_attrib *attrib, struct target_ops *target) @@ -651,7 +386,7 @@ xfer_kmem (CORE_ADDR memaddr, char *myaddr, int len, int write, n = kvm_read (core_kd, memaddr, myaddr, len) ; if (n < 0) { fprintf_unfiltered (gdb_stderr, "can not access 0x%x, %s\n", - memaddr, kvm_geterr (core_kd)); + (unsigned)memaddr, kvm_geterr (core_kd)); n = 0; } |