/* Generic remote debugging interface for simulators.
- Copyright 1993 Free Software Foundation, Inc.
+ Copyright 1993, 1994 Free Software Foundation, Inc.
Contributed by Cygnus Support.
- Steve Chamberlain (sac@cygnus.com) and Doug Evans (dje@cygnus.com).
+ Steve Chamberlain (sac@cygnus.com).
This file is part of GDB.
}
}
+/* Kill the running program. This may involve closing any open files
+ and releasing other resources acquired by the simulated program. */
+
static void
gdbsim_kill ()
{
if (sr_get_debug ())
printf_filtered ("gdbsim_load: prog \"%s\"\n", prog);
- inferior_pid = 0;
+ inferior_pid = 0;
+
+ /* This must be done before calling gr_load_image. */
program_loaded = 1;
- gr_load_image (prog, fromtty);
+
+ if (sim_load (prog, fromtty) != 0)
+ gr_load_image (prog, fromtty);
}
char *args;
char **env;
{
- int len,entry_pt;
+ int len;
char *arg_buf,**argv;
+ CORE_ADDR entry_pt;
if (! program_loaded)
error ("No program loaded.");
if (exec_file == 0 || exec_bfd == 0)
error ("No exec file specified.");
- entry_pt = (int) bfd_get_start_address (exec_bfd);
+ entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
gdbsim_kill (NULL, NULL);
remove_breakpoints ();
strcat (arg_buf, args);
argv = buildargv (arg_buf);
make_cleanup (freeargv, (char *) argv);
- /* FIXME: remote-sim.h says targets that don't support this return
- non-zero. Perhaps distinguish between "not supported" and other errors?
- Or maybe that can be the only error. */
- if (sim_set_args (argv, env) != 0)
- return;
+ sim_create_inferior (entry_pt, argv, env);
inferior_pid = 42;
insert_breakpoints (); /* Needed to get correct instruction in cache */
int from_tty;
{
if (sr_get_debug ())
- printf_filtered ("gdbsim_open: args \"%s\"\n", args);
+ printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
- if (sim_open (args) != 0)
- {
- /* FIXME: This is totally bogus. sim_open should have a way to
- tell us what the error was, so we can tell the user. */
- error ("Unable to initialize simulator (insufficient memory?).");
- return;
- }
+ sim_open (args);
push_target (&gdbsim_ops);
target_fetch_registers (-1);
program_loaded = 0;
- /* FIXME: Need to call sim_close() to close all files and
- delete all mappings. */
+ sim_close (quitting);
}
/* Takes a program previously attached to and detaches it.
{
printf_filtered ("\tAttached to %s running program %s\n",
target_shortname, file);
- sim_info (printf_filtered, 0);
+ sim_info (0);
}
}
0, 0, /* Breakpoints */
0, 0, 0, 0, 0, /* Terminal handling */
gdbsim_kill, /* kill */
- gdbsim_load,
+ gdbsim_load, /* load */
0, /* lookup_symbol */
- gdbsim_create_inferior, /* create_inferior */
- gdbsim_mourn_inferior, /* mourn_inferior */
+ gdbsim_create_inferior, /* create_inferior */
+ gdbsim_mourn_inferior, /* mourn_inferior */
0, /* can_run */
0, /* notice_signals */
process_stratum, 0, /* next */
/* This file defines the interface between the simulator and gdb.
- Copyright (C) 1993 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1994 Free Software Foundation, Inc.
This file is part of GDB.
typedef CORE_ADDR_TYPE SIM_ADDR;
#endif
-/* Main simulator globals ... */
+/* Callbacks.
+ The simulator may use the following callbacks (gdb routines) which the
+ standalone program must provide.
-extern int sim_verbose;
+ void printf_filtered (char *msg, ...);
+ void error /-* noreturn *-/ (char *msg, ...);
+ void *xmalloc (long size);
+*/
/* Main simulator entry points ...
- Except where noted, all functions return 0 for success and non-zero for
- failure. Sometimes there won't be much possibility of error, but maybe
- in the future. */
+ All functions that can get an error must call the gdb routine `error',
+ they can only return upon success. */
/* Initialize the simulator. This function is called when the simulator
is selected from the command line. ARGS is passed from the command line
and can be used to select whatever run time options the simulator provides.
- ARGS is the raw character string and must be parsed by the simulator.
+ ARGS is the raw character string and must be parsed by the simulator,
+ which is trivial to do with the buildargv function in libiberty.
+ It is ok to do nothing. */
- Returns 0 for success, non-zero for failure (FIXME: how do we say what
- kind of failure it was?). */
+void sim_open PARAMS ((char *args));
-int sim_open PARAMS ((char *name));
+/* Terminate usage of the simulator. This may involve freeing target memory
+ and closing any open files and mmap'd areas. You cannot assume sim_kill
+ has already been called.
+ QUITTING is non-zero if we cannot hang on errors. */
-/* Load program PROG into the simulator.
- We use "void *" instead of "bfd *" to isolate this file from BFD. */
-
-int sim_load PARAMS ((void *bfd_handle, char *args));
-
-/* Set the arguments and environment for the program loaded into the
- simulator. ARGV and ENV are NULL terminated lists of pointers.
- If the simulator doesn't support setting arguments, print an error message
- and return non-zero. */
-
-int sim_set_args PARAMS ((char **argv, char **env));
+void sim_close PARAMS ((int quitting));
-/* Fetch register REGNO and store the raw value in BUF. */
+/* Load program PROG into the simulator.
+ Return non-zero if you wish the caller to handle it
+ (it is done this way because most simulators can use gr_load_image,
+ but defining it as a callback seems awkward). */
-int sim_fetch_register PARAMS ((int regno, unsigned char *buf));
+int sim_load PARAMS ((char *prog, int from_tty));
-/* Store register REGNO from BUF (in raw format). */
+/* Prepare to run the simulated program.
+ START_ADDRESS is, yes, you guessed it, the start address of the program.
+ ARGV and ENV are NULL terminated lists of pointers.
+ Gdb will set the start address via sim_store_register as well, but
+ standalone versions of existing simulators are not set up to cleanly call
+ sim_store_register, so the START_ADDRESS argument is there as a
+ workaround. */
-int sim_store_register PARAMS ((int regno, unsigned char *buf));
+void sim_create_inferior PARAMS ((SIM_ADDR start_address,
+ char **argv, char **env));
/* Kill the running program.
This may involve closing any open files and deleting any mmap'd areas. */
-int sim_kill PARAMS ((void));
+void sim_kill PARAMS ((void));
/* Read LENGTH bytes of the simulated program's memory and store in BUF.
Result is number of bytes read, or zero if error. */
int sim_write PARAMS ((SIM_ADDR mem, unsigned char *buf, int length));
-/* Print some interesting information about the simulator.
- VERBOSE is non-zero for the wordy version. */
+/* Fetch register REGNO and store the raw value in BUF. */
-int sim_info PARAMS ((void (*printf_fn)(), int verbose));
+void sim_fetch_register PARAMS ((int regno, unsigned char *buf));
+
+/* Store register REGNO from BUF (in raw format). */
-/* Set the simulated cpu's program counter to PC. */
+void sim_store_register PARAMS ((int regno, unsigned char *buf));
+
+/* Print some interesting information about the simulator.
+ VERBOSE is non-zero for the wordy version. */
-int sim_set_pc PARAMS ((SIM_ADDR pc));
+void sim_info PARAMS ((int verbose));
/* Fetch why the program stopped.
SIGRC will contain either the argument to exit() or the signal number. */
enum sim_stop { sim_exited, sim_stopped, sim_signalled };
-int sim_stop_reason PARAMS ((enum sim_stop *reason, int *sigrc));
+void sim_stop_reason PARAMS ((enum sim_stop *reason, int *sigrc));
/* Run (or resume) the program. */
-int sim_resume PARAMS ((int step, int siggnal));
+void sim_resume PARAMS ((int step, int siggnal));
#endif /* !defined (REMOTE_SIM_H) */