More updated translations
[binutils-gdb.git] / gdb / amd64-windows-tdep.c
blobb9de332e308e6f359371b180f68356e392f9d176
1 /* Copyright (C) 2009-2024 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/>. */
18 #include "event-top.h"
19 #include "extract-store-integer.h"
20 #include "osabi.h"
21 #include "amd64-tdep.h"
22 #include "gdbsupport/x86-xstate.h"
23 #include "gdbtypes.h"
24 #include "gdbcore.h"
25 #include "regcache.h"
26 #include "windows-tdep.h"
27 #include "frame.h"
28 #include "objfiles.h"
29 #include "frame-unwind.h"
30 #include "coff/internal.h"
31 #include "coff/i386.h"
32 #include "coff/pe.h"
33 #include "libcoff.h"
34 #include "value.h"
35 #include <algorithm>
37 /* The registers used to pass integer arguments during a function call. */
38 static int amd64_windows_dummy_call_integer_regs[] =
40 AMD64_RCX_REGNUM, /* %rcx */
41 AMD64_RDX_REGNUM, /* %rdx */
42 AMD64_R8_REGNUM, /* %r8 */
43 AMD64_R9_REGNUM /* %r9 */
46 /* This vector maps GDB's idea of a register's number into an offset into
47 the Windows API CONTEXT structure. */
48 static int amd64_windows_gregset_reg_offset[] =
50 120, /* Rax */
51 144, /* Rbx */
52 128, /* Rcx */
53 136, /* Rdx */
54 168, /* Rsi */
55 176, /* Rdi */
56 160, /* Rbp */
57 152, /* Rsp */
58 184, /* R8 */
59 192, /* R9 */
60 200, /* R10 */
61 208, /* R11 */
62 216, /* R12 */
63 224, /* R13 */
64 232, /* R14 */
65 240, /* R15 */
66 248, /* Rip */
67 68, /* EFlags */
68 56, /* SegCs */
69 66, /* SegSs */
70 58, /* SegDs */
71 60, /* SegEs */
72 62, /* SegFs */
73 64, /* SegGs */
74 288, /* FloatSave.FloatRegisters[0] */
75 304, /* FloatSave.FloatRegisters[1] */
76 320, /* FloatSave.FloatRegisters[2] */
77 336, /* FloatSave.FloatRegisters[3] */
78 352, /* FloatSave.FloatRegisters[4] */
79 368, /* FloatSave.FloatRegisters[5] */
80 384, /* FloatSave.FloatRegisters[6] */
81 400, /* FloatSave.FloatRegisters[7] */
82 256, /* FloatSave.ControlWord */
83 258, /* FloatSave.StatusWord */
84 260, /* FloatSave.TagWord */
85 268, /* FloatSave.ErrorSelector */
86 264, /* FloatSave.ErrorOffset */
87 276, /* FloatSave.DataSelector */
88 272, /* FloatSave.DataOffset */
89 268, /* FloatSave.ErrorSelector */
90 416, /* Xmm0 */
91 432, /* Xmm1 */
92 448, /* Xmm2 */
93 464, /* Xmm3 */
94 480, /* Xmm4 */
95 496, /* Xmm5 */
96 512, /* Xmm6 */
97 528, /* Xmm7 */
98 544, /* Xmm8 */
99 560, /* Xmm9 */
100 576, /* Xmm10 */
101 592, /* Xmm11 */
102 608, /* Xmm12 */
103 624, /* Xmm13 */
104 640, /* Xmm14 */
105 656, /* Xmm15 */
106 280, /* FloatSave.MxCsr */
109 #define AMD64_WINDOWS_SIZEOF_GREGSET 1232
111 /* Return nonzero if an argument of type TYPE should be passed
112 via one of the integer registers. */
114 static int
115 amd64_windows_passed_by_integer_register (struct type *type)
117 switch (type->code ())
119 case TYPE_CODE_INT:
120 case TYPE_CODE_ENUM:
121 case TYPE_CODE_BOOL:
122 case TYPE_CODE_RANGE:
123 case TYPE_CODE_CHAR:
124 case TYPE_CODE_PTR:
125 case TYPE_CODE_REF:
126 case TYPE_CODE_RVALUE_REF:
127 case TYPE_CODE_STRUCT:
128 case TYPE_CODE_UNION:
129 case TYPE_CODE_COMPLEX:
130 return (type->length () == 1
131 || type->length () == 2
132 || type->length () == 4
133 || type->length () == 8);
135 default:
136 return 0;
140 /* Return nonzero if an argument of type TYPE should be passed
141 via one of the XMM registers. */
143 static int
144 amd64_windows_passed_by_xmm_register (struct type *type)
146 return ((type->code () == TYPE_CODE_FLT
147 || type->code () == TYPE_CODE_DECFLOAT)
148 && (type->length () == 4 || type->length () == 8));
151 /* Return non-zero iff an argument of the given TYPE should be passed
152 by pointer. */
154 static int
155 amd64_windows_passed_by_pointer (struct type *type)
157 if (amd64_windows_passed_by_integer_register (type))
158 return 0;
160 if (amd64_windows_passed_by_xmm_register (type))
161 return 0;
163 return 1;
166 /* For each argument that should be passed by pointer, reserve some
167 stack space, store a copy of the argument on the stack, and replace
168 the argument by its address. Return the new Stack Pointer value.
170 NARGS is the number of arguments. ARGS is the array containing
171 the value of each argument. SP is value of the Stack Pointer. */
173 static CORE_ADDR
174 amd64_windows_adjust_args_passed_by_pointer (struct value **args,
175 int nargs, CORE_ADDR sp)
177 int i;
179 for (i = 0; i < nargs; i++)
180 if (amd64_windows_passed_by_pointer (args[i]->type ()))
182 struct type *type = args[i]->type ();
183 const gdb_byte *valbuf = args[i]->contents ().data ();
184 const int len = type->length ();
186 /* Store a copy of that argument on the stack, aligned to
187 a 16 bytes boundary, and then use the copy's address as
188 the argument. */
190 sp -= len;
191 sp &= ~0xf;
192 write_memory (sp, valbuf, len);
194 args[i]
195 = value_addr (value_from_contents_and_address (type, valbuf, sp));
198 return sp;
201 /* Store the value of ARG in register REGNO (right-justified).
202 REGCACHE is the register cache. */
204 static void
205 amd64_windows_store_arg_in_reg (struct regcache *regcache,
206 struct value *arg, int regno)
208 gdb::array_view<const gdb_byte> valbuf = arg->contents ();
209 /* We only set 8 bytes, buf if it's a XMM register, 16 bytes are read. */
210 std::array<gdb_byte, 16> buf {};
212 gdb_assert (valbuf.size () <= 8);
213 std::copy (valbuf.begin (), valbuf.end (), buf.begin ());
214 size_t reg_size = regcache->register_size (regno);
215 gdb_assert (reg_size <= buf.size ());
216 gdb::array_view<gdb_byte> view (buf);
217 regcache->cooked_write (regno, view.slice (0, reg_size));
220 /* Push the arguments for an inferior function call, and return
221 the updated value of the SP (Stack Pointer).
223 All arguments are identical to the arguments used in
224 amd64_windows_push_dummy_call. */
226 static CORE_ADDR
227 amd64_windows_push_arguments (struct regcache *regcache, int nargs,
228 struct value **args, CORE_ADDR sp,
229 function_call_return_method return_method)
231 int reg_idx = 0;
232 int i;
233 struct value **stack_args = XALLOCAVEC (struct value *, nargs);
234 int num_stack_args = 0;
235 int num_elements = 0;
236 int element = 0;
238 /* First, handle the arguments passed by pointer.
240 These arguments are replaced by pointers to a copy we are making
241 in inferior memory. So use a copy of the ARGS table, to avoid
242 modifying the original one. */
243 if (nargs > 0)
245 struct value **args1 = XALLOCAVEC (struct value *, nargs);
247 memcpy (args1, args, nargs * sizeof (struct value *));
248 sp = amd64_windows_adjust_args_passed_by_pointer (args1, nargs, sp);
249 args = args1;
252 /* Reserve a register for the "hidden" argument. */
253 if (return_method == return_method_struct)
254 reg_idx++;
256 for (i = 0; i < nargs; i++)
258 struct type *type = args[i]->type ();
259 int len = type->length ();
260 int on_stack_p = 1;
262 if (reg_idx < ARRAY_SIZE (amd64_windows_dummy_call_integer_regs))
264 if (amd64_windows_passed_by_integer_register (type))
266 amd64_windows_store_arg_in_reg
267 (regcache, args[i],
268 amd64_windows_dummy_call_integer_regs[reg_idx]);
269 on_stack_p = 0;
270 reg_idx++;
272 else if (amd64_windows_passed_by_xmm_register (type))
274 amd64_windows_store_arg_in_reg
275 (regcache, args[i], AMD64_XMM0_REGNUM + reg_idx);
276 /* In case of varargs, these parameters must also be
277 passed via the integer registers. */
278 amd64_windows_store_arg_in_reg
279 (regcache, args[i],
280 amd64_windows_dummy_call_integer_regs[reg_idx]);
281 on_stack_p = 0;
282 reg_idx++;
286 if (on_stack_p)
288 num_elements += ((len + 7) / 8);
289 stack_args[num_stack_args++] = args[i];
293 /* Allocate space for the arguments on the stack, keeping it
294 aligned on a 16 byte boundary. */
295 sp -= num_elements * 8;
296 sp &= ~0xf;
298 /* Write out the arguments to the stack. */
299 for (i = 0; i < num_stack_args; i++)
301 struct type *type = stack_args[i]->type ();
302 const gdb_byte *valbuf = stack_args[i]->contents ().data ();
304 write_memory (sp + element * 8, valbuf, type->length ());
305 element += ((type->length () + 7) / 8);
308 return sp;
311 /* Implement the "push_dummy_call" gdbarch method. */
313 static CORE_ADDR
314 amd64_windows_push_dummy_call
315 (struct gdbarch *gdbarch, struct value *function,
316 struct regcache *regcache, CORE_ADDR bp_addr,
317 int nargs, struct value **args, CORE_ADDR sp,
318 function_call_return_method return_method, CORE_ADDR struct_addr)
320 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
321 std::array<gdb_byte, 8> buf;
323 /* Pass arguments. */
324 sp = amd64_windows_push_arguments (regcache, nargs, args, sp,
325 return_method);
327 /* Pass "hidden" argument". */
328 if (return_method == return_method_struct)
330 /* The "hidden" argument is passed through the first argument
331 register. */
332 const int arg_regnum = amd64_windows_dummy_call_integer_regs[0];
334 store_unsigned_integer (buf, byte_order, struct_addr);
335 regcache->cooked_write (arg_regnum, buf);
338 /* Reserve some memory on the stack for the integer-parameter
339 registers, as required by the ABI. */
340 sp -= ARRAY_SIZE (amd64_windows_dummy_call_integer_regs) * 8;
342 /* Store return address. */
343 sp -= 8;
344 store_unsigned_integer (buf, byte_order, bp_addr);
345 write_memory (sp, buf.data (), buf.size ());
347 /* Update the stack pointer... */
348 store_unsigned_integer (buf, byte_order, sp);
349 regcache->cooked_write (AMD64_RSP_REGNUM, buf);
351 /* ...and fake a frame pointer. */
352 regcache->cooked_write (AMD64_RBP_REGNUM, buf);
354 return sp + 16;
357 /* Implement the "return_value" gdbarch method for amd64-windows. */
359 static enum return_value_convention
360 amd64_windows_return_value (struct gdbarch *gdbarch, struct value *function,
361 struct type *type, struct regcache *regcache,
362 struct value **read_value, const gdb_byte *writebuf)
364 int len = type->length ();
365 int regnum = -1;
367 /* See if our value is returned through a register. If it is, then
368 store the associated register number in REGNUM. */
369 switch (type->code ())
371 case TYPE_CODE_FLT:
372 /* floats, and doubles are returned via XMM0. */
373 if (len == 4 || len == 8)
374 regnum = AMD64_XMM0_REGNUM;
375 break;
376 case TYPE_CODE_ARRAY:
377 /* __m128, __m128i and __m128d are returned via XMM0. */
378 if (type->is_vector () && len == 16)
380 enum type_code code = type->target_type ()->code ();
381 if (code == TYPE_CODE_INT || code == TYPE_CODE_FLT)
383 regnum = AMD64_XMM0_REGNUM;
384 break;
387 [[fallthrough]];
388 default:
389 /* All other values that are 1, 2, 4 or 8 bytes long are returned
390 via RAX. */
391 if (len == 1 || len == 2 || len == 4 || len == 8)
392 regnum = AMD64_RAX_REGNUM;
393 else if (len == 16 && type->code () == TYPE_CODE_INT)
394 regnum = AMD64_XMM0_REGNUM;
395 break;
398 if (regnum < 0)
400 /* RAX contains the address where the return value has been stored. */
401 if (read_value != nullptr)
403 ULONGEST addr;
405 regcache_raw_read_unsigned (regcache, AMD64_RAX_REGNUM, &addr);
406 *read_value = value_at_non_lval (type, addr);
408 return RETURN_VALUE_ABI_RETURNS_ADDRESS;
410 else
412 /* Extract the return value from the register where it was stored. */
413 if (read_value != nullptr)
415 *read_value = value::allocate (type);
416 regcache->raw_read_part (regnum, 0, len,
417 (*read_value)->contents_raw ().data ());
419 if (writebuf)
420 regcache->raw_write_part (regnum, 0, len, writebuf);
421 return RETURN_VALUE_REGISTER_CONVENTION;
425 /* Check that the code pointed to by PC corresponds to a call to
426 __main, skip it if so. Return PC otherwise. */
428 static CORE_ADDR
429 amd64_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
431 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
432 gdb_byte op;
434 target_read_memory (pc, &op, 1);
435 if (op == 0xe8)
437 std::array<gdb_byte, 4> buf;
439 if (target_read_memory (pc + 1, buf.data (), buf.size ()) == 0)
441 CORE_ADDR call_dest;
443 call_dest = pc + 5 + extract_signed_integer (buf, byte_order);
444 bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
445 if (s.minsym != NULL
446 && s.minsym->linkage_name () != NULL
447 && strcmp (s.minsym->linkage_name (), "__main") == 0)
448 pc += 5;
452 return pc;
455 struct amd64_windows_frame_cache
457 /* ImageBase for the module. */
458 CORE_ADDR image_base;
460 /* Function start and end rva. */
461 CORE_ADDR start_rva;
462 CORE_ADDR end_rva;
464 /* Next instruction to be executed. */
465 CORE_ADDR pc;
467 /* Current sp. */
468 CORE_ADDR sp;
470 /* Address of saved integer and xmm registers. */
471 CORE_ADDR prev_reg_addr[16];
472 CORE_ADDR prev_xmm_addr[16];
474 /* These two next fields are set only for machine info frames. */
476 /* Likewise for RIP. */
477 CORE_ADDR prev_rip_addr;
479 /* Likewise for RSP. */
480 CORE_ADDR prev_rsp_addr;
482 /* Address of the previous frame. */
483 CORE_ADDR prev_sp;
486 /* Convert a Windows register number to gdb. */
487 static const enum amd64_regnum amd64_windows_w2gdb_regnum[] =
489 AMD64_RAX_REGNUM,
490 AMD64_RCX_REGNUM,
491 AMD64_RDX_REGNUM,
492 AMD64_RBX_REGNUM,
493 AMD64_RSP_REGNUM,
494 AMD64_RBP_REGNUM,
495 AMD64_RSI_REGNUM,
496 AMD64_RDI_REGNUM,
497 AMD64_R8_REGNUM,
498 AMD64_R9_REGNUM,
499 AMD64_R10_REGNUM,
500 AMD64_R11_REGNUM,
501 AMD64_R12_REGNUM,
502 AMD64_R13_REGNUM,
503 AMD64_R14_REGNUM,
504 AMD64_R15_REGNUM
507 /* Return TRUE iff PC is the range of the function corresponding to
508 CACHE. */
510 static int
511 pc_in_range (CORE_ADDR pc, const struct amd64_windows_frame_cache *cache)
513 return (pc >= cache->image_base + cache->start_rva
514 && pc < cache->image_base + cache->end_rva);
517 /* Try to recognize and decode an epilogue sequence.
519 Return -1 if we fail to read the instructions for any reason.
520 Return 1 if an epilogue sequence was recognized, 0 otherwise. */
522 static int
523 amd64_windows_frame_decode_epilogue (const frame_info_ptr &this_frame,
524 struct amd64_windows_frame_cache *cache)
526 /* According to MSDN an epilogue "must consist of either an add RSP,constant
527 or lea RSP,constant[FPReg], followed by a series of zero or more 8-byte
528 register pops and a return or a jmp".
530 Furthermore, according to RtlVirtualUnwind, the complete list of
531 epilog marker is:
532 - ret [c3]
533 - ret n [c2 imm16]
534 - rep ret [f3 c3]
535 - jmp imm8 | imm32 [eb rel8] or [e9 rel32]
536 - jmp qword ptr imm32 - not handled
537 - rex.w jmp reg [4X ff eY]
540 CORE_ADDR pc = cache->pc;
541 CORE_ADDR cur_sp = cache->sp;
542 struct gdbarch *gdbarch = get_frame_arch (this_frame);
543 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
544 gdb_byte op;
545 gdb_byte rex;
547 /* We don't care about the instruction deallocating the frame:
548 if it hasn't been executed, the pc is still in the body,
549 if it has been executed, the following epilog decoding will work. */
551 /* First decode:
552 - pop reg [41 58-5f] or [58-5f]. */
554 while (1)
556 /* Read opcode. */
557 if (target_read_memory (pc, &op, 1) != 0)
558 return -1;
560 if (op >= 0x40 && op <= 0x4f)
562 /* REX prefix. */
563 rex = op;
565 /* Read opcode. */
566 if (target_read_memory (pc + 1, &op, 1) != 0)
567 return -1;
569 else
570 rex = 0;
572 if (op >= 0x58 && op <= 0x5f)
574 /* pop reg */
575 gdb_byte reg = (op & 0x0f) | ((rex & 1) << 3);
577 cache->prev_reg_addr[amd64_windows_w2gdb_regnum[reg]] = cur_sp;
578 cur_sp += 8;
579 pc += rex ? 2 : 1;
581 else
582 break;
584 /* Allow the user to break this loop. This shouldn't happen as the
585 number of consecutive pop should be small. */
586 QUIT;
589 /* Then decode the marker. */
591 /* Read opcode. */
592 if (target_read_memory (pc, &op, 1) != 0)
593 return -1;
595 switch (op)
597 case 0xc3:
598 /* Ret. */
599 cache->prev_rip_addr = cur_sp;
600 cache->prev_sp = cur_sp + 8;
601 return 1;
603 case 0xeb:
605 /* jmp rel8 */
606 gdb_byte rel8;
607 CORE_ADDR npc;
609 if (target_read_memory (pc + 1, &rel8, 1) != 0)
610 return -1;
611 npc = pc + 2 + (signed char) rel8;
613 /* If the jump is within the function, then this is not a marker,
614 otherwise this is a tail-call. */
615 return !pc_in_range (npc, cache);
618 case 0xec:
620 /* jmp rel32 */
621 std::array<gdb_byte, 4> rel32;
622 CORE_ADDR npc;
624 if (target_read_memory (pc + 1, rel32.data (), rel32.size ()) != 0)
625 return -1;
626 npc = pc + 5 + extract_signed_integer (rel32, byte_order);
628 /* If the jump is within the function, then this is not a marker,
629 otherwise this is a tail-call. */
630 return !pc_in_range (npc, cache);
633 case 0xc2:
635 /* ret n */
636 std::array<gdb_byte, 2> imm16;
638 if (target_read_memory (pc + 1, imm16.data (), imm16.size ()) != 0)
639 return -1;
640 cache->prev_rip_addr = cur_sp;
641 cache->prev_sp = cur_sp
642 + extract_unsigned_integer (imm16, byte_order);
643 return 1;
646 case 0xf3:
648 /* rep; ret */
649 gdb_byte op1;
651 if (target_read_memory (pc + 2, &op1, 1) != 0)
652 return -1;
653 if (op1 != 0xc3)
654 return 0;
656 cache->prev_rip_addr = cur_sp;
657 cache->prev_sp = cur_sp + 8;
658 return 1;
661 case 0x40:
662 case 0x41:
663 case 0x42:
664 case 0x43:
665 case 0x44:
666 case 0x45:
667 case 0x46:
668 case 0x47:
669 case 0x48:
670 case 0x49:
671 case 0x4a:
672 case 0x4b:
673 case 0x4c:
674 case 0x4d:
675 case 0x4e:
676 case 0x4f:
677 /* Got a REX prefix, read next byte. */
678 rex = op;
679 if (target_read_memory (pc + 1, &op, 1) != 0)
680 return -1;
682 if (op == 0xff)
684 /* rex jmp reg */
685 gdb_byte op1;
687 if (target_read_memory (pc + 2, &op1, 1) != 0)
688 return -1;
689 return (op1 & 0xf8) == 0xe0;
691 else
692 return 0;
694 default:
695 /* Not REX, so unknown. */
696 return 0;
700 /* Decode and execute unwind insns at UNWIND_INFO. */
702 static void
703 amd64_windows_frame_decode_insns (const frame_info_ptr &this_frame,
704 struct amd64_windows_frame_cache *cache,
705 CORE_ADDR unwind_info)
707 CORE_ADDR save_addr = 0;
708 CORE_ADDR cur_sp = cache->sp;
709 struct gdbarch *gdbarch = get_frame_arch (this_frame);
710 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
711 int first = 1;
713 /* There are at least 3 possibilities to share an unwind info entry:
714 1. Two different runtime_function entries (in .pdata) can point to the
715 same unwind info entry. There is no such indication while unwinding,
716 so we don't really care about that case. We suppose this scheme is
717 used to save memory when the unwind entries are exactly the same.
718 2. Chained unwind_info entries, with no unwind codes (no prologue).
719 There is a major difference with the previous case: the pc range for
720 the function is different (in case 1, the pc range comes from the
721 runtime_function entry; in case 2, the pc range for the chained entry
722 comes from the first unwind entry). Case 1 cannot be used instead as
723 the pc is not in the prologue. This case is officially documented.
724 (There might be unwind code in the first unwind entry to handle
725 additional unwinding). GCC (at least until gcc 5.0) doesn't chain
726 entries.
727 3. Undocumented unwind info redirection. Hard to know the exact purpose,
728 so it is considered as a memory optimization of case 2.
731 if (unwind_info & 1)
733 /* Unofficially documented unwind info redirection, when UNWIND_INFO
734 address is odd (http://www.codemachine.com/article_x64deepdive.html).
736 struct external_pex64_runtime_function d;
738 if (target_read_memory (cache->image_base + (unwind_info & ~1),
739 (gdb_byte *) &d, sizeof (d)) != 0)
740 return;
742 cache->start_rva
743 = extract_unsigned_integer (d.rva_BeginAddress, 4, byte_order);
744 cache->end_rva
745 = extract_unsigned_integer (d.rva_EndAddress, 4, byte_order);
746 unwind_info
747 = extract_unsigned_integer (d.rva_UnwindData, 4, byte_order);
750 while (1)
752 struct external_pex64_unwind_info ex_ui;
753 /* There are at most 256 16-bit unwind insns. */
754 gdb_byte insns[2 * 256];
755 gdb_byte *p;
756 gdb_byte *end_insns;
757 unsigned char codes_count;
758 unsigned char frame_reg;
759 CORE_ADDR start;
761 /* Read and decode header. */
762 if (target_read_memory (cache->image_base + unwind_info,
763 (gdb_byte *) &ex_ui, sizeof (ex_ui)) != 0)
764 return;
766 frame_debug_printf ("%s: ver: %02x, plgsz: %02x, cnt: %02x, frame: %02x",
767 paddress (gdbarch, unwind_info),
768 ex_ui.Version_Flags, ex_ui.SizeOfPrologue,
769 ex_ui.CountOfCodes, ex_ui.FrameRegisterOffset);
771 /* Check version. */
772 if (PEX64_UWI_VERSION (ex_ui.Version_Flags) != 1
773 && PEX64_UWI_VERSION (ex_ui.Version_Flags) != 2)
774 return;
776 start = cache->image_base + cache->start_rva;
777 if (first
778 && !(cache->pc >= start && cache->pc < start + ex_ui.SizeOfPrologue))
780 /* We want to detect if the PC points to an epilogue. This needs
781 to be checked only once, and an epilogue can be anywhere but in
782 the prologue. If so, the epilogue detection+decoding function is
783 sufficient. Otherwise, the unwinder will consider that the PC
784 is in the body of the function and will need to decode unwind
785 info. */
786 if (amd64_windows_frame_decode_epilogue (this_frame, cache) == 1)
787 return;
789 /* Not in an epilog. Clear possible side effects. */
790 memset (cache->prev_reg_addr, 0, sizeof (cache->prev_reg_addr));
793 codes_count = ex_ui.CountOfCodes;
794 frame_reg = PEX64_UWI_FRAMEREG (ex_ui.FrameRegisterOffset);
796 if (frame_reg != 0)
798 /* According to msdn:
799 If an FP reg is used, then any unwind code taking an offset must
800 only be used after the FP reg is established in the prolog. */
801 std::array<gdb_byte, 8> buf;
802 int frreg = amd64_windows_w2gdb_regnum[frame_reg];
804 get_frame_register (this_frame, frreg, buf);
805 save_addr = extract_unsigned_integer (buf, byte_order);
807 frame_debug_printf (" frame_reg=%s, val=%s",
808 gdbarch_register_name (gdbarch, frreg),
809 paddress (gdbarch, save_addr));
812 /* Read opcodes. */
813 if (codes_count != 0
814 && target_read_memory (cache->image_base + unwind_info
815 + sizeof (ex_ui),
816 insns, codes_count * 2) != 0)
817 return;
819 end_insns = &insns[codes_count * 2];
820 p = insns;
822 /* Skip opcodes 6 of version 2. This opcode is not documented. */
823 if (PEX64_UWI_VERSION (ex_ui.Version_Flags) == 2)
825 for (; p < end_insns; p += 2)
826 if (PEX64_UNWCODE_CODE (p[1]) != 6)
827 break;
830 for (; p < end_insns; p += 2)
832 int reg;
834 /* Virtually execute the operation if the pc is after the
835 corresponding instruction (that does matter in case of break
836 within the prologue). Note that for chained info (!first), the
837 prologue has been fully executed. */
838 if (cache->pc >= start + p[0] || cache->pc < start)
840 frame_debug_printf (" op #%u: off=0x%02x, insn=0x%02x",
841 (unsigned) (p - insns), p[0], p[1]);
843 /* If there is no frame registers defined, the current value of
844 rsp is used instead. */
845 if (frame_reg == 0)
846 save_addr = cur_sp;
848 reg = -1;
850 switch (PEX64_UNWCODE_CODE (p[1]))
852 case UWOP_PUSH_NONVOL:
853 /* Push pre-decrements RSP. */
854 reg = amd64_windows_w2gdb_regnum[PEX64_UNWCODE_INFO (p[1])];
855 cache->prev_reg_addr[reg] = cur_sp;
856 cur_sp += 8;
857 break;
858 case UWOP_ALLOC_LARGE:
859 if (PEX64_UNWCODE_INFO (p[1]) == 0)
860 cur_sp +=
861 8 * extract_unsigned_integer (p + 2, 2, byte_order);
862 else if (PEX64_UNWCODE_INFO (p[1]) == 1)
863 cur_sp += extract_unsigned_integer (p + 2, 4, byte_order);
864 else
865 return;
866 break;
867 case UWOP_ALLOC_SMALL:
868 cur_sp += 8 + 8 * PEX64_UNWCODE_INFO (p[1]);
869 break;
870 case UWOP_SET_FPREG:
871 cur_sp = save_addr
872 - PEX64_UWI_FRAMEOFF (ex_ui.FrameRegisterOffset) * 16;
873 break;
874 case UWOP_SAVE_NONVOL:
875 reg = amd64_windows_w2gdb_regnum[PEX64_UNWCODE_INFO (p[1])];
876 cache->prev_reg_addr[reg] = save_addr
877 + 8 * extract_unsigned_integer (p + 2, 2, byte_order);
878 break;
879 case UWOP_SAVE_NONVOL_FAR:
880 reg = amd64_windows_w2gdb_regnum[PEX64_UNWCODE_INFO (p[1])];
881 cache->prev_reg_addr[reg] = save_addr
882 + 8 * extract_unsigned_integer (p + 2, 4, byte_order);
883 break;
884 case UWOP_SAVE_XMM128:
885 cache->prev_xmm_addr[PEX64_UNWCODE_INFO (p[1])] =
886 save_addr
887 - 16 * extract_unsigned_integer (p + 2, 2, byte_order);
888 break;
889 case UWOP_SAVE_XMM128_FAR:
890 cache->prev_xmm_addr[PEX64_UNWCODE_INFO (p[1])] =
891 save_addr
892 - 16 * extract_unsigned_integer (p + 2, 4, byte_order);
893 break;
894 case UWOP_PUSH_MACHFRAME:
895 if (PEX64_UNWCODE_INFO (p[1]) == 0)
897 cache->prev_rip_addr = cur_sp + 0;
898 cache->prev_rsp_addr = cur_sp + 24;
899 cur_sp += 40;
901 else if (PEX64_UNWCODE_INFO (p[1]) == 1)
903 cache->prev_rip_addr = cur_sp + 8;
904 cache->prev_rsp_addr = cur_sp + 32;
905 cur_sp += 48;
907 else
908 return;
909 break;
910 default:
911 return;
914 /* Display address where the register was saved. */
915 if (reg >= 0)
916 frame_debug_printf (" [reg %s at %s]",
917 gdbarch_register_name (gdbarch, reg),
918 paddress (gdbarch,
919 cache->prev_reg_addr[reg]));
922 /* Adjust with the length of the opcode. */
923 switch (PEX64_UNWCODE_CODE (p[1]))
925 case UWOP_PUSH_NONVOL:
926 case UWOP_ALLOC_SMALL:
927 case UWOP_SET_FPREG:
928 case UWOP_PUSH_MACHFRAME:
929 break;
930 case UWOP_ALLOC_LARGE:
931 if (PEX64_UNWCODE_INFO (p[1]) == 0)
932 p += 2;
933 else if (PEX64_UNWCODE_INFO (p[1]) == 1)
934 p += 4;
935 else
936 return;
937 break;
938 case UWOP_SAVE_NONVOL:
939 case UWOP_SAVE_XMM128:
940 p += 2;
941 break;
942 case UWOP_SAVE_NONVOL_FAR:
943 case UWOP_SAVE_XMM128_FAR:
944 p += 4;
945 break;
946 default:
947 return;
950 if (PEX64_UWI_FLAGS (ex_ui.Version_Flags) != UNW_FLAG_CHAININFO)
952 /* End of unwind info. */
953 break;
955 else
957 /* Read the chained unwind info. */
958 struct external_pex64_runtime_function d;
959 CORE_ADDR chain_vma;
961 /* Not anymore the first entry. */
962 first = 0;
964 /* Stay aligned on word boundary. */
965 chain_vma = cache->image_base + unwind_info
966 + sizeof (ex_ui) + ((codes_count + 1) & ~1) * 2;
968 if (target_read_memory (chain_vma, (gdb_byte *) &d, sizeof (d)) != 0)
969 return;
971 /* Decode begin/end. This may be different from .pdata index, as
972 an unwind info may be shared by several functions (in particular
973 if many functions have the same prolog and handler. */
974 cache->start_rva =
975 extract_unsigned_integer (d.rva_BeginAddress, 4, byte_order);
976 cache->end_rva =
977 extract_unsigned_integer (d.rva_EndAddress, 4, byte_order);
978 unwind_info =
979 extract_unsigned_integer (d.rva_UnwindData, 4, byte_order);
981 frame_debug_printf ("next in chain: unwind_data=%s, start_rva=%s, "
982 "end_rva=%s",
983 paddress (gdbarch, unwind_info),
984 paddress (gdbarch, cache->start_rva),
985 paddress (gdbarch, cache->end_rva));
988 /* Allow the user to break this loop. */
989 QUIT;
991 /* PC is saved by the call. */
992 if (cache->prev_rip_addr == 0)
993 cache->prev_rip_addr = cur_sp;
994 cache->prev_sp = cur_sp + 8;
996 frame_debug_printf (" prev_sp: %s, prev_pc @%s",
997 paddress (gdbarch, cache->prev_sp),
998 paddress (gdbarch, cache->prev_rip_addr));
1001 /* Find SEH unwind info for PC, returning 0 on success.
1003 UNWIND_INFO is set to the rva of unwind info address, IMAGE_BASE
1004 to the base address of the corresponding image, and START_RVA
1005 to the rva of the function containing PC. */
1007 static int
1008 amd64_windows_find_unwind_info (struct gdbarch *gdbarch, CORE_ADDR pc,
1009 CORE_ADDR *unwind_info,
1010 CORE_ADDR *image_base,
1011 CORE_ADDR *start_rva,
1012 CORE_ADDR *end_rva)
1014 struct obj_section *sec;
1015 pe_data_type *pe;
1016 IMAGE_DATA_DIRECTORY *dir;
1017 struct objfile *objfile;
1018 unsigned long lo, hi;
1019 CORE_ADDR base;
1020 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1022 /* Get the corresponding exception directory. */
1023 sec = find_pc_section (pc);
1024 if (sec == NULL)
1025 return -1;
1026 objfile = sec->objfile;
1027 pe = pe_data (sec->objfile->obfd);
1028 dir = &pe->pe_opthdr.DataDirectory[PE_EXCEPTION_TABLE];
1030 base = pe->pe_opthdr.ImageBase + objfile->text_section_offset ();
1031 *image_base = base;
1033 /* Find the entry.
1035 Note: This does not handle dynamically added entries (for JIT
1036 engines). For this, we would need to ask the kernel directly,
1037 which means getting some info from the native layer. For the
1038 rest of the code, however, it's probably faster to search
1039 the entry ourselves. */
1040 lo = 0;
1041 hi = dir->Size / sizeof (struct external_pex64_runtime_function);
1042 *unwind_info = 0;
1043 while (lo <= hi)
1045 unsigned long mid = lo + (hi - lo) / 2;
1046 struct external_pex64_runtime_function d;
1047 CORE_ADDR sa, ea;
1049 if (target_read_memory (base + dir->VirtualAddress + mid * sizeof (d),
1050 (gdb_byte *) &d, sizeof (d)) != 0)
1051 return -1;
1053 sa = extract_unsigned_integer (d.rva_BeginAddress, 4, byte_order);
1054 ea = extract_unsigned_integer (d.rva_EndAddress, 4, byte_order);
1055 if (pc < base + sa)
1056 hi = mid - 1;
1057 else if (pc >= base + ea)
1058 lo = mid + 1;
1059 else if (pc >= base + sa && pc < base + ea)
1061 /* Got it. */
1062 *start_rva = sa;
1063 *end_rva = ea;
1064 *unwind_info =
1065 extract_unsigned_integer (d.rva_UnwindData, 4, byte_order);
1066 break;
1068 else
1069 break;
1072 frame_debug_printf ("image_base=%s, unwind_data=%s",
1073 paddress (gdbarch, base),
1074 paddress (gdbarch, *unwind_info));
1076 return 0;
1079 /* Fill THIS_CACHE using the native amd64-windows unwinding data
1080 for THIS_FRAME. */
1082 static struct amd64_windows_frame_cache *
1083 amd64_windows_frame_cache (const frame_info_ptr &this_frame, void **this_cache)
1085 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1086 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1087 struct amd64_windows_frame_cache *cache;
1088 std::array<gdb_byte, 8> buf;
1089 CORE_ADDR pc;
1090 CORE_ADDR unwind_info = 0;
1092 if (*this_cache)
1093 return (struct amd64_windows_frame_cache *) *this_cache;
1095 cache = FRAME_OBSTACK_ZALLOC (struct amd64_windows_frame_cache);
1096 *this_cache = cache;
1098 /* Get current PC and SP. */
1099 pc = get_frame_pc (this_frame);
1100 get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
1101 cache->sp = extract_unsigned_integer (buf, byte_order);
1102 cache->pc = pc;
1104 /* If we can't find the unwind info, keep trying as though this is a
1105 leaf function. This situation can happen when PC==0, see
1106 https://sourceware.org/bugzilla/show_bug.cgi?id=30255. */
1107 if (amd64_windows_find_unwind_info (gdbarch, pc, &unwind_info,
1108 &cache->image_base,
1109 &cache->start_rva,
1110 &cache->end_rva)
1111 || unwind_info == 0)
1113 /* Assume a leaf function. */
1114 cache->prev_sp = cache->sp + 8;
1115 cache->prev_rip_addr = cache->sp;
1117 else
1119 /* Decode unwind insns to compute saved addresses. */
1120 amd64_windows_frame_decode_insns (this_frame, cache, unwind_info);
1122 return cache;
1125 /* Implement the "prev_register" method of struct frame_unwind
1126 using the standard Windows x64 SEH info. */
1128 static struct value *
1129 amd64_windows_frame_prev_register (const frame_info_ptr &this_frame,
1130 void **this_cache, int regnum)
1132 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1133 struct amd64_windows_frame_cache *cache =
1134 amd64_windows_frame_cache (this_frame, this_cache);
1135 CORE_ADDR prev;
1137 frame_debug_printf ("%s for sp=%s",
1138 gdbarch_register_name (gdbarch, regnum),
1139 paddress (gdbarch, cache->prev_sp));
1141 if (regnum >= AMD64_XMM0_REGNUM && regnum <= AMD64_XMM0_REGNUM + 15)
1142 prev = cache->prev_xmm_addr[regnum - AMD64_XMM0_REGNUM];
1143 else if (regnum == AMD64_RSP_REGNUM)
1145 prev = cache->prev_rsp_addr;
1146 if (prev == 0)
1147 return frame_unwind_got_constant (this_frame, regnum, cache->prev_sp);
1149 else if (regnum >= AMD64_RAX_REGNUM && regnum <= AMD64_R15_REGNUM)
1150 prev = cache->prev_reg_addr[regnum - AMD64_RAX_REGNUM];
1151 else if (regnum == AMD64_RIP_REGNUM)
1152 prev = cache->prev_rip_addr;
1153 else
1154 prev = 0;
1156 if (prev != 0)
1157 frame_debug_printf (" -> at %s", paddress (gdbarch, prev));
1159 if (prev)
1161 /* Register was saved. */
1162 return frame_unwind_got_memory (this_frame, regnum, prev);
1164 else
1166 /* Register is either volatile or not modified. */
1167 return frame_unwind_got_register (this_frame, regnum, regnum);
1171 /* Implement the "this_id" method of struct frame_unwind using
1172 the standard Windows x64 SEH info. */
1174 static void
1175 amd64_windows_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
1176 struct frame_id *this_id)
1178 struct amd64_windows_frame_cache *cache =
1179 amd64_windows_frame_cache (this_frame, this_cache);
1181 *this_id = frame_id_build (cache->prev_sp,
1182 cache->image_base + cache->start_rva);
1185 /* Windows x64 SEH unwinder. */
1187 static const struct frame_unwind_legacy amd64_windows_frame_unwind (
1188 "amd64 windows",
1189 NORMAL_FRAME,
1190 FRAME_UNWIND_ARCH,
1191 default_frame_unwind_stop_reason,
1192 &amd64_windows_frame_this_id,
1193 &amd64_windows_frame_prev_register,
1194 NULL,
1195 default_frame_sniffer
1198 /* Implement the "skip_prologue" gdbarch method. */
1200 static CORE_ADDR
1201 amd64_windows_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1203 CORE_ADDR func_addr;
1204 CORE_ADDR unwind_info = 0;
1205 CORE_ADDR image_base, start_rva, end_rva;
1206 struct external_pex64_unwind_info ex_ui;
1208 /* Use prologue size from unwind info. */
1209 if (amd64_windows_find_unwind_info (gdbarch, pc, &unwind_info,
1210 &image_base, &start_rva, &end_rva) == 0)
1212 if (unwind_info == 0)
1214 /* Leaf function. */
1215 return pc;
1217 else if (target_read_memory (image_base + unwind_info,
1218 (gdb_byte *) &ex_ui, sizeof (ex_ui)) == 0
1219 && PEX64_UWI_VERSION (ex_ui.Version_Flags) == 1)
1220 return std::max (pc, image_base + start_rva + ex_ui.SizeOfPrologue);
1223 /* See if we can determine the end of the prologue via the symbol
1224 table. If so, then return either the PC, or the PC after
1225 the prologue, whichever is greater. */
1226 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
1228 CORE_ADDR post_prologue_pc
1229 = skip_prologue_using_sal (gdbarch, func_addr);
1231 if (post_prologue_pc != 0)
1232 return std::max (pc, post_prologue_pc);
1235 return pc;
1238 /* Check Win64 DLL jmp trampolines and find jump destination. */
1240 static CORE_ADDR
1241 amd64_windows_skip_trampoline_code (const frame_info_ptr &frame, CORE_ADDR pc)
1243 CORE_ADDR destination = 0;
1244 struct gdbarch *gdbarch = get_frame_arch (frame);
1245 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1247 /* Check for jmp *<offset>(%rip) (jump near, absolute indirect (/4)). */
1248 if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
1250 /* Get opcode offset and see if we can find a reference in our data. */
1251 ULONGEST offset
1252 = read_memory_unsigned_integer (pc + 2, 4, byte_order);
1254 /* Get address of function pointer at end of pc. */
1255 CORE_ADDR indirect_addr = pc + offset + 6;
1257 struct minimal_symbol *indsym
1258 = (indirect_addr
1259 ? lookup_minimal_symbol_by_pc (indirect_addr).minsym
1260 : NULL);
1261 const char *symname = indsym ? indsym->linkage_name () : NULL;
1263 if (symname)
1265 if (startswith (symname, "__imp_")
1266 || startswith (symname, "_imp_"))
1267 destination
1268 = read_memory_unsigned_integer (indirect_addr, 8, byte_order);
1272 return destination;
1275 /* Implement the "auto_wide_charset" gdbarch method. */
1277 static const char *
1278 amd64_windows_auto_wide_charset (void)
1280 return "UTF-16";
1283 /* Common parts for gdbarch initialization for Windows and Cygwin on AMD64. */
1285 static void
1286 amd64_windows_init_abi_common (gdbarch_info info, struct gdbarch *gdbarch)
1288 i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch);
1290 /* The dwarf2 unwinder (appended very early by i386_gdbarch_init) is
1291 preferred over the SEH one. The reasons are:
1292 - binaries without SEH but with dwarf2 debug info are correctly handled
1293 (although they aren't ABI compliant, gcc before 4.7 didn't emit SEH
1294 info).
1295 - dwarf3 DW_OP_call_frame_cfa is correctly handled (it can only be
1296 handled if the dwarf2 unwinder is used).
1298 The call to amd64_init_abi appends default unwinders, that aren't
1299 compatible with the SEH one.
1301 frame_unwind_append_unwinder (gdbarch, &amd64_windows_frame_unwind);
1303 amd64_init_abi (info, gdbarch,
1304 amd64_target_description (X86_XSTATE_SSE_MASK, false));
1306 /* Function calls. */
1307 set_gdbarch_push_dummy_call (gdbarch, amd64_windows_push_dummy_call);
1308 set_gdbarch_return_value_as_value (gdbarch, amd64_windows_return_value);
1309 set_gdbarch_skip_main_prologue (gdbarch, amd64_skip_main_prologue);
1310 set_gdbarch_skip_trampoline_code (gdbarch,
1311 amd64_windows_skip_trampoline_code);
1313 set_gdbarch_skip_prologue (gdbarch, amd64_windows_skip_prologue);
1315 tdep->gregset_reg_offset = amd64_windows_gregset_reg_offset;
1316 tdep->gregset_num_regs = ARRAY_SIZE (amd64_windows_gregset_reg_offset);
1317 tdep->sizeof_gregset = AMD64_WINDOWS_SIZEOF_GREGSET;
1318 tdep->sizeof_fpregset = 0;
1320 /* Core file support. */
1321 set_gdbarch_core_xfer_shared_libraries
1322 (gdbarch, windows_core_xfer_shared_libraries);
1323 set_gdbarch_core_pid_to_str (gdbarch, windows_core_pid_to_str);
1325 set_gdbarch_auto_wide_charset (gdbarch, amd64_windows_auto_wide_charset);
1328 /* gdbarch initialization for Windows on AMD64. */
1330 static void
1331 amd64_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1333 amd64_windows_init_abi_common (info, gdbarch);
1334 windows_init_abi (info, gdbarch);
1336 /* On Windows, "long"s are only 32bit. */
1337 set_gdbarch_long_bit (gdbarch, 32);
1340 /* Sigwrapper unwinder instruction patterns for AMD64. */
1342 static const gdb_byte amd64_sigbe_bytes[] = {
1343 0x49, 0xc7, 0xc3, 0xf8, 0xff, 0xff, 0xff, /* movq $-8,%r11 */
1344 0x4d, 0x0f, 0xc1, 0x9a, /* xaddq %r11,$tls::stackptr(%r10) */
1345 /* 4 bytes for tls::stackptr operand. */
1348 static const gdb_byte amd64_sigdelayed_bytes[] = {
1349 0x49, 0xc7, 0xc3, 0xf8, 0xff, 0xff, 0xff, /* movq $-8,%r11 */
1350 0x4d, 0x0f, 0xc1, 0x9c, 0x24, /* xaddq %r11,$tls::stackptr(%r12) */
1351 /* 4 bytes for tls::stackptr operand. */
1354 static const gdb::array_view<const gdb_byte> amd64_sig_patterns[] {
1355 { amd64_sigbe_bytes },
1356 { amd64_sigdelayed_bytes },
1359 /* The sigwrapper unwinder on AMD64. */
1361 static const cygwin_sigwrapper_frame_unwind
1362 amd64_cygwin_sigwrapper_frame_unwind (amd64_sig_patterns);
1364 /* gdbarch initialization for Cygwin on AMD64. */
1366 static void
1367 amd64_cygwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1369 frame_unwind_append_unwinder (gdbarch, &amd64_cygwin_sigwrapper_frame_unwind);
1371 amd64_windows_init_abi_common (info, gdbarch);
1372 cygwin_init_abi (info, gdbarch);
1375 static gdb_osabi
1376 amd64_windows_osabi_sniffer (bfd *abfd)
1378 const char *target_name = bfd_get_target (abfd);
1380 if (!streq (target_name, "pei-x86-64"))
1381 return GDB_OSABI_UNKNOWN;
1383 if (is_linked_with_cygwin_dll (abfd))
1384 return GDB_OSABI_CYGWIN;
1386 return GDB_OSABI_WINDOWS;
1389 static enum gdb_osabi
1390 amd64_cygwin_core_osabi_sniffer (bfd *abfd)
1392 const char *target_name = bfd_get_target (abfd);
1394 /* Cygwin uses elf core dumps. Do not claim all ELF executables,
1395 check whether there is a .reg section of proper size. */
1396 if (strcmp (target_name, "elf64-x86-64") == 0)
1398 asection *section = bfd_get_section_by_name (abfd, ".reg");
1399 if (section != nullptr
1400 && bfd_section_size (section) == AMD64_WINDOWS_SIZEOF_GREGSET)
1401 return GDB_OSABI_CYGWIN;
1404 return GDB_OSABI_UNKNOWN;
1407 void _initialize_amd64_windows_tdep ();
1408 void
1409 _initialize_amd64_windows_tdep ()
1411 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_WINDOWS,
1412 amd64_windows_init_abi);
1413 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_CYGWIN,
1414 amd64_cygwin_init_abi);
1416 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour,
1417 amd64_windows_osabi_sniffer);
1419 /* Cygwin uses elf core dumps. */
1420 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
1421 amd64_cygwin_core_osabi_sniffer);