35 #include "gdb/callback.h"
36 #include "gdb/remote-sim.h"
41 #include "readline/readline.h"
103 static
const struct inferior_data *sim_inferior_data_key;
106 struct sim_inferior_data {
111 SIM_DESC gdbsim_desc;
121 enum gdb_signal resume_siggnal;
135 #define INITIAL_PID 42000
154 struct sim_inferior_data *sim_data;
155 SIM_DESC new_sim_desc = arg;
157 sim_data = inferior_data (inf, sim_inferior_data_key);
159 return (sim_data != NULL && sim_data->gdbsim_desc == new_sim_desc);
170 static struct sim_inferior_data *
173 SIM_DESC sim_desc = NULL;
174 struct sim_inferior_data *sim_data
175 = inferior_data (inf, sim_inferior_data_key);
182 && (sim_data == NULL || sim_data->gdbsim_desc == NULL))
186 if (sim_desc == NULL)
187 error (
_(
"Unable to create simulator instance for inferior %d."),
202 _(
"Inferior %d and inferior %d would have identical simulator state.\n"
203 "(This simulator does not support the running of more than one inferior.)"),
208 if (sim_data == NULL)
210 sim_data = XCNEW(
struct sim_inferior_data);
211 set_inferior_data (inf, sim_inferior_data_key, sim_data);
218 sim_data->program_loaded = 0;
219 sim_data->gdbsim_desc = sim_desc;
220 sim_data->resume_siggnal = GDB_SIGNAL_0;
221 sim_data->resume_step = 0;
227 sim_data->gdbsim_desc = sim_desc;
238 static struct sim_inferior_data *
260 struct sim_inferior_data *sim_data = data;
262 if (sim_data != NULL)
264 if (sim_data->gdbsim_desc)
266 sim_close (sim_data->gdbsim_desc, 0);
267 sim_data->gdbsim_desc = NULL;
278 if (len == 8 || len == 4)
282 memcpy (l, buf, len);
291 for (i = 0; i <
len; i++)
361 for (i = 0; i <
len; i++)
385 va_start (args, format);
409 gdb_os_error (host_callback * p,
const char *format, ...)
413 va_start (args, format);
431 struct sim_inferior_data *sim_data
459 static int warn_user = 1;
465 nr_bytes = sim_fetch_register (sim_data->gdbsim_desc,
474 "Size of register %s (%d/%d) "
475 "incorrect (%d instead of %d))",
492 "gdbsim_fetch_register: %d", regno);
507 struct sim_inferior_data *sim_data
522 nr_bytes = sim_store_register (sim_data->gdbsim_desc,
526 if (nr_bytes > 0 && nr_bytes !=
register_size (gdbarch, regno))
528 _(
"Register size different to expected"));
531 _(
"Register %d not updated"), regno);
533 warning (
_(
"Register %s not updated"),
568 struct sim_inferior_data *sim_data
577 prog = tilde_expand (argv[0]);
580 error (
_(
"GDB sim does not yet support a load offset."));
588 if (sim_load (sim_data->gdbsim_desc, prog, NULL, fromtty) == SIM_RC_FAIL)
589 error (
_(
"unable to load program"));
594 sim_data->program_loaded = 1;
608 char **env,
int from_tty)
610 struct sim_inferior_data *sim_data
613 char *arg_buf, **argv;
615 if (exec_file == 0 ||
exec_bfd == 0)
616 warning (
_(
"No executable file specified."));
617 if (!sim_data->program_loaded)
622 "gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n",
623 (exec_file ? exec_file :
"(NULL)"),
631 if (exec_file != NULL)
633 len = strlen (exec_file) + 1 + strlen (args) + 1 + 10;
634 arg_buf = (
char *) alloca (len);
636 strcat (arg_buf, exec_file);
637 strcat (arg_buf,
" ");
638 strcat (arg_buf, args);
648 if (sim_create_inferior (sim_data->gdbsim_desc,
exec_bfd, argv, env)
650 error (
_(
"Unable to create sim inferior."));
672 struct sim_inferior_data *sim_data;
674 SIM_DESC gdbsim_desc;
682 "gdbsim_open: args \"%s\"\n", args ? args :
"(null)");
695 + strlen (
" -E little")
696 + strlen (
" --architecture=xxxxxxxxxx")
697 + strlen (
" --sysroot=") + strlen (sysroot) +
698 + (args ? strlen (args) : 0)
700 arg_buf = (
char *) alloca (len);
701 strcpy (arg_buf,
"gdbsim");
707 strcat (arg_buf,
" -E big");
709 case BFD_ENDIAN_LITTLE:
710 strcat (arg_buf,
" -E little");
712 case BFD_ENDIAN_UNKNOWN:
719 strcat (arg_buf,
" --architecture=");
723 strcat (arg_buf,
" --sysroot=");
724 strcat (arg_buf, sysroot);
728 strcat (arg_buf,
" ");
729 strcat (arg_buf, args);
736 if (gdbsim_desc == 0)
740 error (
_(
"unable to create simulator instance"));
751 sim_data->gdbsim_desc = gdbsim_desc;
769 struct sim_inferior_data *sim_data = inferior_data (inf,
770 sim_inferior_data_key);
771 if (sim_data != NULL)
776 set_inferior_data (inf, sim_inferior_data_key, NULL);
798 struct sim_inferior_data *sim_data
850 struct sim_inferior_data *sim_data
856 sim_data->resume_siggnal = rd->
siggnal;
857 sim_data->resume_step = rd->
step;
861 _(
"gdbsim_resume: pid %d, step %d, signal %d\n"),
876 struct sim_inferior_data *sim_data
894 error (
_(
"The program is not being run."));
909 struct sim_inferior_data *sim_data
914 if (!sim_stop (sim_data->gdbsim_desc))
929 struct sim_inferior_data *sim_data;
940 error (
_(
"Can't stop pid %d. No inferior found."),
978 struct sim_inferior_data *sim_data;
981 enum sim_stop reason = sim_running;
992 if (sim_data == NULL)
993 error (
_(
"Unable to wait for pid %d. Inferior not found."),
1001 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
1003 struct sigaction sa, osa;
1005 sigemptyset (&sa.sa_mask);
1007 sigaction (SIGINT, &sa, &osa);
1008 prev_sigint = osa.sa_handler;
1013 sim_resume (sim_data->gdbsim_desc, sim_data->resume_step,
1014 sim_data->resume_siggnal);
1016 signal (SIGINT, prev_sigint);
1017 sim_data->resume_step = 0;
1019 sim_stop_reason (sim_data->gdbsim_desc, &reason, &sigrc);
1030 case GDB_SIGNAL_ABRT:
1033 case GDB_SIGNAL_INT:
1034 case GDB_SIGNAL_TRAP:
1074 struct sim_inferior_data *sim_data
1084 if (!sim_data->program_loaded)
1085 error (
_(
"No program loaded."));
1097 "gdbsim_xfer_memory: readbuf %s, writebuf %s, "
1098 "memaddr %s, len %s\n",
1108 l = sim_write (sim_data->gdbsim_desc, memaddr, writebuf, len);
1112 l = sim_read (sim_data->gdbsim_desc, memaddr, readbuf, len);
1131 const char *annex,
gdb_byte *readbuf,
1149 struct sim_inferior_data *sim_data
1151 const char *file =
"nothing";
1154 file = bfd_get_filename (
exec_bfd);
1163 sim_info (sim_data->gdbsim_desc, 0);
1172 struct sim_inferior_data *sim_data
1189 struct sim_inferior_data *sim_data;
1202 if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
1215 error (
_(
"Not connected to the simulator target"));
1218 sim_do_command (sim_data->gdbsim_desc, args);
1229 struct sim_inferior_data *sim_data;
1235 if (sim_data == NULL || sim_data->gdbsim_desc == NULL)
1238 tmp = sim_complete_command (sim_data->gdbsim_desc, text, word);
1243 for (i = 0; tmp[i] != NULL; i++)
1255 struct sim_inferior_data *sim_data
1258 if (sim_data == NULL)
1261 if (
ptid_equal (ptid, sim_data->remote_sim_ptid))
1282 struct sim_inferior_data *sim_data
1285 if (!sim_data->program_loaded)
1294 struct sim_inferior_data *sim_data
1297 if (!sim_data->program_loaded)
1350 _(
"Send a command to the simulator."));
1353 sim_inferior_data_key
void error_no_arg(const char *why)
struct gdbarch * target_gdbarch(void)
struct cleanup * make_cleanup_freeargv(char **arg)
void add_target(struct target_ops *t)
int default_child_has_stack(struct target_ops *ops)
static void sim_inferior_data_cleanup(struct inferior *inf, void *data)
static void gdbsim_stop(struct target_ops *self, ptid_t ptid)
static void gdbsim_detach(struct target_ops *ops, const char *args, int from_tty)
static enum target_xfer_status gdbsim_xfer_memory(struct target_ops *target, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
int one2one_register_sim_regno(struct gdbarch *gdbarch, int regnum)
int ptid_equal(ptid_t ptid1, ptid_t ptid2)
void insert_breakpoints(void)
void fputs_unfiltered(const char *buf, struct ui_file *file)
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
void clear_quit_flag(void)
int(* to_has_memory)(struct target_ops *)
void warning(const char *fmt,...)
char *(* to_pid_to_str)(struct target_ops *, ptid_t) TARGET_DEFAULT_FUNC(default_pid_to_str)
struct type ** const(pascal_builtin_types[])
void init_wait_for_inferior(void)
int(* to_has_stack)(struct target_ops *)
void push_target(struct target_ops *t)
int(* to_insert_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_insert_breakpoint)
void delete_thread_silent(ptid_t)
struct ui_file * gdb_stdout
int unpush_target(struct target_ops *t)
void simulator_command(char *args, int from_tty)
enum bfd_endian selected_byte_order(void)
void internal_error(const char *file, int line, const char *fmt,...)
void generic_mourn_inferior(void)
void(* to_close)(struct target_ops *)
void switch_to_thread(ptid_t ptid)
static int gdbsim_stop_inferior(struct inferior *inf, void *arg)
static host_callback gdb_callback
#define VEC_safe_push(T, V, O)
struct inferior * find_inferior_ptid(ptid_t ptid)
int(* to_remove_breakpoint)(struct target_ops *, struct gdbarch *, struct bp_target_info *) TARGET_DEFAULT_FUNC(memory_remove_breakpoint)
struct inferior * iterate_over_inferiors(int(*callback)(struct inferior *, void *), void *data)
int gdbarch_num_regs(struct gdbarch *gdbarch)
ptid_t(* to_wait)(struct target_ops *, ptid_t, struct target_waitstatus *, int TARGET_DEBUG_PRINTER(target_debug_print_options)) TARGET_DEFAULT_NORETURN(noprocess())
static int gdb_os_write_stderr(host_callback *, const char *, int)
static void gdbsim_files_info(struct target_ops *target)
int default_child_has_execution(struct target_ops *ops, ptid_t the_ptid)
static void gdb_os_flush_stderr(host_callback *)
static int gdbsim_resume_inferior(struct inferior *inf, void *arg)
void printf_filtered(const char *format,...)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
ptid_t ptid_build(int pid, long lwp, long tid)
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
#define TARGET_SYSROOT_PREFIX
const char * selected_architecture_name(void)
static int gdbsim_has_all_memory(struct target_ops *ops)
static void gdbsim_cntrl_c(int signo)
void void void void verror(const char *fmt, va_list args) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF(1
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
static void init_gdbsim_ops(void)
void vfprintf_filtered(struct ui_file *stream, const char *format, va_list args)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
void(* to_resume)(struct target_ops *, ptid_t, int TARGET_DEBUG_PRINTER(target_debug_print_step), enum gdb_signal) TARGET_DEFAULT_NORETURN(noprocess())
static void gdbsim_fetch_register(struct target_ops *ops, struct regcache *regcache, int regno)
static void gdbsim_resume(struct target_ops *ops, ptid_t ptid, int step, enum gdb_signal siggnal)
union target_waitstatus::@161 value
char * pulongest(ULONGEST u)
int(* to_has_execution)(struct target_ops *, ptid_t)
int gdbarch_register_sim_regno(struct gdbarch *gdbarch, int reg_nr)
struct inferior * find_inferior_pid(int pid)
static int gdb_os_poll_quit(host_callback *)
static void gdb_os_evprintf_filtered(host_callback *, const char *, va_list)
void target_mourn_inferior(void)
const char * gdbarch_register_name(struct gdbarch *gdbarch, int regnr)
struct thread_info * add_thread_silent(ptid_t ptid)
static void gdbsim_prepare_to_store(struct target_ops *self, struct regcache *regcache)
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
void(* to_detach)(struct target_ops *ops, const char *, int) TARGET_DEFAULT_IGNORE()
struct ui_file * gdb_stdlog
static int gdbsim_is_open
char * normal_pid_to_str(ptid_t ptid)
static void init_callbacks(void)
static void gdbsim_close(struct target_ops *self)
int ptid_get_pid(ptid_t ptid)
static void gdb_os_flush_stdout(host_callback *)
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
void(* to_mourn_inferior)(struct target_ops *) TARGET_DEFAULT_FUNC(default_mourn_inferior)
static int gdbsim_has_memory(struct target_ops *ops)
int default_child_has_registers(struct target_ops *ops)
void(* to_stop)(struct target_ops *, ptid_t) TARGET_DEFAULT_IGNORE()
void clear_proceed_status(int step)
int check_quit_flag(void)
enum target_waitkind kind
void(* to_kill)(struct target_ops *) TARGET_DEFAULT_NORETURN(noprocess())
struct ui_file * gdb_stderr
static void gdb_os_printf_filtered(host_callback *, const char *,...)
const char * host_address_to_string(const void *addr)
int remove_breakpoints(void)
static char * gdbsim_pid_to_str(struct target_ops *ops, ptid_t ptid)
void(* to_open)(const char *, int)
void ui_file_write(struct ui_file *file, const char *buf, long length_buf)
void registers_changed(void)
static struct sim_inferior_data * get_sim_inferior_data(struct inferior *inf, int sim_instance_needed)
enum register_status regcache_cooked_read(struct regcache *regcache, int regnum, gdb_byte *buf)
void(* to_create_inferior)(struct target_ops *, char *, char *, char **, int)
char ** gdb_buildargv(const char *s)
static struct sim_inferior_data * get_sim_inferior_data_by_ptid(ptid_t ptid, int sim_instance_needed)
struct ui_file * gdb_stdtarg
static void end_callbacks(void)
struct inferior * current_inferior(void)
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
const char * to_shortname
static void gdbsim_open(const char *args, int from_tty)
unsigned long long ULONGEST
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static int gdbsim_close_inferior(struct inferior *inf, void *arg)
int register_size(struct gdbarch *gdbarch, int regnum)
static void gdbsim_load(struct target_ops *self, const char *args, int fromtty)
static void gdb_os_error(host_callback *, const char *,...)
static void gdbsim_create_inferior(struct target_ops *target, char *exec_file, char *args, char **env, int from_tty)
int memory_insert_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
static void gdbsim_store_register(struct target_ops *ops, struct regcache *regcache, int regno)
int(* to_has_all_memory)(struct target_ops *)
int memory_remove_breakpoint(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
struct ui_file * gdb_stdtargerr
int(* to_thread_alive)(struct target_ops *, ptid_t ptid) TARGET_DEFAULT_RETURN(0)
static enum target_xfer_status gdbsim_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static int callbacks_initialized
static int check_for_duplicate_sim_descriptor(struct inferior *inf, void *arg)
void gdb_flush(struct ui_file *file)
void _initialize_remote_sim(void)
void(* to_prepare_to_store)(struct target_ops *, struct regcache *) TARGET_DEFAULT_NORETURN(noprocess())
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
static void gdbsim_kill(struct target_ops *ops)
int(* to_has_registers)(struct target_ops *)
static void gdbsim_mourn_inferior(struct target_ops *target)
int is_target_filename(const char *name)
struct target_ops gdbsim_ops
static void dump_mem(const gdb_byte *buf, int len)
void error(const char *fmt,...)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
static ptid_t gdbsim_wait(struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void inferior_appeared(struct inferior *inf, int pid)
void(* to_load)(struct target_ops *, const char *, int) TARGET_DEFAULT_NORETURN(tcomplain())
static int gdbsim_thread_alive(struct target_ops *ops, ptid_t ptid)
int(* deprecated_ui_loop_hook)(int signo)
void init_thread_list(void)
static int gdb_os_write_stdout(host_callback *, const char *, int)
static void gdb_os_vprintf_filtered(host_callback *, const char *, va_list)
const ULONGEST const LONGEST len