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 | 155 | |
7928d571 HD |
156 | static struct gdbarch_data *windows_gdbarch_data_handle; |
157 | ||
158 | struct windows_gdbarch_data | |
159 | { | |
160 | struct type *siginfo_type; | |
cd5900f3 | 161 | struct type *tib_ptr_type; /* Type of thread information block */ |
7928d571 HD |
162 | }; |
163 | ||
164 | /* Allocate windows_gdbarch_data for an arch. */ | |
165 | ||
166 | static void * | |
167 | init_windows_gdbarch_data (struct gdbarch *gdbarch) | |
168 | { | |
169 | return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct windows_gdbarch_data); | |
170 | } | |
171 | ||
172 | /* Get windows_gdbarch_data of an arch. */ | |
173 | ||
174 | static struct windows_gdbarch_data * | |
175 | get_windows_gdbarch_data (struct gdbarch *gdbarch) | |
176 | { | |
177 | return ((struct windows_gdbarch_data *) | |
178 | gdbarch_data (gdbarch, windows_gdbarch_data_handle)); | |
179 | } | |
180 | ||
711e434b PM |
181 | /* Define Thread Local Base pointer type. */ |
182 | ||
183 | static struct type * | |
184 | windows_get_tlb_type (struct gdbarch *gdbarch) | |
185 | { | |
186 | struct type *dword_ptr_type, *dword32_type, *void_ptr_type; | |
187 | struct type *peb_ldr_type, *peb_ldr_ptr_type; | |
870f88f7 | 188 | struct type *peb_type, *peb_ptr_type, *list_type; |
711e434b PM |
189 | struct type *module_list_ptr_type; |
190 | struct type *tib_type, *seh_type, *tib_ptr_type, *seh_ptr_type; | |
e0cdfe3c HD |
191 | struct type *word_type, *wchar_type, *wchar_ptr_type; |
192 | struct type *uni_str_type, *rupp_type, *rupp_ptr_type; | |
711e434b | 193 | |
cd5900f3 HD |
194 | windows_gdbarch_data *windows_gdbarch_data |
195 | = get_windows_gdbarch_data (gdbarch); | |
196 | if (windows_gdbarch_data->tib_ptr_type != nullptr) | |
197 | return windows_gdbarch_data->tib_ptr_type; | |
198 | ||
711e434b PM |
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"); | |
e0cdfe3c HD |
203 | word_type = arch_integer_type (gdbarch, 16, |
204 | 1, "WORD"); | |
205 | wchar_type = arch_integer_type (gdbarch, 16, | |
206 | 1, "wchar_t"); | |
711e434b | 207 | void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); |
e0cdfe3c HD |
208 | wchar_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), |
209 | NULL, wchar_type); | |
711e434b PM |
210 | |
211 | /* list entry */ | |
212 | ||
213 | list_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
214 | TYPE_NAME (list_type) = xstrdup ("list"); | |
215 | ||
711e434b PM |
216 | module_list_ptr_type = void_ptr_type; |
217 | ||
581e13c1 MS |
218 | append_composite_type_field (list_type, "forward_list", |
219 | module_list_ptr_type); | |
711e434b PM |
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, | |
77b7c781 UW |
229 | TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT, |
230 | NULL); | |
711e434b PM |
231 | TYPE_TARGET_TYPE (seh_ptr_type) = seh_type; |
232 | ||
233 | append_composite_type_field (seh_type, "next_seh", seh_ptr_type); | |
e8e6c82e PM |
234 | append_composite_type_field (seh_type, "handler", |
235 | builtin_type (gdbarch)->builtin_func_ptr); | |
711e434b PM |
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, | |
77b7c781 UW |
250 | TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT, |
251 | NULL); | |
711e434b PM |
252 | TYPE_TARGET_TYPE (peb_ldr_ptr_type) = peb_ldr_type; |
253 | ||
e0cdfe3c HD |
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 | ||
711e434b PM |
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); | |
e0cdfe3c | 315 | append_composite_type_field (peb_type, "process_parameters", rupp_ptr_type); |
711e434b PM |
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, | |
77b7c781 UW |
320 | TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT, |
321 | NULL); | |
711e434b PM |
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 */ | |
581e13c1 MS |
332 | append_composite_type_field (tib_type, "current_top_of_stack", |
333 | void_ptr_type); | |
711e434b PM |
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 */ | |
581e13c1 MS |
355 | append_composite_type_field (tib_type, "thread_local_storage", |
356 | void_ptr_type); | |
711e434b PM |
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, | |
77b7c781 UW |
364 | TYPE_LENGTH (void_ptr_type) * TARGET_CHAR_BIT, |
365 | NULL); | |
711e434b PM |
366 | TYPE_TARGET_TYPE (tib_ptr_type) = tib_type; |
367 | ||
cd5900f3 | 368 | windows_gdbarch_data->tib_ptr_type = tib_ptr_type; |
ea1fae46 | 369 | |
711e434b PM |
370 | return tib_ptr_type; |
371 | } | |
372 | ||
373 | /* The $_tlb convenience variable is a bit special. We don't know | |
374 | for sure the type of the value until we actually have a chance to | |
375 | fetch the data. The type can change depending on gdbarch, so it is | |
376 | also dependent on which thread you have selected. */ | |
377 | ||
378 | /* This function implements the lval_computed support for reading a | |
379 | $_tlb value. */ | |
380 | ||
381 | static void | |
382 | tlb_value_read (struct value *val) | |
383 | { | |
384 | CORE_ADDR tlb; | |
385 | struct type *type = check_typedef (value_type (val)); | |
386 | ||
387 | if (!target_get_tib_address (inferior_ptid, &tlb)) | |
388 | error (_("Unable to read tlb")); | |
389 | store_typed_address (value_contents_raw (val), type, tlb); | |
390 | } | |
391 | ||
392 | /* This function implements the lval_computed support for writing a | |
393 | $_tlb value. */ | |
394 | ||
395 | static void | |
396 | tlb_value_write (struct value *v, struct value *fromval) | |
397 | { | |
398 | error (_("Impossible to change the Thread Local Base")); | |
399 | } | |
400 | ||
c8f2448a | 401 | static const struct lval_funcs tlb_value_funcs = |
711e434b PM |
402 | { |
403 | tlb_value_read, | |
404 | tlb_value_write | |
405 | }; | |
406 | ||
407 | ||
408 | /* Return a new value with the correct type for the tlb object of | |
409 | the current thread using architecture GDBARCH. Return a void value | |
410 | if there's no object available. */ | |
411 | ||
412 | static struct value * | |
22d2b532 | 413 | tlb_make_value (struct gdbarch *gdbarch, struct internalvar *var, void *ignore) |
711e434b | 414 | { |
d7e15655 | 415 | if (target_has_stack && inferior_ptid != null_ptid) |
711e434b PM |
416 | { |
417 | struct type *type = windows_get_tlb_type (gdbarch); | |
418 | return allocate_computed_value (type, &tlb_value_funcs, NULL); | |
419 | } | |
420 | ||
421 | return allocate_value (builtin_type (gdbarch)->builtin_void); | |
422 | } | |
423 | ||
424 | ||
425 | /* Display thread information block of a given thread. */ | |
426 | ||
427 | static int | |
428 | display_one_tib (ptid_t ptid) | |
429 | { | |
430 | gdb_byte *tib = NULL; | |
431 | gdb_byte *index; | |
432 | CORE_ADDR thread_local_base; | |
433 | ULONGEST i, val, max, max_name, size, tib_size; | |
f5656ead TT |
434 | ULONGEST sizeof_ptr = gdbarch_ptr_bit (target_gdbarch ()); |
435 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ()); | |
711e434b PM |
436 | |
437 | if (sizeof_ptr == 64) | |
438 | { | |
439 | size = sizeof (uint64_t); | |
440 | tib_size = sizeof (thread_information_64); | |
441 | max = MAX_TIB64; | |
442 | } | |
443 | else | |
444 | { | |
445 | size = sizeof (uint32_t); | |
446 | tib_size = sizeof (thread_information_32); | |
447 | max = MAX_TIB32; | |
448 | } | |
449 | ||
450 | max_name = max; | |
451 | ||
452 | if (maint_display_all_tib) | |
453 | { | |
454 | tib_size = FULL_TIB_SIZE; | |
455 | max = tib_size / size; | |
456 | } | |
457 | ||
224c3ddb | 458 | tib = (gdb_byte *) alloca (tib_size); |
711e434b PM |
459 | |
460 | if (target_get_tib_address (ptid, &thread_local_base) == 0) | |
461 | { | |
462 | printf_filtered (_("Unable to get thread local base for %s\n"), | |
a068643d | 463 | target_pid_to_str (ptid).c_str ()); |
711e434b PM |
464 | return -1; |
465 | } | |
466 | ||
8b88a78e | 467 | if (target_read (current_top_target (), TARGET_OBJECT_MEMORY, |
711e434b PM |
468 | NULL, tib, thread_local_base, tib_size) != tib_size) |
469 | { | |
581e13c1 MS |
470 | printf_filtered (_("Unable to read thread information " |
471 | "block for %s at address %s\n"), | |
a068643d TT |
472 | target_pid_to_str (ptid).c_str (), |
473 | paddress (target_gdbarch (), thread_local_base)); | |
711e434b PM |
474 | return -1; |
475 | } | |
476 | ||
477 | printf_filtered (_("Thread Information Block %s at %s\n"), | |
a068643d | 478 | target_pid_to_str (ptid).c_str (), |
f5656ead | 479 | paddress (target_gdbarch (), thread_local_base)); |
711e434b PM |
480 | |
481 | index = (gdb_byte *) tib; | |
482 | ||
483 | /* All fields have the size of a pointer, this allows to iterate | |
484 | using the same for loop for both layouts. */ | |
485 | for (i = 0; i < max; i++) | |
486 | { | |
487 | val = extract_unsigned_integer (index, size, byte_order); | |
488 | if (i < max_name) | |
489 | printf_filtered (_("%s is 0x%s\n"), TIB_NAME[i], phex (val, size)); | |
490 | else if (val != 0) | |
491 | printf_filtered (_("TIB[0x%s] is 0x%s\n"), phex (i * size, 2), | |
492 | phex (val, size)); | |
493 | index += size; | |
494 | } | |
495 | return 1; | |
496 | } | |
497 | ||
5d5658a1 | 498 | /* Display thread information block of the current thread. */ |
711e434b PM |
499 | |
500 | static void | |
c281872e | 501 | display_tib (const char * args, int from_tty) |
711e434b | 502 | { |
d7e15655 | 503 | if (inferior_ptid != null_ptid) |
711e434b PM |
504 | display_one_tib (inferior_ptid); |
505 | } | |
bfb87e33 JB |
506 | |
507 | void | |
dc05df57 | 508 | windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr, |
c162ed3e | 509 | CORE_ADDR *text_offset_cached, |
5af949e3 | 510 | struct gdbarch *gdbarch, struct obstack *obstack) |
bfb87e33 | 511 | { |
c162ed3e | 512 | CORE_ADDR text_offset = text_offset_cached ? *text_offset_cached : 0; |
3999122f | 513 | |
bfb87e33 | 514 | obstack_grow_str (obstack, "<library name=\""); |
5e187554 SM |
515 | std::string p = xml_escape_text (so_name); |
516 | obstack_grow_str (obstack, p.c_str ()); | |
5af949e3 | 517 | obstack_grow_str (obstack, "\"><segment address=\""); |
c162ed3e HD |
518 | |
519 | if (!text_offset) | |
520 | { | |
521 | gdb_bfd_ref_ptr dll (gdb_bfd_open (so_name, gnutarget, -1)); | |
522 | /* The following calls are OK even if dll is NULL. | |
523 | The default value 0x1000 is returned by pe_text_section_offset | |
524 | in that case. */ | |
525 | text_offset = pe_text_section_offset (dll.get ()); | |
526 | if (text_offset_cached) | |
527 | *text_offset_cached = text_offset; | |
528 | } | |
529 | ||
3999122f | 530 | obstack_grow_str (obstack, paddress (gdbarch, load_addr + text_offset)); |
bfb87e33 JB |
531 | obstack_grow_str (obstack, "\"/></library>"); |
532 | } | |
711e434b | 533 | |
a8e1bb34 JB |
534 | /* Implement the "iterate_over_objfiles_in_search_order" gdbarch |
535 | method. It searches all objfiles, starting with CURRENT_OBJFILE | |
536 | first (if not NULL). | |
537 | ||
538 | On Windows, the system behaves a little differently when two | |
539 | objfiles each define a global symbol using the same name, compared | |
540 | to other platforms such as GNU/Linux for instance. On GNU/Linux, | |
541 | all instances of the symbol effectively get merged into a single | |
542 | one, but on Windows, they remain distinct. | |
543 | ||
544 | As a result, it usually makes sense to start global symbol searches | |
545 | with the current objfile before expanding it to all other objfiles. | |
546 | This helps for instance when a user debugs some code in a DLL that | |
547 | refers to a global variable defined inside that DLL. When trying | |
548 | to print the value of that global variable, it would be unhelpful | |
549 | to print the value of another global variable defined with the same | |
550 | name, but in a different DLL. */ | |
551 | ||
64870a42 | 552 | static void |
a8e1bb34 JB |
553 | windows_iterate_over_objfiles_in_search_order |
554 | (struct gdbarch *gdbarch, | |
555 | iterate_over_objfiles_in_search_order_cb_ftype *cb, | |
556 | void *cb_data, struct objfile *current_objfile) | |
557 | { | |
558 | int stop; | |
a8e1bb34 JB |
559 | |
560 | if (current_objfile) | |
561 | { | |
562 | stop = cb (current_objfile, cb_data); | |
563 | if (stop) | |
564 | return; | |
565 | } | |
566 | ||
2030c079 | 567 | for (objfile *objfile : current_program_space->objfiles ()) |
a8e1bb34 JB |
568 | { |
569 | if (objfile != current_objfile) | |
570 | { | |
571 | stop = cb (objfile, cb_data); | |
572 | if (stop) | |
573 | return; | |
574 | } | |
575 | } | |
576 | } | |
577 | ||
711e434b PM |
578 | static void |
579 | show_maint_show_all_tib (struct ui_file *file, int from_tty, | |
580 | struct cmd_list_element *c, const char *value) | |
581 | { | |
581e13c1 MS |
582 | fprintf_filtered (file, _("Show all non-zero elements of " |
583 | "Thread Information Block is %s.\n"), value); | |
711e434b PM |
584 | } |
585 | ||
586 | static void | |
981a3fb3 | 587 | info_w32_command (const char *args, int from_tty) |
711e434b PM |
588 | { |
589 | help_list (info_w32_cmdlist, "info w32 ", class_info, gdb_stdout); | |
590 | } | |
591 | ||
592 | static int w32_prefix_command_valid = 0; | |
593 | void | |
594 | init_w32_command_list (void) | |
595 | { | |
596 | if (!w32_prefix_command_valid) | |
597 | { | |
598 | add_prefix_cmd ("w32", class_info, info_w32_command, | |
599 | _("Print information specific to Win32 debugging."), | |
600 | &info_w32_cmdlist, "info w32 ", 0, &infolist); | |
601 | w32_prefix_command_valid = 1; | |
602 | } | |
603 | } | |
604 | ||
559e7e50 EZ |
605 | /* Implementation of `gdbarch_gdb_signal_to_target'. */ |
606 | ||
607 | static int | |
608 | windows_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal) | |
609 | { | |
610 | switch (signal) | |
611 | { | |
612 | case GDB_SIGNAL_0: | |
613 | return 0; | |
614 | case GDB_SIGNAL_HUP: | |
615 | return WINDOWS_SIGHUP; | |
616 | case GDB_SIGNAL_INT: | |
617 | return WINDOWS_SIGINT; | |
618 | case GDB_SIGNAL_QUIT: | |
619 | return WINDOWS_SIGQUIT; | |
620 | case GDB_SIGNAL_ILL: | |
621 | return WINDOWS_SIGILL; | |
622 | case GDB_SIGNAL_TRAP: | |
623 | return WINDOWS_SIGTRAP; | |
624 | case GDB_SIGNAL_ABRT: | |
625 | return WINDOWS_SIGABRT; | |
626 | case GDB_SIGNAL_EMT: | |
627 | return WINDOWS_SIGEMT; | |
628 | case GDB_SIGNAL_FPE: | |
629 | return WINDOWS_SIGFPE; | |
630 | case GDB_SIGNAL_KILL: | |
631 | return WINDOWS_SIGKILL; | |
632 | case GDB_SIGNAL_BUS: | |
633 | return WINDOWS_SIGBUS; | |
634 | case GDB_SIGNAL_SEGV: | |
635 | return WINDOWS_SIGSEGV; | |
636 | case GDB_SIGNAL_SYS: | |
637 | return WINDOWS_SIGSYS; | |
638 | case GDB_SIGNAL_PIPE: | |
639 | return WINDOWS_SIGPIPE; | |
640 | case GDB_SIGNAL_ALRM: | |
641 | return WINDOWS_SIGALRM; | |
642 | case GDB_SIGNAL_TERM: | |
643 | return WINDOWS_SIGTERM; | |
644 | #ifdef __CYGWIN__ | |
645 | case GDB_SIGNAL_URG: | |
646 | return WINDOWS_SIGURG; | |
647 | case GDB_SIGNAL_STOP: | |
648 | return WINDOWS_SIGSTOP; | |
649 | case GDB_SIGNAL_TSTP: | |
650 | return WINDOWS_SIGTSTP; | |
651 | case GDB_SIGNAL_CONT: | |
652 | return WINDOWS_SIGCONT; | |
653 | case GDB_SIGNAL_CHLD: | |
654 | return WINDOWS_SIGCHLD; | |
655 | case GDB_SIGNAL_TTIN: | |
656 | return WINDOWS_SIGTTIN; | |
657 | case GDB_SIGNAL_TTOU: | |
658 | return WINDOWS_SIGTTOU; | |
659 | case GDB_SIGNAL_IO: | |
660 | return WINDOWS_SIGIO; | |
661 | case GDB_SIGNAL_XCPU: | |
662 | return WINDOWS_SIGXCPU; | |
663 | case GDB_SIGNAL_XFSZ: | |
664 | return WINDOWS_SIGXFSZ; | |
665 | case GDB_SIGNAL_VTALRM: | |
666 | return WINDOWS_SIGVTALRM; | |
667 | case GDB_SIGNAL_PROF: | |
668 | return WINDOWS_SIGPROF; | |
669 | case GDB_SIGNAL_WINCH: | |
670 | return WINDOWS_SIGWINCH; | |
671 | case GDB_SIGNAL_PWR: | |
672 | return WINDOWS_SIGLOST; | |
673 | case GDB_SIGNAL_USR1: | |
674 | return WINDOWS_SIGUSR1; | |
675 | case GDB_SIGNAL_USR2: | |
676 | return WINDOWS_SIGUSR2; | |
677 | #endif /* __CYGWIN__ */ | |
678 | } | |
679 | return -1; | |
680 | } | |
681 | ||
6bafc845 HD |
682 | struct enum_value_name |
683 | { | |
684 | uint32_t value; | |
685 | const char *name; | |
686 | }; | |
687 | ||
688 | /* Allocate a TYPE_CODE_ENUM type structure with its named values. */ | |
689 | ||
690 | static struct type * | |
691 | create_enum (struct gdbarch *gdbarch, int bit, const char *name, | |
692 | const struct enum_value_name *values, int count) | |
693 | { | |
694 | struct type *type; | |
695 | int i; | |
696 | ||
697 | type = arch_type (gdbarch, TYPE_CODE_ENUM, bit, name); | |
698 | TYPE_NFIELDS (type) = count; | |
699 | TYPE_FIELDS (type) = (struct field *) | |
700 | TYPE_ZALLOC (type, sizeof (struct field) * count); | |
701 | TYPE_UNSIGNED (type) = 1; | |
702 | ||
703 | for (i = 0; i < count; i++) | |
704 | { | |
705 | TYPE_FIELD_NAME (type, i) = values[i].name; | |
706 | SET_FIELD_ENUMVAL (TYPE_FIELD (type, i), values[i].value); | |
707 | } | |
708 | ||
709 | return type; | |
710 | } | |
711 | ||
712 | static const struct enum_value_name exception_values[] = | |
713 | { | |
714 | { 0x40000015, "FATAL_APP_EXIT" }, | |
715 | { 0x40010005, "DBG_CONTROL_C" }, | |
716 | { 0x40010008, "DBG_CONTROL_BREAK" }, | |
717 | { 0x80000002, "DATATYPE_MISALIGNMENT" }, | |
718 | { 0x80000003, "BREAKPOINT" }, | |
719 | { 0x80000004, "SINGLE_STEP" }, | |
720 | { 0xC0000005, "ACCESS_VIOLATION" }, | |
721 | { 0xC0000006, "IN_PAGE_ERROR" }, | |
722 | { 0xC000001D, "ILLEGAL_INSTRUCTION" }, | |
723 | { 0xC0000025, "NONCONTINUABLE_EXCEPTION" }, | |
724 | { 0xC0000026, "INVALID_DISPOSITION" }, | |
725 | { 0xC000008C, "ARRAY_BOUNDS_EXCEEDED" }, | |
726 | { 0xC000008D, "FLOAT_DENORMAL_OPERAND" }, | |
727 | { 0xC000008E, "FLOAT_DIVIDE_BY_ZERO" }, | |
728 | { 0xC000008F, "FLOAT_INEXACT_RESULT" }, | |
729 | { 0xC0000090, "FLOAT_INVALID_OPERATION" }, | |
730 | { 0xC0000091, "FLOAT_OVERFLOW" }, | |
731 | { 0xC0000092, "FLOAT_STACK_CHECK" }, | |
732 | { 0xC0000093, "FLOAT_UNDERFLOW" }, | |
733 | { 0xC0000094, "INTEGER_DIVIDE_BY_ZERO" }, | |
734 | { 0xC0000095, "INTEGER_OVERFLOW" }, | |
735 | { 0xC0000096, "PRIV_INSTRUCTION" }, | |
736 | { 0xC00000FD, "STACK_OVERFLOW" }, | |
737 | { 0xC0000409, "FAST_FAIL" }, | |
738 | }; | |
739 | ||
740 | static const struct enum_value_name violation_values[] = | |
741 | { | |
742 | { 0, "READ_ACCESS_VIOLATION" }, | |
743 | { 1, "WRITE_ACCESS_VIOLATION" }, | |
744 | { 8, "DATA_EXECUTION_PREVENTION_VIOLATION" }, | |
745 | }; | |
746 | ||
7928d571 HD |
747 | /* Implement the "get_siginfo_type" gdbarch method. */ |
748 | ||
749 | static struct type * | |
750 | windows_get_siginfo_type (struct gdbarch *gdbarch) | |
751 | { | |
752 | struct windows_gdbarch_data *windows_gdbarch_data; | |
753 | struct type *dword_type, *pvoid_type, *ulongptr_type; | |
6bafc845 HD |
754 | struct type *code_enum, *violation_enum; |
755 | struct type *violation_type, *para_type, *siginfo_ptr_type, *siginfo_type; | |
7928d571 HD |
756 | |
757 | windows_gdbarch_data = get_windows_gdbarch_data (gdbarch); | |
758 | if (windows_gdbarch_data->siginfo_type != NULL) | |
759 | return windows_gdbarch_data->siginfo_type; | |
760 | ||
761 | dword_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
762 | 1, "DWORD"); | |
763 | pvoid_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), "PVOID", | |
764 | builtin_type (gdbarch)->builtin_void); | |
765 | ulongptr_type = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), | |
766 | 1, "ULONG_PTR"); | |
767 | ||
6bafc845 HD |
768 | /* ExceptionCode value names */ |
769 | code_enum = create_enum (gdbarch, gdbarch_int_bit (gdbarch), | |
770 | "ExceptionCode", exception_values, | |
771 | ARRAY_SIZE (exception_values)); | |
772 | ||
773 | /* ACCESS_VIOLATION type names */ | |
774 | violation_enum = create_enum (gdbarch, gdbarch_ptr_bit (gdbarch), | |
775 | "ViolationType", violation_values, | |
776 | ARRAY_SIZE (violation_values)); | |
777 | ||
778 | /* ACCESS_VIOLATION information */ | |
779 | violation_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
780 | append_composite_type_field (violation_type, "Type", violation_enum); | |
781 | append_composite_type_field (violation_type, "Address", pvoid_type); | |
782 | ||
783 | /* Unnamed union of the documented field ExceptionInformation, | |
784 | and the alternative AccessViolationInformation (which displays | |
785 | human-readable values for ExceptionCode ACCESS_VIOLATION). */ | |
786 | para_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); | |
787 | append_composite_type_field (para_type, "ExceptionInformation", | |
788 | lookup_array_range_type (ulongptr_type, 0, 14)); | |
789 | append_composite_type_field (para_type, "AccessViolationInformation", | |
790 | violation_type); | |
791 | ||
7928d571 HD |
792 | siginfo_type = arch_composite_type (gdbarch, "EXCEPTION_RECORD", |
793 | TYPE_CODE_STRUCT); | |
794 | siginfo_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), | |
795 | NULL, siginfo_type); | |
796 | ||
6bafc845 HD |
797 | /* ExceptionCode is documented as type DWORD, but here a helper |
798 | enum type is used instead to display a human-readable value. */ | |
799 | append_composite_type_field (siginfo_type, "ExceptionCode", code_enum); | |
7928d571 HD |
800 | append_composite_type_field (siginfo_type, "ExceptionFlags", dword_type); |
801 | append_composite_type_field (siginfo_type, "ExceptionRecord", | |
802 | siginfo_ptr_type); | |
803 | append_composite_type_field (siginfo_type, "ExceptionAddress", | |
804 | pvoid_type); | |
805 | append_composite_type_field (siginfo_type, "NumberParameters", dword_type); | |
806 | /* The 64-bit variant needs some padding. */ | |
6bafc845 HD |
807 | append_composite_type_field_aligned (siginfo_type, "", |
808 | para_type, TYPE_LENGTH (ulongptr_type)); | |
7928d571 HD |
809 | |
810 | windows_gdbarch_data->siginfo_type = siginfo_type; | |
811 | ||
812 | return siginfo_type; | |
813 | } | |
814 | ||
64870a42 YQ |
815 | /* To be called from the various GDB_OSABI_CYGWIN handlers for the |
816 | various Windows architectures and machine types. */ | |
817 | ||
818 | void | |
819 | windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
820 | { | |
53375380 PA |
821 | set_gdbarch_wchar_bit (gdbarch, 16); |
822 | set_gdbarch_wchar_signed (gdbarch, 0); | |
823 | ||
64870a42 YQ |
824 | /* Canonical paths on this target look like |
825 | `c:\Program Files\Foo App\mydll.dll', for example. */ | |
826 | set_gdbarch_has_dos_based_file_system (gdbarch, 1); | |
827 | ||
828 | set_gdbarch_iterate_over_objfiles_in_search_order | |
829 | (gdbarch, windows_iterate_over_objfiles_in_search_order); | |
830 | ||
559e7e50 EZ |
831 | set_gdbarch_gdb_signal_to_target (gdbarch, windows_gdb_signal_to_target); |
832 | ||
64870a42 | 833 | set_solib_ops (gdbarch, &solib_target_so_ops); |
7928d571 HD |
834 | |
835 | set_gdbarch_get_siginfo_type (gdbarch, windows_get_siginfo_type); | |
64870a42 YQ |
836 | } |
837 | ||
22d2b532 SDJ |
838 | /* Implementation of `tlb' variable. */ |
839 | ||
840 | static const struct internalvar_funcs tlb_funcs = | |
841 | { | |
842 | tlb_make_value, | |
843 | NULL, | |
844 | NULL | |
845 | }; | |
846 | ||
6c265988 | 847 | void _initialize_windows_tdep (); |
711e434b | 848 | void |
6c265988 | 849 | _initialize_windows_tdep () |
711e434b | 850 | { |
7928d571 HD |
851 | windows_gdbarch_data_handle |
852 | = gdbarch_data_register_post_init (init_windows_gdbarch_data); | |
853 | ||
711e434b PM |
854 | init_w32_command_list (); |
855 | add_cmd ("thread-information-block", class_info, display_tib, | |
856 | _("Display thread information block."), | |
857 | &info_w32_cmdlist); | |
858 | add_alias_cmd ("tib", "thread-information-block", class_info, 1, | |
859 | &info_w32_cmdlist); | |
860 | ||
861 | add_setshow_boolean_cmd ("show-all-tib", class_maintenance, | |
862 | &maint_display_all_tib, _("\ | |
863 | Set whether to display all non-zero fields of thread information block."), _("\ | |
864 | Show whether to display all non-zero fields of thread information block."), _("\ | |
865 | Use \"on\" to enable, \"off\" to disable.\n\ | |
866 | If enabled, all non-zero fields of thread information block are displayed,\n\ | |
867 | even if their meaning is unknown."), | |
868 | NULL, | |
869 | show_maint_show_all_tib, | |
870 | &maintenance_set_cmdlist, | |
871 | &maintenance_show_cmdlist); | |
872 | ||
873 | /* Explicitly create without lookup, since that tries to create a | |
874 | value with a void typed value, and when we get here, gdbarch | |
875 | isn't initialized yet. At this point, we're quite sure there | |
876 | isn't another convenience variable of the same name. */ | |
22d2b532 | 877 | create_internalvar_type_lazy ("_tlb", &tlb_funcs, NULL); |
711e434b | 878 | } |