Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / nat / windows-nat.h
CommitLineData
ae1f8880 1/* Internal interfaces for the Windows code
88b9d363 2 Copyright (C) 1995-2022 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
e228ef97
TT
138 DLL_NAME is the name of the library. BASE is the base load
139 address.
140
a816ba18
TT
141 This function must be supplied by the embedding application. */
142
e228ef97 143extern void handle_load_dll (const char *dll_name, LPVOID base);
a816ba18
TT
144
145/* Handle a DLL unload event.
146
147 This function assumes that this event did not occur during inferior
148 initialization.
149
150 This function must be supplied by the embedding application. */
151
152extern void handle_unload_dll ();
153
8d30e395
TT
154/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
155 somewhat undocumented but is used to tell the debugger the name of
156 a thread.
157
158 Return true if the exception was handled; return false otherwise.
159
160 This function must be supplied by the embedding application. */
161
162extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec);
163
a010605f
TT
164/* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding
165 application a chance to change it to be considered "unhandled".
166 This function must be supplied by the embedding application. If it
167 returns true, then the exception is "unhandled". */
168
169extern bool handle_access_violation (const EXCEPTION_RECORD *rec);
170
a816ba18 171
3c76026d
TT
172/* Currently executing process */
173extern HANDLE current_process_handle;
174extern DWORD current_process_id;
175extern DWORD main_thread_id;
176extern enum gdb_signal last_sig;
177
178/* The current debug event from WaitForDebugEvent or from a pending
179 stop. */
180extern DEBUG_EVENT current_event;
181
3c76026d
TT
182/* The ID of the thread for which we anticipate a stop event.
183 Normally this is -1, meaning we'll accept an event in any
184 thread. */
185extern DWORD desired_stop_thread_id;
186
187/* A single pending stop. See "pending_stops" for more
188 information. */
189struct pending_stop
190{
191 /* The thread id. */
192 DWORD thread_id;
193
194 /* The target waitstatus we computed. */
195 target_waitstatus status;
196
197 /* The event. A few fields of this can be referenced after a stop,
198 and it seemed simplest to store the entire event. */
199 DEBUG_EVENT event;
200};
201
202/* A vector of pending stops. Sometimes, Windows will report a stop
203 on a thread that has been ostensibly suspended. We believe what
204 happens here is that two threads hit a breakpoint simultaneously,
205 and the Windows kernel queues the stop events. However, this can
206 result in the strange effect of trying to single step thread A --
207 leaving all other threads suspended -- and then seeing a stop in
208 thread B. To handle this scenario, we queue all such "pending"
209 stops here, and then process them once the step has completed. See
210 PR gdb/22992. */
211extern std::vector<pending_stop> pending_stops;
212
213/* Contents of $_siginfo */
214extern EXCEPTION_RECORD siginfo_er;
215
13302e95 216#ifdef __x86_64__
99bb393f
HD
217/* The target is a WOW64 process */
218extern bool wow64_process;
13302e95
HD
219/* Ignore first breakpoint exception of WOW64 process */
220extern bool ignore_first_breakpoint;
221#endif
222
8d30e395
TT
223typedef enum
224{
225 HANDLE_EXCEPTION_UNHANDLED = 0,
226 HANDLE_EXCEPTION_HANDLED,
227 HANDLE_EXCEPTION_IGNORED
228} handle_exception_result;
229
230extern handle_exception_result handle_exception
231 (struct target_waitstatus *ourstatus, bool debug_exceptions);
232
e228ef97
TT
233/* Call to indicate that a DLL was loaded. */
234
235extern void dll_loaded_event ();
236
237/* Iterate over all DLLs currently mapped by our inferior, and
238 add them to our list of solibs. */
239
240extern void windows_add_all_dlls ();
241
e758e19c
TT
242/* Return true if there is a pending stop matching
243 desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be
244 enabled. */
245
246extern bool matching_pending_stop (bool debug_events);
247
d2977bc4
TT
248/* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so,
249 remove it from the list of pending stops, set 'current_event', and
250 return it. Otherwise, return an empty optional. */
251
252extern gdb::optional<pending_stop> fetch_pending_stop (bool debug_events);
253
e758e19c
TT
254/* A simple wrapper for ContinueDebugEvent that continues the last
255 waited-for event. If DEBUG_EVENTS is true, logging will be
256 enabled. */
257
258extern BOOL continue_last_debug_event (DWORD continue_status,
259 bool debug_events);
260
71fbdbaf 261/* A simple wrapper for WaitForDebugEvent that also sets the internal
2c1d95e8
TT
262 'last_wait_event' on success. */
263
264extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
265
9e439f00
TT
266#define AdjustTokenPrivileges dyn_AdjustTokenPrivileges
267#define DebugActiveProcessStop dyn_DebugActiveProcessStop
268#define DebugBreakProcess dyn_DebugBreakProcess
269#define DebugSetProcessKillOnExit dyn_DebugSetProcessKillOnExit
270#define EnumProcessModules dyn_EnumProcessModules
271#define EnumProcessModulesEx dyn_EnumProcessModulesEx
272#define GetModuleInformation dyn_GetModuleInformation
273#define GetModuleFileNameExA dyn_GetModuleFileNameExA
274#define GetModuleFileNameExW dyn_GetModuleFileNameExW
275#define LookupPrivilegeValueA dyn_LookupPrivilegeValueA
276#define OpenProcessToken dyn_OpenProcessToken
277#define GetConsoleFontSize dyn_GetConsoleFontSize
278#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont
279#define Wow64SuspendThread dyn_Wow64SuspendThread
280#define Wow64GetThreadContext dyn_Wow64GetThreadContext
281#define Wow64SetThreadContext dyn_Wow64SetThreadContext
282#define Wow64GetThreadSelectorEntry dyn_Wow64GetThreadSelectorEntry
de071872 283#define GenerateConsoleCtrlEvent dyn_GenerateConsoleCtrlEvent
9e439f00
TT
284
285typedef BOOL WINAPI (AdjustTokenPrivileges_ftype) (HANDLE, BOOL,
286 PTOKEN_PRIVILEGES,
287 DWORD, PTOKEN_PRIVILEGES,
288 PDWORD);
289extern AdjustTokenPrivileges_ftype *AdjustTokenPrivileges;
290
291typedef BOOL WINAPI (DebugActiveProcessStop_ftype) (DWORD);
292extern DebugActiveProcessStop_ftype *DebugActiveProcessStop;
293
294typedef BOOL WINAPI (DebugBreakProcess_ftype) (HANDLE);
295extern DebugBreakProcess_ftype *DebugBreakProcess;
296
297typedef BOOL WINAPI (DebugSetProcessKillOnExit_ftype) (BOOL);
298extern DebugSetProcessKillOnExit_ftype *DebugSetProcessKillOnExit;
299
300typedef BOOL WINAPI (EnumProcessModules_ftype) (HANDLE, HMODULE *, DWORD,
301 LPDWORD);
302extern EnumProcessModules_ftype *EnumProcessModules;
303
304#ifdef __x86_64__
305typedef BOOL WINAPI (EnumProcessModulesEx_ftype) (HANDLE, HMODULE *, DWORD,
306 LPDWORD, DWORD);
307extern EnumProcessModulesEx_ftype *EnumProcessModulesEx;
308#endif
309
310typedef BOOL WINAPI (GetModuleInformation_ftype) (HANDLE, HMODULE,
311 LPMODULEINFO, DWORD);
312extern GetModuleInformation_ftype *GetModuleInformation;
313
314typedef DWORD WINAPI (GetModuleFileNameExA_ftype) (HANDLE, HMODULE, LPSTR,
315 DWORD);
316extern GetModuleFileNameExA_ftype *GetModuleFileNameExA;
317
318typedef DWORD WINAPI (GetModuleFileNameExW_ftype) (HANDLE, HMODULE,
319 LPWSTR, DWORD);
320extern GetModuleFileNameExW_ftype *GetModuleFileNameExW;
321
322typedef BOOL WINAPI (LookupPrivilegeValueA_ftype) (LPCSTR, LPCSTR, PLUID);
323extern LookupPrivilegeValueA_ftype *LookupPrivilegeValueA;
324
325typedef BOOL WINAPI (OpenProcessToken_ftype) (HANDLE, DWORD, PHANDLE);
326extern OpenProcessToken_ftype *OpenProcessToken;
327
328typedef BOOL WINAPI (GetCurrentConsoleFont_ftype) (HANDLE, BOOL,
329 CONSOLE_FONT_INFO *);
330extern GetCurrentConsoleFont_ftype *GetCurrentConsoleFont;
331
332typedef COORD WINAPI (GetConsoleFontSize_ftype) (HANDLE, DWORD);
333extern GetConsoleFontSize_ftype *GetConsoleFontSize;
334
335#ifdef __x86_64__
336typedef DWORD WINAPI (Wow64SuspendThread_ftype) (HANDLE);
337extern Wow64SuspendThread_ftype *Wow64SuspendThread;
338
339typedef BOOL WINAPI (Wow64GetThreadContext_ftype) (HANDLE, PWOW64_CONTEXT);
340extern Wow64GetThreadContext_ftype *Wow64GetThreadContext;
341
342typedef BOOL WINAPI (Wow64SetThreadContext_ftype) (HANDLE,
343 const WOW64_CONTEXT *);
344extern Wow64SetThreadContext_ftype *Wow64SetThreadContext;
345
346typedef BOOL WINAPI (Wow64GetThreadSelectorEntry_ftype) (HANDLE, DWORD,
347 PLDT_ENTRY);
348extern Wow64GetThreadSelectorEntry_ftype *Wow64GetThreadSelectorEntry;
349#endif
350
de071872
TT
351typedef BOOL WINAPI (GenerateConsoleCtrlEvent_ftype) (DWORD, DWORD);
352extern GenerateConsoleCtrlEvent_ftype *GenerateConsoleCtrlEvent;
353
9e439f00
TT
354/* Load any functions which may not be available in ancient versions
355 of Windows. */
356
357extern bool initialize_loadable ();
358
4834dad0
TT
359}
360
ae1f8880 361#endif
This page took 0.189813 seconds and 4 git commands to generate.