Commit | Line | Data |
---|---|---|
ae1f8880 TT |
1 | /* Internal interfaces for the Windows code |
2 | Copyright (C) 1995-2020 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
18 | ||
19 | #ifndef NAT_WINDOWS_NAT_H | |
20 | #define NAT_WINDOWS_NAT_H | |
21 | ||
22 | #include <windows.h> | |
3c76026d TT |
23 | #include <vector> |
24 | ||
d2977bc4 | 25 | #include "gdbsupport/gdb_optional.h" |
3c76026d | 26 | #include "target/waitstatus.h" |
ae1f8880 | 27 | |
4834dad0 TT |
28 | namespace windows_nat |
29 | { | |
30 | ||
ae1f8880 TT |
31 | /* Thread information structure used to track extra information about |
32 | each thread. */ | |
33 | struct windows_thread_info | |
34 | { | |
e9534bd2 TT |
35 | windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb) |
36 | : tid (tid_), | |
37 | h (h_), | |
38 | thread_local_base (tlb) | |
39 | { | |
40 | } | |
41 | ||
65bafd5b TT |
42 | ~windows_thread_info (); |
43 | ||
e9534bd2 TT |
44 | DISABLE_COPY_AND_ASSIGN (windows_thread_info); |
45 | ||
98a03287 TT |
46 | /* Ensure that this thread has been suspended. */ |
47 | void suspend (); | |
48 | ||
49 | /* Resume the thread if it has been suspended. */ | |
50 | void resume (); | |
51 | ||
ae1f8880 TT |
52 | /* The Win32 thread identifier. */ |
53 | DWORD tid; | |
54 | ||
55 | /* The handle to the thread. */ | |
56 | HANDLE h; | |
57 | ||
58 | /* Thread Information Block address. */ | |
59 | CORE_ADDR thread_local_base; | |
60 | ||
62fe396b TT |
61 | /* This keeps track of whether SuspendThread was called on this |
62 | thread. -1 means there was a failure or that the thread was | |
63 | explicitly not suspended, 1 means it was called, and 0 means it | |
64 | was not. */ | |
e9534bd2 | 65 | int suspended = 0; |
ae1f8880 TT |
66 | |
67 | #ifdef _WIN32_WCE | |
68 | /* The context as retrieved right after suspending the thread. */ | |
e9534bd2 | 69 | CONTEXT base_context {}; |
ae1f8880 TT |
70 | #endif |
71 | ||
72 | /* The context of the thread, including any manipulations. */ | |
73 | union | |
74 | { | |
e9534bd2 | 75 | CONTEXT context {}; |
ae1f8880 TT |
76 | #ifdef __x86_64__ |
77 | WOW64_CONTEXT wow64_context; | |
78 | #endif | |
79 | }; | |
80 | ||
81 | /* Whether debug registers changed since we last set CONTEXT back to | |
82 | the thread. */ | |
62fe396b | 83 | bool debug_registers_changed = false; |
ae1f8880 TT |
84 | |
85 | /* Nonzero if CONTEXT is invalidated and must be re-read from the | |
86 | inferior thread. */ | |
62fe396b | 87 | bool reload_context = false; |
ae1f8880 | 88 | |
0a4afda3 TT |
89 | /* True if this thread is currently stopped at a software |
90 | breakpoint. This is used to offset the PC when needed. */ | |
91 | bool stopped_at_software_breakpoint = false; | |
92 | ||
ae1f8880 | 93 | /* The name of the thread, allocated by xmalloc. */ |
2950fdf7 | 94 | gdb::unique_xmalloc_ptr<char> name; |
ae1f8880 TT |
95 | }; |
96 | ||
28688adf TT |
97 | |
98 | /* Possible values to pass to 'thread_rec'. */ | |
99 | enum thread_disposition_type | |
100 | { | |
101 | /* Do not invalidate the thread's context, and do not suspend the | |
102 | thread. */ | |
103 | DONT_INVALIDATE_CONTEXT, | |
104 | /* Invalidate the context, but do not suspend the thread. */ | |
105 | DONT_SUSPEND, | |
106 | /* Invalidate the context and suspend the thread. */ | |
107 | INVALIDATE_CONTEXT | |
108 | }; | |
109 | ||
110 | /* Find a thread record given a thread id. THREAD_DISPOSITION | |
111 | controls whether the thread is suspended, and whether the context | |
112 | is invalidated. | |
113 | ||
114 | This function must be supplied by the embedding application. */ | |
115 | extern windows_thread_info *thread_rec (ptid_t ptid, | |
116 | thread_disposition_type disposition); | |
117 | ||
d41b524f TT |
118 | |
119 | /* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates | |
120 | OURSTATUS and returns the thread id if this represents a thread | |
121 | change (this is specific to Cygwin), otherwise 0. | |
122 | ||
123 | Cygwin prepends its messages with a "cygwin:". Interpret this as | |
124 | a Cygwin signal. Otherwise just print the string as a warning. | |
125 | ||
126 | This function must be supplied by the embedding application. */ | |
127 | extern int handle_output_debug_string (struct target_waitstatus *ourstatus); | |
128 | ||
a816ba18 TT |
129 | /* Handle a DLL load event. |
130 | ||
131 | This function assumes that the current event did not occur during | |
132 | inferior initialization. | |
133 | ||
134 | This function must be supplied by the embedding application. */ | |
135 | ||
136 | extern void handle_load_dll (); | |
137 | ||
138 | /* Handle a DLL unload event. | |
139 | ||
140 | This function assumes that this event did not occur during inferior | |
141 | initialization. | |
142 | ||
143 | This function must be supplied by the embedding application. */ | |
144 | ||
145 | extern void handle_unload_dll (); | |
146 | ||
8d30e395 TT |
147 | /* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is |
148 | somewhat undocumented but is used to tell the debugger the name of | |
149 | a thread. | |
150 | ||
151 | Return true if the exception was handled; return false otherwise. | |
152 | ||
153 | This function must be supplied by the embedding application. */ | |
154 | ||
155 | extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec); | |
156 | ||
a816ba18 | 157 | |
3c76026d TT |
158 | /* Currently executing process */ |
159 | extern HANDLE current_process_handle; | |
160 | extern DWORD current_process_id; | |
161 | extern DWORD main_thread_id; | |
162 | extern enum gdb_signal last_sig; | |
163 | ||
164 | /* The current debug event from WaitForDebugEvent or from a pending | |
165 | stop. */ | |
166 | extern DEBUG_EVENT current_event; | |
167 | ||
168 | /* The most recent event from WaitForDebugEvent. Unlike | |
169 | current_event, this is guaranteed never to come from a pending | |
170 | stop. This is important because only data from the most recent | |
171 | event from WaitForDebugEvent can be used when calling | |
172 | ContinueDebugEvent. */ | |
173 | extern DEBUG_EVENT last_wait_event; | |
174 | ||
175 | /* Info on currently selected thread */ | |
176 | extern windows_thread_info *current_windows_thread; | |
177 | ||
178 | /* The ID of the thread for which we anticipate a stop event. | |
179 | Normally this is -1, meaning we'll accept an event in any | |
180 | thread. */ | |
181 | extern DWORD desired_stop_thread_id; | |
182 | ||
183 | /* A single pending stop. See "pending_stops" for more | |
184 | information. */ | |
185 | struct pending_stop | |
186 | { | |
187 | /* The thread id. */ | |
188 | DWORD thread_id; | |
189 | ||
190 | /* The target waitstatus we computed. */ | |
191 | target_waitstatus status; | |
192 | ||
193 | /* The event. A few fields of this can be referenced after a stop, | |
194 | and it seemed simplest to store the entire event. */ | |
195 | DEBUG_EVENT event; | |
196 | }; | |
197 | ||
198 | /* A vector of pending stops. Sometimes, Windows will report a stop | |
199 | on a thread that has been ostensibly suspended. We believe what | |
200 | happens here is that two threads hit a breakpoint simultaneously, | |
201 | and the Windows kernel queues the stop events. However, this can | |
202 | result in the strange effect of trying to single step thread A -- | |
203 | leaving all other threads suspended -- and then seeing a stop in | |
204 | thread B. To handle this scenario, we queue all such "pending" | |
205 | stops here, and then process them once the step has completed. See | |
206 | PR gdb/22992. */ | |
207 | extern std::vector<pending_stop> pending_stops; | |
208 | ||
209 | /* Contents of $_siginfo */ | |
210 | extern EXCEPTION_RECORD siginfo_er; | |
211 | ||
9d8679cc TT |
212 | /* Return the name of the DLL referenced by H at ADDRESS. UNICODE |
213 | determines what sort of string is read from the inferior. Returns | |
214 | the name of the DLL, or NULL on error. If a name is returned, it | |
215 | is stored in a static buffer which is valid until the next call to | |
216 | get_image_name. */ | |
217 | extern const char *get_image_name (HANDLE h, void *address, int unicode); | |
218 | ||
8d30e395 TT |
219 | typedef enum |
220 | { | |
221 | HANDLE_EXCEPTION_UNHANDLED = 0, | |
222 | HANDLE_EXCEPTION_HANDLED, | |
223 | HANDLE_EXCEPTION_IGNORED | |
224 | } handle_exception_result; | |
225 | ||
226 | extern handle_exception_result handle_exception | |
227 | (struct target_waitstatus *ourstatus, bool debug_exceptions); | |
228 | ||
e758e19c TT |
229 | /* Return true if there is a pending stop matching |
230 | desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be | |
231 | enabled. */ | |
232 | ||
233 | extern bool matching_pending_stop (bool debug_events); | |
234 | ||
d2977bc4 TT |
235 | /* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so, |
236 | remove it from the list of pending stops, set 'current_event', and | |
237 | return it. Otherwise, return an empty optional. */ | |
238 | ||
239 | extern gdb::optional<pending_stop> fetch_pending_stop (bool debug_events); | |
240 | ||
e758e19c TT |
241 | /* A simple wrapper for ContinueDebugEvent that continues the last |
242 | waited-for event. If DEBUG_EVENTS is true, logging will be | |
243 | enabled. */ | |
244 | ||
245 | extern BOOL continue_last_debug_event (DWORD continue_status, | |
246 | bool debug_events); | |
247 | ||
4834dad0 TT |
248 | } |
249 | ||
ae1f8880 | 250 | #endif |