1 /* Low level interface to Windows debugging, for gdbserver.
2 Copyright (C) 2006-2020 Free Software Foundation, Inc.
4 Contributed by Leo Zayas. Based on "win32-nat.c" from GDB.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb/fileio.h"
24 #include "mem-break.h"
25 #include "win32-low.h"
26 #include "gdbthread.h"
35 #include "gdbsupport/gdb_tilde_expand.h"
36 #include "gdbsupport/common-inferior.h"
37 #include "gdbsupport/gdb_wait.h"
39 using namespace windows_nat
;
42 #include <sys/cygwin.h>
45 #define OUTMSG(X) do { printf X; fflush (stderr); } while (0)
58 #define _T(x) TEXT (x)
62 #define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
66 # define GETPROCADDRESS(DLL, PROC) \
67 ((winapi_ ## PROC) GetProcAddress (DLL, TEXT (#PROC)))
69 # define GETPROCADDRESS(DLL, PROC) \
70 ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))
73 int using_threads
= 1;
76 static int attaching
= 0;
78 /* A status that hasn't been reported to the core yet, and so
79 win32_wait should return it next, instead of fetching the next
80 debug event off the win32 API. */
81 static struct target_waitstatus cached_status
;
83 /* Non zero if an interrupt request is to be satisfied by suspending
85 static int soft_interrupt_requested
= 0;
87 /* Non zero if the inferior is stopped in a simulated breakpoint done
88 by suspending all the threads. */
89 static int faked_breakpoint
= 0;
91 const struct target_desc
*win32_tdesc
;
93 #define NUM_REGS (the_low_target.num_regs)
95 typedef BOOL (WINAPI
*winapi_DebugActiveProcessStop
) (DWORD dwProcessId
);
96 typedef BOOL (WINAPI
*winapi_DebugSetProcessKillOnExit
) (BOOL KillOnExit
);
97 typedef BOOL (WINAPI
*winapi_DebugBreakProcess
) (HANDLE
);
98 typedef BOOL (WINAPI
*winapi_GenerateConsoleCtrlEvent
) (DWORD
, DWORD
);
101 static void win32_add_all_dlls (void);
104 /* Get the thread ID from the current selected inferior (the current
107 current_thread_ptid (void)
112 /* The current debug event from WaitForDebugEvent. */
114 debug_event_ptid (DEBUG_EVENT
*event
)
116 return ptid_t (event
->dwProcessId
, event
->dwThreadId
, 0);
119 /* Get the thread context of the thread associated with TH. */
122 win32_get_thread_context (windows_thread_info
*th
)
124 memset (&th
->context
, 0, sizeof (CONTEXT
));
125 (*the_low_target
.get_thread_context
) (th
);
127 memcpy (&th
->base_context
, &th
->context
, sizeof (CONTEXT
));
131 /* Set the thread context of the thread associated with TH. */
134 win32_set_thread_context (windows_thread_info
*th
)
137 /* Calling SuspendThread on a thread that is running kernel code
138 will report that the suspending was successful, but in fact, that
139 will often not be true. In those cases, the context returned by
140 GetThreadContext will not be correct by the time the thread
141 stops, hence we can't set that context back into the thread when
142 resuming - it will most likely crash the inferior.
143 Unfortunately, there is no way to know when the thread will
144 really stop. To work around it, we'll only write the context
145 back to the thread when either the user or GDB explicitly change
146 it between stopping and resuming. */
147 if (memcmp (&th
->context
, &th
->base_context
, sizeof (CONTEXT
)) != 0)
149 SetThreadContext (th
->h
, &th
->context
);
152 /* Set the thread context of the thread associated with TH. */
155 win32_prepare_to_resume (windows_thread_info
*th
)
157 if (the_low_target
.prepare_to_resume
!= NULL
)
158 (*the_low_target
.prepare_to_resume
) (th
);
161 /* See win32-low.h. */
164 win32_require_context (windows_thread_info
*th
)
166 if (th
->context
.ContextFlags
== 0)
169 win32_get_thread_context (th
);
173 /* See nat/windows-nat.h. */
175 windows_thread_info
*
176 windows_nat::thread_rec (ptid_t ptid
, thread_disposition_type disposition
)
178 thread_info
*thread
= find_thread_ptid (ptid
);
182 windows_thread_info
*th
= (windows_thread_info
*) thread_target_data (thread
);
183 if (disposition
!= DONT_INVALIDATE_CONTEXT
)
184 win32_require_context (th
);
188 /* Add a thread to the thread list. */
189 static windows_thread_info
*
190 child_add_thread (DWORD pid
, DWORD tid
, HANDLE h
, void *tlb
)
192 windows_thread_info
*th
;
193 ptid_t ptid
= ptid_t (pid
, tid
, 0);
195 if ((th
= thread_rec (ptid
, DONT_INVALIDATE_CONTEXT
)))
198 th
= new windows_thread_info (tid
, h
, (CORE_ADDR
) (uintptr_t) tlb
);
200 add_thread (ptid
, th
);
202 if (the_low_target
.thread_added
!= NULL
)
203 (*the_low_target
.thread_added
) (th
);
208 /* Delete a thread from the list of threads. */
210 delete_thread_info (thread_info
*thread
)
212 windows_thread_info
*th
= (windows_thread_info
*) thread_target_data (thread
);
214 remove_thread (thread
);
218 /* Delete a thread from the list of threads. */
220 child_delete_thread (DWORD pid
, DWORD tid
)
222 /* If the last thread is exiting, just return. */
223 if (all_threads
.size () == 1)
226 thread_info
*thread
= find_thread_ptid (ptid_t (pid
, tid
));
230 delete_thread_info (thread
);
233 /* These watchpoint related wrapper functions simply pass on the function call
234 if the low target has registered a corresponding function. */
237 win32_process_target::supports_z_point_type (char z_type
)
239 return (z_type
== Z_PACKET_SW_BP
240 || (the_low_target
.supports_z_point_type
!= NULL
241 && the_low_target
.supports_z_point_type (z_type
)));
245 win32_process_target::insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
246 int size
, raw_breakpoint
*bp
)
248 if (type
== raw_bkpt_type_sw
)
249 return insert_memory_breakpoint (bp
);
250 else if (the_low_target
.insert_point
!= NULL
)
251 return the_low_target
.insert_point (type
, addr
, size
, bp
);
253 /* Unsupported (see target.h). */
258 win32_process_target::remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
259 int size
, raw_breakpoint
*bp
)
261 if (type
== raw_bkpt_type_sw
)
262 return remove_memory_breakpoint (bp
);
263 else if (the_low_target
.remove_point
!= NULL
)
264 return the_low_target
.remove_point (type
, addr
, size
, bp
);
266 /* Unsupported (see target.h). */
271 win32_process_target::stopped_by_watchpoint ()
273 if (the_low_target
.stopped_by_watchpoint
!= NULL
)
274 return the_low_target
.stopped_by_watchpoint ();
280 win32_process_target::stopped_data_address ()
282 if (the_low_target
.stopped_data_address
!= NULL
)
283 return the_low_target
.stopped_data_address ();
289 /* Transfer memory from/to the debugged process. */
291 child_xfer_memory (CORE_ADDR memaddr
, char *our
, int len
,
292 int write
, process_stratum_target
*target
)
297 uintptr_t addr
= (uintptr_t) memaddr
;
301 success
= WriteProcessMemory (current_process_handle
, (LPVOID
) addr
,
302 (LPCVOID
) our
, len
, &done
);
304 lasterror
= GetLastError ();
305 FlushInstructionCache (current_process_handle
, (LPCVOID
) addr
, len
);
309 success
= ReadProcessMemory (current_process_handle
, (LPCVOID
) addr
,
310 (LPVOID
) our
, len
, &done
);
312 lasterror
= GetLastError ();
314 if (!success
&& lasterror
== ERROR_PARTIAL_COPY
&& done
> 0)
317 return success
? done
: -1;
320 /* Clear out any old thread list and reinitialize it to a pristine
323 child_init_thread_list (void)
325 for_each_thread (delete_thread_info
);
328 /* Zero during the child initialization phase, and nonzero otherwise. */
330 static int child_initialization_done
= 0;
333 do_initial_child_stuff (HANDLE proch
, DWORD pid
, int attached
)
335 struct process_info
*proc
;
337 last_sig
= GDB_SIGNAL_0
;
339 current_process_handle
= proch
;
340 current_process_id
= pid
;
343 soft_interrupt_requested
= 0;
344 faked_breakpoint
= 0;
346 memset (¤t_event
, 0, sizeof (current_event
));
348 proc
= add_process (pid
, attached
);
349 proc
->tdesc
= win32_tdesc
;
350 child_init_thread_list ();
351 child_initialization_done
= 0;
353 if (the_low_target
.initial_stuff
!= NULL
)
354 (*the_low_target
.initial_stuff
) ();
356 cached_status
.kind
= TARGET_WAITKIND_IGNORE
;
358 /* Flush all currently pending debug events (thread and dll list) up
359 to the initial breakpoint. */
362 struct target_waitstatus status
;
364 the_target
->wait (minus_one_ptid
, &status
, 0);
366 /* Note win32_wait doesn't return thread events. */
367 if (status
.kind
!= TARGET_WAITKIND_LOADED
)
369 cached_status
= status
;
374 struct thread_resume resume
;
376 resume
.thread
= minus_one_ptid
;
377 resume
.kind
= resume_continue
;
380 the_target
->resume (&resume
, 1);
385 /* Now that the inferior has been started and all DLLs have been mapped,
386 we can iterate over all DLLs and load them in.
388 We avoid doing it any earlier because, on certain versions of Windows,
389 LOAD_DLL_DEBUG_EVENTs are sometimes not complete. In particular,
390 we have seen on Windows 8.1 that the ntdll.dll load event does not
391 include the DLL name, preventing us from creating an associated SO.
392 A possible explanation is that ntdll.dll might be mapped before
393 the SO info gets created by the Windows system -- ntdll.dll is
394 the first DLL to be reported via LOAD_DLL_DEBUG_EVENT and other DLLs
395 do not seem to suffer from that problem.
397 Rather than try to work around this sort of issue, it is much
398 simpler to just ignore DLL load/unload events during the startup
399 phase, and then process them all in one batch now. */
400 win32_add_all_dlls ();
403 child_initialization_done
= 1;
406 /* Resume all artificially suspended threads if we are continuing
409 continue_one_thread (thread_info
*thread
, int thread_id
)
411 windows_thread_info
*th
= (windows_thread_info
*) thread_target_data (thread
);
413 if (thread_id
== -1 || thread_id
== th
->tid
)
415 win32_prepare_to_resume (th
);
419 if (th
->context
.ContextFlags
)
421 win32_set_thread_context (th
);
422 th
->context
.ContextFlags
= 0;
431 child_continue (DWORD continue_status
, int thread_id
)
433 desired_stop_thread_id
= thread_id
;
434 if (matching_pending_stop (debug_threads
))
437 /* The inferior will only continue after the ContinueDebugEvent
439 for_each_thread ([&] (thread_info
*thread
)
441 continue_one_thread (thread
, thread_id
);
443 faked_breakpoint
= 0;
445 return continue_last_debug_event (continue_status
, debug_threads
);
448 /* Fetch register(s) from the current thread context. */
450 child_fetch_inferior_registers (struct regcache
*regcache
, int r
)
453 windows_thread_info
*th
= thread_rec (current_thread_ptid (),
455 if (r
== -1 || r
> NUM_REGS
)
456 child_fetch_inferior_registers (regcache
, NUM_REGS
);
458 for (regno
= 0; regno
< r
; regno
++)
459 (*the_low_target
.fetch_inferior_register
) (regcache
, th
, regno
);
462 /* Store a new register value into the current thread context. We don't
463 change the program's context until later, when we resume it. */
465 child_store_inferior_registers (struct regcache
*regcache
, int r
)
468 windows_thread_info
*th
= thread_rec (current_thread_ptid (),
470 if (r
== -1 || r
== 0 || r
> NUM_REGS
)
471 child_store_inferior_registers (regcache
, NUM_REGS
);
473 for (regno
= 0; regno
< r
; regno
++)
474 (*the_low_target
.store_inferior_register
) (regcache
, th
, regno
);
477 /* Map the Windows error number in ERROR to a locale-dependent error
478 message string and return a pointer to it. Typically, the values
479 for ERROR come from GetLastError.
481 The string pointed to shall not be modified by the application,
482 but may be overwritten by a subsequent call to strwinerror
484 The strwinerror function does not change the current setting
488 strwinerror (DWORD error
)
490 static char buf
[1024];
492 DWORD lasterr
= GetLastError ();
493 DWORD chars
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
494 | FORMAT_MESSAGE_ALLOCATE_BUFFER
,
497 0, /* Default language */
503 /* If there is an \r\n appended, zap it. */
505 && msgbuf
[chars
- 2] == '\r'
506 && msgbuf
[chars
- 1] == '\n')
512 if (chars
> ((COUNTOF (buf
)) - 1))
514 chars
= COUNTOF (buf
) - 1;
519 wcstombs (buf
, msgbuf
, chars
+ 1);
521 strncpy (buf
, msgbuf
, chars
+ 1);
526 sprintf (buf
, "unknown win32 error (%u)", (unsigned) error
);
528 SetLastError (lasterr
);
533 create_process (const char *program
, char *args
,
534 DWORD flags
, PROCESS_INFORMATION
*pi
)
536 const char *inferior_cwd
= get_inferior_cwd ();
538 size_t argslen
, proglen
;
540 proglen
= strlen (program
) + 1;
541 argslen
= strlen (args
) + proglen
;
544 wchar_t *p
, *wprogram
, *wargs
, *wcwd
= NULL
;
546 wprogram
= (wchar_t *) alloca (proglen
* sizeof (wchar_t));
547 mbstowcs (wprogram
, program
, proglen
);
549 for (p
= wprogram
; *p
; ++p
)
553 wargs
= alloca ((argslen
+ 1) * sizeof (wchar_t));
554 wcscpy (wargs
, wprogram
);
555 wcscat (wargs
, L
" ");
556 mbstowcs (wargs
+ proglen
, args
, argslen
+ 1 - proglen
);
558 if (inferior_cwd
!= NULL
)
560 std::string expanded_infcwd
= gdb_tilde_expand (inferior_cwd
);
561 std::replace (expanded_infcwd
.begin (), expanded_infcwd
.end (),
563 wcwd
= alloca ((expanded_infcwd
.size () + 1) * sizeof (wchar_t));
564 if (mbstowcs (wcwd
, expanded_infcwd
.c_str (),
565 expanded_infcwd
.size () + 1) == NULL
)
568 Could not convert the expanded inferior cwd to wide-char."));
572 ret
= CreateProcessW (wprogram
, /* image name */
573 wargs
, /* command line */
574 NULL
, /* security, not supported */
575 NULL
, /* thread, not supported */
576 FALSE
, /* inherit handles, not supported */
577 flags
, /* start flags */
578 NULL
, /* environment, not supported */
579 wcwd
, /* current directory */
580 NULL
, /* start info, not supported */
583 STARTUPINFOA si
= { sizeof (STARTUPINFOA
) };
584 char *program_and_args
= (char *) alloca (argslen
+ 1);
586 strcpy (program_and_args
, program
);
587 strcat (program_and_args
, " ");
588 strcat (program_and_args
, args
);
589 ret
= CreateProcessA (program
, /* image name */
590 program_and_args
, /* command line */
593 TRUE
, /* inherit handles */
594 flags
, /* start flags */
595 NULL
, /* environment */
596 /* current directory */
597 (inferior_cwd
== NULL
599 : gdb_tilde_expand (inferior_cwd
).c_str()),
600 &si
, /* start info */
607 /* Start a new process.
608 PROGRAM is the program name.
609 PROGRAM_ARGS is the vector containing the inferior's args.
610 Returns the new PID on success, -1 on failure. Registers the new
611 process with the process list. */
613 win32_process_target::create_inferior (const char *program
,
614 const std::vector
<char *> &program_args
)
616 client_state
&cs
= get_client_state ();
618 char real_path
[PATH_MAX
];
619 char *orig_path
, *new_path
, *path_ptr
;
623 PROCESS_INFORMATION pi
;
625 std::string str_program_args
= stringify_argv (program_args
);
626 char *args
= (char *) str_program_args
.c_str ();
628 /* win32_wait needs to know we're not attaching. */
632 error ("No executable specified, specify executable to debug.\n");
634 flags
= DEBUG_PROCESS
| DEBUG_ONLY_THIS_PROCESS
;
638 path_ptr
= getenv ("PATH");
641 int size
= cygwin_conv_path_list (CCP_POSIX_TO_WIN_A
, path_ptr
, NULL
, 0);
642 orig_path
= (char *) alloca (strlen (path_ptr
) + 1);
643 new_path
= (char *) alloca (size
);
644 strcpy (orig_path
, path_ptr
);
645 cygwin_conv_path_list (CCP_POSIX_TO_WIN_A
, path_ptr
, new_path
, size
);
646 setenv ("PATH", new_path
, 1);
648 cygwin_conv_path (CCP_POSIX_TO_WIN_A
, program
, real_path
, PATH_MAX
);
652 OUTMSG2 (("Command line is \"%s %s\"\n", program
, args
));
654 #ifdef CREATE_NEW_PROCESS_GROUP
655 flags
|= CREATE_NEW_PROCESS_GROUP
;
658 ret
= create_process (program
, args
, flags
, &pi
);
659 err
= GetLastError ();
660 if (!ret
&& err
== ERROR_FILE_NOT_FOUND
)
662 char *exename
= (char *) alloca (strlen (program
) + 5);
663 strcat (strcpy (exename
, program
), ".exe");
664 ret
= create_process (exename
, args
, flags
, &pi
);
665 err
= GetLastError ();
670 setenv ("PATH", orig_path
, 1);
675 error ("Error creating process \"%s %s\", (error %d): %s\n",
676 program
, args
, (int) err
, strwinerror (err
));
680 OUTMSG2 (("Process created: %s %s\n", program
, (char *) args
));
684 /* On Windows CE this handle can't be closed. The OS reuses
685 it in the debug events, while the 9x/NT versions of Windows
686 probably use a DuplicateHandle'd one. */
687 CloseHandle (pi
.hThread
);
690 do_initial_child_stuff (pi
.hProcess
, pi
.dwProcessId
, 0);
692 /* Wait till we are at 1st instruction in program, return new pid
693 (assuming success). */
694 cs
.last_ptid
= wait (ptid_t (current_process_id
), &cs
.last_status
, 0);
696 /* Necessary for handle_v_kill. */
697 signal_pid
= current_process_id
;
699 return current_process_id
;
702 /* Attach to a running process.
703 PID is the process ID to attach to, specified by the user
704 or a higher layer. */
706 win32_process_target::attach (unsigned long pid
)
709 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit
= NULL
;
712 HMODULE dll
= GetModuleHandle (_T("COREDLL.DLL"));
714 HMODULE dll
= GetModuleHandle (_T("KERNEL32.DLL"));
716 DebugSetProcessKillOnExit
= GETPROCADDRESS (dll
, DebugSetProcessKillOnExit
);
718 h
= OpenProcess (PROCESS_ALL_ACCESS
, FALSE
, pid
);
721 if (DebugActiveProcess (pid
))
723 if (DebugSetProcessKillOnExit
!= NULL
)
724 DebugSetProcessKillOnExit (FALSE
);
726 /* win32_wait needs to know we're attaching. */
728 do_initial_child_stuff (h
, pid
, 1);
735 err
= GetLastError ();
736 error ("Attach to process failed (error %d): %s\n",
737 (int) err
, strwinerror (err
));
740 /* See nat/windows-nat.h. */
743 windows_nat::handle_output_debug_string (struct target_waitstatus
*ourstatus
)
745 #define READ_BUFFER_LEN 1024
747 char s
[READ_BUFFER_LEN
+ 1] = { 0 };
748 DWORD nbytes
= current_event
.u
.DebugString
.nDebugStringLength
;
753 if (nbytes
> READ_BUFFER_LEN
)
754 nbytes
= READ_BUFFER_LEN
;
756 addr
= (CORE_ADDR
) (size_t) current_event
.u
.DebugString
.lpDebugStringData
;
758 if (current_event
.u
.DebugString
.fUnicode
)
760 /* The event tells us how many bytes, not chars, even
762 WCHAR buffer
[(READ_BUFFER_LEN
+ 1) / sizeof (WCHAR
)] = { 0 };
763 if (read_inferior_memory (addr
, (unsigned char *) buffer
, nbytes
) != 0)
765 wcstombs (s
, buffer
, (nbytes
+ 1) / sizeof (WCHAR
));
769 if (read_inferior_memory (addr
, (unsigned char *) s
, nbytes
) != 0)
773 if (!startswith (s
, "cYg"))
783 #undef READ_BUFFER_LEN
789 win32_clear_inferiors (void)
791 if (current_process_handle
!= NULL
)
792 CloseHandle (current_process_handle
);
794 for_each_thread (delete_thread_info
);
795 siginfo_er
.ExceptionCode
= 0;
799 /* Implementation of target_ops::kill. */
802 win32_process_target::kill (process_info
*process
)
804 TerminateProcess (current_process_handle
, 0);
807 if (!child_continue (DBG_CONTINUE
, -1))
809 if (!wait_for_debug_event (¤t_event
, INFINITE
))
811 if (current_event
.dwDebugEventCode
== EXIT_PROCESS_DEBUG_EVENT
)
813 else if (current_event
.dwDebugEventCode
== OUTPUT_DEBUG_STRING_EVENT
)
814 handle_output_debug_string (nullptr);
817 win32_clear_inferiors ();
819 remove_process (process
);
823 /* Implementation of target_ops::detach. */
826 win32_process_target::detach (process_info
*process
)
828 winapi_DebugActiveProcessStop DebugActiveProcessStop
= NULL
;
829 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit
= NULL
;
831 HMODULE dll
= GetModuleHandle (_T("COREDLL.DLL"));
833 HMODULE dll
= GetModuleHandle (_T("KERNEL32.DLL"));
835 DebugActiveProcessStop
= GETPROCADDRESS (dll
, DebugActiveProcessStop
);
836 DebugSetProcessKillOnExit
= GETPROCADDRESS (dll
, DebugSetProcessKillOnExit
);
838 if (DebugSetProcessKillOnExit
== NULL
839 || DebugActiveProcessStop
== NULL
)
843 struct thread_resume resume
;
844 resume
.thread
= minus_one_ptid
;
845 resume
.kind
= resume_continue
;
847 this->resume (&resume
, 1);
850 if (!DebugActiveProcessStop (current_process_id
))
853 DebugSetProcessKillOnExit (FALSE
);
854 remove_process (process
);
856 win32_clear_inferiors ();
861 win32_process_target::mourn (struct process_info
*process
)
863 remove_process (process
);
866 /* Implementation of target_ops::join. */
869 win32_process_target::join (int pid
)
871 HANDLE h
= OpenProcess (PROCESS_ALL_ACCESS
, FALSE
, pid
);
874 WaitForSingleObject (h
, INFINITE
);
879 /* Return true iff the thread with thread ID TID is alive. */
881 win32_process_target::thread_alive (ptid_t ptid
)
883 /* Our thread list is reliable; don't bother to poll target
885 return find_thread_ptid (ptid
) != NULL
;
888 /* Resume the inferior process. RESUME_INFO describes how we want
891 win32_process_target::resume (thread_resume
*resume_info
, size_t n
)
896 windows_thread_info
*th
;
897 DWORD continue_status
= DBG_CONTINUE
;
900 /* This handles the very limited set of resume packets that GDB can
901 currently produce. */
903 if (n
== 1 && resume_info
[0].thread
== minus_one_ptid
)
908 /* Yes, we're ignoring resume_info[0].thread. It'd be tricky to make
909 the Windows resume code do the right thing for thread switching. */
910 tid
= current_event
.dwThreadId
;
912 if (resume_info
[0].thread
!= minus_one_ptid
)
914 sig
= gdb_signal_from_host (resume_info
[0].sig
);
915 step
= resume_info
[0].kind
== resume_step
;
923 if (sig
!= GDB_SIGNAL_0
)
925 if (current_event
.dwDebugEventCode
!= EXCEPTION_DEBUG_EVENT
)
927 OUTMSG (("Cannot continue with signal %s here.\n",
928 gdb_signal_to_string (sig
)));
930 else if (sig
== last_sig
)
931 continue_status
= DBG_EXCEPTION_NOT_HANDLED
;
933 OUTMSG (("Can only continue with received signal %s.\n",
934 gdb_signal_to_string (last_sig
)));
937 last_sig
= GDB_SIGNAL_0
;
939 /* Get context for the currently selected thread. */
940 ptid
= debug_event_ptid (¤t_event
);
941 th
= thread_rec (ptid
, DONT_INVALIDATE_CONTEXT
);
944 win32_prepare_to_resume (th
);
946 if (th
->context
.ContextFlags
)
948 /* Move register values from the inferior into the thread
949 context structure. */
950 regcache_invalidate ();
954 if (the_low_target
.single_step
!= NULL
)
955 (*the_low_target
.single_step
) (th
);
957 error ("Single stepping is not supported "
958 "in this configuration.\n");
961 win32_set_thread_context (th
);
962 th
->context
.ContextFlags
= 0;
966 /* Allow continuing with the same signal that interrupted us.
967 Otherwise complain. */
969 child_continue (continue_status
, tid
);
973 win32_add_one_solib (const char *name
, CORE_ADDR load_addr
)
975 char buf
[MAX_PATH
+ 1];
976 char buf2
[MAX_PATH
+ 1];
979 WIN32_FIND_DATA w32_fd
;
980 WCHAR wname
[MAX_PATH
+ 1];
981 mbstowcs (wname
, name
, MAX_PATH
);
982 HANDLE h
= FindFirstFile (wname
, &w32_fd
);
984 WIN32_FIND_DATAA w32_fd
;
985 HANDLE h
= FindFirstFileA (name
, &w32_fd
);
988 /* The symbols in a dll are offset by 0x1000, which is the
989 offset from 0 of the first byte in an image - because
990 of the file header and the section alignment. */
993 if (h
== INVALID_HANDLE_VALUE
)
1001 char cwd
[MAX_PATH
+ 1];
1003 if (GetCurrentDirectoryA (MAX_PATH
+ 1, cwd
))
1005 p
= strrchr (buf
, '\\');
1008 SetCurrentDirectoryA (buf
);
1009 GetFullPathNameA (w32_fd
.cFileName
, MAX_PATH
, buf
, &p
);
1010 SetCurrentDirectoryA (cwd
);
1017 if (strcasecmp (buf
, "ntdll.dll") == 0)
1019 GetSystemDirectoryA (buf
, sizeof (buf
));
1020 strcat (buf
, "\\ntdll.dll");
1025 cygwin_conv_path (CCP_WIN_A_TO_POSIX
, buf
, buf2
, sizeof (buf2
));
1030 loaded_dll (buf2
, load_addr
);
1033 typedef BOOL (WINAPI
*winapi_EnumProcessModules
) (HANDLE
, HMODULE
*,
1035 typedef BOOL (WINAPI
*winapi_GetModuleInformation
) (HANDLE
, HMODULE
,
1036 LPMODULEINFO
, DWORD
);
1037 typedef DWORD (WINAPI
*winapi_GetModuleFileNameExA
) (HANDLE
, HMODULE
,
1040 static winapi_EnumProcessModules win32_EnumProcessModules
;
1041 static winapi_GetModuleInformation win32_GetModuleInformation
;
1042 static winapi_GetModuleFileNameExA win32_GetModuleFileNameExA
;
1047 static int psapi_loaded
= 0;
1048 static HMODULE dll
= NULL
;
1053 dll
= LoadLibrary (TEXT("psapi.dll"));
1056 win32_EnumProcessModules
=
1057 GETPROCADDRESS (dll
, EnumProcessModules
);
1058 win32_GetModuleInformation
=
1059 GETPROCADDRESS (dll
, GetModuleInformation
);
1060 win32_GetModuleFileNameExA
=
1061 GETPROCADDRESS (dll
, GetModuleFileNameExA
);
1064 return (win32_EnumProcessModules
!= NULL
1065 && win32_GetModuleInformation
!= NULL
1066 && win32_GetModuleFileNameExA
!= NULL
);
1071 /* Iterate over all DLLs currently mapped by our inferior, and
1072 add them to our list of solibs. */
1075 win32_add_all_dlls (void)
1079 HMODULE
*DllHandle
= dh_buf
;
1087 ok
= (*win32_EnumProcessModules
) (current_process_handle
,
1092 if (!ok
|| !cbNeeded
)
1095 DllHandle
= (HMODULE
*) alloca (cbNeeded
);
1099 ok
= (*win32_EnumProcessModules
) (current_process_handle
,
1106 for (i
= 1; i
< ((size_t) cbNeeded
/ sizeof (HMODULE
)); i
++)
1109 char dll_name
[MAX_PATH
];
1111 if (!(*win32_GetModuleInformation
) (current_process_handle
,
1116 if ((*win32_GetModuleFileNameExA
) (current_process_handle
,
1121 win32_add_one_solib (dll_name
, (CORE_ADDR
) (uintptr_t) mi
.lpBaseOfDll
);
1126 typedef HANDLE (WINAPI
*winapi_CreateToolhelp32Snapshot
) (DWORD
, DWORD
);
1127 typedef BOOL (WINAPI
*winapi_Module32First
) (HANDLE
, LPMODULEENTRY32
);
1128 typedef BOOL (WINAPI
*winapi_Module32Next
) (HANDLE
, LPMODULEENTRY32
);
1130 /* See nat/windows-nat.h. */
1133 windows_nat::handle_load_dll ()
1135 LOAD_DLL_DEBUG_INFO
*event
= ¤t_event
.u
.LoadDll
;
1136 const char *dll_name
;
1138 dll_name
= get_image_name (current_process_handle
,
1139 event
->lpImageName
, event
->fUnicode
);
1143 win32_add_one_solib (dll_name
, (CORE_ADDR
) (uintptr_t) event
->lpBaseOfDll
);
1146 /* See nat/windows-nat.h. */
1149 windows_nat::handle_unload_dll ()
1151 CORE_ADDR load_addr
=
1152 (CORE_ADDR
) (uintptr_t) current_event
.u
.UnloadDll
.lpBaseOfDll
;
1154 /* The symbols in a dll are offset by 0x1000, which is the
1155 offset from 0 of the first byte in an image - because
1156 of the file header and the section alignment. */
1157 load_addr
+= 0x1000;
1158 unloaded_dll (NULL
, load_addr
);
1162 suspend_one_thread (thread_info
*thread
)
1164 windows_thread_info
*th
= (windows_thread_info
*) thread_target_data (thread
);
1170 fake_breakpoint_event (void)
1172 OUTMSG2(("fake_breakpoint_event\n"));
1174 faked_breakpoint
= 1;
1176 memset (¤t_event
, 0, sizeof (current_event
));
1177 current_event
.dwThreadId
= main_thread_id
;
1178 current_event
.dwDebugEventCode
= EXCEPTION_DEBUG_EVENT
;
1179 current_event
.u
.Exception
.ExceptionRecord
.ExceptionCode
1180 = EXCEPTION_BREAKPOINT
;
1182 for_each_thread (suspend_one_thread
);
1187 auto_delete_breakpoint (CORE_ADDR stop_pc
)
1193 /* See nat/windows-nat.h. */
1196 windows_nat::handle_ms_vc_exception (const EXCEPTION_RECORD
*rec
)
1201 /* A helper function that will, if needed, set
1202 'stopped_at_software_breakpoint' on the thread and adjust the
1208 struct regcache
*regcache
= get_thread_regcache (current_thread
, 1);
1209 child_fetch_inferior_registers (regcache
, -1);
1211 windows_thread_info
*th
= thread_rec (current_thread_ptid (),
1212 DONT_INVALIDATE_CONTEXT
);
1213 th
->stopped_at_software_breakpoint
= false;
1215 if (current_event
.dwDebugEventCode
== EXCEPTION_DEBUG_EVENT
1216 && (current_event
.u
.Exception
.ExceptionRecord
.ExceptionCode
1217 == EXCEPTION_BREAKPOINT
)
1218 && child_initialization_done
)
1220 th
->stopped_at_software_breakpoint
= true;
1221 CORE_ADDR pc
= regcache_read_pc (regcache
);
1222 CORE_ADDR sw_breakpoint_pc
= pc
- the_low_target
.decr_pc_after_break
;
1223 regcache_write_pc (regcache
, sw_breakpoint_pc
);
1227 /* Get the next event from the child. */
1230 get_child_debug_event (DWORD
*continue_status
,
1231 struct target_waitstatus
*ourstatus
)
1235 last_sig
= GDB_SIGNAL_0
;
1236 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
1237 *continue_status
= DBG_CONTINUE
;
1239 /* Check if GDB sent us an interrupt request. */
1240 check_remote_input_interrupt_request ();
1242 if (soft_interrupt_requested
)
1244 soft_interrupt_requested
= 0;
1245 fake_breakpoint_event ();
1254 /* WinCE doesn't set an initial breakpoint automatically. To
1255 stop the inferior, we flush all currently pending debug
1256 events -- the thread list and the dll list are always
1257 reported immediatelly without delay, then, we suspend all
1258 threads and pretend we saw a trap at the current PC of the
1261 Contrary to desktop Windows, Windows CE *does* report the dll
1262 names on LOAD_DLL_DEBUG_EVENTs resulting from a
1263 DebugActiveProcess call. This limits the way we can detect
1264 if all the dlls have already been reported. If we get a real
1265 debug event before leaving attaching, the worst that will
1266 happen is the user will see a spurious breakpoint. */
1268 current_event
.dwDebugEventCode
= 0;
1269 if (!wait_for_debug_event (¤t_event
, 0))
1271 OUTMSG2(("no attach events left\n"));
1272 fake_breakpoint_event ();
1276 OUTMSG2(("got attach event\n"));
1281 gdb::optional
<pending_stop
> stop
= fetch_pending_stop (debug_threads
);
1282 if (stop
.has_value ())
1284 *ourstatus
= stop
->status
;
1285 current_event
= stop
->event
;
1286 ptid
= debug_event_ptid (¤t_event
);
1287 current_thread
= find_thread_ptid (ptid
);
1291 /* Keep the wait time low enough for comfortable remote
1292 interruption, but high enough so gdbserver doesn't become a
1294 if (!wait_for_debug_event (¤t_event
, 250))
1296 DWORD e
= GetLastError();
1298 if (e
== ERROR_PIPE_NOT_CONNECTED
)
1300 /* This will happen if the loader fails to succesfully
1301 load the application, e.g., if the main executable
1302 tries to pull in a non-existing export from a
1304 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1305 ourstatus
->value
.integer
= 1;
1315 switch (current_event
.dwDebugEventCode
)
1317 case CREATE_THREAD_DEBUG_EVENT
:
1318 OUTMSG2 (("gdbserver: kernel event CREATE_THREAD_DEBUG_EVENT "
1319 "for pid=%u tid=%x)\n",
1320 (unsigned) current_event
.dwProcessId
,
1321 (unsigned) current_event
.dwThreadId
));
1323 /* Record the existence of this thread. */
1324 child_add_thread (current_event
.dwProcessId
,
1325 current_event
.dwThreadId
,
1326 current_event
.u
.CreateThread
.hThread
,
1327 current_event
.u
.CreateThread
.lpThreadLocalBase
);
1330 case EXIT_THREAD_DEBUG_EVENT
:
1331 OUTMSG2 (("gdbserver: kernel event EXIT_THREAD_DEBUG_EVENT "
1332 "for pid=%u tid=%x\n",
1333 (unsigned) current_event
.dwProcessId
,
1334 (unsigned) current_event
.dwThreadId
));
1335 child_delete_thread (current_event
.dwProcessId
,
1336 current_event
.dwThreadId
);
1338 current_thread
= get_first_thread ();
1341 case CREATE_PROCESS_DEBUG_EVENT
:
1342 OUTMSG2 (("gdbserver: kernel event CREATE_PROCESS_DEBUG_EVENT "
1343 "for pid=%u tid=%x\n",
1344 (unsigned) current_event
.dwProcessId
,
1345 (unsigned) current_event
.dwThreadId
));
1346 CloseHandle (current_event
.u
.CreateProcessInfo
.hFile
);
1348 current_process_handle
= current_event
.u
.CreateProcessInfo
.hProcess
;
1349 main_thread_id
= current_event
.dwThreadId
;
1351 /* Add the main thread. */
1352 child_add_thread (current_event
.dwProcessId
,
1354 current_event
.u
.CreateProcessInfo
.hThread
,
1355 current_event
.u
.CreateProcessInfo
.lpThreadLocalBase
);
1360 /* Windows CE doesn't set the initial breakpoint
1361 automatically like the desktop versions of Windows do.
1362 We add it explicitly here. It will be removed as soon as
1364 set_breakpoint_at ((CORE_ADDR
) (long) current_event
.u
1365 .CreateProcessInfo
.lpStartAddress
,
1366 auto_delete_breakpoint
);
1371 case EXIT_PROCESS_DEBUG_EVENT
:
1372 OUTMSG2 (("gdbserver: kernel event EXIT_PROCESS_DEBUG_EVENT "
1373 "for pid=%u tid=%x\n",
1374 (unsigned) current_event
.dwProcessId
,
1375 (unsigned) current_event
.dwThreadId
));
1377 DWORD exit_status
= current_event
.u
.ExitProcess
.dwExitCode
;
1378 /* If the exit status looks like a fatal exception, but we
1379 don't recognize the exception's code, make the original
1380 exit status value available, to avoid losing information. */
1382 = WIFSIGNALED (exit_status
) ? WTERMSIG (exit_status
) : -1;
1383 if (exit_signal
== -1)
1385 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1386 ourstatus
->value
.integer
= exit_status
;
1390 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1391 ourstatus
->value
.sig
= gdb_signal_from_host (exit_signal
);
1394 child_continue (DBG_CONTINUE
, desired_stop_thread_id
);
1395 CloseHandle (current_process_handle
);
1396 current_process_handle
= NULL
;
1399 case LOAD_DLL_DEBUG_EVENT
:
1400 OUTMSG2 (("gdbserver: kernel event LOAD_DLL_DEBUG_EVENT "
1401 "for pid=%u tid=%x\n",
1402 (unsigned) current_event
.dwProcessId
,
1403 (unsigned) current_event
.dwThreadId
));
1404 CloseHandle (current_event
.u
.LoadDll
.hFile
);
1405 if (! child_initialization_done
)
1409 ourstatus
->kind
= TARGET_WAITKIND_LOADED
;
1410 ourstatus
->value
.sig
= GDB_SIGNAL_TRAP
;
1413 case UNLOAD_DLL_DEBUG_EVENT
:
1414 OUTMSG2 (("gdbserver: kernel event UNLOAD_DLL_DEBUG_EVENT "
1415 "for pid=%u tid=%x\n",
1416 (unsigned) current_event
.dwProcessId
,
1417 (unsigned) current_event
.dwThreadId
));
1418 if (! child_initialization_done
)
1420 handle_unload_dll ();
1421 ourstatus
->kind
= TARGET_WAITKIND_LOADED
;
1422 ourstatus
->value
.sig
= GDB_SIGNAL_TRAP
;
1425 case EXCEPTION_DEBUG_EVENT
:
1426 OUTMSG2 (("gdbserver: kernel event EXCEPTION_DEBUG_EVENT "
1427 "for pid=%u tid=%x\n",
1428 (unsigned) current_event
.dwProcessId
,
1429 (unsigned) current_event
.dwThreadId
));
1430 if (handle_exception (ourstatus
, debug_threads
)
1431 == HANDLE_EXCEPTION_UNHANDLED
)
1432 *continue_status
= DBG_EXCEPTION_NOT_HANDLED
;
1435 case OUTPUT_DEBUG_STRING_EVENT
:
1436 /* A message from the kernel (or Cygwin). */
1437 OUTMSG2 (("gdbserver: kernel event OUTPUT_DEBUG_STRING_EVENT "
1438 "for pid=%u tid=%x\n",
1439 (unsigned) current_event
.dwProcessId
,
1440 (unsigned) current_event
.dwThreadId
));
1441 handle_output_debug_string (nullptr);
1445 OUTMSG2 (("gdbserver: kernel event unknown "
1446 "for pid=%u tid=%x code=%x\n",
1447 (unsigned) current_event
.dwProcessId
,
1448 (unsigned) current_event
.dwThreadId
,
1449 (unsigned) current_event
.dwDebugEventCode
));
1453 ptid
= debug_event_ptid (¤t_event
);
1455 if (desired_stop_thread_id
!= -1 && desired_stop_thread_id
!= ptid
.lwp ())
1457 /* Pending stop. See the comment by the definition of
1458 "pending_stops" for details on why this is needed. */
1459 OUTMSG2 (("get_windows_debug_event - "
1460 "unexpected stop in 0x%lx (expecting 0x%x)\n",
1461 ptid
.lwp (), desired_stop_thread_id
));
1463 pending_stops
.push_back ({(DWORD
) ptid
.lwp (), *ourstatus
, current_event
});
1464 ourstatus
->kind
= TARGET_WAITKIND_SPURIOUS
;
1467 current_thread
= find_thread_ptid (ptid
);
1472 /* Wait for the inferior process to change state.
1473 STATUS will be filled in with a response code to send to GDB.
1474 Returns the signal which caused the process to stop. */
1476 win32_process_target::wait (ptid_t ptid
, target_waitstatus
*ourstatus
,
1479 if (cached_status
.kind
!= TARGET_WAITKIND_IGNORE
)
1481 /* The core always does a wait after creating the inferior, and
1482 do_initial_child_stuff already ran the inferior to the
1483 initial breakpoint (or an exit, if creating the process
1484 fails). Report it now. */
1485 *ourstatus
= cached_status
;
1486 cached_status
.kind
= TARGET_WAITKIND_IGNORE
;
1487 return debug_event_ptid (¤t_event
);
1492 DWORD continue_status
;
1493 if (!get_child_debug_event (&continue_status
, ourstatus
))
1496 switch (ourstatus
->kind
)
1498 case TARGET_WAITKIND_EXITED
:
1499 OUTMSG2 (("Child exited with retcode = %x\n",
1500 ourstatus
->value
.integer
));
1501 win32_clear_inferiors ();
1502 return ptid_t (current_event
.dwProcessId
);
1503 case TARGET_WAITKIND_STOPPED
:
1504 case TARGET_WAITKIND_SIGNALLED
:
1505 case TARGET_WAITKIND_LOADED
:
1507 OUTMSG2 (("Child Stopped with signal = %d \n",
1508 ourstatus
->value
.sig
));
1510 return debug_event_ptid (¤t_event
);
1513 OUTMSG (("Ignoring unknown internal event, %d\n", ourstatus
->kind
));
1515 case TARGET_WAITKIND_SPURIOUS
:
1516 /* do nothing, just continue */
1517 child_continue (continue_status
, desired_stop_thread_id
);
1523 /* Fetch registers from the inferior process.
1524 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
1526 win32_process_target::fetch_registers (regcache
*regcache
, int regno
)
1528 child_fetch_inferior_registers (regcache
, regno
);
1531 /* Store registers to the inferior process.
1532 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
1534 win32_process_target::store_registers (regcache
*regcache
, int regno
)
1536 child_store_inferior_registers (regcache
, regno
);
1539 /* Read memory from the inferior process. This should generally be
1540 called through read_inferior_memory, which handles breakpoint shadowing.
1541 Read LEN bytes at MEMADDR into a buffer at MYADDR. */
1543 win32_process_target::read_memory (CORE_ADDR memaddr
, unsigned char *myaddr
,
1546 return child_xfer_memory (memaddr
, (char *) myaddr
, len
, 0, 0) != len
;
1549 /* Write memory to the inferior process. This should generally be
1550 called through write_inferior_memory, which handles breakpoint shadowing.
1551 Write LEN bytes from the buffer at MYADDR to MEMADDR.
1552 Returns 0 on success and errno on failure. */
1554 win32_process_target::write_memory (CORE_ADDR memaddr
,
1555 const unsigned char *myaddr
, int len
)
1557 return child_xfer_memory (memaddr
, (char *) myaddr
, len
, 1, 0) != len
;
1560 /* Send an interrupt request to the inferior process. */
1562 win32_process_target::request_interrupt ()
1564 winapi_DebugBreakProcess DebugBreakProcess
;
1565 winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent
;
1568 HMODULE dll
= GetModuleHandle (_T("COREDLL.DLL"));
1570 HMODULE dll
= GetModuleHandle (_T("KERNEL32.DLL"));
1573 GenerateConsoleCtrlEvent
= GETPROCADDRESS (dll
, GenerateConsoleCtrlEvent
);
1575 if (GenerateConsoleCtrlEvent
!= NULL
1576 && GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT
, current_process_id
))
1579 /* GenerateConsoleCtrlEvent can fail if process id being debugged is
1580 not a process group id.
1581 Fallback to XP/Vista 'DebugBreakProcess', which generates a
1582 breakpoint exception in the interior process. */
1584 DebugBreakProcess
= GETPROCADDRESS (dll
, DebugBreakProcess
);
1586 if (DebugBreakProcess
!= NULL
1587 && DebugBreakProcess (current_process_handle
))
1590 /* Last resort, suspend all threads manually. */
1591 soft_interrupt_requested
= 1;
1595 win32_process_target::supports_hardware_single_step ()
1602 win32_error_to_fileio_error (DWORD err
)
1606 case ERROR_BAD_PATHNAME
:
1607 case ERROR_FILE_NOT_FOUND
:
1608 case ERROR_INVALID_NAME
:
1609 case ERROR_PATH_NOT_FOUND
:
1610 return FILEIO_ENOENT
;
1612 case ERROR_IO_DEVICE
:
1613 case ERROR_OPEN_FAILED
:
1615 case ERROR_INVALID_HANDLE
:
1616 return FILEIO_EBADF
;
1617 case ERROR_ACCESS_DENIED
:
1618 case ERROR_SHARING_VIOLATION
:
1619 return FILEIO_EACCES
;
1620 case ERROR_NOACCESS
:
1621 return FILEIO_EFAULT
;
1623 return FILEIO_EBUSY
;
1624 case ERROR_ALREADY_EXISTS
:
1625 case ERROR_FILE_EXISTS
:
1626 return FILEIO_EEXIST
;
1627 case ERROR_BAD_DEVICE
:
1628 return FILEIO_ENODEV
;
1629 case ERROR_DIRECTORY
:
1630 return FILEIO_ENOTDIR
;
1631 case ERROR_FILENAME_EXCED_RANGE
:
1632 case ERROR_INVALID_DATA
:
1633 case ERROR_INVALID_PARAMETER
:
1634 case ERROR_NEGATIVE_SEEK
:
1635 return FILEIO_EINVAL
;
1636 case ERROR_TOO_MANY_OPEN_FILES
:
1637 return FILEIO_EMFILE
;
1638 case ERROR_HANDLE_DISK_FULL
:
1639 case ERROR_DISK_FULL
:
1640 return FILEIO_ENOSPC
;
1641 case ERROR_WRITE_PROTECT
:
1642 return FILEIO_EROFS
;
1643 case ERROR_NOT_SUPPORTED
:
1644 return FILEIO_ENOSYS
;
1647 return FILEIO_EUNKNOWN
;
1651 win32_process_target::hostio_last_error (char *buf
)
1653 DWORD winerr
= GetLastError ();
1654 int fileio_err
= win32_error_to_fileio_error (winerr
);
1655 sprintf (buf
, "F-1,%x", fileio_err
);
1660 win32_process_target::supports_qxfer_siginfo ()
1665 /* Write Windows signal info. */
1668 win32_process_target::qxfer_siginfo (const char *annex
,
1669 unsigned char *readbuf
,
1670 unsigned const char *writebuf
,
1671 CORE_ADDR offset
, int len
)
1673 if (siginfo_er
.ExceptionCode
== 0)
1676 if (readbuf
== nullptr)
1679 if (offset
> sizeof (siginfo_er
))
1682 if (offset
+ len
> sizeof (siginfo_er
))
1683 len
= sizeof (siginfo_er
) - offset
;
1685 memcpy (readbuf
, (char *) &siginfo_er
+ offset
, len
);
1691 win32_process_target::supports_get_tib_address ()
1696 /* Write Windows OS Thread Information Block address. */
1699 win32_process_target::get_tib_address (ptid_t ptid
, CORE_ADDR
*addr
)
1701 windows_thread_info
*th
;
1702 th
= thread_rec (ptid
, DONT_INVALIDATE_CONTEXT
);
1706 *addr
= th
->thread_local_base
;
1710 /* Implementation of the target_ops method "sw_breakpoint_from_kind". */
1713 win32_process_target::sw_breakpoint_from_kind (int kind
, int *size
)
1715 *size
= the_low_target
.breakpoint_len
;
1716 return the_low_target
.breakpoint
;
1720 win32_process_target::stopped_by_sw_breakpoint ()
1722 windows_thread_info
*th
= thread_rec (current_thread_ptid (),
1723 DONT_INVALIDATE_CONTEXT
);
1724 return th
== nullptr ? false : th
->stopped_at_software_breakpoint
;
1728 win32_process_target::supports_stopped_by_sw_breakpoint ()
1734 win32_process_target::read_pc (struct regcache
*regcache
)
1736 return (*the_low_target
.get_pc
) (regcache
);
1740 win32_process_target::write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1742 return (*the_low_target
.set_pc
) (regcache
, pc
);
1745 /* The win32 target ops object. */
1747 static win32_process_target the_win32_target
;
1749 /* Initialize the Win32 backend. */
1751 initialize_low (void)
1753 set_target_ops (&the_win32_target
);
1754 the_low_target
.arch_setup ();