diff options
author | Tom Tromey <tromey@adacore.com> | 2020-04-08 14:33:35 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-04-08 14:47:58 -0600 |
commit | 98a032873232f9685dc7a5d632481c1488b9f1c5 (patch) | |
tree | 70351fce16a4d7860fa2cc9bb92032363babd7ed /gdb/nat | |
parent | 7c7411bcabdbe88c6a2f1b9a6090eea0dc50686f (diff) | |
download | gdb-98a032873232f9685dc7a5d632481c1488b9f1c5.zip gdb-98a032873232f9685dc7a5d632481c1488b9f1c5.tar.gz gdb-98a032873232f9685dc7a5d632481c1488b9f1c5.tar.bz2 |
Share Windows thread-suspend and -resume code
This adds "suspend" and "resume" methods to windows_thread_info, and
changes gdb and gdbserver to share this code.
gdb/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c (thread_rec): Use windows_thread_info::suspend.
(windows_continue): Use windows_continue::resume.
* nat/windows-nat.h (struct windows_thread_info) <suspend,
resume>: Declare new methods.
* nat/windows-nat.c: New file.
* configure.nat (NATDEPFILES): Add nat/windows-nat.o when needed.
gdbserver/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* win32-low.c (win32_require_context, suspend_one_thread): Use
windows_thread_info::suspend.
(continue_one_thread): Use windows_thread_info::resume.
* configure.srv (srv_tgtobj): Add windows-nat.o when needed.
Diffstat (limited to 'gdb/nat')
-rw-r--r-- | gdb/nat/windows-nat.c | 60 | ||||
-rw-r--r-- | gdb/nat/windows-nat.h | 6 |
2 files changed, 66 insertions, 0 deletions
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c new file mode 100644 index 0000000..a98ff42 --- /dev/null +++ b/gdb/nat/windows-nat.c @@ -0,0 +1,60 @@ +/* Internal interfaces for the Windows code + Copyright (C) 1995-2019 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/>. */ + +#include "gdbsupport/common-defs.h" +#include "nat/windows-nat.h" + +void +windows_thread_info::suspend () +{ + if (suspended != 0) + return; + + if (SuspendThread (h) == (DWORD) -1) + { + DWORD err = GetLastError (); + + /* We get Access Denied (5) when trying to suspend + threads that Windows started on behalf of the + debuggee, usually when those threads are just + about to exit. + We can get Invalid Handle (6) if the main thread + has exited. */ + if (err != ERROR_INVALID_HANDLE && err != ERROR_ACCESS_DENIED) + warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"), + (unsigned) tid, (unsigned) err); + suspended = -1; + } + else + suspended = 1; +} + +void +windows_thread_info::resume () +{ + if (suspended > 0) + { + if (ResumeThread (h) == (DWORD) -1) + { + DWORD err = GetLastError (); + warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"), + (unsigned) tid, (unsigned) err); + } + } + suspended = 0; +} diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 543de89..695f801 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -34,6 +34,12 @@ struct windows_thread_info DISABLE_COPY_AND_ASSIGN (windows_thread_info); + /* Ensure that this thread has been suspended. */ + void suspend (); + + /* Resume the thread if it has been suspended. */ + void resume (); + /* The Win32 thread identifier. */ DWORD tid; |