/* Target-dependent code for GNU/Linux i386.
- Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007
+ Free Software Foundation, Inc.
This file is part of GDB.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
#include "defs.h"
#include "gdbcore.h"
#include "inferior.h"
#include "osabi.h"
#include "reggroups.h"
-
+#include "dwarf2-frame.h"
#include "gdb_string.h"
#include "i386-tdep.h"
#include "i386-linux-tdep.h"
#include "glibc-tdep.h"
#include "solib-svr4.h"
+#include "symtab.h"
/* Return the name of register REG. */
#define LINUX_SIGTRAMP_INSN2 0xcd /* int */
#define LINUX_SIGTRAMP_OFFSET2 6
-static const unsigned char linux_sigtramp_code[] =
+static const gdb_byte linux_sigtramp_code[] =
{
LINUX_SIGTRAMP_INSN0, /* pop %eax */
LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
-/* If PC is in a sigtramp routine, return the address of the start of
- the routine. Otherwise, return 0. */
+/* If NEXT_FRAME unwinds into a sigtramp routine, return the address
+ of the start of the routine. Otherwise, return 0. */
static CORE_ADDR
-i386_linux_sigtramp_start (CORE_ADDR pc)
+i386_linux_sigtramp_start (struct frame_info *next_frame)
{
- unsigned char buf[LINUX_SIGTRAMP_LEN];
+ CORE_ADDR pc = frame_pc_unwind (next_frame);
+ gdb_byte buf[LINUX_SIGTRAMP_LEN];
/* We only recognize a signal trampoline if PC is at the start of
one of the three instructions. We optimize for finding the PC at
PC is not at the start of the instruction sequence, there will be
a few trailing readable bytes on the stack. */
- if (read_memory_nobpt (pc, (char *) buf, LINUX_SIGTRAMP_LEN) != 0)
+ if (!safe_frame_unwind_memory (next_frame, pc, buf, LINUX_SIGTRAMP_LEN))
return 0;
if (buf[0] != LINUX_SIGTRAMP_INSN0)
pc -= adjust;
- if (read_memory_nobpt (pc, (char *) buf, LINUX_SIGTRAMP_LEN) != 0)
+ if (!safe_frame_unwind_memory (next_frame, pc, buf, LINUX_SIGTRAMP_LEN))
return 0;
}
#define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
#define LINUX_RT_SIGTRAMP_OFFSET1 5
-static const unsigned char linux_rt_sigtramp_code[] =
+static const gdb_byte linux_rt_sigtramp_code[] =
{
LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
-/* If PC is in a RT sigtramp routine, return the address of the start
- of the routine. Otherwise, return 0. */
+/* If NEXT_FRAME unwinds into an RT sigtramp routine, return the
+ address of the start of the routine. Otherwise, return 0. */
static CORE_ADDR
-i386_linux_rt_sigtramp_start (CORE_ADDR pc)
+i386_linux_rt_sigtramp_start (struct frame_info *next_frame)
{
- unsigned char buf[LINUX_RT_SIGTRAMP_LEN];
+ CORE_ADDR pc = frame_pc_unwind (next_frame);
+ gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
/* We only recognize a signal trampoline if PC is at the start of
one of the two instructions. We optimize for finding the PC at
PC is not at the start of the instruction sequence, there will be
a few trailing readable bytes on the stack. */
- if (read_memory_nobpt (pc, (char *) buf, LINUX_RT_SIGTRAMP_LEN) != 0)
+ if (!safe_frame_unwind_memory (next_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
return 0;
if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
pc -= LINUX_RT_SIGTRAMP_OFFSET1;
- if (read_memory_nobpt (pc, (char *) buf, LINUX_RT_SIGTRAMP_LEN) != 0)
+ if (!safe_frame_unwind_memory (next_frame, pc, buf,
+ LINUX_RT_SIGTRAMP_LEN))
return 0;
}
return pc;
}
-/* Return whether the frame preciding NEXT_FRAME corresponds to a
+/* Return whether the frame preceding NEXT_FRAME corresponds to a
GNU/Linux sigtramp routine. */
static int
be part of the preceding function. This should always be sigaction,
__sigaction, or __libc_sigaction (all aliases to the same function). */
if (name == NULL || strstr (name, "sigaction") != NULL)
- return (i386_linux_sigtramp_start (pc) != 0
- || i386_linux_rt_sigtramp_start (pc) != 0);
+ return (i386_linux_sigtramp_start (next_frame) != 0
+ || i386_linux_rt_sigtramp_start (next_frame) != 0);
return (strcmp ("__restore", name) == 0
|| strcmp ("__restore_rt", name) == 0);
}
+/* Return one if the unwound PC from NEXT_FRAME is in a signal trampoline
+ which may have DWARF-2 CFI. */
+
+static int
+i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
+ struct frame_info *next_frame)
+{
+ CORE_ADDR pc = frame_pc_unwind (next_frame);
+ char *name;
+
+ find_pc_partial_function (pc, &name, NULL, NULL);
+
+ /* If a vsyscall DSO is in use, the signal trampolines may have these
+ names. */
+ if (name && (strcmp (name, "__kernel_sigreturn") == 0
+ || strcmp (name, "__kernel_rt_sigreturn") == 0))
+ return 1;
+
+ return 0;
+}
+
/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
{
CORE_ADDR pc;
CORE_ADDR sp;
- char buf[4];
+ gdb_byte buf[4];
frame_unwind_register (next_frame, I386_ESP_REGNUM, buf);
sp = extract_unsigned_integer (buf, 4);
- pc = i386_linux_sigtramp_start (frame_pc_unwind (next_frame));
+ pc = i386_linux_sigtramp_start (next_frame);
if (pc)
{
/* The sigcontext structure lives on the stack, right after
return sp;
}
- pc = i386_linux_rt_sigtramp_start (frame_pc_unwind (next_frame));
+ pc = i386_linux_rt_sigtramp_start (next_frame);
if (pc)
{
CORE_ADDR ucontext_addr;
return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
}
- error ("Couldn't recognize signal trampoline.");
+ error (_("Couldn't recognize signal trampoline."));
return 0;
}
tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
/* GNU/Linux uses SVR4-style shared libraries. */
+ set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
set_solib_svr4_fetch_link_map_offsets
(gdbarch, svr4_ilp32_fetch_link_map_offsets);
/* GNU/Linux uses the dynamic linker included in the GNU C Library. */
set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
+
+ dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
+
+ /* Enable TLS support. */
+ set_gdbarch_fetch_tls_load_module_address (gdbarch,
+ svr4_fetch_objfile_link_map);
}
/* Provide a prototype to silence -Wmissing-prototypes. */