From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29572 invoked by alias); 16 Mar 2012 09:56:40 -0000 Received: (qmail 29559 invoked by uid 22791); 16 Mar 2012 09:56:39 -0000 X-SWARE-Spam-Status: No, hits=0.4 required=5.0 tests=AWL,BAYES_40,KAM_STOCKGEN X-Spam-Check-By: sourceware.org Received: from outdoor.onevision.de (HELO outdoor.onevision.de) (212.77.172.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Mar 2012 09:56:25 +0000 Received: from sanders.onevision.de (moonrace [212.77.172.62]) by outdoor.onevision.de (8.14.3/8.13.7/ROSCH/DDB) with ESMTP id q2G9uHSk011772 for ; Fri, 16 Mar 2012 10:56:22 +0100 Received: from [192.168.5.32] ([192.168.5.32]) by sanders.onevision.de (Lotus Domino Release 8.5.1FP3) with ESMTP id 2012031610561239-117342 ; Fri, 16 Mar 2012 10:56:12 +0100 Message-ID: <4F630E3C.8010006@onevision.com> Date: Fri, 16 Mar 2012 09:56:00 -0000 From: Roland Schwingel User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: [PATCH v3] Add dll trampoline code handling for windows 64bit Content-Type: multipart/mixed; boundary="------------000201080003010607030505" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-03/txt/msg00593.txt.bz2 This is a multi-part message in MIME format. --------------000201080003010607030505 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-length: 908 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 * amd64-windows-tdep.c: #include "frame.h". (amd64_windows_skip_trampoline_code): New function. (amd64_windows_init_abi): Add trampoline registration. Roland --------------000201080003010607030505 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="amd64-windows-tdep.c.patch" Content-Disposition: attachment; filename="amd64-windows-tdep.c.patch" Content-length: 1999 --- 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 *(%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. */ --------------000201080003010607030505--