1 /* Generic remote debugging interface for simulators.
2 Copyright 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 Steve Chamberlain (sac@cygnus.com) and Doug Evans (dje@cygnus.com).
6 This file is part of GDB.
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.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
35 #include "remote-sim.h"
36 #include "remote-utils.h"
40 sim_* are the interface to the simulator (see remote-sim.h).
42 gdbsim_* are stuff which is internal to gdb. */
44 /* Forward data declarations */
45 extern struct target_ops gdbsim_ops
;
47 static int program_loaded
= 0;
56 if (len
== 8 || len
== 4)
60 printf_filtered ("\t0x%x", l
[0]);
61 printf_filtered (len
== 8 ? " 0x%x\n" : "\n", l
[1]);
66 printf_filtered ("\t");
67 for (i
= 0; i
< len
; i
++)
68 printf_filtered ("0x%x ", buf
[i
]);
69 printf_filtered ("\n");
75 gdbsim_fetch_register (regno
)
80 for (regno
= 0; regno
< NUM_REGS
; regno
++)
81 gdbsim_fetch_register (regno
);
85 char buf
[MAX_REGISTER_RAW_SIZE
];
87 sim_fetch_register (regno
, buf
);
88 supply_register (regno
, buf
);
91 printf_filtered ("gdbsim_fetch_register: %d", regno
);
92 /* FIXME: We could print something more intelligible. */
93 dump_mem (buf
, REGISTER_RAW_SIZE (regno
));
99 gdbsim_store_register (regno
)
104 for (regno
= 0; regno
< NUM_REGS
; regno
++)
105 gdbsim_store_register (regno
);
109 /* FIXME: Until read_register() returns LONGEST, we have this. */
110 char tmp
[MAX_REGISTER_RAW_SIZE
];
111 read_register_gen (regno
, tmp
);
112 sim_store_register (regno
, tmp
);
115 printf_filtered ("gdbsim_store_register: %d", regno
);
116 /* FIXME: We could print something more intelligible. */
117 dump_mem (tmp
, REGISTER_RAW_SIZE (regno
));
126 printf_filtered ("gdbsim_kill\n");
128 sim_kill (); /* close fd's, remove mappings */
132 /* Load an executable file into the target process. This is expected to
133 not only bring new code into the target process, but also to update
134 GDB's symbol tables to match. */
137 gdbsim_load (prog
, fromtty
)
142 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog
);
146 gr_load_image (prog
, fromtty
);
150 /* Start an inferior process and set inferior_pid to its pid.
151 EXEC_FILE is the file to run.
152 ALLARGS is a string containing the arguments to the program.
153 ENV is the environment vector to pass. Errors reported with error().
154 On VxWorks and various standalone systems, we ignore exec_file. */
155 /* This is called not only when we first attach, but also when the
156 user types "run" after having attached. */
159 gdbsim_create_inferior (exec_file
, args
, env
)
165 char *arg_buf
,**argv
;
167 if (! program_loaded
)
168 error ("No program loaded.");
171 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
174 if (exec_file
== 0 || exec_bfd
== 0)
175 error ("No exec file specified.");
177 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
179 gdbsim_kill (NULL
, NULL
);
180 remove_breakpoints ();
181 init_wait_for_inferior ();
183 len
= 5 + strlen (exec_file
) + 1 + strlen (args
) + 1 + /*slop*/ 10;
184 arg_buf
= (char *) alloca (len
);
186 strcat (arg_buf
, exec_file
);
187 strcat (arg_buf
, " ");
188 strcat (arg_buf
, args
);
189 argv
= buildargv (arg_buf
);
190 make_cleanup (freeargv
, (char *) argv
);
191 /* FIXME: remote-sim.h says targets that don't support this return
192 non-zero. Perhaps distinguish between "not supported" and other errors?
193 Or maybe that can be the only error. */
194 if (sim_set_args (argv
, env
) != 0)
198 insert_breakpoints (); /* Needed to get correct instruction in cache */
199 proceed (entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
202 /* The open routine takes the rest of the parameters from the command,
203 and (if successful) pushes a new target onto the stack.
204 Targets should supply this routine, if only to provide an error message. */
205 /* Called when selecting the simulator. EG: (gdb) target sim name. */
208 gdbsim_open (args
, from_tty
)
213 printf_filtered ("gdbsim_open: args \"%s\"\n", args
);
215 if (sim_open (args
) != 0)
217 /* FIXME: This is totally bogus. sim_open should have a way to
218 tell us what the error was, so we can tell the user. */
219 error ("Unable to initialize simulator (insufficient memory?).");
223 push_target (&gdbsim_ops
);
224 target_fetch_registers (-1);
226 printf_filtered ("Connected to the simulator.\n");
229 /* Does whatever cleanup is required for a target that we are no longer
230 going to be calling. Argument says whether we are quitting gdb and
231 should not get hung in case of errors, or whether we want a clean
232 termination even if it takes a while. This routine is automatically
233 always called just before a routine is popped off the target stack.
234 Closing file descriptors and freeing memory are typical things it should
236 /* Close out all files and local state before this target loses control. */
239 gdbsim_close (quitting
)
243 printf_filtered ("gdbsim_close: quitting %d\n", quitting
);
247 /* FIXME: Need to call sim_close() to close all files and
248 delete all mappings. */
251 /* Takes a program previously attached to and detaches it.
252 The program may resume execution (some targets do, some don't) and will
253 no longer stop on signals, etc. We better not have left any breakpoints
254 in the program or it'll die when it hits one. ARGS is arguments
255 typed by the user (e.g. a signal to send the process). FROM_TTY
256 says whether to be verbose or not. */
257 /* Terminate the open connection to the remote debugger.
258 Use this when you want to detach and do something else with your gdb. */
261 gdbsim_detach (args
,from_tty
)
266 printf_filtered ("gdbsim_detach: args \"%s\"\n", args
);
268 pop_target (); /* calls gdbsim_close to do the real work */
270 printf_filtered ("Ending simulator %s debugging\n", target_shortname
);
273 /* Resume execution of the target process. STEP says whether to single-step
274 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
275 to the target, or zero for no signal. */
278 gdbsim_resume (pid
, step
, siggnal
)
280 enum target_signal siggnal
;
283 printf_filtered ("gdbsim_resume: step %d, signal %d\n", step
, siggnal
);
285 sim_resume (step
, target_signal_to_host (siggnal
));
288 /* Wait for inferior process to do something. Return pid of child,
289 or -1 in case of error; store status through argument pointer STATUS,
290 just as `wait' would. */
293 gdbsim_wait (pid
, status
)
295 struct target_waitstatus
*status
;
298 enum sim_stop reason
;
301 printf_filtered ("gdbsim_wait\n");
303 sim_stop_reason (&reason
, &sigrc
);
307 status
->kind
= TARGET_WAITKIND_EXITED
;
308 status
->value
.integer
= sigrc
;
311 status
->kind
= TARGET_WAITKIND_STOPPED
;
312 /* The signal in sigrc is a host signal. That probably
314 status
->value
.sig
= target_signal_from_host (sigrc
);
317 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
318 /* The signal in sigrc is a host signal. That probably
320 status
->value
.sig
= target_signal_from_host (sigrc
);
327 /* Get ready to modify the registers array. On machines which store
328 individual registers, this doesn't need to do anything. On machines
329 which store all the registers in one fell swoop, this makes sure
330 that registers contains all the registers from the program being
334 gdbsim_prepare_to_store ()
336 /* Do nothing, since we can store individual regs */
340 gdbsim_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
345 struct target_ops
*target
; /* ignored */
347 if (! program_loaded
)
348 error ("No program loaded.");
352 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
353 myaddr
, memaddr
, len
, write
);
354 if (sr_get_debug () && write
)
355 dump_mem(myaddr
, len
);
360 len
= sim_write (memaddr
, myaddr
, len
);
364 len
= sim_read (memaddr
, myaddr
, len
);
365 if (sr_get_debug () && len
> 0)
366 dump_mem(myaddr
, len
);
372 gdbsim_files_info (target
)
373 struct target_ops
*target
;
375 char *file
= "nothing";
378 file
= bfd_get_filename (exec_bfd
);
381 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file
);
385 printf_filtered ("\tAttached to %s running program %s\n",
386 target_shortname
, file
);
387 sim_info (printf_filtered
, 0);
391 /* Clear the sims notion of what the break points are. */
394 gdbsim_mourn_inferior ()
397 printf_filtered ("gdbsim_mourn_inferior:\n");
399 remove_breakpoints ();
400 generic_mourn_inferior ();
403 /* Define the target subroutine names */
405 struct target_ops gdbsim_ops
=
409 gdbsim_open
, gdbsim_close
,
410 0, gdbsim_detach
, gdbsim_resume
, gdbsim_wait
, /* attach */
411 gdbsim_fetch_register
, gdbsim_store_register
,
412 gdbsim_prepare_to_store
,
413 gdbsim_xfer_inferior_memory
,
415 0, 0, /* Breakpoints */
416 0, 0, 0, 0, 0, /* Terminal handling */
417 gdbsim_kill
, /* kill */
419 0, /* lookup_symbol */
420 gdbsim_create_inferior
, /* create_inferior */
421 gdbsim_mourn_inferior
, /* mourn_inferior */
423 0, /* notice_signals */
424 process_stratum
, 0, /* next */
425 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
426 0, 0, /* Section pointers */
427 OPS_MAGIC
, /* Always the last thing */
431 _initialize_remote_sim ()
433 add_target (&gdbsim_ops
);