1 /* Internal interfaces for the Windows code
2 Copyright (C) 1995-2020 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 HANDLE current_process_handle
;
26 DWORD current_process_id
;
28 enum gdb_signal last_sig
= GDB_SIGNAL_0
;
29 DEBUG_EVENT current_event
;
30 DEBUG_EVENT last_wait_event
;
31 windows_thread_info
*current_windows_thread
;
32 DWORD desired_stop_thread_id
= -1;
33 std::vector
<pending_stop
> pending_stops
;
34 EXCEPTION_RECORD siginfo_er
;
36 windows_thread_info::~windows_thread_info ()
42 windows_thread_info::suspend ()
47 if (SuspendThread (h
) == (DWORD
) -1)
49 DWORD err
= GetLastError ();
51 /* We get Access Denied (5) when trying to suspend
52 threads that Windows started on behalf of the
53 debuggee, usually when those threads are just
55 We can get Invalid Handle (6) if the main thread
57 if (err
!= ERROR_INVALID_HANDLE
&& err
!= ERROR_ACCESS_DENIED
)
58 warning (_("SuspendThread (tid=0x%x) failed. (winerr %u)"),
59 (unsigned) tid
, (unsigned) err
);
67 windows_thread_info::resume ()
71 stopped_at_software_breakpoint
= false;
73 if (ResumeThread (h
) == (DWORD
) -1)
75 DWORD err
= GetLastError ();
76 warning (_("warning: ResumeThread (tid=0x%x) failed. (winerr %u)"),
77 (unsigned) tid
, (unsigned) err
);
84 get_image_name (HANDLE h
, void *address
, int unicode
)
87 static char buf
[MAX_PATH
];
89 static char buf
[(2 * MAX_PATH
) + 1];
91 DWORD size
= unicode
? sizeof (WCHAR
) : sizeof (char);
97 /* Attempt to read the name of the dll that was detected.
98 This is documented to work only when actively debugging
99 a program. It will not work for attached processes. */
104 /* Windows CE reports the address of the image name,
105 instead of an address of a pointer into the image name. */
106 address_ptr
= address
;
108 /* See if we could read the address of a string, and that the
109 address isn't null. */
110 if (!ReadProcessMemory (h
, address
, &address_ptr
,
111 sizeof (address_ptr
), &done
)
112 || done
!= sizeof (address_ptr
)
117 /* Find the length of the string. */
118 while (ReadProcessMemory (h
, address_ptr
+ len
++ * size
, &b
, size
, &done
)
119 && (b
[0] != 0 || b
[size
- 1] != 0) && done
== size
)
123 ReadProcessMemory (h
, address_ptr
, buf
, len
, &done
);
126 WCHAR
*unicode_address
= (WCHAR
*) alloca (len
* sizeof (WCHAR
));
127 ReadProcessMemory (h
, address_ptr
, unicode_address
, len
* sizeof (WCHAR
),
130 wcstombs (buf
, unicode_address
, MAX_PATH
);
132 WideCharToMultiByte (CP_ACP
, 0, unicode_address
, len
, buf
, sizeof buf
,