From 1196bfdaf9becb2a90e01bec41fc18b24affad38 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Wed, 24 Mar 2004 23:14:39 +0000 Subject: [PATCH] 2004-03-24 Andrew Cagney * tramp-frame.h (TRAMP_SENTINEL_INSN): Define, document. * tramp-frame.c: Include "gdb_assert.h". (tramp_frame_start): Use TRAMP_SENTINEL_INSN. Use ULONGEST and correct sizeof. (tramp_frame_append): Validate the tramp frame's instructions. * Makefile.in (tramp-frame.o): Update dependencies. --- gdb/ChangeLog | 9 +++++++++ gdb/tramp-frame.c | 19 +++++++++++++++---- gdb/tramp-frame.h | 7 ++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 312afc385e1..512129ef358 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2004-03-24 Andrew Cagney + + * tramp-frame.h (TRAMP_SENTINEL_INSN): Define, document. + * tramp-frame.c: Include "gdb_assert.h". + (tramp_frame_start): Use TRAMP_SENTINEL_INSN. Use ULONGEST and + correct sizeof. + (tramp_frame_append): Validate the tramp frame's instructions. + * Makefile.in (tramp-frame.o): Update dependencies. + 2004-03-23 Andrew Cagney * trad-frame.h (trad_frame_set_reg_addr): Declare. diff --git a/gdb/tramp-frame.c b/gdb/tramp-frame.c index 7a8057e85e1..ee3635f743b 100644 --- a/gdb/tramp-frame.c +++ b/gdb/tramp-frame.c @@ -28,6 +28,7 @@ #include "target.h" #include "trad-frame.h" #include "frame-base.h" +#include "gdb_assert.h" struct frame_data { @@ -89,15 +90,15 @@ tramp_frame_start (CORE_ADDR pc, const struct tramp_frame *tramp) int ti; /* Search through the trampoline for one that matches the instruction sequence around PC. */ - for (ti = 0; tramp->insn[ti] != 0; ti++) + for (ti = 0; tramp->insn[ti] != TRAMP_SENTINEL_INSN; ti++) { CORE_ADDR func = pc - tramp->insn_size * ti; int i; for (i = 0; 1; i++) { - bfd_byte buf[sizeof (LONGEST)]; - CORE_ADDR insn; - if (tramp->insn[i] == 0) + bfd_byte buf[sizeof (tramp->insn[0])]; + ULONGEST insn; + if (tramp->insn[i] == TRAMP_SENTINEL_INSN) return func; if (target_read_memory (func + i * tramp->insn_size, buf, tramp->insn_size) != 0) @@ -148,6 +149,16 @@ tramp_frame_append (struct gdbarch *gdbarch, { struct frame_data *data; struct frame_unwind *unwinder; + int i; + + /* Check that the instruction sequence contains a sentinel. */ + for (i = 0; i < ARRAY_SIZE (tramp_frame->insn); i++) + { + if (tramp_frame->insn[i] == TRAMP_SENTINEL_INSN) + break; + } + gdb_assert (i < ARRAY_SIZE (tramp_frame->insn)); + gdb_assert (tramp_frame->insn_size <= sizeof (tramp_frame->insn[0])); data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_data); unwinder = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind); diff --git a/gdb/tramp-frame.h b/gdb/tramp-frame.h index 44e266eaab6..54f29bbca54 100644 --- a/gdb/tramp-frame.h +++ b/gdb/tramp-frame.h @@ -39,6 +39,10 @@ struct trad_frame_cache; /* A trampoline descriptor. */ +/* Magic instruction that to mark the end of the signal trampoline + instruction sequence. */ +#define TRAMP_SENTINEL_INSN ((LONGEST) -1) + struct tramp_frame { /* The trampoline's entire instruction sequence. Search for this in @@ -47,7 +51,8 @@ struct tramp_frame one INSN_SIZE instruction. It is also assumed that TRAMP[0] contains the first instruction of the trampoline and hence the address of the instruction matching TRAMP[0] is the trampoline's - "func" address. */ + "func" address. The instruction sequence shall be terminated by + TRAMP_SENTINEL_INSN. */ int insn_size; ULONGEST insn[8]; /* Initialize a trad-frame cache corresponding to the tramp-frame. -- 2.30.2