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
;
163 /* Allocate windows_gdbarch_data for an arch. */
166 init_windows_gdbarch_data (struct gdbarch
*gdbarch
)
168 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct windows_gdbarch_data
);
171 /* Get windows_gdbarch_data of an arch. */
173 static struct windows_gdbarch_data
*
174 get_windows_gdbarch_data (struct gdbarch
*gdbarch
)
176 return ((struct windows_gdbarch_data
*)
177 gdbarch_data (gdbarch
, windows_gdbarch_data_handle
));
180 /* Define Thread Local Base pointer type. */
183 windows_get_tlb_type (struct gdbarch
*gdbarch
)
185 static struct gdbarch
*last_gdbarch
= NULL
;
186 static struct type
*last_tlb_type
= NULL
;
187 struct type
*dword_ptr_type
, *dword32_type
, *void_ptr_type
;
188 struct type
*peb_ldr_type
, *peb_ldr_ptr_type
;
189 struct type
*peb_type
, *peb_ptr_type
, *list_type
;
190 struct type
*module_list_ptr_type
;
191 struct type
*tib_type
, *seh_type
, *tib_ptr_type
, *seh_ptr_type
;
192 struct type
*word_type
, *wchar_type
, *wchar_ptr_type
;
193 struct type
*uni_str_type
, *rupp_type
, *rupp_ptr_type
;
195 /* Do not rebuild type if same gdbarch as last time. */
196 if (last_tlb_type
&& last_gdbarch
== gdbarch
)
197 return last_tlb_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 last_tlb_type
= tib_ptr_type
;
369 last_gdbarch
= gdbarch
;
374 /* The $_tlb convenience variable is a bit special. We don't know
375 for sure the type of the value until we actually have a chance to
376 fetch the data. The type can change depending on gdbarch, so it is
377 also dependent on which thread you have selected. */
379 /* This function implements the lval_computed support for reading a
383 tlb_value_read (struct value
*val
)
386 struct type
*type
= check_typedef (value_type (val
));
388 if (!target_get_tib_address (inferior_ptid
, &tlb
))
389 error (_("Unable to read tlb"));
390 store_typed_address (value_contents_raw (val
), type
, tlb
);
393 /* This function implements the lval_computed support for writing a
397 tlb_value_write (struct value
*v
, struct value
*fromval
)
399 error (_("Impossible to change the Thread Local Base"));
402 static const struct lval_funcs tlb_value_funcs
=
409 /* Return a new value with the correct type for the tlb object of
410 the current thread using architecture GDBARCH. Return a void value
411 if there's no object available. */
413 static struct value
*
414 tlb_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
, void *ignore
)
416 if (target_has_stack
&& inferior_ptid
!= null_ptid
)
418 struct type
*type
= windows_get_tlb_type (gdbarch
);
419 return allocate_computed_value (type
, &tlb_value_funcs
, NULL
);
422 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
426 /* Display thread information block of a given thread. */
429 display_one_tib (ptid_t ptid
)
431 gdb_byte
*tib
= NULL
;
433 CORE_ADDR thread_local_base
;
434 ULONGEST i
, val
, max
, max_name
, size
, tib_size
;
435 ULONGEST sizeof_ptr
= gdbarch_ptr_bit (target_gdbarch ());
436 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
438 if (sizeof_ptr
== 64)
440 size
= sizeof (uint64_t);
441 tib_size
= sizeof (thread_information_64
);
446 size
= sizeof (uint32_t);
447 tib_size
= sizeof (thread_information_32
);
453 if (maint_display_all_tib
)
455 tib_size
= FULL_TIB_SIZE
;
456 max
= tib_size
/ size
;
459 tib
= (gdb_byte
*) alloca (tib_size
);
461 if (target_get_tib_address (ptid
, &thread_local_base
) == 0)
463 printf_filtered (_("Unable to get thread local base for %s\n"),
464 target_pid_to_str (ptid
).c_str ());
468 if (target_read (current_top_target (), TARGET_OBJECT_MEMORY
,
469 NULL
, tib
, thread_local_base
, tib_size
) != tib_size
)
471 printf_filtered (_("Unable to read thread information "
472 "block for %s at address %s\n"),
473 target_pid_to_str (ptid
).c_str (),
474 paddress (target_gdbarch (), thread_local_base
));
478 printf_filtered (_("Thread Information Block %s at %s\n"),
479 target_pid_to_str (ptid
).c_str (),
480 paddress (target_gdbarch (), thread_local_base
));
482 index
= (gdb_byte
*) tib
;
484 /* All fields have the size of a pointer, this allows to iterate
485 using the same for loop for both layouts. */
486 for (i
= 0; i
< max
; i
++)
488 val
= extract_unsigned_integer (index
, size
, byte_order
);
490 printf_filtered (_("%s is 0x%s\n"), TIB_NAME
[i
], phex (val
, size
));
492 printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i
* size
, 2),
499 /* Display thread information block of the current thread. */
502 display_tib (const char * args
, int from_tty
)
504 if (inferior_ptid
!= null_ptid
)
505 display_one_tib (inferior_ptid
);
509 windows_xfer_shared_library (const char* so_name
, CORE_ADDR load_addr
,
510 CORE_ADDR
*text_offset_cached
,
511 struct gdbarch
*gdbarch
, struct obstack
*obstack
)
513 CORE_ADDR text_offset
= text_offset_cached
? *text_offset_cached
: 0;
515 obstack_grow_str (obstack
, "<library name=\"");
516 std::string p
= xml_escape_text (so_name
);
517 obstack_grow_str (obstack
, p
.c_str ());
518 obstack_grow_str (obstack
, "\"><segment address=\"");
522 gdb_bfd_ref_ptr
dll (gdb_bfd_open (so_name
, gnutarget
, -1));
523 /* The following calls are OK even if dll is NULL.
524 The default value 0x1000 is returned by pe_text_section_offset
526 text_offset
= pe_text_section_offset (dll
.get ());
527 if (text_offset_cached
)
528 *text_offset_cached
= text_offset
;
531 obstack_grow_str (obstack
, paddress (gdbarch
, load_addr
+ text_offset
));
532 obstack_grow_str (obstack
, "\"/></library>");
535 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
536 method. It searches all objfiles, starting with CURRENT_OBJFILE
539 On Windows, the system behaves a little differently when two
540 objfiles each define a global symbol using the same name, compared
541 to other platforms such as GNU/Linux for instance. On GNU/Linux,
542 all instances of the symbol effectively get merged into a single
543 one, but on Windows, they remain distinct.
545 As a result, it usually makes sense to start global symbol searches
546 with the current objfile before expanding it to all other objfiles.
547 This helps for instance when a user debugs some code in a DLL that
548 refers to a global variable defined inside that DLL. When trying
549 to print the value of that global variable, it would be unhelpful
550 to print the value of another global variable defined with the same
551 name, but in a different DLL. */
554 windows_iterate_over_objfiles_in_search_order
555 (struct gdbarch
*gdbarch
,
556 iterate_over_objfiles_in_search_order_cb_ftype
*cb
,
557 void *cb_data
, struct objfile
*current_objfile
)
563 stop
= cb (current_objfile
, cb_data
);
568 for (objfile
*objfile
: current_program_space
->objfiles ())
570 if (objfile
!= current_objfile
)
572 stop
= cb (objfile
, cb_data
);
580 show_maint_show_all_tib (struct ui_file
*file
, int from_tty
,
581 struct cmd_list_element
*c
, const char *value
)
583 fprintf_filtered (file
, _("Show all non-zero elements of "
584 "Thread Information Block is %s.\n"), value
);
588 info_w32_command (const char *args
, int from_tty
)
590 help_list (info_w32_cmdlist
, "info w32 ", class_info
, gdb_stdout
);
593 static int w32_prefix_command_valid
= 0;
595 init_w32_command_list (void)
597 if (!w32_prefix_command_valid
)
599 add_prefix_cmd ("w32", class_info
, info_w32_command
,
600 _("Print information specific to Win32 debugging."),
601 &info_w32_cmdlist
, "info w32 ", 0, &infolist
);
602 w32_prefix_command_valid
= 1;
606 /* Implementation of `gdbarch_gdb_signal_to_target'. */
609 windows_gdb_signal_to_target (struct gdbarch
*gdbarch
, enum gdb_signal signal
)
616 return WINDOWS_SIGHUP
;
618 return WINDOWS_SIGINT
;
619 case GDB_SIGNAL_QUIT
:
620 return WINDOWS_SIGQUIT
;
622 return WINDOWS_SIGILL
;
623 case GDB_SIGNAL_TRAP
:
624 return WINDOWS_SIGTRAP
;
625 case GDB_SIGNAL_ABRT
:
626 return WINDOWS_SIGABRT
;
628 return WINDOWS_SIGEMT
;
630 return WINDOWS_SIGFPE
;
631 case GDB_SIGNAL_KILL
:
632 return WINDOWS_SIGKILL
;
634 return WINDOWS_SIGBUS
;
635 case GDB_SIGNAL_SEGV
:
636 return WINDOWS_SIGSEGV
;
638 return WINDOWS_SIGSYS
;
639 case GDB_SIGNAL_PIPE
:
640 return WINDOWS_SIGPIPE
;
641 case GDB_SIGNAL_ALRM
:
642 return WINDOWS_SIGALRM
;
643 case GDB_SIGNAL_TERM
:
644 return WINDOWS_SIGTERM
;
647 return WINDOWS_SIGURG
;
648 case GDB_SIGNAL_STOP
:
649 return WINDOWS_SIGSTOP
;
650 case GDB_SIGNAL_TSTP
:
651 return WINDOWS_SIGTSTP
;
652 case GDB_SIGNAL_CONT
:
653 return WINDOWS_SIGCONT
;
654 case GDB_SIGNAL_CHLD
:
655 return WINDOWS_SIGCHLD
;
656 case GDB_SIGNAL_TTIN
:
657 return WINDOWS_SIGTTIN
;
658 case GDB_SIGNAL_TTOU
:
659 return WINDOWS_SIGTTOU
;
661 return WINDOWS_SIGIO
;
662 case GDB_SIGNAL_XCPU
:
663 return WINDOWS_SIGXCPU
;
664 case GDB_SIGNAL_XFSZ
:
665 return WINDOWS_SIGXFSZ
;
666 case GDB_SIGNAL_VTALRM
:
667 return WINDOWS_SIGVTALRM
;
668 case GDB_SIGNAL_PROF
:
669 return WINDOWS_SIGPROF
;
670 case GDB_SIGNAL_WINCH
:
671 return WINDOWS_SIGWINCH
;
673 return WINDOWS_SIGLOST
;
674 case GDB_SIGNAL_USR1
:
675 return WINDOWS_SIGUSR1
;
676 case GDB_SIGNAL_USR2
:
677 return WINDOWS_SIGUSR2
;
678 #endif /* __CYGWIN__ */
683 struct enum_value_name
689 /* Allocate a TYPE_CODE_ENUM type structure with its named values. */
692 create_enum (struct gdbarch
*gdbarch
, int bit
, const char *name
,
693 const struct enum_value_name
*values
, int count
)
698 type
= arch_type (gdbarch
, TYPE_CODE_ENUM
, bit
, name
);
699 TYPE_NFIELDS (type
) = count
;
700 TYPE_FIELDS (type
) = (struct field
*)
701 TYPE_ZALLOC (type
, sizeof (struct field
) * count
);
702 TYPE_UNSIGNED (type
) = 1;
704 for (i
= 0; i
< count
; i
++)
706 TYPE_FIELD_NAME (type
, i
) = values
[i
].name
;
707 SET_FIELD_ENUMVAL (TYPE_FIELD (type
, i
), values
[i
].value
);
713 static const struct enum_value_name exception_values
[] =
715 { 0x40000015, "FATAL_APP_EXIT" },
716 { 0x40010005, "DBG_CONTROL_C" },
717 { 0x40010008, "DBG_CONTROL_BREAK" },
718 { 0x80000002, "DATATYPE_MISALIGNMENT" },
719 { 0x80000003, "BREAKPOINT" },
720 { 0x80000004, "SINGLE_STEP" },
721 { 0xC0000005, "ACCESS_VIOLATION" },
722 { 0xC0000006, "IN_PAGE_ERROR" },
723 { 0xC000001D, "ILLEGAL_INSTRUCTION" },
724 { 0xC0000025, "NONCONTINUABLE_EXCEPTION" },
725 { 0xC0000026, "INVALID_DISPOSITION" },
726 { 0xC000008C, "ARRAY_BOUNDS_EXCEEDED" },
727 { 0xC000008D, "FLOAT_DENORMAL_OPERAND" },
728 { 0xC000008E, "FLOAT_DIVIDE_BY_ZERO" },
729 { 0xC000008F, "FLOAT_INEXACT_RESULT" },
730 { 0xC0000090, "FLOAT_INVALID_OPERATION" },
731 { 0xC0000091, "FLOAT_OVERFLOW" },
732 { 0xC0000092, "FLOAT_STACK_CHECK" },
733 { 0xC0000093, "FLOAT_UNDERFLOW" },
734 { 0xC0000094, "INTEGER_DIVIDE_BY_ZERO" },
735 { 0xC0000095, "INTEGER_OVERFLOW" },
736 { 0xC0000096, "PRIV_INSTRUCTION" },
737 { 0xC00000FD, "STACK_OVERFLOW" },
738 { 0xC0000409, "FAST_FAIL" },
741 static const struct enum_value_name violation_values
[] =
743 { 0, "READ_ACCESS_VIOLATION" },
744 { 1, "WRITE_ACCESS_VIOLATION" },
745 { 8, "DATA_EXECUTION_PREVENTION_VIOLATION" },
748 /* Implement the "get_siginfo_type" gdbarch method. */
751 windows_get_siginfo_type (struct gdbarch
*gdbarch
)
753 struct windows_gdbarch_data
*windows_gdbarch_data
;
754 struct type
*dword_type
, *pvoid_type
, *ulongptr_type
;
755 struct type
*code_enum
, *violation_enum
;
756 struct type
*violation_type
, *para_type
, *siginfo_ptr_type
, *siginfo_type
;
758 windows_gdbarch_data
= get_windows_gdbarch_data (gdbarch
);
759 if (windows_gdbarch_data
->siginfo_type
!= NULL
)
760 return windows_gdbarch_data
->siginfo_type
;
762 dword_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
764 pvoid_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
), "PVOID",
765 builtin_type (gdbarch
)->builtin_void
);
766 ulongptr_type
= arch_integer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
769 /* ExceptionCode value names */
770 code_enum
= create_enum (gdbarch
, gdbarch_int_bit (gdbarch
),
771 "ExceptionCode", exception_values
,
772 ARRAY_SIZE (exception_values
));
774 /* ACCESS_VIOLATION type names */
775 violation_enum
= create_enum (gdbarch
, gdbarch_ptr_bit (gdbarch
),
776 "ViolationType", violation_values
,
777 ARRAY_SIZE (violation_values
));
779 /* ACCESS_VIOLATION information */
780 violation_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
781 append_composite_type_field (violation_type
, "Type", violation_enum
);
782 append_composite_type_field (violation_type
, "Address", pvoid_type
);
784 /* Unnamed union of the documented field ExceptionInformation,
785 and the alternative AccessViolationInformation (which displays
786 human-readable values for ExceptionCode ACCESS_VIOLATION). */
787 para_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
788 append_composite_type_field (para_type
, "ExceptionInformation",
789 lookup_array_range_type (ulongptr_type
, 0, 14));
790 append_composite_type_field (para_type
, "AccessViolationInformation",
793 siginfo_type
= arch_composite_type (gdbarch
, "EXCEPTION_RECORD",
795 siginfo_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
798 /* ExceptionCode is documented as type DWORD, but here a helper
799 enum type is used instead to display a human-readable value. */
800 append_composite_type_field (siginfo_type
, "ExceptionCode", code_enum
);
801 append_composite_type_field (siginfo_type
, "ExceptionFlags", dword_type
);
802 append_composite_type_field (siginfo_type
, "ExceptionRecord",
804 append_composite_type_field (siginfo_type
, "ExceptionAddress",
806 append_composite_type_field (siginfo_type
, "NumberParameters", dword_type
);
807 /* The 64-bit variant needs some padding. */
808 append_composite_type_field_aligned (siginfo_type
, "",
809 para_type
, TYPE_LENGTH (ulongptr_type
));
811 windows_gdbarch_data
->siginfo_type
= siginfo_type
;
816 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
817 various Windows architectures and machine types. */
820 windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
822 set_gdbarch_wchar_bit (gdbarch
, 16);
823 set_gdbarch_wchar_signed (gdbarch
, 0);
825 /* Canonical paths on this target look like
826 `c:\Program Files\Foo App\mydll.dll', for example. */
827 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
829 set_gdbarch_iterate_over_objfiles_in_search_order
830 (gdbarch
, windows_iterate_over_objfiles_in_search_order
);
832 set_gdbarch_gdb_signal_to_target (gdbarch
, windows_gdb_signal_to_target
);
834 set_solib_ops (gdbarch
, &solib_target_so_ops
);
836 set_gdbarch_get_siginfo_type (gdbarch
, windows_get_siginfo_type
);
839 /* Implementation of `tlb' variable. */
841 static const struct internalvar_funcs tlb_funcs
=
848 void _initialize_windows_tdep ();
850 _initialize_windows_tdep ()
852 windows_gdbarch_data_handle
853 = gdbarch_data_register_post_init (init_windows_gdbarch_data
);
855 init_w32_command_list ();
856 add_cmd ("thread-information-block", class_info
, display_tib
,
857 _("Display thread information block."),
859 add_alias_cmd ("tib", "thread-information-block", class_info
, 1,
862 add_setshow_boolean_cmd ("show-all-tib", class_maintenance
,
863 &maint_display_all_tib
, _("\
864 Set whether to display all non-zero fields of thread information block."), _("\
865 Show whether to display all non-zero fields of thread information block."), _("\
866 Use \"on\" to enable, \"off\" to disable.\n\
867 If enabled, all non-zero fields of thread information block are displayed,\n\
868 even if their meaning is unknown."),
870 show_maint_show_all_tib
,
871 &maintenance_set_cmdlist
,
872 &maintenance_show_cmdlist
);
874 /* Explicitly create without lookup, since that tries to create a
875 value with a void typed value, and when we get here, gdbarch
876 isn't initialized yet. At this point, we're quite sure there
877 isn't another convenience variable of the same name. */
878 create_internalvar_type_lazy ("_tlb", &tlb_funcs
, NULL
);