Fix -Wuninitialized warnings.
[deliverable/binutils-gdb.git] / gdb / arm-linux-tdep.c
index 667fd0bd18c63dc89c8315a59d6fa60cfd25b0b4..f50f7121f49ddcc7f2929f67993a5ae94afb0d30 100644 (file)
 #include "value.h"
 #include "gdbtypes.h"
 #include "floatformat.h"
+#include "gdbcore.h"
+#include "frame.h"
+
+/* For arm_linux_skip_solib_resolver.  */
+#include "symtab.h"
+#include "symfile.h"
+#include "objfiles.h"
 
 #ifdef GET_LONGJMP_TARGET
 
@@ -340,13 +347,174 @@ arm_linux_push_arguments (int nargs, value_ptr * args, CORE_ADDR sp,
    with.  Before the fixup/resolver code returns, it actually calls
    the requested function and repairs &GOT[n+3].  */
 
+/* Find the minimal symbol named NAME, and return both the minsym
+   struct and its objfile.  This probably ought to be in minsym.c, but
+   everything there is trying to deal with things like C++ and
+   SOFUN_ADDRESS_MAYBE_TURQUOISE, ...  Since this is so simple, it may
+   be considered too special-purpose for general consumption.  */
+
+static struct minimal_symbol *
+find_minsym_and_objfile (char *name, struct objfile **objfile_p)
+{
+  struct objfile *objfile;
+
+  ALL_OBJFILES (objfile)
+    {
+      struct minimal_symbol *msym;
+
+      ALL_OBJFILE_MSYMBOLS (objfile, msym)
+       {
+         if (SYMBOL_NAME (msym)
+             && STREQ (SYMBOL_NAME (msym), name))
+           {
+             *objfile_p = objfile;
+             return msym;
+           }
+       }
+    }
+
+  return 0;
+}
+
+
+static CORE_ADDR
+skip_hurd_resolver (CORE_ADDR pc)
+{
+  /* The HURD dynamic linker is part of the GNU C library, so many
+     GNU/Linux distributions use it.  (All ELF versions, as far as I
+     know.)  An unresolved PLT entry points to "_dl_runtime_resolve",
+     which calls "fixup" to patch the PLT, and then passes control to
+     the function.
+
+     We look for the symbol `_dl_runtime_resolve', and find `fixup' in
+     the same objfile.  If we are at the entry point of `fixup', then
+     we set a breakpoint at the return address (at the top of the
+     stack), and continue.
+  
+     It's kind of gross to do all these checks every time we're
+     called, since they don't change once the executable has gotten
+     started.  But this is only a temporary hack --- upcoming versions
+     of Linux will provide a portable, efficient interface for
+     debugging programs that use shared libraries.  */
+
+  struct objfile *objfile;
+  struct minimal_symbol *resolver 
+    = find_minsym_and_objfile ("_dl_runtime_resolve", &objfile);
+
+  if (resolver)
+    {
+      struct minimal_symbol *fixup
+       = lookup_minimal_symbol ("fixup", 0, objfile);
+
+      if (fixup && SYMBOL_VALUE_ADDRESS (fixup) == pc)
+       return (SAVED_PC_AFTER_CALL (get_current_frame ()));
+    }
+
+  return 0;
+}      
+
+/* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c.
+   This function:
+   1) decides whether a PLT has sent us into the linker to resolve
+      a function reference, and 
+   2) if so, tells us where to set a temporary breakpoint that will
+      trigger when the dynamic linker is done.  */
+
 CORE_ADDR
-arm_skip_solib_resolver (CORE_ADDR pc)
+arm_linux_skip_solib_resolver (CORE_ADDR pc)
 {
-  /* FIXME */
+  CORE_ADDR result;
+
+  /* Plug in functions for other kinds of resolvers here.  */
+  result = skip_hurd_resolver (pc);
+
+  if (result)
+    return result;
+  
   return 0;
 }
 
+/* The constants below were determined by examining the following files
+   in the linux kernel sources:
+
+      arch/arm/kernel/signal.c
+         - see SWI_SYS_SIGRETURN and SWI_SYS_RT_SIGRETURN
+      include/asm-arm/unistd.h
+         - see __NR_sigreturn, __NR_rt_sigreturn, and __NR_SYSCALL_BASE */
+
+#define ARM_LINUX_SIGRETURN_INSTR      0xef900077
+#define ARM_LINUX_RT_SIGRETURN_INSTR   0xef9000ad
+
+/* arm_linux_in_sigtramp determines if PC points at one of the
+   instructions which cause control to return to the Linux kernel upon
+   return from a signal handler.  FUNC_NAME is unused.  */
+
+int
+arm_linux_in_sigtramp (CORE_ADDR pc, char *func_name)
+{
+  unsigned long inst;
+
+  inst = read_memory_integer (pc, 4);
+
+  return (inst == ARM_LINUX_SIGRETURN_INSTR
+         || inst == ARM_LINUX_RT_SIGRETURN_INSTR);
+
+}
+
+/* arm_linux_sigcontext_register_address returns the address in the
+   sigcontext of register REGNO given a stack pointer value SP and
+   program counter value PC.  The value 0 is returned if PC is not
+   pointing at one of the signal return instructions or if REGNO is
+   not saved in the sigcontext struct.  */
+
+CORE_ADDR
+arm_linux_sigcontext_register_address (CORE_ADDR sp, CORE_ADDR pc, int regno)
+{
+  unsigned long inst;
+  CORE_ADDR reg_addr = 0;
+
+  inst = read_memory_integer (pc, 4);
+
+  if (inst == ARM_LINUX_SIGRETURN_INSTR || inst == ARM_LINUX_RT_SIGRETURN_INSTR)
+    {
+      CORE_ADDR sigcontext_addr;
+
+      /* The sigcontext structure is at different places for the two
+         signal return instructions.  For ARM_LINUX_SIGRETURN_INSTR,
+        it starts at the SP value.  For ARM_LINUX_RT_SIGRETURN_INSTR,
+        it is at SP+8.  For the latter instruction, it may also be
+        the case that the address of this structure may be determined
+        by reading the 4 bytes at SP, but I'm not convinced this is
+        reliable.
+
+        In any event, these magic constants (0 and 8) may be
+        determined by examining struct sigframe and struct
+        rt_sigframe in arch/arm/kernel/signal.c in the Linux kernel
+        sources.  */
+
+      if (inst == ARM_LINUX_RT_SIGRETURN_INSTR)
+       sigcontext_addr = sp + 8;
+      else /* inst == ARM_LINUX_SIGRETURN_INSTR */
+        sigcontext_addr = sp + 0;
+
+      /* The layout of the sigcontext structure for ARM GNU/Linux is
+         in include/asm-arm/sigcontext.h in the Linux kernel sources.
+
+        There are three 4-byte fields which precede the saved r0
+        field.  (This accounts for the 12 in the code below.)  The
+        sixteen registers (4 bytes per field) follow in order.  The
+        PSR value follows the sixteen registers which accounts for
+        the constant 19 below. */
+
+      if (0 <= regno && regno <= PC_REGNUM)
+       reg_addr = sigcontext_addr + 12 + (4 * regno);
+      else if (regno == PS_REGNUM)
+       reg_addr = sigcontext_addr + 19 * 4;
+    }
+
+  return reg_addr;
+}
+
 void
 _initialize_arm_linux_tdep (void)
 {
This page took 0.024868 seconds and 4 git commands to generate.