OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [mac-nat.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* 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,
20
   Boston, MA 02111-1307, USA.  */
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"
29
#include "gdb_wait.h"
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
 
47
extern struct target_ops child_ops;
48
 
49
static void child_stop PARAMS ((void));
50
 
51
static void
52
child_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
 
65
static void
66
child_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
 
79
static int
80
child_wait (int pid, struct target_waitstatus *ourstatus)
81
{
82
}
83
 
84
/* Attach to process PID, then initialize for debugging it.  */
85
 
86
static void
87
child_attach (args, from_tty)
88
     char *args;
89
     int from_tty;
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
 
107
  inforec.processInfoLength = sizeof (ProcessInfoRec);
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
 
132
static void
133
child_detach (args, from_tty)
134
     char *args;
135
     int from_tty;
136
{
137
  char *exec_file;
138
 
139
  if (from_tty)
140
    {
141
      exec_file = get_exec_file (0);
142
      if (exec_file == 0)
143
        exec_file = "";
144
      printf_unfiltered ("Detaching from program: %s %s\n", exec_file,
145
                         target_pid_to_str (inferior_pid));
146
      gdb_flush (gdb_stdout);
147
    }
148
  inferior_pid = 0;
149
  unpush_target (&child_ops);
150
}
151
 
152
/* Print status information about what we're accessing.  */
153
 
154
static void
155
child_files_info (ignore)
156
     struct target_ops *ignore;
157
{
158
  printf_unfiltered ("\tUsing the running image of %s %s.\n",
159
      attach_flag ? "attached" : "child", target_pid_to_str (inferior_pid));
160
}
161
 
162
/* ARGSUSED */
163
static void
164
child_open (arg, from_tty)
165
     char *arg;
166
     int from_tty;
167
{
168
  error ("Use the \"run\" command to start a Mac application.");
169
}
170
 
171
/* Start an inferior Mac program and sets inferior_pid to its pid.
172
   EXEC_FILE is the file to run.
173
   ALLARGS is a string containing the arguments to the program.
174
   ENV is the environment vector to pass.  Errors reported with error().  */
175
 
176
static void
177
child_create_inferior (exec_file, allargs, env)
178
     char *exec_file;
179
     char *allargs;
180
     char **env;
181
{
182
  LaunchParamBlockRec launchparms;
183
  FSSpec fsspec;
184
  OSErr launch_err;
185
 
186
  if (!exec_file)
187
    {
188
      error ("No executable specified, use `target exec'.\n");
189
    }
190
 
191
  launchparms.launchBlockID = extendedBlock;
192
  launchparms.launchEPBLength = extendedBlockLen;
193
  launchparms.launchFileFlags = 0;
194
  launchparms.launchControlFlags = launchContinue | launchNoFileFlags;
195
  fsspec.vRefNum = 0;
196
  fsspec.parID = 0;
197
  strcpy (fsspec.name + 1, exec_file);
198
  fsspec.name[0] = strlen (exec_file);
199
  launchparms.launchAppSpec = &fsspec;
200
  launchparms.launchAppParameters = nil;
201
 
202
  launch_err = LaunchApplication (&launchparms);
203
 
204
  if (launch_err == 999 /*memFullErr */ )
205
    {
206
      error ("Not enough memory to launch %s\n", exec_file);
207
    }
208
  else if (launch_err != noErr)
209
    {
210
      error ("Error launching %s, code %d\n", exec_file, launch_err);
211
    }
212
 
213
  inferior_pid = launchparms.launchProcessSN.lowLongOfPSN;
214
  /* FIXME be sure that high long of PSN is 0 */
215
 
216
  push_target (&child_ops);
217
  init_wait_for_inferior ();
218
  clear_proceed_status ();
219
 
220
/*  proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);  */
221
}
222
 
223
static void
224
child_mourn_inferior ()
225
{
226
  unpush_target (&child_ops);
227
  generic_mourn_inferior ();
228
}
229
 
230
static void
231
child_stop ()
232
{
233
}
234
 
235
int
236
child_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len,
237
                   int write, struct target_ops *target)
238
{
239
  int i;
240
 
241
  for (i = 0; i < len; ++i)
242
    {
243
      if (write)
244
        {
245
          ((char *) memaddr)[i] = myaddr[i];
246
        }
247
      else
248
        {
249
          myaddr[i] = ((char *) memaddr)[i];
250
        }
251
    }
252
  return len;
253
}
254
 
255
void
256
child_kill_inferior (void)
257
{
258
}
259
 
260
void
261
child_resume (int pid, int step, enum target_signal signal)
262
{
263
}
264
 
265
static void
266
child_prepare_to_store ()
267
{
268
  /* Do nothing, since we can store individual regs */
269
}
270
 
271
static int
272
child_can_run ()
273
{
274
  return 1;
275
}
276
 
277
static void
278
child_close ()
279
{
280
}
281
 
282
static void
283
info_proc (args, from_tty)
284
     char *args;
285
     int from_tty;
