Fix the year on the following lines:
[deliverable/binutils-gdb.git] / gdb / mac-nat.c
CommitLineData
c906108c
SS
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.
4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b
JM
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,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22/* Note that because all the available Mac compilers are ANSI or very
23 close, and this is a native-only file, the code may be purely ANSI. */
24
25#include "defs.h"
26#include "frame.h" /* required by inferior.h */
27#include "inferior.h"
28#include "target.h"
03f2053f 29#include "gdb_wait.h"
c906108c
SS
30#include "gdbcore.h"
31#include "command.h"
32#include <signal.h>
33#include <sys/types.h>
34#include <fcntl.h>
35#include "buildsym.h"
36#include "gdb_string.h"
37#include "gdbthread.h"
38#include "gdbcmd.h"
39
40#include <Processes.h>
41
42/* We call the functions "child_..." rather than "mac_..." so no one
43 is tempted to try to link this with other native-only code. */
44
45/* Forward declaration */
46
47extern struct target_ops child_ops;
48
a14ed312 49static void child_stop (void);
c906108c
SS
50
51static void
52child_fetch_inferior_registers (int r)
53{
54 if (r < 0)
55 {
56 for (r = 0; r < NUM_REGS; r++)
57 child_fetch_inferior_registers (r);
58 }
59 else
60 {
61 supply_register (r, 0);
62 }
63}
64
65static void
66child_store_inferior_registers (int r)
67{
68 if (r < 0)
69 {
70 for (r = 0; r < NUM_REGS; r++)
71 child_store_inferior_registers (r);
72 }
73 else
74 {
75 read_register_gen (r, 0);
76 }
77}
78
79static int
80child_wait (int pid, struct target_waitstatus *ourstatus)
81{
82}
83
84/* Attach to process PID, then initialize for debugging it. */
85
86static void
fba45db2 87child_attach (char *args, int from_tty)
c906108c
SS
88{
89 ProcessSerialNumber psn;
90 ProcessInfoRec inforec;
91 Str31 name;
92 FSSpecPtr fsspec;
93 OSType code;
94 int pid;
95 char *exec_file;
96
97 if (!args)
98 error_no_arg ("process-id to attach");
99
100 pid = atoi (args);
101
102 psn.highLongOfPSN = 0;
103 psn.lowLongOfPSN = pid;
104
c5aa993b 105 inforec.processInfoLength = sizeof (ProcessInfoRec);
c906108c
SS
106 inforec.processName = name;
107 inforec.processAppSpec = fsspec;
108
109 if (GetProcessInformation (&psn, &inforec) == noErr)
110 {
111 if (from_tty)
112 {
113 exec_file = (char *) get_exec_file (0);
114
115 if (exec_file)
116 printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
117 target_pid_to_str (pid));
118 else
119 printf_unfiltered ("Attaching to %s\n", target_pid_to_str (pid));
120
121 gdb_flush (gdb_stdout);
122 }
123 /* Do we need to do anything special? */
124 attach_flag = 1;
125 inferior_pid = pid;
126 push_target (&child_ops);
127 }
128}
129
130static void
fba45db2 131child_detach (char *args, int from_tty)
c906108c
SS
132{
133 char *exec_file;
134
135 if (from_tty)
136 {
137 exec_file = get_exec_file (0);
138 if (exec_file == 0)
139 exec_file = "";
140 printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
141 target_pid_to_str (inferior_pid));
142 gdb_flush (gdb_stdout);
143 }
144 inferior_pid = 0;
145 unpush_target (&child_ops);
146}
147
148/* Print status information about what we're accessing. */
149
150static void
fba45db2 151child_files_info (struct target_ops *ignore)
c906108c
SS
152{
153 printf_unfiltered ("\tUsing the running image of %s %s.\n",
154 attach_flag ? "attached" : "child", target_pid_to_str (inferior_pid));
155}
156
157/* ARGSUSED */
158static void
fba45db2 159child_open (char *arg, int from_tty)
c906108c
SS
160{
161 error ("Use the \"run\" command to start a Mac application.");
162}
163
164/* Start an inferior Mac program and sets inferior_pid to its pid.
165 EXEC_FILE is the file to run.
166 ALLARGS is a string containing the arguments to the program.
167 ENV is the environment vector to pass. Errors reported with error(). */
168
169static void
fba45db2 170child_create_inferior (char *exec_file, char *allargs, char **env)
c906108c
SS
171{
172 LaunchParamBlockRec launchparms;
173 FSSpec fsspec;
174 OSErr launch_err;
175
176 if (!exec_file)
177 {
178 error ("No executable specified, use `target exec'.\n");
179 }
180
181 launchparms.launchBlockID = extendedBlock;
182 launchparms.launchEPBLength = extendedBlockLen;
183 launchparms.launchFileFlags = 0;
184 launchparms.launchControlFlags = launchContinue | launchNoFileFlags;
185 fsspec.vRefNum = 0;
186 fsspec.parID = 0;
c5aa993b
JM
187 strcpy (fsspec.name + 1, exec_file);
188 fsspec.name[0] = strlen (exec_file);
c906108c
SS
189 launchparms.launchAppSpec = &fsspec;
190 launchparms.launchAppParameters = nil;
191
192 launch_err = LaunchApplication (&launchparms);
193
c5aa993b 194 if (launch_err == 999 /*memFullErr */ )
c906108c
SS
195 {
196 error ("Not enough memory to launch %s\n", exec_file);
197 }
198 else if (launch_err != noErr)
199 {
200 error ("Error launching %s, code %d\n", exec_file, launch_err);
201 }
202
203 inferior_pid = launchparms.launchProcessSN.lowLongOfPSN;
204 /* FIXME be sure that high long of PSN is 0 */
205
206 push_target (&child_ops);
207 init_wait_for_inferior ();
208 clear_proceed_status ();
209
2acceee2 210/* proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0); */
c906108c
SS
211}
212
213static void
fba45db2 214child_mourn_inferior (void)
c906108c
SS
215{
216 unpush_target (&child_ops);
217 generic_mourn_inferior ();
218}
219
220static void
fba45db2 221child_stop (void)
c906108c
SS
222{
223}
224
225int
226child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
c5aa993b 227 int write, struct target_ops *target)
c906108c
SS
228{
229 int i;
230
231 for (i = 0; i < len; ++i)
232 {
233 if (write)
234 {
235 ((char *) memaddr)[i] = myaddr[i];
236 }
237 else
238 {
239 myaddr[i] = ((char *) memaddr)[i];
240 }
241 }
242 return len;
243}
244
245void
246child_kill_inferior (void)
247{
248}
249
250void
251child_resume (int pid, int step, enum target_signal signal)
252{
253}
254
255static void
fba45db2 256child_prepare_to_store (void)
c906108c
SS
257{
258 /* Do nothing, since we can store individual regs */
259}
260
261static int
fba45db2 262child_can_run (void)
c906108c
SS
263{
264 return 1;
265}
266
267static void
fba45db2 268child_close (void)
c906108c
SS
269{
270}
271
272static void
fba45db2 273info_proc (char *args, int from_tty)
c906108c
SS
274{
275 ProcessSerialNumber psn;
276 ProcessInfoRec inforec;
277 Str31 name;
278 FSSpecPtr fsspec;
279 OSType code;
280
281 /* Eventually use args, but not right now. */
282
283 psn.highLongOfPSN = 0;
284 psn.lowLongOfPSN = kNoProcess;
285
c5aa993b 286 inforec.processInfoLength = sizeof (ProcessInfoRec);
c906108c
SS
287 inforec.processName = name;
288 inforec.processAppSpec = fsspec;
289
290 printf_filtered ("Process Name Sgnt Type PSN Loc Size FreeMem Time\n");
291
292 while (GetNextProcess (&psn) == noErr)
293 {
294 if (GetProcessInformation (&psn, &inforec) == noErr)
295 {
296 name[name[0] + 1] = '\0';
297 printf_filtered ("%-32.32s", name + 1);
298 code = inforec.processSignature;
299 printf_filtered (" %c%c%c%c",
300 (code >> 24) & 0xff,
301 (code >> 16) & 0xff,
c5aa993b
JM
302 (code >> 8) & 0xff,
303 (code >> 0) & 0xff);
c906108c
SS
304 code = inforec.processType;
305 printf_filtered (" %c%c%c%c",
306 (code >> 24) & 0xff,
307 (code >> 16) & 0xff,
c5aa993b
JM
308 (code >> 8) & 0xff,
309 (code >> 0) & 0xff);
c906108c
SS
310 if (psn.highLongOfPSN == 0)
311 printf_filtered (" %9d", psn.lowLongOfPSN);
312 else
313 printf_filtered (" %9d,%9d\n",
314 psn.highLongOfPSN, psn.lowLongOfPSN);
315 printf_filtered (" 0x%x", inforec.processLocation);
316 printf_filtered (" %9d", inforec.processSize);
317 printf_filtered (" %9d", inforec.processFreeMem);
318 printf_filtered (" %9d", inforec.processActiveTime);
319 printf_filtered ("\n");
320 }
321 }
322}
323
c5aa993b 324struct target_ops child_ops;
c906108c 325
c5aa993b
JM
326static void
327init_child_ops (void)
c906108c 328{
c5aa993b
JM
329 child_ops.to_shortname = "mac";
330 child_ops.to_longname = "MacOS application";
331 child_ops.to_doc = "MacOS application (started by the \"run\" command).";
332 child_ops.to_open = child_open;
333 child_ops.to_close = child_close;
334 child_ops.to_attach = child_attach;
c906108c 335 child_ops.to_post_attach = NULL;
c5aa993b
JM
336 child_ops.to_require_attach = NULL; /* to_require_attach */
337 child_ops.to_detach = child_detach;
338 child_ops.to_require_detach = NULL; /* to_require_detach */
339 child_ops.to_resume = child_resume;
340 child_ops.to_wait = child_wait;
341 child_ops.to_post_wait = NULL; /* to_post_wait */
342 child_ops.to_fetch_registers = child_fetch_inferior_registers;
343 child_ops.to_store_registers = child_store_inferior_registers;
344 child_ops.to_prepare_to_store = child_prepare_to_store;
345 child_ops.to_xfer_memory = child_xfer_memory;
346 child_ops.to_files_info = child_files_info;
347 child_ops.to_insert_breakpoint = memory_insert_breakpoint;
348 child_ops.to_remove_breakpoint = memory_remove_breakpoint;
349 child_ops.to_terminal_init = 0;
350 child_ops.to_terminal_inferior = 0;
351 child_ops.to_terminal_ours_for_output = 0;
352 child_ops.to_terminal_ours = 0;
353 child_ops.to_terminal_info = 0;
354 child_ops.to_kill = child_kill_inferior;
355 child_ops.to_load = 0;
356 child_ops.to_lookup_symbol = 0;
c906108c 357 child_ops.to_create_inferior = child_create_inferior;
c5aa993b
JM
358 child_ops.to_post_startup_inferior = NULL; /* to_post_startup_inferior */
359 child_ops.to_acknowledge_created_inferior = NULL; /* to_acknowledge_created_inferior */
360 child_ops.to_clone_and_follow_inferior = NULL; /* to_clone_and_follow_inferior */
361 child_ops.to_post_follow_inferior_by_clone = NULL; /* to_post_follow_inferior_by_clone */
c906108c
SS
362 child_ops.to_insert_fork_catchpoint = NULL;
363 child_ops.to_remove_fork_catchpoint = NULL;
364 child_ops.to_insert_vfork_catchpoint = NULL;
365 child_ops.to_remove_vfork_catchpoint = NULL;
c5aa993b
JM
366 child_ops.to_has_forked = NULL; /* to_has_forked */
367 child_ops.to_has_vforked = NULL; /* to_has_vforked */
c906108c 368 child_ops.to_can_follow_vfork_prior_to_exec = NULL;
c5aa993b 369 child_ops.to_post_follow_vfork = NULL; /* to_post_follow_vfork */
c906108c
SS
370 child_ops.to_insert_exec_catchpoint = NULL;
371 child_ops.to_remove_exec_catchpoint = NULL;
372 child_ops.to_has_execd = NULL;
373 child_ops.to_reported_exec_events_per_exec_call = NULL;
374 child_ops.to_has_exited = NULL;
c5aa993b
JM
375 child_ops.to_mourn_inferior = child_mourn_inferior;
376 child_ops.to_can_run = child_can_run;
377 child_ops.to_notice_signals = 0;
378 child_ops.to_thread_alive = 0;
379 child_ops.to_stop = child_stop;
380 child_ops.to_pid_to_exec_file = NULL; /* to_pid_to_exec_file */
c906108c 381 child_ops.to_core_file_to_sym_file = NULL;
c5aa993b
JM
382 child_ops.to_stratum = process_stratum;
383 child_ops.DONT_USE = 0;
384 child_ops.to_has_all_memory = 1;
385 child_ops.to_has_memory = 1;
386 child_ops.to_has_stack = 1;
387 child_ops.to_has_registers = 1;
388 child_ops.to_has_execution = 1;
389 child_ops.to_sections = 0;
390 child_ops.to_sections_end = 0;
391 child_ops.to_magic = OPS_MAGIC;
c906108c
SS
392};
393
394void
fba45db2 395_initialize_mac_nat (void)
c906108c 396{
c5aa993b 397 init_child_ops ();
c906108c
SS
398
399 add_info ("proc", info_proc,
400 "Show information about processes.");
401}
This page took 0.10082 seconds and 4 git commands to generate.