--- amd64-windows-tdep.c_orig 2012-03-02 01:06:12.000000000 +0100 +++ amd64-windows-tdep.c 2012-03-15 15:37:45.647047400 +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,65 @@ 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 indirect = + read_memory_unsigned_integer (pc + 2, 4, byte_order); + struct minimal_symbol *indsym = + indirect ? lookup_minimal_symbol_by_pc (pc + indirect) : 0; + const char *symname = indsym ? SYMBOL_LINKAGE_NAME (indsym) : 0; + + if (symname) + { + if (strncmp (symname, "__imp_", 6) == 0 + || strncmp (symname, "_imp_", 5) == 0) + { + gdb_byte *pos,addr[8]; + + read_memory(pc + indirect, addr, 8); + /* The data fetched from the inferior is in this + case not little endian, 2 bytes from the + beginning are rotated to the end. + Example: + function pointer expected in little endian: + 0xba7b021500000000 + pointer fetched from inferior: + 0x021500000000ba7b + So I do byteswapping here on my own. */ + pos = (gdb_byte *)&destination; + pos[0] = addr[6]; + pos[1] = addr[7]; + pos[2] = addr[0]; + pos[3] = addr[1]; + pos[4] = addr[2]; + pos[5] = addr[3]; + pos[6] = addr[4]; + pos[7] = addr[5]; + } + } + } + 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. */