1 /* Internal interfaces for the Windows code
2 Copyright (C) 1995-2019 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 #include "gdbsupport/common-defs.h"
20 #include "nat/windows-nat.h"
25 windows_thread_info::~windows_thread_info ()
31 windows_thread_info::suspend ()
36 if (SuspendThread (h
) == (DWORD
) -1)
38 DWORD err
= GetLastError ();
40 /* We get Access Denied (5) when trying to suspend
41 threads that Windows started on behalf of the
42 debuggee, usually when those threads are just
44 We can get Invalid Handle (6) if the main thread
46 if (err
!= ERROR_INVALID_HANDLE
&& err
!= ERROR_ACCESS_DENIED
)
47 warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"),
48 (unsigned) tid
, (unsigned) err
);
56 windows_thread_info::resume ()
60 stopped_at_software_breakpoint
= false;
62 if (ResumeThread (h
) == (DWORD
) -1)
64 DWORD err
= GetLastError ();
65 warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"),
66 (unsigned) tid
, (unsigned) err
);
73 get_image_name (HANDLE h
, void *address
, int unicode
)
76 static char buf
[MAX_PATH
];
78 static char buf
[(2 * MAX_PATH
) + 1];
80 DWORD size
= unicode
? sizeof (WCHAR
) : sizeof (char);
86 /* Attempt to read the name of the dll that was detected.
87 This is documented to work only when actively debugging
88 a program. It will not work for attached processes. */
93 /* Windows CE reports the address of the image name,
94 instead of an address of a pointer into the image name. */
95 address_ptr
= address
;
97 /* See if we could read the address of a string, and that the
98 address isn't null. */
99 if (!ReadProcessMemory (h
, address
, &address_ptr
,
100 sizeof (address_ptr
), &done
)
101 || done
!= sizeof (address_ptr
)
106 /* Find the length of the string. */
107 while (ReadProcessMemory (h
, address_ptr
+ len
++ * size
, &b
, size
, &done
)
108 && (b
[0] != 0 || b
[size
- 1] != 0) && done
== size
)
112 ReadProcessMemory (h
, address_ptr
, buf
, len
, &done
);
115 WCHAR
*unicode_address
= (WCHAR
*) alloca (len
* sizeof (WCHAR
));
116 ReadProcessMemory (h
, address_ptr
, unicode_address
, len
* sizeof (WCHAR
),
119 wcstombs (buf
, unicode_address
, MAX_PATH
);
121 WideCharToMultiByte (CP_ACP
, 0, unicode_address
, len
, buf
, sizeof buf
,