gdb/doc:
[deliverable/binutils-gdb.git] / gdb / amd64-windows-tdep.c
index 0ed93680340c169d5d65362fb122d64e57dc95cb..528fbb6107b7e72a6b3284530763096741df66f4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2009-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "solib.h"
 #include "solib-target.h"
 #include "gdbtypes.h"
+#include "gdbcore.h"
+#include "regcache.h"
+#include "windows-tdep.h"
+#include "frame.h"
 
 /* The registers used to pass integer arguments during a function call.  */
 static int amd64_windows_dummy_call_integer_regs[] =
@@ -68,6 +72,124 @@ amd64_windows_classify (struct type *type, enum amd64_reg_class class[2])
     }
 }
 
+/* Implement the "return_value" gdbarch method for amd64-windows.  */
+
+static enum return_value_convention
+amd64_windows_return_value (struct gdbarch *gdbarch, struct value *function,
+                           struct type *type, struct regcache *regcache,
+                           gdb_byte *readbuf, const gdb_byte *writebuf)
+{
+  int len = TYPE_LENGTH (type);
+  int regnum = -1;
+
+  /* See if our value is returned through a register.  If it is, then
+     store the associated register number in REGNUM.  */
+  switch (TYPE_CODE (type))
+    {
+      case TYPE_CODE_FLT:
+      case TYPE_CODE_DECFLOAT:
+        /* __m128, __m128i, __m128d, floats, and doubles are returned
+           via XMM0.  */
+        if (len == 4 || len == 8 || len == 16)
+          regnum = AMD64_XMM0_REGNUM;
+        break;
+      default:
+        /* All other values that are 1, 2, 4 or 8 bytes long are returned
+           via RAX.  */
+        if (len == 1 || len == 2 || len == 4 || len == 8)
+          regnum = AMD64_RAX_REGNUM;
+        break;
+    }
+
+  if (regnum < 0)
+    {
+      /* RAX contains the address where the return value has been stored.  */
+      if (readbuf)
+        {
+         ULONGEST addr;
+
+         regcache_raw_read_unsigned (regcache, AMD64_RAX_REGNUM, &addr);
+         read_memory (addr, readbuf, TYPE_LENGTH (type));
+       }
+      return RETURN_VALUE_ABI_RETURNS_ADDRESS;
+    }
+  else
+    {
+      /* Extract the return value from the register where it was stored.  */
+      if (readbuf)
+       regcache_raw_read_part (regcache, regnum, 0, len, readbuf);
+      if (writebuf)
+       regcache_raw_write_part (regcache, regnum, 0, len, writebuf);
+      return RETURN_VALUE_REGISTER_CONVENTION;
+    }
+}
+
+/* Check that the code pointed to by PC corresponds to a call to
+   __main, skip it if so.  Return PC otherwise.  */
+
+static CORE_ADDR
+amd64_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+  gdb_byte op;
+
+  target_read_memory (pc, &op, 1);
+  if (op == 0xe8)
+    {
+      gdb_byte buf[4];
+
+      if (target_read_memory (pc + 1, buf, sizeof buf) == 0)
+       {
+         struct minimal_symbol *s;
+         CORE_ADDR call_dest;
+
+         call_dest = pc + 5 + extract_signed_integer (buf, 4, byte_order);
+         s = lookup_minimal_symbol_by_pc (call_dest);
+         if (s != NULL
+             && SYMBOL_LINKAGE_NAME (s) != NULL
+             && strcmp (SYMBOL_LINKAGE_NAME (s), "__main") == 0)
+           pc += 5;
+       }
+    }
+
+  return pc;
+}
+
+/* Check Win64 DLL jmp trampolines and find jump destination.  */
+
+static CORE_ADDR
+amd64_windows_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
+{
+  CORE_ADDR destination = 0;
+  struct gdbarch *gdbarch = get_frame_arch (frame);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+
+  /* Check for jmp *<offset>(%rip) (jump near, absolute indirect (/4)).  */
+  if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
+    {
+      /* Get opcode offset and see if we can find a reference in our data.  */
+      ULONGEST offset
+       = read_memory_unsigned_integer (pc + 2, 4, byte_order);
+
+      /* Get address of function pointer at end of pc.  */
+      CORE_ADDR indirect_addr = pc + offset + 6;
+
+      struct minimal_symbol *indsym
+       = indirect_addr ? lookup_minimal_symbol_by_pc (indirect_addr) : NULL;
+      const char *symname = indsym ? SYMBOL_LINKAGE_NAME (indsym) : NULL;
+
+      if (symname)
+       {
+         if (strncmp (symname, "__imp_", 6) == 0
+             || strncmp (symname, "_imp_", 5) == 0)
+           destination
+             = read_memory_unsigned_integer (indirect_addr, 8, byte_order);
+       }
+    }
+
+  return destination;
+}
+
 static void
 amd64_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
 {
@@ -84,10 +206,21 @@ amd64_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->call_dummy_integer_regs = amd64_windows_dummy_call_integer_regs;
   tdep->classify = amd64_windows_classify;
   tdep->memory_args_by_pointer = 1;
+  tdep->integer_param_regs_saved_in_caller_frame = 1;
+  set_gdbarch_return_value (gdbarch, amd64_windows_return_value);
+  set_gdbarch_skip_main_prologue (gdbarch, amd64_skip_main_prologue);
+  set_gdbarch_skip_trampoline_code (gdbarch,
+                                   amd64_windows_skip_trampoline_code);
+
+  set_gdbarch_iterate_over_objfiles_in_search_order
+    (gdbarch, windows_iterate_over_objfiles_in_search_order);
 
   set_solib_ops (gdbarch, &solib_target_so_ops);
 }
 
+/* -Wmissing-prototypes */
+extern initialize_file_ftype _initialize_amd64_windows_tdep;
+
 void
 _initialize_amd64_windows_tdep (void)
 {
This page took 0.02582 seconds and 4 git commands to generate.