Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Roland Schwingel <roland@onevision.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v3] Add dll trampoline code handling for windows 64bit
Date: Fri, 16 Mar 2012 09:56:00 -0000	[thread overview]
Message-ID: <4F630E3C.8010006@onevision.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

Hi,

I hope this is the last round on this...

 > Kai Tietz read this patch -- he says "hello" and asked me to respond.
 >
 > Roland> +      struct minimal_symbol *indsym =
 > Roland> +        indirect ? lookup_minimal_symbol_by_pc (pc + 
indirect) : 0;
 >
 > Kai says that PC-relative expressions are relative to the end of the
 > instruction.  So, 'pc + indirect' is incorrect here and also in the
 > read_memory call.
Oh man! I couldn't see the forest for the trees.
While my previous approach was in the end correctly working this is
the cleaner solution. That way read_memory_unsigned_integer()
can be used now, delivering correct results.

ChangeLog:

2012-03-16  Roland Schwingel <roland.schwingel@onevision.com>

         * amd64-windows-tdep.c: #include "frame.h".
         (amd64_windows_skip_trampoline_code): New function.
         (amd64_windows_init_abi): Add trampoline registration.

Roland


[-- Attachment #2: amd64-windows-tdep.c.patch --]
[-- Type: text/plain, Size: 1999 bytes --]

--- amd64-windows-tdep.c_orig	2012-03-02 01:06:12.000000000 +0100
+++ amd64-windows-tdep.c	2012-03-16 10:35:22.863279100 +0100
@@ -23,6 +23,7 @@
 #include "gdbtypes.h"
 #include "gdbcore.h"
 #include "regcache.h"
+#include "frame.h"
 
 /* The registers used to pass integer arguments during a function call.  */
 static int amd64_windows_dummy_call_integer_regs[] =
@@ -153,12 +154,49 @@
   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) : 0;
+      const char *symname = indsym ? SYMBOL_LINKAGE_NAME (indsym) : 0;
+
+      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)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
 
+  /* register trampoline handling code.  */
+  set_gdbarch_skip_trampoline_code (gdbarch, amd64_windows_skip_trampoline_code);
+
   amd64_init_abi (info, gdbarch);
 
   /* On Windows, "long"s are only 32bit.  */

             reply	other threads:[~2012-03-16  9:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16  9:56 Roland Schwingel [this message]
2012-03-29 18:21 ` Joel Brobecker
2012-03-30  6:47 Roland Schwingel
2012-03-30  9:15 ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F630E3C.8010006@onevision.com \
    --to=roland@onevision.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox