static void gdbsim_create_inferior (char *exec_file, char *args, char **env) { int len; char *arg_buf, **argv; if (exec_file == 0 || exec_bfd == 0) warning ("No executable file specified."); if (!program_loaded) warning ("No program loaded."); if (sr_get_debug ()) printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n", (exec_file ? exec_file : "(NULL)"), args); gdbsim_kill (); remove_breakpoints (); init_wait_for_inferior (); if (exec_file != NULL) { len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; arg_buf = (char *) alloca (len); arg_buf[0] = '\0'; strcat (arg_buf, exec_file); strcat (arg_buf, " "); strcat (arg_buf, args); argv = buildargv (arg_buf); make_cleanup_freeargv (argv); } else argv = NULL; sim_create_inferior (gdbsim_desc, exec_bfd, argv, env); inferior_ptid = pid_to_ptid (42); insert_breakpoints (); /* Needed to get correct instruction in cache */ clear_proceed_status (); /* NB: Entry point already set by sim_create_inferior. */ proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); }
static void gdbsim_create_inferior (char *exec_file, char *args, char **env, int from_tty) { int len; char *arg_buf, **argv; if (exec_file == 0 || exec_bfd == 0) warning (_("No executable file specified.")); if (!program_loaded) warning (_("No program loaded.")); if (remote_debug) printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n", (exec_file ? exec_file : "(NULL)"), args); gdbsim_kill (); remove_breakpoints (); init_wait_for_inferior (); if (exec_file != NULL) { len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; arg_buf = (char *) alloca (len); arg_buf[0] = '\0'; strcat (arg_buf, exec_file); strcat (arg_buf, " "); strcat (arg_buf, args); argv = buildargv (arg_buf); make_cleanup_freeargv (argv); } else argv = NULL; sim_create_inferior (gdbsim_desc, exec_bfd, argv, env); inferior_ptid = pid_to_ptid (42); target_mark_running (&gdbsim_ops); insert_breakpoints (); /* Needed to get correct instruction in cache */ clear_proceed_status (); }
static void e7000_create_inferior (char *execfile, char *args, char **env, int from_tty) { int entry_pt; if (args && *args) error (_("Can't pass arguments to remote E7000DEBUG process")); if (execfile == 0 || exec_bfd == 0) error (_("No executable file specified")); entry_pt = (int) bfd_get_start_address (exec_bfd); #ifdef CREATE_INFERIOR_HOOK CREATE_INFERIOR_HOOK (0); /* No process-ID */ #endif /* The "process" (board) is already stopped awaiting our commands, and the program is already downloaded. We just set its PC and go. */ clear_proceed_status (); /* Tell wait_for_inferior that we've started a new process. */ init_wait_for_inferior (); /* Set up the "saved terminal modes" of the inferior based on what modes we are starting it with. */ target_terminal_init (); /* Install inferior's terminal modes. */ target_terminal_inferior (); /* insert_step_breakpoint (); FIXME, do we need this? */ proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */ }
void startup_inferior (int ntraps) { int pending_execs = ntraps; int terminal_initted = 0; /* The process was started by the fork that created it, but it will have stopped one instruction after execing the shell. Here we must get it up to actual execution of the real program. */ clear_proceed_status (); init_wait_for_inferior (); if (STARTUP_WITH_SHELL) inferior_ignoring_startup_exec_events = ntraps; else inferior_ignoring_startup_exec_events = 0; inferior_ignoring_leading_exec_events = target_reported_exec_events_per_exec_call () - 1; while (1) { /* Make wait_for_inferior be quiet. */ stop_soon = STOP_QUIETLY; wait_for_inferior (); if (stop_signal != TARGET_SIGNAL_TRAP) { /* Let shell child handle its own signals in its own way. FIXME: what if child has exited? Must exit loop somehow. */ resume (0, stop_signal); } else { /* We handle SIGTRAP, however; it means child did an exec. */ if (!terminal_initted) { /* Now that the child has exec'd we know it has already set its process group. On POSIX systems, tcsetpgrp will fail with EPERM if we try it before the child's setpgid. */ /* Set up the "saved terminal modes" of the inferior based on what modes we are starting it with. */ target_terminal_init (); /* Install inferior's terminal modes. */ target_terminal_inferior (); terminal_initted = 1; } if (--pending_execs == 0) break; resume (0, TARGET_SIGNAL_0); /* Just make it go on. */ } } stop_soon = NO_STOP_QUIETLY; }
static void haiku_init_child_debugging (thread_id threadID, bool debugThread) { thread_info threadInfo; status_t result; port_id nubPort; // get a thread info result = get_thread_info(threadID, &threadInfo); if (result != B_OK) error("Thread with ID %ld not found: %s", threadID, strerror(result)); // init our team debug structure sTeamDebugInfo.team = threadInfo.team; sTeamDebugInfo.debugger_port = -1; sTeamDebugInfo.context.nub_port = -1; sTeamDebugInfo.context.reply_port = -1; sTeamDebugInfo.threads = NULL; sTeamDebugInfo.events.head = NULL; sTeamDebugInfo.events.tail = NULL; // create the debugger port sTeamDebugInfo.debugger_port = create_port(10, "gdb debug"); if (sTeamDebugInfo.debugger_port < 0) { error("Failed to create debugger port: %s", strerror(sTeamDebugInfo.debugger_port)); } // install ourselves as the team debugger nubPort = install_team_debugger(sTeamDebugInfo.team, sTeamDebugInfo.debugger_port); if (nubPort < 0) { error("Failed to install ourselves as debugger for team %ld: %s", sTeamDebugInfo.team, strerror(nubPort)); } // get the nub thread { team_info teamInfo; result = get_team_info(sTeamDebugInfo.team, &teamInfo); if (result != B_OK) { error("Failed to get info for team %ld: %s\n", sTeamDebugInfo.team, strerror(result)); } sTeamDebugInfo.nub_thread = teamInfo.debugger_nub_thread; } // init the debug context result = init_debug_context(&sTeamDebugInfo.context, sTeamDebugInfo.team, nubPort); if (result != B_OK) { error("Failed to init debug context for team %ld: %s\n", sTeamDebugInfo.team, strerror(result)); } // start debugging the thread if (debugThread) { result = debug_thread(threadID); if (result != B_OK) { error("Failed to start debugging thread %ld: %s", threadID, strerror(result)); } } // set the team debug flags { debug_nub_set_team_flags message; message.flags = B_TEAM_DEBUG_SIGNALS /*| B_TEAM_DEBUG_PRE_SYSCALL | B_TEAM_DEBUG_POST_SYSCALL*/ | B_TEAM_DEBUG_TEAM_CREATION | B_TEAM_DEBUG_THREADS | B_TEAM_DEBUG_IMAGES; // TODO: We probably don't need all events haiku_send_debugger_message(&sTeamDebugInfo, B_DEBUG_MESSAGE_SET_TEAM_FLAGS, &message, sizeof(message), NULL, 0); } // the fun can start: push the target and init the rest push_target(sHaikuTarget); haiku_init_thread_list(&sTeamDebugInfo); haiku_init_image_list(&sTeamDebugInfo); disable_breakpoints_in_shlibs (1); // child_clear_solibs (); // TODO: Implement? Do we need this? clear_proceed_status (); init_wait_for_inferior (); target_terminal_init (); target_terminal_inferior (); }
static void haiku_init_debug_create_inferior(int pid) { extern int stop_after_trap; // fix inferior_ptid -- fork_inferior() sets the process ID only inferior_ptid = ptid_build (pid, 0, pid); // team ID == team main thread ID under Haiku haiku_init_child_debugging(pid, false); // eat the initial `debugged' event caused by wait_for_inferior() // TODO: Maybe we should just dequeue the event and continue the thread instead // of using gdb's mechanism, since I don't know what undesired side-effects // they may have. clear_proceed_status (); init_wait_for_inferior (); if (STARTUP_WITH_SHELL) inferior_ignoring_startup_exec_events = 2; else inferior_ignoring_startup_exec_events = 1; inferior_ignoring_leading_exec_events = 0; while (true) { thread_debug_info *thread; stop_soon = STOP_QUIETLY; wait_for_inferior(); if (stop_signal == TARGET_SIGNAL_TRAP) { thread = haiku_find_thread(&sTeamDebugInfo, pid); if (thread && thread->stopped && thread->last_event->message == B_DEBUGGER_MESSAGE_IMAGE_CREATED && thread->last_event->data.image_created.info.type == B_APP_IMAGE && thread->reprocess_event == 0 && inferior_ignoring_startup_exec_events <= 0) { // This is the trap for the last (second, if started via shell) // `load app image' event. Be done. break; } } resume(0, stop_signal); } stop_soon = NO_STOP_QUIETLY; // load shared library symbols target_terminal_ours_for_output (); SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); target_terminal_inferior (); // startup_inferior (START_INFERIOR_TRAPS_EXPECTED); //while (1) { // stop_after_trap = 1; // wait_for_inferior (); // if (debugThread && stop_signal != TARGET_SIGNAL_TRAP) // resume (0, stop_signal); // else // break; //} //stop_after_trap = 0; // while (1) { // thread_debug_info *thread; // // stop_after_trap = 1; // wait_for_inferior (); //// TODO: Catch deadly events, so that we won't block here. // // thread = haiku_find_thread(&sTeamDebugInfo, pid); //TRACE(("haiku_init_debug_create_inferior(): wait_for_inferior() returned: " //"thread: %p (%ld)\n", thread, (thread ? thread->thread : -1))); // if (thread && thread->stopped // && thread->last_event->message // == B_DEBUGGER_MESSAGE_IMAGE_CREATED // && thread->last_event->data.image_created.info.type // == B_APP_IMAGE) { //TRACE(("haiku_init_debug_create_inferior(): Got an `app image created' " //"message\n")); // break; // } // // resume (0, stop_signal); // } }