1 /* Copyright (C) 2008-2020 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/>. */
19 #include "windows-tdep.h"
20 #include "gdb_obstack.h"
21 #include "xml-support.h"
28 #include "gdbthread.h"
31 #include "coff-pe-read.h"
33 #include "complaints.h"
35 #include "solib-target.h"
38 /* Windows signal numbers differ between MinGW flavors and between
39 those and Cygwin. The below enumeration was gleaned from the
40 respective headers; the ones marked with MinGW64/Cygwin are defined
41 only by MinGW64 and Cygwin, not by mingw.org's MinGW. FIXME: We
42 should really have distinct MinGW vs Cygwin OSABIs, and two
43 separate enums, selected at runtime. */
47 WINDOWS_SIGHUP
= 1, /* MinGW64/Cygwin */
49 WINDOWS_SIGQUIT
= 3, /* MinGW64/Cygwin */
51 WINDOWS_SIGTRAP
= 5, /* MinGW64/Cygwin */
55 WINDOWS_SIGIOT
= 6, /* MinGW64 */
57 WINDOWS_SIGEMT
= 7, /* MinGW64/Cygwin */
59 WINDOWS_SIGKILL
= 9, /* MinGW64/Cygwin */
60 WINDOWS_SIGBUS
= 10, /* MinGW64/Cygwin */
62 WINDOWS_SIGSYS
= 12, /* MinGW64/Cygwin */
63 WINDOWS_SIGPIPE
= 13,/* MinGW64/Cygwin */
64 WINDOWS_SIGALRM
= 14,/* MinGW64/Cygwin */
77 WINDOWS_SIGVTALRM
= 26,
79 WINDOWS_SIGWINCH
= 28,
84 WINDOWS_SIGBREAK
= 21,
89 struct cmd_list_element
*info_w32_cmdlist
;
91 typedef struct thread_information_block_32
93 uint32_t current_seh
; /* %fs:0x0000 */
94 uint32_t current_top_of_stack
; /* %fs:0x0004 */
95 uint32_t current_bottom_of_stack
; /* %fs:0x0008 */
96 uint32_t sub_system_tib
; /* %fs:0x000c */
97 uint32_t fiber_data
; /* %fs:0x0010 */
98 uint32_t arbitrary_data_slot
; /* %fs:0x0014 */
99 uint32_t linear_address_tib
; /* %fs:0x0018 */
100 uint32_t environment_pointer
; /* %fs:0x001c */
101 uint32_t process_id
; /* %fs:0x0020 */
102 uint32_t current_thread_id
; /* %fs:0x0024 */
103 uint32_t active_rpc_handle
; /* %fs:0x0028 */
104 uint32_t thread_local_storage
; /* %fs:0x002c */
105 uint32_t process_environment_block
; /* %fs:0x0030 */
106 uint32_t last_error_number
; /* %fs:0x0034 */
108 thread_information_32
;
110 typedef struct thread_information_block_64
112 uint64_t current_seh
; /* %gs:0x0000 */
113 uint64_t current_top_of_stack
; /* %gs:0x0008 */
114 uint64_t current_bottom_of_stack
; /* %gs:0x0010 */
115 uint64_t sub_system_tib
; /* %gs:0x0018 */
116 uint64_t fiber_data
; /* %gs:0x0020 */
117 uint64_t arbitrary_data_slot
; /* %gs:0x0028 */
118 uint64_t linear_address_tib
; /* %gs:0x0030 */
119 uint64_t environment_pointer
; /* %gs:0x0038 */
120 uint64_t process_id
; /* %gs:0x0040 */
121 uint64_t current_thread_id
; /* %gs:0x0048 */
122 uint64_t active_rpc_handle
; /* %gs:0x0050 */
123 uint64_t thread_local_storage
; /* %gs:0x0058 */
124 uint64_t process_environment_block
; /* %gs:0x0060 */
125 uint64_t last_error_number
; /* %gs:0x0068 */
127 thread_information_64
;
130 static const char* TIB_NAME
[] =
132 " current_seh ", /* %fs:0x0000 */
133 " current_top_of_stack ", /* %fs:0x0004 */
134 " current_bottom_of_stack ", /* %fs:0x0008 */
135 " sub_system_tib ", /* %fs:0x000c */
136 " fiber_data ", /* %fs:0x0010 */
137 " arbitrary_data_slot ", /* %fs:0x0014 */
138 " linear_address_tib ", /* %fs:0x0018 */
139 " environment_pointer ", /* %fs:0x001c */
140 " process_id ", /* %fs:0x0020 */
141 " current_thread_id ", /* %fs:0x0024 */
142 " active_rpc_handle ", /* %fs:0x0028 */
143 " thread_local_storage ", /* %fs:0x002c */
144 " process_environment_block ", /* %fs:0x0030 */
145 " last_error_number " /* %fs:0x0034 */
148 static const int MAX_TIB32
=
149 sizeof (thread_information_32
) / sizeof (uint32_t);
150 static const int MAX_TIB64
=
151 sizeof (thread_information_64
) / sizeof (uint64_t);
152 static const int FULL_TIB_SIZE
= 0x1000;
154 static bool maint_display_all_tib
= false;
156 static struct gdbarch_data
*windows_gdbarch_data_handle
;
158 struct windows_gdbarch_data
160 struct type
*siginfo_type
;
161 struct type
*tib_ptr_type
; /* Type of thread information block */
164 /* Allocate windows_gdbarch_data for an arch. */
167 init_windows_gdbarch_data (struct gdbarch
*gdbarch
)
169 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct windows_gdbarch_data
);
172 /* Get windows_gdbarch_data of an arch. */
174 static struct windows_gdbarch_data
*
175 get_windows_gdbarch_data (struct gdbarch
*gdbarch
)
177 return ((struct windows_gdbarch_data
*)
178 gdbarch_data (gdbarch
, windows_gdbarch_data_handle
));
181 /* Define Thread Local Base pointer type. */
184 windows_get_tlb_type (struct gdbarch
*gdbarch
)
186 struct type
*dword_ptr_type
, *dword32_type
, *void_ptr_type
;
187 struct type
*peb_ldr_type
, *peb_ldr_ptr_type
;
188 struct type
*peb_type
, *peb_ptr_type
, *list_type
;
189 struct type
*module_list_ptr_type
;
190 struct type
*tib_type
, *seh_type
, *tib_ptr_type
, *seh_ptr_type
;
191 struct type
*word_type
, *wchar_type
, *wchar_ptr_type
;
192 struct type
*uni_str_type
, *rupp_type
, *rupp_ptr_type
;
194 windows_gdbarch_data
*windows_gdbarch_data
195 = get_windows_gdbarch_data (gdbarch
);
196 if (windows_gdbarch_data
->tib_ptr_type
!= nullptr)
197 return windows_gdbarch_data
->tib_ptr_type
;
199 dword_ptr_type
= arch_integer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
201 dword32_type
= arch_integer_type (gdbarch
, 32,
203 word_type
= arch_integer_type (gdbarch
, 16,
205 wchar_type
= arch_integer_type (gdbarch
, 16,
207 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
208 wchar_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
213 list_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
214 TYPE_NAME (list_type
) = xstrdup ("list");
216 module_list_ptr_type
= void_ptr_type
;
218 append_composite_type_field (list_type
, "forward_list",
219 module_list_ptr_type
);
220 append_composite_type_field (list_type
, "backward_list",
221 module_list_ptr_type
);
223 /* Structured Exception Handler */
225 seh_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
226 TYPE_NAME (seh_type
) = xstrdup ("seh");
228 seh_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
229 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
231 TYPE_TARGET_TYPE (seh_ptr_type
) = seh_type
;
233 append_composite_type_field (seh_type
, "next_seh", seh_ptr_type
);
234 append_composite_type_field (seh_type
, "handler",
235 builtin_type (gdbarch
)->builtin_func_ptr
);
237 /* struct _PEB_LDR_DATA */
238 peb_ldr_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
239 TYPE_NAME (peb_ldr_type
) = xstrdup ("peb_ldr_data");
241 append_composite_type_field (peb_ldr_type
, "length", dword32_type
);
242 append_composite_type_field (peb_ldr_type
, "initialized", dword32_type
);
243 append_composite_type_field (peb_ldr_type
, "ss_handle", void_ptr_type
);
244 append_composite_type_field (peb_ldr_type
, "in_load_order", list_type
);
245 append_composite_type_field (peb_ldr_type
, "in_memory_order", list_type
);
246 append_composite_type_field (peb_ldr_type
, "in_init_order", list_type
);
247 append_composite_type_field (peb_ldr_type
, "entry_in_progress",
249 peb_ldr_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
250 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
252 TYPE_TARGET_TYPE (peb_ldr_ptr_type
) = peb_ldr_type
;
254 /* struct UNICODE_STRING */
255 uni_str_type
= arch_composite_type (gdbarch
, "unicode_string",
258 append_composite_type_field (uni_str_type
, "length", word_type
);
259 append_composite_type_field (uni_str_type
, "maximum_length", word_type
);
260 append_composite_type_field_aligned (uni_str_type
, "buffer",
262 TYPE_LENGTH (wchar_ptr_type
));
264 /* struct _RTL_USER_PROCESS_PARAMETERS */
265 rupp_type
= arch_composite_type (gdbarch
, "rtl_user_process_parameters",
268 append_composite_type_field (rupp_type
, "maximum_length", dword32_type
);
269 append_composite_type_field (rupp_type
, "length", dword32_type
);
270 append_composite_type_field (rupp_type
, "flags", dword32_type
);
271 append_composite_type_field (rupp_type
, "debug_flags", dword32_type
);
272 append_composite_type_field (rupp_type
, "console_handle", void_ptr_type
);
273 append_composite_type_field (rupp_type
, "console_flags", dword32_type
);
274 append_composite_type_field_aligned (rupp_type
, "standard_input",
276 TYPE_LENGTH (void_ptr_type
));
277 append_composite_type_field (rupp_type
, "standard_output", void_ptr_type
);
278 append_composite_type_field (rupp_type
, "standard_error", void_ptr_type
);
279 append_composite_type_field (rupp_type
, "current_directory", uni_str_type
);
280 append_composite_type_field (rupp_type
, "current_directory_handle",
282 append_composite_type_field (rupp_type
, "dll_path", uni_str_type
);
283 append_composite_type_field (rupp_type
, "image_path_name", uni_str_type
);
284 append_composite_type_field (rupp_type
, "command_line", uni_str_type
);
285 append_composite_type_field (rupp_type
, "environment", void_ptr_type
);
286 append_composite_type_field (rupp_type
, "starting_x", dword32_type
);
287 append_composite_type_field (rupp_type
, "starting_y", dword32_type
);
288 append_composite_type_field (rupp_type
, "count_x", dword32_type
);
289 append_composite_type_field (rupp_type
, "count_y", dword32_type
);
290 append_composite_type_field (rupp_type
, "count_chars_x", dword32_type
);
291 append_composite_type_field (rupp_type
, "count_chars_y", dword32_type
);
292 append_composite_type_field (rupp_type
, "fill_attribute", dword32_type
);
293 append_composite_type_field (rupp_type
, "window_flags", dword32_type
);
294 append_composite_type_field (rupp_type
, "show_window_flags", dword32_type
);
295 append_composite_type_field_aligned (rupp_type
, "window_title",
297 TYPE_LENGTH (void_ptr_type
));
298 append_composite_type_field (rupp_type
, "desktop_info", uni_str_type
);
299 append_composite_type_field (rupp_type
, "shell_info", uni_str_type
);
300 append_composite_type_field (rupp_type
, "runtime_data", uni_str_type
);
302 rupp_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
306 /* struct process environment block */
307 peb_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
308 TYPE_NAME (peb_type
) = xstrdup ("peb");
310 /* First bytes contain several flags. */
311 append_composite_type_field (peb_type
, "flags", dword_ptr_type
);
312 append_composite_type_field (peb_type
, "mutant", void_ptr_type
);
313 append_composite_type_field (peb_type
, "image_base_address", void_ptr_type
);
314 append_composite_type_field (peb_type
, "ldr", peb_ldr_ptr_type
);
315 append_composite_type_field (peb_type
, "process_parameters", rupp_ptr_type
);
316 append_composite_type_field (peb_type
, "sub_system_data", void_ptr_type
);
317 append_composite_type_field (peb_type
, "process_heap", void_ptr_type
);
318 append_composite_type_field (peb_type
, "fast_peb_lock", void_ptr_type
);
319 peb_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
320 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
322 TYPE_TARGET_TYPE (peb_ptr_type
) = peb_type
;
325 /* struct thread information block */
326 tib_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
327 TYPE_NAME (tib_type
) = xstrdup ("tib");
329 /* uint32_t current_seh; %fs:0x0000 */
330 append_composite_type_field (tib_type
, "current_seh", seh_ptr_type
);
331 /* uint32_t current_top_of_stack; %fs:0x0004 */
332 append_composite_type_field (tib_type
, "current_top_of_stack",
334 /* uint32_t current_bottom_of_stack; %fs:0x0008 */
335 append_composite_type_field (tib_type
, "current_bottom_of_stack",
337 /* uint32_t sub_system_tib; %fs:0x000c */
338 append_composite_type_field (tib_type
, "sub_system_tib", void_ptr_type
);
340 /* uint32_t fiber_data; %fs:0x0010 */
341 append_composite_type_field (tib_type
, "fiber_data", void_ptr_type
);
342 /* uint32_t arbitrary_data_slot; %fs:0x0014 */
343 append_composite_type_field (tib_type
, "arbitrary_data_slot", void_ptr_type
);
344 /* uint32_t linear_address_tib; %fs:0x0018 */
345 append_composite_type_field (tib_type
, "linear_address_tib", void_ptr_type
);
346 /* uint32_t environment_pointer; %fs:0x001c */
347 append_composite_type_field (tib_type
, "environment_pointer", void_ptr_type
);
348 /* uint32_t process_id; %fs:0x0020 */
349 append_composite_type_field (tib_type
, "process_id", dword_ptr_type
);
350 /* uint32_t current_thread_id; %fs:0x0024 */
351 append_composite_type_field (tib_type
, "thread_id", dword_ptr_type
);
352 /* uint32_t active_rpc_handle; %fs:0x0028 */
353 append_composite_type_field (tib_type
, "active_rpc_handle", dword_ptr_type
);
354 /* uint32_t thread_local_storage; %fs:0x002c */
355 append_composite_type_field (tib_type
, "thread_local_storage",
357 /* uint32_t process_environment_block; %fs:0x0030 */
358 append_composite_type_field (tib_type
, "process_environment_block",
360 /* uint32_t last_error_number; %fs:0x0034 */
361 append_composite_type_field (tib_type
, "last_error_number", dword_ptr_type
);
363 tib_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
364 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
366 TYPE_TARGET_TYPE (tib_ptr_type
) = tib_type
;
368 windows_gdbarch_data
->tib_ptr_type
= tib_ptr_type
;
373 /* The $_tlb convenience variable is a bit special. We don't know
374 for sure the type of the value until we actually have a chance to
375 fetch the data. The type can change depending on gdbarch, so it is
376 also dependent on which thread you have selected. */
378 /* This function implements the lval_computed support for reading a
382 tlb_value_read (struct value
*val
)
385 struct type
*type
= check_typedef (value_type (val
));
387 if (!target_get_tib_address (inferior_ptid
, &tlb
))
388 error (_("Unable to read tlb"));
389 store_typed_address (value_contents_raw (val
), type
, tlb
);
392 /* This function implements the lval_computed support for writing a
396 tlb_value_write (struct value
*v
, struct value
*fromval
)
398 error (_("Impossible to change the Thread Local Base"));
401 static const struct lval_funcs tlb_value_funcs
=
408 /* Return a new value with the correct type for the tlb object of
409 the current thread using architecture GDBARCH. Return a void value
410 if there's no object available. */
412 static struct value
*
413 tlb_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
, void *ignore
)
415 if (target_has_stack
&& inferior_ptid
!= null_ptid
)
417 struct type
*type
= windows_get_tlb_type (gdbarch
);
418 return allocate_computed_value (type
, &tlb_value_funcs
, NULL
);
421 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
425 /* Display thread information block of a given thread. */
428 display_one_tib (ptid_t ptid
)
430 gdb_byte
*tib
= NULL
;
432 CORE_ADDR thread_local_base
;
433 ULONGEST i
, val
, max
, max_name
, size
, tib_size
;
434 ULONGEST sizeof_ptr
= gdbarch_ptr_bit (target_gdbarch ());
435 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
437 if (sizeof_ptr
== 64)
439 size
= sizeof (uint64_t);
440 tib_size
= sizeof (thread_information_64
);
445 size
= sizeof (uint32_t);
446 tib_size
= sizeof (thread_information_32
);
452 if (maint_display_all_tib
)
454 tib_size
= FULL_TIB_SIZE
;
455 max
= tib_size
/ size
;
458 tib
= (gdb_byte
*) alloca (tib_size
);
460 if (target_get_tib_address (ptid
, &thread_local_base
) == 0)
462 printf_filtered (_("Unable to get thread local base for %s\n"),
463 target_pid_to_str (ptid
).c_str ());
467 if (target_read (current_top_target (), TARGET_OBJECT_MEMORY
,
468 NULL
, tib
, thread_local_base
, tib_size
) != tib_size
)
470 printf_filtered (_("Unable to read thread information "
471 "block for %s at address %s\n"),
472 target_pid_to_str (ptid
).c_str (),
473 paddress (target_gdbarch (), thread_local_base
));
477 printf_filtered (_("Thread Information Block %s at %s\n"),
478 target_pid_to_str (ptid
).c_str (),
479 paddress (target_gdbarch (), thread_local_base
));
481 index
= (gdb_byte
*) tib
;
483 /* All fields have the size of a pointer, this allows to iterate
484 using the same for loop for both layouts. */
485 for (i
= 0; i
< max
; i
++)
487 val
= extract_unsigned_integer (index
, size
, byte_order
);
489 printf_filtered (_("%s is 0x%s\n"), TIB_NAME
[i
], phex (val
, size
));
491 printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i
* size
, 2),
498 /* Display thread information block of the current thread. */
501 display_tib (const char * args
, int from_tty
)
503 if (inferior_ptid
!= null_ptid
)
504 display_one_tib (inferior_ptid
);
508 windows_xfer_shared_library (const char* so_name
, CORE_ADDR load_addr
,
509 CORE_ADDR
*text_offset_cached
,
510 struct gdbarch
*gdbarch
, struct obstack
*obstack
)
512 CORE_ADDR text_offset
= text_offset_cached
? *text_offset_cached
: 0;
514 obstack_grow_str (obstack
, "<library name=\"");
515 std::string p
= xml_escape_text (so_name
);
516 obstack_grow_str (obstack
, p
.c_str ());
517 obstack_grow_str (obstack
, "\"><segment address=\"");
521 gdb_bfd_ref_ptr
dll (gdb_bfd_open (so_name
, gnutarget
, -1));
522 /* The following calls are OK even if dll is NULL.
523 The default value 0x1000 is returned by pe_text_section_offset
525 text_offset
= pe_text_section_offset (dll
.get ());
526 if (text_offset_cached
)
527 *text_offset_cached
= text_offset
;
530 obstack_grow_str (obstack
, paddress (gdbarch
, load_addr
+ text_offset
));
531 obstack_grow_str (obstack
, "\"/></library>");
534 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
535 method. It searches all objfiles, starting with CURRENT_OBJFILE
538 On Windows, the system behaves a little differently when two
539 objfiles each define a global symbol using the same name, compared
540 to other platforms such as GNU/Linux for instance. On GNU/Linux,
541 all instances of the symbol effectively get merged into a single
542 one, but on Windows, they remain distinct.
544 As a result, it usually makes sense to start global symbol searches
545 with the current objfile before expanding it to all other objfiles.
546 This helps for instance when a user debugs some code in a DLL that
547 refers to a global variable defined inside that DLL. When trying
548 to print the value of that global variable, it would be unhelpful
549 to print the value of another global variable defined with the same
550 name, but in a different DLL. */
553 windows_iterate_over_objfiles_in_search_order
554 (struct gdbarch
*gdbarch
,
555 iterate_over_objfiles_in_search_order_cb_ftype
*cb
,
556 void *cb_data
, struct objfile
*current_objfile
)
562 stop
= cb (current_objfile
, cb_data
);
567 for (objfile
*objfile
: current_program_space
->objfiles ())
569 if (objfile
!= current_objfile
)
571 stop
= cb (objfile
, cb_data
);
579 show_maint_show_all_tib (struct ui_file
*file
, int from_tty
,
580 struct cmd_list_element
*c
, const char *value
)
582 fprintf_filtered (file
, _("Show all non-zero elements of "
583 "Thread Information Block is %s.\n"), value
);
587 info_w32_command (const char *args
, int from_tty
)
589 help_list (info_w32_cmdlist
, "info w32 ", class_info
, gdb_stdout
);
592 static int w32_prefix_command_valid
= 0;
594 init_w32_command_list (void)
596 if (!w32_prefix_command_valid
)
598 add_prefix_cmd ("w32", class_info
, info_w32_command
,
599 _("Print information specific to Win32 debugging."),
600 &info_w32_cmdlist
, "info w32 ", 0, &infolist
);
601 w32_prefix_command_valid
= 1;
605 /* Implementation of `gdbarch_gdb_signal_to_target'. */
608 windows_gdb_signal_to_target (struct gdbarch
*gdbarch
, enum gdb_signal signal
)
615 return WINDOWS_SIGHUP
;
617 return WINDOWS_SIGINT
;
618 case GDB_SIGNAL_QUIT
:
619 return WINDOWS_SIGQUIT
;
621 return WINDOWS_SIGILL
;
622 case GDB_SIGNAL_TRAP
:
623 return WINDOWS_SIGTRAP
;
624 case GDB_SIGNAL_ABRT
:
625 return WINDOWS_SIGABRT
;
627 return WINDOWS_SIGEMT
;
629 return WINDOWS_SIGFPE
;
630 case GDB_SIGNAL_KILL
:
631 return WINDOWS_SIGKILL
;
633 return WINDOWS_SIGBUS
;
634 case GDB_SIGNAL_SEGV
:
635 return WINDOWS_SIGSEGV
;
637 return WINDOWS_SIGSYS
;
638 case GDB_SIGNAL_PIPE
:
639 return WINDOWS_SIGPIPE
;
640 case GDB_SIGNAL_ALRM
:
641 return WINDOWS_SIGALRM
;
642 case GDB_SIGNAL_TERM
:
643 return WINDOWS_SIGTERM
;
646 return WINDOWS_SIGURG
;
647 case GDB_SIGNAL_STOP
:
648 return WINDOWS_SIGSTOP
;
649 case GDB_SIGNAL_TSTP
:
650 return WINDOWS_SIGTSTP
;
651 case GDB_SIGNAL_CONT
:
652 return WINDOWS_SIGCONT
;
653 case GDB_SIGNAL_CHLD
:
654 return WINDOWS_SIGCHLD
;
655 case GDB_SIGNAL_TTIN
:
656 return WINDOWS_SIGTTIN
;
657 case GDB_SIGNAL_TTOU
:
658 return WINDOWS_SIGTTOU
;
660 return WINDOWS_SIGIO
;
661 case GDB_SIGNAL_XCPU
:
662 return WINDOWS_SIGXCPU
;
663 case GDB_SIGNAL_XFSZ
:
664 return WINDOWS_SIGXFSZ
;
665 case GDB_SIGNAL_VTALRM
:
666 return WINDOWS_SIGVTALRM
;
667 case GDB_SIGNAL_PROF
:
668 return WINDOWS_SIGPROF
;
669 case GDB_SIGNAL_WINCH
:
670 return WINDOWS_SIGWINCH
;
672 return WINDOWS_SIGLOST
;
673 case GDB_SIGNAL_USR1
:
674 return WINDOWS_SIGUSR1
;
675 case GDB_SIGNAL_USR2
:
676 return WINDOWS_SIGUSR2
;
677 #endif /* __CYGWIN__ */
682 struct enum_value_name
688 /* Allocate a TYPE_CODE_ENUM type structure with its named values. */
691 create_enum (struct gdbarch
*gdbarch
, int bit
, const char *name
,
692 const struct enum_value_name
*values
, int count
)
697 type
= arch_type (gdbarch
, TYPE_CODE_ENUM
, bit
, name
);
698 TYPE_NFIELDS (type
) = count
;
699 TYPE_FIELDS (type
) = (struct field
*)
700 TYPE_ZALLOC (type
, sizeof (struct field
) * count
);
701 TYPE_UNSIGNED (type
) = 1;
703 for (i
= 0; i
< count
; i
++)
705 TYPE_FIELD_NAME (type
, i
) = values
[i
].name
;
706 SET_FIELD_ENUMVAL (TYPE_FIELD (type
, i
), values
[i
].value
);
712 static const struct enum_value_name exception_values
[] =
714 { 0x40000015, "FATAL_APP_EXIT" },
715 { 0x40010005, "DBG_CONTROL_C" },
716 { 0x40010008, "DBG_CONTROL_BREAK" },
717 { 0x80000002, "DATATYPE_MISALIGNMENT" },
718 { 0x80000003, "BREAKPOINT" },
719 { 0x80000004, "SINGLE_STEP" },
720 { 0xC0000005, "ACCESS_VIOLATION" },
721 { 0xC0000006, "IN_PAGE_ERROR" },
722 { 0xC000001D, "ILLEGAL_INSTRUCTION" },
723 { 0xC0000025, "NONCONTINUABLE_EXCEPTION" },
724 { 0xC0000026, "INVALID_DISPOSITION" },
725 { 0xC000008C, "ARRAY_BOUNDS_EXCEEDED" },
726 { 0xC000008D, "FLOAT_DENORMAL_OPERAND" },
727 { 0xC000008E, "FLOAT_DIVIDE_BY_ZERO" },
728 { 0xC000008F, "FLOAT_INEXACT_RESULT" },
729 { 0xC0000090, "FLOAT_INVALID_OPERATION" },
730 { 0xC0000091, "FLOAT_OVERFLOW" },
731 { 0xC0000092, "FLOAT_STACK_CHECK" },
732 { 0xC0000093, "FLOAT_UNDERFLOW" },
733 { 0xC0000094, "INTEGER_DIVIDE_BY_ZERO" },
734 { 0xC0000095, "INTEGER_OVERFLOW" },
735 { 0xC0000096, "PRIV_INSTRUCTION" },
736 { 0xC00000FD, "STACK_OVERFLOW" },
737 { 0xC0000409, "FAST_FAIL" },
740 static const struct enum_value_name violation_values
[] =
742 { 0, "READ_ACCESS_VIOLATION" },
743 { 1, "WRITE_ACCESS_VIOLATION" },
744 { 8, "DATA_EXECUTION_PREVENTION_VIOLATION" },
747 /* Implement the "get_siginfo_type" gdbarch method. */
750 windows_get_siginfo_type (struct gdbarch
*gdbarch
)
752 struct windows_gdbarch_data
*windows_gdbarch_data
;
753 struct type
*dword_type
, *pvoid_type
, *ulongptr_type
;
754 struct type
*code_enum
, *violation_enum
;
755 struct type
*violation_type
, *para_type
, *siginfo_ptr_type
, *siginfo_type
;
757 windows_gdbarch_data
= get_windows_gdbarch_data (gdbarch
);
758 if (windows_gdbarch_data
->siginfo_type
!= NULL
)
759 return windows_gdbarch_data
->siginfo_type
;
761 dword_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
763 pvoid_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
), "PVOID",
764 builtin_type (gdbarch
)->builtin_void
);
765 ulongptr_type
= arch_integer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
768 /* ExceptionCode value names */
769 code_enum
= create_enum (gdbarch
, gdbarch_int_bit (gdbarch
),
770 "ExceptionCode", exception_values
,
771 ARRAY_SIZE (exception_values
));
773 /* ACCESS_VIOLATION type names */
774 violation_enum
= create_enum (gdbarch
, gdbarch_ptr_bit (gdbarch
),
775 "ViolationType", violation_values
,
776 ARRAY_SIZE (violation_values
));
778 /* ACCESS_VIOLATION information */
779 violation_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
780 append_composite_type_field (violation_type
, "Type", violation_enum
);
781 append_composite_type_field (violation_type
, "Address", pvoid_type
);
783 /* Unnamed union of the documented field ExceptionInformation,
784 and the alternative AccessViolationInformation (which displays
785 human-readable values for ExceptionCode ACCESS_VIOLATION). */
786 para_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
787 append_composite_type_field (para_type
, "ExceptionInformation",
788 lookup_array_range_type (ulongptr_type
, 0, 14));
789 append_composite_type_field (para_type
, "AccessViolationInformation",
792 siginfo_type
= arch_composite_type (gdbarch
, "EXCEPTION_RECORD",
794 siginfo_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
797 /* ExceptionCode is documented as type DWORD, but here a helper
798 enum type is used instead to display a human-readable value. */
799 append_composite_type_field (siginfo_type
, "ExceptionCode", code_enum
);
800 append_composite_type_field (siginfo_type
, "ExceptionFlags", dword_type
);
801 append_composite_type_field (siginfo_type
, "ExceptionRecord",
803 append_composite_type_field (siginfo_type
, "ExceptionAddress",
805 append_composite_type_field (siginfo_type
, "NumberParameters", dword_type
);
806 /* The 64-bit variant needs some padding. */
807 append_composite_type_field_aligned (siginfo_type
, "",
808 para_type
, TYPE_LENGTH (ulongptr_type
));
810 windows_gdbarch_data
->siginfo_type
= siginfo_type
;
815 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
816 various Windows architectures and machine types. */
819 windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
821 set_gdbarch_wchar_bit (gdbarch
, 16);
822 set_gdbarch_wchar_signed (gdbarch
, 0);
824 /* Canonical paths on this target look like
825 `c:\Program Files\Foo App\mydll.dll', for example. */
826 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
828 set_gdbarch_iterate_over_objfiles_in_search_order
829 (gdbarch
, windows_iterate_over_objfiles_in_search_order
);
831 set_gdbarch_gdb_signal_to_target (gdbarch
, windows_gdb_signal_to_target
);
833 set_solib_ops (gdbarch
, &solib_target_so_ops
);
835 set_gdbarch_get_siginfo_type (gdbarch
, windows_get_siginfo_type
);
838 /* Implementation of `tlb' variable. */
840 static const struct internalvar_funcs tlb_funcs
=
847 void _initialize_windows_tdep ();
849 _initialize_windows_tdep ()
851 windows_gdbarch_data_handle
852 = gdbarch_data_register_post_init (init_windows_gdbarch_data
);
854 init_w32_command_list ();
855 add_cmd ("thread-information-block", class_info
, display_tib
,
856 _("Display thread information block."),
858 add_alias_cmd ("tib", "thread-information-block", class_info
, 1,
861 add_setshow_boolean_cmd ("show-all-tib", class_maintenance
,
862 &maint_display_all_tib
, _("\
863 Set whether to display all non-zero fields of thread information block."), _("\
864 Show whether to display all non-zero fields of thread information block."), _("\
865 Use \"on\" to enable, \"off\" to disable.\n\
866 If enabled, all non-zero fields of thread information block are displayed,\n\
867 even if their meaning is unknown."),
869 show_maint_show_all_tib
,
870 &maintenance_set_cmdlist
,
871 &maintenance_show_cmdlist
);
873 /* Explicitly create without lookup, since that tries to create a
874 value with a void typed value, and when we get here, gdbarch
875 isn't initialized yet. At this point, we're quite sure there
876 isn't another convenience variable of the same name. */
877 create_internalvar_type_lazy ("_tlb", &tlb_funcs
, NULL
);