Remove WITH_SIM define
[binutils-gdb.git] / gdbserver / win32-low.cc
1 /* Low level interface to Windows debugging, for gdbserver.
2 Copyright (C) 2006-2022 Free Software Foundation, Inc.
3
4 Contributed by Leo Zayas. Based on "win32-nat.c" from GDB.
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21 #include "server.h"
22 #include "regcache.h"
23 #include "gdb/fileio.h"
24 #include "mem-break.h"
25 #include "win32-low.h"
26 #include "gdbthread.h"
27 #include "dll.h"
28 #include "hostio.h"
29 #include <windows.h>
30 #include <winnt.h>
31 #include <imagehlp.h>
32 #include <tlhelp32.h>
33 #include <psapi.h>
34 #include <process.h>
35 #include "gdbsupport/gdb_tilde_expand.h"
36 #include "gdbsupport/common-inferior.h"
37 #include "gdbsupport/gdb_wait.h"
38
39 using namespace windows_nat;
40
41 static windows_process_info windows_process;
42
43 #ifndef USE_WIN32API
44 #include <sys/cygwin.h>
45 #endif
46
47 #define OUTMSG(X) do { printf X; fflush (stderr); } while (0)
48
49 #define OUTMSG2(X) \
50 do \
51 { \
52 if (debug_threads) \
53 { \
54 printf X; \
55 fflush (stderr); \
56 } \
57 } while (0)
58
59 #ifndef _T
60 #define _T(x) TEXT (x)
61 #endif
62
63 #ifndef COUNTOF
64 #define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
65 #endif
66
67 int using_threads = 1;
68
69 /* Globals. */
70 static int attaching = 0;
71
72 /* A status that hasn't been reported to the core yet, and so
73 win32_wait should return it next, instead of fetching the next
74 debug event off the win32 API. */
75 static struct target_waitstatus cached_status;
76
77 /* Non zero if an interrupt request is to be satisfied by suspending
78 all threads. */
79 static int soft_interrupt_requested = 0;
80
81 /* Non zero if the inferior is stopped in a simulated breakpoint done
82 by suspending all the threads. */
83 static int faked_breakpoint = 0;
84
85 /* True if current_process_handle needs to be closed. */
86 static bool open_process_used = false;
87
88 const struct target_desc *win32_tdesc;
89 #ifdef __x86_64__
90 const struct target_desc *wow64_win32_tdesc;
91 #endif
92
93 #define NUM_REGS (the_low_target.num_regs ())
94
95 /* Get the thread ID from the current selected inferior (the current
96 thread). */
97 static ptid_t
98 current_thread_ptid (void)
99 {
100 return current_ptid;
101 }
102
103 /* The current debug event from WaitForDebugEvent. */
104 static ptid_t
105 debug_event_ptid (DEBUG_EVENT *event)
106 {
107 return ptid_t (event->dwProcessId, event->dwThreadId, 0);
108 }
109
110 /* Get the thread context of the thread associated with TH. */
111
112 static void
113 win32_get_thread_context (windows_thread_info *th)
114 {
115 #ifdef __x86_64__
116 if (wow64_process)
117 memset (&th->wow64_context, 0, sizeof (WOW64_CONTEXT));
118 else
119 #endif
120 memset (&th->context, 0, sizeof (CONTEXT));
121 (*the_low_target.get_thread_context) (th);
122 }
123
124 /* Set the thread context of the thread associated with TH. */
125
126 static void
127 win32_set_thread_context (windows_thread_info *th)
128 {
129 #ifdef __x86_64__
130 if (wow64_process)
131 Wow64SetThreadContext (th->h, &th->wow64_context);
132 else
133 #endif
134 SetThreadContext (th->h, &th->context);
135 }
136
137 /* Set the thread context of the thread associated with TH. */
138
139 static void
140 win32_prepare_to_resume (windows_thread_info *th)
141 {
142 if (the_low_target.prepare_to_resume != NULL)
143 (*the_low_target.prepare_to_resume) (th);
144 }
145
146 /* See win32-low.h. */
147
148 void
149 win32_require_context (windows_thread_info *th)
150 {
151 DWORD context_flags;
152 #ifdef __x86_64__
153 if (wow64_process)
154 context_flags = th->wow64_context.ContextFlags;
155 else
156 #endif
157 context_flags = th->context.ContextFlags;
158 if (context_flags == 0)
159 {
160 th->suspend ();
161 win32_get_thread_context (th);
162 }
163 }
164
165 /* See nat/windows-nat.h. */
166
167 windows_thread_info *
168 windows_nat::windows_process_info::thread_rec
169 (ptid_t ptid, thread_disposition_type disposition)
170 {
171 thread_info *thread = find_thread_ptid (ptid);
172 if (thread == NULL)
173 return NULL;
174
175 windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);
176 if (disposition != DONT_INVALIDATE_CONTEXT)
177 win32_require_context (th);
178 return th;
179 }
180
181 /* Add a thread to the thread list. */
182 static windows_thread_info *
183 child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
184 {
185 windows_thread_info *th;
186 ptid_t ptid = ptid_t (pid, tid, 0);
187
188 if ((th = windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT)))
189 return th;
190
191 CORE_ADDR base = (CORE_ADDR) (uintptr_t) tlb;
192 #ifdef __x86_64__
193 /* For WOW64 processes, this is actually the pointer to the 64bit TIB,
194 and the 32bit TIB is exactly 2 pages after it. */
195 if (wow64_process)
196 base += 2 * 4096; /* page size = 4096 */
197 #endif
198 th = new windows_thread_info (tid, h, base);
199
200 add_thread (ptid, th);
201
202 if (the_low_target.thread_added != NULL)
203 (*the_low_target.thread_added) (th);
204
205 return th;
206 }
207
208 /* Delete a thread from the list of threads. */
209 static void
210 delete_thread_info (thread_info *thread)
211 {
212 windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);
213
214 remove_thread (thread);
215 delete th;
216 }
217
218 /* Delete a thread from the list of threads. */
219 static void
220 child_delete_thread (DWORD pid, DWORD tid)
221 {
222 /* If the last thread is exiting, just return. */
223 if (all_threads.size () == 1)
224 return;
225
226 thread_info *thread = find_thread_ptid (ptid_t (pid, tid));
227 if (thread == NULL)
228 return;
229
230 delete_thread_info (thread);
231 }
232
233 /* These watchpoint related wrapper functions simply pass on the function call
234 if the low target has registered a corresponding function. */
235
236 bool
237 win32_process_target::supports_z_point_type (char z_type)
238 {
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)));
242 }
243
244 int
245 win32_process_target::insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
246 int size, raw_breakpoint *bp)
247 {
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);
252 else
253 /* Unsupported (see target.h). */
254 return 1;
255 }
256
257 int
258 win32_process_target::remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
259 int size, raw_breakpoint *bp)
260 {
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);
265 else
266 /* Unsupported (see target.h). */
267 return 1;
268 }
269
270 bool
271 win32_process_target::stopped_by_watchpoint ()
272 {
273 if (the_low_target.stopped_by_watchpoint != NULL)
274 return the_low_target.stopped_by_watchpoint ();
275 else
276 return false;
277 }
278
279 CORE_ADDR
280 win32_process_target::stopped_data_address ()
281 {
282 if (the_low_target.stopped_data_address != NULL)
283 return the_low_target.stopped_data_address ();
284 else
285 return 0;
286 }
287
288
289 /* Transfer memory from/to the debugged process. */
290 static int
291 child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
292 int write, process_stratum_target *target)
293 {
294 BOOL success;
295 SIZE_T done = 0;
296 DWORD lasterror = 0;
297 uintptr_t addr = (uintptr_t) memaddr;
298
299 if (write)
300 {
301 success = WriteProcessMemory (windows_process.handle, (LPVOID) addr,
302 (LPCVOID) our, len, &done);
303 if (!success)
304 lasterror = GetLastError ();
305 FlushInstructionCache (windows_process.handle, (LPCVOID) addr, len);
306 }
307 else
308 {
309 success = ReadProcessMemory (windows_process.handle, (LPCVOID) addr,
310 (LPVOID) our, len, &done);
311 if (!success)
312 lasterror = GetLastError ();
313 }
314 if (!success && lasterror == ERROR_PARTIAL_COPY && done > 0)
315 return done;
316 else
317 return success ? done : -1;
318 }
319
320 /* Clear out any old thread list and reinitialize it to a pristine
321 state. */
322 static void
323 child_init_thread_list (void)
324 {
325 for_each_thread (delete_thread_info);
326 }
327
328 /* Zero during the child initialization phase, and nonzero otherwise. */
329
330 static int child_initialization_done = 0;
331
332 static void
333 do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
334 {
335 struct process_info *proc;
336
337 windows_process.last_sig = GDB_SIGNAL_0;
338 windows_process.handle = proch;
339 windows_process.id = pid;
340 windows_process.main_thread_id = 0;
341
342 soft_interrupt_requested = 0;
343 faked_breakpoint = 0;
344 open_process_used = true;
345
346 memset (&windows_process.current_event, 0,
347 sizeof (windows_process.current_event));
348
349 #ifdef __x86_64__
350 BOOL wow64;
351 if (!IsWow64Process (proch, &wow64))
352 {
353 DWORD err = GetLastError ();
354 error ("Check if WOW64 process failed (error %d): %s\n",
355 (int) err, strwinerror (err));
356 }
357 wow64_process = wow64;
358
359 if (wow64_process
360 && (Wow64GetThreadContext == nullptr
361 || Wow64SetThreadContext == nullptr))
362 error ("WOW64 debugging is not supported on this system.\n");
363
364 ignore_first_breakpoint = !attached && wow64_process;
365 #endif
366
367 proc = add_process (pid, attached);
368 #ifdef __x86_64__
369 if (wow64_process)
370 proc->tdesc = wow64_win32_tdesc;
371 else
372 #endif
373 proc->tdesc = win32_tdesc;
374 child_init_thread_list ();
375 child_initialization_done = 0;
376
377 if (the_low_target.initial_stuff != NULL)
378 (*the_low_target.initial_stuff) ();
379
380 cached_status.set_ignore ();
381
382 /* Flush all currently pending debug events (thread and dll list) up
383 to the initial breakpoint. */
384 while (1)
385 {
386 struct target_waitstatus status;
387
388 the_target->wait (minus_one_ptid, &status, 0);
389
390 /* Note win32_wait doesn't return thread events. */
391 if (status.kind () != TARGET_WAITKIND_LOADED)
392 {
393 cached_status = status;
394 break;
395 }
396
397 {
398 struct thread_resume resume;
399
400 resume.thread = minus_one_ptid;
401 resume.kind = resume_continue;
402 resume.sig = 0;
403
404 the_target->resume (&resume, 1);
405 }
406 }
407
408 /* Now that the inferior has been started and all DLLs have been mapped,
409 we can iterate over all DLLs and load them in.
410
411 We avoid doing it any earlier because, on certain versions of Windows,
412 LOAD_DLL_DEBUG_EVENTs are sometimes not complete. In particular,
413 we have seen on Windows 8.1 that the ntdll.dll load event does not
414 include the DLL name, preventing us from creating an associated SO.
415 A possible explanation is that ntdll.dll might be mapped before
416 the SO info gets created by the Windows system -- ntdll.dll is
417 the first DLL to be reported via LOAD_DLL_DEBUG_EVENT and other DLLs
418 do not seem to suffer from that problem.
419
420 Rather than try to work around this sort of issue, it is much
421 simpler to just ignore DLL load/unload events during the startup
422 phase, and then process them all in one batch now. */
423 windows_process.add_all_dlls ();
424
425 child_initialization_done = 1;
426 }
427
428 /* Resume all artificially suspended threads if we are continuing
429 execution. */
430 static void
431 continue_one_thread (thread_info *thread, int thread_id)
432 {
433 windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);
434
435 if (thread_id == -1 || thread_id == th->tid)
436 {
437 win32_prepare_to_resume (th);
438
439 if (th->suspended)
440 {
441 DWORD *context_flags;
442 #ifdef __x86_64__
443 if (wow64_process)
444 context_flags = &th->wow64_context.ContextFlags;
445 else
446 #endif
447 context_flags = &th->context.ContextFlags;
448 if (*context_flags)
449 {
450 win32_set_thread_context (th);
451 *context_flags = 0;
452 }
453
454 th->resume ();
455 }
456 }
457 }
458
459 static BOOL
460 child_continue (DWORD continue_status, int thread_id)
461 {
462 windows_process.desired_stop_thread_id = thread_id;
463 if (windows_process.matching_pending_stop (debug_threads))
464 return TRUE;
465
466 /* The inferior will only continue after the ContinueDebugEvent
467 call. */
468 for_each_thread ([&] (thread_info *thread)
469 {
470 continue_one_thread (thread, thread_id);
471 });
472 faked_breakpoint = 0;
473
474 return continue_last_debug_event (continue_status, debug_threads);
475 }
476
477 /* Fetch register(s) from the current thread context. */
478 static void
479 child_fetch_inferior_registers (struct regcache *regcache, int r)
480 {
481 int regno;
482 windows_thread_info *th
483 = windows_process.thread_rec (current_thread_ptid (),
484 INVALIDATE_CONTEXT);
485 if (r == -1 || r > NUM_REGS)
486 child_fetch_inferior_registers (regcache, NUM_REGS);
487 else
488 for (regno = 0; regno < r; regno++)
489 (*the_low_target.fetch_inferior_register) (regcache, th, regno);
490 }
491
492 /* Store a new register value into the current thread context. We don't
493 change the program's context until later, when we resume it. */
494 static void
495 child_store_inferior_registers (struct regcache *regcache, int r)
496 {
497 int regno;
498 windows_thread_info *th
499 = windows_process.thread_rec (current_thread_ptid (),
500 INVALIDATE_CONTEXT);
501 if (r == -1 || r == 0 || r > NUM_REGS)
502 child_store_inferior_registers (regcache, NUM_REGS);
503 else
504 for (regno = 0; regno < r; regno++)
505 (*the_low_target.store_inferior_register) (regcache, th, regno);
506 }
507
508 /* Map the Windows error number in ERROR to a locale-dependent error
509 message string and return a pointer to it. Typically, the values
510 for ERROR come from GetLastError.
511
512 The string pointed to shall not be modified by the application,
513 but may be overwritten by a subsequent call to strwinerror
514
515 The strwinerror function does not change the current setting
516 of GetLastError. */
517
518 char *
519 strwinerror (DWORD error)
520 {
521 static char buf[1024];
522 TCHAR *msgbuf;
523 DWORD lasterr = GetLastError ();
524 DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
525 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
526 NULL,
527 error,
528 0, /* Default language */
529 (LPTSTR) &msgbuf,
530 0,
531 NULL);
532 if (chars != 0)
533 {
534 /* If there is an \r\n appended, zap it. */
535 if (chars >= 2
536 && msgbuf[chars - 2] == '\r'
537 && msgbuf[chars - 1] == '\n')
538 {
539 chars -= 2;
540 msgbuf[chars] = 0;
541 }
542
543 if (chars > ((COUNTOF (buf)) - 1))
544 {
545 chars = COUNTOF (buf) - 1;
546 msgbuf [chars] = 0;
547 }
548
549 #ifdef UNICODE
550 wcstombs (buf, msgbuf, chars + 1);
551 #else
552 strncpy (buf, msgbuf, chars + 1);
553 #endif
554 LocalFree (msgbuf);
555 }
556 else
557 sprintf (buf, "unknown win32 error (%u)", (unsigned) error);
558
559 SetLastError (lasterr);
560 return buf;
561 }
562
563 static BOOL
564 create_process (const char *program, char *args,
565 DWORD flags, PROCESS_INFORMATION *pi)
566 {
567 const std::string &inferior_cwd = get_inferior_cwd ();
568 BOOL ret;
569 size_t argslen, proglen;
570
571 proglen = strlen (program) + 1;
572 argslen = strlen (args) + proglen;
573
574 STARTUPINFOA si = { sizeof (STARTUPINFOA) };
575 char *program_and_args = (char *) alloca (argslen + 1);
576
577 strcpy (program_and_args, program);
578 strcat (program_and_args, " ");
579 strcat (program_and_args, args);
580 ret = CreateProcessA (program, /* image name */
581 program_and_args, /* command line */
582 NULL, /* security */
583 NULL, /* thread */
584 TRUE, /* inherit handles */
585 flags, /* start flags */
586 NULL, /* environment */
587 /* current directory */
588 (inferior_cwd.empty ()
589 ? NULL
590 : gdb_tilde_expand (inferior_cwd.c_str ()).c_str()),
591 &si, /* start info */
592 pi); /* proc info */
593
594 return ret;
595 }
596
597 /* Start a new process.
598 PROGRAM is the program name.
599 PROGRAM_ARGS is the vector containing the inferior's args.
600 Returns the new PID on success, -1 on failure. Registers the new
601 process with the process list. */
602 int
603 win32_process_target::create_inferior (const char *program,
604 const std::vector<char *> &program_args)
605 {
606 client_state &cs = get_client_state ();
607 #ifndef USE_WIN32API
608 char real_path[PATH_MAX];
609 char *orig_path, *new_path, *path_ptr;
610 #endif
611 BOOL ret;
612 DWORD flags;
613 PROCESS_INFORMATION pi;
614 DWORD err;
615 std::string str_program_args = construct_inferior_arguments (program_args);
616 char *args = (char *) str_program_args.c_str ();
617
618 /* win32_wait needs to know we're not attaching. */
619 attaching = 0;
620
621 if (!program)
622 error ("No executable specified, specify executable to debug.\n");
623
624 flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
625
626 #ifndef USE_WIN32API
627 orig_path = NULL;
628 path_ptr = getenv ("PATH");
629 if (path_ptr)
630 {
631 int size = cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, NULL, 0);
632 orig_path = (char *) alloca (strlen (path_ptr) + 1);
633 new_path = (char *) alloca (size);
634 strcpy (orig_path, path_ptr);
635 cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, new_path, size);
636 setenv ("PATH", new_path, 1);
637 }
638 cygwin_conv_path (CCP_POSIX_TO_WIN_A, program, real_path, PATH_MAX);
639 program = real_path;
640 #endif
641
642 OUTMSG2 (("Command line is \"%s %s\"\n", program, args));
643
644 #ifdef CREATE_NEW_PROCESS_GROUP
645 flags |= CREATE_NEW_PROCESS_GROUP;
646 #endif
647
648 ret = create_process (program, args, flags, &pi);
649 err = GetLastError ();
650 if (!ret && err == ERROR_FILE_NOT_FOUND)
651 {
652 char *exename = (char *) alloca (strlen (program) + 5);
653 strcat (strcpy (exename, program), ".exe");
654 ret = create_process (exename, args, flags, &pi);
655 err = GetLastError ();
656 }
657
658 #ifndef USE_WIN32API
659 if (orig_path)
660 setenv ("PATH", orig_path, 1);
661 #endif
662
663 if (!ret)
664 {
665 error ("Error creating process \"%s %s\", (error %d): %s\n",
666 program, args, (int) err, strwinerror (err));
667 }
668 else
669 {
670 OUTMSG2 (("Process created: %s %s\n", program, (char *) args));
671 }
672
673 CloseHandle (pi.hThread);
674
675 do_initial_child_stuff (pi.hProcess, pi.dwProcessId, 0);
676
677 /* Wait till we are at 1st instruction in program, return new pid
678 (assuming success). */
679 cs.last_ptid = wait (ptid_t (windows_process.id), &cs.last_status, 0);
680
681 /* Necessary for handle_v_kill. */
682 signal_pid = windows_process.id;
683
684 return windows_process.id;
685 }
686
687 /* Attach to a running process.
688 PID is the process ID to attach to, specified by the user
689 or a higher layer. */
690 int
691 win32_process_target::attach (unsigned long pid)
692 {
693 HANDLE h;
694 DWORD err;
695
696 h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
697 if (h != NULL)
698 {
699 if (DebugActiveProcess (pid))
700 {
701 DebugSetProcessKillOnExit (FALSE);
702
703 /* win32_wait needs to know we're attaching. */
704 attaching = 1;
705 do_initial_child_stuff (h, pid, 1);
706 return 0;
707 }
708
709 CloseHandle (h);
710 }
711
712 err = GetLastError ();
713 error ("Attach to process failed (error %d): %s\n",
714 (int) err, strwinerror (err));
715 }
716
717 /* See nat/windows-nat.h. */
718
719 int
720 windows_nat::windows_process_info::handle_output_debug_string
721 (struct target_waitstatus *ourstatus)
722 {
723 #define READ_BUFFER_LEN 1024
724 CORE_ADDR addr;
725 char s[READ_BUFFER_LEN + 1] = { 0 };
726 DWORD nbytes = current_event.u.DebugString.nDebugStringLength;
727
728 if (nbytes == 0)
729 return 0;
730
731 if (nbytes > READ_BUFFER_LEN)
732 nbytes = READ_BUFFER_LEN;
733
734 addr = (CORE_ADDR) (size_t) current_event.u.DebugString.lpDebugStringData;
735
736 if (current_event.u.DebugString.fUnicode)
737 {
738 /* The event tells us how many bytes, not chars, even
739 in Unicode. */
740 WCHAR buffer[(READ_BUFFER_LEN + 1) / sizeof (WCHAR)] = { 0 };
741 if (read_inferior_memory (addr, (unsigned char *) buffer, nbytes) != 0)
742 return 0;
743 wcstombs (s, buffer, (nbytes + 1) / sizeof (WCHAR));
744 }
745 else
746 {
747 if (read_inferior_memory (addr, (unsigned char *) s, nbytes) != 0)
748 return 0;
749 }
750
751 if (!startswith (s, "cYg"))
752 {
753 if (!server_waiting)
754 {
755 OUTMSG2(("%s", s));
756 return 0;
757 }
758
759 monitor_output (s);
760 }
761 #undef READ_BUFFER_LEN
762
763 return 0;
764 }
765
766 static void
767 win32_clear_inferiors (void)
768 {
769 if (open_process_used)
770 {
771 CloseHandle (windows_process.handle);
772 open_process_used = false;
773 }
774
775 for_each_thread (delete_thread_info);
776 windows_process.siginfo_er.ExceptionCode = 0;
777 clear_inferiors ();
778 }
779
780 /* Implementation of target_ops::kill. */
781
782 int
783 win32_process_target::kill (process_info *process)
784 {
785 TerminateProcess (windows_process.handle, 0);
786 for (;;)
787 {
788 if (!child_continue (DBG_CONTINUE, -1))
789 break;
790 if (!wait_for_debug_event (&windows_process.current_event, INFINITE))
791 break;
792 if (windows_process.current_event.dwDebugEventCode
793 == EXIT_PROCESS_DEBUG_EVENT)
794 break;
795 else if (windows_process.current_event.dwDebugEventCode
796 == OUTPUT_DEBUG_STRING_EVENT)
797 windows_process.handle_output_debug_string (nullptr);
798 }
799
800 win32_clear_inferiors ();
801
802 remove_process (process);
803 return 0;
804 }
805
806 /* Implementation of target_ops::detach. */
807
808 int
809 win32_process_target::detach (process_info *process)
810 {
811 struct thread_resume resume;
812 resume.thread = minus_one_ptid;
813 resume.kind = resume_continue;
814 resume.sig = 0;
815 this->resume (&resume, 1);
816
817 if (!DebugActiveProcessStop (windows_process.id))
818 return -1;
819
820 DebugSetProcessKillOnExit (FALSE);
821 remove_process (process);
822
823 win32_clear_inferiors ();
824 return 0;
825 }
826
827 void
828 win32_process_target::mourn (struct process_info *process)
829 {
830 remove_process (process);
831 }
832
833 /* Implementation of target_ops::join. */
834
835 void
836 win32_process_target::join (int pid)
837 {
838 HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
839 if (h != NULL)
840 {
841 WaitForSingleObject (h, INFINITE);
842 CloseHandle (h);
843 }
844 }
845
846 /* Return true iff the thread with thread ID TID is alive. */
847 bool
848 win32_process_target::thread_alive (ptid_t ptid)
849 {
850 /* Our thread list is reliable; don't bother to poll target
851 threads. */
852 return find_thread_ptid (ptid) != NULL;
853 }
854
855 /* Resume the inferior process. RESUME_INFO describes how we want
856 to resume. */
857 void
858 win32_process_target::resume (thread_resume *resume_info, size_t n)
859 {
860 DWORD tid;
861 enum gdb_signal sig;
862 int step;
863 windows_thread_info *th;
864 DWORD continue_status = DBG_CONTINUE;
865 ptid_t ptid;
866
867 /* This handles the very limited set of resume packets that GDB can
868 currently produce. */
869
870 if (n == 1 && resume_info[0].thread == minus_one_ptid)
871 tid = -1;
872 else if (n > 1)
873 tid = -1;
874 else
875 /* Yes, we're ignoring resume_info[0].thread. It'd be tricky to make
876 the Windows resume code do the right thing for thread switching. */
877 tid = windows_process.current_event.dwThreadId;
878
879 if (resume_info[0].thread != minus_one_ptid)
880 {
881 sig = gdb_signal_from_host (resume_info[0].sig);
882 step = resume_info[0].kind == resume_step;
883 }
884 else
885 {
886 sig = GDB_SIGNAL_0;
887 step = 0;
888 }
889
890 if (sig != GDB_SIGNAL_0)
891 {
892 if (windows_process.current_event.dwDebugEventCode
893 != EXCEPTION_DEBUG_EVENT)
894 {
895 OUTMSG (("Cannot continue with signal %s here.\n",
896 gdb_signal_to_string (sig)));
897 }
898 else if (sig == windows_process.last_sig)
899 continue_status = DBG_EXCEPTION_NOT_HANDLED;
900 else
901 OUTMSG (("Can only continue with received signal %s.\n",
902 gdb_signal_to_string (windows_process.last_sig)));
903 }
904
905 windows_process.last_sig = GDB_SIGNAL_0;
906
907 /* Get context for the currently selected thread. */
908 ptid = debug_event_ptid (&windows_process.current_event);
909 th = windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT);
910 if (th)
911 {
912 win32_prepare_to_resume (th);
913
914 DWORD *context_flags;
915 #ifdef __x86_64__
916 if (wow64_process)
917 context_flags = &th->wow64_context.ContextFlags;
918 else
919 #endif
920 context_flags = &th->context.ContextFlags;
921 if (*context_flags)
922 {
923 /* Move register values from the inferior into the thread
924 context structure. */
925 regcache_invalidate ();
926
927 if (step)
928 {
929 if (the_low_target.single_step != NULL)
930 (*the_low_target.single_step) (th);
931 else
932 error ("Single stepping is not supported "
933 "in this configuration.\n");
934 }
935
936 win32_set_thread_context (th);
937 *context_flags = 0;
938 }
939 }
940
941 /* Allow continuing with the same signal that interrupted us.
942 Otherwise complain. */
943
944 child_continue (continue_status, tid);
945 }
946
947 /* See nat/windows-nat.h. */
948
949 void
950 windows_nat::windows_process_info::handle_load_dll (const char *name,
951 LPVOID base)
952 {
953 CORE_ADDR load_addr = (CORE_ADDR) (uintptr_t) base;
954
955 char buf[MAX_PATH + 1];
956 char buf2[MAX_PATH + 1];
957
958 WIN32_FIND_DATAA w32_fd;
959 HANDLE h = FindFirstFileA (name, &w32_fd);
960
961 /* The symbols in a dll are offset by 0x1000, which is the
962 offset from 0 of the first byte in an image - because
963 of the file header and the section alignment. */
964 load_addr += 0x1000;
965
966 if (h == INVALID_HANDLE_VALUE)
967 strcpy (buf, name);
968 else
969 {
970 FindClose (h);
971 strcpy (buf, name);
972 {
973 char cwd[MAX_PATH + 1];
974 char *p;
975 if (GetCurrentDirectoryA (MAX_PATH + 1, cwd))
976 {
977 p = strrchr (buf, '\\');
978 if (p)
979 p[1] = '\0';
980 SetCurrentDirectoryA (buf);
981 GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p);
982 SetCurrentDirectoryA (cwd);
983 }
984 }
985 }
986
987 if (strcasecmp (buf, "ntdll.dll") == 0)
988 {
989 GetSystemDirectoryA (buf, sizeof (buf));
990 strcat (buf, "\\ntdll.dll");
991 }
992
993 #ifdef __CYGWIN__
994 cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2, sizeof (buf2));
995 #else
996 strcpy (buf2, buf);
997 #endif
998
999 loaded_dll (buf2, load_addr);
1000 }
1001
1002 /* See nat/windows-nat.h. */
1003
1004 void
1005 windows_nat::windows_process_info::handle_unload_dll ()
1006 {
1007 CORE_ADDR load_addr =
1008 (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll;
1009
1010 /* The symbols in a dll are offset by 0x1000, which is the
1011 offset from 0 of the first byte in an image - because
1012 of the file header and the section alignment. */
1013 load_addr += 0x1000;
1014 unloaded_dll (NULL, load_addr);
1015 }
1016
1017 static void
1018 suspend_one_thread (thread_info *thread)
1019 {
1020 windows_thread_info *th = (windows_thread_info *) thread_target_data (thread);
1021
1022 th->suspend ();
1023 }
1024
1025 static void
1026 fake_breakpoint_event (void)
1027 {
1028 OUTMSG2(("fake_breakpoint_event\n"));
1029
1030 faked_breakpoint = 1;
1031
1032 memset (&windows_process.current_event, 0,
1033 sizeof (windows_process.current_event));
1034 windows_process.current_event.dwThreadId = windows_process.main_thread_id;
1035 windows_process.current_event.dwDebugEventCode = EXCEPTION_DEBUG_EVENT;
1036 windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode
1037 = EXCEPTION_BREAKPOINT;
1038
1039 for_each_thread (suspend_one_thread);
1040 }
1041
1042 /* See nat/windows-nat.h. */
1043
1044 bool
1045 windows_nat::windows_process_info::handle_access_violation
1046 (const EXCEPTION_RECORD *rec)
1047 {
1048 return false;
1049 }
1050
1051 /* A helper function that will, if needed, set
1052 'stopped_at_software_breakpoint' on the thread and adjust the
1053 PC. */
1054
1055 static void
1056 maybe_adjust_pc ()
1057 {
1058 struct regcache *regcache = get_thread_regcache (current_thread, 1);
1059 child_fetch_inferior_registers (regcache, -1);
1060
1061 windows_thread_info *th
1062 = windows_process.thread_rec (current_thread_ptid (),
1063 DONT_INVALIDATE_CONTEXT);
1064 th->stopped_at_software_breakpoint = false;
1065
1066 if (windows_process.current_event.dwDebugEventCode == EXCEPTION_DEBUG_EVENT
1067 && ((windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode
1068 == EXCEPTION_BREAKPOINT)
1069 || (windows_process.current_event.u.Exception.ExceptionRecord.ExceptionCode
1070 == STATUS_WX86_BREAKPOINT))
1071 && child_initialization_done)
1072 {
1073 th->stopped_at_software_breakpoint = true;
1074 CORE_ADDR pc = regcache_read_pc (regcache);
1075 CORE_ADDR sw_breakpoint_pc = pc - the_low_target.decr_pc_after_break;
1076 regcache_write_pc (regcache, sw_breakpoint_pc);
1077 }
1078 }
1079
1080 /* Get the next event from the child. */
1081
1082 static int
1083 get_child_debug_event (DWORD *continue_status,
1084 struct target_waitstatus *ourstatus)
1085 {
1086 ptid_t ptid;
1087
1088 windows_process.last_sig = GDB_SIGNAL_0;
1089 ourstatus->set_spurious ();
1090 *continue_status = DBG_CONTINUE;
1091
1092 /* Check if GDB sent us an interrupt request. */
1093 check_remote_input_interrupt_request ();
1094
1095 DEBUG_EVENT *current_event = &windows_process.current_event;
1096
1097 if (soft_interrupt_requested)
1098 {
1099 soft_interrupt_requested = 0;
1100 fake_breakpoint_event ();
1101 goto gotevent;
1102 }
1103
1104 attaching = 0;
1105 {
1106 gdb::optional<pending_stop> stop
1107 = windows_process.fetch_pending_stop (debug_threads);
1108 if (stop.has_value ())
1109 {
1110 *ourstatus = stop->status;
1111 windows_process.current_event = stop->event;
1112 ptid = debug_event_ptid (&windows_process.current_event);
1113 switch_to_thread (find_thread_ptid (ptid));
1114 return 1;
1115 }
1116
1117 /* Keep the wait time low enough for comfortable remote
1118 interruption, but high enough so gdbserver doesn't become a
1119 bottleneck. */
1120 if (!wait_for_debug_event (&windows_process.current_event, 250))
1121 {
1122 DWORD e = GetLastError();
1123
1124 if (e == ERROR_PIPE_NOT_CONNECTED)
1125 {
1126 /* This will happen if the loader fails to succesfully
1127 load the application, e.g., if the main executable
1128 tries to pull in a non-existing export from a
1129 DLL. */
1130 ourstatus->set_exited (1);
1131 return 1;
1132 }
1133
1134 return 0;
1135 }
1136 }
1137
1138 gotevent:
1139
1140 switch (current_event->dwDebugEventCode)
1141 {
1142 case CREATE_THREAD_DEBUG_EVENT:
1143 OUTMSG2 (("gdbserver: kernel event CREATE_THREAD_DEBUG_EVENT "
1144 "for pid=%u tid=%x)\n",
1145 (unsigned) current_event->dwProcessId,
1146 (unsigned) current_event->dwThreadId));
1147
1148 /* Record the existence of this thread. */
1149 child_add_thread (current_event->dwProcessId,
1150 current_event->dwThreadId,
1151 current_event->u.CreateThread.hThread,
1152 current_event->u.CreateThread.lpThreadLocalBase);
1153 break;
1154
1155 case EXIT_THREAD_DEBUG_EVENT:
1156 OUTMSG2 (("gdbserver: kernel event EXIT_THREAD_DEBUG_EVENT "
1157 "for pid=%u tid=%x\n",
1158 (unsigned) current_event->dwProcessId,
1159 (unsigned) current_event->dwThreadId));
1160 child_delete_thread (current_event->dwProcessId,
1161 current_event->dwThreadId);
1162
1163 switch_to_thread (get_first_thread ());
1164 return 1;
1165
1166 case CREATE_PROCESS_DEBUG_EVENT:
1167 OUTMSG2 (("gdbserver: kernel event CREATE_PROCESS_DEBUG_EVENT "
1168 "for pid=%u tid=%x\n",
1169 (unsigned) current_event->dwProcessId,
1170 (unsigned) current_event->dwThreadId));
1171 CloseHandle (current_event->u.CreateProcessInfo.hFile);
1172
1173 if (open_process_used)
1174 {
1175 CloseHandle (windows_process.handle);
1176 open_process_used = false;
1177 }
1178
1179 windows_process.handle = current_event->u.CreateProcessInfo.hProcess;
1180 windows_process.main_thread_id = current_event->dwThreadId;
1181
1182 /* Add the main thread. */
1183 child_add_thread (current_event->dwProcessId,
1184 windows_process.main_thread_id,
1185 current_event->u.CreateProcessInfo.hThread,
1186 current_event->u.CreateProcessInfo.lpThreadLocalBase);
1187 break;
1188
1189 case EXIT_PROCESS_DEBUG_EVENT:
1190 OUTMSG2 (("gdbserver: kernel event EXIT_PROCESS_DEBUG_EVENT "
1191 "for pid=%u tid=%x\n",
1192 (unsigned) current_event->dwProcessId,
1193 (unsigned) current_event->dwThreadId));
1194 {
1195 DWORD exit_status = current_event->u.ExitProcess.dwExitCode;
1196 /* If the exit status looks like a fatal exception, but we
1197 don't recognize the exception's code, make the original
1198 exit status value available, to avoid losing information. */
1199 int exit_signal
1200 = WIFSIGNALED (exit_status) ? WTERMSIG (exit_status) : -1;
1201 if (exit_signal == -1)
1202 ourstatus->set_exited (exit_status);
1203 else
1204 ourstatus->set_signalled (gdb_signal_from_host (exit_signal));
1205 }
1206 child_continue (DBG_CONTINUE, windows_process.desired_stop_thread_id);
1207 break;
1208
1209 case LOAD_DLL_DEBUG_EVENT:
1210 OUTMSG2 (("gdbserver: kernel event LOAD_DLL_DEBUG_EVENT "
1211 "for pid=%u tid=%x\n",
1212 (unsigned) current_event->dwProcessId,
1213 (unsigned) current_event->dwThreadId));
1214 CloseHandle (current_event->u.LoadDll.hFile);
1215 if (! child_initialization_done)
1216 break;
1217 windows_process.dll_loaded_event ();
1218
1219 ourstatus->set_loaded ();
1220 break;
1221
1222 case UNLOAD_DLL_DEBUG_EVENT:
1223 OUTMSG2 (("gdbserver: kernel event UNLOAD_DLL_DEBUG_EVENT "
1224 "for pid=%u tid=%x\n",
1225 (unsigned) current_event->dwProcessId,
1226 (unsigned) current_event->dwThreadId));
1227 if (! child_initialization_done)
1228 break;
1229 windows_process.handle_unload_dll ();
1230 ourstatus->set_loaded ();
1231 break;
1232
1233 case EXCEPTION_DEBUG_EVENT:
1234 OUTMSG2 (("gdbserver: kernel event EXCEPTION_DEBUG_EVENT "
1235 "for pid=%u tid=%x\n",
1236 (unsigned) current_event->dwProcessId,
1237 (unsigned) current_event->dwThreadId));
1238 if (windows_process.handle_exception (ourstatus, debug_threads)
1239 == HANDLE_EXCEPTION_UNHANDLED)
1240 *continue_status = DBG_EXCEPTION_NOT_HANDLED;
1241 break;
1242
1243 case OUTPUT_DEBUG_STRING_EVENT:
1244 /* A message from the kernel (or Cygwin). */
1245 OUTMSG2 (("gdbserver: kernel event OUTPUT_DEBUG_STRING_EVENT "
1246 "for pid=%u tid=%x\n",
1247 (unsigned) current_event->dwProcessId,
1248 (unsigned) current_event->dwThreadId));
1249 windows_process.handle_output_debug_string (nullptr);
1250 break;
1251
1252 default:
1253 OUTMSG2 (("gdbserver: kernel event unknown "
1254 "for pid=%u tid=%x code=%x\n",
1255 (unsigned) current_event->dwProcessId,
1256 (unsigned) current_event->dwThreadId,
1257 (unsigned) current_event->dwDebugEventCode));
1258 break;
1259 }
1260
1261 ptid = debug_event_ptid (&windows_process.current_event);
1262
1263 if (windows_process.desired_stop_thread_id != -1
1264 && windows_process.desired_stop_thread_id != ptid.lwp ())
1265 {
1266 /* Pending stop. See the comment by the definition of
1267 "pending_stops" for details on why this is needed. */
1268 OUTMSG2 (("get_windows_debug_event - "
1269 "unexpected stop in 0x%lx (expecting 0x%x)\n",
1270 ptid.lwp (), windows_process.desired_stop_thread_id));
1271 maybe_adjust_pc ();
1272 windows_process.pending_stops.push_back
1273 ({(DWORD) ptid.lwp (), *ourstatus, *current_event});
1274 ourstatus->set_spurious ();
1275 }
1276 else
1277 switch_to_thread (find_thread_ptid (ptid));
1278
1279 return 1;
1280 }
1281
1282 /* Wait for the inferior process to change state.
1283 STATUS will be filled in with a response code to send to GDB.
1284 Returns the signal which caused the process to stop. */
1285 ptid_t
1286 win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus,
1287 target_wait_flags options)
1288 {
1289 if (cached_status.kind () != TARGET_WAITKIND_IGNORE)
1290 {
1291 /* The core always does a wait after creating the inferior, and
1292 do_initial_child_stuff already ran the inferior to the
1293 initial breakpoint (or an exit, if creating the process
1294 fails). Report it now. */
1295 *ourstatus = cached_status;
1296 cached_status.set_ignore ();
1297 return debug_event_ptid (&windows_process.current_event);
1298 }
1299
1300 while (1)
1301 {
1302 DWORD continue_status;
1303 if (!get_child_debug_event (&continue_status, ourstatus))
1304 continue;
1305
1306 switch (ourstatus->kind ())
1307 {
1308 case TARGET_WAITKIND_EXITED:
1309 OUTMSG2 (("Child exited with retcode = %x\n",
1310 ourstatus->exit_status ()));
1311 win32_clear_inferiors ();
1312 return ptid_t (windows_process.current_event.dwProcessId);
1313 case TARGET_WAITKIND_STOPPED:
1314 case TARGET_WAITKIND_SIGNALLED:
1315 case TARGET_WAITKIND_LOADED:
1316 {
1317 OUTMSG2 (("Child Stopped with signal = %d \n",
1318 ourstatus->sig ()));
1319 maybe_adjust_pc ();
1320 return debug_event_ptid (&windows_process.current_event);
1321 }
1322 default:
1323 OUTMSG (("Ignoring unknown internal event, %d\n",
1324 ourstatus->kind ()));
1325 /* fall-through */
1326 case TARGET_WAITKIND_SPURIOUS:
1327 /* do nothing, just continue */
1328 child_continue (continue_status,
1329 windows_process.desired_stop_thread_id);
1330 break;
1331 }
1332 }
1333 }
1334
1335 /* Fetch registers from the inferior process.
1336 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
1337 void
1338 win32_process_target::fetch_registers (regcache *regcache, int regno)
1339 {
1340 child_fetch_inferior_registers (regcache, regno);
1341 }
1342
1343 /* Store registers to the inferior process.
1344 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
1345 void
1346 win32_process_target::store_registers (regcache *regcache, int regno)
1347 {
1348 child_store_inferior_registers (regcache, regno);
1349 }
1350
1351 /* Read memory from the inferior process. This should generally be
1352 called through read_inferior_memory, which handles breakpoint shadowing.
1353 Read LEN bytes at MEMADDR into a buffer at MYADDR. */
1354 int
1355 win32_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
1356 int len)
1357 {
1358 return child_xfer_memory (memaddr, (char *) myaddr, len, 0, 0) != len;
1359 }
1360
1361 /* Write memory to the inferior process. This should generally be
1362 called through write_inferior_memory, which handles breakpoint shadowing.
1363 Write LEN bytes from the buffer at MYADDR to MEMADDR.
1364 Returns 0 on success and errno on failure. */
1365 int
1366 win32_process_target::write_memory (CORE_ADDR memaddr,
1367 const unsigned char *myaddr, int len)
1368 {
1369 return child_xfer_memory (memaddr, (char *) myaddr, len, 1, 0) != len;
1370 }
1371
1372 /* Send an interrupt request to the inferior process. */
1373 void
1374 win32_process_target::request_interrupt ()
1375 {
1376 if (GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, windows_process.id))
1377 return;
1378
1379 /* GenerateConsoleCtrlEvent can fail if process id being debugged is
1380 not a process group id.
1381 Fallback to XP/Vista 'DebugBreakProcess', which generates a
1382 breakpoint exception in the interior process. */
1383
1384 if (DebugBreakProcess (windows_process.handle))
1385 return;
1386
1387 /* Last resort, suspend all threads manually. */
1388 soft_interrupt_requested = 1;
1389 }
1390
1391 bool
1392 win32_process_target::supports_hardware_single_step ()
1393 {
1394 return true;
1395 }
1396
1397 bool
1398 win32_process_target::supports_qxfer_siginfo ()
1399 {
1400 return true;
1401 }
1402
1403 /* Write Windows signal info. */
1404
1405 int
1406 win32_process_target::qxfer_siginfo (const char *annex,
1407 unsigned char *readbuf,
1408 unsigned const char *writebuf,
1409 CORE_ADDR offset, int len)
1410 {
1411 if (windows_process.siginfo_er.ExceptionCode == 0)
1412 return -1;
1413
1414 if (readbuf == nullptr)
1415 return -1;
1416
1417 char *buf = (char *) &windows_process.siginfo_er;
1418 size_t bufsize = sizeof (windows_process.siginfo_er);
1419
1420 #ifdef __x86_64__
1421 EXCEPTION_RECORD32 er32;
1422 if (wow64_process)
1423 {
1424 buf = (char *) &er32;
1425 bufsize = sizeof (er32);
1426
1427 er32.ExceptionCode = siginfo_er.ExceptionCode;
1428 er32.ExceptionFlags = siginfo_er.ExceptionFlags;
1429 er32.ExceptionRecord = (uintptr_t) siginfo_er.ExceptionRecord;
1430 er32.ExceptionAddress = (uintptr_t) siginfo_er.ExceptionAddress;
1431 er32.NumberParameters = siginfo_er.NumberParameters;
1432 int i;
1433 for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
1434 er32.ExceptionInformation[i] = siginfo_er.ExceptionInformation[i];
1435 }
1436 #endif
1437
1438 if (offset > bufsize)
1439 return -1;
1440
1441 if (offset + len > bufsize)
1442 len = bufsize - offset;
1443
1444 memcpy (readbuf, buf + offset, len);
1445
1446 return len;
1447 }
1448
1449 bool
1450 win32_process_target::supports_get_tib_address ()
1451 {
1452 return true;
1453 }
1454
1455 /* Write Windows OS Thread Information Block address. */
1456
1457 int
1458 win32_process_target::get_tib_address (ptid_t ptid, CORE_ADDR *addr)
1459 {
1460 windows_thread_info *th;
1461 th = windows_process.thread_rec (ptid, DONT_INVALIDATE_CONTEXT);
1462 if (th == NULL)
1463 return 0;
1464 if (addr != NULL)
1465 *addr = th->thread_local_base;
1466 return 1;
1467 }
1468
1469 /* Implementation of the target_ops method "sw_breakpoint_from_kind". */
1470
1471 const gdb_byte *
1472 win32_process_target::sw_breakpoint_from_kind (int kind, int *size)
1473 {
1474 *size = the_low_target.breakpoint_len;
1475 return the_low_target.breakpoint;
1476 }
1477
1478 bool
1479 win32_process_target::stopped_by_sw_breakpoint ()
1480 {
1481 windows_thread_info *th
1482 = windows_process.thread_rec (current_thread_ptid (),
1483 DONT_INVALIDATE_CONTEXT);
1484 return th == nullptr ? false : th->stopped_at_software_breakpoint;
1485 }
1486
1487 bool
1488 win32_process_target::supports_stopped_by_sw_breakpoint ()
1489 {
1490 return true;
1491 }
1492
1493 CORE_ADDR
1494 win32_process_target::read_pc (struct regcache *regcache)
1495 {
1496 return (*the_low_target.get_pc) (regcache);
1497 }
1498
1499 void
1500 win32_process_target::write_pc (struct regcache *regcache, CORE_ADDR pc)
1501 {
1502 return (*the_low_target.set_pc) (regcache, pc);
1503 }
1504
1505 const char *
1506 win32_process_target::thread_name (ptid_t thread)
1507 {
1508 windows_thread_info *th
1509 = windows_process.thread_rec (current_thread_ptid (),
1510 DONT_INVALIDATE_CONTEXT);
1511 return th->thread_name ();
1512 }
1513
1514 /* The win32 target ops object. */
1515
1516 static win32_process_target the_win32_target;
1517
1518 /* Initialize the Win32 backend. */
1519 void
1520 initialize_low (void)
1521 {
1522 set_target_ops (&the_win32_target);
1523 the_low_target.arch_setup ();
1524
1525 initialize_loadable ();
1526 }