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