Use nat/windows-nat function indirection code
[deliverable/binutils-gdb.git] / gdb / nat / windows-nat.h
CommitLineData
ae1f8880 1/* Internal interfaces for the Windows code
3666a048 2 Copyright (C) 1995-2021 Free Software Foundation, Inc.
ae1f8880
TT
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>
9e439f00 23#include <psapi.h>
3c76026d
TT
24#include <vector>
25
d2977bc4 26#include "gdbsupport/gdb_optional.h"
3c76026d 27#include "target/waitstatus.h"
ae1f8880 28
13302e95
HD
29#define STATUS_WX86_BREAKPOINT 0x4000001F
30#define STATUS_WX86_SINGLE_STEP 0x4000001E
31
4834dad0
TT
32namespace windows_nat
33{
34
ae1f8880
TT
35/* Thread information structure used to track extra information about
36 each thread. */
37struct windows_thread_info
38{
e9534bd2
TT
39 windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb)
40 : tid (tid_),
41 h (h_),
42 thread_local_base (tlb)
43 {
44 }
45
65bafd5b
TT
46 ~windows_thread_info ();
47
e9534bd2
TT
48 DISABLE_COPY_AND_ASSIGN (windows_thread_info);
49
98a03287
TT
50 /* Ensure that this thread has been suspended. */
51 void suspend ();
52
53 /* Resume the thread if it has been suspended. */
54 void resume ();
55
ae1f8880
TT
56 /* The Win32 thread identifier. */
57 DWORD tid;
58
59 /* The handle to the thread. */
60 HANDLE h;
61
62 /* Thread Information Block address. */
63 CORE_ADDR thread_local_base;
64
62fe396b
TT
65 /* This keeps track of whether SuspendThread was called on this
66 thread. -1 means there was a failure or that the thread was
67 explicitly not suspended, 1 means it was called, and 0 means it
68 was not. */
e9534bd2 69 int suspended = 0;
ae1f8880 70
ae1f8880
TT
71 /* The context of the thread, including any manipulations. */
72 union
73 {
e9534bd2 74 CONTEXT context {};
ae1f8880
TT
75#ifdef __x86_64__
76 WOW64_CONTEXT wow64_context;
77#endif
78 };
79
80 /* Whether debug registers changed since we last set CONTEXT back to
81 the thread. */
62fe396b 82 bool debug_registers_changed = false;
ae1f8880
TT
83
84 /* Nonzero if CONTEXT is invalidated and must be re-read from the
85 inferior thread. */
62fe396b 86 bool reload_context = false;
ae1f8880 87
0a4afda3
TT
88 /* True if this thread is currently stopped at a software
89 breakpoint. This is used to offset the PC when needed. */
90 bool stopped_at_software_breakpoint = false;
91
7be2bb4f
TT
92 /* True if we've adjusted the PC after hitting a software
93 breakpoint, false otherwise. This lets us avoid multiple
94 adjustments if the registers are read multiple times. */
95 bool pc_adjusted = false;
96
ae1f8880 97 /* The name of the thread, allocated by xmalloc. */
2950fdf7 98 gdb::unique_xmalloc_ptr<char> name;
ae1f8880
TT
99};
100
28688adf
TT
101
102/* Possible values to pass to 'thread_rec'. */
103enum thread_disposition_type
104{
105 /* Do not invalidate the thread's context, and do not suspend the
106 thread. */
107 DONT_INVALIDATE_CONTEXT,
108 /* Invalidate the context, but do not suspend the thread. */
109 DONT_SUSPEND,
110 /* Invalidate the context and suspend the thread. */
111 INVALIDATE_CONTEXT
112};
113
114/* Find a thread record given a thread id. THREAD_DISPOSITION
115 controls whether the thread is suspended, and whether the context
116 is invalidated.
117
118 This function must be supplied by the embedding application. */
119extern windows_thread_info *thread_rec (ptid_t ptid,
120 thread_disposition_type disposition);
121
d41b524f
TT
122
123/* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates
124 OURSTATUS and returns the thread id if this represents a thread
125 change (this is specific to Cygwin), otherwise 0.
126
127 Cygwin prepends its messages with a "cygwin:". Interpret this as
128 a Cygwin signal. Otherwise just print the string as a warning.
129
130 This function must be supplied by the embedding application. */
131extern int handle_output_debug_string (struct target_waitstatus *ourstatus);
132
a816ba18
TT
133/* Handle a DLL load event.
134
135 This function assumes that the current event did not occur during
136 inferior initialization.
137
138 This function must be supplied by the embedding application. */
139
140extern void handle_load_dll ();
141
142/* Handle a DLL unload event.
143
144 This function assumes that this event did not occur during inferior
145 initialization.
146
147 This function must be supplied by the embedding application. */
148
149extern void handle_unload_dll ();
150
8d30e395
TT
151/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
152 somewhat undocumented but is used to tell the debugger the name of
153 a thread.
154
155 Return true if the exception was handled; return false otherwise.
156
157 This function must be supplied by the embedding application. */
158
159extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec);
160
a010605f
TT
161/* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding
162 application a chance to change it to be considered "unhandled".
163 This function must be supplied by the embedding application. If it
164 returns true, then the exception is "unhandled". */
165
166extern bool handle_access_violation (const EXCEPTION_RECORD *rec);
167
a816ba18 168
3c76026d
TT
169/* Currently executing process */
170extern HANDLE current_process_handle;
171extern DWORD current_process_id;
172extern DWORD main_thread_id;
173extern enum gdb_signal last_sig;
174
175/* The current debug event from WaitForDebugEvent or from a pending
176 stop. */
177extern DEBUG_EVENT current_event;
178
3c76026d
TT
179/* The ID of the thread for which we anticipate a stop event.
180 Normally this is -1, meaning we'll accept an event in any
181 thread. */
182extern DWORD desired_stop_thread_id;
183
184/* A single pending stop. See "pending_stops" for more
185 information. */
186struct pending_stop
187{
188 /* The thread id. */
189 DWORD thread_id;
190
191 /* The target waitstatus we computed. */
192 target_waitstatus status;
193
194 /* The event. A few fields of this can be referenced after a stop,
195 and it seemed simplest to store the entire event. */
196 DEBUG_EVENT event;
197};
198
199/* A vector of pending stops. Sometimes, Windows will report a stop
200 on a thread that has been ostensibly suspended. We believe what
201 happens here is that two threads hit a breakpoint simultaneously,
202 and the Windows kernel queues the stop events. However, this can
203 result in the strange effect of trying to single step thread A --
204 leaving all other threads suspended -- and then seeing a stop in
205 thread B. To handle this scenario, we queue all such "pending"
206 stops here, and then process them once the step has completed. See
207 PR gdb/22992. */
208extern std::vector<pending_stop> pending_stops;
209
210/* Contents of $_siginfo */
211extern EXCEPTION_RECORD siginfo_er;
212
13302e95 213#ifdef __x86_64__
99bb393f
HD
214/* The target is a WOW64 process */
215extern bool wow64_process;
13302e95
HD
216/* Ignore first breakpoint exception of WOW64 process */
217extern bool ignore_first_breakpoint;
218#endif
219
9d8679cc
TT
220/* Return the name of the DLL referenced by H at ADDRESS. UNICODE
221 determines what sort of string is read from the inferior. Returns
222 the name of the DLL, or NULL on error. If a name is returned, it
223 is stored in a static buffer which is valid until the next call to
224 get_image_name. */
225extern const char *get_image_name (HANDLE h, void *address, int unicode);
226
8d30e395
TT
227typedef enum
228{
229 HANDLE_EXCEPTION_UNHANDLED = 0,
230 HANDLE_EXCEPTION_HANDLED,
231 HANDLE_EXCEPTION_IGNORED
232} handle_exception_result;
233
234extern handle_exception_result handle_exception
235 (struct target_waitstatus *ourstatus, bool debug_exceptions);
236
e758e19c
TT
237/* Return true if there is a pending stop matching
238 desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be
239 enabled. */
240
241extern bool matching_pending_stop (bool debug_events);
242
d2977bc4
TT
243/* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so,
244 remove it from the list of pending stops, set 'current_event', and
245 return it. Otherwise, return an empty optional. */
246
247extern gdb::optional<pending_stop> fetch_pending_stop (bool debug_events);
248
e758e19c
TT
249/* A simple wrapper for ContinueDebugEvent that continues the last
250 waited-for event. If DEBUG_EVENTS is true, logging will be
251 enabled. */
252
253extern BOOL continue_last_debug_event (DWORD continue_status,
254 bool debug_events);
255
71fbdbaf 256/* A simple wrapper for WaitForDebugEvent that also sets the internal
2c1d95e8
TT
257 'last_wait_event' on success. */
258
259extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
260
9e439f00
TT
261#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
262#define DebugActiveProcessStop dyn_DebugActiveProcessStop
263#define DebugBreakProcess dyn_DebugBreakProcess
264#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit
265#define EnumProcessModules dyn_EnumProcessModules
266#define EnumProcessModulesEx dyn_EnumProcessModulesEx
267#define GetModuleInformation dyn_GetModuleInformation
268#define GetModuleFileNameExA dyn_GetModuleFileNameExA
269#define GetModuleFileNameExW dyn_GetModuleFileNameExW
270#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA
271#define OpenProcessToken dyn_OpenProcessToken
272#define GetConsoleFontSize dyn_GetConsoleFontSize
273#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont
274#define Wow64SuspendThread dyn_Wow64SuspendThread
275#define Wow64GetThreadContext dyn_Wow64GetThreadContext
276#define Wow64SetThreadContext dyn_Wow64SetThreadContext
277#define Wow64GetThreadSelectorEntry dyn_Wow64GetThreadSelectorEntry
de071872 278#define GenerateConsoleCtrlEvent dyn_GenerateConsoleCtrlEvent
9e439f00
TT
279
280typedef BOOL WINAPI (AdjustTokenPrivileges_ftype) (HANDLE, BOOL,
281 PTOKEN_PRIVILEGES,
282 DWORD, PTOKEN_PRIVILEGES,
283 PDWORD);
284extern AdjustTokenPrivileges_ftype *AdjustTokenPrivileges;
285
286typedef BOOL WINAPI (DebugActiveProcessStop_ftype) (DWORD);
287extern DebugActiveProcessStop_ftype *DebugActiveProcessStop;
288
289typedef BOOL WINAPI (DebugBreakProcess_ftype) (HANDLE);
290extern DebugBreakProcess_ftype *DebugBreakProcess;
291
292typedef BOOL WINAPI (DebugSetProcessKillOnExit_ftype) (BOOL);
293extern DebugSetProcessKillOnExit_ftype *DebugSetProcessKillOnExit;
294
295typedef BOOL WINAPI (EnumProcessModules_ftype) (HANDLE, HMODULE *, DWORD,
296 LPDWORD);
297extern EnumProcessModules_ftype *EnumProcessModules;
298
299#ifdef __x86_64__
300typedef BOOL WINAPI (EnumProcessModulesEx_ftype) (HANDLE, HMODULE *, DWORD,
301 LPDWORD, DWORD);
302extern EnumProcessModulesEx_ftype *EnumProcessModulesEx;
303#endif
304
305typedef BOOL WINAPI (GetModuleInformation_ftype) (HANDLE, HMODULE,
306 LPMODULEINFO, DWORD);
307extern GetModuleInformation_ftype *GetModuleInformation;
308
309typedef DWORD WINAPI (GetModuleFileNameExA_ftype) (HANDLE, HMODULE, LPSTR,
310 DWORD);
311extern GetModuleFileNameExA_ftype *GetModuleFileNameExA;
312
313typedef DWORD WINAPI (GetModuleFileNameExW_ftype) (HANDLE, HMODULE,
314 LPWSTR, DWORD);
315extern GetModuleFileNameExW_ftype *GetModuleFileNameExW;
316
317typedef BOOL WINAPI (LookupPrivilegeValueA_ftype) (LPCSTR, LPCSTR, PLUID);
318extern LookupPrivilegeValueA_ftype *LookupPrivilegeValueA;
319
320typedef BOOL WINAPI (OpenProcessToken_ftype) (HANDLE, DWORD, PHANDLE);
321extern OpenProcessToken_ftype *OpenProcessToken;
322
323typedef BOOL WINAPI (GetCurrentConsoleFont_ftype) (HANDLE, BOOL,
324 CONSOLE_FONT_INFO *);
325extern GetCurrentConsoleFont_ftype *GetCurrentConsoleFont;
326
327typedef COORD WINAPI (GetConsoleFontSize_ftype) (HANDLE, DWORD);
328extern GetConsoleFontSize_ftype *GetConsoleFontSize;
329
330#ifdef __x86_64__
331typedef DWORD WINAPI (Wow64SuspendThread_ftype) (HANDLE);
332extern Wow64SuspendThread_ftype *Wow64SuspendThread;
333
334typedef BOOL WINAPI (Wow64GetThreadContext_ftype) (HANDLE, PWOW64_CONTEXT);
335extern Wow64GetThreadContext_ftype *Wow64GetThreadContext;
336
337typedef BOOL WINAPI (Wow64SetThreadContext_ftype) (HANDLE,
338 const WOW64_CONTEXT *);
339extern Wow64SetThreadContext_ftype *Wow64SetThreadContext;
340
341typedef BOOL WINAPI (Wow64GetThreadSelectorEntry_ftype) (HANDLE, DWORD,
342 PLDT_ENTRY);
343extern Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
344#endif
345
de071872
TT
346typedef BOOL WINAPI (GenerateConsoleCtrlEvent_ftype) (DWORD, DWORD);
347extern GenerateConsoleCtrlEvent_ftype *GenerateConsoleCtrlEvent;
348
9e439f00
TT
349/* Load any functions which may not be available in ancient versions
350 of Windows. */
351
352extern bool initialize_loadable ();
353
4834dad0
TT
354}
355
ae1f8880 356#endif
This page took 0.17593 seconds and 4 git commands to generate.