Use template functions in windows-nat.c
[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>
3c76026d
TT
23#include <vector>
24
d2977bc4 25#include "gdbsupport/gdb_optional.h"
3c76026d 26#include "target/waitstatus.h"
ae1f8880 27
13302e95
HD
28#define STATUS_WX86_BREAKPOINT 0x4000001F
29#define STATUS_WX86_SINGLE_STEP 0x4000001E
30
4834dad0
TT
31namespace windows_nat
32{
33
ae1f8880
TT
34/* Thread information structure used to track extra information about
35 each thread. */
36struct windows_thread_info
37{
e9534bd2
TT
38 windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb)
39 : tid (tid_),
40 h (h_),
41 thread_local_base (tlb)
42 {
43 }
44
65bafd5b
TT
45 ~windows_thread_info ();
46
e9534bd2
TT
47 DISABLE_COPY_AND_ASSIGN (windows_thread_info);
48
98a03287
TT
49 /* Ensure that this thread has been suspended. */
50 void suspend ();
51
52 /* Resume the thread if it has been suspended. */
53 void resume ();
54
ae1f8880
TT
55 /* The Win32 thread identifier. */
56 DWORD tid;
57
58 /* The handle to the thread. */
59 HANDLE h;
60
61 /* Thread Information Block address. */
62 CORE_ADDR thread_local_base;
63
62fe396b
TT
64 /* This keeps track of whether SuspendThread was called on this
65 thread. -1 means there was a failure or that the thread was
66 explicitly not suspended, 1 means it was called, and 0 means it
67 was not. */
e9534bd2 68 int suspended = 0;
ae1f8880 69
ae1f8880
TT
70 /* The context of the thread, including any manipulations. */
71 union
72 {
e9534bd2 73 CONTEXT context {};
ae1f8880
TT
74#ifdef __x86_64__
75 WOW64_CONTEXT wow64_context;
76#endif
77 };
78
79 /* Whether debug registers changed since we last set CONTEXT back to
80 the thread. */
62fe396b 81 bool debug_registers_changed = false;
ae1f8880
TT
82
83 /* Nonzero if CONTEXT is invalidated and must be re-read from the
84 inferior thread. */
62fe396b 85 bool reload_context = false;
ae1f8880 86
0a4afda3
TT
87 /* True if this thread is currently stopped at a software
88 breakpoint. This is used to offset the PC when needed. */
89 bool stopped_at_software_breakpoint = false;
90
7be2bb4f
TT
91 /* True if we've adjusted the PC after hitting a software
92 breakpoint, false otherwise. This lets us avoid multiple
93 adjustments if the registers are read multiple times. */
94 bool pc_adjusted = false;
95
ae1f8880 96 /* The name of the thread, allocated by xmalloc. */
2950fdf7 97 gdb::unique_xmalloc_ptr<char> name;
ae1f8880
TT
98};
99
28688adf
TT
100
101/* Possible values to pass to 'thread_rec'. */
102enum thread_disposition_type
103{
104 /* Do not invalidate the thread's context, and do not suspend the
105 thread. */
106 DONT_INVALIDATE_CONTEXT,
107 /* Invalidate the context, but do not suspend the thread. */
108 DONT_SUSPEND,
109 /* Invalidate the context and suspend the thread. */
110 INVALIDATE_CONTEXT
111};
112
113/* Find a thread record given a thread id. THREAD_DISPOSITION
114 controls whether the thread is suspended, and whether the context
115 is invalidated.
116
117 This function must be supplied by the embedding application. */
118extern windows_thread_info *thread_rec (ptid_t ptid,
119 thread_disposition_type disposition);
120
d41b524f
TT
121
122/* Handle OUTPUT_DEBUG_STRING_EVENT from child process. Updates
123 OURSTATUS and returns the thread id if this represents a thread
124 change (this is specific to Cygwin), otherwise 0.
125
126 Cygwin prepends its messages with a "cygwin:". Interpret this as
127 a Cygwin signal. Otherwise just print the string as a warning.
128
129 This function must be supplied by the embedding application. */
130extern int handle_output_debug_string (struct target_waitstatus *ourstatus);
131
a816ba18
TT
132/* Handle a DLL load event.
133
134 This function assumes that the current event did not occur during
135 inferior initialization.
136
137 This function must be supplied by the embedding application. */
138
139extern void handle_load_dll ();
140
141/* Handle a DLL unload event.
142
143 This function assumes that this event did not occur during inferior
144 initialization.
145
146 This function must be supplied by the embedding application. */
147
148extern void handle_unload_dll ();
149
8d30e395
TT
150/* Handle MS_VC_EXCEPTION when processing a stop. MS_VC_EXCEPTION is
151 somewhat undocumented but is used to tell the debugger the name of
152 a thread.
153
154 Return true if the exception was handled; return false otherwise.
155
156 This function must be supplied by the embedding application. */
157
158extern bool handle_ms_vc_exception (const EXCEPTION_RECORD *rec);
159
a010605f
TT
160/* When EXCEPTION_ACCESS_VIOLATION is processed, we give the embedding
161 application a chance to change it to be considered "unhandled".
162 This function must be supplied by the embedding application. If it
163 returns true, then the exception is "unhandled". */
164
165extern bool handle_access_violation (const EXCEPTION_RECORD *rec);
166
a816ba18 167
3c76026d
TT
168/* Currently executing process */
169extern HANDLE current_process_handle;
170extern DWORD current_process_id;
171extern DWORD main_thread_id;
172extern enum gdb_signal last_sig;
173
174/* The current debug event from WaitForDebugEvent or from a pending
175 stop. */
176extern DEBUG_EVENT current_event;
177
3c76026d
TT
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. */
181extern DWORD desired_stop_thread_id;
182
183/* A single pending stop. See "pending_stops" for more
184 information. */
185struct 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. */
207extern std::vector<pending_stop> pending_stops;
208
209/* Contents of $_siginfo */
210extern EXCEPTION_RECORD siginfo_er;
211
13302e95 212#ifdef __x86_64__
99bb393f
HD
213/* The target is a WOW64 process */
214extern bool wow64_process;
13302e95
HD
215/* Ignore first breakpoint exception of WOW64 process */
216extern bool ignore_first_breakpoint;
217#endif
218
9d8679cc
TT
219/* Return the name of the DLL referenced by H at ADDRESS. UNICODE
220 determines what sort of string is read from the inferior. Returns
221 the name of the DLL, or NULL on error. If a name is returned, it
222 is stored in a static buffer which is valid until the next call to
223 get_image_name. */
224extern const char *get_image_name (HANDLE h, void *address, int unicode);
225
8d30e395
TT
226typedef enum
227{
228 HANDLE_EXCEPTION_UNHANDLED = 0,
229 HANDLE_EXCEPTION_HANDLED,
230 HANDLE_EXCEPTION_IGNORED
231} handle_exception_result;
232
233extern handle_exception_result handle_exception
234 (struct target_waitstatus *ourstatus, bool debug_exceptions);
235
e758e19c
TT
236/* Return true if there is a pending stop matching
237 desired_stop_thread_id. If DEBUG_EVENTS is true, logging will be
238 enabled. */
239
240extern bool matching_pending_stop (bool debug_events);
241
d2977bc4
TT
242/* See if a pending stop matches DESIRED_STOP_THREAD_ID. If so,
243 remove it from the list of pending stops, set 'current_event', and
244 return it. Otherwise, return an empty optional. */
245
246extern gdb::optional<pending_stop> fetch_pending_stop (bool debug_events);
247
e758e19c
TT
248/* A simple wrapper for ContinueDebugEvent that continues the last
249 waited-for event. If DEBUG_EVENTS is true, logging will be
250 enabled. */
251
252extern BOOL continue_last_debug_event (DWORD continue_status,
253 bool debug_events);
254
71fbdbaf 255/* A simple wrapper for WaitForDebugEvent that also sets the internal
2c1d95e8
TT
256 'last_wait_event' on success. */
257
258extern BOOL wait_for_debug_event (DEBUG_EVENT *event, DWORD timeout);
259
4834dad0
TT
260}
261
ae1f8880 262#endif
This page took 0.165117 seconds and 4 git commands to generate.