1 /* Target-vector operations for controlling win32 child processes, for GDB.
2 Copyright 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without eve nthe implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 /* We assume we're being built with and will be used for cygwin32. */
27 #include "frame.h" /* required by inferior.h */
34 #include <sys/types.h>
40 #else /* other WIN32 compiler */
47 #include "gdb_string.h"
48 #include "gdbthread.h"
50 #include <sys/param.h>
53 #define CHECK(x) check (x, __FILE__,__LINE__)
54 #define DEBUG_EXEC(x) if (debug_exec) printf x
55 #define DEBUG_EVENTS(x) if (debug_events) printf x
56 #define DEBUG_MEM(x) if (debug_memory) printf x
57 #define DEBUG_EXCEPT(x) if (debug_exceptions) printf x
59 /* Forward declaration */
60 extern struct target_ops child_ops;
62 static void child_stop PARAMS ((void));
64 /* The most recently read context. Inspect ContextFlags to see what
67 static CONTEXT context;
69 /* The process and thread handles for the above context. */
71 static HANDLE current_process;
72 static HANDLE current_thread;
73 static int current_process_id;
74 static int current_thread_id;
76 /* Counts of things. */
77 static int exception_count = 0;
78 static int event_count = 0;
81 static int new_console = 0;
82 static int new_group = 0;
83 static int debug_exec = 0; /* show execution */
84 static int debug_events = 0; /* show events from kernel */
85 static int debug_memory = 0; /* show target memory accesses */
86 static int debug_exceptions = 0; /* show target exceptions */
88 /* This vector maps GDB's idea of a register's number into an address
89 in the win32 exception context vector.
91 It also contains the bit mask needed to load the register in question.
93 One day we could read a reg, we could inspect the context we
94 already have loaded, if it doesn't have the bit set that we need,
95 we read that set of registers in using GetThreadContext. If the
96 context already contains what we need, we just unpack it. Then to
97 write a register, first we have to ensure that the context contains
98 the other regs of the group, and then we copy the info in and set
107 static const struct regmappings mappings[] =
110 {(char *) &context.Gpr0, CONTEXT_INTEGER},
111 {(char *) &context.Gpr1, CONTEXT_INTEGER},
112 {(char *) &context.Gpr2, CONTEXT_INTEGER},
113 {(char *) &context.Gpr3, CONTEXT_INTEGER},
114 {(char *) &context.Gpr4, CONTEXT_INTEGER},
115 {(char *) &context.Gpr5, CONTEXT_INTEGER},
116 {(char *) &context.Gpr6, CONTEXT_INTEGER},
117 {(char *) &context.Gpr7, CONTEXT_INTEGER},
119 {(char *) &context.Gpr8, CONTEXT_INTEGER},
120 {(char *) &context.Gpr9, CONTEXT_INTEGER},
121 {(char *) &context.Gpr10, CONTEXT_INTEGER},
122 {(char *) &context.Gpr11, CONTEXT_INTEGER},
123 {(char *) &context.Gpr12, CONTEXT_INTEGER},
124 {(char *) &context.Gpr13, CONTEXT_INTEGER},
125 {(char *) &context.Gpr14, CONTEXT_INTEGER},
126 {(char *) &context.Gpr15, CONTEXT_INTEGER},
128 {(char *) &context.Gpr16, CONTEXT_INTEGER},
129 {(char *) &context.Gpr17, CONTEXT_INTEGER},
130 {(char *) &context.Gpr18, CONTEXT_INTEGER},
131 {(char *) &context.Gpr19, CONTEXT_INTEGER},
132 {(char *) &context.Gpr20, CONTEXT_INTEGER},
133 {(char *) &context.Gpr21, CONTEXT_INTEGER},
134 {(char *) &context.Gpr22, CONTEXT_INTEGER},
135 {(char *) &context.Gpr23, CONTEXT_INTEGER},
137 {(char *) &context.Gpr24, CONTEXT_INTEGER},
138 {(char *) &context.Gpr25, CONTEXT_INTEGER},
139 {(char *) &context.Gpr26, CONTEXT_INTEGER},
140 {(char *) &context.Gpr27, CONTEXT_INTEGER},
141 {(char *) &context.Gpr28, CONTEXT_INTEGER},
142 {(char *) &context.Gpr29, CONTEXT_INTEGER},
143 {(char *) &context.Gpr30, CONTEXT_INTEGER},
144 {(char *) &context.Gpr31, CONTEXT_INTEGER},
146 {(char *) &context.Fpr0, CONTEXT_FLOATING_POINT},
147 {(char *) &context.Fpr1, CONTEXT_FLOATING_POINT},
148 {(char *) &context.Fpr2, CONTEXT_FLOATING_POINT},
149 {(char *) &context.Fpr3, CONTEXT_FLOATING_POINT},
150 {(char *) &context.Fpr4, CONTEXT_FLOATING_POINT},
151 {(char *) &context.Fpr5, CONTEXT_FLOATING_POINT},
152 {(char *) &context.Fpr6, CONTEXT_FLOATING_POINT},
153 {(char *) &context.Fpr7, CONTEXT_FLOATING_POINT},
155 {(char *) &context.Fpr8, CONTEXT_FLOATING_POINT},
156 {(char *) &context.Fpr9, CONTEXT_FLOATING_POINT},
157 {(char *) &context.Fpr10, CONTEXT_FLOATING_POINT},
158 {(char *) &context.Fpr11, CONTEXT_FLOATING_POINT},
159 {(char *) &context.Fpr12, CONTEXT_FLOATING_POINT},
160 {(char *) &context.Fpr13, CONTEXT_FLOATING_POINT},
161 {(char *) &context.Fpr14, CONTEXT_FLOATING_POINT},
162 {(char *) &context.Fpr15, CONTEXT_FLOATING_POINT},
164 {(char *) &context.Fpr16, CONTEXT_FLOATING_POINT},
165 {(char *) &context.Fpr17, CONTEXT_FLOATING_POINT},
166 {(char *) &context.Fpr18, CONTEXT_FLOATING_POINT},
167 {(char *) &context.Fpr19, CONTEXT_FLOATING_POINT},
168 {(char *) &context.Fpr20, CONTEXT_FLOATING_POINT},
169 {(char *) &context.Fpr21, CONTEXT_FLOATING_POINT},
170 {(char *) &context.Fpr22, CONTEXT_FLOATING_POINT},
171 {(char *) &context.Fpr23, CONTEXT_FLOATING_POINT},
173 {(char *) &context.Fpr24, CONTEXT_FLOATING_POINT},
174 {(char *) &context.Fpr25, CONTEXT_FLOATING_POINT},
175 {(char *) &context.Fpr26, CONTEXT_FLOATING_POINT},
176 {(char *) &context.Fpr27, CONTEXT_FLOATING_POINT},
177 {(char *) &context.Fpr28, CONTEXT_FLOATING_POINT},
178 {(char *) &context.Fpr29, CONTEXT_FLOATING_POINT},
179 {(char *) &context.Fpr30, CONTEXT_FLOATING_POINT},
180 {(char *) &context.Fpr31, CONTEXT_FLOATING_POINT},
182 {(char *) &context.Iar, CONTEXT_CONTROL},
183 {(char *) &context.Msr, CONTEXT_CONTROL},
184 {(char *) &context.Cr, CONTEXT_INTEGER},
185 {(char *) &context.Lr, CONTEXT_CONTROL},
186 {(char *) &context.Ctr, CONTEXT_CONTROL},
188 {(char *) &context.Xer, CONTEXT_INTEGER},
189 {0,0}, /* MQ, but there isn't one */
191 {(char *) &context.Eax, CONTEXT_INTEGER},
192 {(char *) &context.Ecx, CONTEXT_INTEGER},
193 {(char *) &context.Edx, CONTEXT_INTEGER},
194 {(char *) &context.Ebx, CONTEXT_INTEGER},
195 {(char *) &context.Esp, CONTEXT_CONTROL},
196 {(char *) &context.Ebp, CONTEXT_CONTROL},
197 {(char *) &context.Esi, CONTEXT_INTEGER},
198 {(char *) &context.Edi, CONTEXT_INTEGER},
199 {(char *) &context.Eip, CONTEXT_CONTROL},
200 {(char *) &context.EFlags, CONTEXT_CONTROL},
201 {(char *) &context.SegCs, CONTEXT_SEGMENTS},
202 {(char *) &context.SegSs, CONTEXT_SEGMENTS},
203 {(char *) &context.SegDs, CONTEXT_SEGMENTS},
204 {(char *) &context.SegEs, CONTEXT_SEGMENTS},
205 {(char *) &context.SegFs, CONTEXT_SEGMENTS},
206 {(char *) &context.SegGs, CONTEXT_SEGMENTS},
207 {&context.FloatSave.RegisterArea[0 * 10], CONTEXT_FLOATING_POINT},
208 {&context.FloatSave.RegisterArea[1 * 10], CONTEXT_FLOATING_POINT},
209 {&context.FloatSave.RegisterArea[2 * 10], CONTEXT_FLOATING_POINT},
210 {&context.FloatSave.RegisterArea[3 * 10], CONTEXT_FLOATING_POINT},
211 {&context.FloatSave.RegisterArea[4 * 10], CONTEXT_FLOATING_POINT},
212 {&context.FloatSave.RegisterArea[5 * 10], CONTEXT_FLOATING_POINT},
213 {&context.FloatSave.RegisterArea[6 * 10], CONTEXT_FLOATING_POINT},
214 {&context.FloatSave.RegisterArea[7 * 10], CONTEXT_FLOATING_POINT},
218 /* This vector maps the target's idea of an exception (extracted
219 from the DEBUG_EVENT structure) to GDB's idea. */
221 struct xlate_exception
224 enum target_signal us;
227 static const struct xlate_exception
230 {EXCEPTION_ACCESS_VIOLATION, TARGET_SIGNAL_SEGV},
231 {STATUS_STACK_OVERFLOW, TARGET_SIGNAL_SEGV},
232 {EXCEPTION_BREAKPOINT, TARGET_SIGNAL_TRAP},
233 {DBG_CONTROL_C, TARGET_SIGNAL_INT},
234 {EXCEPTION_SINGLE_STEP, TARGET_SIGNAL_TRAP},
238 check (BOOL ok, const char *file, int line)
241 printf_filtered ("error return %s:%d was %d\n", file, line, GetLastError ());
245 child_fetch_inferior_registers (int r)
249 for (r = 0; r < NUM_REGS; r++)
250 child_fetch_inferior_registers (r);
254 supply_register (r, mappings[r].incontext);
259 child_store_inferior_registers (int r)
263 for (r = 0; r < NUM_REGS; r++)
264 child_store_inferior_registers (r);
268 read_register_gen (r, mappings[r].incontext);
273 /* Wait for child to do something. Return pid of child, or -1 in case
274 of error; store status through argument pointer OURSTATUS. */
277 handle_load_dll (char *eventp)
279 DEBUG_EVENT * event = (DEBUG_EVENT *)eventp;
283 ReadProcessMemory (current_process,
284 (DWORD) event->u.LoadDll.lpImageName,
285 (char *) &dll_name_ptr,
286 sizeof (dll_name_ptr), &done);
288 /* See if we could read the address of a string, and that the
289 address isn't null. */
291 if (done == sizeof (dll_name_ptr) && dll_name_ptr)
293 char *dll_name, *dll_basename;
294 struct objfile *objfile;
295 char unix_dll_name[MAX_PATH];
296 int size = event->u.LoadDll.fUnicode ? sizeof (WCHAR) : sizeof (char);
301 ReadProcessMemory (current_process,
302 dll_name_ptr + len * size,
308 while ((b[0] != 0 || b[size - 1] != 0) && done == size);
310 dll_name = alloca (len);
312 if (event->u.LoadDll.fUnicode)
314 WCHAR *unicode_dll_name = (WCHAR *) alloca (len * sizeof (WCHAR));
315 ReadProcessMemory (current_process,
318 len * sizeof (WCHAR),
321 WideCharToMultiByte (CP_ACP, 0,
322 unicode_dll_name, len,
323 dll_name, len, 0, 0);
327 ReadProcessMemory (current_process,
334 /* FIXME: Can we delete this call? */
335 cygwin32_conv_to_posix_path (dll_name, unix_dll_name);
337 /* FIXME!! It would be nice to define one symbol which pointed to the
338 front of the dll if we can't find any symbols. */
340 if (!(dll_basename = strrchr(dll_name, '\\')))
341 dll_basename = strrchr(dll_name, '/');
343 ALL_OBJFILES(objfile)
345 char *objfile_basename;
346 if (!(objfile_basename = strrchr(objfile->name, '\\')))
347 objfile_basename = strrchr(objfile->name, '/');
349 if (dll_basename && objfile_basename &&
350 strcmp(dll_basename+1, objfile_basename+1) == 0)
352 printf_unfiltered ("%s (symbols previously loaded)\n",
358 context.ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT;
359 GetThreadContext (current_thread, &context);
361 /* The symbols in a dll are offset by 0x1000, which is the
362 the offset from 0 of the first byte in an image - because
363 of the file header and the section alignment.
365 FIXME: Is this the real reason that we need the 0x1000 ? */
368 symbol_file_add (unix_dll_name, 0,
369 (int) event->u.LoadDll.lpBaseOfDll + 0x1000, 0, 0, 0);
371 printf_unfiltered ("%x:%s\n", event->u.LoadDll.lpBaseOfDll,
379 handle_exception (DEBUG_EVENT * event, struct target_waitstatus *ourstatus)
383 ourstatus->kind = TARGET_WAITKIND_STOPPED;
386 switch (event->u.Exception.ExceptionRecord.ExceptionCode)
388 case EXCEPTION_ACCESS_VIOLATION:
389 DEBUG_EXCEPT (("gdb: Target exception ACCESS_VIOLATION at 0x%08x\n",
390 event->u.Exception.ExceptionRecord.ExceptionAddress));
391 ourstatus->value.sig = TARGET_SIGNAL_SEGV;
393 case STATUS_STACK_OVERFLOW:
394 DEBUG_EXCEPT (("gdb: Target exception STACK_OVERFLOW at 0x%08x\n",
395 event->u.Exception.ExceptionRecord.ExceptionAddress));
396 ourstatus->value.sig = TARGET_SIGNAL_SEGV;
398 case EXCEPTION_BREAKPOINT:
399 DEBUG_EXCEPT (("gdb: Target exception BREAKPOINT at 0x%08x\n",
400 event->u.Exception.ExceptionRecord.ExceptionAddress));
401 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
404 DEBUG_EXCEPT (("gdb: Target exception CONTROL_C at 0x%08x\n",
405 event->u.Exception.ExceptionRecord.ExceptionAddress));
406 ourstatus->value.sig = TARGET_SIGNAL_INT;
408 case EXCEPTION_SINGLE_STEP:
409 DEBUG_EXCEPT (("gdb: Target exception SINGLE_STEP at 0x%08x\n",
410 event->u.Exception.ExceptionRecord.ExceptionAddress));
411 ourstatus->value.sig = TARGET_SIGNAL_TRAP;
414 printf_unfiltered ("gdb: unknown target exception 0x%08x at 0x%08x\n",
415 event->u.Exception.ExceptionRecord.ExceptionCode,
416 event->u.Exception.ExceptionRecord.ExceptionAddress);
417 ourstatus->value.sig = TARGET_SIGNAL_UNKNOWN;
420 context.ContextFlags = CONTEXT_FULL | CONTEXT_FLOATING_POINT;
421 GetThreadContext (current_thread, &context);
426 child_wait (int pid, struct target_waitstatus *ourstatus)
428 /* We loop when we get a non-standard exception rather than return
429 with a SPURIOUS because resume can try and step or modify things,
430 which needs a current_thread. But some of these exceptions mark
431 the birth or death of threads, which mean that the current thread
432 isn't necessarily what you think it is. */
437 BOOL t = WaitForDebugEvent (&event, INFINITE);
442 current_thread_id = event.dwThreadId;
443 current_process_id = event.dwProcessId;
445 switch (event.dwDebugEventCode)
447 case CREATE_THREAD_DEBUG_EVENT:
448 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
449 event.dwProcessId, event.dwThreadId,
450 "CREATE_THREAD_DEBUG_EVENT"));
452 case EXIT_THREAD_DEBUG_EVENT:
453 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
454 event.dwProcessId, event.dwThreadId,
455 "EXIT_THREAD_DEBUG_EVENT"));
457 case CREATE_PROCESS_DEBUG_EVENT:
458 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
459 event.dwProcessId, event.dwThreadId,
460 "CREATE_PROCESS_DEBUG_EVENT"));
463 case EXIT_PROCESS_DEBUG_EVENT:
464 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
465 event.dwProcessId, event.dwThreadId,
466 "EXIT_PROCESS_DEBUG_EVENT"));
467 ourstatus->kind = TARGET_WAITKIND_EXITED;
468 ourstatus->value.integer = event.u.ExitProcess.dwExitCode;
469 CloseHandle (current_process);
470 CloseHandle (current_thread);
471 return current_process_id;
474 case LOAD_DLL_DEBUG_EVENT:
475 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
476 event.dwProcessId, event.dwThreadId,
477 "LOAD_DLL_DEBUG_EVENT"));
478 catch_errors (handle_load_dll,
480 "\n[failed reading symbols from DLL]\n",
482 registers_changed(); /* mark all regs invalid */
484 case UNLOAD_DLL_DEBUG_EVENT:
485 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
486 event.dwProcessId, event.dwThreadId,
487 "UNLOAD_DLL_DEBUG_EVENT"));
488 break; /* FIXME: don't know what to do here */
489 case EXCEPTION_DEBUG_EVENT:
490 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
491 event.dwProcessId, event.dwThreadId,
492 "EXCEPTION_DEBUG_EVENT"));
493 handle_exception (&event, ourstatus);
494 return current_process_id;
496 case OUTPUT_DEBUG_STRING_EVENT: /* message from the kernel */
497 DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
498 event.dwProcessId, event.dwThreadId,
499 "OUTPUT_DEBUG_STRING_EVENT"));
500 if (target_read_string
501 ((CORE_ADDR) event.u.DebugString.lpDebugStringData,
502 &p, 1024, 0) && p && *p)
509 printf_unfiltered ("gdb: kernel event for pid=%d tid=%d\n",
510 event.dwProcessId, event.dwThreadId);
511 printf_unfiltered (" unknown event code %d\n",
512 event.dwDebugEventCode);
515 DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=%d, DBG_CONTINUE);\n",
516 current_process_id, current_thread_id));
517 CHECK (ContinueDebugEvent (current_process_id,
523 /* Attach to process PID, then initialize for debugging it. */
526 child_attach (args, from_tty)
533 error_no_arg ("process-id to attach");
535 current_process_id = strtoul (args, 0, 0);
537 ok = DebugActiveProcess (current_process_id);
540 error ("Can't attach to process.");
547 char *exec_file = (char *) get_exec_file (0);
550 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
551 target_pid_to_str (current_process_id));
553 printf_unfiltered ("Attaching to %s\n",
554 target_pid_to_str (current_process_id));
556 gdb_flush (gdb_stdout);
559 inferior_pid = current_process_id;
560 push_target (&child_ops);
564 child_detach (args, from_tty)
570 char *exec_file = get_exec_file (0);
573 printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
574 target_pid_to_str (inferior_pid));
575 gdb_flush (gdb_stdout);
578 unpush_target (&child_ops);
581 /* Print status information about what we're accessing. */
584 child_files_info (ignore)
585 struct target_ops *ignore;
587 printf_unfiltered ("\tUsing the running image of %s %s.\n",
588 attach_flag ? "attached" : "child", target_pid_to_str (inferior_pid));
593 child_open (arg, from_tty)
597 error ("Use the \"run\" command to start a Unix child process.");
600 /* Start an inferior win32 child process and sets inferior_pid to its pid.
601 EXEC_FILE is the file to run.
602 ALLARGS is a string containing the arguments to the program.
603 ENV is the environment vector to pass. Errors reported with error(). */
606 child_create_inferior (exec_file, allargs, env)
611 char real_path[MAXPATHLEN];
618 PROCESS_INFORMATION pi;
619 struct target_waitstatus dummy;
626 error ("No executable specified, use `target exec'.\n");
629 memset (&si, 0, sizeof (si));
632 cygwin32_conv_to_win32_path (exec_file, real_path);
634 flags = DEBUG_ONLY_THIS_PROCESS;
637 flags |= CREATE_NEW_PROCESS_GROUP;
640 flags |= CREATE_NEW_CONSOLE;
642 args = alloca (strlen (real_path) + strlen (allargs) + 2);
644 strcpy (args, real_path);
647 strcat (args, allargs);
649 /* Prepare the environment vars for CreateProcess. */
651 /* This code use to assume all env vars were file names and would
652 translate them all to win32 style. That obviously doesn't work in the
653 general case. The current rule is that we only translate PATH.
654 We need to handle PATH because we're about to call CreateProcess and
655 it uses PATH to find DLL's. Fortunately PATH has a well-defined value
656 in both posix and win32 environments. cygwin.dll will change it back
657 to posix style if necessary. */
659 static const char *conv_path_names[] =
665 /* CreateProcess takes the environment list as a null terminated set of
666 strings (i.e. two nulls terminate the list). */
668 /* Get total size for env strings. */
669 for (envlen = 0, i = 0; env[i] && *env[i]; i++)
673 for (j = 0; conv_path_names[j]; j++)
675 len = strlen (conv_path_names[j]);
676 if (strncmp (conv_path_names[j], env[i], len) == 0)
678 if (cygwin32_posix_path_list_p (env[i] + len))
680 + cygwin32_posix_to_win32_path_list_buf_size (env[i] + len);
682 envlen += strlen (env[i]) + 1;
686 if (conv_path_names[j] == NULL)
687 envlen += strlen (env[i]) + 1;
690 winenv = alloca (envlen + 1);
692 /* Copy env strings into new buffer. */
693 for (temp = winenv, i = 0; env[i] && *env[i]; i++)
697 for (j = 0; conv_path_names[j]; j++)
699 len = strlen (conv_path_names[j]);
700 if (strncmp (conv_path_names[j], env[i], len) == 0)
702 if (cygwin32_posix_path_list_p (env[i] + len))
704 memcpy (temp, env[i], len);
705 cygwin32_posix_to_win32_path_list (env[i] + len, temp + len);
708 strcpy (temp, env[i]);
712 if (conv_path_names[j] == NULL)
713 strcpy (temp, env[i]);
715 temp += strlen (temp) + 1;
718 /* Final nil string to terminate new env. */
722 ret = CreateProcess (0,
723 args, /* command line */
726 TRUE, /* inherit handles */
727 flags, /* start flags */
729 NULL, /* current directory */
733 error ("Error creating process %s, (error %d)\n", exec_file, GetLastError());
738 inferior_pid = pi.dwProcessId;
739 current_process = pi.hProcess;
740 current_thread = pi.hThread;
741 current_process_id = pi.dwProcessId;
742 current_thread_id = pi.dwThreadId;
743 push_target (&child_ops);
745 init_wait_for_inferior ();
746 clear_proceed_status ();
747 target_terminal_init ();
748 target_terminal_inferior ();
750 /* Ignore the first trap */
751 child_wait (inferior_pid, &dummy);
753 proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_0, 0);
757 child_mourn_inferior ()
759 unpush_target (&child_ops);
760 generic_mourn_inferior ();
763 /* Send a SIGINT to the process group. This acts just like the user typed a
764 ^C on the controlling terminal. */
769 DEBUG_EVENTS (("gdb: GenerateConsoleCtrlEvent (CTRLC_EVENT, 0)\n"));
770 CHECK (GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0));
771 registers_changed(); /* refresh register state */
775 child_xfer_memory (CORE_ADDR memaddr, char *our, int len,
776 int write, struct target_ops *target)
781 DEBUG_MEM (("gdb: write target memory, %d bytes at 0x%08x\n",
783 WriteProcessMemory (current_process, memaddr, our, len, &done);
784 FlushInstructionCache (current_process, memaddr, len);
788 DEBUG_MEM (("gdb: read target memory, %d bytes at 0x%08x\n",
790 ReadProcessMemory (current_process, memaddr, our, len, &done);
796 child_kill_inferior (void)
798 CHECK (TerminateProcess (current_process, 0));
799 CHECK (CloseHandle (current_process));
800 CHECK (CloseHandle (current_thread));
801 target_mourn_inferior(); /* or just child_mourn_inferior? */
805 child_resume (int pid, int step, enum target_signal signal)
807 DEBUG_EXEC (("gdb: child_resume (pid=%d, step=%d, signal=%d);\n",
813 warning ("Single stepping not done.\n");
816 /* Single step by setting t bit */
817 child_fetch_inferior_registers (PS_REGNUM);
818 context.EFlags |= FLAG_TRACE_BIT;
822 if (context.ContextFlags)
824 CHECK (SetThreadContext (current_thread, &context));
825 context.ContextFlags = 0;
830 fprintf_unfiltered (gdb_stderr, "Can't send signals to the child.\n");
833 DEBUG_EVENTS (("gdb: ContinueDebugEvent (cpid=%d, ctid=%d, DBG_CONTINUE);\n",
834 current_process_id, current_thread_id));
835 CHECK (ContinueDebugEvent (current_process_id,
841 child_prepare_to_store ()
843 /* Do nothing, since we can store individual regs */
855 DEBUG_EVENTS (("gdb: child_close, inferior_pid=%d\n", inferior_pid));
858 struct target_ops child_ops =
860 "child", /* to_shortname */
861 "Win32 child process", /* to_longname */
862 "Win32 child process (started by the \"run\" command).", /* to_doc */
863 child_open, /* to_open */
864 child_close, /* to_close */
865 child_attach, /* to_attach */
866 child_detach, /* to_detach */
867 child_resume, /* to_resume */
868 child_wait, /* to_wait */
869 child_fetch_inferior_registers,/* to_fetch_registers */
870 child_store_inferior_registers,/* to_store_registers */
871 child_prepare_to_store, /* to_child_prepare_to_store */
872 child_xfer_memory, /* to_xfer_memory */
873 child_files_info, /* to_files_info */
874 memory_insert_breakpoint, /* to_insert_breakpoint */
875 memory_remove_breakpoint, /* to_remove_breakpoint */
876 terminal_init_inferior, /* to_terminal_init */
877 terminal_inferior, /* to_terminal_inferior */
878 terminal_ours_for_output, /* to_terminal_ours_for_output */
879 terminal_ours, /* to_terminal_ours */
880 child_terminal_info, /* to_terminal_info */
881 child_kill_inferior, /* to_kill */
883 0, /* to_lookup_symbol */
884 child_create_inferior, /* to_create_inferior */
885 child_mourn_inferior, /* to_mourn_inferior */
886 child_can_run, /* to_can_run */
887 0, /* to_notice_signals */
888 0, /* to_thread_alive */
889 child_stop, /* to_stop */
890 process_stratum, /* to_stratum */
892 1, /* to_has_all_memory */
893 1, /* to_has_memory */
894 1, /* to_has_stack */
895 1, /* to_has_registers */
896 1, /* to_has_execution */
898 0, /* to_sections_end */
899 OPS_MAGIC /* to_magic */
903 _initialize_inftarg ()
905 struct cmd_list_element *c;
908 (add_set_cmd ("new-console", class_support, var_boolean,
909 (char *) &new_console,
910 "Set creation of new console when creating child process.",
915 (add_set_cmd ("new-group", class_support, var_boolean,
917 "Set creation of new group when creating child process.",
922 (add_set_cmd ("debugexec", class_support, var_boolean,
923 (char *) &debug_exec,
924 "Set whether to display execution in child process.",
929 (add_set_cmd ("debugevents", class_support, var_boolean,
930 (char *) &debug_events,
931 "Set whether to display kernel events in child process.",
936 (add_set_cmd ("debugmemory", class_support, var_boolean,
937 (char *) &debug_memory,
938 "Set whether to display memory accesses in child process.",
943 (add_set_cmd ("debugexceptions", class_support, var_boolean,
944 (char *) &debug_exceptions,
945 "Set whether to display kernel exceptions in child process.",
949 add_target (&child_ops);