void change_line_handler (int editing) { struct ui *ui = current_ui; /* We can only have one instance of readline, so we only allow editing on the main UI. */ if (ui != main_ui) return; /* Don't try enabling editing if the interpreter doesn't support it (e.g., MI). */ if (!interp_supports_command_editing (top_level_interpreter ()) || !interp_supports_command_editing (command_interp ())) return; if (editing) { gdb_assert (ui == main_ui); /* Turn on editing by using readline. */ ui->call_readline = gdb_rl_callback_read_char_wrapper; } else { /* Turn off editing by using gdb_readline_no_editing_callback. */ if (ui->command_editing) gdb_rl_callback_handler_remove (); ui->call_readline = gdb_readline_no_editing_callback; } ui->command_editing = editing; }
/* Change the function to be invoked every time there is a character ready on stdin. This is used when the user sets the editing off, therefore bypassing readline, and letting gdb handle the input itself, via gdb_readline_no_editing_callback. Also it is used in the opposite case in which the user sets editing on again, by restoring readline handling of the input. */ static void change_line_handler (void) { /* NOTE: this operates on input_fd, not instream. If we are reading commands from a file, instream will point to the file. However in async mode, we always read commands from a file with editing off. This means that the 'set editing on/off' will have effect only on the interactive session. */ if (async_command_editing_p) { /* Turn on editing by using readline. */ call_readline = rl_callback_read_char_wrapper; input_handler = command_line_handler; } else { /* Turn off editing by using gdb_readline_no_editing_callback. */ gdb_rl_callback_handler_remove (); call_readline = gdb_readline_no_editing_callback; /* Set up the command handler as well, in case we are called as first thing from .gdbinit. */ input_handler = command_line_handler; } }
/* Disable command input through the standard CLI channels. Used in the suspend proc for interpreters that use the standard gdb readline interface, like the cli & the mi. */ void gdb_disable_readline (void) { /* FIXME - It is too heavyweight to delete and remake these every time you run an interpreter that needs readline. It is probably better to have the interpreters cache these, which in turn means that this needs to be moved into interpreter specific code. */ #if 0 ui_file_delete (gdb_stdout); ui_file_delete (gdb_stderr); gdb_stdlog = NULL; gdb_stdtarg = NULL; gdb_stdtargerr = NULL; #endif gdb_rl_callback_handler_remove (); delete_file_handler (input_fd); }
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 (const 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 (); 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. */ gdb_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) { gdb_rl_callback_handler_remove (); gdb_rl_callback_handler_install (actual_gdb_prompt); } /* 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); }