e9787887a4af87c0faf547b916ecf71feea72dec
[deliverable/binutils-gdb.git] / gdb / windows-tdep.c
1 /* Copyright (C) 2008-2020 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
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.
9
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.
14
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/>. */
17
18 #include "defs.h"
19 #include "windows-tdep.h"
20 #include "gdb_obstack.h"
21 #include "xml-support.h"
22 #include "gdbarch.h"
23 #include "target.h"
24 #include "value.h"
25 #include "inferior.h"
26 #include "command.h"
27 #include "gdbcmd.h"
28 #include "gdbthread.h"
29 #include "objfiles.h"
30 #include "symfile.h"
31 #include "coff-pe-read.h"
32 #include "gdb_bfd.h"
33 #include "complaints.h"
34 #include "solib.h"
35 #include "solib-target.h"
36 #include "gdbcore.h"
37
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. */
44
45 enum
46 {
47 WINDOWS_SIGHUP = 1, /* MinGW64/Cygwin */
48 WINDOWS_SIGINT = 2,
49 WINDOWS_SIGQUIT = 3, /* MinGW64/Cygwin */
50 WINDOWS_SIGILL = 4,
51 WINDOWS_SIGTRAP = 5, /* MinGW64/Cygwin */
52 #ifdef __CYGWIN__
53 WINDOWS_SIGABRT = 6,
54 #else
55 WINDOWS_SIGIOT = 6, /* MinGW64 */
56 #endif
57 WINDOWS_SIGEMT = 7, /* MinGW64/Cygwin */
58 WINDOWS_SIGFPE = 8,
59 WINDOWS_SIGKILL = 9, /* MinGW64/Cygwin */
60 WINDOWS_SIGBUS = 10, /* MinGW64/Cygwin */
61 WINDOWS_SIGSEGV = 11,
62 WINDOWS_SIGSYS = 12, /* MinGW64/Cygwin */
63 WINDOWS_SIGPIPE = 13,/* MinGW64/Cygwin */
64 WINDOWS_SIGALRM = 14,/* MinGW64/Cygwin */
65 WINDOWS_SIGTERM = 15,
66 #ifdef __CYGWIN__
67 WINDOWS_SIGURG = 16,
68 WINDOWS_SIGSTOP = 17,
69 WINDOWS_SIGTSTP = 18,
70 WINDOWS_SIGCONT = 19,
71 WINDOWS_SIGCHLD = 20,
72 WINDOWS_SIGTTIN = 21,
73 WINDOWS_SIGTTOU = 22,
74 WINDOWS_SIGIO = 23,
75 WINDOWS_SIGXCPU = 24,
76 WINDOWS_SIGXFSZ = 25,
77 WINDOWS_SIGVTALRM = 26,
78 WINDOWS_SIGPROF = 27,
79 WINDOWS_SIGWINCH = 28,
80 WINDOWS_SIGLOST = 29,
81 WINDOWS_SIGUSR1 = 30,
82 WINDOWS_SIGUSR2 = 31
83 #else
84 WINDOWS_SIGBREAK = 21,
85 WINDOWS_SIGABRT = 22
86 #endif
87 };
88
89 struct cmd_list_element *info_w32_cmdlist;
90
91 typedef struct thread_information_block_32
92 {
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 */
107 }
108 thread_information_32;
109
110 typedef struct thread_information_block_64
111 {
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 */
126 }
127 thread_information_64;
128
129
130 static const char* TIB_NAME[] =
131 {
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 */
146 };
147
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;
153
154 static bool maint_display_all_tib = false;
155
156 static struct gdbarch_data *windows_gdbarch_data_handle;
157
158 struct windows_gdbarch_data
159 {
160 struct type *siginfo_type;
161 };
162
163 /* Allocate windows_gdbarch_data for an arch. */
164
165 static void *
166 init_windows_gdbarch_data (struct gdbarch *gdbarch)
167 {
168 return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct windows_gdbarch_data);
169 }
170
171 /* Get windows_gdbarch_data of an arch. */
172
173 static struct windows_gdbarch_data *
174 get_windows_gdbarch_data (struct gdbarch *gdbarch)
175 {
176 return ((struct windows_gdbarch_data *)
177 gdbarch_data (gdbarch, windows_gdbarch_data_handle));
178 }
179
180 /* Define Thread Local Base pointer type. */
181
182 static struct type *
183 windows_get_tlb_type (struct gdbarch *gdbarch)
184 {
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;
194
195 /* Do not rebuild type if same gdbarch as last time. */
196 if (last_tlb_type && last_gdbarch == gdbarch)
197 return last_tlb_type;
198
199 dword_ptr_type = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
200 1, "DWORD_PTR");
201 dword32_type = arch_integer_type (gdbarch, 32,
202 1, "DWORD32");
203 word_type = arch_integer_type (gdbarch, 16,
204 1, "WORD");
205 wchar_type = arch_integer_type (gdbarch, 16,
206 1, "wchar_t");
207 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
208 wchar_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
209 NULL, wchar_type);
210
211 /* list entry */
212
213 list_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
214 TYPE_NAME (list_type) = xstrdup ("list");
215
216 module_list_ptr_type = void_ptr_type;
217
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);
222
223 /* Structured Exception Handler */
224
225 seh_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
226 TYPE_NAME (seh_type) = xstrdup ("seh");
227
228 seh_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
229 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
230 NULL);
231 TYPE_TARGET_TYPE (seh_ptr_type) = seh_type;
232
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);
236
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");
240
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",
248 void_ptr_type);
249 peb_ldr_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
250 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
251 NULL);
252 TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type;
253
254 /* struct UNICODE_STRING */
255 uni_str_type = arch_composite_type (gdbarch, "unicode_string",
256 TYPE_CODE_STRUCT);
257
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",
261 wchar_ptr_type,
262 TYPE_LENGTH (wchar_ptr_type));
263
264 /* struct _RTL_USER_PROCESS_PARAMETERS */
265 rupp_type = arch_composite_type (gdbarch, "rtl_user_process_parameters",
266 TYPE_CODE_STRUCT);
267
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",
275 void_ptr_type,
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",
281 void_ptr_type);
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",
296 uni_str_type,
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);
301
302 rupp_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
303 NULL, rupp_type);
304
305
306 /* struct process environment block */
307 peb_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
308 TYPE_NAME (peb_type) = xstrdup ("peb");
309
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,
321 NULL);
322 TYPE_TARGET_TYPE (peb_ptr_type) = peb_type;
323
324
325 /* struct thread information block */
326 tib_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
327 TYPE_NAME (tib_type) = xstrdup ("tib");
328
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",
333 void_ptr_type);
334 /* uint32_t current_bottom_of_stack; %fs:0x0008 */
335 append_composite_type_field (tib_type, "current_bottom_of_stack",
336 void_ptr_type);
337 /* uint32_t sub_system_tib; %fs:0x000c */
338 append_composite_type_field (tib_type, "sub_system_tib", void_ptr_type);
339
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",
356 void_ptr_type);
357 /* uint32_t process_environment_block; %fs:0x0030 */
358 append_composite_type_field (tib_type, "process_environment_block",
359 peb_ptr_type);
360 /* uint32_t last_error_number; %fs:0x0034 */
361 append_composite_type_field (tib_type, "last_error_number", dword_ptr_type);
362
363 tib_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
364 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
365 NULL);
366 TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
367
368 last_tlb_type = tib_ptr_type;
369 last_gdbarch = gdbarch;
370
371 return tib_ptr_type;
372 }
373
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. */
378
379 /* This function implements the lval_computed support for reading a
380 $_tlb value. */
381
382 static void
383 tlb_value_read (struct value *val)
384 {
385 CORE_ADDR tlb;
386 struct type *type = check_typedef (value_type (val));
387
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);
391 }
392
393 /* This function implements the lval_computed support for writing a
394 $_tlb value. */
395
396 static void
397 tlb_value_write (struct value *v, struct value *fromval)
398 {
399 error (_("Impossible to change the Thread Local Base"));
400 }
401
402 static const struct lval_funcs tlb_value_funcs =
403 {
404 tlb_value_read,
405 tlb_value_write
406 };
407
408
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. */
412
413 static struct value *
414 tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
415 {
416 if (target_has_stack && inferior_ptid != null_ptid)
417 {
418 struct type *type = windows_get_tlb_type (gdbarch);
419 return allocate_computed_value (type, &tlb_value_funcs, NULL);
420 }
421
422 return allocate_value (builtin_type (gdbarch)->builtin_void);
423 }
424
425
426 /* Display thread information block of a given thread. */
427
428 static int
429 display_one_tib (ptid_t ptid)
430 {
431 gdb_byte *tib = NULL;
432 gdb_byte *index;
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 ());
437
438 if (sizeof_ptr == 64)
439 {
440 size = sizeof (uint64_t);
441 tib_size = sizeof (thread_information_64);
442 max = MAX_TIB64;
443 }
444 else
445 {
446 size = sizeof (uint32_t);
447 tib_size = sizeof (thread_information_32);
448 max = MAX_TIB32;
449 }
450
451 max_name = max;
452
453 if (maint_display_all_tib)
454 {
455 tib_size = FULL_TIB_SIZE;
456 max = tib_size / size;
457 }
458
459 tib = (gdb_byte *) alloca (tib_size);
460
461 if (target_get_tib_address (ptid, &thread_local_base) == 0)
462 {
463 printf_filtered (_("Unable to get thread local base for %s\n"),
464 target_pid_to_str (ptid).c_str ());
465 return -1;
466 }
467
468 if (target_read (current_top_target (), TARGET_OBJECT_MEMORY,
469 NULL, tib, thread_local_base, tib_size) != tib_size)
470 {
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));
475 return -1;
476 }
477
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));
481
482 index = (gdb_byte *) tib;
483
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++)
487 {
488 val = extract_unsigned_integer (index, size, byte_order);
489 if (i < max_name)
490 printf_filtered (_("%s is 0x%s\n"), TIB_NAME[i], phex (val, size));
491 else if (val != 0)
492 printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i * size, 2),
493 phex (val, size));
494 index += size;
495 }
496 return 1;
497 }
498
499 /* Display thread information block of the current thread. */
500
501 static void
502 display_tib (const char * args, int from_tty)
503 {
504 if (inferior_ptid != null_ptid)
505 display_one_tib (inferior_ptid);
506 }
507
508 void
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)
512 {
513 CORE_ADDR text_offset = text_offset_cached ? *text_offset_cached : 0;
514
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=\"");
519
520 if (!text_offset)
521 {
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
525 in that case. */
526 text_offset = pe_text_section_offset (dll.get ());
527 if (text_offset_cached)
528 *text_offset_cached = text_offset;
529 }
530
531 obstack_grow_str (obstack, paddress (gdbarch, load_addr + text_offset));
532 obstack_grow_str (obstack, "\"/></library>");
533 }
534
535 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
536 method. It searches all objfiles, starting with CURRENT_OBJFILE
537 first (if not NULL).
538
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.
544
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. */
552
553 static void
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)
558 {
559 int stop;
560
561 if (current_objfile)
562 {
563 stop = cb (current_objfile, cb_data);
564 if (stop)
565 return;
566 }
567
568 for (objfile *objfile : current_program_space->objfiles ())
569 {
570 if (objfile != current_objfile)
571 {
572 stop = cb (objfile, cb_data);
573 if (stop)
574 return;
575 }
576 }
577 }
578
579 static void
580 show_maint_show_all_tib (struct ui_file *file, int from_tty,
581 struct cmd_list_element *c, const char *value)
582 {
583 fprintf_filtered (file, _("Show all non-zero elements of "
584 "Thread Information Block is %s.\n"), value);
585 }
586
587 static void
588 info_w32_command (const char *args, int from_tty)
589 {
590 help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);
591 }
592
593 static int w32_prefix_command_valid = 0;
594 void
595 init_w32_command_list (void)
596 {
597 if (!w32_prefix_command_valid)
598 {
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;
603 }
604 }
605
606 /* Implementation of `gdbarch_gdb_signal_to_target'. */
607
608 static int
609 windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
610 {
611 switch (signal)
612 {
613 case GDB_SIGNAL_0:
614 return 0;
615 case GDB_SIGNAL_HUP:
616 return WINDOWS_SIGHUP;
617 case GDB_SIGNAL_INT:
618 return WINDOWS_SIGINT;
619 case GDB_SIGNAL_QUIT:
620 return WINDOWS_SIGQUIT;
621 case GDB_SIGNAL_ILL:
622 return WINDOWS_SIGILL;
623 case GDB_SIGNAL_TRAP:
624 return WINDOWS_SIGTRAP;
625 case GDB_SIGNAL_ABRT:
626 return WINDOWS_SIGABRT;
627 case GDB_SIGNAL_EMT:
628 return WINDOWS_SIGEMT;
629 case GDB_SIGNAL_FPE:
630 return WINDOWS_SIGFPE;
631 case GDB_SIGNAL_KILL:
632 return WINDOWS_SIGKILL;
633 case GDB_SIGNAL_BUS:
634 return WINDOWS_SIGBUS;
635 case GDB_SIGNAL_SEGV:
636 return WINDOWS_SIGSEGV;
637 case GDB_SIGNAL_SYS:
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;
645 #ifdef __CYGWIN__
646 case GDB_SIGNAL_URG:
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;
660 case GDB_SIGNAL_IO:
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;
672 case GDB_SIGNAL_PWR:
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__ */
679 }
680 return -1;
681 }
682
683 struct enum_value_name
684 {
685 uint32_t value;
686 const char *name;
687 };
688
689 /* Allocate a TYPE_CODE_ENUM type structure with its named values. */
690
691 static struct type *
692 create_enum (struct gdbarch *gdbarch, int bit, const char *name,
693 const struct enum_value_name *values, int count)
694 {
695 struct type *type;
696 int i;
697
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;
703
704 for (i = 0; i < count; i++)
705 {
706 TYPE_FIELD_NAME (type, i) = values[i].name;
707 SET_FIELD_ENUMVAL (TYPE_FIELD (type, i), values[i].value);
708 }
709
710 return type;
711 }
712
713 static const struct enum_value_name exception_values[] =
714 {
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" },
739 };
740
741 static const struct enum_value_name violation_values[] =
742 {
743 { 0, "READ_ACCESS_VIOLATION" },
744 { 1, "WRITE_ACCESS_VIOLATION" },
745 { 8, "DATA_EXECUTION_PREVENTION_VIOLATION" },
746 };
747
748 /* Implement the "get_siginfo_type" gdbarch method. */
749
750 static struct type *
751 windows_get_siginfo_type (struct gdbarch *gdbarch)
752 {
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;
757
758 windows_gdbarch_data = get_windows_gdbarch_data (gdbarch);
759 if (windows_gdbarch_data->siginfo_type != NULL)
760 return windows_gdbarch_data->siginfo_type;
761
762 dword_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
763 1, "DWORD");
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),
767 1, "ULONG_PTR");
768
769 /* ExceptionCode value names */
770 code_enum = create_enum (gdbarch, gdbarch_int_bit (gdbarch),
771 "ExceptionCode", exception_values,
772 ARRAY_SIZE (exception_values));
773
774 /* ACCESS_VIOLATION type names */
775 violation_enum = create_enum (gdbarch, gdbarch_ptr_bit (gdbarch),
776 "ViolationType", violation_values,
777 ARRAY_SIZE (violation_values));
778
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);
783
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",
791 violation_type);
792
793 siginfo_type = arch_composite_type (gdbarch, "EXCEPTION_RECORD",
794 TYPE_CODE_STRUCT);
795 siginfo_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
796 NULL, siginfo_type);
797
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",
803 siginfo_ptr_type);
804 append_composite_type_field (siginfo_type, "ExceptionAddress",
805 pvoid_type);
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));
810
811 windows_gdbarch_data->siginfo_type = siginfo_type;
812
813 return siginfo_type;
814 }
815
816 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
817 various Windows architectures and machine types. */
818
819 void
820 windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
821 {
822 set_gdbarch_wchar_bit (gdbarch, 16);
823 set_gdbarch_wchar_signed (gdbarch, 0);
824
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);
828
829 set_gdbarch_iterate_over_objfiles_in_search_order
830 (gdbarch, windows_iterate_over_objfiles_in_search_order);
831
832 set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
833
834 set_solib_ops (gdbarch, &solib_target_so_ops);
835
836 set_gdbarch_get_siginfo_type (gdbarch, windows_get_siginfo_type);
837 }
838
839 /* Implementation of `tlb' variable. */
840
841 static const struct internalvar_funcs tlb_funcs =
842 {
843 tlb_make_value,
844 NULL,
845 NULL
846 };
847
848 void _initialize_windows_tdep ();
849 void
850 _initialize_windows_tdep ()
851 {
852 windows_gdbarch_data_handle
853 = gdbarch_data_register_post_init (init_windows_gdbarch_data);
854
855 init_w32_command_list ();
856 add_cmd ("thread-information-block", class_info, display_tib,
857 _("Display thread information block."),
858 &info_w32_cmdlist);
859 add_alias_cmd ("tib", "thread-information-block", class_info, 1,
860 &info_w32_cmdlist);
861
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."),
869 NULL,
870 show_maint_show_all_tib,
871 &maintenance_set_cmdlist,
872 &maintenance_show_cmdlist);
873
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);
879 }
This page took 0.051169 seconds and 4 git commands to generate.