server.c:gdb_read_memory: Fix error return.
[deliverable/binutils-gdb.git] / gdb / gdbserver / win32-low.c
CommitLineData
b80864fb 1/* Low level interface to Windows debugging, for gdbserver.
28e7fd62 2 Copyright (C) 2006-2013 Free Software Foundation, Inc.
b80864fb
DJ
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
b80864fb
DJ
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
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b80864fb
DJ
20
21#include "server.h"
22#include "regcache.h"
23#include "gdb/signals.h"
59a016f0 24#include "gdb/fileio.h"
ed50f18f
PA
25#include "mem-break.h"
26#include "win32-low.h"
623b6bdf 27#include "gdbthread.h"
b80864fb 28
a959a88d 29#include <stdint.h>
b80864fb 30#include <windows.h>
ed50f18f 31#include <winnt.h>
b80864fb 32#include <imagehlp.h>
255e7678 33#include <tlhelp32.h>
b80864fb 34#include <psapi.h>
b80864fb
DJ
35#include <process.h>
36
37#ifndef USE_WIN32API
38#include <sys/cygwin.h>
39#endif
40
10357975
PA
41#define OUTMSG(X) do { printf X; fflush (stderr); } while (0)
42
43#define OUTMSG2(X) \
44 do \
45 { \
46 if (debug_threads) \
47 { \
48 printf X; \
49 fflush (stderr); \
50 } \
51 } while (0)
ed50f18f
PA
52
53#ifndef _T
54#define _T(x) TEXT (x)
55#endif
56
57#ifndef COUNTOF
58#define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0]))
b80864fb
DJ
59#endif
60
bf914831
PA
61#ifdef _WIN32_WCE
62# define GETPROCADDRESS(DLL, PROC) \
63 ((winapi_ ## PROC) GetProcAddress (DLL, TEXT (#PROC)))
64#else
65# define GETPROCADDRESS(DLL, PROC) \
66 ((winapi_ ## PROC) GetProcAddress (DLL, #PROC))
67#endif
68
b80864fb
DJ
69int using_threads = 1;
70
71/* Globals. */
d97903b2 72static int attaching = 0;
b80864fb
DJ
73static HANDLE current_process_handle = NULL;
74static DWORD current_process_id = 0;
5ac588cf 75static DWORD main_thread_id = 0;
a493e3e2 76static enum gdb_signal last_sig = GDB_SIGNAL_0;
b80864fb
DJ
77
78/* The current debug event from WaitForDebugEvent. */
79static DEBUG_EVENT current_event;
80
4d5d1aaa
PA
81/* Non zero if an interrupt request is to be satisfied by suspending
82 all threads. */
83static int soft_interrupt_requested = 0;
84
85/* Non zero if the inferior is stopped in a simulated breakpoint done
86 by suspending all the threads. */
87static int faked_breakpoint = 0;
88
3aee8918
PA
89const struct target_desc *win32_tdesc;
90
ed50f18f 91#define NUM_REGS (the_low_target.num_regs)
b80864fb 92
7a9a7487
MG
93typedef BOOL (WINAPI *winapi_DebugActiveProcessStop) (DWORD dwProcessId);
94typedef BOOL (WINAPI *winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit);
95typedef BOOL (WINAPI *winapi_DebugBreakProcess) (HANDLE);
96typedef BOOL (WINAPI *winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD);
b80864fb 97
2bd7c093 98static void win32_resume (struct thread_resume *resume_info, size_t n);
34b34921 99
b80864fb
DJ
100/* Get the thread ID from the current selected inferior (the current
101 thread). */
95954743
PA
102static ptid_t
103current_inferior_ptid (void)
b80864fb 104{
95954743
PA
105 return ((struct inferior_list_entry*) current_inferior)->id;
106}
107
108/* The current debug event from WaitForDebugEvent. */
109static ptid_t
110debug_event_ptid (DEBUG_EVENT *event)
111{
112 return ptid_build (event->dwProcessId, event->dwThreadId, 0);
b80864fb
DJ
113}
114
9c6c8194
PA
115/* Get the thread context of the thread associated with TH. */
116
117static void
118win32_get_thread_context (win32_thread_info *th)
119{
120 memset (&th->context, 0, sizeof (CONTEXT));
121 (*the_low_target.get_thread_context) (th, &current_event);
122#ifdef _WIN32_WCE
123 memcpy (&th->base_context, &th->context, sizeof (CONTEXT));
124#endif
125}
126
127/* Set the thread context of the thread associated with TH. */
128
129static void
130win32_set_thread_context (win32_thread_info *th)
131{
132#ifdef _WIN32_WCE
133 /* Calling SuspendThread on a thread that is running kernel code
134 will report that the suspending was successful, but in fact, that
135 will often not be true. In those cases, the context returned by
136 GetThreadContext will not be correct by the time the thread
137 stops, hence we can't set that context back into the thread when
138 resuming - it will most likelly crash the inferior.
139 Unfortunately, there is no way to know when the thread will
140 really stop. To work around it, we'll only write the context
141 back to the thread when either the user or GDB explicitly change
142 it between stopping and resuming. */
143 if (memcmp (&th->context, &th->base_context, sizeof (CONTEXT)) != 0)
144#endif
145 (*the_low_target.set_thread_context) (th, &current_event);
146}
147
b80864fb
DJ
148/* Find a thread record given a thread id. If GET_CONTEXT is set then
149 also retrieve the context for this thread. */
41093d81 150static win32_thread_info *
95954743 151thread_rec (ptid_t ptid, int get_context)
b80864fb
DJ
152{
153 struct thread_info *thread;
41093d81 154 win32_thread_info *th;
b80864fb 155
95954743 156 thread = (struct thread_info *) find_inferior_id (&all_threads, ptid);
b80864fb
DJ
157 if (thread == NULL)
158 return NULL;
159
160 th = inferior_target_data (thread);
c436e841 161 if (get_context && th->context.ContextFlags == 0)
b80864fb 162 {
c436e841
PA
163 if (!th->suspended)
164 {
165 if (SuspendThread (th->h) == (DWORD) -1)
166 {
167 DWORD err = GetLastError ();
168 OUTMSG (("warning: SuspendThread failed in thread_rec, "
169 "(error %d): %s\n", (int) err, strwinerror (err)));
170 }
171 else
172 th->suspended = 1;
173 }
b80864fb 174
9c6c8194 175 win32_get_thread_context (th);
b80864fb
DJ
176 }
177
178 return th;
179}
180
181/* Add a thread to the thread list. */
41093d81 182static win32_thread_info *
711e434b 183child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
b80864fb 184{
41093d81 185 win32_thread_info *th;
95954743 186 ptid_t ptid = ptid_build (pid, tid, 0);
b80864fb 187
95954743 188 if ((th = thread_rec (ptid, FALSE)))
b80864fb
DJ
189 return th;
190
bca929d3 191 th = xcalloc (1, sizeof (*th));
b80864fb
DJ
192 th->tid = tid;
193 th->h = h;
711e434b 194 th->thread_local_base = (CORE_ADDR) (uintptr_t) tlb;
b80864fb 195
95954743 196 add_thread (ptid, th);
b80864fb 197
34b34921
PA
198 if (the_low_target.thread_added != NULL)
199 (*the_low_target.thread_added) (th);
b80864fb
DJ
200
201 return th;
202}
203
204/* Delete a thread from the list of threads. */
205static void
206delete_thread_info (struct inferior_list_entry *thread)
207{
41093d81 208 win32_thread_info *th = inferior_target_data ((struct thread_info *) thread);
b80864fb
DJ
209
210 remove_thread ((struct thread_info *) thread);
211 CloseHandle (th->h);
212 free (th);
213}
214
215/* Delete a thread from the list of threads. */
216static void
95954743 217child_delete_thread (DWORD pid, DWORD tid)
b80864fb
DJ
218{
219 struct inferior_list_entry *thread;
95954743 220 ptid_t ptid;
b80864fb
DJ
221
222 /* If the last thread is exiting, just return. */
223 if (all_threads.head == all_threads.tail)
224 return;
225
95954743
PA
226 ptid = ptid_build (pid, tid, 0);
227 thread = find_inferior_id (&all_threads, ptid);
b80864fb
DJ
228 if (thread == NULL)
229 return;
230
231 delete_thread_info (thread);
232}
233
aa5ca48f
DE
234/* These watchpoint related wrapper functions simply pass on the function call
235 if the low target has registered a corresponding function. */
236
237static int
238win32_insert_point (char type, CORE_ADDR addr, int len)
239{
240 if (the_low_target.insert_point != NULL)
241 return the_low_target.insert_point (type, addr, len);
242 else
243 /* Unsupported (see target.h). */
244 return 1;
245}
246
247static int
248win32_remove_point (char type, CORE_ADDR addr, int len)
249{
250 if (the_low_target.remove_point != NULL)
251 return the_low_target.remove_point (type, addr, len);
252 else
253 /* Unsupported (see target.h). */
254 return 1;
255}
256
257static int
258win32_stopped_by_watchpoint (void)
259{
260 if (the_low_target.stopped_by_watchpoint != NULL)
261 return the_low_target.stopped_by_watchpoint ();
262 else
263 return 0;
264}
265
266static CORE_ADDR
267win32_stopped_data_address (void)
268{
269 if (the_low_target.stopped_data_address != NULL)
270 return the_low_target.stopped_data_address ();
271 else
272 return 0;
273}
274
275
b80864fb
DJ
276/* Transfer memory from/to the debugged process. */
277static int
278child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
279 int write, struct target_ops *target)
280{
281 SIZE_T done;
e8f0053d 282 uintptr_t addr = (uintptr_t) memaddr;
b80864fb
DJ
283
284 if (write)
285 {
286 WriteProcessMemory (current_process_handle, (LPVOID) addr,
287 (LPCVOID) our, len, &done);
288 FlushInstructionCache (current_process_handle, (LPCVOID) addr, len);
289 }
290 else
291 {
292 ReadProcessMemory (current_process_handle, (LPCVOID) addr, (LPVOID) our,
293 len, &done);
294 }
295 return done;
296}
297
ed50f18f 298/* Clear out any old thread list and reinitialize it to a pristine
b80864fb
DJ
299 state. */
300static void
301child_init_thread_list (void)
302{
303 for_each_inferior (&all_threads, delete_thread_info);
304}
305
306static void
95954743 307do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
b80864fb 308{
3aee8918
PA
309 struct process_info *proc;
310
a493e3e2 311 last_sig = GDB_SIGNAL_0;
b80864fb 312
5ac588cf
PA
313 current_process_handle = proch;
314 current_process_id = pid;
315 main_thread_id = 0;
316
317 soft_interrupt_requested = 0;
318 faked_breakpoint = 0;
319
b80864fb
DJ
320 memset (&current_event, 0, sizeof (current_event));
321
3aee8918
PA
322 proc = add_process (pid, attached);
323 proc->tdesc = win32_tdesc;
b80864fb 324 child_init_thread_list ();
ed50f18f
PA
325
326 if (the_low_target.initial_stuff != NULL)
327 (*the_low_target.initial_stuff) ();
b80864fb
DJ
328}
329
330/* Resume all artificially suspended threads if we are continuing
331 execution. */
332static int
333continue_one_thread (struct inferior_list_entry *this_thread, void *id_ptr)
334{
335 struct thread_info *thread = (struct thread_info *) this_thread;
336 int thread_id = * (int *) id_ptr;
41093d81 337 win32_thread_info *th = inferior_target_data (thread);
b80864fb
DJ
338
339 if ((thread_id == -1 || thread_id == th->tid)
c436e841 340 && th->suspended)
b80864fb 341 {
34b34921 342 if (th->context.ContextFlags)
b80864fb 343 {
9c6c8194 344 win32_set_thread_context (th);
b80864fb
DJ
345 th->context.ContextFlags = 0;
346 }
34b34921 347
c436e841
PA
348 if (ResumeThread (th->h) == (DWORD) -1)
349 {
350 DWORD err = GetLastError ();
351 OUTMSG (("warning: ResumeThread failed in continue_one_thread, "
352 "(error %d): %s\n", (int) err, strwinerror (err)));
353 }
354 th->suspended = 0;
b80864fb
DJ
355 }
356
357 return 0;
358}
359
360static BOOL
361child_continue (DWORD continue_status, int thread_id)
362{
4d5d1aaa
PA
363 /* The inferior will only continue after the ContinueDebugEvent
364 call. */
365 find_inferior (&all_threads, continue_one_thread, &thread_id);
366 faked_breakpoint = 0;
b80864fb 367
4d5d1aaa
PA
368 if (!ContinueDebugEvent (current_event.dwProcessId,
369 current_event.dwThreadId,
370 continue_status))
371 return FALSE;
b80864fb 372
4d5d1aaa 373 return TRUE;
b80864fb
DJ
374}
375
b80864fb
DJ
376/* Fetch register(s) from the current thread context. */
377static void
442ea881 378child_fetch_inferior_registers (struct regcache *regcache, int r)
b80864fb
DJ
379{
380 int regno;
95954743 381 win32_thread_info *th = thread_rec (current_inferior_ptid (), TRUE);
4463ce24 382 if (r == -1 || r > NUM_REGS)
442ea881 383 child_fetch_inferior_registers (regcache, NUM_REGS);
b80864fb
DJ
384 else
385 for (regno = 0; regno < r; regno++)
442ea881 386 (*the_low_target.fetch_inferior_register) (regcache, th, regno);
b80864fb
DJ
387}
388
389/* Store a new register value into the current thread context. We don't
390 change the program's context until later, when we resume it. */
391static void
442ea881 392child_store_inferior_registers (struct regcache *regcache, int r)
b80864fb
DJ
393{
394 int regno;
95954743 395 win32_thread_info *th = thread_rec (current_inferior_ptid (), TRUE);
b80864fb 396 if (r == -1 || r == 0 || r > NUM_REGS)
442ea881 397 child_store_inferior_registers (regcache, NUM_REGS);
b80864fb
DJ
398 else
399 for (regno = 0; regno < r; regno++)
442ea881 400 (*the_low_target.store_inferior_register) (regcache, th, regno);
b80864fb
DJ
401}
402
ed50f18f
PA
403/* Map the Windows error number in ERROR to a locale-dependent error
404 message string and return a pointer to it. Typically, the values
405 for ERROR come from GetLastError.
406
407 The string pointed to shall not be modified by the application,
408 but may be overwritten by a subsequent call to strwinerror
409
410 The strwinerror function does not change the current setting
411 of GetLastError. */
412
413char *
414strwinerror (DWORD error)
415{
416 static char buf[1024];
417 TCHAR *msgbuf;
418 DWORD lasterr = GetLastError ();
419 DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
420 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
421 NULL,
422 error,
423 0, /* Default language */
424 (LPVOID)&msgbuf,
425 0,
426 NULL);
427 if (chars != 0)
428 {
429 /* If there is an \r\n appended, zap it. */
430 if (chars >= 2
431 && msgbuf[chars - 2] == '\r'
432 && msgbuf[chars - 1] == '\n')
433 {
434 chars -= 2;
435 msgbuf[chars] = 0;
436 }
437
438 if (chars > ((COUNTOF (buf)) - 1))
439 {
440 chars = COUNTOF (buf) - 1;
441 msgbuf [chars] = 0;
442 }
443
444#ifdef UNICODE
445 wcstombs (buf, msgbuf, chars + 1);
446#else
447 strncpy (buf, msgbuf, chars + 1);
448#endif
449 LocalFree (msgbuf);
450 }
451 else
dfe07582 452 sprintf (buf, "unknown win32 error (%u)", (unsigned) error);
ed50f18f
PA
453
454 SetLastError (lasterr);
455 return buf;
456}
457
aec18585
PA
458static BOOL
459create_process (const char *program, char *args,
460 DWORD flags, PROCESS_INFORMATION *pi)
461{
462 BOOL ret;
463
464#ifdef _WIN32_WCE
465 wchar_t *p, *wprogram, *wargs;
466 size_t argslen;
467
468 wprogram = alloca ((strlen (program) + 1) * sizeof (wchar_t));
469 mbstowcs (wprogram, program, strlen (program) + 1);
470
471 for (p = wprogram; *p; ++p)
472 if (L'/' == *p)
473 *p = L'\\';
474
475 argslen = strlen (args);
476 wargs = alloca ((argslen + 1) * sizeof (wchar_t));
477 mbstowcs (wargs, args, argslen + 1);
478
479 ret = CreateProcessW (wprogram, /* image name */
1b3f6016
PA
480 wargs, /* command line */
481 NULL, /* security, not supported */
482 NULL, /* thread, not supported */
483 FALSE, /* inherit handles, not supported */
484 flags, /* start flags */
485 NULL, /* environment, not supported */
486 NULL, /* current directory, not supported */
487 NULL, /* start info, not supported */
488 pi); /* proc info */
aec18585
PA
489#else
490 STARTUPINFOA si = { sizeof (STARTUPINFOA) };
491
492 ret = CreateProcessA (program, /* image name */
493 args, /* command line */
494 NULL, /* security */
495 NULL, /* thread */
496 TRUE, /* inherit handles */
497 flags, /* start flags */
498 NULL, /* environment */
499 NULL, /* current directory */
500 &si, /* start info */
501 pi); /* proc info */
502#endif
503
504 return ret;
505}
506
b80864fb
DJ
507/* Start a new process.
508 PROGRAM is a path to the program to execute.
509 ARGS is a standard NULL-terminated array of arguments,
510 to be passed to the inferior as ``argv''.
511 Returns the new PID on success, -1 on failure. Registers the new
512 process with the process list. */
513static int
514win32_create_inferior (char *program, char **program_args)
515{
516#ifndef USE_WIN32API
d8d2a3ee 517 char real_path[PATH_MAX];
b80864fb
DJ
518 char *orig_path, *new_path, *path_ptr;
519#endif
b80864fb
DJ
520 BOOL ret;
521 DWORD flags;
522 char *args;
523 int argslen;
524 int argc;
ed50f18f 525 PROCESS_INFORMATION pi;
aec18585 526 DWORD err;
b80864fb 527
d97903b2
PA
528 /* win32_wait needs to know we're not attaching. */
529 attaching = 0;
530
b80864fb
DJ
531 if (!program)
532 error ("No executable specified, specify executable to debug.\n");
533
b80864fb
DJ
534 flags = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
535
536#ifndef USE_WIN32API
537 orig_path = NULL;
538 path_ptr = getenv ("PATH");
539 if (path_ptr)
540 {
81239425 541 int size = cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, NULL, 0);
b80864fb 542 orig_path = alloca (strlen (path_ptr) + 1);
81239425 543 new_path = alloca (size);
b80864fb 544 strcpy (orig_path, path_ptr);
81239425 545 cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, path_ptr, new_path, size);
b80864fb 546 setenv ("PATH", new_path, 1);
81239425 547 }
d8d2a3ee 548 cygwin_conv_path (CCP_POSIX_TO_WIN_A, program, real_path, PATH_MAX);
b80864fb
DJ
549 program = real_path;
550#endif
551
ed50f18f 552 argslen = 1;
b80864fb
DJ
553 for (argc = 1; program_args[argc]; argc++)
554 argslen += strlen (program_args[argc]) + 1;
555 args = alloca (argslen);
ed50f18f 556 args[0] = '\0';
b80864fb
DJ
557 for (argc = 1; program_args[argc]; argc++)
558 {
559 /* FIXME: Can we do better about quoting? How does Cygwin
1b3f6016 560 handle this? */
b80864fb
DJ
561 strcat (args, " ");
562 strcat (args, program_args[argc]);
563 }
ed50f18f 564 OUTMSG2 (("Command line is \"%s\"\n", args));
b80864fb 565
ed50f18f 566#ifdef CREATE_NEW_PROCESS_GROUP
b80864fb 567 flags |= CREATE_NEW_PROCESS_GROUP;
ed50f18f 568#endif
b80864fb 569
aec18585
PA
570 ret = create_process (program, args, flags, &pi);
571 err = GetLastError ();
572 if (!ret && err == ERROR_FILE_NOT_FOUND)
573 {
574 char *exename = alloca (strlen (program) + 5);
575 strcat (strcpy (exename, program), ".exe");
576 ret = create_process (exename, args, flags, &pi);
577 err = GetLastError ();
578 }
b80864fb
DJ
579
580#ifndef USE_WIN32API
581 if (orig_path)
582 setenv ("PATH", orig_path, 1);
583#endif
584
585 if (!ret)
586 {
ed50f18f
PA
587 error ("Error creating process \"%s%s\", (error %d): %s\n",
588 program, args, (int) err, strwinerror (err));
b80864fb
DJ
589 }
590 else
591 {
592 OUTMSG2 (("Process created: %s\n", (char *) args));
593 }
594
ed50f18f
PA
595#ifndef _WIN32_WCE
596 /* On Windows CE this handle can't be closed. The OS reuses
597 it in the debug events, while the 9x/NT versions of Windows
598 probably use a DuplicateHandle'd one. */
b80864fb 599 CloseHandle (pi.hThread);
ed50f18f 600#endif
b80864fb 601
95954743 602 do_initial_child_stuff (pi.hProcess, pi.dwProcessId, 0);
b80864fb
DJ
603
604 return current_process_id;
605}
606
607/* Attach to a running process.
608 PID is the process ID to attach to, specified by the user
609 or a higher layer. */
610static int
611win32_attach (unsigned long pid)
612{
5ca906e6 613 HANDLE h;
bf914831 614 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
5ca906e6 615 DWORD err;
ed50f18f
PA
616#ifdef _WIN32_WCE
617 HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
618#else
619 HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
620#endif
bf914831 621 DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
b80864fb 622
5ca906e6
PA
623 h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
624 if (h != NULL)
1d5315fe 625 {
5ca906e6
PA
626 if (DebugActiveProcess (pid))
627 {
628 if (DebugSetProcessKillOnExit != NULL)
629 DebugSetProcessKillOnExit (FALSE);
630
d97903b2 631 /* win32_wait needs to know we're attaching. */
1b3f6016 632 attaching = 1;
95954743 633 do_initial_child_stuff (h, pid, 1);
5ca906e6
PA
634 return 0;
635 }
636
637 CloseHandle (h);
b80864fb
DJ
638 }
639
5ca906e6
PA
640 err = GetLastError ();
641 error ("Attach to process failed (error %d): %s\n",
642 (int) err, strwinerror (err));
b80864fb
DJ
643}
644
bce7165d
PA
645/* Handle OUTPUT_DEBUG_STRING_EVENT from child process. */
646static void
647handle_output_debug_string (struct target_waitstatus *ourstatus)
648{
649#define READ_BUFFER_LEN 1024
650 CORE_ADDR addr;
651 char s[READ_BUFFER_LEN + 1] = { 0 };
652 DWORD nbytes = current_event.u.DebugString.nDebugStringLength;
653
654 if (nbytes == 0)
655 return;
656
657 if (nbytes > READ_BUFFER_LEN)
658 nbytes = READ_BUFFER_LEN;
659
660 addr = (CORE_ADDR) (size_t) current_event.u.DebugString.lpDebugStringData;
661
662 if (current_event.u.DebugString.fUnicode)
663 {
664 /* The event tells us how many bytes, not chars, even
1b3f6016 665 in Unicode. */
bce7165d
PA
666 WCHAR buffer[(READ_BUFFER_LEN + 1) / sizeof (WCHAR)] = { 0 };
667 if (read_inferior_memory (addr, (unsigned char *) buffer, nbytes) != 0)
668 return;
669 wcstombs (s, buffer, (nbytes + 1) / sizeof (WCHAR));
670 }
671 else
672 {
673 if (read_inferior_memory (addr, (unsigned char *) s, nbytes) != 0)
674 return;
675 }
676
677 if (strncmp (s, "cYg", 3) != 0)
45e2715e
PA
678 {
679 if (!server_waiting)
680 {
681 OUTMSG2(("%s", s));
682 return;
683 }
684
685 monitor_output (s);
686 }
bce7165d
PA
687#undef READ_BUFFER_LEN
688}
689
5ac588cf
PA
690static void
691win32_clear_inferiors (void)
692{
693 if (current_process_handle != NULL)
694 CloseHandle (current_process_handle);
695
696 for_each_inferior (&all_threads, delete_thread_info);
697 clear_inferiors ();
698}
699
b80864fb 700/* Kill all inferiors. */
95954743
PA
701static int
702win32_kill (int pid)
b80864fb 703{
95954743
PA
704 struct process_info *process;
705
9d606399 706 if (current_process_handle == NULL)
95954743 707 return -1;
9d606399 708
b80864fb
DJ
709 TerminateProcess (current_process_handle, 0);
710 for (;;)
711 {
712 if (!child_continue (DBG_CONTINUE, -1))
713 break;
714 if (!WaitForDebugEvent (&current_event, INFINITE))
715 break;
716 if (current_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
717 break;
bce7165d
PA
718 else if (current_event.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)
719 {
1b3f6016 720 struct target_waitstatus our_status = { 0 };
bce7165d 721 handle_output_debug_string (&our_status);
1b3f6016 722 }
b80864fb 723 }
ed50f18f 724
5ac588cf 725 win32_clear_inferiors ();
95954743
PA
726
727 process = find_process_pid (pid);
728 remove_process (process);
729 return 0;
b80864fb
DJ
730}
731
95954743 732/* Detach from inferior PID. */
444d6139 733static int
95954743 734win32_detach (int pid)
b80864fb 735{
95954743 736 struct process_info *process;
bf914831
PA
737 winapi_DebugActiveProcessStop DebugActiveProcessStop = NULL;
738 winapi_DebugSetProcessKillOnExit DebugSetProcessKillOnExit = NULL;
ed50f18f
PA
739#ifdef _WIN32_WCE
740 HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
741#else
742 HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
743#endif
bf914831
PA
744 DebugActiveProcessStop = GETPROCADDRESS (dll, DebugActiveProcessStop);
745 DebugSetProcessKillOnExit = GETPROCADDRESS (dll, DebugSetProcessKillOnExit);
b80864fb 746
444d6139
PA
747 if (DebugSetProcessKillOnExit == NULL
748 || DebugActiveProcessStop == NULL)
749 return -1;
b80864fb 750
444d6139
PA
751 {
752 struct thread_resume resume;
95954743 753 resume.thread = minus_one_ptid;
bd99dc85 754 resume.kind = resume_continue;
444d6139 755 resume.sig = 0;
2bd7c093 756 win32_resume (&resume, 1);
444d6139
PA
757 }
758
759 if (!DebugActiveProcessStop (current_process_id))
5ac588cf
PA
760 return -1;
761
444d6139 762 DebugSetProcessKillOnExit (FALSE);
95954743
PA
763 process = find_process_pid (pid);
764 remove_process (process);
444d6139 765
5ac588cf 766 win32_clear_inferiors ();
444d6139
PA
767 return 0;
768}
769
505106cd
PA
770static void
771win32_mourn (struct process_info *process)
772{
773 remove_process (process);
774}
775
444d6139
PA
776/* Wait for inferiors to end. */
777static void
95954743 778win32_join (int pid)
444d6139 779{
95954743 780 HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
5ac588cf
PA
781 if (h != NULL)
782 {
783 WaitForSingleObject (h, INFINITE);
784 CloseHandle (h);
785 }
b80864fb
DJ
786}
787
788/* Return 1 iff the thread with thread ID TID is alive. */
789static int
95954743 790win32_thread_alive (ptid_t ptid)
b80864fb
DJ
791{
792 int res;
793
794 /* Our thread list is reliable; don't bother to poll target
795 threads. */
95954743 796 if (find_inferior_id (&all_threads, ptid) != NULL)
b80864fb
DJ
797 res = 1;
798 else
799 res = 0;
800 return res;
801}
802
803/* Resume the inferior process. RESUME_INFO describes how we want
804 to resume. */
805static void
2bd7c093 806win32_resume (struct thread_resume *resume_info, size_t n)
b80864fb
DJ
807{
808 DWORD tid;
2ea28649 809 enum gdb_signal sig;
b80864fb 810 int step;
41093d81 811 win32_thread_info *th;
b80864fb 812 DWORD continue_status = DBG_CONTINUE;
95954743 813 ptid_t ptid;
b80864fb
DJ
814
815 /* This handles the very limited set of resume packets that GDB can
816 currently produce. */
817
95954743 818 if (n == 1 && ptid_equal (resume_info[0].thread, minus_one_ptid))
b80864fb 819 tid = -1;
2bd7c093 820 else if (n > 1)
b80864fb
DJ
821 tid = -1;
822 else
823 /* Yes, we're ignoring resume_info[0].thread. It'd be tricky to make
824 the Windows resume code do the right thing for thread switching. */
825 tid = current_event.dwThreadId;
826
95954743 827 if (!ptid_equal (resume_info[0].thread, minus_one_ptid))
b80864fb
DJ
828 {
829 sig = resume_info[0].sig;
bd99dc85 830 step = resume_info[0].kind == resume_step;
b80864fb
DJ
831 }
832 else
833 {
834 sig = 0;
835 step = 0;
836 }
837
a493e3e2 838 if (sig != GDB_SIGNAL_0)
b80864fb
DJ
839 {
840 if (current_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
841 {
842 OUTMSG (("Cannot continue with signal %d here.\n", sig));
843 }
844 else if (sig == last_sig)
845 continue_status = DBG_EXCEPTION_NOT_HANDLED;
846 else
847 OUTMSG (("Can only continue with recieved signal %d.\n", last_sig));
848 }
849
a493e3e2 850 last_sig = GDB_SIGNAL_0;
b80864fb
DJ
851
852 /* Get context for the currently selected thread. */
95954743
PA
853 ptid = debug_event_ptid (&current_event);
854 th = thread_rec (ptid, FALSE);
b80864fb
DJ
855 if (th)
856 {
857 if (th->context.ContextFlags)
858 {
b80864fb
DJ
859 /* Move register values from the inferior into the thread
860 context structure. */
861 regcache_invalidate ();
862
863 if (step)
ed50f18f
PA
864 {
865 if (the_low_target.single_step != NULL)
866 (*the_low_target.single_step) (th);
867 else
868 error ("Single stepping is not supported "
869 "in this configuration.\n");
870 }
34b34921 871
9c6c8194 872 win32_set_thread_context (th);
b80864fb
DJ
873 th->context.ContextFlags = 0;
874 }
875 }
876
877 /* Allow continuing with the same signal that interrupted us.
878 Otherwise complain. */
879
880 child_continue (continue_status, tid);
881}
882
255e7678
DJ
883static void
884win32_add_one_solib (const char *name, CORE_ADDR load_addr)
885{
886 char buf[MAX_PATH + 1];
887 char buf2[MAX_PATH + 1];
888
889#ifdef _WIN32_WCE
890 WIN32_FIND_DATA w32_fd;
891 WCHAR wname[MAX_PATH + 1];
892 mbstowcs (wname, name, MAX_PATH);
893 HANDLE h = FindFirstFile (wname, &w32_fd);
894#else
895 WIN32_FIND_DATAA w32_fd;
896 HANDLE h = FindFirstFileA (name, &w32_fd);
897#endif
898
899 if (h == INVALID_HANDLE_VALUE)
900 strcpy (buf, name);
901 else
902 {
903 FindClose (h);
904 strcpy (buf, name);
905#ifndef _WIN32_WCE
906 {
907 char cwd[MAX_PATH + 1];
908 char *p;
909 if (GetCurrentDirectoryA (MAX_PATH + 1, cwd))
910 {
911 p = strrchr (buf, '\\');
912 if (p)
913 p[1] = '\0';
914 SetCurrentDirectoryA (buf);
915 GetFullPathNameA (w32_fd.cFileName, MAX_PATH, buf, &p);
916 SetCurrentDirectoryA (cwd);
917 }
918 }
919#endif
920 }
921
cf6e3471
PA
922#ifndef _WIN32_WCE
923 if (strcasecmp (buf, "ntdll.dll") == 0)
924 {
925 GetSystemDirectoryA (buf, sizeof (buf));
926 strcat (buf, "\\ntdll.dll");
927 }
928#endif
929
255e7678 930#ifdef __CYGWIN__
81239425 931 cygwin_conv_path (CCP_WIN_A_TO_POSIX, buf, buf2, sizeof (buf2));
255e7678
DJ
932#else
933 strcpy (buf2, buf);
934#endif
935
936 loaded_dll (buf2, load_addr);
937}
938
939static char *
940get_image_name (HANDLE h, void *address, int unicode)
941{
942 static char buf[(2 * MAX_PATH) + 1];
943 DWORD size = unicode ? sizeof (WCHAR) : sizeof (char);
944 char *address_ptr;
945 int len = 0;
946 char b[2];
e8f0053d 947 SIZE_T done;
255e7678
DJ
948
949 /* Attempt to read the name of the dll that was detected.
950 This is documented to work only when actively debugging
951 a program. It will not work for attached processes. */
952 if (address == NULL)
953 return NULL;
954
955#ifdef _WIN32_WCE
956 /* Windows CE reports the address of the image name,
957 instead of an address of a pointer into the image name. */
958 address_ptr = address;
959#else
960 /* See if we could read the address of a string, and that the
961 address isn't null. */
962 if (!ReadProcessMemory (h, address, &address_ptr,
963 sizeof (address_ptr), &done)
964 || done != sizeof (address_ptr)
965 || !address_ptr)
966 return NULL;
967#endif
968
969 /* Find the length of the string */
970 while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done)
971 && (b[0] != 0 || b[size - 1] != 0) && done == size)
972 continue;
973
974 if (!unicode)
975 ReadProcessMemory (h, address_ptr, buf, len, &done);
976 else
977 {
978 WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR));
979 ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR),
980 &done);
981
982 WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, len, 0, 0);
983 }
984
985 return buf;
986}
987
988typedef BOOL (WINAPI *winapi_EnumProcessModules) (HANDLE, HMODULE *,
989 DWORD, LPDWORD);
990typedef BOOL (WINAPI *winapi_GetModuleInformation) (HANDLE, HMODULE,
991 LPMODULEINFO, DWORD);
992typedef DWORD (WINAPI *winapi_GetModuleFileNameExA) (HANDLE, HMODULE,
993 LPSTR, DWORD);
994
995static winapi_EnumProcessModules win32_EnumProcessModules;
996static winapi_GetModuleInformation win32_GetModuleInformation;
997static winapi_GetModuleFileNameExA win32_GetModuleFileNameExA;
998
999static BOOL
1000load_psapi (void)
1001{
1002 static int psapi_loaded = 0;
1003 static HMODULE dll = NULL;
1004
1005 if (!psapi_loaded)
1006 {
1007 psapi_loaded = 1;
1008 dll = LoadLibrary (TEXT("psapi.dll"));
1009 if (!dll)
1010 return FALSE;
1011 win32_EnumProcessModules =
1012 GETPROCADDRESS (dll, EnumProcessModules);
1013 win32_GetModuleInformation =
1014 GETPROCADDRESS (dll, GetModuleInformation);
1015 win32_GetModuleFileNameExA =
1016 GETPROCADDRESS (dll, GetModuleFileNameExA);
1017 }
1018
1019 return (win32_EnumProcessModules != NULL
1020 && win32_GetModuleInformation != NULL
1021 && win32_GetModuleFileNameExA != NULL);
1022}
1023
1024static int
e8f0053d 1025psapi_get_dll_name (LPVOID BaseAddress, char *dll_name_ret)
255e7678
DJ
1026{
1027 DWORD len;
1028 MODULEINFO mi;
1029 size_t i;
1030 HMODULE dh_buf[1];
1031 HMODULE *DllHandle = dh_buf;
1032 DWORD cbNeeded;
1033 BOOL ok;
1034
1035 if (!load_psapi ())
1036 goto failed;
1037
1038 cbNeeded = 0;
1039 ok = (*win32_EnumProcessModules) (current_process_handle,
1040 DllHandle,
1041 sizeof (HMODULE),
1042 &cbNeeded);
1043
1044 if (!ok || !cbNeeded)
1045 goto failed;
1046
1047 DllHandle = (HMODULE *) alloca (cbNeeded);
1048 if (!DllHandle)
1049 goto failed;
1050
1051 ok = (*win32_EnumProcessModules) (current_process_handle,
1052 DllHandle,
1053 cbNeeded,
1054 &cbNeeded);
1055 if (!ok)
1056 goto failed;
1057
1058 for (i = 0; i < ((size_t) cbNeeded / sizeof (HMODULE)); i++)
1059 {
1060 if (!(*win32_GetModuleInformation) (current_process_handle,
1061 DllHandle[i],
1062 &mi,
1063 sizeof (mi)))
1064 {
1065 DWORD err = GetLastError ();
1066 error ("Can't get module info: (error %d): %s\n",
1067 (int) err, strwinerror (err));
1068 }
1069
e8f0053d 1070 if (mi.lpBaseOfDll == BaseAddress)
255e7678
DJ
1071 {
1072 len = (*win32_GetModuleFileNameExA) (current_process_handle,
1073 DllHandle[i],
1074 dll_name_ret,
1075 MAX_PATH);
1076 if (len == 0)
1077 {
1078 DWORD err = GetLastError ();
1079 error ("Error getting dll name: (error %d): %s\n",
1080 (int) err, strwinerror (err));
1081 }
1082 return 1;
1083 }
1084 }
1085
1086failed:
1087 dll_name_ret[0] = '\0';
1088 return 0;
1089}
1090
1091typedef HANDLE (WINAPI *winapi_CreateToolhelp32Snapshot) (DWORD, DWORD);
1092typedef BOOL (WINAPI *winapi_Module32First) (HANDLE, LPMODULEENTRY32);
1093typedef BOOL (WINAPI *winapi_Module32Next) (HANDLE, LPMODULEENTRY32);
1094
1095static winapi_CreateToolhelp32Snapshot win32_CreateToolhelp32Snapshot;
1096static winapi_Module32First win32_Module32First;
1097static winapi_Module32Next win32_Module32Next;
6b3d9b83
PA
1098#ifdef _WIN32_WCE
1099typedef BOOL (WINAPI *winapi_CloseToolhelp32Snapshot) (HANDLE);
1100static winapi_CloseToolhelp32Snapshot win32_CloseToolhelp32Snapshot;
1101#endif
255e7678
DJ
1102
1103static BOOL
1104load_toolhelp (void)
1105{
1106 static int toolhelp_loaded = 0;
1107 static HMODULE dll = NULL;
1108
1109 if (!toolhelp_loaded)
1110 {
1111 toolhelp_loaded = 1;
1112#ifndef _WIN32_WCE
1113 dll = GetModuleHandle (_T("KERNEL32.DLL"));
1114#else
6b3d9b83 1115 dll = LoadLibrary (L"TOOLHELP.DLL");
255e7678
DJ
1116#endif
1117 if (!dll)
1118 return FALSE;
1119
1120 win32_CreateToolhelp32Snapshot =
1121 GETPROCADDRESS (dll, CreateToolhelp32Snapshot);
1122 win32_Module32First = GETPROCADDRESS (dll, Module32First);
1123 win32_Module32Next = GETPROCADDRESS (dll, Module32Next);
6b3d9b83
PA
1124#ifdef _WIN32_WCE
1125 win32_CloseToolhelp32Snapshot =
1126 GETPROCADDRESS (dll, CloseToolhelp32Snapshot);
1127#endif
255e7678
DJ
1128 }
1129
1130 return (win32_CreateToolhelp32Snapshot != NULL
1131 && win32_Module32First != NULL
6b3d9b83
PA
1132 && win32_Module32Next != NULL
1133#ifdef _WIN32_WCE
1134 && win32_CloseToolhelp32Snapshot != NULL
1135#endif
1136 );
255e7678
DJ
1137}
1138
1139static int
e8f0053d 1140toolhelp_get_dll_name (LPVOID BaseAddress, char *dll_name_ret)
255e7678
DJ
1141{
1142 HANDLE snapshot_module;
1143 MODULEENTRY32 modEntry = { sizeof (MODULEENTRY32) };
6b3d9b83 1144 int found = 0;
255e7678
DJ
1145
1146 if (!load_toolhelp ())
1147 return 0;
1148
1149 snapshot_module = win32_CreateToolhelp32Snapshot (TH32CS_SNAPMODULE,
1150 current_event.dwProcessId);
1151 if (snapshot_module == INVALID_HANDLE_VALUE)
1152 return 0;
1153
1154 /* Ignore the first module, which is the exe. */
6b3d9b83
PA
1155 if (win32_Module32First (snapshot_module, &modEntry))
1156 while (win32_Module32Next (snapshot_module, &modEntry))
e8f0053d 1157 if (modEntry.modBaseAddr == BaseAddress)
6b3d9b83 1158 {
255e7678 1159#ifdef UNICODE
6b3d9b83 1160 wcstombs (dll_name_ret, modEntry.szExePath, MAX_PATH + 1);
255e7678 1161#else
6b3d9b83 1162 strcpy (dll_name_ret, modEntry.szExePath);
255e7678 1163#endif
6b3d9b83
PA
1164 found = 1;
1165 break;
1166 }
255e7678 1167
6b3d9b83
PA
1168#ifdef _WIN32_WCE
1169 win32_CloseToolhelp32Snapshot (snapshot_module);
1170#else
255e7678 1171 CloseHandle (snapshot_module);
6b3d9b83
PA
1172#endif
1173 return found;
255e7678
DJ
1174}
1175
1176static void
1177handle_load_dll (void)
1178{
1179 LOAD_DLL_DEBUG_INFO *event = &current_event.u.LoadDll;
1180 char dll_buf[MAX_PATH + 1];
1181 char *dll_name = NULL;
e8f0053d 1182 CORE_ADDR load_addr;
255e7678
DJ
1183
1184 dll_buf[0] = dll_buf[sizeof (dll_buf) - 1] = '\0';
1185
34d86ddd
PA
1186 /* Windows does not report the image name of the dlls in the debug
1187 event on attaches. We resort to iterating over the list of
1188 loaded dlls looking for a match by image base. */
e8f0053d 1189 if (!psapi_get_dll_name (event->lpBaseOfDll, dll_buf))
34d86ddd
PA
1190 {
1191 if (!server_waiting)
1192 /* On some versions of Windows and Windows CE, we can't create
1193 toolhelp snapshots while the inferior is stopped in a
1194 LOAD_DLL_DEBUG_EVENT due to a dll load, but we can while
1195 Windows is reporting the already loaded dlls. */
e8f0053d 1196 toolhelp_get_dll_name (event->lpBaseOfDll, dll_buf);
34d86ddd 1197 }
255e7678
DJ
1198
1199 dll_name = dll_buf;
1200
1201 if (*dll_name == '\0')
1202 dll_name = get_image_name (current_process_handle,
1203 event->lpImageName, event->fUnicode);
1204 if (!dll_name)
1205 return;
1206
1207 /* The symbols in a dll are offset by 0x1000, which is the
7a9dd1b2 1208 offset from 0 of the first byte in an image - because
255e7678
DJ
1209 of the file header and the section alignment. */
1210
e8f0053d 1211 load_addr = (CORE_ADDR) (uintptr_t) event->lpBaseOfDll + 0x1000;
255e7678
DJ
1212 win32_add_one_solib (dll_name, load_addr);
1213}
1214
1215static void
1216handle_unload_dll (void)
1217{
1218 CORE_ADDR load_addr =
e8f0053d 1219 (CORE_ADDR) (uintptr_t) current_event.u.UnloadDll.lpBaseOfDll;
255e7678
DJ
1220 load_addr += 0x1000;
1221 unloaded_dll (NULL, load_addr);
1222}
1223
34b34921 1224static void
b80864fb
DJ
1225handle_exception (struct target_waitstatus *ourstatus)
1226{
b80864fb
DJ
1227 DWORD code = current_event.u.Exception.ExceptionRecord.ExceptionCode;
1228
1229 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1230
b80864fb
DJ
1231 switch (code)
1232 {
1233 case EXCEPTION_ACCESS_VIOLATION:
1234 OUTMSG2 (("EXCEPTION_ACCESS_VIOLATION"));
a493e3e2 1235 ourstatus->value.sig = GDB_SIGNAL_SEGV;
b80864fb
DJ
1236 break;
1237 case STATUS_STACK_OVERFLOW:
1238 OUTMSG2 (("STATUS_STACK_OVERFLOW"));
a493e3e2 1239 ourstatus->value.sig = GDB_SIGNAL_SEGV;
b80864fb
DJ
1240 break;
1241 case STATUS_FLOAT_DENORMAL_OPERAND:
1242 OUTMSG2 (("STATUS_FLOAT_DENORMAL_OPERAND"));
a493e3e2 1243 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1244 break;
1245 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
1246 OUTMSG2 (("EXCEPTION_ARRAY_BOUNDS_EXCEEDED"));
a493e3e2 1247 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1248 break;
1249 case STATUS_FLOAT_INEXACT_RESULT:
1250 OUTMSG2 (("STATUS_FLOAT_INEXACT_RESULT"));
a493e3e2 1251 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1252 break;
1253 case STATUS_FLOAT_INVALID_OPERATION:
1254 OUTMSG2 (("STATUS_FLOAT_INVALID_OPERATION"));
a493e3e2 1255 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1256 break;
1257 case STATUS_FLOAT_OVERFLOW:
1258 OUTMSG2 (("STATUS_FLOAT_OVERFLOW"));
a493e3e2 1259 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1260 break;
1261 case STATUS_FLOAT_STACK_CHECK:
1262 OUTMSG2 (("STATUS_FLOAT_STACK_CHECK"));
a493e3e2 1263 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1264 break;
1265 case STATUS_FLOAT_UNDERFLOW:
1266 OUTMSG2 (("STATUS_FLOAT_UNDERFLOW"));
a493e3e2 1267 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1268 break;
1269 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1270 OUTMSG2 (("STATUS_FLOAT_DIVIDE_BY_ZERO"));
a493e3e2 1271 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1272 break;
1273 case STATUS_INTEGER_DIVIDE_BY_ZERO:
1274 OUTMSG2 (("STATUS_INTEGER_DIVIDE_BY_ZERO"));
a493e3e2 1275 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1276 break;
1277 case STATUS_INTEGER_OVERFLOW:
1278 OUTMSG2 (("STATUS_INTEGER_OVERFLOW"));
a493e3e2 1279 ourstatus->value.sig = GDB_SIGNAL_FPE;
b80864fb
DJ
1280 break;
1281 case EXCEPTION_BREAKPOINT:
1282 OUTMSG2 (("EXCEPTION_BREAKPOINT"));
a493e3e2 1283 ourstatus->value.sig = GDB_SIGNAL_TRAP;
ed50f18f
PA
1284#ifdef _WIN32_WCE
1285 /* Remove the initial breakpoint. */
1286 check_breakpoints ((CORE_ADDR) (long) current_event
1b3f6016 1287 .u.Exception.ExceptionRecord.ExceptionAddress);
ed50f18f 1288#endif
b80864fb
DJ
1289 break;
1290 case DBG_CONTROL_C:
1291 OUTMSG2 (("DBG_CONTROL_C"));
a493e3e2 1292 ourstatus->value.sig = GDB_SIGNAL_INT;
b80864fb
DJ
1293 break;
1294 case DBG_CONTROL_BREAK:
1295 OUTMSG2 (("DBG_CONTROL_BREAK"));
a493e3e2 1296 ourstatus->value.sig = GDB_SIGNAL_INT;
b80864fb
DJ
1297 break;
1298 case EXCEPTION_SINGLE_STEP:
1299 OUTMSG2 (("EXCEPTION_SINGLE_STEP"));
a493e3e2 1300 ourstatus->value.sig = GDB_SIGNAL_TRAP;
b80864fb
DJ
1301 break;
1302 case EXCEPTION_ILLEGAL_INSTRUCTION:
1303 OUTMSG2 (("EXCEPTION_ILLEGAL_INSTRUCTION"));
a493e3e2 1304 ourstatus->value.sig = GDB_SIGNAL_ILL;
b80864fb
DJ
1305 break;
1306 case EXCEPTION_PRIV_INSTRUCTION:
1307 OUTMSG2 (("EXCEPTION_PRIV_INSTRUCTION"));
a493e3e2 1308 ourstatus->value.sig = GDB_SIGNAL_ILL;
b80864fb
DJ
1309 break;
1310 case EXCEPTION_NONCONTINUABLE_EXCEPTION:
1311 OUTMSG2 (("EXCEPTION_NONCONTINUABLE_EXCEPTION"));
a493e3e2 1312 ourstatus->value.sig = GDB_SIGNAL_ILL;
b80864fb
DJ
1313 break;
1314 default:
1315 if (current_event.u.Exception.dwFirstChance)
34b34921
PA
1316 {
1317 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1318 return;
1319 }
dfe07582
CV
1320 OUTMSG2 (("gdbserver: unknown target exception 0x%08x at 0x%s",
1321 (unsigned) current_event.u.Exception.ExceptionRecord.ExceptionCode,
1322 phex_nz ((uintptr_t) current_event.u.Exception.ExceptionRecord.
1323 ExceptionAddress, sizeof (uintptr_t))));
a493e3e2 1324 ourstatus->value.sig = GDB_SIGNAL_UNKNOWN;
b80864fb
DJ
1325 break;
1326 }
1327 OUTMSG2 (("\n"));
1328 last_sig = ourstatus->value.sig;
b80864fb
DJ
1329}
1330
4d5d1aaa 1331
34b34921 1332static void
4d5d1aaa
PA
1333suspend_one_thread (struct inferior_list_entry *entry)
1334{
1335 struct thread_info *thread = (struct thread_info *) entry;
1336 win32_thread_info *th = inferior_target_data (thread);
1337
1338 if (!th->suspended)
1339 {
1340 if (SuspendThread (th->h) == (DWORD) -1)
1341 {
1342 DWORD err = GetLastError ();
1343 OUTMSG (("warning: SuspendThread failed in suspend_one_thread, "
1344 "(error %d): %s\n", (int) err, strwinerror (err)));
1345 }
1346 else
1347 th->suspended = 1;
1348 }
1349}
1350
1351static void
1352fake_breakpoint_event (void)
b80864fb 1353{
4d5d1aaa 1354 OUTMSG2(("fake_breakpoint_event\n"));
b80864fb 1355
4d5d1aaa
PA
1356 faked_breakpoint = 1;
1357
1358 memset (&current_event, 0, sizeof (current_event));
1359 current_event.dwThreadId = main_thread_id;
1360 current_event.dwDebugEventCode = EXCEPTION_DEBUG_EVENT;
1361 current_event.u.Exception.ExceptionRecord.ExceptionCode
1362 = EXCEPTION_BREAKPOINT;
1363
1364 for_each_inferior (&all_threads, suspend_one_thread);
1365}
1366
b65d95c5
DJ
1367#ifdef _WIN32_WCE
1368static int
1369auto_delete_breakpoint (CORE_ADDR stop_pc)
1370{
1371 return 1;
1372}
1373#endif
1374
4d5d1aaa
PA
1375/* Get the next event from the child. */
1376
1377static int
1378get_child_debug_event (struct target_waitstatus *ourstatus)
1379{
95954743
PA
1380 ptid_t ptid;
1381
a493e3e2 1382 last_sig = GDB_SIGNAL_0;
b80864fb
DJ
1383 ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
1384
4d5d1aaa
PA
1385 /* Check if GDB sent us an interrupt request. */
1386 check_remote_input_interrupt_request ();
1387
1388 if (soft_interrupt_requested)
1389 {
1390 soft_interrupt_requested = 0;
1391 fake_breakpoint_event ();
1392 goto gotevent;
1393 }
1394
d97903b2
PA
1395#ifndef _WIN32_WCE
1396 attaching = 0;
1397#else
1398 if (attaching)
1399 {
1400 /* WinCE doesn't set an initial breakpoint automatically. To
1b3f6016
PA
1401 stop the inferior, we flush all currently pending debug
1402 events -- the thread list and the dll list are always
1403 reported immediatelly without delay, then, we suspend all
1404 threads and pretend we saw a trap at the current PC of the
1405 main thread.
1406
1407 Contrary to desktop Windows, Windows CE *does* report the dll
1408 names on LOAD_DLL_DEBUG_EVENTs resulting from a
1409 DebugActiveProcess call. This limits the way we can detect
1410 if all the dlls have already been reported. If we get a real
1411 debug event before leaving attaching, the worst that will
1412 happen is the user will see a spurious breakpoint. */
d97903b2
PA
1413
1414 current_event.dwDebugEventCode = 0;
1415 if (!WaitForDebugEvent (&current_event, 0))
1b3f6016
PA
1416 {
1417 OUTMSG2(("no attach events left\n"));
1418 fake_breakpoint_event ();
1419 attaching = 0;
1420 }
d97903b2 1421 else
1b3f6016 1422 OUTMSG2(("got attach event\n"));
d97903b2
PA
1423 }
1424 else
1425#endif
1426 {
1427 /* Keep the wait time low enough for confortable remote
1b3f6016
PA
1428 interruption, but high enough so gdbserver doesn't become a
1429 bottleneck. */
d97903b2 1430 if (!WaitForDebugEvent (&current_event, 250))
912cf4ba
PA
1431 {
1432 DWORD e = GetLastError();
1433
1434 if (e == ERROR_PIPE_NOT_CONNECTED)
1435 {
1436 /* This will happen if the loader fails to succesfully
1437 load the application, e.g., if the main executable
1438 tries to pull in a non-existing export from a
1439 DLL. */
1440 ourstatus->kind = TARGET_WAITKIND_EXITED;
1441 ourstatus->value.integer = 1;
1442 return 1;
1443 }
1444
1445 return 0;
1446 }
d97903b2 1447 }
4d5d1aaa
PA
1448
1449 gotevent:
b80864fb 1450
34b34921 1451 switch (current_event.dwDebugEventCode)
b80864fb
DJ
1452 {
1453 case CREATE_THREAD_DEBUG_EVENT:
1454 OUTMSG2 (("gdbserver: kernel event CREATE_THREAD_DEBUG_EVENT "
dfe07582 1455 "for pid=%u tid=%x)\n",
b80864fb
DJ
1456 (unsigned) current_event.dwProcessId,
1457 (unsigned) current_event.dwThreadId));
1458
1459 /* Record the existence of this thread. */
95954743
PA
1460 child_add_thread (current_event.dwProcessId,
1461 current_event.dwThreadId,
711e434b
PM
1462 current_event.u.CreateThread.hThread,
1463 current_event.u.CreateThread.lpThreadLocalBase);
b80864fb
DJ
1464 break;
1465
1466 case EXIT_THREAD_DEBUG_EVENT:
1467 OUTMSG2 (("gdbserver: kernel event EXIT_THREAD_DEBUG_EVENT "
dfe07582 1468 "for pid=%u tid=%x\n",
b80864fb
DJ
1469 (unsigned) current_event.dwProcessId,
1470 (unsigned) current_event.dwThreadId));
95954743
PA
1471 child_delete_thread (current_event.dwProcessId,
1472 current_event.dwThreadId);
aeeb81d1
PA
1473
1474 current_inferior = (struct thread_info *) all_threads.head;
1475 return 1;
b80864fb
DJ
1476
1477 case CREATE_PROCESS_DEBUG_EVENT:
1478 OUTMSG2 (("gdbserver: kernel event CREATE_PROCESS_DEBUG_EVENT "
dfe07582 1479 "for pid=%u tid=%x\n",
b80864fb
DJ
1480 (unsigned) current_event.dwProcessId,
1481 (unsigned) current_event.dwThreadId));
1482 CloseHandle (current_event.u.CreateProcessInfo.hFile);
1483
1484 current_process_handle = current_event.u.CreateProcessInfo.hProcess;
1485 main_thread_id = current_event.dwThreadId;
1486
1487 ourstatus->kind = TARGET_WAITKIND_EXECD;
1488 ourstatus->value.execd_pathname = "Main executable";
1489
1490 /* Add the main thread. */
95954743
PA
1491 child_add_thread (current_event.dwProcessId,
1492 main_thread_id,
711e434b
PM
1493 current_event.u.CreateProcessInfo.hThread,
1494 current_event.u.CreateProcessInfo.lpThreadLocalBase);
b80864fb 1495
95954743 1496 ourstatus->value.related_pid = debug_event_ptid (&current_event);
ed50f18f 1497#ifdef _WIN32_WCE
d97903b2
PA
1498 if (!attaching)
1499 {
1500 /* Windows CE doesn't set the initial breakpoint
1501 automatically like the desktop versions of Windows do.
1502 We add it explicitly here. It will be removed as soon as
1503 it is hit. */
1504 set_breakpoint_at ((CORE_ADDR) (long) current_event.u
1505 .CreateProcessInfo.lpStartAddress,
b65d95c5 1506 auto_delete_breakpoint);
d97903b2 1507 }
ed50f18f 1508#endif
b80864fb
DJ
1509 break;
1510
1511 case EXIT_PROCESS_DEBUG_EVENT:
1512 OUTMSG2 (("gdbserver: kernel event EXIT_PROCESS_DEBUG_EVENT "
dfe07582 1513 "for pid=%u tid=%x\n",
b80864fb
DJ
1514 (unsigned) current_event.dwProcessId,
1515 (unsigned) current_event.dwThreadId));
1516 ourstatus->kind = TARGET_WAITKIND_EXITED;
1517 ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
18aae699 1518 child_continue (DBG_CONTINUE, -1);
b80864fb 1519 CloseHandle (current_process_handle);
9d606399 1520 current_process_handle = NULL;
b80864fb
DJ
1521 break;
1522
1523 case LOAD_DLL_DEBUG_EVENT:
1524 OUTMSG2 (("gdbserver: kernel event LOAD_DLL_DEBUG_EVENT "
dfe07582 1525 "for pid=%u tid=%x\n",
b80864fb
DJ
1526 (unsigned) current_event.dwProcessId,
1527 (unsigned) current_event.dwThreadId));
1528 CloseHandle (current_event.u.LoadDll.hFile);
255e7678 1529 handle_load_dll ();
b80864fb
DJ
1530
1531 ourstatus->kind = TARGET_WAITKIND_LOADED;
a493e3e2 1532 ourstatus->value.sig = GDB_SIGNAL_TRAP;
b80864fb
DJ
1533 break;
1534
1535 case UNLOAD_DLL_DEBUG_EVENT:
1536 OUTMSG2 (("gdbserver: kernel event UNLOAD_DLL_DEBUG_EVENT "
dfe07582 1537 "for pid=%u tid=%x\n",
b80864fb
DJ
1538 (unsigned) current_event.dwProcessId,
1539 (unsigned) current_event.dwThreadId));
255e7678
DJ
1540 handle_unload_dll ();
1541 ourstatus->kind = TARGET_WAITKIND_LOADED;
a493e3e2 1542 ourstatus->value.sig = GDB_SIGNAL_TRAP;
b80864fb
DJ
1543 break;
1544
1545 case EXCEPTION_DEBUG_EVENT:
1546 OUTMSG2 (("gdbserver: kernel event EXCEPTION_DEBUG_EVENT "
dfe07582 1547 "for pid=%u tid=%x\n",
b80864fb
DJ
1548 (unsigned) current_event.dwProcessId,
1549 (unsigned) current_event.dwThreadId));
34b34921 1550 handle_exception (ourstatus);
b80864fb
DJ
1551 break;
1552
1553 case OUTPUT_DEBUG_STRING_EVENT:
1554 /* A message from the kernel (or Cygwin). */
1555 OUTMSG2 (("gdbserver: kernel event OUTPUT_DEBUG_STRING_EVENT "
dfe07582 1556 "for pid=%u tid=%x\n",
b80864fb
DJ
1557 (unsigned) current_event.dwProcessId,
1558 (unsigned) current_event.dwThreadId));
bce7165d 1559 handle_output_debug_string (ourstatus);
b80864fb
DJ
1560 break;
1561
1562 default:
1563 OUTMSG2 (("gdbserver: kernel event unknown "
dfe07582 1564 "for pid=%u tid=%x code=%x\n",
b80864fb
DJ
1565 (unsigned) current_event.dwProcessId,
1566 (unsigned) current_event.dwThreadId,
dfe07582 1567 (unsigned) current_event.dwDebugEventCode));
b80864fb
DJ
1568 break;
1569 }
1570
aeeb81d1 1571 ptid = debug_event_ptid (&current_event);
b80864fb 1572 current_inferior =
95954743 1573 (struct thread_info *) find_inferior_id (&all_threads, ptid);
4d5d1aaa 1574 return 1;
b80864fb
DJ
1575}
1576
1577/* Wait for the inferior process to change state.
1578 STATUS will be filled in with a response code to send to GDB.
1579 Returns the signal which caused the process to stop. */
95954743
PA
1580static ptid_t
1581win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
b80864fb 1582{
442ea881 1583 struct regcache *regcache;
95954743 1584
b80864fb
DJ
1585 while (1)
1586 {
5b1c542e 1587 if (!get_child_debug_event (ourstatus))
4d5d1aaa 1588 continue;
b80864fb 1589
5b1c542e 1590 switch (ourstatus->kind)
b80864fb 1591 {
34b34921 1592 case TARGET_WAITKIND_EXITED:
b80864fb 1593 OUTMSG2 (("Child exited with retcode = %x\n",
5b1c542e 1594 ourstatus->value.integer));
5ac588cf 1595 win32_clear_inferiors ();
95954743 1596 return pid_to_ptid (current_event.dwProcessId);
34b34921 1597 case TARGET_WAITKIND_STOPPED:
1b3f6016 1598 case TARGET_WAITKIND_LOADED:
f72f3e60 1599 OUTMSG2 (("Child Stopped with signal = %d \n",
10357975 1600 ourstatus->value.sig));
b80864fb 1601
442ea881
PA
1602 regcache = get_thread_regcache (current_inferior, 1);
1603 child_fetch_inferior_registers (regcache, -1);
b80864fb 1604
5b1c542e 1605 if (ourstatus->kind == TARGET_WAITKIND_LOADED
255e7678
DJ
1606 && !server_waiting)
1607 {
1608 /* When gdb connects, we want to be stopped at the
1609 initial breakpoint, not in some dll load event. */
1610 child_continue (DBG_CONTINUE, -1);
1611 break;
1612 }
1613
5b1c542e
PA
1614 /* We don't expose _LOADED events to gdbserver core. See
1615 the `dlls_changed' global. */
1616 if (ourstatus->kind == TARGET_WAITKIND_LOADED)
1617 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1618
95954743 1619 return debug_event_ptid (&current_event);
1b3f6016 1620 default:
5b1c542e 1621 OUTMSG (("Ignoring unknown internal event, %d\n", ourstatus->kind));
1b3f6016
PA
1622 /* fall-through */
1623 case TARGET_WAITKIND_SPURIOUS:
1624 case TARGET_WAITKIND_EXECD:
34b34921
PA
1625 /* do nothing, just continue */
1626 child_continue (DBG_CONTINUE, -1);
1627 break;
b80864fb 1628 }
b80864fb
DJ
1629 }
1630}
1631
1632/* Fetch registers from the inferior process.
1633 If REGNO is -1, fetch all registers; otherwise, fetch at least REGNO. */
1634static void
442ea881 1635win32_fetch_inferior_registers (struct regcache *regcache, int regno)
b80864fb 1636{
442ea881 1637 child_fetch_inferior_registers (regcache, regno);
b80864fb
DJ
1638}
1639
1640/* Store registers to the inferior process.
1641 If REGNO is -1, store all registers; otherwise, store at least REGNO. */
1642static void
442ea881 1643win32_store_inferior_registers (struct regcache *regcache, int regno)
b80864fb 1644{
442ea881 1645 child_store_inferior_registers (regcache, regno);
b80864fb
DJ
1646}
1647
1648/* Read memory from the inferior process. This should generally be
1649 called through read_inferior_memory, which handles breakpoint shadowing.
1650 Read LEN bytes at MEMADDR into a buffer at MYADDR. */
1651static int
1652win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
1653{
ed50f18f 1654 return child_xfer_memory (memaddr, (char *) myaddr, len, 0, 0) != len;
b80864fb
DJ
1655}
1656
1657/* Write memory to the inferior process. This should generally be
1658 called through write_inferior_memory, which handles breakpoint shadowing.
1659 Write LEN bytes from the buffer at MYADDR to MEMADDR.
1660 Returns 0 on success and errno on failure. */
1661static int
1662win32_write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
1663 int len)
1664{
1665 return child_xfer_memory (memaddr, (char *) myaddr, len, 1, 0) != len;
1666}
1667
7390519e
PA
1668/* Send an interrupt request to the inferior process. */
1669static void
1670win32_request_interrupt (void)
1671{
1672 winapi_DebugBreakProcess DebugBreakProcess;
1673 winapi_GenerateConsoleCtrlEvent GenerateConsoleCtrlEvent;
1674
1675#ifdef _WIN32_WCE
1676 HMODULE dll = GetModuleHandle (_T("COREDLL.DLL"));
1677#else
1678 HMODULE dll = GetModuleHandle (_T("KERNEL32.DLL"));
1679#endif
1680
1681 GenerateConsoleCtrlEvent = GETPROCADDRESS (dll, GenerateConsoleCtrlEvent);
1682
1683 if (GenerateConsoleCtrlEvent != NULL
1684 && GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, current_process_id))
1685 return;
1686
1687 /* GenerateConsoleCtrlEvent can fail if process id being debugged is
1688 not a process group id.
1689 Fallback to XP/Vista 'DebugBreakProcess', which generates a
1690 breakpoint exception in the interior process. */
1691
1692 DebugBreakProcess = GETPROCADDRESS (dll, DebugBreakProcess);
1693
1694 if (DebugBreakProcess != NULL
1695 && DebugBreakProcess (current_process_handle))
1696 return;
1697
4d5d1aaa
PA
1698 /* Last resort, suspend all threads manually. */
1699 soft_interrupt_requested = 1;
7390519e
PA
1700}
1701
59a016f0
PA
1702#ifdef _WIN32_WCE
1703int
1704win32_error_to_fileio_error (DWORD err)
1705{
1706 switch (err)
1707 {
1708 case ERROR_BAD_PATHNAME:
1709 case ERROR_FILE_NOT_FOUND:
1710 case ERROR_INVALID_NAME:
1711 case ERROR_PATH_NOT_FOUND:
1712 return FILEIO_ENOENT;
1713 case ERROR_CRC:
1714 case ERROR_IO_DEVICE:
1715 case ERROR_OPEN_FAILED:
1716 return FILEIO_EIO;
1717 case ERROR_INVALID_HANDLE:
1718 return FILEIO_EBADF;
1719 case ERROR_ACCESS_DENIED:
1720 case ERROR_SHARING_VIOLATION:
1721 return FILEIO_EACCES;
1722 case ERROR_NOACCESS:
1723 return FILEIO_EFAULT;
1724 case ERROR_BUSY:
1725 return FILEIO_EBUSY;
1726 case ERROR_ALREADY_EXISTS:
1727 case ERROR_FILE_EXISTS:
1728 return FILEIO_EEXIST;
1729 case ERROR_BAD_DEVICE:
1730 return FILEIO_ENODEV;
1731 case ERROR_DIRECTORY:
1732 return FILEIO_ENOTDIR;
1733 case ERROR_FILENAME_EXCED_RANGE:
1734 case ERROR_INVALID_DATA:
1735 case ERROR_INVALID_PARAMETER:
1736 case ERROR_NEGATIVE_SEEK:
1737 return FILEIO_EINVAL;
1738 case ERROR_TOO_MANY_OPEN_FILES:
1739 return FILEIO_EMFILE;
1740 case ERROR_HANDLE_DISK_FULL:
1741 case ERROR_DISK_FULL:
1742 return FILEIO_ENOSPC;
1743 case ERROR_WRITE_PROTECT:
1744 return FILEIO_EROFS;
1745 case ERROR_NOT_SUPPORTED:
1746 return FILEIO_ENOSYS;
1747 }
1748
1749 return FILEIO_EUNKNOWN;
1750}
1751
1752static void
1753wince_hostio_last_error (char *buf)
1754{
1755 DWORD winerr = GetLastError ();
1756 int fileio_err = win32_error_to_fileio_error (winerr);
1757 sprintf (buf, "F-1,%x", fileio_err);
1758}
1759#endif
1760
711e434b
PM
1761/* Write Windows OS Thread Information Block address. */
1762
1763static int
1764win32_get_tib_address (ptid_t ptid, CORE_ADDR *addr)
1765{
1766 win32_thread_info *th;
1767 th = thread_rec (ptid, 0);
1768 if (th == NULL)
1769 return 0;
1770 if (addr != NULL)
1771 *addr = th->thread_local_base;
1772 return 1;
1773}
1774
b80864fb
DJ
1775static struct target_ops win32_target_ops = {
1776 win32_create_inferior,
1777 win32_attach,
1778 win32_kill,
1779 win32_detach,
505106cd 1780 win32_mourn,
444d6139 1781 win32_join,
b80864fb
DJ
1782 win32_thread_alive,
1783 win32_resume,
1784 win32_wait,
1785 win32_fetch_inferior_registers,
1786 win32_store_inferior_registers,
90d74c30 1787 NULL, /* prepare_to_access_memory */
0146f85b 1788 NULL, /* done_accessing_memory */
b80864fb
DJ
1789 win32_read_inferior_memory,
1790 win32_write_inferior_memory,
711e434b 1791 NULL, /* lookup_symbols */
7390519e 1792 win32_request_interrupt,
711e434b 1793 NULL, /* read_auxv */
aa5ca48f
DE
1794 win32_insert_point,
1795 win32_remove_point,
1796 win32_stopped_by_watchpoint,
1797 win32_stopped_data_address,
711e434b
PM
1798 NULL, /* read_offsets */
1799 NULL, /* get_tls_address */
1800 NULL, /* qxfer_spu */
59a016f0
PA
1801#ifdef _WIN32_WCE
1802 wince_hostio_last_error,
1803#else
1804 hostio_last_error_from_errno,
1805#endif
711e434b
PM
1806 NULL, /* qxfer_osdata */
1807 NULL, /* qxfer_siginfo */
1808 NULL, /* supports_non_stop */
1809 NULL, /* async */
1810 NULL, /* start_non_stop */
1811 NULL, /* supports_multi_process */
1812 NULL, /* handle_monitor_command */
1813 NULL, /* core_of_thread */
881127c9 1814 NULL, /* read_loadmap */
711e434b
PM
1815 NULL, /* process_qsupported */
1816 NULL, /* supports_tracepoints */
1817 NULL, /* read_pc */
1818 NULL, /* write_pc */
1819 NULL, /* thread_stopped */
7984d532 1820 win32_get_tib_address
b80864fb
DJ
1821};
1822
1823/* Initialize the Win32 backend. */
1824void
1825initialize_low (void)
1826{
1827 set_target_ops (&win32_target_ops);
ed50f18f
PA
1828 if (the_low_target.breakpoint != NULL)
1829 set_breakpoint_data (the_low_target.breakpoint,
1830 the_low_target.breakpoint_len);
d05b4ac3 1831 the_low_target.arch_setup ();
b80864fb 1832}
This page took 1.17095 seconds and 4 git commands to generate.