*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / i386-linux-tdep.c
index 2733b5f4df5e736b76a351a331546505299e5940..97dda8248d887f49e49dc597f5429017425720f0 100644 (file)
@@ -1,6 +1,7 @@
 /* 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
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -16,8 +17,8 @@
 
    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"
@@ -27,7 +28,7 @@
 #include "inferior.h"
 #include "osabi.h"
 #include "reggroups.h"
-
+#include "dwarf2-frame.h"
 #include "gdb_string.h"
 
 #include "i386-tdep.h"
@@ -106,7 +107,7 @@ i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 #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 */
@@ -115,13 +116,14 @@ static const unsigned char linux_sigtramp_code[] =
 
 #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
@@ -130,7 +132,7 @@ i386_linux_sigtramp_start (CORE_ADDR pc)
      PC is not at the start of the instruction sequence, there will be
      a few trailing readable bytes on the stack.  */
 
-  if (deprecated_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)
@@ -151,7 +153,7 @@ i386_linux_sigtramp_start (CORE_ADDR pc)
 
       pc -= adjust;
 
-      if (deprecated_read_memory_nobpt (pc, (char *) buf, LINUX_SIGTRAMP_LEN) != 0)
+      if (!safe_frame_unwind_memory (next_frame, pc, buf, LINUX_SIGTRAMP_LEN))
        return 0;
     }
 
@@ -174,7 +176,7 @@ i386_linux_sigtramp_start (CORE_ADDR pc)
 #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 */
@@ -182,13 +184,14 @@ static const unsigned char linux_rt_sigtramp_code[] =
 
 #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
@@ -197,7 +200,7 @@ i386_linux_rt_sigtramp_start (CORE_ADDR pc)
      PC is not at the start of the instruction sequence, there will be
      a few trailing readable bytes on the stack.  */
 
-  if (deprecated_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)
@@ -207,7 +210,8 @@ i386_linux_rt_sigtramp_start (CORE_ADDR pc)
 
       pc -= LINUX_RT_SIGTRAMP_OFFSET1;
 
-      if (deprecated_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;
     }
 
@@ -234,13 +238,34 @@ i386_linux_sigtramp_p (struct frame_info *next_frame)
      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
 
@@ -252,12 +277,12 @@ i386_linux_sigcontext_addr (struct frame_info *next_frame)
 {
   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
@@ -271,7 +296,7 @@ i386_linux_sigcontext_addr (struct frame_info *next_frame)
       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;
@@ -284,7 +309,7 @@ i386_linux_sigcontext_addr (struct frame_info *next_frame)
       return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
     }
 
-  error ("Couldn't recognize signal trampoline.");
+  error (_("Couldn't recognize signal trampoline."));
   return 0;
 }
 
@@ -411,6 +436,12 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 
   /* 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.  */
This page took 0.026589 seconds and 4 git commands to generate.