Cache the text section offset of shared libraries
[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 CORE_ADDR *text_offset_cached,
487 struct gdbarch *gdbarch, struct obstack *obstack)
488 {
489 CORE_ADDR text_offset = text_offset_cached ? *text_offset_cached : 0;
490
491 obstack_grow_str (obstack, "<library name=\"");
492 std::string p = xml_escape_text (so_name);
493 obstack_grow_str (obstack, p.c_str ());
494 obstack_grow_str (obstack, "\"><segment address=\"");
495
496 if (!text_offset)
497 {
498 gdb_bfd_ref_ptr dll (gdb_bfd_open (so_name, gnutarget, -1));
499 /* The following calls are OK even if dll is NULL.
500 The default value 0x1000 is returned by pe_text_section_offset
501 in that case. */
502 text_offset = pe_text_section_offset (dll.get ());
503 if (text_offset_cached)
504 *text_offset_cached = text_offset;
505 }
506
507 obstack_grow_str (obstack, paddress (gdbarch, load_addr + text_offset));
508 obstack_grow_str (obstack, "\"/></library>");
509 }
510
511 /* Implement the "iterate_over_objfiles_in_search_order" gdbarch
512 method. It searches all objfiles, starting with CURRENT_OBJFILE
513 first (if not NULL).
514
515 On Windows, the system behaves a little differently when two
516 objfiles each define a global symbol using the same name, compared
517 to other platforms such as GNU/Linux for instance. On GNU/Linux,
518 all instances of the symbol effectively get merged into a single
519 one, but on Windows, they remain distinct.
520
521 As a result, it usually makes sense to start global symbol searches
522 with the current objfile before expanding it to all other objfiles.
523 This helps for instance when a user debugs some code in a DLL that
524 refers to a global variable defined inside that DLL. When trying
525 to print the value of that global variable, it would be unhelpful
526 to print the value of another global variable defined with the same
527 name, but in a different DLL. */
528
529 static void
530 windows_iterate_over_objfiles_in_search_order
531 (struct gdbarch *gdbarch,
532 iterate_over_objfiles_in_search_order_cb_ftype *cb,
533 void *cb_data, struct objfile *current_objfile)
534 {
535 int stop;
536
537 if (current_objfile)
538 {
539 stop = cb (current_objfile, cb_data);
540 if (stop)
541 return;
542 }
543
544 for (objfile *objfile : current_program_space->objfiles ())
545 {
546 if (objfile != current_objfile)
547 {
548 stop = cb (objfile, cb_data);
549 if (stop)
550 return;
551 }
552 }
553 }
554
555 static void
556 show_maint_show_all_tib (struct ui_file *file, int from_tty,
557 struct cmd_list_element *c, const char *value)
558 {
559 fprintf_filtered (file, _("Show all non-zero elements of "
560 "Thread Information Block is %s.\n"), value);
561 }
562
563 static void
564 info_w32_command (const char *args, int from_tty)
565 {
566 help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout);
567 }
568
569 static int w32_prefix_command_valid = 0;
570 void
571 init_w32_command_list (void)
572 {
573 if (!w32_prefix_command_valid)
574 {
575 add_prefix_cmd ("w32", class_info, info_w32_command,
576 _("Print information specific to Win32 debugging."),
577 &info_w32_cmdlist, "info w32 ", 0, &infolist);
578 w32_prefix_command_valid = 1;
579 }
580 }
581
582 /* Implementation of `gdbarch_gdb_signal_to_target'. */
583
584 static int
585 windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal)
586 {
587 switch (signal)
588 {
589 case GDB_SIGNAL_0:
590 return 0;
591 case GDB_SIGNAL_HUP:
592 return WINDOWS_SIGHUP;
593 case GDB_SIGNAL_INT:
594 return WINDOWS_SIGINT;
595 case GDB_SIGNAL_QUIT:
596 return WINDOWS_SIGQUIT;
597 case GDB_SIGNAL_ILL:
598 return WINDOWS_SIGILL;
599 case GDB_SIGNAL_TRAP:
600 return WINDOWS_SIGTRAP;
601 case GDB_SIGNAL_ABRT:
602 return WINDOWS_SIGABRT;
603 case GDB_SIGNAL_EMT:
604 return WINDOWS_SIGEMT;
605 case GDB_SIGNAL_FPE:
606 return WINDOWS_SIGFPE;
607 case GDB_SIGNAL_KILL:
608 return WINDOWS_SIGKILL;
609 case GDB_SIGNAL_BUS:
610 return WINDOWS_SIGBUS;
611 case GDB_SIGNAL_SEGV:
612 return WINDOWS_SIGSEGV;
613 case GDB_SIGNAL_SYS:
614 return WINDOWS_SIGSYS;
615 case GDB_SIGNAL_PIPE:
616 return WINDOWS_SIGPIPE;
617 case GDB_SIGNAL_ALRM:
618 return WINDOWS_SIGALRM;
619 case GDB_SIGNAL_TERM:
620 return WINDOWS_SIGTERM;
621 #ifdef __CYGWIN__
622 case GDB_SIGNAL_URG:
623 return WINDOWS_SIGURG;
624 case GDB_SIGNAL_STOP:
625 return WINDOWS_SIGSTOP;
626 case GDB_SIGNAL_TSTP:
627 return WINDOWS_SIGTSTP;
628 case GDB_SIGNAL_CONT:
629 return WINDOWS_SIGCONT;
630 case GDB_SIGNAL_CHLD:
631 return WINDOWS_SIGCHLD;
632 case GDB_SIGNAL_TTIN:
633 return WINDOWS_SIGTTIN;
634 case GDB_SIGNAL_TTOU:
635 return WINDOWS_SIGTTOU;
636 case GDB_SIGNAL_IO:
637 return WINDOWS_SIGIO;
638 case GDB_SIGNAL_XCPU:
639 return WINDOWS_SIGXCPU;
640 case GDB_SIGNAL_XFSZ:
641 return WINDOWS_SIGXFSZ;
642 case GDB_SIGNAL_VTALRM:
643 return WINDOWS_SIGVTALRM;
644 case GDB_SIGNAL_PROF:
645 return WINDOWS_SIGPROF;
646 case GDB_SIGNAL_WINCH:
647 return WINDOWS_SIGWINCH;
648 case GDB_SIGNAL_PWR:
649 return WINDOWS_SIGLOST;
650 case GDB_SIGNAL_USR1:
651 return WINDOWS_SIGUSR1;
652 case GDB_SIGNAL_USR2:
653 return WINDOWS_SIGUSR2;
654 #endif /* __CYGWIN__ */
655 }
656 return -1;
657 }
658
659 /* To be called from the various GDB_OSABI_CYGWIN handlers for the
660 various Windows architectures and machine types. */
661
662 void
663 windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
664 {
665 set_gdbarch_wchar_bit (gdbarch, 16);
666 set_gdbarch_wchar_signed (gdbarch, 0);
667
668 /* Canonical paths on this target look like
669 `c:\Program Files\Foo App\mydll.dll', for example. */
670 set_gdbarch_has_dos_based_file_system (gdbarch, 1);
671
672 set_gdbarch_iterate_over_objfiles_in_search_order
673 (gdbarch, windows_iterate_over_objfiles_in_search_order);
674
675 set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target);
676
677 set_solib_ops (gdbarch, &solib_target_so_ops);
678 }
679
680 /* Implementation of `tlb' variable. */
681
682 static const struct internalvar_funcs tlb_funcs =
683 {
684 tlb_make_value,
685 NULL,
686 NULL
687 };
688
689 void _initialize_windows_tdep ();
690 void
691 _initialize_windows_tdep ()
692 {
693 init_w32_command_list ();
694 add_cmd ("thread-information-block", class_info, display_tib,
695 _("Display thread information block."),
696 &info_w32_cmdlist);
697 add_alias_cmd ("tib", "thread-information-block", class_info, 1,
698 &info_w32_cmdlist);
699
700 add_setshow_boolean_cmd ("show-all-tib", class_maintenance,
701 &maint_display_all_tib, _("\
702 Set whether to display all non-zero fields of thread information block."), _("\
703 Show whether to display all non-zero fields of thread information block."), _("\
704 Use \"on\" to enable, \"off\" to disable.\n\
705 If enabled, all non-zero fields of thread information block are displayed,\n\
706 even if their meaning is unknown."),
707 NULL,
708 show_maint_show_all_tib,
709 &maintenance_set_cmdlist,
710 &maintenance_show_cmdlist);
711
712 /* Explicitly create without lookup, since that tries to create a
713 value with a void typed value, and when we get here, gdbarch
714 isn't initialized yet. At this point, we're quite sure there
715 isn't another convenience variable of the same name. */
716 create_internalvar_type_lazy ("_tlb", &tlb_funcs, NULL);
717 }
This page took 0.053739 seconds and 5 git commands to generate.