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