1 /* Generic remote debugging interface for simulators.
2 Copyright 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 Steve Chamberlain (sac@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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
35 #include "remote-sim.h"
36 #include "remote-utils.h"
40 sim_* are the interface to the simulator (see remote-sim.h).
41 sim_callback_* are the stuff which the simulator can see inside GDB.
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
));
100 gdbsim_store_register (regno
)
105 for (regno
= 0; regno
< NUM_REGS
; regno
++)
106 gdbsim_store_register (regno
);
110 /* FIXME: Until read_register() returns LONGEST, we have this. */
111 char tmp
[MAX_REGISTER_RAW_SIZE
];
112 read_register_gen (regno
, tmp
);
113 sim_store_register (regno
, tmp
);
116 printf_filtered ("gdbsim_store_register: %d", regno
);
117 /* FIXME: We could print something more intelligible. */
118 dump_mem (tmp
, REGISTER_RAW_SIZE (regno
));
123 /* Kill the running program. This may involve closing any open files
124 and releasing other resources acquired by the simulated program. */
130 printf_filtered ("gdbsim_kill\n");
132 sim_kill (); /* close fd's, remove mappings */
136 /* Load an executable file into the target process. This is expected to
137 not only bring new code into the target process, but also to update
138 GDB's symbol tables to match. */
141 gdbsim_load (prog
, fromtty
)
146 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog
);
150 /* This must be done before calling gr_load_image. */
153 if (sim_load (prog
, fromtty
) != 0)
154 generic_load (prog
, fromtty
);
158 /* Start an inferior process and set inferior_pid to its pid.
159 EXEC_FILE is the file to run.
160 ALLARGS is a string containing the arguments to the program.
161 ENV is the environment vector to pass. Errors reported with error().
162 On VxWorks and various standalone systems, we ignore exec_file. */
163 /* This is called not only when we first attach, but also when the
164 user types "run" after having attached. */
167 gdbsim_create_inferior (exec_file
, args
, env
)
173 char *arg_buf
,**argv
;
176 if (! program_loaded
)
177 error ("No program loaded.");
180 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
183 if (exec_file
== 0 || exec_bfd
== 0)
184 error ("No exec file specified.");
186 entry_pt
= (CORE_ADDR
) bfd_get_start_address (exec_bfd
);
188 gdbsim_kill (NULL
, NULL
);
189 remove_breakpoints ();
190 init_wait_for_inferior ();
192 len
= 5 + strlen (exec_file
) + 1 + strlen (args
) + 1 + /*slop*/ 10;
193 arg_buf
= (char *) alloca (len
);
195 strcat (arg_buf
, exec_file
);
196 strcat (arg_buf
, " ");
197 strcat (arg_buf
, args
);
198 argv
= buildargv (arg_buf
);
199 make_cleanup (freeargv
, (char *) argv
);
200 sim_create_inferior (entry_pt
, argv
, env
);
203 insert_breakpoints (); /* Needed to get correct instruction in cache */
204 proceed (entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
207 /* The open routine takes the rest of the parameters from the command,
208 and (if successful) pushes a new target onto the stack.
209 Targets should supply this routine, if only to provide an error message. */
210 /* Called when selecting the simulator. EG: (gdb) target sim name. */
213 gdbsim_open (args
, from_tty
)
218 printf_filtered ("gdbsim_open: args \"%s\"\n", args
? args
: "(null)");
220 push_target (&gdbsim_ops
);
221 target_fetch_registers (-1);
222 printf_filtered ("Connected to the simulator.\n");
225 /* Does whatever cleanup is required for a target that we are no longer
226 going to be calling. Argument says whether we are quitting gdb and
227 should not get hung in case of errors, or whether we want a clean
228 termination even if it takes a while. This routine is automatically
229 always called just before a routine is popped off the target stack.
230 Closing file descriptors and freeing memory are typical things it should
232 /* Close out all files and local state before this target loses control. */
235 gdbsim_close (quitting
)
239 printf_filtered ("gdbsim_close: quitting %d\n", quitting
);
243 sim_close (quitting
);
246 /* Takes a program previously attached to and detaches it.
247 The program may resume execution (some targets do, some don't) and will
248 no longer stop on signals, etc. We better not have left any breakpoints
249 in the program or it'll die when it hits one. ARGS is arguments
250 typed by the user (e.g. a signal to send the process). FROM_TTY
251 says whether to be verbose or not. */
252 /* Terminate the open connection to the remote debugger.
253 Use this when you want to detach and do something else with your gdb. */
256 gdbsim_detach (args
,from_tty
)
261 printf_filtered ("gdbsim_detach: args \"%s\"\n", args
);
263 pop_target (); /* calls gdbsim_close to do the real work */
265 printf_filtered ("Ending simulator %s debugging\n", target_shortname
);
268 /* Resume execution of the target process. STEP says whether to single-step
269 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
270 to the target, or zero for no signal. */
273 gdbsim_resume (pid
, step
, siggnal
)
275 enum target_signal siggnal
;
278 printf_filtered ("gdbsim_resume: step %d, signal %d\n", step
, siggnal
);
280 sim_resume (step
, target_signal_to_host (siggnal
));
283 /* Wait for inferior process to do something. Return pid of child,
284 or -1 in case of error; store status through argument pointer STATUS,
285 just as `wait' would. */
288 gdbsim_wait (pid
, status
)
290 struct target_waitstatus
*status
;
293 enum sim_stop reason
;
296 printf_filtered ("gdbsim_wait\n");
298 sim_stop_reason (&reason
, &sigrc
);
302 status
->kind
= TARGET_WAITKIND_EXITED
;
303 status
->value
.integer
= sigrc
;
306 status
->kind
= TARGET_WAITKIND_STOPPED
;
307 /* The signal in sigrc is a host signal. That probably
309 status
->value
.sig
= target_signal_from_host (sigrc
);
312 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
313 /* The signal in sigrc is a host signal. That probably
315 status
->value
.sig
= target_signal_from_host (sigrc
);
322 /* Get ready to modify the registers array. On machines which store
323 individual registers, this doesn't need to do anything. On machines
324 which store all the registers in one fell swoop, this makes sure
325 that registers contains all the registers from the program being
329 gdbsim_prepare_to_store ()
331 /* Do nothing, since we can store individual regs */
335 gdbsim_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
340 struct target_ops
*target
; /* ignored */
342 if (! program_loaded
)
343 error ("No program loaded.");
347 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
348 myaddr
, memaddr
, len
, write
);
349 if (sr_get_debug () && write
)
350 dump_mem(myaddr
, len
);
355 len
= sim_write (memaddr
, myaddr
, len
);
359 len
= sim_read (memaddr
, myaddr
, len
);
360 if (sr_get_debug () && len
> 0)
361 dump_mem(myaddr
, len
);
367 gdbsim_files_info (target
)
368 struct target_ops
*target
;
370 char *file
= "nothing";
373 file
= bfd_get_filename (exec_bfd
);
376 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file
);
380 printf_filtered ("\tAttached to %s running program %s\n",
381 target_shortname
, file
);
386 /* Clear the simulator's notion of what the break points are. */
389 gdbsim_mourn_inferior ()
392 printf_filtered ("gdbsim_mourn_inferior:\n");
394 remove_breakpoints ();
395 generic_mourn_inferior ();
398 /* Put a command string, in args, out to MONITOR. Output from MONITOR
399 is placed on the users terminal until the prompt is seen. FIXME: We
400 read the characters ourseleves here cause of a nasty echo. */
403 simulator_command (args
, from_tty
)
407 sim_do_command (args
);
410 /* Define the target subroutine names */
412 struct target_ops gdbsim_ops
= {
413 "sim", /* to_shortname */
414 "simulator", /* to_longname */
415 "Use the compiled-in simulator.", /* to_doc */
416 gdbsim_open
, /* to_open */
417 gdbsim_close
, /* to_close */
418 NULL
, /* to_attach */
419 gdbsim_detach
, /* to_detach */
420 gdbsim_resume
, /* to_resume */
421 gdbsim_wait
, /* to_wait */
422 gdbsim_fetch_register
, /* to_fetch_registers */
423 gdbsim_store_register
, /* to_store_registers */
424 gdbsim_prepare_to_store
, /* to_prepare_to_store */
425 gdbsim_xfer_inferior_memory
, /* to_xfer_memory */
426 gdbsim_files_info
, /* to_files_info */
427 memory_insert_breakpoint
, /* to_insert_breakpoint */
428 memory_remove_breakpoint
, /* to_remove_breakpoint */
429 NULL
, /* to_terminal_init */
430 NULL
, /* to_terminal_inferior */
431 NULL
, /* to_terminal_ours_for_output */
432 NULL
, /* to_terminal_ours */
433 NULL
, /* to_terminal_info */
434 gdbsim_kill
, /* to_kill */
435 gdbsim_load
, /* to_load */
436 NULL
, /* to_lookup_symbol */
437 gdbsim_create_inferior
, /* to_create_inferior */
438 gdbsim_mourn_inferior
, /* to_mourn_inferior */
440 0, /* to_notice_signals */
441 0, /* to_thread_alive */
443 process_stratum
, /* to_stratum */
445 1, /* to_has_all_memory */
446 1, /* to_has_memory */
447 1, /* to_has_stack */
448 1, /* to_has_registers */
449 1, /* to_has_execution */
451 NULL
, /* sections_end */
452 OPS_MAGIC
, /* to_magic */
456 _initialize_remote_sim ()
458 add_target (&gdbsim_ops
);
460 add_com ("sim <command>", class_obscure
, simulator_command
,
461 "Send a command to the simulator.");