2020-04-09 04:33:35 +08:00
|
|
|
/* Internal interfaces for the Windows code
|
|
|
|
Copyright (C) 1995-2020 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef NAT_WINDOWS_NAT_H
|
|
|
|
#define NAT_WINDOWS_NAT_H
|
|
|
|
|
|
|
|
#include <windows.h>
|
Share some Windows-related globals
This moves some Windows-related globals into nat/windows-nat.c,
sharing them between gdb and gdbserver.
gdb/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(struct pending_stop, siginfo_er): Move to nat/windows-nat.c.
(display_selectors, fake_create_process)
(get_windows_debug_event): Update.
* nat/windows-nat.h (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(struct pending_stop, siginfo_er): Move from windows-nat.c.
* nat/windows-nat.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(siginfo_er): New globals. Move from windows-nat.c.
gdbserver/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* win32-low.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, siginfo_er): Move to
nat/windows-nat.c.
2020-04-09 04:33:35 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "target/waitstatus.h"
|
2020-04-09 04:33:35 +08:00
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
namespace windows_nat
|
|
|
|
{
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* Thread information structure used to track extra information about
|
|
|
|
each thread. */
|
|
|
|
struct windows_thread_info
|
|
|
|
{
|
2020-04-09 04:33:35 +08:00
|
|
|
windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb)
|
|
|
|
: tid (tid_),
|
|
|
|
h (h_),
|
|
|
|
thread_local_base (tlb)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
~windows_thread_info ();
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
DISABLE_COPY_AND_ASSIGN (windows_thread_info);
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* Ensure that this thread has been suspended. */
|
|
|
|
void suspend ();
|
|
|
|
|
|
|
|
/* Resume the thread if it has been suspended. */
|
|
|
|
void resume ();
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* The Win32 thread identifier. */
|
|
|
|
DWORD tid;
|
|
|
|
|
|
|
|
/* The handle to the thread. */
|
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
/* Thread Information Block address. */
|
|
|
|
CORE_ADDR thread_local_base;
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* This keeps track of whether SuspendThread was called on this
|
|
|
|
thread. -1 means there was a failure or that the thread was
|
|
|
|
explicitly not suspended, 1 means it was called, and 0 means it
|
|
|
|
was not. */
|
2020-04-09 04:33:35 +08:00
|
|
|
int suspended = 0;
|
2020-04-09 04:33:35 +08:00
|
|
|
|
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
/* The context as retrieved right after suspending the thread. */
|
2020-04-09 04:33:35 +08:00
|
|
|
CONTEXT base_context {};
|
2020-04-09 04:33:35 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The context of the thread, including any manipulations. */
|
|
|
|
union
|
|
|
|
{
|
2020-04-09 04:33:35 +08:00
|
|
|
CONTEXT context {};
|
2020-04-09 04:33:35 +08:00
|
|
|
#ifdef __x86_64__
|
|
|
|
WOW64_CONTEXT wow64_context;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Whether debug registers changed since we last set CONTEXT back to
|
|
|
|
the thread. */
|
2020-04-09 04:33:35 +08:00
|
|
|
bool debug_registers_changed = false;
|
2020-04-09 04:33:35 +08:00
|
|
|
|
|
|
|
/* Nonzero if CONTEXT is invalidated and must be re-read from the
|
|
|
|
inferior thread. */
|
2020-04-09 04:33:35 +08:00
|
|
|
bool reload_context = false;
|
2020-04-09 04:33:35 +08:00
|
|
|
|
Handle pending stops from the Windows kernel
PR gdb/22992 concerns an assertion failure in gdb when debugging a
certain inferior:
int finish_step_over(execution_control_state*): Assertion `ecs->event_thread->control.trap_expected' failed.
Initially the investigation centered on the discovery that gdb was not
suspending other threads when attempting to single-step. This
oversight is corrected in this patch: now, when stepping a thread, gdb
will call SuspendThread on all other threads.
However, the bug persisted even after this change. In particular,
WaitForDebugEvent could see a stop for a thread that was ostensibly
suspended. Our theory of what is happening here is that there are
actually simultaneous breakpoint hits, and the Windows kernel queues
the events, causing the second stop to be reported on a suspended
thread.
In Windows 10 or later gdb could use the DBG_REPLY_LATER flag to
ContinueDebugEvent to request that such events be re-reported later.
However, relying on that did not seem advisable, so this patch instead
arranges to queue such "pending" stops, and then to report them later,
once the step has completed.
In the PR, Pedro pointed out that it's best in this scenario to
implement the stopped_by_sw_breakpoint method, so this patch does this
as well.
gdb/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
PR gdb/22992
* windows-nat.c (current_event): Update comment.
(last_wait_event, desired_stop_thread_id): New globals.
(struct pending_stop): New.
(pending_stops): New global.
(windows_nat_target) <stopped_by_sw_breakpoint>
<supports_stopped_by_sw_breakpoint>: New methods.
(windows_fetch_one_register): Add assertions. Adjust PC.
(windows_continue): Handle pending stops. Suspend other threads
when stepping. Use last_wait_event
(wait_for_debug_event): New function.
(get_windows_debug_event): Use wait_for_debug_event. Handle
pending stops. Queue spurious stops.
(windows_nat_target::wait): Set stopped_at_software_breakpoint.
(windows_nat_target::kill): Use wait_for_debug_event.
* nat/windows-nat.h (struct windows_thread_info)
<stopped_at_software_breakpoint>: New field.
* nat/windows-nat.c (windows_thread_info::resume): Clear
stopped_at_software_breakpoint.
2020-04-09 04:33:35 +08:00
|
|
|
/* True if this thread is currently stopped at a software
|
|
|
|
breakpoint. This is used to offset the PC when needed. */
|
|
|
|
bool stopped_at_software_breakpoint = false;
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* The name of the thread, allocated by xmalloc. */
|
2020-04-09 04:33:35 +08:00
|
|
|
gdb::unique_xmalloc_ptr<char> name;
|
2020-04-09 04:33:35 +08:00
|
|
|
};
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
|
|
|
|
/* Possible values to pass to 'thread_rec'. */
|
|
|
|
enum thread_disposition_type
|
|
|
|
{
|
|
|
|
/* Do not invalidate the thread's context, and do not suspend the
|
|
|
|
thread. */
|
|
|
|
DONT_INVALIDATE_CONTEXT,
|
|
|
|
/* Invalidate the context, but do not suspend the thread. */
|
|
|
|
DONT_SUSPEND,
|
|
|
|
/* Invalidate the context and suspend the thread. */
|
|
|
|
INVALIDATE_CONTEXT
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Find a thread record given a thread id. THREAD_DISPOSITION
|
|
|
|
controls whether the thread is suspended, and whether the context
|
|
|
|
is invalidated.
|
|
|
|
|
|
|
|
This function must be supplied by the embedding application. */
|
|
|
|
extern windows_thread_info *thread_rec (ptid_t ptid,
|
|
|
|
thread_disposition_type disposition);
|
|
|
|
|
Share some Windows-related globals
This moves some Windows-related globals into nat/windows-nat.c,
sharing them between gdb and gdbserver.
gdb/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(struct pending_stop, siginfo_er): Move to nat/windows-nat.c.
(display_selectors, fake_create_process)
(get_windows_debug_event): Update.
* nat/windows-nat.h (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(struct pending_stop, siginfo_er): Move from windows-nat.c.
* nat/windows-nat.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, last_wait_event)
(current_windows_thread, desired_stop_thread_id, pending_stops)
(siginfo_er): New globals. Move from windows-nat.c.
gdbserver/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* win32-low.c (current_process_handle, current_process_id)
(main_thread_id, last_sig, current_event, siginfo_er): Move to
nat/windows-nat.c.
2020-04-09 04:33:35 +08:00
|
|
|
/* Currently executing process */
|
|
|
|
extern HANDLE current_process_handle;
|
|
|
|
extern DWORD current_process_id;
|
|
|
|
extern DWORD main_thread_id;
|
|
|
|
extern enum gdb_signal last_sig;
|
|
|
|
|
|
|
|
/* The current debug event from WaitForDebugEvent or from a pending
|
|
|
|
stop. */
|
|
|
|
extern DEBUG_EVENT current_event;
|
|
|
|
|
|
|
|
/* The most recent event from WaitForDebugEvent. Unlike
|
|
|
|
current_event, this is guaranteed never to come from a pending
|
|
|
|
stop. This is important because only data from the most recent
|
|
|
|
event from WaitForDebugEvent can be used when calling
|
|
|
|
ContinueDebugEvent. */
|
|
|
|
extern DEBUG_EVENT last_wait_event;
|
|
|
|
|
|
|
|
/* Info on currently selected thread */
|
|
|
|
extern windows_thread_info *current_windows_thread;
|
|
|
|
|
|
|
|
/* The ID of the thread for which we anticipate a stop event.
|
|
|
|
Normally this is -1, meaning we'll accept an event in any
|
|
|
|
thread. */
|
|
|
|
extern DWORD desired_stop_thread_id;
|
|
|
|
|
|
|
|
/* A single pending stop. See "pending_stops" for more
|
|
|
|
information. */
|
|
|
|
struct pending_stop
|
|
|
|
{
|
|
|
|
/* The thread id. */
|
|
|
|
DWORD thread_id;
|
|
|
|
|
|
|
|
/* The target waitstatus we computed. */
|
|
|
|
target_waitstatus status;
|
|
|
|
|
|
|
|
/* The event. A few fields of this can be referenced after a stop,
|
|
|
|
and it seemed simplest to store the entire event. */
|
|
|
|
DEBUG_EVENT event;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A vector of pending stops. Sometimes, Windows will report a stop
|
|
|
|
on a thread that has been ostensibly suspended. We believe what
|
|
|
|
happens here is that two threads hit a breakpoint simultaneously,
|
|
|
|
and the Windows kernel queues the stop events. However, this can
|
|
|
|
result in the strange effect of trying to single step thread A --
|
|
|
|
leaving all other threads suspended -- and then seeing a stop in
|
|
|
|
thread B. To handle this scenario, we queue all such "pending"
|
|
|
|
stops here, and then process them once the step has completed. See
|
|
|
|
PR gdb/22992. */
|
|
|
|
extern std::vector<pending_stop> pending_stops;
|
|
|
|
|
|
|
|
/* Contents of $_siginfo */
|
|
|
|
extern EXCEPTION_RECORD siginfo_er;
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
/* Return the name of the DLL referenced by H at ADDRESS. UNICODE
|
|
|
|
determines what sort of string is read from the inferior. Returns
|
|
|
|
the name of the DLL, or NULL on error. If a name is returned, it
|
|
|
|
is stored in a static buffer which is valid until the next call to
|
|
|
|
get_image_name. */
|
|
|
|
extern const char *get_image_name (HANDLE h, void *address, int unicode);
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
}
|
|
|
|
|
2020-04-09 04:33:35 +08:00
|
|
|
#endif
|