Call CloseHandle from ~windows_thread_info
[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 windows_thread_info::~windows_thread_info ()
23 {
24 CloseHandle (h);
25 }
26
27 void
28 windows_thread_info::suspend ()
29 {
30 if (suspended != 0)
31 return;
32
33 if (SuspendThread (h) == (DWORD) -1)
34 {
35 DWORD err = GetLastError ();
36
37 /* We get Access Denied (5) when trying to suspend
38 threads that Windows started on behalf of the
39 debuggee, usually when those threads are just
40 about to exit.
41 We can get Invalid Handle (6) if the main thread
42 has exited. */
43 if (err != ERROR_INVALID_HANDLE && err != ERROR_ACCESS_DENIED)
44 warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"),
45 (unsigned) tid, (unsigned) err);
46 suspended = -1;
47 }
48 else
49 suspended = 1;
50 }
51
52 void
53 windows_thread_info::resume ()
54 {
55 if (suspended > 0)
56 {
57 stopped_at_software_breakpoint = false;
58
59 if (ResumeThread (h) == (DWORD) -1)
60 {
61 DWORD err = GetLastError ();
62 warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"),
63 (unsigned) tid, (unsigned) err);
64 }
65 }
66 suspended = 0;
67 }
This page took 0.032249 seconds and 5 git commands to generate.