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