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"
37 #include "coff/internal.h"
41 /* Windows signal numbers differ between MinGW flavors and between
42 those and Cygwin. The below enumeration was gleaned from the
43 respective headers; the ones marked with MinGW64/Cygwin are defined
44 only by MinGW64 and Cygwin, not by mingw.org's MinGW. FIXME: We
45 should really have distinct MinGW vs Cygwin OSABIs, and two
46 separate enums, selected at runtime. */
50 WINDOWS_SIGHUP
= 1, /* MinGW64/Cygwin */
52 WINDOWS_SIGQUIT
= 3, /* MinGW64/Cygwin */
54 WINDOWS_SIGTRAP
= 5, /* MinGW64/Cygwin */
58 WINDOWS_SIGIOT
= 6, /* MinGW64 */
60 WINDOWS_SIGEMT
= 7, /* MinGW64/Cygwin */
62 WINDOWS_SIGKILL
= 9, /* MinGW64/Cygwin */
63 WINDOWS_SIGBUS
= 10, /* MinGW64/Cygwin */
65 WINDOWS_SIGSYS
= 12, /* MinGW64/Cygwin */
66 WINDOWS_SIGPIPE
= 13,/* MinGW64/Cygwin */
67 WINDOWS_SIGALRM
= 14,/* MinGW64/Cygwin */
80 WINDOWS_SIGVTALRM
= 26,
82 WINDOWS_SIGWINCH
= 28,
87 WINDOWS_SIGBREAK
= 21,
92 struct cmd_list_element
*info_w32_cmdlist
;
94 typedef struct thread_information_block_32
96 uint32_t current_seh
; /* %fs:0x0000 */
97 uint32_t current_top_of_stack
; /* %fs:0x0004 */
98 uint32_t current_bottom_of_stack
; /* %fs:0x0008 */
99 uint32_t sub_system_tib
; /* %fs:0x000c */
100 uint32_t fiber_data
; /* %fs:0x0010 */
101 uint32_t arbitrary_data_slot
; /* %fs:0x0014 */
102 uint32_t linear_address_tib
; /* %fs:0x0018 */
103 uint32_t environment_pointer
; /* %fs:0x001c */
104 uint32_t process_id
; /* %fs:0x0020 */
105 uint32_t current_thread_id
; /* %fs:0x0024 */
106 uint32_t active_rpc_handle
; /* %fs:0x0028 */
107 uint32_t thread_local_storage
; /* %fs:0x002c */
108 uint32_t process_environment_block
; /* %fs:0x0030 */
109 uint32_t last_error_number
; /* %fs:0x0034 */
111 thread_information_32
;
113 typedef struct thread_information_block_64
115 uint64_t current_seh
; /* %gs:0x0000 */
116 uint64_t current_top_of_stack
; /* %gs:0x0008 */
117 uint64_t current_bottom_of_stack
; /* %gs:0x0010 */
118 uint64_t sub_system_tib
; /* %gs:0x0018 */
119 uint64_t fiber_data
; /* %gs:0x0020 */
120 uint64_t arbitrary_data_slot
; /* %gs:0x0028 */
121 uint64_t linear_address_tib
; /* %gs:0x0030 */
122 uint64_t environment_pointer
; /* %gs:0x0038 */
123 uint64_t process_id
; /* %gs:0x0040 */
124 uint64_t current_thread_id
; /* %gs:0x0048 */
125 uint64_t active_rpc_handle
; /* %gs:0x0050 */
126 uint64_t thread_local_storage
; /* %gs:0x0058 */
127 uint64_t process_environment_block
; /* %gs:0x0060 */
128 uint64_t last_error_number
; /* %gs:0x0068 */
130 thread_information_64
;
133 static const char* TIB_NAME
[] =
135 " current_seh ", /* %fs:0x0000 */
136 " current_top_of_stack ", /* %fs:0x0004 */
137 " current_bottom_of_stack ", /* %fs:0x0008 */
138 " sub_system_tib ", /* %fs:0x000c */
139 " fiber_data ", /* %fs:0x0010 */
140 " arbitrary_data_slot ", /* %fs:0x0014 */
141 " linear_address_tib ", /* %fs:0x0018 */
142 " environment_pointer ", /* %fs:0x001c */
143 " process_id ", /* %fs:0x0020 */
144 " current_thread_id ", /* %fs:0x0024 */
145 " active_rpc_handle ", /* %fs:0x0028 */
146 " thread_local_storage ", /* %fs:0x002c */
147 " process_environment_block ", /* %fs:0x0030 */
148 " last_error_number " /* %fs:0x0034 */
151 static const int MAX_TIB32
=
152 sizeof (thread_information_32
) / sizeof (uint32_t);
153 static const int MAX_TIB64
=
154 sizeof (thread_information_64
) / sizeof (uint64_t);
155 static const int FULL_TIB_SIZE
= 0x1000;
157 static bool maint_display_all_tib
= false;
159 static struct gdbarch_data
*windows_gdbarch_data_handle
;
161 struct windows_gdbarch_data
163 struct type
*siginfo_type
;
164 struct type
*tib_ptr_type
; /* Type of thread information block */
167 /* Allocate windows_gdbarch_data for an arch. */
170 init_windows_gdbarch_data (struct gdbarch
*gdbarch
)
172 return GDBARCH_OBSTACK_ZALLOC (gdbarch
, struct windows_gdbarch_data
);
175 /* Get windows_gdbarch_data of an arch. */
177 static struct windows_gdbarch_data
*
178 get_windows_gdbarch_data (struct gdbarch
*gdbarch
)
180 return ((struct windows_gdbarch_data
*)
181 gdbarch_data (gdbarch
, windows_gdbarch_data_handle
));
184 /* Define Thread Local Base pointer type. */
187 windows_get_tlb_type (struct gdbarch
*gdbarch
)
189 struct type
*dword_ptr_type
, *dword32_type
, *void_ptr_type
;
190 struct type
*peb_ldr_type
, *peb_ldr_ptr_type
;
191 struct type
*peb_type
, *peb_ptr_type
, *list_type
;
192 struct type
*module_list_ptr_type
;
193 struct type
*tib_type
, *seh_type
, *tib_ptr_type
, *seh_ptr_type
;
194 struct type
*word_type
, *wchar_type
, *wchar_ptr_type
;
195 struct type
*uni_str_type
, *rupp_type
, *rupp_ptr_type
;
197 windows_gdbarch_data
*windows_gdbarch_data
198 = get_windows_gdbarch_data (gdbarch
);
199 if (windows_gdbarch_data
->tib_ptr_type
!= nullptr)
200 return windows_gdbarch_data
->tib_ptr_type
;
202 dword_ptr_type
= arch_integer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
204 dword32_type
= arch_integer_type (gdbarch
, 32,
206 word_type
= arch_integer_type (gdbarch
, 16,
208 wchar_type
= arch_integer_type (gdbarch
, 16,
210 void_ptr_type
= lookup_pointer_type (builtin_type (gdbarch
)->builtin_void
);
211 wchar_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
216 list_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
217 TYPE_NAME (list_type
) = xstrdup ("list");
219 module_list_ptr_type
= void_ptr_type
;
221 append_composite_type_field (list_type
, "forward_list",
222 module_list_ptr_type
);
223 append_composite_type_field (list_type
, "backward_list",
224 module_list_ptr_type
);
226 /* Structured Exception Handler */
228 seh_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
229 TYPE_NAME (seh_type
) = xstrdup ("seh");
231 seh_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
232 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
234 TYPE_TARGET_TYPE (seh_ptr_type
) = seh_type
;
236 append_composite_type_field (seh_type
, "next_seh", seh_ptr_type
);
237 append_composite_type_field (seh_type
, "handler",
238 builtin_type (gdbarch
)->builtin_func_ptr
);
240 /* struct _PEB_LDR_DATA */
241 peb_ldr_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
242 TYPE_NAME (peb_ldr_type
) = xstrdup ("peb_ldr_data");
244 append_composite_type_field (peb_ldr_type
, "length", dword32_type
);
245 append_composite_type_field (peb_ldr_type
, "initialized", dword32_type
);
246 append_composite_type_field (peb_ldr_type
, "ss_handle", void_ptr_type
);
247 append_composite_type_field (peb_ldr_type
, "in_load_order", list_type
);
248 append_composite_type_field (peb_ldr_type
, "in_memory_order", list_type
);
249 append_composite_type_field (peb_ldr_type
, "in_init_order", list_type
);
250 append_composite_type_field (peb_ldr_type
, "entry_in_progress",
252 peb_ldr_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
253 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
255 TYPE_TARGET_TYPE (peb_ldr_ptr_type
) = peb_ldr_type
;
257 /* struct UNICODE_STRING */
258 uni_str_type
= arch_composite_type (gdbarch
, "unicode_string",
261 append_composite_type_field (uni_str_type
, "length", word_type
);
262 append_composite_type_field (uni_str_type
, "maximum_length", word_type
);
263 append_composite_type_field_aligned (uni_str_type
, "buffer",
265 TYPE_LENGTH (wchar_ptr_type
));
267 /* struct _RTL_USER_PROCESS_PARAMETERS */
268 rupp_type
= arch_composite_type (gdbarch
, "rtl_user_process_parameters",
271 append_composite_type_field (rupp_type
, "maximum_length", dword32_type
);
272 append_composite_type_field (rupp_type
, "length", dword32_type
);
273 append_composite_type_field (rupp_type
, "flags", dword32_type
);
274 append_composite_type_field (rupp_type
, "debug_flags", dword32_type
);
275 append_composite_type_field (rupp_type
, "console_handle", void_ptr_type
);
276 append_composite_type_field (rupp_type
, "console_flags", dword32_type
);
277 append_composite_type_field_aligned (rupp_type
, "standard_input",
279 TYPE_LENGTH (void_ptr_type
));
280 append_composite_type_field (rupp_type
, "standard_output", void_ptr_type
);
281 append_composite_type_field (rupp_type
, "standard_error", void_ptr_type
);
282 append_composite_type_field (rupp_type
, "current_directory", uni_str_type
);
283 append_composite_type_field (rupp_type
, "current_directory_handle",
285 append_composite_type_field (rupp_type
, "dll_path", uni_str_type
);
286 append_composite_type_field (rupp_type
, "image_path_name", uni_str_type
);
287 append_composite_type_field (rupp_type
, "command_line", uni_str_type
);
288 append_composite_type_field (rupp_type
, "environment", void_ptr_type
);
289 append_composite_type_field (rupp_type
, "starting_x", dword32_type
);
290 append_composite_type_field (rupp_type
, "starting_y", dword32_type
);
291 append_composite_type_field (rupp_type
, "count_x", dword32_type
);
292 append_composite_type_field (rupp_type
, "count_y", dword32_type
);
293 append_composite_type_field (rupp_type
, "count_chars_x", dword32_type
);
294 append_composite_type_field (rupp_type
, "count_chars_y", dword32_type
);
295 append_composite_type_field (rupp_type
, "fill_attribute", dword32_type
);
296 append_composite_type_field (rupp_type
, "window_flags", dword32_type
);
297 append_composite_type_field (rupp_type
, "show_window_flags", dword32_type
);
298 append_composite_type_field_aligned (rupp_type
, "window_title",
300 TYPE_LENGTH (void_ptr_type
));
301 append_composite_type_field (rupp_type
, "desktop_info", uni_str_type
);
302 append_composite_type_field (rupp_type
, "shell_info", uni_str_type
);
303 append_composite_type_field (rupp_type
, "runtime_data", uni_str_type
);
305 rupp_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
309 /* struct process environment block */
310 peb_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
311 TYPE_NAME (peb_type
) = xstrdup ("peb");
313 /* First bytes contain several flags. */
314 append_composite_type_field (peb_type
, "flags", dword_ptr_type
);
315 append_composite_type_field (peb_type
, "mutant", void_ptr_type
);
316 append_composite_type_field (peb_type
, "image_base_address", void_ptr_type
);
317 append_composite_type_field (peb_type
, "ldr", peb_ldr_ptr_type
);
318 append_composite_type_field (peb_type
, "process_parameters", rupp_ptr_type
);
319 append_composite_type_field (peb_type
, "sub_system_data", void_ptr_type
);
320 append_composite_type_field (peb_type
, "process_heap", void_ptr_type
);
321 append_composite_type_field (peb_type
, "fast_peb_lock", void_ptr_type
);
322 peb_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
323 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
325 TYPE_TARGET_TYPE (peb_ptr_type
) = peb_type
;
328 /* struct thread information block */
329 tib_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
330 TYPE_NAME (tib_type
) = xstrdup ("tib");
332 /* uint32_t current_seh; %fs:0x0000 */
333 append_composite_type_field (tib_type
, "current_seh", seh_ptr_type
);
334 /* uint32_t current_top_of_stack; %fs:0x0004 */
335 append_composite_type_field (tib_type
, "current_top_of_stack",
337 /* uint32_t current_bottom_of_stack; %fs:0x0008 */
338 append_composite_type_field (tib_type
, "current_bottom_of_stack",
340 /* uint32_t sub_system_tib; %fs:0x000c */
341 append_composite_type_field (tib_type
, "sub_system_tib", void_ptr_type
);
343 /* uint32_t fiber_data; %fs:0x0010 */
344 append_composite_type_field (tib_type
, "fiber_data", void_ptr_type
);
345 /* uint32_t arbitrary_data_slot; %fs:0x0014 */
346 append_composite_type_field (tib_type
, "arbitrary_data_slot", void_ptr_type
);
347 /* uint32_t linear_address_tib; %fs:0x0018 */
348 append_composite_type_field (tib_type
, "linear_address_tib", void_ptr_type
);
349 /* uint32_t environment_pointer; %fs:0x001c */
350 append_composite_type_field (tib_type
, "environment_pointer", void_ptr_type
);
351 /* uint32_t process_id; %fs:0x0020 */
352 append_composite_type_field (tib_type
, "process_id", dword_ptr_type
);
353 /* uint32_t current_thread_id; %fs:0x0024 */
354 append_composite_type_field (tib_type
, "thread_id", dword_ptr_type
);
355 /* uint32_t active_rpc_handle; %fs:0x0028 */
356 append_composite_type_field (tib_type
, "active_rpc_handle", dword_ptr_type
);
357 /* uint32_t thread_local_storage; %fs:0x002c */
358 append_composite_type_field (tib_type
, "thread_local_storage",
360 /* uint32_t process_environment_block; %fs:0x0030 */
361 append_composite_type_field (tib_type
, "process_environment_block",
363 /* uint32_t last_error_number; %fs:0x0034 */
364 append_composite_type_field (tib_type
, "last_error_number", dword_ptr_type
);
366 tib_ptr_type
= arch_type (gdbarch
, TYPE_CODE_PTR
,
367 TYPE_LENGTH (void_ptr_type
) * TARGET_CHAR_BIT
,
369 TYPE_TARGET_TYPE (tib_ptr_type
) = tib_type
;
371 windows_gdbarch_data
->tib_ptr_type
= tib_ptr_type
;
376 /* The $_tlb convenience variable is a bit special. We don't know
377 for sure the type of the value until we actually have a chance to
378 fetch the data. The type can change depending on gdbarch, so it is
379 also dependent on which thread you have selected. */
381 /* This function implements the lval_computed support for reading a
385 tlb_value_read (struct value
*val
)
388 struct type
*type
= check_typedef (value_type (val
));
390 if (!target_get_tib_address (inferior_ptid
, &tlb
))
391 error (_("Unable to read tlb"));
392 store_typed_address (value_contents_raw (val
), type
, tlb
);
395 /* This function implements the lval_computed support for writing a
399 tlb_value_write (struct value
*v
, struct value
*fromval
)
401 error (_("Impossible to change the Thread Local Base"));
404 static const struct lval_funcs tlb_value_funcs
=
411 /* Return a new value with the correct type for the tlb object of
412 the current thread using architecture GDBARCH. Return a void value
413 if there's no object available. */
415 static struct value
*
416 tlb_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
, void *ignore
)
418 if (target_has_stack
&& inferior_ptid
!= null_ptid
)
420 struct type
*type
= windows_get_tlb_type (gdbarch
);
421 return allocate_computed_value (type
, &tlb_value_funcs
, NULL
);
424 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
428 /* Display thread information block of a given thread. */
431 display_one_tib (ptid_t ptid
)
433 gdb_byte
*tib
= NULL
;
435 CORE_ADDR thread_local_base
;
436 ULONGEST i
, val
, max
, max_name
, size
, tib_size
;
437 ULONGEST sizeof_ptr
= gdbarch_ptr_bit (target_gdbarch ());
438 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
440 if (sizeof_ptr
== 64)
442 size
= sizeof (uint64_t);
443 tib_size
= sizeof (thread_information_64
);
448 size
= sizeof (uint32_t);
449 tib_size
= sizeof (thread_information_32
);
455 if (maint_display_all_tib
)
457 tib_size
= FULL_TIB_SIZE
;
458 max
= tib_size
/ size
;
461 tib
= (gdb_byte
*) alloca (tib_size
);
463 if (target_get_tib_address (ptid
, &thread_local_base
) == 0)
465 printf_filtered (_("Unable to get thread local base for %s\n"),
466 target_pid_to_str (ptid
).c_str ());
470 if (target_read (current_top_target (), TARGET_OBJECT_MEMORY
,
471 NULL
, tib
, thread_local_base
, tib_size
) != tib_size
)
473 printf_filtered (_("Unable to read thread information "
474 "block for %s at address %s\n"),
475 target_pid_to_str (ptid
).c_str (),
476 paddress (target_gdbarch (), thread_local_base
));
480 printf_filtered (_("Thread Information Block %s at %s\n"),
481 target_pid_to_str (ptid
).c_str (),
482 paddress (target_gdbarch (), thread_local_base
));
484 index
= (gdb_byte
*) tib
;
486 /* All fields have the size of a pointer, this allows to iterate
487 using the same for loop for both layouts. */
488 for (i
= 0; i
< max
; i
++)
490 val
= extract_unsigned_integer (index
, size
, byte_order
);
492 printf_filtered (_("%s is 0x%s\n"), TIB_NAME
[i
], phex (val
, size
));
494 printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i
* size
, 2),
501 /* Display thread information block of the current thread. */
504 display_tib (const char * args
, int from_tty
)
506 if (inferior_ptid
!= null_ptid
)
507 display_one_tib (inferior_ptid
);
511 windows_xfer_shared_library (const char* so_name
, CORE_ADDR load_addr
,
512 CORE_ADDR
*text_offset_cached
,
513 struct gdbarch
*gdbarch
, struct obstack
*obstack
)
515 CORE_ADDR text_offset
= text_offset_cached
? *text_offset_cached
: 0;
517 obstack_grow_str (obstack
, "<library name=\"");
518 std::string p
= xml_escape_text (so_name
);
519 obstack_grow_str (obstack
, p
.c_str ());
520 obstack_grow_str (obstack
, "\"><segment address=\"");
524 gdb_bfd_ref_ptr
dll (gdb_bfd_open (so_name
, gnutarget
, -1));
525 /* The following calls are OK even if dll is NULL.
526 The default value 0x1000 is returned by pe_text_section_offset
528 text_offset
= pe_text_section_offset (dll
.get ());
529 if (text_offset_cached
)
530 *text_offset_cached
= text_offset
;
533 obstack_grow_str (obstack
, paddress (gdbarch
, load_addr
+ text_offset
));
534 obstack_grow_str (obstack
, "\"/></library>");
537 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
538 method. It searches all objfiles, starting with CURRENT_OBJFILE
541 On Windows, the system behaves a little differently when two
542 objfiles each define a global symbol using the same name, compared
543 to other platforms such as GNU/Linux for instance. On GNU/Linux,
544 all instances of the symbol effectively get merged into a single
545 one, but on Windows, they remain distinct.
547 As a result, it usually makes sense to start global symbol searches
548 with the current objfile before expanding it to all other objfiles.
549 This helps for instance when a user debugs some code in a DLL that
550 refers to a global variable defined inside that DLL. When trying
551 to print the value of that global variable, it would be unhelpful
552 to print the value of another global variable defined with the same
553 name, but in a different DLL. */
556 windows_iterate_over_objfiles_in_search_order
557 (struct gdbarch
*gdbarch
,
558 iterate_over_objfiles_in_search_order_cb_ftype
*cb
,
559 void *cb_data
, struct objfile
*current_objfile
)
565 stop
= cb (current_objfile
, cb_data
);
570 for (objfile
*objfile
: current_program_space
->objfiles ())
572 if (objfile
!= current_objfile
)
574 stop
= cb (objfile
, cb_data
);
582 show_maint_show_all_tib (struct ui_file
*file
, int from_tty
,
583 struct cmd_list_element
*c
, const char *value
)
585 fprintf_filtered (file
, _("Show all non-zero elements of "
586 "Thread Information Block is %s.\n"), value
);
590 info_w32_command (const char *args
, int from_tty
)
592 help_list (info_w32_cmdlist
, "info w32 ", class_info
, gdb_stdout
);
595 static int w32_prefix_command_valid
= 0;
597 init_w32_command_list (void)
599 if (!w32_prefix_command_valid
)
601 add_prefix_cmd ("w32", class_info
, info_w32_command
,
602 _("Print information specific to Win32 debugging."),
603 &info_w32_cmdlist
, "info w32 ", 0, &infolist
);
604 w32_prefix_command_valid
= 1;
608 /* Implementation of `gdbarch_gdb_signal_to_target'. */
611 windows_gdb_signal_to_target (struct gdbarch
*gdbarch
, enum gdb_signal signal
)
618 return WINDOWS_SIGHUP
;
620 return WINDOWS_SIGINT
;
621 case GDB_SIGNAL_QUIT
:
622 return WINDOWS_SIGQUIT
;
624 return WINDOWS_SIGILL
;
625 case GDB_SIGNAL_TRAP
:
626 return WINDOWS_SIGTRAP
;
627 case GDB_SIGNAL_ABRT
:
628 return WINDOWS_SIGABRT
;
630 return WINDOWS_SIGEMT
;
632 return WINDOWS_SIGFPE
;
633 case GDB_SIGNAL_KILL
:
634 return WINDOWS_SIGKILL
;
636 return WINDOWS_SIGBUS
;
637 case GDB_SIGNAL_SEGV
:
638 return WINDOWS_SIGSEGV
;
640 return WINDOWS_SIGSYS
;
641 case GDB_SIGNAL_PIPE
:
642 return WINDOWS_SIGPIPE
;
643 case GDB_SIGNAL_ALRM
:
644 return WINDOWS_SIGALRM
;
645 case GDB_SIGNAL_TERM
:
646 return WINDOWS_SIGTERM
;
649 return WINDOWS_SIGURG
;
650 case GDB_SIGNAL_STOP
:
651 return WINDOWS_SIGSTOP
;
652 case GDB_SIGNAL_TSTP
:
653 return WINDOWS_SIGTSTP
;
654 case GDB_SIGNAL_CONT
:
655 return WINDOWS_SIGCONT
;
656 case GDB_SIGNAL_CHLD
:
657 return WINDOWS_SIGCHLD
;
658 case GDB_SIGNAL_TTIN
:
659 return WINDOWS_SIGTTIN
;
660 case GDB_SIGNAL_TTOU
:
661 return WINDOWS_SIGTTOU
;
663 return WINDOWS_SIGIO
;
664 case GDB_SIGNAL_XCPU
:
665 return WINDOWS_SIGXCPU
;
666 case GDB_SIGNAL_XFSZ
:
667 return WINDOWS_SIGXFSZ
;
668 case GDB_SIGNAL_VTALRM
:
669 return WINDOWS_SIGVTALRM
;
670 case GDB_SIGNAL_PROF
:
671 return WINDOWS_SIGPROF
;
672 case GDB_SIGNAL_WINCH
:
673 return WINDOWS_SIGWINCH
;
675 return WINDOWS_SIGLOST
;
676 case GDB_SIGNAL_USR1
:
677 return WINDOWS_SIGUSR1
;
678 case GDB_SIGNAL_USR2
:
679 return WINDOWS_SIGUSR2
;
680 #endif /* __CYGWIN__ */
685 struct enum_value_name
691 /* Allocate a TYPE_CODE_ENUM type structure with its named values. */
694 create_enum (struct gdbarch
*gdbarch
, int bit
, const char *name
,
695 const struct enum_value_name
*values
, int count
)
700 type
= arch_type (gdbarch
, TYPE_CODE_ENUM
, bit
, name
);
701 TYPE_NFIELDS (type
) = count
;
702 TYPE_FIELDS (type
) = (struct field
*)
703 TYPE_ZALLOC (type
, sizeof (struct field
) * count
);
704 TYPE_UNSIGNED (type
) = 1;
706 for (i
= 0; i
< count
; i
++)
708 TYPE_FIELD_NAME (type
, i
) = values
[i
].name
;
709 SET_FIELD_ENUMVAL (TYPE_FIELD (type
, i
), values
[i
].value
);
715 static const struct enum_value_name exception_values
[] =
717 { 0x40000015, "FATAL_APP_EXIT" },
718 { 0x40010005, "DBG_CONTROL_C" },
719 { 0x40010008, "DBG_CONTROL_BREAK" },
720 { 0x80000002, "DATATYPE_MISALIGNMENT" },
721 { 0x80000003, "BREAKPOINT" },
722 { 0x80000004, "SINGLE_STEP" },
723 { 0xC0000005, "ACCESS_VIOLATION" },
724 { 0xC0000006, "IN_PAGE_ERROR" },
725 { 0xC000001D, "ILLEGAL_INSTRUCTION" },
726 { 0xC0000025, "NONCONTINUABLE_EXCEPTION" },
727 { 0xC0000026, "INVALID_DISPOSITION" },
728 { 0xC000008C, "ARRAY_BOUNDS_EXCEEDED" },
729 { 0xC000008D, "FLOAT_DENORMAL_OPERAND" },
730 { 0xC000008E, "FLOAT_DIVIDE_BY_ZERO" },
731 { 0xC000008F, "FLOAT_INEXACT_RESULT" },
732 { 0xC0000090, "FLOAT_INVALID_OPERATION" },
733 { 0xC0000091, "FLOAT_OVERFLOW" },
734 { 0xC0000092, "FLOAT_STACK_CHECK" },
735 { 0xC0000093, "FLOAT_UNDERFLOW" },
736 { 0xC0000094, "INTEGER_DIVIDE_BY_ZERO" },
737 { 0xC0000095, "INTEGER_OVERFLOW" },
738 { 0xC0000096, "PRIV_INSTRUCTION" },
739 { 0xC00000FD, "STACK_OVERFLOW" },
740 { 0xC0000409, "FAST_FAIL" },
743 static const struct enum_value_name violation_values
[] =
745 { 0, "READ_ACCESS_VIOLATION" },
746 { 1, "WRITE_ACCESS_VIOLATION" },
747 { 8, "DATA_EXECUTION_PREVENTION_VIOLATION" },
750 /* Implement the "get_siginfo_type" gdbarch method. */
753 windows_get_siginfo_type (struct gdbarch
*gdbarch
)
755 struct windows_gdbarch_data
*windows_gdbarch_data
;
756 struct type
*dword_type
, *pvoid_type
, *ulongptr_type
;
757 struct type
*code_enum
, *violation_enum
;
758 struct type
*violation_type
, *para_type
, *siginfo_ptr_type
, *siginfo_type
;
760 windows_gdbarch_data
= get_windows_gdbarch_data (gdbarch
);
761 if (windows_gdbarch_data
->siginfo_type
!= NULL
)
762 return windows_gdbarch_data
->siginfo_type
;
764 dword_type
= arch_integer_type (gdbarch
, gdbarch_int_bit (gdbarch
),
766 pvoid_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
), "PVOID",
767 builtin_type (gdbarch
)->builtin_void
);
768 ulongptr_type
= arch_integer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
771 /* ExceptionCode value names */
772 code_enum
= create_enum (gdbarch
, gdbarch_int_bit (gdbarch
),
773 "ExceptionCode", exception_values
,
774 ARRAY_SIZE (exception_values
));
776 /* ACCESS_VIOLATION type names */
777 violation_enum
= create_enum (gdbarch
, gdbarch_ptr_bit (gdbarch
),
778 "ViolationType", violation_values
,
779 ARRAY_SIZE (violation_values
));
781 /* ACCESS_VIOLATION information */
782 violation_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
783 append_composite_type_field (violation_type
, "Type", violation_enum
);
784 append_composite_type_field (violation_type
, "Address", pvoid_type
);
786 /* Unnamed union of the documented field ExceptionInformation,
787 and the alternative AccessViolationInformation (which displays
788 human-readable values for ExceptionCode ACCESS_VIOLATION). */
789 para_type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
790 append_composite_type_field (para_type
, "ExceptionInformation",
791 lookup_array_range_type (ulongptr_type
, 0, 14));
792 append_composite_type_field (para_type
, "AccessViolationInformation",
795 siginfo_type
= arch_composite_type (gdbarch
, "EXCEPTION_RECORD",
797 siginfo_ptr_type
= arch_pointer_type (gdbarch
, gdbarch_ptr_bit (gdbarch
),
800 /* ExceptionCode is documented as type DWORD, but here a helper
801 enum type is used instead to display a human-readable value. */
802 append_composite_type_field (siginfo_type
, "ExceptionCode", code_enum
);
803 append_composite_type_field (siginfo_type
, "ExceptionFlags", dword_type
);
804 append_composite_type_field (siginfo_type
, "ExceptionRecord",
806 append_composite_type_field (siginfo_type
, "ExceptionAddress",
808 append_composite_type_field (siginfo_type
, "NumberParameters", dword_type
);
809 /* The 64-bit variant needs some padding. */
810 append_composite_type_field_aligned (siginfo_type
, "",
811 para_type
, TYPE_LENGTH (ulongptr_type
));
813 windows_gdbarch_data
->siginfo_type
= siginfo_type
;
818 /* Implement the "solib_create_inferior_hook" target_so_ops method. */
821 windows_solib_create_inferior_hook (int from_tty
)
823 CORE_ADDR exec_base
= 0;
825 /* Find base address of main executable in
826 TIB->process_environment_block->image_base_address. */
827 struct gdbarch
*gdbarch
= target_gdbarch ();
828 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
830 int peb_offset
; /* Offset of process_environment_block in TIB. */
831 int base_offset
; /* Offset of image_base_address in PEB. */
832 if (gdbarch_ptr_bit (gdbarch
) == 32)
846 if (target_has_execution
847 && target_get_tib_address (inferior_ptid
, &tlb
)
848 && !target_read_memory (tlb
+ peb_offset
, buf
, ptr_bytes
))
850 CORE_ADDR peb
= extract_unsigned_integer (buf
, ptr_bytes
, byte_order
);
851 if (!target_read_memory (peb
+ base_offset
, buf
, ptr_bytes
))
852 exec_base
= extract_unsigned_integer (buf
, ptr_bytes
, byte_order
);
855 /* Rebase executable if the base address changed because of ASLR. */
856 if (symfile_objfile
!= nullptr && exec_base
!= 0)
858 CORE_ADDR vmaddr
= pe_data (exec_bfd
)->pe_opthdr
.ImageBase
;
859 if (vmaddr
!= exec_base
)
860 objfile_rebase (symfile_objfile
, exec_base
- vmaddr
);
864 static struct target_so_ops windows_so_ops
;
866 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
867 various Windows architectures and machine types. */
870 windows_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
872 set_gdbarch_wchar_bit (gdbarch
, 16);
873 set_gdbarch_wchar_signed (gdbarch
, 0);
875 /* Canonical paths on this target look like
876 `c:\Program Files\Foo App\mydll.dll', for example. */
877 set_gdbarch_has_dos_based_file_system (gdbarch
, 1);
879 set_gdbarch_iterate_over_objfiles_in_search_order
880 (gdbarch
, windows_iterate_over_objfiles_in_search_order
);
882 set_gdbarch_gdb_signal_to_target (gdbarch
, windows_gdb_signal_to_target
);
884 windows_so_ops
= solib_target_so_ops
;
885 windows_so_ops
.solib_create_inferior_hook
886 = windows_solib_create_inferior_hook
;
887 set_solib_ops (gdbarch
, &windows_so_ops
);
889 set_gdbarch_get_siginfo_type (gdbarch
, windows_get_siginfo_type
);
892 /* Implementation of `tlb' variable. */
894 static const struct internalvar_funcs tlb_funcs
=
901 void _initialize_windows_tdep ();
903 _initialize_windows_tdep ()
905 windows_gdbarch_data_handle
906 = gdbarch_data_register_post_init (init_windows_gdbarch_data
);
908 init_w32_command_list ();
909 add_cmd ("thread-information-block", class_info
, display_tib
,
910 _("Display thread information block."),
912 add_alias_cmd ("tib", "thread-information-block", class_info
, 1,
915 add_setshow_boolean_cmd ("show-all-tib", class_maintenance
,
916 &maint_display_all_tib
, _("\
917 Set whether to display all non-zero fields of thread information block."), _("\
918 Show whether to display all non-zero fields of thread information block."), _("\
919 Use \"on\" to enable, \"off\" to disable.\n\
920 If enabled, all non-zero fields of thread information block are displayed,\n\
921 even if their meaning is unknown."),
923 show_maint_show_all_tib
,
924 &maintenance_set_cmdlist
,
925 &maintenance_show_cmdlist
);
927 /* Explicitly create without lookup, since that tries to create a
928 value with a void typed value, and when we get here, gdbarch
929 isn't initialized yet. At this point, we're quite sure there
930 isn't another convenience variable of the same name. */
931 create_internalvar_type_lazy ("_tlb", &tlb_funcs
, NULL
);