diff options
author | Jason Thorpe <thorpej@netbsd.org> | 2002-09-02 16:35:14 +0000 |
---|---|---|
committer | Jason Thorpe <thorpej@netbsd.org> | 2002-09-02 16:35:14 +0000 |
commit | d66198e1a79726cf2c4eac8cb9e9b25b40a928e6 (patch) | |
tree | dcd11dfabbeff1378bcae42abc421aac3d4fda97 | |
parent | 3e369e968e378f3025ec2a98382869b4d70f17fb (diff) | |
download | gdb-d66198e1a79726cf2c4eac8cb9e9b25b40a928e6.zip gdb-d66198e1a79726cf2c4eac8cb9e9b25b40a928e6.tar.gz gdb-d66198e1a79726cf2c4eac8cb9e9b25b40a928e6.tar.bz2 |
* i386nbsd-tdep.c (i386nbsd_sigtramp_offset): New function.
(i386nbsd_pc_in_sigtramp): Rewrite to use i386nbsd_sigtramp_offset.
(i386nbsd_init_abi): Don't initialize tdep->sigtramp_start or
tdep->sigtramp_end.
(i386nbsd_sigtramp_start, i386nbsd_sigtramp_end): Remove.
* config/i386/tm-nbsd.h (SIGTRAMP_START, SIGTRAMP_END)
(i386bsd_sigtramp_start, i386bsd_sigtramp_end): Remove.
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/config/i386/tm-nbsd.h | 12 | ||||
-rw-r--r-- | gdb/i386nbsd-tdep.c | 104 |
3 files changed, 99 insertions, 27 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index da5ebb6..c3ab7b0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2002-09-02 Jason Thorpe <thorpej@wasabisystems.com> + * i386nbsd-tdep.c (i386nbsd_sigtramp_offset): New function. + (i386nbsd_pc_in_sigtramp): Rewrite to use i386nbsd_sigtramp_offset. + (i386nbsd_init_abi): Don't initialize tdep->sigtramp_start or + tdep->sigtramp_end. + (i386nbsd_sigtramp_start, i386nbsd_sigtramp_end): Remove. + * config/i386/tm-nbsd.h (SIGTRAMP_START, SIGTRAMP_END) + (i386bsd_sigtramp_start, i386bsd_sigtramp_end): Remove. + +2002-09-02 Jason Thorpe <thorpej@wasabisystems.com> + * Makefile.in (i386nbsd-tdep.o): Add $(arch_utils_h), $(i386_tdep_h), and $(nbsd_tdep_h) to dependency list. * i386-tdep.h (i386bsd_init_abi): New prototype. diff --git a/gdb/config/i386/tm-nbsd.h b/gdb/config/i386/tm-nbsd.h index 0d73d3a..d7c79d7 100644 --- a/gdb/config/i386/tm-nbsd.h +++ b/gdb/config/i386/tm-nbsd.h @@ -23,16 +23,4 @@ #include "i386/tm-i386.h" -/* These defines allow the recognition of sigtramps as a function name - <sigtramp>. - - FIXME: kettenis/2002-05-12: Of course these defines will have to go - if we go truly "multi-arch", but I don't know yet how to get rid of - them. */ - -#define SIGTRAMP_START(pc) i386bsd_sigtramp_start (pc) -#define SIGTRAMP_END(pc) i386bsd_sigtramp_end (pc) -extern CORE_ADDR i386bsd_sigtramp_start (CORE_ADDR pc); -extern CORE_ADDR i386bsd_sigtramp_end (CORE_ADDR pc); - #endif /* TM_NBSD_H */ diff --git a/gdb/i386nbsd-tdep.c b/gdb/i386nbsd-tdep.c index cba2f19..dccd5cd 100644 --- a/gdb/i386nbsd-tdep.c +++ b/gdb/i386nbsd-tdep.c @@ -140,23 +140,101 @@ static struct core_fns i386nbsd_elfcore_fns = NULL /* next */ }; -static int -i386nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name) +/* Under NetBSD/i386, signal handler invocations can be identified by the + designated code sequence that is used to return from a signal handler. + In particular, the return address of a signal handler points to the + following code sequence: + + leal 0x10(%esp), %eax + pushl %eax + pushl %eax + movl $0x127, %eax # __sigreturn14 + int $0x80 + + Each instruction has a unique encoding, so we simply attempt to match + the instruction the PC is pointing to with any of the above instructions. + If there is a hit, we know the offset to the start of the designated + sequence and can then check whether we really are executing in the + signal trampoline. If not, -1 is returned, otherwise the offset from the + start of the return sequence is returned. */ +#define RETCODE_INSN1 0x8d +#define RETCODE_INSN2 0x50 +#define RETCODE_INSN3 0x50 +#define RETCODE_INSN4 0xb8 +#define RETCODE_INSN5 0xcd + +#define RETCODE_INSN2_OFF 4 +#define RETCODE_INSN3_OFF 5 +#define RETCODE_INSN4_OFF 6 +#define RETCODE_INSN5_OFF 11 + +static const unsigned char sigtramp_retcode[] = { - struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + RETCODE_INSN1, 0x44, 0x24, 0x10, + RETCODE_INSN2, + RETCODE_INSN3, + RETCODE_INSN4, 0x27, 0x01, 0x00, 0x00, + RETCODE_INSN5, 0x80, +}; + +static LONGEST +i386nbsd_sigtramp_offset (CORE_ADDR pc) +{ + unsigned char ret[sizeof(sigtramp_retcode)], insn; + LONGEST off; + int i; + + if (read_memory_nobpt (pc, &insn, 1) != 0) + return -1; + + switch (insn) + { + case RETCODE_INSN1: + off = 0; + break; + + case RETCODE_INSN2: + /* INSN2 and INSN3 are the same. Read at the location of PC+1 + to determine if we're actually looking at INSN2 or INSN3. */ + if (read_memory_nobpt (pc + 1, &insn, 1) != 0) + return -1; + + if (insn == RETCODE_INSN3) + off = RETCODE_INSN2_OFF; + else + off = RETCODE_INSN3_OFF; + break; - /* Check for libc-provided signal trampoline. */ - if (nbsd_pc_in_sigtramp (pc, name)) - return 1; + case RETCODE_INSN4: + off = RETCODE_INSN4_OFF; + break; + + case RETCODE_INSN5: + off = RETCODE_INSN5_OFF; + break; + + default: + return -1; + } + + pc -= off; - /* FIXME: sigtramp_start/sigtramp_end need to go away; we should - not be assuming the location of the kernel-provided trampoline! */ + if (read_memory_nobpt (pc, (char *) ret, sizeof (ret)) != 0) + return -1; - return (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end); + if (memcmp (ret, sigtramp_retcode, sizeof (ret)) == 0) + return off; + + return -1; } -CORE_ADDR i386nbsd_sigtramp_start = 0xbfbfdf20; -CORE_ADDR i386nbsd_sigtramp_end = 0xbfbfdff0; +static int +i386nbsd_pc_in_sigtramp (CORE_ADDR pc, char *name) +{ + + return (nbsd_pc_in_sigtramp (pc, name) + || i386nbsd_sigtramp_offset (pc) >= 0); +} /* From <machine/signal.h>. */ int i386nbsd_sc_pc_offset = 44; @@ -176,10 +254,6 @@ i386nbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) /* NetBSD uses -freg-struct-return by default. */ tdep->struct_return = reg_struct_return; - /* NetBSD uses a different memory layout. */ - tdep->sigtramp_start = i386nbsd_sigtramp_start; - tdep->sigtramp_end = i386nbsd_sigtramp_end; - /* NetBSD has a `struct sigcontext' that's different from the origional 4.3 BSD. */ tdep->sc_pc_offset = i386nbsd_sc_pc_offset; |