gdb: add declaration for _initialize_gdbarch in gdbarch.sh
[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 /* Define Thread Local Base pointer type. */
157
158 static struct type *
159 windows_get_tlb_type (struct gdbarch *gdbarch)
160 {
161 static struct gdbarch *last_gdbarch = NULL;
162 static struct type *last_tlb_type = NULL;
163 struct type *dword_ptr_type, *dword32_type, *void_ptr_type;
164 struct type *peb_ldr_type, *peb_ldr_ptr_type;
165 struct type *peb_type, *peb_ptr_type, *list_type;
166 struct type *module_list_ptr_type;
167 struct type *tib_type, *seh_type, *tib_ptr_type, *seh_ptr_type;
168 struct type *word_type, *wchar_type, *wchar_ptr_type;
169 struct type *uni_str_type, *rupp_type, *rupp_ptr_type;
170
171 /* Do not rebuild type if same gdbarch as last time. */
172 if (last_tlb_type && last_gdbarch == gdbarch)
173 return last_tlb_type;
174
175 dword_ptr_type = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
176 1, "DWORD_PTR");
177 dword32_type = arch_integer_type (gdbarch, 32,
178 1, "DWORD32");
179 word_type = arch_integer_type (gdbarch, 16,
180 1, "WORD");
181 wchar_type = arch_integer_type (gdbarch, 16,
182 1, "wchar_t");
183 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
184 wchar_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
185 NULL, wchar_type);
186
187 /* list entry */
188
189 list_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
190 TYPE_NAME (list_type) = xstrdup ("list");
191
192 module_list_ptr_type = void_ptr_type;
193
194 append_composite_type_field (list_type, "forward_list",
195 module_list_ptr_type);
196 append_composite_type_field (list_type, "backward_list",
197 module_list_ptr_type);
198
199 /* Structured Exception Handler */
200
201 seh_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
202 TYPE_NAME (seh_type) = xstrdup ("seh");
203
204 seh_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
205 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
206 NULL);
207 TYPE_TARGET_TYPE (seh_ptr_type) = seh_type;
208
209 append_composite_type_field (seh_type, "next_seh", seh_ptr_type);
210 append_composite_type_field (seh_type, "handler",
211 builtin_type (gdbarch)->builtin_func_ptr);
212
213 /* struct _PEB_LDR_DATA */
214 peb_ldr_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
215 TYPE_NAME (peb_ldr_type) = xstrdup ("peb_ldr_data");
216
217 append_composite_type_field (peb_ldr_type, "length", dword32_type);
218 append_composite_type_field (peb_ldr_type, "initialized", dword32_type);
219 append_composite_type_field (peb_ldr_type, "ss_handle", void_ptr_type);
220 append_composite_type_field (peb_ldr_type, "in_load_order", list_type);
221 append_composite_type_field (peb_ldr_type, "in_memory_order", list_type);
222 append_composite_type_field (peb_ldr_type, "in_init_order", list_type);
223 append_composite_type_field (peb_ldr_type, "entry_in_progress",
224 void_ptr_type);
225 peb_ldr_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
226 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
227 NULL);
228 TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type;
229
230 /* struct UNICODE_STRING */
231 uni_str_type = arch_composite_type (gdbarch, "unicode_string",
232 TYPE_CODE_STRUCT);
233
234 append_composite_type_field (uni_str_type, "length", word_type);
235 append_composite_type_field (uni_str_type, "maximum_length", word_type);
236 append_composite_type_field_aligned (uni_str_type, "buffer",
237 wchar_ptr_type,
238 TYPE_LENGTH (wchar_ptr_type));
239
240 /* struct _RTL_USER_PROCESS_PARAMETERS */
241 rupp_type = arch_composite_type (gdbarch, "rtl_user_process_parameters",
242 TYPE_CODE_STRUCT);
243
244 append_composite_type_field (rupp_type, "maximum_length", dword32_type);
245 append_composite_type_field (rupp_type, "length", dword32_type);
246 append_composite_type_field (rupp_type, "flags", dword32_type);
247 append_composite_type_field (rupp_type, "debug_flags", dword32_type);
248 append_composite_type_field (rupp_type, "console_handle", void_ptr_type);
249 append_composite_type_field (rupp_type, "console_flags", dword32_type);
250 append_composite_type_field_aligned (rupp_type, "standard_input",
251 void_ptr_type,
252 TYPE_LENGTH (void_ptr_type));
253 append_composite_type_field (rupp_type, "standard_output", void_ptr_type);
254 append_composite_type_field (rupp_type, "standard_error", void_ptr_type);
255 append_composite_type_field (rupp_type, "current_directory", uni_str_type);
256 append_composite_type_field (rupp_type, "current_directory_handle",
257 void_ptr_type);
258 append_composite_type_field (rupp_type, "dll_path", uni_str_type);
259 append_composite_type_field (rupp_type, "image_path_name", uni_str_type);
260 append_composite_type_field (rupp_type, "command_line", uni_str_type);
261 append_composite_type_field (rupp_type, "environment", void_ptr_type);
262 append_composite_type_field (rupp_type, "starting_x", dword32_type);
263 append_composite_type_field (rupp_type, "starting_y", dword32_type);
264 append_composite_type_field (rupp_type, "count_x", dword32_type);
265 append_composite_type_field (rupp_type, "count_y", dword32_type);
266 append_composite_type_field (rupp_type, "count_chars_x", dword32_type);
267 append_composite_type_field (rupp_type, "count_chars_y", dword32_type);
268 append_composite_type_field (rupp_type, "fill_attribute", dword32_type);
269 append_composite_type_field (rupp_type, "window_flags", dword32_type);
270 append_composite_type_field (rupp_type, "show_window_flags", dword32_type);
271 append_composite_type_field_aligned (rupp_type, "window_title",
272 uni_str_type,
273 TYPE_LENGTH (void_ptr_type));
274 append_composite_type_field (rupp_type, "desktop_info", uni_str_type);
275 append_composite_type_field (rupp_type, "shell_info", uni_str_type);
276 append_composite_type_field (rupp_type, "runtime_data", uni_str_type);
277
278 rupp_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
279 NULL, rupp_type);
280
281
282 /* struct process environment block */
283 peb_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
284 TYPE_NAME (peb_type) = xstrdup ("peb");
285
286 /* First bytes contain several flags. */
287 append_composite_type_field (peb_type, "flags", dword_ptr_type);
288 append_composite_type_field (peb_type, "mutant", void_ptr_type);
289 append_composite_type_field (peb_type, "image_base_address", void_ptr_type);
290 append_composite_type_field (peb_type, "ldr", peb_ldr_ptr_type);
291 append_composite_type_field (peb_type, "process_parameters", rupp_ptr_type);
292 append_composite_type_field (peb_type, "sub_system_data", void_ptr_type);
293 append_composite_type_field (peb_type, "process_heap", void_ptr_type);
294 append_composite_type_field (peb_type, "fast_peb_lock", void_ptr_type);
295 peb_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
296 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
297 NULL);
298 TYPE_TARGET_TYPE (peb_ptr_type) = peb_type;
299
300
301 /* struct thread information block */
302 tib_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
303 TYPE_NAME (tib_type) = xstrdup ("tib");
304
305 /* uint32_t current_seh; %fs:0x0000 */
306 append_composite_type_field (tib_type, "current_seh", seh_ptr_type);
307 /* uint32_t current_top_of_stack; %fs:0x0004 */
308 append_composite_type_field (tib_type, "current_top_of_stack",
309 void_ptr_type);
310 /* uint32_t current_bottom_of_stack; %fs:0x0008 */
311 append_composite_type_field (tib_type, "current_bottom_of_stack",
312 void_ptr_type);
313 /* uint32_t sub_system_tib; %fs:0x000c */
314 append_composite_type_field (tib_type, "sub_system_tib", void_ptr_type);
315
316 /* uint32_t fiber_data; %fs:0x0010 */
317 append_composite_type_field (tib_type, "fiber_data", void_ptr_type);
318 /* uint32_t arbitrary_data_slot; %fs:0x0014 */
319 append_composite_type_field (tib_type, "arbitrary_data_slot", void_ptr_type);
320 /* uint32_t linear_address_tib; %fs:0x0018 */
321 append_composite_type_field (tib_type, "linear_address_tib", void_ptr_type);
322 /* uint32_t environment_pointer; %fs:0x001c */
323 append_composite_type_field (tib_type, "environment_pointer", void_ptr_type);
324 /* uint32_t process_id; %fs:0x0020 */
325 append_composite_type_field (tib_type, "process_id", dword_ptr_type);
326 /* uint32_t current_thread_id; %fs:0x0024 */
327 append_composite_type_field (tib_type, "thread_id", dword_ptr_type);
328 /* uint32_t active_rpc_handle; %fs:0x0028 */
329 append_composite_type_field (tib_type, "active_rpc_handle", dword_ptr_type);
330 /* uint32_t thread_local_storage; %fs:0x002c */
331 append_composite_type_field (tib_type, "thread_local_storage",
332 void_ptr_type);
333 /* uint32_t process_environment_block; %fs:0x0030 */
334 append_composite_type_field (tib_type, "process_environment_block",
335 peb_ptr_type);
336 /* uint32_t last_error_number; %fs:0x0034 */
337 append_composite_type_field (tib_type, "last_error_number", dword_ptr_type);
338
339 tib_ptr_type = arch_type (gdbarch, TYPE_CODE_PTR,
340 TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT,
341 NULL);
342 TYPE_TARGET_TYPE (tib_ptr_type) = tib_type;
343
344 last_tlb_type = tib_ptr_type;
345 last_gdbarch = gdbarch;
346
347 return tib_ptr_type;
348 }
349
350 /* The $_tlb convenience variable is a bit special. We don't know
351 for sure the type of the value until we actually have a chance to
352 fetch the data. The type can change depending on gdbarch, so it is
353 also dependent on which thread you have selected. */
354
355 /* This function implements the lval_computed support for reading a
356 $_tlb value. */
357
358 static void
359 tlb_value_read (struct value *val)
360 {
361 CORE_ADDR tlb;
362 struct type *type = check_typedef (value_type (val));
363
364 if (!target_get_tib_address (inferior_ptid, &tlb))
365 error (_("Unable to read tlb"));
366 store_typed_address (value_contents_raw (val), type, tlb);
367 }
368
369 /* This function implements the lval_computed support for writing a
370 $_tlb value. */
371
372 static void
373 tlb_value_write (struct value *v, struct value *fromval)
374 {
375 error (_("Impossible to change the Thread Local Base"));
376 }
377
378 static const struct lval_funcs tlb_value_funcs =
379 {
380 tlb_value_read,
381 tlb_value_write
382 };
383
384
385 /* Return a new value with the correct type for the tlb object of
386 the current thread using architecture GDBARCH. Return a void value
387 if there's no object available. */
388
389 static struct value *
390 tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
391 {
392 if (target_has_stack && inferior_ptid != null_ptid)
393 {
394 struct type *type = windows_get_tlb_type (gdbarch);
395 return allocate_computed_value (type, &tlb_value_funcs, NULL);
396 }
397
398 return allocate_value (builtin_type (gdbarch)->builtin_void);
399 }
400
401
402 /* Display thread information block of a given thread. */
403
404 static int
405 display_one_tib (ptid_t ptid)
406 {
407 gdb_byte *tib = NULL;
408 gdb_byte *index;
409 CORE_ADDR thread_local_base;
410 ULONGEST i, val, max, max_name, size, tib_size;
411 ULONGEST sizeof_ptr = gdbarch_ptr_bit (target_gdbarch ());
412 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
413
414 if (sizeof_ptr == 64)
415 {
416 size = sizeof (uint64_t);
417 tib_size = sizeof (thread_information_64);
418 max = MAX_TIB64;
419 }
420 else
421 {
422 size = sizeof (uint32_t);
423 tib_size = sizeof (thread_information_32);
424 max = MAX_TIB32;
425 }
426
427 max_name = max;
428
429 if (maint_display_all_tib)
430 {
431 tib_size = FULL_TIB_SIZE;
432 max = tib_size / size;
433 }
434
435 tib = (gdb_byte *) alloca (tib_size);
436
437 if (target_get_tib_address (ptid, &thread_local_base) == 0)
438 {
439 printf_filtered (_("Unable to get thread local base for %s\n"),
440 target_pid_to_str (ptid).c_str ());
441 return -1;
442 }
443
444 if (target_read (current_top_target (), TARGET_OBJECT_MEMORY,
445 NULL, tib, thread_local_base, tib_size) != tib_size)
446 {
447 printf_filtered (_("Unable to read thread information "
448 "block for %s at address %s\n"),
449 target_pid_to_str (ptid).c_str (),
450 paddress (target_gdbarch (), thread_local_base));
451 return -1;
452 }
453
454 printf_filtered (_("Thread Information Block %s at %s\n"),
455 target_pid_to_str (ptid).c_str (),
456 paddress (target_gdbarch (), thread_local_base));
457
458 index = (gdb_byte *) tib;
459
460 /* All fields have the size of a pointer, this allows to iterate
461 using the same for loop for both layouts. */
462 for (i = 0; i < max; i++)
463 {
464 val = extract_unsigned_integer (index, size, byte_order);
465 if (i < max_name)
466 printf_filtered (_("%s is 0x%s\n"), TIB_NAME[i], phex (val, size));
467 else if (val != 0)
468 printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i * size, 2),
469 phex (val, size));
470 index += size;
471 }
472 return 1;
473 }
474
475 /* Display thread information block of the current thread. */
476
477 static void
478 display_tib (const char * args, int from_tty)
479 {
480 if (inferior_ptid != null_ptid)
481 display_one_tib (inferior_ptid);
482 }
483
484 void
485 windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
486 struct gdbarch *gdbarch, struct obstack *obstack)
487 {
488 CORE_ADDR text_offset;
489
490 obstack_grow_str (obstack, "<library name=\"");
491 std::string p = xml_escape_text (so_name);
492 obstack_grow_str (obstack, p.c_str ());
493 obstack_grow_str (obstack, "\"><segment address=\"");
494 gdb_bfd_ref_ptr dll (gdb_bfd_open (so_name, gnutarget, -1));
495 /* The following calls are OK even if dll is NULL.
496 The default value 0x1000 is returned by pe_text_section_offset
497 in that case. */
498 text_offset = pe_text_section_offset (dll.get ());
499 obstack_grow_str (obstack, paddress (gdbarch, load_addr + text_offset));
500 obstack_grow_str (obstack, "\"/></library>");
501 }
502
503 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
504 method. It searches all objfiles, starting with CURRENT_OBJFILE
505 first (if not NULL).
506
507 On Windows, the system behaves a little differently when two
508 objfiles each define a global symbol using the same name, compared
509 to other platforms such as GNU/Linux for instance. On GNU/Linux,
510 all instances of the symbol effectively get merged into a single
511 one, but on Windows, they remain distinct.
512
513 As a result, it usually makes sense to start global symbol searches
514 with the current objfile before expanding it to all other objfiles.
515 This helps for instance when a user debugs some code in a DLL that
516 refers to a global variable defined inside that DLL. When trying
517 to print the value of that global variable, it would be unhelpful
518 to print the value of another global variable defined with the same
519 name, but in a different DLL. */
520
521 static void
522 windows_iterate_over_objfiles_in_search_order
523 (struct gdbarch *gdbarch,
524 iterate_over_objfiles_in_search_order_cb_ftype *cb,
525 void *cb_data, struct objfile *current_objfile)
526 {
527 int stop;
528
529 if (current_objfile)
530 {
531 stop = cb (current_objfile, cb_data);
532 if (stop)
533 return;
534 }
535
536 for (objfile *objfile : current_program_space->objfiles ())
537 {
538 if (objfile != current_objfile)
539 {
540 stop = cb (objfile, cb_data);
541 if (stop)
542 return;
543 }
544 }
545 }
546
547 static void
548 show_maint_show_all_tib (struct ui_file *file, int from_tty,
549 struct cmd_list_element *c, const char *value)
550 {
551 fprintf_filtered (file, _("Show all non-zero elements of "
552 "Thread Information Block is %s.\n"), value);
553 }
554
555 static void
556 info_w32_command (const char *args, int from_tty)
557 {
558 help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);
559 }
560
561 static int w32_prefix_command_valid = 0;
562 void
563 init_w32_command_list (void)
564 {
565 if (!w32_prefix_command_valid)
566 {
567 add_prefix_cmd ("w32", class_info, info_w32_command,
568 _("Print information specific to Win32 debugging."),
569 &info_w32_cmdlist, "info w32 ", 0, &infolist);
570 w32_prefix_command_valid = 1;
571 }
572 }
573
574 /* Implementation of `gdbarch_gdb_signal_to_target'. */
575
576 static int
577 windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
578 {
579 switch (signal)
580 {
581 case GDB_SIGNAL_0:
582 return 0;
583 case GDB_SIGNAL_HUP:
584 return WINDOWS_SIGHUP;
585 case GDB_SIGNAL_INT:
586 return WINDOWS_SIGINT;
587 case GDB_SIGNAL_QUIT:
588 return WINDOWS_SIGQUIT;
589 case GDB_SIGNAL_ILL:
590 return WINDOWS_SIGILL;
591 case GDB_SIGNAL_TRAP:
592 return WINDOWS_SIGTRAP;
593 case GDB_SIGNAL_ABRT:
594 return WINDOWS_SIGABRT;
595 case GDB_SIGNAL_EMT:
596 return WINDOWS_SIGEMT;
597 case GDB_SIGNAL_FPE:
598 return WINDOWS_SIGFPE;
599 case GDB_SIGNAL_KILL:
600 return WINDOWS_SIGKILL;
601 case GDB_SIGNAL_BUS:
602 return WINDOWS_SIGBUS;
603 case GDB_SIGNAL_SEGV:
604 return WINDOWS_SIGSEGV;
605 case GDB_SIGNAL_SYS:
606 return WINDOWS_SIGSYS;
607 case GDB_SIGNAL_PIPE:
608 return WINDOWS_SIGPIPE;
609 case GDB_SIGNAL_ALRM:
610 return WINDOWS_SIGALRM;
611 case GDB_SIGNAL_TERM:
612 return WINDOWS_SIGTERM;
613 #ifdef __CYGWIN__
614 case GDB_SIGNAL_URG:
615 return WINDOWS_SIGURG;
616 case GDB_SIGNAL_STOP:
617 return WINDOWS_SIGSTOP;
618 case GDB_SIGNAL_TSTP:
619 return WINDOWS_SIGTSTP;
620 case GDB_SIGNAL_CONT:
621 return WINDOWS_SIGCONT;
622 case GDB_SIGNAL_CHLD:
623 return WINDOWS_SIGCHLD;
624 case GDB_SIGNAL_TTIN:
625 return WINDOWS_SIGTTIN;
626 case GDB_SIGNAL_TTOU:
627 return WINDOWS_SIGTTOU;
628 case GDB_SIGNAL_IO:
629 return WINDOWS_SIGIO;
630 case GDB_SIGNAL_XCPU:
631 return WINDOWS_SIGXCPU;
632 case GDB_SIGNAL_XFSZ:
633 return WINDOWS_SIGXFSZ;
634 case GDB_SIGNAL_VTALRM:
635 return WINDOWS_SIGVTALRM;
636 case GDB_SIGNAL_PROF:
637 return WINDOWS_SIGPROF;
638 case GDB_SIGNAL_WINCH:
639 return WINDOWS_SIGWINCH;
640 case GDB_SIGNAL_PWR:
641 return WINDOWS_SIGLOST;
642 case GDB_SIGNAL_USR1:
643 return WINDOWS_SIGUSR1;
644 case GDB_SIGNAL_USR2:
645 return WINDOWS_SIGUSR2;
646 #endif /* __CYGWIN__ */
647 }
648 return -1;
649 }
650
651 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
652 various Windows architectures and machine types. */
653
654 void
655 windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
656 {
657 set_gdbarch_wchar_bit (gdbarch, 16);
658 set_gdbarch_wchar_signed (gdbarch, 0);
659
660 /* Canonical paths on this target look like
661 `c:\Program Files\Foo App\mydll.dll', for example. */
662 set_gdbarch_has_dos_based_file_system (gdbarch, 1);
663
664 set_gdbarch_iterate_over_objfiles_in_search_order
665 (gdbarch, windows_iterate_over_objfiles_in_search_order);
666
667 set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
668
669 set_solib_ops (gdbarch, &solib_target_so_ops);
670 }
671
672 /* Implementation of `tlb' variable. */
673
674 static const struct internalvar_funcs tlb_funcs =
675 {
676 tlb_make_value,
677 NULL,
678 NULL
679 };
680
681 void _initialize_windows_tdep ();
682 void
683 _initialize_windows_tdep ()
684 {
685 init_w32_command_list ();
686 add_cmd ("thread-information-block", class_info, display_tib,
687 _("Display thread information block."),
688 &info_w32_cmdlist);
689 add_alias_cmd ("tib", "thread-information-block", class_info, 1,
690 &info_w32_cmdlist);
691
692 add_setshow_boolean_cmd ("show-all-tib", class_maintenance,
693 &maint_display_all_tib, _("\
694 Set whether to display all non-zero fields of thread information block."), _("\
695 Show whether to display all non-zero fields of thread information block."), _("\
696 Use \"on\" to enable, \"off\" to disable.\n\
697 If enabled, all non-zero fields of thread information block are displayed,\n\
698 even if their meaning is unknown."),
699 NULL,
700 show_maint_show_all_tib,
701 &maintenance_set_cmdlist,
702 &maintenance_show_cmdlist);
703
704 /* Explicitly create without lookup, since that tries to create a
705 value with a void typed value, and when we get here, gdbarch
706 isn't initialized yet. At this point, we're quite sure there
707 isn't another convenience variable of the same name. */
708 create_internalvar_type_lazy ("_tlb", &tlb_funcs, NULL);
709 }
This page took 0.043498 seconds and 4 git commands to generate.