1 /* Target-vector operations for controlling Mac applications, for GDB.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Stan Shebs. 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. */
21 /* Note that because all the available Mac compilers are ANSI or very
22 close, and this is a native-only file, the code may be purely ANSI. */
25 #include "frame.h" /* required by inferior.h */
32 #include <sys/types.h>
35 #include "gdb_string.h"
36 #include "gdbthread.h"
39 #include <Processes.h>
41 /* We call the functions "child_..." rather than "mac_..." so no one
42 is tempted to try to link this with other native-only code. */
44 /* Forward declaration */
46 extern struct target_ops child_ops;
48 static void child_stop PARAMS ((void));
51 child_fetch_inferior_registers (int r)
55 for (r = 0; r < NUM_REGS; r++)
56 child_fetch_inferior_registers (r);
60 supply_register (r, 0);
65 child_store_inferior_registers (int r)
69 for (r = 0; r < NUM_REGS; r++)
70 child_store_inferior_registers (r);
74 read_register_gen (r, 0);
79 child_wait (int pid, struct target_waitstatus *ourstatus)
83 /* Attach to process PID, then initialize for debugging it. */
86 child_attach (args, from_tty)
90 ProcessSerialNumber psn;
91 ProcessInfoRec inforec;
99 error_no_arg ("process-id to attach");
103 psn.highLongOfPSN = 0;
104 psn.lowLongOfPSN = pid;
106 inforec.processInfoLength = sizeof(ProcessInfoRec);
107 inforec.processName = name;
108 inforec.processAppSpec = fsspec;
110 if (GetProcessInformation (&psn, &inforec) == noErr)
114 exec_file = (char *) get_exec_file (0);
117 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
118 target_pid_to_str (pid));
120 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
122 gdb_flush (gdb_stdout);
124 /* Do we need to do anything special? */
127 push_target (&child_ops);
132 child_detach (args, from_tty)
140 exec_file = get_exec_file (0);
143 printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
144 target_pid_to_str (inferior_pid));
145 gdb_flush (gdb_stdout);
148 unpush_target (&child_ops);
151 /* Print status information about what we're accessing. */
154 child_files_info (ignore)
155 struct target_ops *ignore;
157 printf_unfiltered ("\tUsing the running image of %s %s.\n",
158 attach_flag ? "attached" : "child", target_pid_to_str (inferior_pid));
163 child_open (arg, from_tty)
167 error ("Use the \"run\" command to start a Mac application.");
170 /* Start an inferior Mac program and sets inferior_pid to its pid.
171 EXEC_FILE is the file to run.
172 ALLARGS is a string containing the arguments to the program.
173 ENV is the environment vector to pass. Errors reported with error(). */
176 child_create_inferior (exec_file, allargs, env)
181 LaunchParamBlockRec launchparms;
187 error ("No executable specified, use `target exec'.\n");
190 launchparms.launchBlockID = extendedBlock;
191 launchparms.launchEPBLength = extendedBlockLen;
192 launchparms.launchFileFlags = 0;
193 launchparms.launchControlFlags = launchContinue | launchNoFileFlags;
196 strcpy(fsspec.name + 1, exec_file);
197 fsspec.name[0] = strlen(exec_file);
198 launchparms.launchAppSpec = &fsspec;
199 launchparms.launchAppParameters = nil;
201 launch_err = LaunchApplication (&launchparms);
203 if (launch_err == 999 /*memFullErr*/)
205 error ("Not enough memory to launch %s\n", exec_file);
207 else if (launch_err != noErr)
209 error ("Error launching %s, code %d\n", exec_file, launch_err);
212 inferior_pid = launchparms.launchProcessSN.lowLongOfPSN;
213 /* FIXME be sure that high long of PSN is 0 */
215 push_target (&child_ops);
216 init_wait_for_inferior ();
217 clear_proceed_status ();
219 /* proceed ((CORE_ADDR) - 1, TARGET_SIGNAL_0, 0); */
223 child_mourn_inferior ()
225 unpush_target (&child_ops);
226 generic_mourn_inferior ();
235 child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
236 int write, struct target_ops *target)
240 for (i = 0; i < len; ++i)
244 ((char *) memaddr)[i] = myaddr[i];
248 myaddr[i] = ((char *) memaddr)[i];
255 child_kill_inferior (void)
260 child_resume (int pid, int step, enum target_signal signal)
265 child_prepare_to_store ()
267 /* Do nothing, since we can store individual regs */
282 info_proc (args, from_tty)
286 ProcessSerialNumber psn;
287 ProcessInfoRec inforec;
292 /* Eventually use args, but not right now. */
294 psn.highLongOfPSN = 0;
295 psn.lowLongOfPSN = kNoProcess;
297 inforec.processInfoLength = sizeof(ProcessInfoRec);
298 inforec.processName = name;
299 inforec.processAppSpec = fsspec;
301 printf_filtered ("Process Name Sgnt Type PSN Loc Size FreeMem Time\n");
303 while (GetNextProcess (&psn) == noErr)
305 if (GetProcessInformation (&psn, &inforec) == noErr)
307 name[name[0] + 1] = '\0';
308 printf_filtered ("%-32.32s", name + 1);
309 code = inforec.processSignature;
310 printf_filtered (" %c%c%c%c",
315 code = inforec.processType;
316 printf_filtered (" %c%c%c%c",
321 if (psn.highLongOfPSN == 0)
322 printf_filtered (" %9d", psn.lowLongOfPSN);
324 printf_filtered (" %9d,%9d\n",
325 psn.highLongOfPSN, psn.lowLongOfPSN);
326 printf_filtered (" 0x%x", inforec.processLocation);
327 printf_filtered (" %9d", inforec.processSize);
328 printf_filtered (" %9d", inforec.processFreeMem);
329 printf_filtered (" %9d", inforec.processActiveTime);
330 printf_filtered ("\n");
335 struct target_ops child_ops =
337 "mac", /* to_shortname */
338 "MacOS application", /* to_longname */
339 "MacOS application (started by the \"run\" command).", /* to_doc */
340 child_open, /* to_open */
341 child_close, /* to_close */
342 child_attach, /* to_attach */
343 child_detach, /* to_detach */
344 child_resume, /* to_resume */
345 child_wait, /* to_wait */
346 child_fetch_inferior_registers,/* to_fetch_registers */
347 child_store_inferior_registers,/* to_store_registers */
348 child_prepare_to_store, /* to_prepare_to_store */
349 child_xfer_memory, /* to_xfer_memory */
350 child_files_info, /* to_files_info */
351 memory_insert_breakpoint, /* to_insert_breakpoint */
352 memory_remove_breakpoint, /* to_remove_breakpoint */
353 0, /* to_terminal_init */
354 0, /* to_terminal_inferior */
355 0, /* to_terminal_ours_for_output */
356 0, /* to_terminal_ours */
357 0, /* to_terminal_info */
358 child_kill_inferior, /* to_kill */
360 0, /* to_lookup_symbol */
361 child_create_inferior, /* to_create_inferior */
362 child_mourn_inferior, /* to_mourn_inferior */
363 child_can_run, /* to_can_run */
364 0, /* to_notice_signals */
365 0, /* to_thread_alive */
366 child_stop, /* to_stop */
367 process_stratum, /* to_stratum */
369 1, /* to_has_all_memory */
370 1, /* to_has_memory */
371 1, /* to_has_stack */
372 1, /* to_has_registers */
373 1, /* to_has_execution */
375 0, /* to_sections_end */
376 OPS_MAGIC /* to_magic */
380 _initialize_mac_nat ()
382 add_target (&child_ops);
384 add_info ("proc", info_proc,
385 "Show information about processes.");