Now handles multiple hosts and targets.
[deliverable/binutils-gdb.git] / gdb / inftarg.c
CommitLineData
bd5635a1
RP
1/* Subroutines for handling an "inferior" (child) process as a target
2 for debugging, in GDB.
3 Copyright 1990, 1991 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
5
6This file is part of GDB.
7
8GDB is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 1, or (at your option)
11any later version.
12
13GDB is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GDB; see the file COPYING. If not, write to
20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include <stdio.h>
23#include "defs.h"
24#include "param.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 "ieee-float.h" /* Required by REGISTER_CONVERT_TO_XXX */
31
32extern int fetch_inferior_registers();
33extern int store_inferior_registers();
34extern int child_xfer_memory();
35extern int memory_insert_breakpoint(), memory_remove_breakpoint();
36extern void terminal_init_inferior(), terminal_ours(), terminal_inferior();
37extern void terminal_ours_for_output(), child_terminal_info();
38extern void kill_inferior(), add_syms_addr_command();
39extern struct value *call_function_by_hand();
40extern void child_resume();
41extern void child_create_inferior();
42extern void child_mourn_inferior();
43extern void child_attach ();
44
45/* Forward declaration */
46extern struct target_ops child_ops;
47
48/* Wait for child to do something. Return pid of child, or -1 in case
49 of error; store status through argument pointer STATUS. */
50
51int
52child_wait (status)
53 int *status;
54{
55 int pid;
56
57 do {
58 pid = wait (status);
59 if (pid == -1) /* No more children to wait for */
60 {
61 fprintf (stderr, "Child process unexpectedly missing.\n");
62 *status = 42; /* Claim it exited with signal 42 */
63 return -1;
64 }
65 } while (pid != inferior_pid); /* Some other child died or stopped */
66 return pid;
67}
68
69
70/*
71 * child_detach()
72 * takes a program previously attached to and detaches it.
73 * The program resumes execution and will no longer stop
74 * on signals, etc. We better not have left any breakpoints
75 * in the program or it'll die when it hits one. For this
76 * to work, it may be necessary for the process to have been
77 * previously attached. It *might* work if the program was
78 * started via the normal ptrace (PTRACE_TRACEME).
79 */
80
81static void
82child_detach (args, from_tty)
83 char *args;
84 int from_tty;
85{
86 int siggnal = 0;
87
88#ifdef ATTACH_DETACH
89 if (from_tty)
90 {
91 char *exec_file = get_exec_file (0);
92 if (exec_file == 0)
93 exec_file = "";
94 printf ("Detaching program: %s pid %d\n",
95 exec_file, inferior_pid);
96 fflush (stdout);
97 }
98 if (args)
99 siggnal = atoi (args);
100
101 detach (siggnal);
102 inferior_pid = 0;
103 unpush_target (&child_ops); /* Pop out of handling an inferior */
104#else
105 error ("This version of Unix does not support detaching a process.");
106#endif
107}
108
109/* Get ready to modify the registers array. On machines which store
110 individual registers, this doesn't need to do anything. On machines
111 which store all the registers in one fell swoop, this makes sure
112 that registers contains all the registers from the program being
113 debugged. */
114
115void
116child_prepare_to_store ()
117{
118#ifdef CHILD_PREPARE_TO_STORE
119 CHILD_PREPARE_TO_STORE ();
120#endif
121}
122
123/* Convert data from raw format for register REGNUM
124 to virtual format for register REGNUM. */
125
126void
127host_convert_to_virtual (regnum, from, to)
128 int regnum;
129 char *from;
130 char *to;
131{
132 REGISTER_CONVERT_TO_VIRTUAL (regnum, from, to);
133}
134
135/* Convert data from virtual format for register REGNUM
136 to raw format for register REGNUM. */
137
138void
139host_convert_from_virtual (regnum, from, to)
140 int regnum;
141 char *from;
142 char *to;
143{
144 REGISTER_CONVERT_TO_RAW (regnum, from, to);
145}
146
147/* Print status information about what we're accessing. */
148
149static void
150child_files_info ()
151{
152 printf ("\tUsing the running image of %s process %d.\n",
153 attach_flag? "attached": "child", inferior_pid);
154}
155
156struct target_ops child_ops = {
157 "child", "Unix child process",
158 0, 0, /* open, close */
159 child_attach, child_detach,
160 child_resume,
161 child_wait,
162 fetch_inferior_registers, store_inferior_registers,
163 child_prepare_to_store,
164 host_convert_to_virtual, host_convert_from_virtual,
165 child_xfer_memory, child_files_info,
166 memory_insert_breakpoint, memory_remove_breakpoint,
167 terminal_init_inferior, terminal_inferior,
168 terminal_ours_for_output, terminal_ours, child_terminal_info,
169 kill_inferior, 0, add_syms_addr_command, /* load */
170 call_function_by_hand,
171 0, /* lookup_symbol */
172 child_create_inferior, child_mourn_inferior,
173 process_stratum, 0, /* next */
174 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
175 OPS_MAGIC, /* Always the last thing */
176};
177
178void
179_initialize_inftarg ()
180{
181 add_target (&child_ops);
182}
This page took 0.0536 seconds and 4 git commands to generate.