static ptid_t gdbsim_wait (ptid_t ptid, struct target_waitstatus *status) { static RETSIGTYPE (*prev_sigint) (); int sigrc = 0; enum sim_stop reason = sim_running; if (sr_get_debug ()) printf_filtered ("gdbsim_wait\n"); #if defined (HAVE_SIGACTION) && defined (SA_RESTART) { struct sigaction sa, osa; sa.sa_handler = gdbsim_cntrl_c; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sigaction (SIGINT, &sa, &osa); prev_sigint = osa.sa_handler; } #else prev_sigint = signal (SIGINT, gdbsim_cntrl_c); #endif sim_resume (gdbsim_desc, resume_step, resume_siggnal); signal (SIGINT, prev_sigint); resume_step = 0; sim_stop_reason (gdbsim_desc, &reason, &sigrc); switch (reason) { case sim_exited: status->kind = TARGET_WAITKIND_EXITED; status->value.integer = sigrc; break; case sim_stopped: switch (sigrc) { case TARGET_SIGNAL_ABRT: quit (); break; case TARGET_SIGNAL_INT: case TARGET_SIGNAL_TRAP: default: status->kind = TARGET_WAITKIND_STOPPED; status->value.sig = sigrc; break; } break; case sim_signalled: status->kind = TARGET_WAITKIND_SIGNALLED; status->value.sig = sigrc; break; case sim_running: case sim_polling: /* FIXME: Is this correct? */ break; } return inferior_ptid; }
void myresume (int step, int signo) { /* Should be using target_signal_to_host() or signal numbers in target.h * to convert GDB signal number to target signal number. */ sim_resume (gdbsim_desc, step, signo); }
int create_inferior (char *program, char **argv) { bfd *abfd; int pid = 0; char **new_argv; int nargs; abfd = bfd_openr (program, 0); if (!abfd) { fprintf (stderr, "gdbserver: cannot open %s: %s\n", program, bfd_errmsg (bfd_get_error ())); exit (1); } if (!bfd_check_format (abfd, bfd_object)) { fprintf (stderr, "gdbserver: unknown load format for %s: %s\n", program, bfd_errmsg (bfd_get_error ())); exit (1); } /* Add "-E big" or "-E little" to the argument list depending on the endianness of the program to be loaded. */ for (nargs = 0; argv[nargs] != NULL; nargs++) /* count the args */ ; new_argv = alloca (sizeof (char *) * (nargs + 3)); /* allocate new args */ for (nargs = 0; argv[nargs] != NULL; nargs++) /* copy old to new */ new_argv[nargs] = argv[nargs]; new_argv[nargs] = "-E"; new_argv[nargs + 1] = bfd_big_endian (abfd) ? "big" : "little"; new_argv[nargs + 2] = NULL; argv = new_argv; /* Create an instance of the simulator. */ default_callback.init (&default_callback); gdbsim_desc = sim_open (SIM_OPEN_STANDALONE, &default_callback, abfd, argv); if (gdbsim_desc == 0) exit (1); /* Load the program into the simulator. */ if (abfd) if (sim_load (gdbsim_desc, program, NULL, 0) == SIM_RC_FAIL) mygeneric_load (abfd); /* Create an inferior process in the simulator. This initializes SP. */ sim_create_inferior (gdbsim_desc, abfd, argv, /* env */ NULL); sim_resume (gdbsim_desc, 1, 0); /* execute one instr */ return pid; }
int main (int argc, char **argv) { char *name; char **prog_argv = NULL; struct bfd *prog_bfd; enum sim_stop reason; int sigrc = 0; int single_step = 0; RETSIGTYPE (*prev_sigint) (); myname = argv[0] + strlen (argv[0]); while (myname > argv[0] && myname[-1] != '/') --myname; /* INTERNAL: When MYNAME is `step', single step the simulator instead of allowing it to run free. The sole purpose of this HACK is to allow the sim_resume interface's step argument to be tested without having to build/run gdb. */ if (strlen (myname) > 4 && strcmp (myname - 4, "step") == 0) { single_step = 1; } /* Create an instance of the simulator. */ default_callback.init (&default_callback); sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, NULL, argv); if (sd == 0) exit (1); if (STATE_MAGIC (sd) != SIM_MAGIC_NUMBER) { fprintf (stderr, "Internal error - bad magic number in simulator struct\n"); abort (); } /* We can't set the endianness in the callback structure until sim_config is called, which happens in sim_open. */ default_callback.target_endian = (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); /* Was there a program to run? */ prog_argv = STATE_PROG_ARGV (sd); prog_bfd = STATE_PROG_BFD (sd); if (prog_argv == NULL || *prog_argv == NULL) usage (); name = *prog_argv; /* For simulators that don't open prog during sim_open() */ if (prog_bfd == NULL) { prog_bfd = bfd_openr (name, 0); if (prog_bfd == NULL) { fprintf (stderr, "%s: can't open \"%s\": %s\n", myname, name, bfd_errmsg (bfd_get_error ())); exit (1); } if (!bfd_check_format (prog_bfd, bfd_object)) { fprintf (stderr, "%s: \"%s\" is not an object file: %s\n", myname, name, bfd_errmsg (bfd_get_error ())); exit (1); } } if (STATE_VERBOSE_P (sd)) printf ("%s %s\n", myname, name); /* Load the program into the simulator. */ if (sim_load (sd, name, prog_bfd, 0) == SIM_RC_FAIL) exit (1); /* Prepare the program for execution. */ #ifdef HAVE_ENVIRON sim_create_inferior (sd, prog_bfd, prog_argv, environ); #else sim_create_inferior (sd, prog_bfd, prog_argv, NULL); #endif /* To accommodate relative file paths, chdir to sysroot now. We mustn't do this until BFD has opened the program, else we wouldn't find the executable if it has a relative file path. */ if (simulator_sysroot[0] != '\0' && chdir (simulator_sysroot) < 0) { fprintf (stderr, "%s: can't change directory to \"%s\"\n", myname, simulator_sysroot); exit (1); } /* Run/Step the program. */ if (single_step) { do { prev_sigint = signal (SIGINT, cntrl_c); sim_resume (sd, 1/*step*/, 0); signal (SIGINT, prev_sigint); sim_stop_reason (sd, &reason, &sigrc); if ((reason == sim_stopped) && (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) break; /* exit on control-C */ } /* remain on breakpoint or signals in oe mode*/ while (((reason == sim_signalled) && (sigrc == sim_signal_to_host (sd, SIM_SIGTRAP))) || ((reason == sim_stopped) && (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT))); } else { do { #if defined (HAVE_SIGACTION) && defined (SA_RESTART) struct sigaction sa, osa; sa.sa_handler = cntrl_c; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sigaction (SIGINT, &sa, &osa); prev_sigint = osa.sa_handler; #else prev_sigint = signal (SIGINT, cntrl_c); #endif sim_resume (sd, 0, sigrc); signal (SIGINT, prev_sigint); sim_stop_reason (sd, &reason, &sigrc); if ((reason == sim_stopped) && (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) break; /* exit on control-C */ /* remain on signals in oe mode */ } while ((reason == sim_stopped) && (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)); } /* Print any stats the simulator collected. */ if (STATE_VERBOSE_P (sd)) sim_info (sd, 0); /* Shutdown the simulator. */ sim_close (sd, 0); /* If reason is sim_exited, then sigrc holds the exit code which we want to return. If reason is sim_stopped or sim_signalled, then sigrc holds the signal that the simulator received; we want to return that to indicate failure. */ /* Why did we stop? */ switch (reason) { case sim_signalled: case sim_stopped: if (sigrc != 0) fprintf (stderr, "program stopped with signal %d.\n", sigrc); break; case sim_exited: break; default: fprintf (stderr, "program in undefined state (%d:%d)\n", reason, sigrc); break; } return sigrc; }
int sim_trace (SIM_DESC sd) { sim_resume (sd, 0, 0); return 1; }
int main (int argc, char **argv) { int ret; sky_pref_t* pref = get_skyeye_pref(); assert(pref != NULL); /* initialization of options from command line */ ret = init_option(argc, argv, pref); /* set the current preference for skyeye */ //update_skyeye_pref(pref); /* return non-zero represent not run skyeye */ if(ret != 0) exit(0); else SIM_init(); /* Do anything you want to do , or just deadloop here. */ while(1) ; #if 0 if(ret < 0) goto exit_skyeye; /* set some environment for running */ init_env(); /* initialization of all the data structure of simulation */ if((ret = init ()) < 0) goto exit_skyeye; #endif #if 0 /* load elf file when running elf image */ if (exec_file) { if (tea_load_exec (exec_file, 0)) { fprintf (stderr, "load \"%s\" error\n", exec_file); goto exit_skyeye; } #if !defined(__MINGW32__) /* get its symbol to debug */ init_symbol_table(exec_file); #endif } #endif /* set the start address for pc */ #if 0 if (skyeye_config.start_address != 0){ unsigned long addr = (skyeye_config.start_address & load_mask)|load_base; arch_instance->set_pc (addr); printf ("start addr is set to 0x%08x by exec file.\n", (unsigned int) addr); } #endif /* never return */ //SIM_start(); //fflush(stdout); #if 0 /* running simulaion */ if (remote_debugmode == 0) sim_resume (0); else{ printf ("remote_debugmode= %d, filename = %s, server TCP port is 12345\n", remote_debugmode, skyeye_config_filename); sim_debug (); } #endif exit_skyeye: return ret; }