1 /* Internal interfaces for the Windows code
2 Copyright (C) 1995-2020 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
19 #ifndef NAT_WINDOWS_NAT_H
20 #define NAT_WINDOWS_NAT_H
25 #include "target/waitstatus.h"
30 /* Thread information structure used to track extra information about
32 struct windows_thread_info
34 windows_thread_info (DWORD tid_
, HANDLE h_
, CORE_ADDR tlb
)
37 thread_local_base (tlb
)
41 ~windows_thread_info ();
43 DISABLE_COPY_AND_ASSIGN (windows_thread_info
);
45 /* Ensure that this thread has been suspended. */
48 /* Resume the thread if it has been suspended. */
51 /* The Win32 thread identifier. */
54 /* The handle to the thread. */
57 /* Thread Information Block address. */
58 CORE_ADDR thread_local_base
;
60 /* This keeps track of whether SuspendThread was called on this
61 thread. -1 means there was a failure or that the thread was
62 explicitly not suspended, 1 means it was called, and 0 means it
67 /* The context as retrieved right after suspending the thread. */
68 CONTEXT base_context
{};
71 /* The context of the thread, including any manipulations. */
76 WOW64_CONTEXT wow64_context
;
80 /* Whether debug registers changed since we last set CONTEXT back to
82 bool debug_registers_changed
= false;
84 /* Nonzero if CONTEXT is invalidated and must be re-read from the
86 bool reload_context
= false;
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;
92 /* The name of the thread, allocated by xmalloc. */
93 gdb::unique_xmalloc_ptr
<char> name
;
97 /* Possible values to pass to 'thread_rec'. */
98 enum thread_disposition_type
100 /* Do not invalidate the thread's context, and do not suspend the
102 DONT_INVALIDATE_CONTEXT
,
103 /* Invalidate the context, but do not suspend the thread. */
105 /* Invalidate the context and suspend the thread. */
109 /* Find a thread record given a thread id. THREAD_DISPOSITION
110 controls whether the thread is suspended, and whether the context
113 This function must be supplied by the embedding application. */
114 extern windows_thread_info
*thread_rec (ptid_t ptid
,
115 thread_disposition_type disposition
);
117 /* Currently executing process */
118 extern HANDLE current_process_handle
;
119 extern DWORD current_process_id
;
120 extern DWORD main_thread_id
;
121 extern enum gdb_signal last_sig
;
123 /* The current debug event from WaitForDebugEvent or from a pending
125 extern DEBUG_EVENT current_event
;
127 /* The most recent event from WaitForDebugEvent. Unlike
128 current_event, this is guaranteed never to come from a pending
129 stop. This is important because only data from the most recent
130 event from WaitForDebugEvent can be used when calling
131 ContinueDebugEvent. */
132 extern DEBUG_EVENT last_wait_event
;
134 /* Info on currently selected thread */
135 extern windows_thread_info
*current_windows_thread
;
137 /* The ID of the thread for which we anticipate a stop event.
138 Normally this is -1, meaning we'll accept an event in any
140 extern DWORD desired_stop_thread_id
;
142 /* A single pending stop. See "pending_stops" for more
149 /* The target waitstatus we computed. */
150 target_waitstatus status
;
152 /* The event. A few fields of this can be referenced after a stop,
153 and it seemed simplest to store the entire event. */
157 /* A vector of pending stops. Sometimes, Windows will report a stop
158 on a thread that has been ostensibly suspended. We believe what
159 happens here is that two threads hit a breakpoint simultaneously,
160 and the Windows kernel queues the stop events. However, this can
161 result in the strange effect of trying to single step thread A --
162 leaving all other threads suspended -- and then seeing a stop in
163 thread B. To handle this scenario, we queue all such "pending"
164 stops here, and then process them once the step has completed. See
166 extern std::vector
<pending_stop
> pending_stops
;
168 /* Contents of $_siginfo */
169 extern EXCEPTION_RECORD siginfo_er
;
171 /* Return the name of the DLL referenced by H at ADDRESS. UNICODE
172 determines what sort of string is read from the inferior. Returns
173 the name of the DLL, or NULL on error. If a name is returned, it
174 is stored in a static buffer which is valid until the next call to
176 extern const char *get_image_name (HANDLE h
, void *address
, int unicode
);