286
{
287
  ProcessSerialNumber psn;
288
  ProcessInfoRec inforec;
289
  Str31 name;
290
  FSSpecPtr fsspec;
291
  OSType code;
292
 
293
  /* Eventually use args, but not right now. */
294
 
295
  psn.highLongOfPSN = 0;
296
  psn.lowLongOfPSN = kNoProcess;
297
 
298
  inforec.processInfoLength = sizeof (ProcessInfoRec);
299
  inforec.processName = name;
300
  inforec.processAppSpec = fsspec;
301
 
302
  printf_filtered ("Process Name                     Sgnt Type    PSN   Loc Size FreeMem Time\n");
303
 
304
  while (GetNextProcess (&psn) == noErr)
305
    {
306
      if (GetProcessInformation (&psn, &inforec) == noErr)
307
        {
308
          name[name[0] + 1] = '\0';
309
          printf_filtered ("%-32.32s", name + 1);
310
          code = inforec.processSignature;
311
          printf_filtered (" %c%c%c%c",
312
                           (code >> 24) & 0xff,
313
                           (code >> 16) & 0xff,
314
                           (code >> 8) & 0xff,
315
                           (code >> 0) & 0xff);
316
          code = inforec.processType;
317
          printf_filtered (" %c%c%c%c",
318
                           (code >> 24) & 0xff,
319
                           (code >> 16) & 0xff,
320
                           (code >> 8) & 0xff,
321
                           (code >> 0) & 0xff);
322
          if (psn.highLongOfPSN == 0)
323
            printf_filtered (" %9d", psn.lowLongOfPSN);
324
          else
325
            printf_filtered (" %9d,%9d\n",
326
                             psn.highLongOfPSN, psn.lowLongOfPSN);
327
          printf_filtered (" 0x%x", inforec.processLocation);
328
          printf_filtered (" %9d", inforec.processSize);
329
          printf_filtered (" %9d", inforec.processFreeMem);
330
          printf_filtered (" %9d", inforec.processActiveTime);
331
          printf_filtered ("\n");
332
        }
333
    }
334
}
335
 
336
struct target_ops child_ops;
337
 
338
static void
339
init_child_ops (void)
340
{
341
  child_ops.to_shortname = "mac";
342
  child_ops.to_longname = "MacOS application";
343
  child_ops.to_doc = "MacOS application (started by the \"run\" command).";
344
  child_ops.to_open = child_open;
345
  child_ops.to_close = child_close;
346
  child_ops.to_attach = child_attach;
347
  child_ops.to_post_attach = NULL;
348
  child_ops.to_require_attach = NULL;   /* to_require_attach */
349
  child_ops.to_detach = child_detach;
350
  child_ops.to_require_detach = NULL;   /* to_require_detach */
351
  child_ops.to_resume = child_resume;
352
  child_ops.to_wait = child_wait;
353
  child_ops.to_post_wait = NULL;        /* to_post_wait */
354
  child_ops.to_fetch_registers = child_fetch_inferior_registers;
355
  child_ops.to_store_registers = child_store_inferior_registers;
356
  child_ops.to_prepare_to_store = child_prepare_to_store;
357
  child_ops.to_xfer_memory = child_xfer_memory;
358
  child_ops.to_files_info = child_files_info;
359
  child_ops.to_insert_breakpoint = memory_insert_breakpoint;
360
  child_ops.to_remove_breakpoint = memory_remove_breakpoint;
361
  child_ops.to_terminal_init = 0;
362
  child_ops.to_terminal_inferior = 0;
363
  child_ops.to_terminal_ours_for_output = 0;
364
  child_ops.to_terminal_ours = 0;
365
  child_ops.to_terminal_info = 0;
366
  child_ops.to_kill = child_kill_inferior;
367
  child_ops.to_load = 0;
368
  child_ops.to_lookup_symbol = 0;
369
  child_ops.to_create_inferior = child_create_inferior;
370
  child_ops.to_post_startup_inferior = NULL;    /* to_post_startup_inferior */
371
  child_ops.to_acknowledge_created_inferior = NULL;     /* to_acknowledge_created_inferior */
372
  child_ops.to_clone_and_follow_inferior = NULL;        /* to_clone_and_follow_inferior */
373
  child_ops.to_post_follow_inferior_by_clone = NULL;    /* to_post_follow_inferior_by_clone */
374
  child_ops.to_insert_fork_catchpoint = NULL;
375
  child_ops.to_remove_fork_catchpoint = NULL;
376
  child_ops.to_insert_vfork_catchpoint = NULL;
377
  child_ops.to_remove_vfork_catchpoint = NULL;
378
  child_ops.to_has_forked = NULL;       /* to_has_forked */
379
  child_ops.to_has_vforked = NULL;      /* to_has_vforked */
380
  child_ops.to_can_follow_vfork_prior_to_exec = NULL;
381
  child_ops.to_post_follow_vfork = NULL;        /* to_post_follow_vfork */
382
  child_ops.to_insert_exec_catchpoint = NULL;
383
  child_ops.to_remove_exec_catchpoint = NULL;
384
  child_ops.to_has_execd = NULL;
385
  child_ops.to_reported_exec_events_per_exec_call = NULL;
386
  child_ops.to_has_exited = NULL;
387
  child_ops.to_mourn_inferior = child_mourn_inferior;
388
  child_ops.to_can_run = child_can_run;
389
  child_ops.to_notice_signals = 0;
390
  child_ops.to_thread_alive = 0;
391
  child_ops.to_stop = child_stop;
392
  child_ops.to_pid_to_exec_file = NULL;         /* to_pid_to_exec_file */
393
  child_ops.to_core_file_to_sym_file = NULL;
394
  child_ops.to_stratum = process_stratum;
395
  child_ops.DONT_USE = 0;
396
  child_ops.to_has_all_memory = 1;
397
  child_ops.to_has_memory = 1;
398
  child_ops.to_has_stack = 1;
399
  child_ops.to_has_registers = 1;
400
  child_ops.to_has_execution = 1;
401
  child_ops.to_sections = 0;
402
  child_ops.to_sections_end = 0;
403
  child_ops.to_magic = OPS_MAGIC;
404
};
405
 
406
void
407
_initialize_mac_nat ()
408
{
409
  init_child_ops ();
410
 
411
  add_info ("proc", info_proc,
412
            "Show information about processes.");
413
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.