summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2005-12-21 15:15:09 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2005-12-21 15:15:09 +0000
commit08bf10da3c66956365f463b9c0e12e74e9a60bc2 (patch)
treea023bca6dff665b202cb7c4d48d3b6f8fd66b9b9 /gnu
parentffe838bfe7a80f3d9dd4b2dd0be11bae732e36e2 (diff)
Teach gdb how to unwind i386 kernel trap frames.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/binutils/gdb/Makefile.in7
-rw-r--r--gnu/usr.bin/binutils/gdb/i386-tdep.h55
-rw-r--r--gnu/usr.bin/binutils/gdb/i386obsd-tdep.c120
3 files changed, 133 insertions, 49 deletions
diff --git a/gnu/usr.bin/binutils/gdb/Makefile.in b/gnu/usr.bin/binutils/gdb/Makefile.in
index 040db280e42..0a8351ba3ec 100644
--- a/gnu/usr.bin/binutils/gdb/Makefile.in
+++ b/gnu/usr.bin/binutils/gdb/Makefile.in
@@ -2028,9 +2028,10 @@ i386-nto-tdep.o: i386-nto-tdep.c $(gdb_string_h) $(gdb_assert_h) $(defs_h) \
$(nto_tdep_h) $(osabi_h) $(i387_tdep_h)
i386obsd-nat.o: i386obsd-nat.c $(defs_h) $(i386_tdep_h)
i386obsd-tdep.o: i386obsd-tdep.c $(defs_h) $(arch_utils_h) $(frame_h) \
- $(gdbcore_h) $(regcache_h) $(regset_h) $(symtab_h) $(objfiles_h) \
- $(osabi_h) $(target_h) $(gdb_assert_h) $(gdb_string_h) \
- $(i386_tdep_h) $(i387_tdep_h) $(solib_svr4_h)
+ $(frame_unwind_h) $(gdbcore_h) $(regcache_h) $(regset_h) $(symtab_h) \
+ $(objfiles_h) $(osabi_h) $(target_h) $(trad_frame_h) $(gdb_assert_h) \
+ $(gdb_string_h) $(i386_tdep_h) $(i387_tdep_h) $(solib_svr4_h) \
+ $(bsd_uthread_h)
i386-sol2-tdep.o: i386-sol2-tdep.c $(defs_h) $(value_h) $(osabi_h) \
$(gdb_string_h) $(i386_tdep_h) $(solib_svr4_h)
i386-stub.o: i386-stub.c
diff --git a/gnu/usr.bin/binutils/gdb/i386-tdep.h b/gnu/usr.bin/binutils/gdb/i386-tdep.h
index 9cb87653e12..0a44db9b1d1 100644
--- a/gnu/usr.bin/binutils/gdb/i386-tdep.h
+++ b/gnu/usr.bin/binutils/gdb/i386-tdep.h
@@ -1,6 +1,6 @@
/* Target-dependent code for the i386.
- Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GDB.
@@ -89,6 +89,9 @@ struct gdbarch_tdep
CORE_ADDR sigtramp_start;
CORE_ADDR sigtramp_end;
+ /* Detect sigtramp. */
+ int (*sigtramp_p) (struct frame_info *);
+
/* Get address of sigcontext for sigtramp. */
CORE_ADDR (*sigcontext_addr) (struct frame_info *);
@@ -108,48 +111,11 @@ struct gdbarch_tdep
(at most) in the FPU, but are zero-extended to 32 bits in GDB's
register cache. */
-/* "Generic" floating point control register. */
-#define FPC_REGNUM (FP0_REGNUM + 8)
-
-/* FPU control word. */
-#define FCTRL_REGNUM FPC_REGNUM
-
-/* FPU status word. */
-#define FSTAT_REGNUM (FPC_REGNUM + 1)
-
-/* FPU register tag word. */
-#define FTAG_REGNUM (FPC_REGNUM + 2)
-
-/* FPU instruction's code segment selector, called "FPU Instruction
- Pointer Selector" in the IA-32 manuals. */
-#define FISEG_REGNUM (FPC_REGNUM + 3)
-
-/* FPU instruction's offset within segment. */
-#define FIOFF_REGNUM (FPC_REGNUM + 4)
-
-/* FPU operand's data segment. */
-#define FOSEG_REGNUM (FPC_REGNUM + 5)
-
-/* FPU operand's offset within segment */
-#define FOOFF_REGNUM (FPC_REGNUM + 6)
-
-/* FPU opcode, bottom eleven bits. */
-#define FOP_REGNUM (FPC_REGNUM + 7)
-
/* Return non-zero if REGNUM matches the FP register and the FP
register set is active. */
extern int i386_fp_regnum_p (int regnum);
extern int i386_fpc_regnum_p (int regnum);
-/* SSE registers. */
-
-/* First SSE data register. */
-#define XMM0_REGNUM (FPC_REGNUM + 8)
-
-/* SSE control/status register. */
-#define MXCSR_REGNUM \
- (XMM0_REGNUM + gdbarch_tdep (current_gdbarch)->num_xmm_regs)
-
/* Register numbers of various important registers. */
enum i386_regnum
@@ -183,12 +149,16 @@ enum i386_regnum
/* Size of the largest register. */
#define I386_MAX_REGISTER_SIZE 16
+/* Segment selectors. */
+#define I386_SEL_RPL 0x0003 /* Requester's Privilege Level mask. */
+#define I386_SEL_UPL 0x0003 /* User Privilige Level. */
+#define I386_SEL_KPL 0x0000 /* Kernel Privilige Level. */
+
/* Functions exported from i386-tdep.c. */
extern CORE_ADDR i386_pe_skip_trampoline_code (CORE_ADDR pc, char *name);
-extern int i386_frameless_signal_p (struct frame_info *frame);
-/* Return the name of register REG. */
-extern char const *i386_register_name (int reg);
+/* Return the name of register REGNUM. */
+extern char const *i386_register_name (int regnum);
/* Return non-zero if REGNUM is a member of the specified group. */
extern int i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
@@ -217,9 +187,6 @@ extern void i386_svr4_init_abi (struct gdbarch_info, struct gdbarch *);
/* Functions and variables exported from i386bsd-tdep.c. */
extern void i386bsd_init_abi (struct gdbarch_info, struct gdbarch *);
-extern int i386bsd_pc_in_sigtramp (CORE_ADDR pc, char *name);
-extern CORE_ADDR i386bsd_sigtramp_start (CORE_ADDR pc);
-extern CORE_ADDR i386bsd_sigtramp_end (CORE_ADDR pc);
extern CORE_ADDR i386fbsd_sigtramp_start_addr;
extern CORE_ADDR i386fbsd_sigtramp_end_addr;
extern CORE_ADDR i386obsd_sigtramp_start_addr;
diff --git a/gnu/usr.bin/binutils/gdb/i386obsd-tdep.c b/gnu/usr.bin/binutils/gdb/i386obsd-tdep.c
index 5b23e93c0e7..27b82448fee 100644
--- a/gnu/usr.bin/binutils/gdb/i386obsd-tdep.c
+++ b/gnu/usr.bin/binutils/gdb/i386obsd-tdep.c
@@ -1,7 +1,7 @@
/* Target-dependent code for OpenBSD/i386.
Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002,
- 2003, 2004
+ 2003, 2004, 2005
Free Software Foundation, Inc.
This file is part of GDB.
@@ -24,6 +24,7 @@
#include "defs.h"
#include "arch-utils.h"
#include "frame.h"
+#include "frame-unwind.h"
#include "gdbcore.h"
#include "regcache.h"
#include "regset.h"
@@ -31,6 +32,7 @@
#include "objfiles.h"
#include "osabi.h"
#include "target.h"
+#include "trad-frame.h"
#include "gdb_assert.h"
#include "gdb_string.h"
@@ -258,7 +260,6 @@ i386obsd_supply_uthread (struct regcache *regcache,
regcache_raw_supply (regcache, i, buf);
}
}
-
}
static void
@@ -306,6 +307,118 @@ i386obsd_collect_uthread (const struct regcache *regcache,
}
}
}
+/* Kernel debugging support. */
+
+/* From <machine/frame.h>. Note that %esp and %ess are only saved in
+ a trap frame when entering the kernel from user space. */
+static int i386obsd_tf_reg_offset[] =
+{
+ 10 * 4, /* %eax */
+ 9 * 4, /* %ecx */
+ 8 * 4, /* %edx */
+ 7 * 4, /* %ebx */
+ -1, /* %esp */
+ 6 * 4, /* %ebp */
+ 5 * 4, /* %esi */
+ 4 * 4, /* %edi */
+ 13 * 4, /* %eip */
+ 15 * 4, /* %eflags */
+ 14 * 4, /* %cs */
+ -1, /* %ss */
+ 3 * 4, /* %ds */
+ 2 * 4, /* %es */
+ 0 * 4, /* %fs */
+ 1 * 4 /* %gs */
+};
+
+static struct trad_frame_cache *
+i386obsd_trapframe_cache(struct frame_info *next_frame, void **this_cache)
+{
+ struct trad_frame_cache *cache;
+ CORE_ADDR func, sp, addr;
+ ULONGEST cs;
+ int i;
+
+ if (*this_cache)
+ return *this_cache;
+
+ cache = trad_frame_cache_zalloc (next_frame);
+ *this_cache = cache;
+
+ func = frame_func_unwind (next_frame);
+ sp = frame_unwind_register_unsigned (next_frame, I386_ESP_REGNUM);
+ for (i = 0; i < ARRAY_SIZE (i386obsd_tf_reg_offset); i++)
+ if (i386obsd_tf_reg_offset[i] != -1)
+ trad_frame_set_reg_addr (cache, i, sp + i386obsd_tf_reg_offset[i]);
+
+ /* Read %cs from trap frame. */
+ addr = sp + i386obsd_tf_reg_offset[I386_CS_REGNUM];
+ cs = read_memory_unsigned_integer (addr, 4);
+ if ((cs & I386_SEL_RPL) == I386_SEL_UPL)
+ {
+ /* Trap from use space; terminate backtrace. */
+ trad_frame_set_id (cache, null_frame_id);
+ }
+ else
+ {
+ /* Construct the frame ID using the function start. */
+ trad_frame_set_id (cache, frame_id_build (sp + 8, func));
+ }
+
+ return cache;
+}
+
+static void
+i386obsd_trapframe_this_id (struct frame_info *next_frame,
+ void **this_cache, struct frame_id *this_id)
+{
+ struct trad_frame_cache *cache =
+ i386obsd_trapframe_cache (next_frame, this_cache);
+
+ trad_frame_get_id (cache, this_id);
+}
+
+static void
+i386obsd_trapframe_prev_register (struct frame_info *next_frame,
+ void **this_cache, int regnum,
+ int *optimizedp, enum lval_type *lvalp,
+ CORE_ADDR *addrp, int *realnump,
+ void *valuep)
+{
+ struct trad_frame_cache *cache =
+ i386obsd_trapframe_cache (next_frame, this_cache);
+
+ trad_frame_get_register (cache, next_frame, regnum,
+ optimizedp, lvalp, addrp, realnump, valuep);
+}
+
+static const struct frame_unwind i386obsd_trapframe_unwind = {
+ /* FIXME: kettenis/20051219: This really is more like an interrupt
+ frame, but SIGTRAMP_FRAME would print <signal handler called>,
+ which really is not what we want here. */
+ NORMAL_FRAME,
+ i386obsd_trapframe_this_id,
+ i386obsd_trapframe_prev_register
+};
+
+static const struct frame_unwind *
+i386obsd_trapframe_sniffer (struct frame_info *next_frame)
+{
+ ULONGEST cs;
+ char *name;
+
+ cs = frame_unwind_register_unsigned (next_frame, I386_CS_REGNUM);
+ if ((cs & I386_SEL_RPL) == I386_SEL_UPL)
+ return NULL;
+
+ find_pc_partial_function (frame_pc_unwind (next_frame), &name, NULL, NULL);
+ if (name && ((strcmp ("calltrap", name) == 0)
+ || (strcmp ("syscall1", name) == 0)))
+ return &i386obsd_trapframe_unwind;
+
+ return NULL;
+}
+
static void
i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
@@ -336,6 +449,9 @@ i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
/* OpenBSD provides a user-level threads implementation. */
bsd_uthread_set_supply_uthread (gdbarch, i386obsd_supply_uthread);
bsd_uthread_set_collect_uthread (gdbarch, i386obsd_collect_uthread);
+
+ /* Unwind kernel trap frames correctly. */
+ frame_unwind_append_sniffer (gdbarch, i386obsd_trapframe_sniffer);
}
/* OpenBSD a.out. */