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"
41 sim_* are the interface to the simulator (see remote-sim.h).
42 sim_callback_* are the stuff which the simulator can see inside GDB.
43 gdbsim_* are stuff which is internal to gdb. */
45 /* Forward data declarations */
46 extern struct target_ops gdbsim_ops
;
48 static int program_loaded
= 0;
57 if (len
== 8 || len
== 4)
61 printf_filtered ("\t0x%x", l
[0]);
62 printf_filtered (len
== 8 ? " 0x%x\n" : "\n", l
[1]);
67 printf_filtered ("\t");
68 for (i
= 0; i
< len
; i
++)
69 printf_filtered ("0x%x ", buf
[i
]);
70 printf_filtered ("\n");
76 gdbsim_fetch_register (regno
)
81 for (regno
= 0; regno
< NUM_REGS
; regno
++)
82 gdbsim_fetch_register (regno
);
86 char buf
[MAX_REGISTER_RAW_SIZE
];
88 sim_fetch_register (regno
, buf
);
89 supply_register (regno
, buf
);
92 printf_filtered ("gdbsim_fetch_register: %d", regno
);
93 /* FIXME: We could print something more intelligible. */
94 dump_mem (buf
, REGISTER_RAW_SIZE (regno
));
101 gdbsim_store_register (regno
)
106 for (regno
= 0; regno
< NUM_REGS
; regno
++)
107 gdbsim_store_register (regno
);
111 /* FIXME: Until read_register() returns LONGEST, we have this. */
112 char tmp
[MAX_REGISTER_RAW_SIZE
];
113 read_register_gen (regno
, tmp
);
114 sim_store_register (regno
, tmp
);
117 printf_filtered ("gdbsim_store_register: %d", regno
);
118 /* FIXME: We could print something more intelligible. */
119 dump_mem (tmp
, REGISTER_RAW_SIZE (regno
));
124 /* Kill the running program. This may involve closing any open files
125 and releasing other resources acquired by the simulated program. */
131 printf_filtered ("gdbsim_kill\n");
133 sim_kill (); /* close fd's, remove mappings */
137 /* Load an executable file into the target process. This is expected to
138 not only bring new code into the target process, but also to update
139 GDB's symbol tables to match. */
142 gdbsim_load (prog
, fromtty
)
147 printf_filtered ("gdbsim_load: prog \"%s\"\n", prog
);
151 /* This must be done before calling gr_load_image. */
154 if (sim_load (prog
, fromtty
) != 0)
155 generic_load (prog
, fromtty
);
159 /* Start an inferior process and set inferior_pid to its pid.
160 EXEC_FILE is the file to run.
161 ALLARGS is a string containing the arguments to the program.
162 ENV is the environment vector to pass. Errors reported with error().
163 On VxWorks and various standalone systems, we ignore exec_file. */
164 /* This is called not only when we first attach, but also when the
165 user types "run" after having attached. */
168 gdbsim_create_inferior (exec_file
, args
, env
)
174 char *arg_buf
,**argv
;
177 if (! program_loaded
)
178 error ("No program loaded.");
181 printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
184 if (exec_file
== 0 || exec_bfd
== 0)
185 error ("No exec file specified.");
187 entry_pt
= (CORE_ADDR
) bfd_get_start_address (exec_bfd
);
189 gdbsim_kill (NULL
, NULL
);
190 remove_breakpoints ();
191 init_wait_for_inferior ();
193 len
= 5 + strlen (exec_file
) + 1 + strlen (args
) + 1 + /*slop*/ 10;
194 arg_buf
= (char *) alloca (len
);
196 strcat (arg_buf
, exec_file
);
197 strcat (arg_buf
, " ");
198 strcat (arg_buf
, args
);
199 argv
= buildargv (arg_buf
);
200 make_cleanup (freeargv
, (char *) argv
);
201 sim_create_inferior (entry_pt
, argv
, env
);
204 insert_breakpoints (); /* Needed to get correct instruction in cache */
205 proceed (entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
208 /* The open routine takes the rest of the parameters from the command,
209 and (if successful) pushes a new target onto the stack.
210 Targets should supply this routine, if only to provide an error message. */
211 /* Called when selecting the simulator. EG: (gdb) target sim name. */
214 gdbsim_open (args
, from_tty
)
219 printf_filtered ("gdbsim_open: args \"%s\"\n", args
? args
: "(null)");
221 push_target (&gdbsim_ops
);
222 target_fetch_registers (-1);
223 printf_filtered ("Connected to the simulator.\n");
226 /* Does whatever cleanup is required for a target that we are no longer
227 going to be calling. Argument says whether we are quitting gdb and
228 should not get hung in case of errors, or whether we want a clean
229 termination even if it takes a while. This routine is automatically
230 always called just before a routine is popped off the target stack.
231 Closing file descriptors and freeing memory are typical things it should
233 /* Close out all files and local state before this target loses control. */
236 gdbsim_close (quitting
)
240 printf_filtered ("gdbsim_close: quitting %d\n", quitting
);
244 sim_close (quitting
);
247 /* Takes a program previously attached to and detaches it.
248 The program may resume execution (some targets do, some don't) and will
249 no longer stop on signals, etc. We better not have left any breakpoints
250 in the program or it'll die when it hits one. ARGS is arguments
251 typed by the user (e.g. a signal to send the process). FROM_TTY
252 says whether to be verbose or not. */
253 /* Terminate the open connection to the remote debugger.
254 Use this when you want to detach and do something else with your gdb. */
257 gdbsim_detach (args
,from_tty
)
262 printf_filtered ("gdbsim_detach: args \"%s\"\n", args
);
264 pop_target (); /* calls gdbsim_close to do the real work */
266 printf_filtered ("Ending simulator %s debugging\n", target_shortname
);
269 /* Resume execution of the target process. STEP says whether to single-step
270 or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
271 to the target, or zero for no signal. */
274 gdbsim_resume (pid
, step
, siggnal
)
276 enum target_signal siggnal
;
279 printf_filtered ("gdbsim_resume: step %d, signal %d\n", step
, siggnal
);
281 sim_resume (step
, target_signal_to_host (siggnal
));
284 /* Wait for inferior process to do something. Return pid of child,
285 or -1 in case of error; store status through argument pointer STATUS,
286 just as `wait' would. */
289 gdbsim_wait (pid
, status
)
291 struct target_waitstatus
*status
;
294 enum sim_stop reason
;
297 printf_filtered ("gdbsim_wait\n");
299 sim_stop_reason (&reason
, &sigrc
);
303 status
->kind
= TARGET_WAITKIND_EXITED
;
304 status
->value
.integer
= sigrc
;
307 status
->kind
= TARGET_WAITKIND_STOPPED
;
308 /* The signal in sigrc is a host signal. That probably
310 status
->value
.sig
= target_signal_from_host (sigrc
);
313 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
314 /* The signal in sigrc is a host signal. That probably
316 status
->value
.sig
= target_signal_from_host (sigrc
);
323 /* Get ready to modify the registers array. On machines which store
324 individual registers, this doesn't need to do anything. On machines
325 which store all the registers in one fell swoop, this makes sure
326 that registers contains all the registers from the program being
330 gdbsim_prepare_to_store ()
332 /* Do nothing, since we can store individual regs */
336 gdbsim_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
341 struct target_ops
*target
; /* ignored */
343 if (! program_loaded
)
344 error ("No program loaded.");
348 printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x%x, memaddr 0x%x, len %d, write %d\n",
349 myaddr
, memaddr
, len
, write
);
350 if (sr_get_debug () && write
)
351 dump_mem(myaddr
, len
);
356 len
= sim_write (memaddr
, myaddr
, len
);
360 len
= sim_read (memaddr
, myaddr
, len
);
361 if (sr_get_debug () && len
> 0)
362 dump_mem(myaddr
, len
);
368 gdbsim_files_info (target
)
369 struct target_ops
*target
;
371 char *file
= "nothing";
374 file
= bfd_get_filename (exec_bfd
);
377 printf_filtered ("gdbsim_files_info: file \"%s\"\n", file
);
381 printf_filtered ("\tAttached to %s running program %s\n",
382 target_shortname
, file
);
387 /* Clear the simulator's notion of what the break points are. */
390 gdbsim_mourn_inferior ()
393 printf_filtered ("gdbsim_mourn_inferior:\n");
395 remove_breakpoints ();
396 generic_mourn_inferior ();
399 /* Put a command string, in args, out to MONITOR. Output from MONITOR
400 is placed on the users terminal until the prompt is seen. FIXME: We
401 read the characters ourseleves here cause of a nasty echo. */
404 simulator_command (args
, from_tty
)
408 sim_do_command (args
);
411 /* Define the target subroutine names */
413 struct target_ops gdbsim_ops
= {
414 "sim", /* to_shortname */
415 "simulator", /* to_longname */
416 "Use the compiled-in simulator.", /* to_doc */
417 gdbsim_open
, /* to_open */
418 gdbsim_close
, /* to_close */
419 NULL
, /* to_attach */
420 gdbsim_detach
, /* to_detach */
421 gdbsim_resume
, /* to_resume */
422 gdbsim_wait
, /* to_wait */
423 gdbsim_fetch_register
, /* to_fetch_registers */
424 gdbsim_store_register
, /* to_store_registers */
425 gdbsim_prepare_to_store
, /* to_prepare_to_store */
426 gdbsim_xfer_inferior_memory
, /* to_xfer_memory */
427 gdbsim_files_info
, /* to_files_info */
428 memory_insert_breakpoint
, /* to_insert_breakpoint */
429 memory_remove_breakpoint
, /* to_remove_breakpoint */
430 NULL
, /* to_terminal_init */
431 NULL
, /* to_terminal_inferior */
432 NULL
, /* to_terminal_ours_for_output */
433 NULL
, /* to_terminal_ours */
434 NULL
, /* to_terminal_info */
435 gdbsim_kill
, /* to_kill */
436 gdbsim_load
, /* to_load */
437 NULL
, /* to_lookup_symbol */
438 gdbsim_create_inferior
, /* to_create_inferior */
439 gdbsim_mourn_inferior
, /* to_mourn_inferior */
441 0, /* to_notice_signals */
442 0, /* to_thread_alive */
444 process_stratum
, /* to_stratum */
446 1, /* to_has_all_memory */
447 1, /* to_has_memory */
448 1, /* to_has_stack */
449 1, /* to_has_registers */
450 1, /* to_has_execution */
452 NULL
, /* sections_end */
453 OPS_MAGIC
, /* to_magic */
457 _initialize_remote_sim ()
459 add_target (&gdbsim_ops
);
461 add_com ("sim <command>", class_obscure
, simulator_command
,
462 "Send a command to the simulator.");
464 sim_set_callbacks (&default_callback
);
465 default_callback
.init (&default_callback
);