void display_gdb_prompt (const char *new_prompt) { std::string actual_gdb_prompt; annotate_display_prompt (); /* Reset the nesting depth used when trace-commands is set. */ reset_command_nest_depth (); /* Do not call the python hook on an explicit prompt change as passed to this function, as this forms a secondary/local prompt, IE, displayed but not set. */ if (! new_prompt) { struct ui *ui = current_ui; if (ui->prompt_state == PROMPTED) internal_error (__FILE__, __LINE__, _("double prompt")); else if (ui->prompt_state == PROMPT_BLOCKED) { /* This is to trick readline into not trying to display the prompt. Even though we display the prompt using this function, readline still tries to do its own display if we don't call rl_callback_handler_install and rl_callback_handler_remove (which readline detects because a global variable is not set). If readline did that, it could mess up gdb signal handlers for SIGINT. Readline assumes that between calls to rl_set_signals and rl_clear_signals gdb doesn't do anything with the signal handlers. Well, that's not the case, because when the target executes we change the SIGINT signal handler. If we allowed readline to display the prompt, the signal handler change would happen exactly between the calls to the above two functions. Calling rl_callback_handler_remove(), does the job. */ if (current_ui->command_editing) gdb_rl_callback_handler_remove (); return; } else if (ui->prompt_state == PROMPT_NEEDED) { /* Display the top level prompt. */ actual_gdb_prompt = top_level_prompt (); ui->prompt_state = PROMPTED; } } else actual_gdb_prompt = new_prompt; if (current_ui->command_editing) { gdb_rl_callback_handler_remove (); gdb_rl_callback_handler_install (actual_gdb_prompt.c_str ()); } /* new_prompt at this point can be the top of the stack or the one passed in. It can't be NULL. */ else { /* Don't use a _filtered function here. It causes the assumed character position to be off, since the newline we read from the user is not accounted for. */ fputs_unfiltered (actual_gdb_prompt.c_str (), gdb_stdout); gdb_flush (gdb_stdout); } }
void display_gdb_prompt (char *new_prompt) { char *actual_gdb_prompt = NULL; struct cleanup *old_chain; annotate_display_prompt (); /* Reset the nesting depth used when trace-commands is set. */ reset_command_nest_depth (); /* Each interpreter has its own rules on displaying the command prompt. */ if (!current_interp_display_prompt_p ()) return; old_chain = make_cleanup (free_current_contents, &actual_gdb_prompt); /* Do not call the python hook on an explicit prompt change as passed to this function, as this forms a secondary/local prompt, IE, displayed but not set. */ if (! new_prompt) { if (sync_execution) { /* This is to trick readline into not trying to display the prompt. Even though we display the prompt using this function, readline still tries to do its own display if we don't call rl_callback_handler_install and rl_callback_handler_remove (which readline detects because a global variable is not set). If readline did that, it could mess up gdb signal handlers for SIGINT. Readline assumes that between calls to rl_set_signals and rl_clear_signals gdb doesn't do anything with the signal handlers. Well, that's not the case, because when the target executes we change the SIGINT signal handler. If we allowed readline to display the prompt, the signal handler change would happen exactly between the calls to the above two functions. Calling rl_callback_handler_remove(), does the job. */ rl_callback_handler_remove (); do_cleanups (old_chain); return; } else { /* Display the top level prompt. */ actual_gdb_prompt = top_level_prompt (); } } else actual_gdb_prompt = xstrdup (new_prompt); if (async_command_editing_p) { rl_callback_handler_remove (); rl_callback_handler_install (actual_gdb_prompt, input_handler); } /* new_prompt at this point can be the top of the stack or the one passed in. It can't be NULL. */ else { /* Don't use a _filtered function here. It causes the assumed character position to be off, since the newline we read from the user is not accounted for. */ fputs_unfiltered (actual_gdb_prompt, gdb_stdout); gdb_flush (gdb_stdout); } do_cleanups (old_chain); }
/* Displays the prompt. The prompt that is displayed is the current top of the prompt stack, if the argument NEW_PROMPT is 0. Otherwise, it displays whatever NEW_PROMPT is. This is used after each gdb command has completed, and in the following cases: 1. when the user enters a command line which is ended by '\' indicating that the command will continue on the next line. In that case the prompt that is displayed is the empty string. 2. When the user is entering 'commands' for a breakpoint, or actions for a tracepoint. In this case the prompt will be '>' 3. Other???? FIXME: 2. & 3. not implemented yet for async. */ void display_gdb_prompt (char *new_prompt) { int prompt_length = 0; char *gdb_prompt = get_prompt (); /* Reset the nesting depth used when trace-commands is set. */ reset_command_nest_depth (); /* Each interpreter has its own rules on displaying the command prompt. */ if (!current_interp_display_prompt_p ()) return; if (sync_execution && is_running (inferior_ptid)) { /* This is to trick readline into not trying to display the prompt. Even though we display the prompt using this function, readline still tries to do its own display if we don't call rl_callback_handler_install and rl_callback_handler_remove (which readline detects because a global variable is not set). If readline did that, it could mess up gdb signal handlers for SIGINT. Readline assumes that between calls to rl_set_signals and rl_clear_signals gdb doesn't do anything with the signal handlers. Well, that's not the case, because when the target executes we change the SIGINT signal handler. If we allowed readline to display the prompt, the signal handler change would happen exactly between the calls to the above two functions. Calling rl_callback_handler_remove(), does the job. */ rl_callback_handler_remove (); return; } if (!new_prompt) { /* Just use the top of the prompt stack. */ prompt_length = strlen (PREFIX (0)) + strlen (SUFFIX (0)) + strlen (gdb_prompt) + 1; new_prompt = (char *) alloca (prompt_length); /* Prefix needs to have new line at end. */ strcpy (new_prompt, PREFIX (0)); strcat (new_prompt, gdb_prompt); /* Suffix needs to have a new line at end and \032 \032 at beginning. */ strcat (new_prompt, SUFFIX (0)); } if (async_command_editing_p) { rl_callback_handler_remove (); rl_callback_handler_install (new_prompt, input_handler); } /* new_prompt at this point can be the top of the stack or the one passed in */ else if (new_prompt) { /* Don't use a _filtered function here. It causes the assumed character position to be off, since the newline we read from the user is not accounted for. */ fputs_unfiltered (new_prompt, gdb_stdout); gdb_flush (gdb_stdout); } }