1 /* Generic remote debugging interface for simulators.
2 Copyright 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
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));
122 /* Kill the running program. This may involve closing any open files
123 and releasing other resources acquired by the simulated program. */
129 printf_filtered ("gdbsim_kill\n");
131 sim_kill (); /* close fd's, remove mappings */
135 /* Load an executable file into the target process. This is expected to
136 not only bring new code into the target process, but also to update
137 GDB's symbol tables to match. */
140 gdbsim_load (prog, fromtty)
145 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog);
149 /* This must be done before calling gr_load_image. */
152 if (sim_load (prog, fromtty) != 0)
153 gr_load_image (prog, fromtty);
157 /* Start an inferior process and set inferior_pid to its pid.
158 EXEC_FILE is the file to run.
159 ALLARGS is a string containing the arguments to the program.
160 ENV is the environment vector to pass. Errors reported with error().
161 On VxWorks and various standalone systems, we ignore exec_file. */
162 /* This is called not only when we first attach, but also when the
163 user types "run" after having attached. */
166 gdbsim_create_inferior (exec_file, args, env)
172 char *arg_buf,**argv;
175 if (! program_loaded)
176 error ("No program loaded.");
179 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
182 if (exec_file == 0 || exec_bfd == 0)
183 error ("No exec file specified.");
185 entry_pt = (CORE_ADDR) bfd_get_start_address (exec_bfd);
187 gdbsim_kill (NULL, NULL);
188 remove_breakpoints ();
189 init_wait_for_inferior ();
191 len = 5 + strlen (exec_file) + 1 + strlen (args) + 1 + /*slop*/ 10;
192 arg_buf = (char *) alloca (len);
194 strcat (arg_buf, exec_file);
195 strcat (arg_buf, " ");
196 strcat (arg_buf, args);
197 argv = buildargv (arg_buf);
198 make_cleanup (freeargv, (char *) argv);
199 sim_create_inferior (entry_pt, argv, env);
202 insert_breakpoints (); /* Needed to get correct instruction in cache */
203 proceed (entry_pt, TARGET_SIGNAL_DEFAULT, 0);
206 /* The open routine takes the rest of the parameters from the command,
207 and (if successful) pushes a new target onto the stack.
208 Targets should supply this routine, if only to provide an error message. */
209 /* Called when selecting the simulator. EG: (gdb) target sim name. */
212 gdbsim_open (args, from_tty)
217 printf_filtered ("gdbsim_open: args \"%s\"\n", args ? args : "(null)");
221 push_target (&gdbsim_ops);
222 target_fetch_registers (-1);
224 printf_filtered ("Connected to the simulator.\n");
227 /* Does whatever cleanup is required for a target that we are no longer
228 going to be calling. Argument says whether we are quitting gdb and
229 should not get hung in case of errors, or whether we want a clean
230 termination even if it takes a while. This routine is automatically
231 always called just before a routine is popped off the target stack.
232 Closing file descriptors and freeing memory are typical things it should
234 /* Close out all files and local state before this target loses control. */
237 gdbsim_close (quitting)
241 printf_filtered ("gdbsim_close: quitting %d\n", quitting);
245 sim_close (quitting);
248 /* Takes a program previously attached to and detaches it.
249 The program may resume execution (some targets do, some don't) and will
250 no longer stop on signals, etc. We better not have left any breakpoints
251 in the program or it'll die when it hits one. ARGS is arguments
252 typed by the user (e.g. a signal to send the process). FROM_TTY
253 says whether to be verbose or not. */
254 /* Terminate the open connection to the remote debugger.
255 Use this when you want to detach and do something else with your gdb. */
258 gdbsim_detach (args,from_tty)
263 printf_filtered ("gdbsim_detach: args \"%s\"\n", args);
265 pop_target (); /* calls gdbsim_close to do the real work */
267 printf_filtered ("Ending simulator %s debugging\n", target_shortname);
270 /* Resume execution of the target process. STEP says whether to single-step
271 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
272 to the target, or zero for no signal. */
275 gdbsim_resume (pid, step, siggnal)
277 enum target_signal siggnal;
280 printf_filtered ("gdbsim_resume: step %d, signal %d\n", step, siggnal);
282 sim_resume (step, target_signal_to_host (siggnal));
285 /* Wait for inferior process to do something. Return pid of child,
286 or -1 in case of error; store status through argument pointer STATUS,
287 just as `wait' would. */
290 gdbsim_wait (pid, status)
292 struct target_waitstatus *status;
295 enum sim_stop reason;
298 printf_filtered ("gdbsim_wait\n");
300 sim_stop_reason (&reason, &sigrc);
304 status->kind = TARGET_WAITKIND_EXITED;
305 status->value.integer = sigrc;
308 status->kind = TARGET_WAITKIND_STOPPED;
309 /* The signal in sigrc is a host signal. That probably
311 status->value.sig = target_signal_from_host (sigrc);
314 status->kind = TARGET_WAITKIND_SIGNALLED;
315 /* The signal in sigrc is a host signal. That probably
317 status->value.sig = target_signal_from_host (sigrc);
324 /* Get ready to modify the registers array. On machines which store
325 individual registers, this doesn't need to do anything. On machines
326 which store all the registers in one fell swoop, this makes sure
327 that registers contains all the registers from the program being
331 gdbsim_prepare_to_store ()
333 /* Do nothing, since we can store individual regs */
337 gdbsim_xfer_inferior_memory (memaddr, myaddr, len, write, target)
342 struct target_ops *target; /* ignored */
344 if (! program_loaded)
345 error ("No program loaded.");
349 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
350 myaddr, memaddr, len, write);
351 if (sr_get_debug () && write)
352 dump_mem(myaddr, len);
357 len = sim_write (memaddr, myaddr, len);
361 len = sim_read (memaddr, myaddr, len);
362 if (sr_get_debug () && len > 0)
363 dump_mem(myaddr, len);
369 gdbsim_files_info (target)
370 struct target_ops *target;
372 char *file = "nothing";
375 file = bfd_get_filename (exec_bfd);
378 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file);
382 printf_filtered ("\tAttached to %s running program %s\n",
383 target_shortname, file);
388 /* Clear the sims notion of what the break points are. */
391 gdbsim_mourn_inferior ()
394 printf_filtered ("gdbsim_mourn_inferior:\n");
396 remove_breakpoints ();
397 generic_mourn_inferior ();
400 /* Define the target subroutine names */
402 struct target_ops gdbsim_ops =
406 gdbsim_open, gdbsim_close,
407 0, gdbsim_detach, gdbsim_resume, gdbsim_wait, /* attach */
408 gdbsim_fetch_register, gdbsim_store_register,
409 gdbsim_prepare_to_store,
410 gdbsim_xfer_inferior_memory,
412 memory_insert_breakpoint,
413 memory_remove_breakpoint,
414 0, 0, 0, 0, 0, /* Terminal handling */
415 gdbsim_kill, /* kill */
416 gdbsim_load, /* load */
417 0, /* lookup_symbol */
418 gdbsim_create_inferior, /* create_inferior */
419 gdbsim_mourn_inferior, /* mourn_inferior */
421 0, /* notice_signals */
423 process_stratum, 0, /* next */
424 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
425 0, 0, /* Section pointers */
426 OPS_MAGIC, /* Always the last thing */
430 _initialize_remote_sim ()
432 add_target (&gdbsim_ops);