1 /* Copyright (C) 2009-2013 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "amd64-tdep.h"
22 #include "solib-target.h"
26 #include "windows-tdep.h"
29 #include "frame-unwind.h"
30 #include "coff/internal.h"
31 #include "coff/i386.h"
35 /* The registers used to pass integer arguments during a function call. */
36 static int amd64_windows_dummy_call_integer_regs
[] =
38 AMD64_RCX_REGNUM
, /* %rcx */
39 AMD64_RDX_REGNUM
, /* %rdx */
44 /* Implement the "classify" method in the gdbarch_tdep structure
48 amd64_windows_classify (struct type
*type
, enum amd64_reg_class
class[2])
50 switch (TYPE_CODE (type
))
53 /* Arrays are always passed by memory. */
54 class[0] = class[1] = AMD64_MEMORY
;
57 case TYPE_CODE_STRUCT
:
59 /* Struct/Union types whose size is 1, 2, 4, or 8 bytes
60 are passed as if they were integers of the same size.
61 Types of different sizes are passed by memory. */
62 if (TYPE_LENGTH (type
) == 1
63 || TYPE_LENGTH (type
) == 2
64 || TYPE_LENGTH (type
) == 4
65 || TYPE_LENGTH (type
) == 8)
67 class[0] = AMD64_INTEGER
;
68 class[1] = AMD64_NO_CLASS
;
71 class[0] = class[1] = AMD64_MEMORY
;
75 /* For all the other types, the conventions are the same as
76 with the System V ABI. */
77 amd64_classify (type
, class);
81 /* Implement the "return_value" gdbarch method for amd64-windows. */
83 static enum return_value_convention
84 amd64_windows_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
85 struct type
*type
, struct regcache
*regcache
,
86 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
88 int len
= TYPE_LENGTH (type
);
91 /* See if our value is returned through a register. If it is, then
92 store the associated register number in REGNUM. */
93 switch (TYPE_CODE (type
))
96 case TYPE_CODE_DECFLOAT
:
97 /* __m128, __m128i, __m128d, floats, and doubles are returned
99 if (len
== 4 || len
== 8 || len
== 16)
100 regnum
= AMD64_XMM0_REGNUM
;
103 /* All other values that are 1, 2, 4 or 8 bytes long are returned
105 if (len
== 1 || len
== 2 || len
== 4 || len
== 8)
106 regnum
= AMD64_RAX_REGNUM
;
112 /* RAX contains the address where the return value has been stored. */
117 regcache_raw_read_unsigned (regcache
, AMD64_RAX_REGNUM
, &addr
);
118 read_memory (addr
, readbuf
, TYPE_LENGTH (type
));
120 return RETURN_VALUE_ABI_RETURNS_ADDRESS
;
124 /* Extract the return value from the register where it was stored. */
126 regcache_raw_read_part (regcache
, regnum
, 0, len
, readbuf
);
128 regcache_raw_write_part (regcache
, regnum
, 0, len
, writebuf
);
129 return RETURN_VALUE_REGISTER_CONVENTION
;
133 /* Check that the code pointed to by PC corresponds to a call to
134 __main, skip it if so. Return PC otherwise. */
137 amd64_skip_main_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
139 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
142 target_read_memory (pc
, &op
, 1);
147 if (target_read_memory (pc
+ 1, buf
, sizeof buf
) == 0)
149 struct bound_minimal_symbol s
;
152 call_dest
= pc
+ 5 + extract_signed_integer (buf
, 4, byte_order
);
153 s
= lookup_minimal_symbol_by_pc (call_dest
);
155 && SYMBOL_LINKAGE_NAME (s
.minsym
) != NULL
156 && strcmp (SYMBOL_LINKAGE_NAME (s
.minsym
), "__main") == 0)
164 struct amd64_windows_frame_cache
166 /* ImageBase for the module. */
167 CORE_ADDR image_base
;
169 /* Function start and end rva. */
173 /* Next instruction to be executed. */
179 /* Address of saved integer and xmm registers. */
180 CORE_ADDR prev_reg_addr
[16];
181 CORE_ADDR prev_xmm_addr
[16];
183 /* These two next fields are set only for machine info frames. */
185 /* Likewise for RIP. */
186 CORE_ADDR prev_rip_addr
;
188 /* Likewise for RSP. */
189 CORE_ADDR prev_rsp_addr
;
191 /* Address of the previous frame. */
195 /* Convert a Windows register number to gdb. */
196 static const enum amd64_regnum amd64_windows_w2gdb_regnum
[] =
216 /* Return TRUE iff PC is the the range of the function corresponding to
220 pc_in_range (CORE_ADDR pc
, const struct amd64_windows_frame_cache
*cache
)
222 return (pc
>= cache
->image_base
+ cache
->start_rva
223 && pc
< cache
->image_base
+ cache
->end_rva
);
226 /* Try to recognize and decode an epilogue sequence.
228 Return -1 if we fail to read the instructions for any reason.
229 Return 1 if an epilogue sequence was recognized, 0 otherwise. */
232 amd64_windows_frame_decode_epilogue (struct frame_info
*this_frame
,
233 struct amd64_windows_frame_cache
*cache
)
235 /* According to MSDN an epilogue "must consist of either an add RSP,constant
236 or lea RSP,constant[FPReg], followed by a series of zero or more 8-byte
237 register pops and a return or a jmp".
239 Furthermore, according to RtlVirtualUnwind, the complete list of
244 - jmp imm8 | imm32 [eb rel8] or [e9 rel32]
245 - jmp qword ptr imm32 - not handled
246 - rex.w jmp reg [4X ff eY]
249 CORE_ADDR pc
= cache
->pc
;
250 CORE_ADDR cur_sp
= cache
->sp
;
251 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
252 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
256 /* We don't care about the instruction deallocating the frame:
257 if it hasn't been executed, the pc is still in the body,
258 if it has been executed, the following epilog decoding will work. */
261 - pop reg [41 58-5f] or [58-5f]. */
266 if (target_read_memory (pc
, &op
, 1) != 0)
269 if (op
>= 0x40 && op
<= 0x4f)
275 if (target_read_memory (pc
+ 1, &op
, 1) != 0)
281 if (op
>= 0x58 && op
<= 0x5f)
284 gdb_byte reg
= (op
& 0x0f) | ((rex
& 1) << 3);
286 cache
->prev_reg_addr
[amd64_windows_w2gdb_regnum
[reg
]] = cur_sp
;
292 /* Allow the user to break this loop. This shouldn't happen as the
293 number of consecutive pop should be small. */
297 /* Then decode the marker. */
300 if (target_read_memory (pc
, &op
, 1) != 0)
307 cache
->prev_rip_addr
= cur_sp
;
308 cache
->prev_sp
= cur_sp
+ 8;
317 if (target_read_memory (pc
+ 1, &rel8
, 1) != 0)
319 npc
= pc
+ 2 + (signed char) rel8
;
321 /* If the jump is within the function, then this is not a marker,
322 otherwise this is a tail-call. */
323 return !pc_in_range (npc
, cache
);
332 if (target_read_memory (pc
+ 1, rel32
, 4) != 0)
334 npc
= pc
+ 5 + extract_signed_integer (rel32
, 4, byte_order
);
336 /* If the jump is within the function, then this is not a marker,
337 otherwise this is a tail-call. */
338 return !pc_in_range (npc
, cache
);
346 if (target_read_memory (pc
+ 1, imm16
, 2) != 0)
348 cache
->prev_rip_addr
= cur_sp
;
349 cache
->prev_sp
= cur_sp
350 + extract_unsigned_integer (imm16
, 4, byte_order
);
359 if (target_read_memory (pc
+ 2, &op1
, 1) != 0)
364 cache
->prev_rip_addr
= cur_sp
;
365 cache
->prev_sp
= cur_sp
+ 8;
385 /* Got a REX prefix, read next byte. */
387 if (target_read_memory (pc
+ 1, &op
, 1) != 0)
397 if (target_read_memory (pc
+ 2, &op1
, 1) != 0)
399 return (op1
& 0xf8) == 0xe0;
405 /* Not REX, so unknown. */
410 /* Decode and execute unwind insns at UNWIND_INFO. */
413 amd64_windows_frame_decode_insns (struct frame_info
*this_frame
,
414 struct amd64_windows_frame_cache
*cache
,
415 CORE_ADDR unwind_info
)
417 CORE_ADDR save_addr
= 0;
418 CORE_ADDR cur_sp
= cache
->sp
;
419 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
420 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
425 struct external_pex64_unwind_info ex_ui
;
426 /* There are at most 256 16-bit unwind insns. */
427 gdb_byte insns
[2 * 256];
430 unsigned char codes_count
;
431 unsigned char frame_reg
;
432 unsigned char frame_off
;
434 /* Read and decode header. */
435 if (target_read_memory (cache
->image_base
+ unwind_info
,
436 (gdb_byte
*) &ex_ui
, sizeof (ex_ui
)) != 0)
442 "amd64_windows_frame_decodes_insn: "
443 "%s: ver: %02x, plgsz: %02x, cnt: %02x, frame: %02x\n",
444 paddress (gdbarch
, unwind_info
),
445 ex_ui
.Version_Flags
, ex_ui
.SizeOfPrologue
,
446 ex_ui
.CountOfCodes
, ex_ui
.FrameRegisterOffset
);
449 if (PEX64_UWI_VERSION (ex_ui
.Version_Flags
) != 1)
454 cache
->image_base
+ cache
->start_rva
+ ex_ui
.SizeOfPrologue
))
456 /* Not in the prologue. We want to detect if the PC points to an
457 epilogue. If so, the epilogue detection+decoding function is
458 sufficient. Otherwise, the unwinder will consider that the PC
459 is in the body of the function and will need to decode unwind
461 if (amd64_windows_frame_decode_epilogue (this_frame
, cache
) == 1)
464 /* Not in an epilog. Clear possible side effects. */
465 memset (cache
->prev_reg_addr
, 0, sizeof (cache
->prev_reg_addr
));
468 codes_count
= ex_ui
.CountOfCodes
;
469 frame_reg
= PEX64_UWI_FRAMEREG (ex_ui
.FrameRegisterOffset
);
473 /* According to msdn:
474 If an FP reg is used, then any unwind code taking an offset must
475 only be used after the FP reg is established in the prolog. */
477 int frreg
= amd64_windows_w2gdb_regnum
[frame_reg
];
479 get_frame_register (this_frame
, frreg
, buf
);
480 save_addr
= extract_unsigned_integer (buf
, 8, byte_order
);
483 fprintf_unfiltered (gdb_stdlog
, " frame_reg=%s, val=%s\n",
484 gdbarch_register_name (gdbarch
, frreg
),
485 paddress (gdbarch
, save_addr
));
490 && target_read_memory (cache
->image_base
+ unwind_info
492 insns
, codes_count
* 2) != 0)
495 end_insns
= &insns
[codes_count
* 2];
496 for (p
= insns
; p
< end_insns
; p
+= 2)
502 (gdb_stdlog
, " op #%u: off=0x%02x, insn=0x%02x\n",
503 (unsigned) (p
- insns
), p
[0], p
[1]);
505 /* Virtually execute the operation. */
506 if (cache
->pc
>= cache
->image_base
+ cache
->start_rva
+ p
[0])
508 /* If there is no frame registers defined, the current value of
509 rsp is used instead. */
513 switch (PEX64_UNWCODE_CODE (p
[1]))
515 case UWOP_PUSH_NONVOL
:
516 /* Push pre-decrements RSP. */
517 reg
= amd64_windows_w2gdb_regnum
[PEX64_UNWCODE_INFO (p
[1])];
518 cache
->prev_reg_addr
[reg
] = cur_sp
;
521 case UWOP_ALLOC_LARGE
:
522 if (PEX64_UNWCODE_INFO (p
[1]) == 0)
524 8 * extract_unsigned_integer (p
+ 2, 2, byte_order
);
525 else if (PEX64_UNWCODE_INFO (p
[1]) == 1)
526 cur_sp
+= extract_unsigned_integer (p
+ 2, 4, byte_order
);
530 case UWOP_ALLOC_SMALL
:
531 cur_sp
+= 8 + 8 * PEX64_UNWCODE_INFO (p
[1]);
535 - PEX64_UWI_FRAMEOFF (ex_ui
.FrameRegisterOffset
) * 16;
537 case UWOP_SAVE_NONVOL
:
538 reg
= amd64_windows_w2gdb_regnum
[PEX64_UNWCODE_INFO (p
[1])];
539 cache
->prev_reg_addr
[reg
] = save_addr
540 - 8 * extract_unsigned_integer (p
+ 2, 2, byte_order
);
542 case UWOP_SAVE_NONVOL_FAR
:
543 reg
= amd64_windows_w2gdb_regnum
[PEX64_UNWCODE_INFO (p
[1])];
544 cache
->prev_reg_addr
[reg
] = save_addr
545 - 8 * extract_unsigned_integer (p
+ 2, 4, byte_order
);
547 case UWOP_SAVE_XMM128
:
548 cache
->prev_xmm_addr
[PEX64_UNWCODE_INFO (p
[1])] =
550 - 16 * extract_unsigned_integer (p
+ 2, 2, byte_order
);
552 case UWOP_SAVE_XMM128_FAR
:
553 cache
->prev_xmm_addr
[PEX64_UNWCODE_INFO (p
[1])] =
555 - 16 * extract_unsigned_integer (p
+ 2, 4, byte_order
);
557 case UWOP_PUSH_MACHFRAME
:
558 if (PEX64_UNWCODE_INFO (p
[1]) == 0)
560 cache
->prev_rip_addr
= cur_sp
+ 0;
561 cache
->prev_rsp_addr
= cur_sp
+ 24;
564 else if (PEX64_UNWCODE_INFO (p
[1]) == 1)
566 cache
->prev_rip_addr
= cur_sp
+ 8;
567 cache
->prev_rsp_addr
= cur_sp
+ 32;
578 /* Adjust with the length of the opcode. */
579 switch (PEX64_UNWCODE_CODE (p
[1]))
581 case UWOP_PUSH_NONVOL
:
582 case UWOP_ALLOC_SMALL
:
584 case UWOP_PUSH_MACHFRAME
:
586 case UWOP_ALLOC_LARGE
:
587 if (PEX64_UNWCODE_INFO (p
[1]) == 0)
589 else if (PEX64_UNWCODE_INFO (p
[1]) == 1)
594 case UWOP_SAVE_NONVOL
:
595 case UWOP_SAVE_XMM128
:
598 case UWOP_SAVE_NONVOL_FAR
:
599 case UWOP_SAVE_XMM128_FAR
:
606 if (PEX64_UWI_FLAGS (ex_ui
.Version_Flags
) != UNW_FLAG_CHAININFO
)
610 /* Read the chained unwind info. */
611 struct external_pex64_runtime_function d
;
614 chain_vma
= cache
->image_base
+ unwind_info
615 + sizeof (ex_ui
) + ((codes_count
+ 1) & ~1) * 2 + 8;
617 if (target_read_memory (chain_vma
, (gdb_byte
*) &d
, sizeof (d
)) != 0)
621 extract_unsigned_integer (d
.rva_BeginAddress
, 4, byte_order
);
623 extract_unsigned_integer (d
.rva_EndAddress
, 4, byte_order
);
625 extract_unsigned_integer (d
.rva_UnwindData
, 4, byte_order
);
628 /* Allow the user to break this loop. */
631 /* PC is saved by the call. */
632 if (cache
->prev_rip_addr
== 0)
633 cache
->prev_rip_addr
= cur_sp
;
634 cache
->prev_sp
= cur_sp
+ 8;
637 fprintf_unfiltered (gdb_stdlog
, " prev_sp: %s, prev_pc @%s\n",
638 paddress (gdbarch
, cache
->prev_sp
),
639 paddress (gdbarch
, cache
->prev_rip_addr
));
642 /* Find SEH unwind info for PC, returning 0 on success.
644 UNWIND_INFO is set to the rva of unwind info address, IMAGE_BASE
645 to the base address of the corresponding image, and START_RVA
646 to the rva of the function containing PC. */
649 amd64_windows_find_unwind_info (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
650 CORE_ADDR
*unwind_info
,
651 CORE_ADDR
*image_base
,
652 CORE_ADDR
*start_rva
,
655 struct obj_section
*sec
;
657 IMAGE_DATA_DIRECTORY
*dir
;
658 struct objfile
*objfile
;
659 unsigned long lo
, hi
;
661 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
663 /* Get the corresponding exception directory. */
664 sec
= find_pc_section (pc
);
667 objfile
= sec
->objfile
;
668 pe
= pe_data (sec
->objfile
->obfd
);
669 dir
= &pe
->pe_opthdr
.DataDirectory
[PE_EXCEPTION_TABLE
];
671 base
= pe
->pe_opthdr
.ImageBase
672 + ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
677 Note: This does not handle dynamically added entries (for JIT
678 engines). For this, we would need to ask the kernel directly,
679 which means getting some info from the native layer. For the
680 rest of the code, however, it's probably faster to search
681 the entry ourselves. */
683 hi
= dir
->Size
/ sizeof (struct external_pex64_runtime_function
);
687 unsigned long mid
= lo
+ (hi
- lo
) / 2;
688 struct external_pex64_runtime_function d
;
691 if (target_read_memory (base
+ dir
->VirtualAddress
+ mid
* sizeof (d
),
692 (gdb_byte
*) &d
, sizeof (d
)) != 0)
695 sa
= extract_unsigned_integer (d
.rva_BeginAddress
, 4, byte_order
);
696 ea
= extract_unsigned_integer (d
.rva_EndAddress
, 4, byte_order
);
699 else if (pc
>= base
+ ea
)
701 else if (pc
>= base
+ sa
&& pc
< base
+ ea
)
707 extract_unsigned_integer (d
.rva_UnwindData
, 4, byte_order
);
717 "amd64_windows_find_unwind_data: image_base=%s, unwind_data=%s\n",
718 paddress (gdbarch
, base
), paddress (gdbarch
, *unwind_info
));
720 if (*unwind_info
& 1)
722 /* Unofficially documented unwind info redirection, when UNWIND_INFO
723 address is odd (http://www.codemachine.com/article_x64deepdive.html).
725 struct external_pex64_runtime_function d
;
728 if (target_read_memory (base
+ (*unwind_info
& ~1),
729 (gdb_byte
*) &d
, sizeof (d
)) != 0)
733 extract_unsigned_integer (d
.rva_BeginAddress
, 4, byte_order
);
734 *end_rva
= extract_unsigned_integer (d
.rva_EndAddress
, 4, byte_order
);
736 extract_unsigned_integer (d
.rva_UnwindData
, 4, byte_order
);
742 /* Fill THIS_CACHE using the native amd64-windows unwinding data
745 static struct amd64_windows_frame_cache
*
746 amd64_windows_frame_cache (struct frame_info
*this_frame
, void **this_cache
)
748 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
749 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
750 struct amd64_windows_frame_cache
*cache
;
752 struct obj_section
*sec
;
754 IMAGE_DATA_DIRECTORY
*dir
;
755 CORE_ADDR image_base
;
757 struct objfile
*objfile
;
758 unsigned long lo
, hi
;
759 CORE_ADDR unwind_info
= 0;
764 cache
= FRAME_OBSTACK_ZALLOC (struct amd64_windows_frame_cache
);
767 /* Get current PC and SP. */
768 pc
= get_frame_pc (this_frame
);
769 get_frame_register (this_frame
, AMD64_RSP_REGNUM
, buf
);
770 cache
->sp
= extract_unsigned_integer (buf
, 8, byte_order
);
773 if (amd64_windows_find_unwind_info (gdbarch
, pc
, &unwind_info
,
779 if (unwind_info
== 0)
781 /* Assume a leaf function. */
782 cache
->prev_sp
= cache
->sp
+ 8;
783 cache
->prev_rip_addr
= cache
->sp
;
787 /* Decode unwind insns to compute saved addresses. */
788 amd64_windows_frame_decode_insns (this_frame
, cache
, unwind_info
);
793 /* Implement the "prev_register" method of struct frame_unwind
794 using the standard Windows x64 SEH info. */
796 static struct value
*
797 amd64_windows_frame_prev_register (struct frame_info
*this_frame
,
798 void **this_cache
, int regnum
)
800 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
801 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
802 struct amd64_windows_frame_cache
*cache
=
803 amd64_windows_frame_cache (this_frame
, this_cache
);
808 fprintf_unfiltered (gdb_stdlog
,
809 "amd64_windows_frame_prev_register %s for sp=%s\n",
810 gdbarch_register_name (gdbarch
, regnum
),
811 paddress (gdbarch
, cache
->prev_sp
));
813 if (regnum
>= AMD64_XMM0_REGNUM
&& regnum
<= AMD64_XMM0_REGNUM
+ 15)
814 prev
= cache
->prev_xmm_addr
[regnum
- AMD64_XMM0_REGNUM
];
815 else if (regnum
== AMD64_RSP_REGNUM
)
817 prev
= cache
->prev_rsp_addr
;
819 return frame_unwind_got_constant (this_frame
, regnum
, cache
->prev_sp
);
821 else if (regnum
>= AMD64_RAX_REGNUM
&& regnum
<= AMD64_R15_REGNUM
)
822 prev
= cache
->prev_reg_addr
[regnum
- AMD64_RAX_REGNUM
];
823 else if (regnum
== AMD64_RIP_REGNUM
)
824 prev
= cache
->prev_rip_addr
;
828 if (prev
&& frame_debug
)
829 fprintf_unfiltered (gdb_stdlog
, " -> at %s\n", paddress (gdbarch
, prev
));
833 /* Register was saved. */
834 return frame_unwind_got_memory (this_frame
, regnum
, prev
);
838 /* Register is either volatile or not modified. */
839 return frame_unwind_got_register (this_frame
, regnum
, regnum
);
843 /* Implement the "this_id" method of struct frame_unwind using
844 the standard Windows x64 SEH info. */
847 amd64_windows_frame_this_id (struct frame_info
*this_frame
, void **this_cache
,
848 struct frame_id
*this_id
)
850 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
851 struct amd64_windows_frame_cache
*cache
=
852 amd64_windows_frame_cache (this_frame
, this_cache
);
854 *this_id
= frame_id_build (cache
->prev_sp
,
855 cache
->image_base
+ cache
->start_rva
);
858 /* Windows x64 SEH unwinder. */
860 static const struct frame_unwind amd64_windows_frame_unwind
=
863 default_frame_unwind_stop_reason
,
864 &amd64_windows_frame_this_id
,
865 &amd64_windows_frame_prev_register
,
867 default_frame_sniffer
870 /* Implement the "skip_prologue" gdbarch method. */
873 amd64_windows_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
876 CORE_ADDR unwind_info
= 0;
877 CORE_ADDR image_base
, start_rva
, end_rva
;
878 struct external_pex64_unwind_info ex_ui
;
880 /* Use prologue size from unwind info. */
881 if (amd64_windows_find_unwind_info (gdbarch
, pc
, &unwind_info
,
882 &image_base
, &start_rva
, &end_rva
) == 0)
884 if (unwind_info
== 0)
889 else if (target_read_memory (image_base
+ unwind_info
,
890 (gdb_byte
*) &ex_ui
, sizeof (ex_ui
)) == 0
891 && PEX64_UWI_VERSION (ex_ui
.Version_Flags
) == 1)
892 return max (pc
, image_base
+ start_rva
+ ex_ui
.SizeOfPrologue
);
895 /* See if we can determine the end of the prologue via the symbol
896 table. If so, then return either the PC, or the PC after
897 the prologue, whichever is greater. */
898 if (find_pc_partial_function (pc
, NULL
, &func_addr
, NULL
))
900 CORE_ADDR post_prologue_pc
901 = skip_prologue_using_sal (gdbarch
, func_addr
);
903 if (post_prologue_pc
!= 0)
904 return max (pc
, post_prologue_pc
);
910 /* Check Win64 DLL jmp trampolines and find jump destination. */
913 amd64_windows_skip_trampoline_code (struct frame_info
*frame
, CORE_ADDR pc
)
915 CORE_ADDR destination
= 0;
916 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
917 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
919 /* Check for jmp *<offset>(%rip) (jump near, absolute indirect (/4)). */
920 if (pc
&& read_memory_unsigned_integer (pc
, 2, byte_order
) == 0x25ff)
922 /* Get opcode offset and see if we can find a reference in our data. */
924 = read_memory_unsigned_integer (pc
+ 2, 4, byte_order
);
926 /* Get address of function pointer at end of pc. */
927 CORE_ADDR indirect_addr
= pc
+ offset
+ 6;
929 struct minimal_symbol
*indsym
931 ? lookup_minimal_symbol_by_pc (indirect_addr
).minsym
933 const char *symname
= indsym
? SYMBOL_LINKAGE_NAME (indsym
) : NULL
;
937 if (strncmp (symname
, "__imp_", 6) == 0
938 || strncmp (symname
, "_imp_", 5) == 0)
940 = read_memory_unsigned_integer (indirect_addr
, 8, byte_order
);
947 /* Implement the "auto_wide_charset" gdbarch method. */
950 amd64_windows_auto_wide_charset (void)
956 amd64_windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
958 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
960 /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
961 preferred over the SEH one. The reasons are:
962 - binaries without SEH but with dwarf2 debug info are correcly handled
963 (although they aren't ABI compliant, gcc before 4.7 didn't emit SEH
965 - dwarf3 DW_OP_call_frame_cfa is correctly handled (it can only be
966 handled if the dwarf2 unwinder is used).
968 The call to amd64_init_abi appends default unwinders, that aren't
969 compatible with the SEH one.
971 frame_unwind_append_unwinder (gdbarch
, &amd64_windows_frame_unwind
);
973 amd64_init_abi (info
, gdbarch
);
975 /* On Windows, "long"s are only 32bit. */
976 set_gdbarch_long_bit (gdbarch
, 32);
978 /* Function calls. */
979 tdep
->call_dummy_num_integer_regs
=
980 ARRAY_SIZE (amd64_windows_dummy_call_integer_regs
);
981 tdep
->call_dummy_integer_regs
= amd64_windows_dummy_call_integer_regs
;
982 tdep
->classify
= amd64_windows_classify
;
983 tdep
->memory_args_by_pointer
= 1;
984 tdep
->integer_param_regs_saved_in_caller_frame
= 1;
985 set_gdbarch_return_value (gdbarch
, amd64_windows_return_value
);
986 set_gdbarch_skip_main_prologue (gdbarch
, amd64_skip_main_prologue
);
987 set_gdbarch_skip_trampoline_code (gdbarch
,
988 amd64_windows_skip_trampoline_code
);
990 set_gdbarch_iterate_over_objfiles_in_search_order
991 (gdbarch
, windows_iterate_over_objfiles_in_search_order
);
993 set_gdbarch_skip_prologue (gdbarch
, amd64_windows_skip_prologue
);
995 set_gdbarch_auto_wide_charset (gdbarch
, amd64_windows_auto_wide_charset
);
997 set_solib_ops (gdbarch
, &solib_target_so_ops
);
1000 /* -Wmissing-prototypes */
1001 extern initialize_file_ftype _initialize_amd64_windows_tdep
;
1004 _initialize_amd64_windows_tdep (void)
1006 gdbarch_register_osabi (bfd_arch_i386
, bfd_mach_x86_64
, GDB_OSABI_CYGWIN
,
1007 amd64_windows_init_abi
);