Share Windows thread-suspend and -resume code
[deliverable/binutils-gdb.git] / gdb / nat / windows-nat.c
1 /* Internal interfaces for the Windows code
2 Copyright (C) 1995-2019 Free Software Foundation, Inc.
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 #include "gdbsupport/common-defs.h"
20 #include "nat/windows-nat.h"
21
22 void
23 windows_thread_info::suspend ()
24 {
25 if (suspended != 0)
26 return;
27
28 if (SuspendThread (h) == (DWORD) -1)
29 {
30 DWORD err = GetLastError ();
31
32 /* We get Access Denied (5) when trying to suspend
33 threads that Windows started on behalf of the
34 debuggee, usually when those threads are just
35 about to exit.
36 We can get Invalid Handle (6) if the main thread
37 has exited. */
38 if (err != ERROR_INVALID_HANDLE && err != ERROR_ACCESS_DENIED)
39 warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"),
40 (unsigned) tid, (unsigned) err);
41 suspended = -1;
42 }
43 else
44 suspended = 1;
45 }
46
47 void
48 windows_thread_info::resume ()
49 {
50 if (suspended > 0)
51 {
52 if (ResumeThread (h) == (DWORD) -1)
53 {
54 DWORD err = GetLastError ();
55 warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"),
56 (unsigned) tid, (unsigned) err);
57 }
58 }
59 suspended = 0;
60 }
This page took 0.038843 seconds and 4 git commands to generate.