// Enter LINE in history void add_to_history(const string& line) { if (!gdb->isReadyWithPrompt()) return; set_history_from_line(line); if (gdb_history.size() < 2 || line != gdb_history[gdb_history.size() - 2]) { gdb_history += ""; if (gdb_history_w) { MString xm_line(line, LIST_CHARSET); int pos = gdb_history.size(); XmListAddItem(gdb_commands_w, xm_line.xmstring(), pos - 1); XmListSelectPos(gdb_commands_w, 0, False); XmListSetBottomPos(gdb_commands_w, 0); } } gdb_current_history = gdb_history.size(); set_history_from_line(""); if (gdb_history_w) { XmListSelectPos(gdb_commands_w, 0, False); XmListSetBottomPos(gdb_commands_w, 0); } gdb_new_history = false; add_to_arguments(line); update_arguments(); update_combo_boxes(line); #if WITH_READLINE add_history(line.chars()); #endif }
// Exit i-search mode and return to normal mode void clear_isearch(bool reset, bool show) { if (!gdb->isReadyWithPrompt()) return; if (isearch_state != ISEARCH_NONE) { isearch_state = ISEARCH_NONE; if (show) show_isearch(); if (reset) { set_history_from_line(current_line()); goto_history(); } } isearch_motion_ok = false; }
// Send completed lines to GDB void gdbChangeCB(Widget w, XtPointer, XtPointer) { if (private_gdb_output) return; string input = current_line(); bool at_prompt = gdb_input_at_prompt; if (at_prompt) input.gsub("\\\n", ""); int newlines = input.freq('\n'); string *lines = new string[newlines + 1]; split(input, lines, newlines, '\n'); private_gdb_input = true; if (newlines == 0 || (gdb_input_at_prompt && input.contains('\\', -1))) { // No newline found - line is still incomplete set_history_from_line(input, true); } else { // Process entered lines clear_isearch(); promptPosition = XmTextGetLastPosition(w); for (int i = 0; i < newlines; i++) { string cmd = lines[i]; tty_out(cmd + "\n"); if (gdb_input_at_prompt) { if (cmd.matches(rxwhite) || cmd.empty()) { // Empty line: repeat last command cmd = last_command_from_history(); } else { // Add new command to history add_to_history(cmd); } } if (at_prompt) { // We're typing at the GDB prompt: place CMD in command queue gdb_command(cmd, w); } else { // Pass anything else right to GDB, clearing the command queue. clearCommandQueue(); gdb->send_user_ctrl_cmd(cmd + "\n"); } } } private_gdb_input = false; delete[] lines; }
void gdbHistoryCB(Widget w, XtPointer, XtPointer) { if (gdb_history_w) { manage_and_raise(gdb_history_w); return; } Arg args[10]; int arg; // Create history viewer arg = 0; gdb_history_w = verify(createTopLevelSelectionDialog(find_shell(w), "history_dialog", args, arg)); Delay::register_shell(gdb_history_w); XtUnmanageChild(XmSelectionBoxGetChild(gdb_history_w, XmDIALOG_OK_BUTTON)); XtUnmanageChild(XmSelectionBoxGetChild(gdb_history_w, XmDIALOG_TEXT)); XtUnmanageChild(XmSelectionBoxGetChild(gdb_history_w, XmDIALOG_SELECTION_LABEL)); gdb_commands_w = XmSelectionBoxGetChild(gdb_history_w, XmDIALOG_LIST); XtVaSetValues(gdb_commands_w, XmNselectionPolicy, XmSINGLE_SELECT, XtPointer(0)); XtAddCallback(gdb_commands_w, XmNsingleSelectionCallback, SelectHistoryCB, 0); XtAddCallback(gdb_commands_w, XmNmultipleSelectionCallback, SelectHistoryCB, 0); XtAddCallback(gdb_commands_w, XmNextendedSelectionCallback, SelectHistoryCB, 0); XtAddCallback(gdb_commands_w, XmNbrowseSelectionCallback, SelectHistoryCB, 0); XtAddCallback(gdb_history_w, XmNokCallback, gdbApplySelectionCB, 0); XtAddCallback(gdb_history_w, XmNapplyCallback, gdbApplySelectionCB, 0); XtAddCallback(gdb_history_w, XmNcancelCallback, DestroyThisCB, gdb_history_w); XtAddCallback(gdb_history_w, XmNhelpCallback, ImmediateHelpCB, 0); XtAddCallback(gdb_history_w, XmNdestroyCallback, HistoryDestroyedCB, XtPointer(gdb_history_w)); bool *selected = new bool[gdb_history.size() + 1]; for (int i = 0; i < gdb_history.size() + 1; i++) selected[i] = false; selected[gdb_current_history] = true; setLabelList(gdb_commands_w, gdb_history.values(), selected, gdb_history.size(), false, false); delete[] selected; set_history_from_line(current_line()); XmListSelectPos(gdb_commands_w, 0, False); XmListSetBottomPos(gdb_commands_w, 0); manage_and_raise(gdb_history_w); }