From d05b9c6e820e8e68064f651bc7e040ff8149f153 Mon Sep 17 00:00:00 2001 From: marcel Date: Sat, 10 Sep 2005 18:25:53 +0000 Subject: [PATCH] Add a kluge to allow kgdb(1) to inject its own frame sniffer in the list of frame sniffers so that trapframes can be detected. The kluge is needed because this version of gdb only supports appending a sniffer to the list of sniffers and the moment kgdb gets a chance to add its own frame sniffer, the target's default frame sniffer is already in the list. Since the default frame sniffer claims any frame thrown at it, kgdb's frame sniffer never gets to smell (a process much akin to tasting, but with lesser chance of hurling :-) This commit adds dummy frame sniffers that never claim a frame and as such don't fix anything yet. However, we now have frame sniffers and they are being called, so it's just a matter of adding meat to the bones and we'll be able to properly unwind across trapframes. MFC after: 1 week --- gnu/usr.bin/gdb/kgdb/kgdb.h | 4 ++- gnu/usr.bin/gdb/kgdb/kthr.c | 1 + gnu/usr.bin/gdb/kgdb/main.c | 5 ++++ gnu/usr.bin/gdb/kgdb/trgt.c | 1 + gnu/usr.bin/gdb/kgdb/trgt_alpha.c | 31 ++++++++++++++++++++++-- gnu/usr.bin/gdb/kgdb/trgt_amd64.c | 31 ++++++++++++++++++++++-- gnu/usr.bin/gdb/kgdb/trgt_i386.c | 31 ++++++++++++++++++++++-- gnu/usr.bin/gdb/kgdb/trgt_ia64.c | 31 ++++++++++++++++++++++-- gnu/usr.bin/gdb/kgdb/trgt_sparc64.c | 31 ++++++++++++++++++++++-- gnu/usr.bin/gdb/libgdb/Makefile | 8 ++++-- gnu/usr.bin/gdb/libgdb/frame-unwind.diff | 27 +++++++++++++++++++++ 11 files changed, 188 insertions(+), 13 deletions(-) create mode 100644 gnu/usr.bin/gdb/libgdb/frame-unwind.diff diff --git a/gnu/usr.bin/gdb/kgdb/kgdb.h b/gnu/usr.bin/gdb/kgdb/kgdb.h index b545ebbe03c4..2103acdb082d 100644 --- a/gnu/usr.bin/gdb/kgdb/kgdb.h +++ b/gnu/usr.bin/gdb/kgdb/kgdb.h @@ -29,7 +29,7 @@ #ifndef _KGDB_H_ #define _KGDB_H_ -struct thread_info; +struct thread_info; extern kvm_t *kvm; extern int verbose; @@ -50,6 +50,8 @@ void kgdb_target(void); void kgdb_trgt_fetch_registers(int); void kgdb_trgt_store_registers(int); +frame_unwind_sniffer_ftype kgdb_trgt_trapframe_sniffer; + struct kthr *kgdb_thr_first(void); struct kthr *kgdb_thr_init(void); struct kthr *kgdb_thr_lookup_tid(int); diff --git a/gnu/usr.bin/gdb/kgdb/kthr.c b/gnu/usr.bin/gdb/kgdb/kthr.c index 505605d406a3..9156f1a9cf66 100644 --- a/gnu/usr.bin/gdb/kgdb/kthr.c +++ b/gnu/usr.bin/gdb/kgdb/kthr.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "kgdb.h" diff --git a/gnu/usr.bin/gdb/kgdb/main.c b/gnu/usr.bin/gdb/kgdb/main.c index 856cb93411f9..b07328cf8e91 100644 --- a/gnu/usr.bin/gdb/kgdb/main.c +++ b/gnu/usr.bin/gdb/kgdb/main.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); /* libgdb stuff. */ #include #include +#include #include #include #include @@ -61,6 +62,8 @@ __FBSDID("$FreeBSD$"); extern void (*init_ui_hook)(char *); +extern frame_unwind_sniffer_ftype *kgdb_sniffer_kluge; + extern void symbol_file_add_main (char *args, int from_tty); #include "kgdb.h" @@ -478,5 +481,7 @@ main(int argc, char *argv[]) init_ui_hook = kgdb_init; + kgdb_sniffer_kluge = kgdb_trgt_trapframe_sniffer; + return (gdb_main(&args)); } diff --git a/gnu/usr.bin/gdb/kgdb/trgt.c b/gnu/usr.bin/gdb/kgdb/trgt.c index 87487ce764d9..dac66c4dc350 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt.c +++ b/gnu/usr.bin/gdb/kgdb/trgt.c @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include diff --git a/gnu/usr.bin/gdb/kgdb/trgt_alpha.c b/gnu/usr.bin/gdb/kgdb/trgt_alpha.c index 336970ba2be6..c63c005b6202 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt_alpha.c +++ b/gnu/usr.bin/gdb/kgdb/trgt_alpha.c @@ -33,13 +33,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include "kgdb.h" - #include #include #include #include #include +#include + +#include "kgdb.h" void kgdb_trgt_fetch_registers(int regno __unused) @@ -71,3 +72,29 @@ kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } + +static void +kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, + struct frame_id *this_id) +{ +} + +static void +kgdb_trgt_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) +{ +} + +static const struct frame_unwind kgdb_trgt_trapframe_unwind = { + UNKNOWN_FRAME, + &kgdb_trgt_trapframe_this_id, + &kgdb_trgt_trapframe_prev_register +}; + +const struct frame_unwind * +kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) +{ + + return (NULL); +} diff --git a/gnu/usr.bin/gdb/kgdb/trgt_amd64.c b/gnu/usr.bin/gdb/kgdb/trgt_amd64.c index 0907d0db5675..bd1558f0b3fa 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt_amd64.c +++ b/gnu/usr.bin/gdb/kgdb/trgt_amd64.c @@ -33,13 +33,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include "kgdb.h" - #include #include #include #include #include +#include + +#include "kgdb.h" void kgdb_trgt_fetch_registers(int regno __unused) @@ -71,3 +72,29 @@ kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } + +static void +kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, + struct frame_id *this_id) +{ +} + +static void +kgdb_trgt_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) +{ +} + +static const struct frame_unwind kgdb_trgt_trapframe_unwind = { + UNKNOWN_FRAME, + &kgdb_trgt_trapframe_this_id, + &kgdb_trgt_trapframe_prev_register +}; + +const struct frame_unwind * +kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) +{ + + return (NULL); +} diff --git a/gnu/usr.bin/gdb/kgdb/trgt_i386.c b/gnu/usr.bin/gdb/kgdb/trgt_i386.c index 96dad51fcffe..eb58df3e4baa 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt_i386.c +++ b/gnu/usr.bin/gdb/kgdb/trgt_i386.c @@ -33,13 +33,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include "kgdb.h" - #include #include #include #include #include +#include + +#include "kgdb.h" void kgdb_trgt_fetch_registers(int regno __unused) @@ -67,3 +68,29 @@ kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } + +static void +kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, + struct frame_id *this_id) +{ +} + +static void +kgdb_trgt_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) +{ +} + +static const struct frame_unwind kgdb_trgt_trapframe_unwind = { + UNKNOWN_FRAME, + &kgdb_trgt_trapframe_this_id, + &kgdb_trgt_trapframe_prev_register +}; + +const struct frame_unwind * +kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) +{ + + return (NULL); +} diff --git a/gnu/usr.bin/gdb/kgdb/trgt_ia64.c b/gnu/usr.bin/gdb/kgdb/trgt_ia64.c index bfceba4cd0aa..7d9e1194b386 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt_ia64.c +++ b/gnu/usr.bin/gdb/kgdb/trgt_ia64.c @@ -34,13 +34,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include "kgdb.h" - #include #include #include #include #include +#include + +#include "kgdb.h" void kgdb_trgt_fetch_registers(int regno __unused) @@ -131,3 +132,29 @@ kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } + +static void +kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, + struct frame_id *this_id) +{ +} + +static void +kgdb_trgt_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) +{ +} + +static const struct frame_unwind kgdb_trgt_trapframe_unwind = { + UNKNOWN_FRAME, + &kgdb_trgt_trapframe_this_id, + &kgdb_trgt_trapframe_prev_register +}; + +const struct frame_unwind * +kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) +{ + + return (NULL); +} diff --git a/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c b/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c index 17d8135fa7a9..d6dcd65a69b6 100644 --- a/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c +++ b/gnu/usr.bin/gdb/kgdb/trgt_sparc64.c @@ -34,16 +34,17 @@ __FBSDID("$FreeBSD$"); #include #include -#include "kgdb.h" - #include #include #include #include #include +#include #include #include +#include "kgdb.h" + void kgdb_trgt_fetch_registers(int regno __unused) { @@ -70,3 +71,29 @@ kgdb_trgt_store_registers(int regno __unused) { fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__); } + +static void +kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache, + struct frame_id *this_id) +{ +} + +static void +kgdb_trgt_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) +{ +} + +static const struct frame_unwind kgdb_trgt_trapframe_unwind = { + UNKNOWN_FRAME, + &kgdb_trgt_trapframe_this_id, + &kgdb_trgt_trapframe_prev_register +}; + +const struct frame_unwind * +kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame) +{ + + return (NULL); +} diff --git a/gnu/usr.bin/gdb/libgdb/Makefile b/gnu/usr.bin/gdb/libgdb/Makefile index e9e92cac200a..29598d3c2305 100644 --- a/gnu/usr.bin/gdb/libgdb/Makefile +++ b/gnu/usr.bin/gdb/libgdb/Makefile @@ -18,7 +18,7 @@ SRCS= annotate.c arch-utils.c auxv.c ax-gdb.c ax-general.c \ elfread.c environ.c eval.c event-loop.c event-top.c exec.c \ expprint.c \ f-exp.y f-lang.c f-typeprint.c f-valprint.c findvar.c \ - ${_fork_child} frame-base.c frame-unwind.c frame.c \ + ${_fork_child} frame-base.c frame-unwind-kluge.c frame.c \ gdb-events.c gdbarch.c gdbtypes.c gnu-v2-abi.c gnu-v3-abi.c \ hpacc-abi.c \ inf-loop.c infcall.c infcmd.c inflow.c ${_infptrace} infrun.c \ @@ -59,7 +59,11 @@ _infptrace= infptrace.c _inftarg= inftarg.c .endif -GENSRCS= version.c +GENSRCS= frame-unwind-kluge.c version.c + +frame-unwind-kluge.c: frame-unwind.diff + cat ${CNTRB_GDB}/gdb/frame-unwind.c > ${.TARGET} + patch ${.TARGET} ${.ALLSRC} version.c: echo '#include "version.h"' > ${.TARGET} diff --git a/gnu/usr.bin/gdb/libgdb/frame-unwind.diff b/gnu/usr.bin/gdb/libgdb/frame-unwind.diff new file mode 100644 index 000000000000..8143c55aeefe --- /dev/null +++ b/gnu/usr.bin/gdb/libgdb/frame-unwind.diff @@ -0,0 +1,27 @@ +$FreeBSD$ + +Index: frame-unwind.c +=================================================================== +RCS file: /home/ncvs/src/contrib/gdb/gdb/frame-unwind.c,v +retrieving revision 1.1.1.1 +diff -u -r1.1.1.1 frame-unwind.c +--- frame-unwind.c 20 Jun 2004 18:16:58 -0000 1.1.1.1 ++++ frame-unwind.c 10 Sep 2005 06:36:55 -0000 +@@ -27,6 +27,8 @@ + + static struct gdbarch_data *frame_unwind_data; + ++frame_unwind_sniffer_ftype *kgdb_sniffer_kluge; ++ + struct frame_unwind_table + { + frame_unwind_sniffer_ftype **sniffer; +@@ -49,6 +51,8 @@ + { + struct frame_unwind_table *table = XCALLOC (1, struct frame_unwind_table); + append_predicate (table, dummy_frame_sniffer); ++ if (kgdb_sniffer_kluge != NULL) ++ append_predicate (table, kgdb_sniffer_kluge); + return table; + } +