| 1 | /* TUI window generic functions. |
| 2 | |
| 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
| 4 | |
| 5 | Contributed by Hewlett-Packard Company. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | /* This module contains procedures for handling tui window functions |
| 23 | like resize, scrolling, scrolling, changing focus, etc. |
| 24 | |
| 25 | Author: Susan B. Macchia */ |
| 26 | |
| 27 | #include "defs.h" |
| 28 | #include "command.h" |
| 29 | #include "symtab.h" |
| 30 | #include "breakpoint.h" |
| 31 | #include "frame.h" |
| 32 | #include "cli/cli-cmds.h" |
| 33 | #include "top.h" |
| 34 | #include "source.h" |
| 35 | #include "event-loop.h" |
| 36 | |
| 37 | #include "tui/tui.h" |
| 38 | #include "tui/tui-io.h" |
| 39 | #include "tui/tui-data.h" |
| 40 | #include "tui/tui-wingeneral.h" |
| 41 | #include "tui/tui-stack.h" |
| 42 | #include "tui/tui-regs.h" |
| 43 | #include "tui/tui-disasm.h" |
| 44 | #include "tui/tui-source.h" |
| 45 | #include "tui/tui-winsource.h" |
| 46 | #include "tui/tui-windata.h" |
| 47 | #include "tui/tui-win.h" |
| 48 | |
| 49 | #include "gdb_curses.h" |
| 50 | #include <ctype.h> |
| 51 | #include "readline/readline.h" |
| 52 | |
| 53 | #include <signal.h> |
| 54 | |
| 55 | /******************************* |
| 56 | ** Static Local Decls |
| 57 | ********************************/ |
| 58 | static void make_visible_with_new_height (struct tui_win_info *); |
| 59 | static void make_invisible_and_set_new_height (struct tui_win_info *, |
| 60 | int); |
| 61 | static enum tui_status tui_adjust_win_heights (struct tui_win_info *, |
| 62 | int); |
| 63 | static int new_height_ok (struct tui_win_info *, int); |
| 64 | static void tui_set_tab_width_command (const char *, int); |
| 65 | static void tui_refresh_all_command (const char *, int); |
| 66 | static void tui_set_win_height_command (const char *, int); |
| 67 | static void tui_all_windows_info (const char *, int); |
| 68 | static void tui_set_focus_command (const char *, int); |
| 69 | static void tui_scroll_forward_command (const char *, int); |
| 70 | static void tui_scroll_backward_command (const char *, int); |
| 71 | static void tui_scroll_left_command (const char *, int); |
| 72 | static void tui_scroll_right_command (const char *, int); |
| 73 | static void parse_scrolling_args (const char *, |
| 74 | struct tui_win_info **, |
| 75 | int *); |
| 76 | |
| 77 | |
| 78 | /*************************************** |
| 79 | ** DEFINITIONS |
| 80 | ***************************************/ |
| 81 | #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n" |
| 82 | #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n" |
| 83 | |
| 84 | /*************************************** |
| 85 | ** PUBLIC FUNCTIONS |
| 86 | ***************************************/ |
| 87 | |
| 88 | #ifndef ACS_LRCORNER |
| 89 | # define ACS_LRCORNER '+' |
| 90 | #endif |
| 91 | #ifndef ACS_LLCORNER |
| 92 | # define ACS_LLCORNER '+' |
| 93 | #endif |
| 94 | #ifndef ACS_ULCORNER |
| 95 | # define ACS_ULCORNER '+' |
| 96 | #endif |
| 97 | #ifndef ACS_URCORNER |
| 98 | # define ACS_URCORNER '+' |
| 99 | #endif |
| 100 | #ifndef ACS_HLINE |
| 101 | # define ACS_HLINE '-' |
| 102 | #endif |
| 103 | #ifndef ACS_VLINE |
| 104 | # define ACS_VLINE '|' |
| 105 | #endif |
| 106 | |
| 107 | /* Possible values for tui-border-kind variable. */ |
| 108 | static const char *const tui_border_kind_enums[] = { |
| 109 | "space", |
| 110 | "ascii", |
| 111 | "acs", |
| 112 | NULL |
| 113 | }; |
| 114 | |
| 115 | /* Possible values for tui-border-mode and tui-active-border-mode. */ |
| 116 | static const char *const tui_border_mode_enums[] = { |
| 117 | "normal", |
| 118 | "standout", |
| 119 | "reverse", |
| 120 | "half", |
| 121 | "half-standout", |
| 122 | "bold", |
| 123 | "bold-standout", |
| 124 | NULL |
| 125 | }; |
| 126 | |
| 127 | struct tui_translate |
| 128 | { |
| 129 | const char *name; |
| 130 | int value; |
| 131 | }; |
| 132 | |
| 133 | /* Translation table for border-mode variables. |
| 134 | The list of values must be terminated by a NULL. |
| 135 | After the NULL value, an entry defines the default. */ |
| 136 | struct tui_translate tui_border_mode_translate[] = { |
| 137 | { "normal", A_NORMAL }, |
| 138 | { "standout", A_STANDOUT }, |
| 139 | { "reverse", A_REVERSE }, |
| 140 | { "half", A_DIM }, |
| 141 | { "half-standout", A_DIM | A_STANDOUT }, |
| 142 | { "bold", A_BOLD }, |
| 143 | { "bold-standout", A_BOLD | A_STANDOUT }, |
| 144 | { 0, 0 }, |
| 145 | { "normal", A_NORMAL } |
| 146 | }; |
| 147 | |
| 148 | /* Translation tables for border-kind, one for each border |
| 149 | character (see wborder, border curses operations). |
| 150 | -1 is used to indicate the ACS because ACS characters |
| 151 | are determined at run time by curses (depends on terminal). */ |
| 152 | struct tui_translate tui_border_kind_translate_vline[] = { |
| 153 | { "space", ' ' }, |
| 154 | { "ascii", '|' }, |
| 155 | { "acs", -1 }, |
| 156 | { 0, 0 }, |
| 157 | { "ascii", '|' } |
| 158 | }; |
| 159 | |
| 160 | struct tui_translate tui_border_kind_translate_hline[] = { |
| 161 | { "space", ' ' }, |
| 162 | { "ascii", '-' }, |
| 163 | { "acs", -1 }, |
| 164 | { 0, 0 }, |
| 165 | { "ascii", '-' } |
| 166 | }; |
| 167 | |
| 168 | struct tui_translate tui_border_kind_translate_ulcorner[] = { |
| 169 | { "space", ' ' }, |
| 170 | { "ascii", '+' }, |
| 171 | { "acs", -1 }, |
| 172 | { 0, 0 }, |
| 173 | { "ascii", '+' } |
| 174 | }; |
| 175 | |
| 176 | struct tui_translate tui_border_kind_translate_urcorner[] = { |
| 177 | { "space", ' ' }, |
| 178 | { "ascii", '+' }, |
| 179 | { "acs", -1 }, |
| 180 | { 0, 0 }, |
| 181 | { "ascii", '+' } |
| 182 | }; |
| 183 | |
| 184 | struct tui_translate tui_border_kind_translate_llcorner[] = { |
| 185 | { "space", ' ' }, |
| 186 | { "ascii", '+' }, |
| 187 | { "acs", -1 }, |
| 188 | { 0, 0 }, |
| 189 | { "ascii", '+' } |
| 190 | }; |
| 191 | |
| 192 | struct tui_translate tui_border_kind_translate_lrcorner[] = { |
| 193 | { "space", ' ' }, |
| 194 | { "ascii", '+' }, |
| 195 | { "acs", -1 }, |
| 196 | { 0, 0 }, |
| 197 | { "ascii", '+' } |
| 198 | }; |
| 199 | |
| 200 | |
| 201 | /* Tui configuration variables controlled with set/show command. */ |
| 202 | const char *tui_active_border_mode = "bold-standout"; |
| 203 | static void |
| 204 | show_tui_active_border_mode (struct ui_file *file, |
| 205 | int from_tty, |
| 206 | struct cmd_list_element *c, |
| 207 | const char *value) |
| 208 | { |
| 209 | fprintf_filtered (file, _("\ |
| 210 | The attribute mode to use for the active TUI window border is \"%s\".\n"), |
| 211 | value); |
| 212 | } |
| 213 | |
| 214 | const char *tui_border_mode = "normal"; |
| 215 | static void |
| 216 | show_tui_border_mode (struct ui_file *file, |
| 217 | int from_tty, |
| 218 | struct cmd_list_element *c, |
| 219 | const char *value) |
| 220 | { |
| 221 | fprintf_filtered (file, _("\ |
| 222 | The attribute mode to use for the TUI window borders is \"%s\".\n"), |
| 223 | value); |
| 224 | } |
| 225 | |
| 226 | const char *tui_border_kind = "acs"; |
| 227 | static void |
| 228 | show_tui_border_kind (struct ui_file *file, |
| 229 | int from_tty, |
| 230 | struct cmd_list_element *c, |
| 231 | const char *value) |
| 232 | { |
| 233 | fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"), |
| 234 | value); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* Tui internal configuration variables. These variables are updated |
| 239 | by tui_update_variables to reflect the tui configuration |
| 240 | variables. */ |
| 241 | chtype tui_border_vline; |
| 242 | chtype tui_border_hline; |
| 243 | chtype tui_border_ulcorner; |
| 244 | chtype tui_border_urcorner; |
| 245 | chtype tui_border_llcorner; |
| 246 | chtype tui_border_lrcorner; |
| 247 | |
| 248 | int tui_border_attrs; |
| 249 | int tui_active_border_attrs; |
| 250 | |
| 251 | /* Identify the item in the translation table. |
| 252 | When the item is not recognized, use the default entry. */ |
| 253 | static struct tui_translate * |
| 254 | translate (const char *name, struct tui_translate *table) |
| 255 | { |
| 256 | while (table->name) |
| 257 | { |
| 258 | if (name && strcmp (table->name, name) == 0) |
| 259 | return table; |
| 260 | table++; |
| 261 | } |
| 262 | |
| 263 | /* Not found, return default entry. */ |
| 264 | table++; |
| 265 | return table; |
| 266 | } |
| 267 | |
| 268 | /* Update the tui internal configuration according to gdb settings. |
| 269 | Returns 1 if the configuration has changed and the screen should |
| 270 | be redrawn. */ |
| 271 | int |
| 272 | tui_update_variables (void) |
| 273 | { |
| 274 | int need_redraw = 0; |
| 275 | struct tui_translate *entry; |
| 276 | |
| 277 | entry = translate (tui_border_mode, tui_border_mode_translate); |
| 278 | if (tui_border_attrs != entry->value) |
| 279 | { |
| 280 | tui_border_attrs = entry->value; |
| 281 | need_redraw = 1; |
| 282 | } |
| 283 | entry = translate (tui_active_border_mode, tui_border_mode_translate); |
| 284 | if (tui_active_border_attrs != entry->value) |
| 285 | { |
| 286 | tui_active_border_attrs = entry->value; |
| 287 | need_redraw = 1; |
| 288 | } |
| 289 | |
| 290 | /* If one corner changes, all characters are changed. |
| 291 | Only check the first one. The ACS characters are determined at |
| 292 | run time by curses terminal management. */ |
| 293 | entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner); |
| 294 | if (tui_border_lrcorner != (chtype) entry->value) |
| 295 | { |
| 296 | tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value; |
| 297 | need_redraw = 1; |
| 298 | } |
| 299 | entry = translate (tui_border_kind, tui_border_kind_translate_llcorner); |
| 300 | tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value; |
| 301 | |
| 302 | entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner); |
| 303 | tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value; |
| 304 | |
| 305 | entry = translate (tui_border_kind, tui_border_kind_translate_urcorner); |
| 306 | tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value; |
| 307 | |
| 308 | entry = translate (tui_border_kind, tui_border_kind_translate_hline); |
| 309 | tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value; |
| 310 | |
| 311 | entry = translate (tui_border_kind, tui_border_kind_translate_vline); |
| 312 | tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value; |
| 313 | |
| 314 | return need_redraw; |
| 315 | } |
| 316 | |
| 317 | static void |
| 318 | set_tui_cmd (const char *args, int from_tty) |
| 319 | { |
| 320 | } |
| 321 | |
| 322 | static void |
| 323 | show_tui_cmd (const char *args, int from_tty) |
| 324 | { |
| 325 | } |
| 326 | |
| 327 | static struct cmd_list_element *tuilist; |
| 328 | |
| 329 | static void |
| 330 | tui_command (const char *args, int from_tty) |
| 331 | { |
| 332 | printf_unfiltered (_("\"tui\" must be followed by the name of a " |
| 333 | "tui command.\n")); |
| 334 | help_list (tuilist, "tui ", all_commands, gdb_stdout); |
| 335 | } |
| 336 | |
| 337 | struct cmd_list_element ** |
| 338 | tui_get_cmd_list (void) |
| 339 | { |
| 340 | if (tuilist == 0) |
| 341 | add_prefix_cmd ("tui", class_tui, tui_command, |
| 342 | _("Text User Interface commands."), |
| 343 | &tuilist, "tui ", 0, &cmdlist); |
| 344 | return &tuilist; |
| 345 | } |
| 346 | |
| 347 | /* The set_func hook of "set tui ..." commands that affect the window |
| 348 | borders on the TUI display. */ |
| 349 | void |
| 350 | tui_set_var_cmd (const char *null_args, |
| 351 | int from_tty, struct cmd_list_element *c) |
| 352 | { |
| 353 | if (tui_update_variables () && tui_active) |
| 354 | tui_rehighlight_all (); |
| 355 | } |
| 356 | |
| 357 | /* Generic window name completion function. Complete window name pointed |
| 358 | to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special |
| 359 | window names 'next' and 'prev' will also be considered as possible |
| 360 | completions of the window name. */ |
| 361 | |
| 362 | static void |
| 363 | window_name_completer (completion_tracker &tracker, |
| 364 | int include_next_prev_p, |
| 365 | const char *text, const char *word) |
| 366 | { |
| 367 | std::vector<const char *> completion_name_vec; |
| 368 | int win_type; |
| 369 | |
| 370 | for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++) |
| 371 | { |
| 372 | const char *completion_name = NULL; |
| 373 | |
| 374 | /* We can't focus on an invisible window. */ |
| 375 | if (tui_win_list[win_type] == NULL |
| 376 | || !tui_win_list[win_type]->is_visible) |
| 377 | continue; |
| 378 | |
| 379 | completion_name = tui_win_name (tui_win_list [win_type]); |
| 380 | gdb_assert (completion_name != NULL); |
| 381 | completion_name_vec.push_back (completion_name); |
| 382 | } |
| 383 | |
| 384 | /* If no windows are considered visible then the TUI has not yet been |
| 385 | initialized. But still "focus src" and "focus cmd" will work because |
| 386 | invoking the focus command will entail initializing the TUI which sets the |
| 387 | default layout to SRC_COMMAND. */ |
| 388 | if (completion_name_vec.empty ()) |
| 389 | { |
| 390 | completion_name_vec.push_back (SRC_NAME); |
| 391 | completion_name_vec.push_back (CMD_NAME); |
| 392 | } |
| 393 | |
| 394 | if (include_next_prev_p) |
| 395 | { |
| 396 | completion_name_vec.push_back ("next"); |
| 397 | completion_name_vec.push_back ("prev"); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | completion_name_vec.push_back (NULL); |
| 402 | complete_on_enum (tracker, completion_name_vec.data (), text, word); |
| 403 | } |
| 404 | |
| 405 | /* Complete possible window names to focus on. TEXT is the complete text |
| 406 | entered so far, WORD is the word currently being completed. */ |
| 407 | |
| 408 | static void |
| 409 | focus_completer (struct cmd_list_element *ignore, |
| 410 | completion_tracker &tracker, |
| 411 | const char *text, const char *word) |
| 412 | { |
| 413 | window_name_completer (tracker, 1, text, word); |
| 414 | } |
| 415 | |
| 416 | /* Complete possible window names for winheight command. TEXT is the |
| 417 | complete text entered so far, WORD is the word currently being |
| 418 | completed. */ |
| 419 | |
| 420 | static void |
| 421 | winheight_completer (struct cmd_list_element *ignore, |
| 422 | completion_tracker &tracker, |
| 423 | const char *text, const char *word) |
| 424 | { |
| 425 | /* The first word is the window name. That we can complete. Subsequent |
| 426 | words can't be completed. */ |
| 427 | if (word != text) |
| 428 | return; |
| 429 | |
| 430 | window_name_completer (tracker, 0, text, word); |
| 431 | } |
| 432 | |
| 433 | /* Update gdb's knowledge of the terminal size. */ |
| 434 | void |
| 435 | tui_update_gdb_sizes (void) |
| 436 | { |
| 437 | int width, height; |
| 438 | |
| 439 | if (tui_active) |
| 440 | { |
| 441 | width = TUI_CMD_WIN->width; |
| 442 | height = TUI_CMD_WIN->height; |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | width = tui_term_width (); |
| 447 | height = tui_term_height (); |
| 448 | } |
| 449 | |
| 450 | set_screen_width_and_height (width, height); |
| 451 | } |
| 452 | |
| 453 | |
| 454 | /* Set the logical focus to win_info. */ |
| 455 | void |
| 456 | tui_set_win_focus_to (struct tui_win_info *win_info) |
| 457 | { |
| 458 | if (win_info != NULL) |
| 459 | { |
| 460 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
| 461 | |
| 462 | if (win_with_focus != NULL |
| 463 | && win_with_focus->type != CMD_WIN) |
| 464 | tui_unhighlight_win (win_with_focus); |
| 465 | tui_set_win_with_focus (win_info); |
| 466 | if (win_info->type != CMD_WIN) |
| 467 | tui_highlight_win (win_info); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | |
| 472 | void |
| 473 | tui_win_info::forward_scroll (int num_to_scroll) |
| 474 | { |
| 475 | if (num_to_scroll == 0) |
| 476 | num_to_scroll = height - 3; |
| 477 | |
| 478 | do_scroll_vertical (FORWARD_SCROLL, num_to_scroll); |
| 479 | } |
| 480 | |
| 481 | void |
| 482 | tui_win_info::backward_scroll (int num_to_scroll) |
| 483 | { |
| 484 | if (num_to_scroll == 0) |
| 485 | num_to_scroll = height - 3; |
| 486 | |
| 487 | do_scroll_vertical (BACKWARD_SCROLL, num_to_scroll); |
| 488 | } |
| 489 | |
| 490 | |
| 491 | void |
| 492 | tui_win_info::left_scroll (int num_to_scroll) |
| 493 | { |
| 494 | if (num_to_scroll == 0) |
| 495 | num_to_scroll = 1; |
| 496 | |
| 497 | do_scroll_horizontal (LEFT_SCROLL, num_to_scroll); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | void |
| 502 | tui_win_info::right_scroll (int num_to_scroll) |
| 503 | { |
| 504 | if (num_to_scroll == 0) |
| 505 | num_to_scroll = 1; |
| 506 | |
| 507 | do_scroll_horizontal (RIGHT_SCROLL, num_to_scroll); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | /* See tui-data.h. */ |
| 512 | |
| 513 | void |
| 514 | tui_source_window_base::refresh_all () |
| 515 | { |
| 516 | tui_show_source_content (this); |
| 517 | tui_check_and_display_highlight_if_needed (this); |
| 518 | tui_erase_exec_info_content (this); |
| 519 | tui_update_exec_info (this); |
| 520 | } |
| 521 | |
| 522 | void |
| 523 | tui_refresh_all_win (void) |
| 524 | { |
| 525 | int type; |
| 526 | |
| 527 | clearok (curscr, TRUE); |
| 528 | tui_refresh_all (tui_win_list); |
| 529 | for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++) |
| 530 | { |
| 531 | if (tui_win_list[type] && tui_win_list[type]->is_visible) |
| 532 | tui_win_list[type]->refresh_all (); |
| 533 | } |
| 534 | tui_show_locator_content (); |
| 535 | } |
| 536 | |
| 537 | void |
| 538 | tui_rehighlight_all (void) |
| 539 | { |
| 540 | int type; |
| 541 | |
| 542 | for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++) |
| 543 | tui_check_and_display_highlight_if_needed (tui_win_list[type]); |
| 544 | } |
| 545 | |
| 546 | /* Resize all the windows based on the terminal size. This function |
| 547 | gets called from within the readline sinwinch handler. */ |
| 548 | void |
| 549 | tui_resize_all (void) |
| 550 | { |
| 551 | int height_diff, width_diff; |
| 552 | int screenheight, screenwidth; |
| 553 | |
| 554 | rl_get_screen_size (&screenheight, &screenwidth); |
| 555 | width_diff = screenwidth - tui_term_width (); |
| 556 | height_diff = screenheight - tui_term_height (); |
| 557 | if (height_diff || width_diff) |
| 558 | { |
| 559 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 560 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
| 561 | struct tui_win_info *first_win; |
| 562 | struct tui_win_info *second_win; |
| 563 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
| 564 | int win_type; |
| 565 | int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2; |
| 566 | |
| 567 | #ifdef HAVE_RESIZE_TERM |
| 568 | resize_term (screenheight, screenwidth); |
| 569 | #endif |
| 570 | /* Turn keypad off while we resize. */ |
| 571 | if (win_with_focus != TUI_CMD_WIN) |
| 572 | keypad (TUI_CMD_WIN->handle, FALSE); |
| 573 | tui_update_gdb_sizes (); |
| 574 | tui_set_term_height_to (screenheight); |
| 575 | tui_set_term_width_to (screenwidth); |
| 576 | if (cur_layout == SRC_DISASSEM_COMMAND |
| 577 | || cur_layout == SRC_DATA_COMMAND |
| 578 | || cur_layout == DISASSEM_DATA_COMMAND) |
| 579 | num_wins_displayed++; |
| 580 | split_diff = height_diff / num_wins_displayed; |
| 581 | cmd_split_diff = split_diff; |
| 582 | if (height_diff % num_wins_displayed) |
| 583 | { |
| 584 | if (height_diff < 0) |
| 585 | cmd_split_diff--; |
| 586 | else |
| 587 | cmd_split_diff++; |
| 588 | } |
| 589 | /* Now adjust each window. */ |
| 590 | /* erase + clearok are used instead of a straightforward clear as |
| 591 | AIX 5.3 does not define clear. */ |
| 592 | erase (); |
| 593 | clearok (curscr, TRUE); |
| 594 | refresh (); |
| 595 | switch (cur_layout) |
| 596 | { |
| 597 | case SRC_COMMAND: |
| 598 | case DISASSEM_COMMAND: |
| 599 | first_win = tui_source_windows ()[0]; |
| 600 | first_win->width += width_diff; |
| 601 | locator->width += width_diff; |
| 602 | /* Check for invalid heights. */ |
| 603 | if (height_diff == 0) |
| 604 | new_height = first_win->height; |
| 605 | else if ((first_win->height + split_diff) >= |
| 606 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
| 607 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
| 608 | else if ((first_win->height + split_diff) <= 0) |
| 609 | new_height = MIN_WIN_HEIGHT; |
| 610 | else |
| 611 | new_height = first_win->height + split_diff; |
| 612 | |
| 613 | locator->origin.y = new_height + 1; |
| 614 | make_invisible_and_set_new_height (first_win, new_height); |
| 615 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
| 616 | TUI_CMD_WIN->width += width_diff; |
| 617 | new_height = screenheight - TUI_CMD_WIN->origin.y; |
| 618 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
| 619 | make_visible_with_new_height (first_win); |
| 620 | make_visible_with_new_height (TUI_CMD_WIN); |
| 621 | if (first_win->content_size <= 0) |
| 622 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); |
| 623 | break; |
| 624 | default: |
| 625 | if (cur_layout == SRC_DISASSEM_COMMAND) |
| 626 | { |
| 627 | first_win = TUI_SRC_WIN; |
| 628 | first_win->width += width_diff; |
| 629 | second_win = TUI_DISASM_WIN; |
| 630 | second_win->width += width_diff; |
| 631 | } |
| 632 | else |
| 633 | { |
| 634 | first_win = TUI_DATA_WIN; |
| 635 | first_win->width += width_diff; |
| 636 | second_win = tui_source_windows ()[0]; |
| 637 | second_win->width += width_diff; |
| 638 | } |
| 639 | /* Change the first window's height/width. */ |
| 640 | /* Check for invalid heights. */ |
| 641 | if (height_diff == 0) |
| 642 | new_height = first_win->height; |
| 643 | else if ((first_win->height + |
| 644 | second_win->height + (split_diff * 2)) >= |
| 645 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
| 646 | new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2; |
| 647 | else if ((first_win->height + split_diff) <= 0) |
| 648 | new_height = MIN_WIN_HEIGHT; |
| 649 | else |
| 650 | new_height = first_win->height + split_diff; |
| 651 | make_invisible_and_set_new_height (first_win, new_height); |
| 652 | |
| 653 | locator->width += width_diff; |
| 654 | |
| 655 | /* Change the second window's height/width. */ |
| 656 | /* Check for invalid heights. */ |
| 657 | if (height_diff == 0) |
| 658 | new_height = second_win->height; |
| 659 | else if ((first_win->height + |
| 660 | second_win->height + (split_diff * 2)) >= |
| 661 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
| 662 | { |
| 663 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
| 664 | if (new_height % 2) |
| 665 | new_height = (new_height / 2) + 1; |
| 666 | else |
| 667 | new_height /= 2; |
| 668 | } |
| 669 | else if ((second_win->height + split_diff) <= 0) |
| 670 | new_height = MIN_WIN_HEIGHT; |
| 671 | else |
| 672 | new_height = second_win->height + split_diff; |
| 673 | second_win->origin.y = first_win->height - 1; |
| 674 | make_invisible_and_set_new_height (second_win, new_height); |
| 675 | |
| 676 | /* Change the command window's height/width. */ |
| 677 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
| 678 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
| 679 | TUI_CMD_WIN->height |
| 680 | + cmd_split_diff); |
| 681 | make_visible_with_new_height (first_win); |
| 682 | make_visible_with_new_height (second_win); |
| 683 | make_visible_with_new_height (TUI_CMD_WIN); |
| 684 | if (first_win->content_size <= 0) |
| 685 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); |
| 686 | if (second_win->content_size <= 0) |
| 687 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); |
| 688 | break; |
| 689 | } |
| 690 | /* Now remove all invisible windows, and their content so that |
| 691 | they get created again when called for with the new size. */ |
| 692 | for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++) |
| 693 | { |
| 694 | if (win_type != CMD_WIN |
| 695 | && (tui_win_list[win_type] != NULL) |
| 696 | && !tui_win_list[win_type]->is_visible) |
| 697 | { |
| 698 | delete tui_win_list[win_type]; |
| 699 | tui_win_list[win_type] = NULL; |
| 700 | } |
| 701 | } |
| 702 | /* Turn keypad back on, unless focus is in the command |
| 703 | window. */ |
| 704 | if (win_with_focus != TUI_CMD_WIN) |
| 705 | keypad (TUI_CMD_WIN->handle, TRUE); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | #ifdef SIGWINCH |
| 710 | /* Token for use by TUI's asynchronous SIGWINCH handler. */ |
| 711 | static struct async_signal_handler *tui_sigwinch_token; |
| 712 | |
| 713 | /* TUI's SIGWINCH signal handler. */ |
| 714 | static void |
| 715 | tui_sigwinch_handler (int signal) |
| 716 | { |
| 717 | mark_async_signal_handler (tui_sigwinch_token); |
| 718 | tui_set_win_resized_to (TRUE); |
| 719 | } |
| 720 | |
| 721 | /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */ |
| 722 | static void |
| 723 | tui_async_resize_screen (gdb_client_data arg) |
| 724 | { |
| 725 | rl_resize_terminal (); |
| 726 | |
| 727 | if (!tui_active) |
| 728 | { |
| 729 | int screen_height, screen_width; |
| 730 | |
| 731 | rl_get_screen_size (&screen_height, &screen_width); |
| 732 | set_screen_width_and_height (screen_width, screen_height); |
| 733 | |
| 734 | /* win_resized is left set so that the next call to tui_enable() |
| 735 | resizes the TUI windows. */ |
| 736 | } |
| 737 | else |
| 738 | { |
| 739 | tui_set_win_resized_to (FALSE); |
| 740 | tui_resize_all (); |
| 741 | tui_refresh_all_win (); |
| 742 | tui_update_gdb_sizes (); |
| 743 | tui_redisplay_readline (); |
| 744 | } |
| 745 | } |
| 746 | #endif |
| 747 | |
| 748 | /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not |
| 749 | uninstalled when we exit TUI, so the handler should not assume that TUI is |
| 750 | always active. */ |
| 751 | void |
| 752 | tui_initialize_win (void) |
| 753 | { |
| 754 | #ifdef SIGWINCH |
| 755 | tui_sigwinch_token |
| 756 | = create_async_signal_handler (tui_async_resize_screen, NULL); |
| 757 | |
| 758 | { |
| 759 | #ifdef HAVE_SIGACTION |
| 760 | struct sigaction old_winch; |
| 761 | |
| 762 | memset (&old_winch, 0, sizeof (old_winch)); |
| 763 | old_winch.sa_handler = &tui_sigwinch_handler; |
| 764 | #ifdef SA_RESTART |
| 765 | old_winch.sa_flags = SA_RESTART; |
| 766 | #endif |
| 767 | sigaction (SIGWINCH, &old_winch, NULL); |
| 768 | #else |
| 769 | signal (SIGWINCH, &tui_sigwinch_handler); |
| 770 | #endif |
| 771 | } |
| 772 | #endif |
| 773 | } |
| 774 | |
| 775 | |
| 776 | /************************* |
| 777 | ** STATIC LOCAL FUNCTIONS |
| 778 | **************************/ |
| 779 | |
| 780 | |
| 781 | static void |
| 782 | tui_scroll_forward_command (const char *arg, int from_tty) |
| 783 | { |
| 784 | int num_to_scroll = 1; |
| 785 | struct tui_win_info *win_to_scroll; |
| 786 | |
| 787 | /* Make sure the curses mode is enabled. */ |
| 788 | tui_enable (); |
| 789 | if (arg == NULL) |
| 790 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
| 791 | else |
| 792 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
| 793 | win_to_scroll->forward_scroll (num_to_scroll); |
| 794 | } |
| 795 | |
| 796 | |
| 797 | static void |
| 798 | tui_scroll_backward_command (const char *arg, int from_tty) |
| 799 | { |
| 800 | int num_to_scroll = 1; |
| 801 | struct tui_win_info *win_to_scroll; |
| 802 | |
| 803 | /* Make sure the curses mode is enabled. */ |
| 804 | tui_enable (); |
| 805 | if (arg == NULL) |
| 806 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
| 807 | else |
| 808 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
| 809 | win_to_scroll->backward_scroll (num_to_scroll); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | static void |
| 814 | tui_scroll_left_command (const char *arg, int from_tty) |
| 815 | { |
| 816 | int num_to_scroll; |
| 817 | struct tui_win_info *win_to_scroll; |
| 818 | |
| 819 | /* Make sure the curses mode is enabled. */ |
| 820 | tui_enable (); |
| 821 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
| 822 | win_to_scroll->left_scroll (num_to_scroll); |
| 823 | } |
| 824 | |
| 825 | |
| 826 | static void |
| 827 | tui_scroll_right_command (const char *arg, int from_tty) |
| 828 | { |
| 829 | int num_to_scroll; |
| 830 | struct tui_win_info *win_to_scroll; |
| 831 | |
| 832 | /* Make sure the curses mode is enabled. */ |
| 833 | tui_enable (); |
| 834 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
| 835 | win_to_scroll->right_scroll (num_to_scroll); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | /* Set focus to the window named by 'arg'. */ |
| 840 | static void |
| 841 | tui_set_focus (const char *arg, int from_tty) |
| 842 | { |
| 843 | if (arg != NULL) |
| 844 | { |
| 845 | char *buf_ptr = xstrdup (arg); |
| 846 | int i; |
| 847 | struct tui_win_info *win_info = NULL; |
| 848 | |
| 849 | for (i = 0; (i < strlen (buf_ptr)); i++) |
| 850 | buf_ptr[i] = tolower (arg[i]); |
| 851 | |
| 852 | if (subset_compare (buf_ptr, "next")) |
| 853 | win_info = tui_next_win (tui_win_with_focus ()); |
| 854 | else if (subset_compare (buf_ptr, "prev")) |
| 855 | win_info = tui_prev_win (tui_win_with_focus ()); |
| 856 | else |
| 857 | win_info = tui_partial_win_by_name (buf_ptr); |
| 858 | |
| 859 | if (win_info == NULL || !win_info->is_visible) |
| 860 | warning (_("Invalid window specified. \n\ |
| 861 | The window name specified must be valid and visible.\n")); |
| 862 | else |
| 863 | { |
| 864 | tui_set_win_focus_to (win_info); |
| 865 | keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN)); |
| 866 | } |
| 867 | |
| 868 | if (TUI_DATA_WIN && TUI_DATA_WIN->is_visible) |
| 869 | TUI_DATA_WIN->refresh_all (); |
| 870 | xfree (buf_ptr); |
| 871 | printf_filtered (_("Focus set to %s window.\n"), |
| 872 | tui_win_name (tui_win_with_focus ())); |
| 873 | } |
| 874 | else |
| 875 | warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE); |
| 876 | } |
| 877 | |
| 878 | static void |
| 879 | tui_set_focus_command (const char *arg, int from_tty) |
| 880 | { |
| 881 | /* Make sure the curses mode is enabled. */ |
| 882 | tui_enable (); |
| 883 | tui_set_focus (arg, from_tty); |
| 884 | } |
| 885 | |
| 886 | |
| 887 | static void |
| 888 | tui_all_windows_info (const char *arg, int from_tty) |
| 889 | { |
| 890 | int type; |
| 891 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
| 892 | |
| 893 | for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++) |
| 894 | if (tui_win_list[type] |
| 895 | && tui_win_list[type]->is_visible) |
| 896 | { |
| 897 | if (win_with_focus == tui_win_list[type]) |
| 898 | printf_filtered (" %s\t(%d lines) <has focus>\n", |
| 899 | tui_win_name (tui_win_list[type]), |
| 900 | tui_win_list[type]->height); |
| 901 | else |
| 902 | printf_filtered (" %s\t(%d lines)\n", |
| 903 | tui_win_name (tui_win_list[type]), |
| 904 | tui_win_list[type]->height); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | |
| 909 | static void |
| 910 | tui_refresh_all_command (const char *arg, int from_tty) |
| 911 | { |
| 912 | /* Make sure the curses mode is enabled. */ |
| 913 | tui_enable (); |
| 914 | |
| 915 | tui_refresh_all_win (); |
| 916 | } |
| 917 | |
| 918 | /* The tab width that should be used by the TUI. */ |
| 919 | |
| 920 | unsigned int tui_tab_width = DEFAULT_TAB_LEN; |
| 921 | |
| 922 | /* The tab width as set by the user. */ |
| 923 | |
| 924 | static unsigned int internal_tab_width = DEFAULT_TAB_LEN; |
| 925 | |
| 926 | /* After the tab width is set, call this to update the relevant |
| 927 | windows. */ |
| 928 | |
| 929 | static void |
| 930 | update_tab_width () |
| 931 | { |
| 932 | /* We don't really change the height of any windows, but |
| 933 | calling these 2 functions causes a complete regeneration |
| 934 | and redisplay of the window's contents, which will take |
| 935 | the new tab width into account. */ |
| 936 | if (tui_win_list[SRC_WIN] |
| 937 | && tui_win_list[SRC_WIN]->is_visible) |
| 938 | { |
| 939 | make_invisible_and_set_new_height (TUI_SRC_WIN, |
| 940 | TUI_SRC_WIN->height); |
| 941 | make_visible_with_new_height (TUI_SRC_WIN); |
| 942 | } |
| 943 | if (tui_win_list[DISASSEM_WIN] |
| 944 | && tui_win_list[DISASSEM_WIN]->is_visible) |
| 945 | { |
| 946 | make_invisible_and_set_new_height (TUI_DISASM_WIN, |
| 947 | TUI_DISASM_WIN->height); |
| 948 | make_visible_with_new_height (TUI_DISASM_WIN); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /* Callback for "set tui tab-width". */ |
| 953 | |
| 954 | static void |
| 955 | tui_set_tab_width (const char *ignore, |
| 956 | int from_tty, struct cmd_list_element *c) |
| 957 | { |
| 958 | if (internal_tab_width == 0) |
| 959 | { |
| 960 | internal_tab_width = tui_tab_width; |
| 961 | error (_("Tab width must not be 0")); |
| 962 | } |
| 963 | |
| 964 | tui_tab_width = internal_tab_width; |
| 965 | update_tab_width (); |
| 966 | } |
| 967 | |
| 968 | /* Callback for "show tui tab-width". */ |
| 969 | |
| 970 | static void |
| 971 | tui_show_tab_width (struct ui_file *file, int from_tty, |
| 972 | struct cmd_list_element *c, const char *value) |
| 973 | { |
| 974 | fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value); |
| 975 | |
| 976 | } |
| 977 | |
| 978 | /* Set the tab width of the specified window. */ |
| 979 | static void |
| 980 | tui_set_tab_width_command (const char *arg, int from_tty) |
| 981 | { |
| 982 | /* Make sure the curses mode is enabled. */ |
| 983 | tui_enable (); |
| 984 | if (arg != NULL) |
| 985 | { |
| 986 | int ts; |
| 987 | |
| 988 | ts = atoi (arg); |
| 989 | if (ts <= 0) |
| 990 | warning (_("Tab widths greater than 0 must be specified.")); |
| 991 | else |
| 992 | { |
| 993 | internal_tab_width = ts; |
| 994 | tui_tab_width = ts; |
| 995 | |
| 996 | update_tab_width (); |
| 997 | } |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | /* Set the height of the specified window. */ |
| 1003 | static void |
| 1004 | tui_set_win_height (const char *arg, int from_tty) |
| 1005 | { |
| 1006 | /* Make sure the curses mode is enabled. */ |
| 1007 | tui_enable (); |
| 1008 | if (arg != NULL) |
| 1009 | { |
| 1010 | std::string copy = arg; |
| 1011 | char *buf = ©[0]; |
| 1012 | char *buf_ptr = buf; |
| 1013 | char *wname = NULL; |
| 1014 | int new_height, i; |
| 1015 | struct tui_win_info *win_info; |
| 1016 | |
| 1017 | wname = buf_ptr; |
| 1018 | buf_ptr = strchr (buf_ptr, ' '); |
| 1019 | if (buf_ptr != NULL) |
| 1020 | { |
| 1021 | *buf_ptr = (char) 0; |
| 1022 | |
| 1023 | /* Validate the window name. */ |
| 1024 | for (i = 0; i < strlen (wname); i++) |
| 1025 | wname[i] = tolower (wname[i]); |
| 1026 | win_info = tui_partial_win_by_name (wname); |
| 1027 | |
| 1028 | if (win_info == NULL || !win_info->is_visible) |
| 1029 | warning (_("Invalid window specified. \n\ |
| 1030 | The window name specified must be valid and visible.\n")); |
| 1031 | else |
| 1032 | { |
| 1033 | /* Process the size. */ |
| 1034 | while (*(++buf_ptr) == ' ') |
| 1035 | ; |
| 1036 | |
| 1037 | if (*buf_ptr != (char) 0) |
| 1038 | { |
| 1039 | int negate = FALSE; |
| 1040 | int fixed_size = TRUE; |
| 1041 | int input_no;; |
| 1042 | |
| 1043 | if (*buf_ptr == '+' || *buf_ptr == '-') |
| 1044 | { |
| 1045 | if (*buf_ptr == '-') |
| 1046 | negate = TRUE; |
| 1047 | fixed_size = FALSE; |
| 1048 | buf_ptr++; |
| 1049 | } |
| 1050 | input_no = atoi (buf_ptr); |
| 1051 | if (input_no > 0) |
| 1052 | { |
| 1053 | if (negate) |
| 1054 | input_no *= (-1); |
| 1055 | if (fixed_size) |
| 1056 | new_height = input_no; |
| 1057 | else |
| 1058 | new_height = win_info->height + input_no; |
| 1059 | |
| 1060 | /* Now change the window's height, and adjust |
| 1061 | all other windows around it. */ |
| 1062 | if (tui_adjust_win_heights (win_info, |
| 1063 | new_height) == TUI_FAILURE) |
| 1064 | warning (_("Invalid window height specified.\n%s"), |
| 1065 | WIN_HEIGHT_USAGE); |
| 1066 | else |
| 1067 | tui_update_gdb_sizes (); |
| 1068 | } |
| 1069 | else |
| 1070 | warning (_("Invalid window height specified.\n%s"), |
| 1071 | WIN_HEIGHT_USAGE); |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | else |
| 1076 | printf_filtered (WIN_HEIGHT_USAGE); |
| 1077 | } |
| 1078 | else |
| 1079 | printf_filtered (WIN_HEIGHT_USAGE); |
| 1080 | } |
| 1081 | |
| 1082 | /* Set the height of the specified window, with va_list. */ |
| 1083 | static void |
| 1084 | tui_set_win_height_command (const char *arg, int from_tty) |
| 1085 | { |
| 1086 | /* Make sure the curses mode is enabled. */ |
| 1087 | tui_enable (); |
| 1088 | tui_set_win_height (arg, from_tty); |
| 1089 | } |
| 1090 | |
| 1091 | /* Function to adjust all window heights around the primary. */ |
| 1092 | static enum tui_status |
| 1093 | tui_adjust_win_heights (struct tui_win_info *primary_win_info, |
| 1094 | int new_height) |
| 1095 | { |
| 1096 | enum tui_status status = TUI_FAILURE; |
| 1097 | |
| 1098 | if (new_height_ok (primary_win_info, new_height)) |
| 1099 | { |
| 1100 | status = TUI_SUCCESS; |
| 1101 | if (new_height != primary_win_info->height) |
| 1102 | { |
| 1103 | int diff; |
| 1104 | struct tui_win_info *win_info; |
| 1105 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
| 1106 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 1107 | |
| 1108 | diff = (new_height - primary_win_info->height) * (-1); |
| 1109 | if (cur_layout == SRC_COMMAND |
| 1110 | || cur_layout == DISASSEM_COMMAND) |
| 1111 | { |
| 1112 | struct tui_win_info *src_win_info; |
| 1113 | |
| 1114 | make_invisible_and_set_new_height (primary_win_info, new_height); |
| 1115 | if (primary_win_info->type == CMD_WIN) |
| 1116 | { |
| 1117 | win_info = tui_source_windows ()[0]; |
| 1118 | src_win_info = win_info; |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | win_info = tui_win_list[CMD_WIN]; |
| 1123 | src_win_info = primary_win_info; |
| 1124 | } |
| 1125 | make_invisible_and_set_new_height (win_info, |
| 1126 | win_info->height + diff); |
| 1127 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
| 1128 | make_visible_with_new_height (win_info); |
| 1129 | make_visible_with_new_height (primary_win_info); |
| 1130 | if (src_win_info->content_size <= 0) |
| 1131 | tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT); |
| 1132 | } |
| 1133 | else |
| 1134 | { |
| 1135 | struct tui_win_info *first_win; |
| 1136 | struct tui_win_info *second_win; |
| 1137 | |
| 1138 | if (cur_layout == SRC_DISASSEM_COMMAND) |
| 1139 | { |
| 1140 | first_win = TUI_SRC_WIN; |
| 1141 | second_win = TUI_DISASM_WIN; |
| 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | first_win = TUI_DATA_WIN; |
| 1146 | second_win = tui_source_windows ()[0]; |
| 1147 | } |
| 1148 | if (primary_win_info == TUI_CMD_WIN) |
| 1149 | { /* Split the change in height accross the 1st & 2nd |
| 1150 | windows, adjusting them as well. */ |
| 1151 | /* Subtract the locator. */ |
| 1152 | int first_split_diff = diff / 2; |
| 1153 | int second_split_diff = first_split_diff; |
| 1154 | |
| 1155 | if (diff % 2) |
| 1156 | { |
| 1157 | if (first_win->height > |
| 1158 | second_win->height) |
| 1159 | if (diff < 0) |
| 1160 | first_split_diff--; |
| 1161 | else |
| 1162 | first_split_diff++; |
| 1163 | else |
| 1164 | { |
| 1165 | if (diff < 0) |
| 1166 | second_split_diff--; |
| 1167 | else |
| 1168 | second_split_diff++; |
| 1169 | } |
| 1170 | } |
| 1171 | /* Make sure that the minimum hieghts are |
| 1172 | honored. */ |
| 1173 | while ((first_win->height + first_split_diff) < 3) |
| 1174 | { |
| 1175 | first_split_diff++; |
| 1176 | second_split_diff--; |
| 1177 | } |
| 1178 | while ((second_win->height + second_split_diff) < 3) |
| 1179 | { |
| 1180 | second_split_diff++; |
| 1181 | first_split_diff--; |
| 1182 | } |
| 1183 | make_invisible_and_set_new_height ( |
| 1184 | first_win, |
| 1185 | first_win->height + first_split_diff); |
| 1186 | second_win->origin.y = first_win->height - 1; |
| 1187 | make_invisible_and_set_new_height (second_win, |
| 1188 | second_win->height |
| 1189 | + second_split_diff); |
| 1190 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
| 1191 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
| 1192 | } |
| 1193 | else |
| 1194 | { |
| 1195 | if ((TUI_CMD_WIN->height + diff) < 1) |
| 1196 | { /* If there is no way to increase the command |
| 1197 | window take real estate from the 1st or 2nd |
| 1198 | window. */ |
| 1199 | if ((TUI_CMD_WIN->height + diff) < 1) |
| 1200 | { |
| 1201 | int i; |
| 1202 | |
| 1203 | for (i = TUI_CMD_WIN->height + diff; |
| 1204 | (i < 1); i++) |
| 1205 | if (primary_win_info == first_win) |
| 1206 | second_win->height--; |
| 1207 | else |
| 1208 | first_win->height--; |
| 1209 | } |
| 1210 | } |
| 1211 | if (primary_win_info == first_win) |
| 1212 | make_invisible_and_set_new_height (first_win, new_height); |
| 1213 | else |
| 1214 | make_invisible_and_set_new_height ( |
| 1215 | first_win, |
| 1216 | first_win->height); |
| 1217 | second_win->origin.y = first_win->height - 1; |
| 1218 | if (primary_win_info == second_win) |
| 1219 | make_invisible_and_set_new_height (second_win, new_height); |
| 1220 | else |
| 1221 | make_invisible_and_set_new_height ( |
| 1222 | second_win, second_win->height); |
| 1223 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
| 1224 | if ((TUI_CMD_WIN->height + diff) < 1) |
| 1225 | make_invisible_and_set_new_height (TUI_CMD_WIN, 1); |
| 1226 | else |
| 1227 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
| 1228 | TUI_CMD_WIN->height + diff); |
| 1229 | } |
| 1230 | make_visible_with_new_height (TUI_CMD_WIN); |
| 1231 | make_visible_with_new_height (second_win); |
| 1232 | make_visible_with_new_height (first_win); |
| 1233 | if (first_win->content_size <= 0) |
| 1234 | tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT); |
| 1235 | if (second_win->content_size <= 0) |
| 1236 | tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT); |
| 1237 | } |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | return status; |
| 1242 | } |
| 1243 | |
| 1244 | |
| 1245 | /* See tui-data.h. */ |
| 1246 | |
| 1247 | void |
| 1248 | tui_source_window_base::set_new_height (int height) |
| 1249 | { |
| 1250 | tui_make_invisible (execution_info); |
| 1251 | execution_info->height = height; |
| 1252 | execution_info->origin.y = origin.y; |
| 1253 | if (height > 1) |
| 1254 | execution_info->viewport_height = height - 1; |
| 1255 | else |
| 1256 | execution_info->viewport_height = height; |
| 1257 | execution_info->viewport_height--; |
| 1258 | |
| 1259 | if (has_locator ()) |
| 1260 | { |
| 1261 | tui_gen_win_info *gen_win_info = tui_locator_win_info_ptr (); |
| 1262 | tui_make_invisible (gen_win_info); |
| 1263 | gen_win_info->origin.y = origin.y + height; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | /* See tui-data.h. */ |
| 1268 | |
| 1269 | void |
| 1270 | tui_data_window::set_new_height (int height) |
| 1271 | { |
| 1272 | /* Delete all data item windows. */ |
| 1273 | for (int i = 0; i < content_size; i++) |
| 1274 | { |
| 1275 | struct tui_gen_win_info *gen_win_info |
| 1276 | = content[i]->which_element.data_window; |
| 1277 | tui_delete_win (gen_win_info->handle); |
| 1278 | gen_win_info->handle = NULL; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | /* Function make the target window (and auxillary windows associated |
| 1283 | with the targer) invisible, and set the new height and |
| 1284 | location. */ |
| 1285 | static void |
| 1286 | make_invisible_and_set_new_height (struct tui_win_info *win_info, |
| 1287 | int height) |
| 1288 | { |
| 1289 | tui_make_invisible (win_info); |
| 1290 | win_info->height = height; |
| 1291 | if (height > 1) |
| 1292 | win_info->viewport_height = height - 1; |
| 1293 | else |
| 1294 | win_info->viewport_height = height; |
| 1295 | if (win_info != TUI_CMD_WIN) |
| 1296 | win_info->viewport_height--; |
| 1297 | |
| 1298 | /* Now deal with the auxillary windows associated with win_info. */ |
| 1299 | win_info->set_new_height (height); |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | /* Function to make the windows with new heights visible. This means |
| 1304 | re-creating the windows' content since the window had to be |
| 1305 | destroyed to be made invisible. */ |
| 1306 | static void |
| 1307 | make_visible_with_new_height (struct tui_win_info *win_info) |
| 1308 | { |
| 1309 | struct symtab *s; |
| 1310 | |
| 1311 | tui_make_visible (win_info); |
| 1312 | tui_check_and_display_highlight_if_needed (win_info); |
| 1313 | tui_source_window_base *base; |
| 1314 | switch (win_info->type) |
| 1315 | { |
| 1316 | case SRC_WIN: |
| 1317 | case DISASSEM_WIN: |
| 1318 | base = (tui_source_window_base *) win_info; |
| 1319 | tui_free_win_content (base->execution_info); |
| 1320 | tui_make_visible (base->execution_info); |
| 1321 | if (win_info->content != NULL) |
| 1322 | { |
| 1323 | struct gdbarch *gdbarch = base->gdbarch; |
| 1324 | struct tui_line_or_address line_or_addr; |
| 1325 | struct symtab_and_line cursal |
| 1326 | = get_current_source_symtab_and_line (); |
| 1327 | |
| 1328 | line_or_addr = base->start_line_or_addr; |
| 1329 | tui_free_win_content (win_info); |
| 1330 | tui_update_source_window (base, gdbarch, |
| 1331 | cursal.symtab, line_or_addr, TRUE); |
| 1332 | } |
| 1333 | else if (deprecated_safe_get_selected_frame () != NULL) |
| 1334 | { |
| 1335 | struct tui_line_or_address line; |
| 1336 | struct symtab_and_line cursal |
| 1337 | = get_current_source_symtab_and_line (); |
| 1338 | struct frame_info *frame = deprecated_safe_get_selected_frame (); |
| 1339 | struct gdbarch *gdbarch = get_frame_arch (frame); |
| 1340 | |
| 1341 | s = find_pc_line_symtab (get_frame_pc (frame)); |
| 1342 | if (win_info->type == SRC_WIN) |
| 1343 | { |
| 1344 | line.loa = LOA_LINE; |
| 1345 | line.u.line_no = cursal.line; |
| 1346 | } |
| 1347 | else |
| 1348 | { |
| 1349 | line.loa = LOA_ADDRESS; |
| 1350 | find_line_pc (s, cursal.line, &line.u.addr); |
| 1351 | } |
| 1352 | tui_update_source_window (base, gdbarch, s, line, TRUE); |
| 1353 | } |
| 1354 | if (win_info->has_locator ()) |
| 1355 | { |
| 1356 | tui_make_visible (tui_locator_win_info_ptr ()); |
| 1357 | tui_show_locator_content (); |
| 1358 | } |
| 1359 | break; |
| 1360 | case DATA_WIN: |
| 1361 | tui_display_all_data (); |
| 1362 | break; |
| 1363 | case CMD_WIN: |
| 1364 | #ifdef HAVE_WRESIZE |
| 1365 | wresize (TUI_CMD_WIN->handle, |
| 1366 | TUI_CMD_WIN->height, |
| 1367 | TUI_CMD_WIN->width); |
| 1368 | #endif |
| 1369 | mvwin (TUI_CMD_WIN->handle, |
| 1370 | TUI_CMD_WIN->origin.y, |
| 1371 | TUI_CMD_WIN->origin.x); |
| 1372 | wmove (win_info->handle, 0, 0); |
| 1373 | break; |
| 1374 | default: |
| 1375 | break; |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | |
| 1380 | /* See tui-data.h. */ |
| 1381 | |
| 1382 | int |
| 1383 | tui_win_info::max_height () const |
| 1384 | { |
| 1385 | return tui_term_height () - 2; |
| 1386 | } |
| 1387 | |
| 1388 | /* See tui-data.h. */ |
| 1389 | |
| 1390 | int |
| 1391 | tui_cmd_window::max_height () const |
| 1392 | { |
| 1393 | return tui_term_height () - 4; |
| 1394 | } |
| 1395 | |
| 1396 | static int |
| 1397 | new_height_ok (struct tui_win_info *primary_win_info, |
| 1398 | int new_height) |
| 1399 | { |
| 1400 | int ok = (new_height < tui_term_height ()); |
| 1401 | |
| 1402 | if (ok) |
| 1403 | { |
| 1404 | int diff; |
| 1405 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 1406 | |
| 1407 | diff = (new_height - primary_win_info->height) * (-1); |
| 1408 | if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND) |
| 1409 | { |
| 1410 | ok = (new_height <= primary_win_info->max_height () |
| 1411 | && new_height >= MIN_CMD_WIN_HEIGHT); |
| 1412 | if (ok) |
| 1413 | { /* Check the total height. */ |
| 1414 | struct tui_win_info *win_info; |
| 1415 | |
| 1416 | if (primary_win_info == TUI_CMD_WIN) |
| 1417 | win_info = tui_source_windows ()[0]; |
| 1418 | else |
| 1419 | win_info = TUI_CMD_WIN; |
| 1420 | ok = ((new_height + |
| 1421 | (win_info->height + diff)) <= tui_term_height ()); |
| 1422 | } |
| 1423 | } |
| 1424 | else |
| 1425 | { |
| 1426 | int cur_total_height, total_height, min_height = 0; |
| 1427 | struct tui_win_info *first_win; |
| 1428 | struct tui_win_info *second_win; |
| 1429 | |
| 1430 | if (cur_layout == SRC_DISASSEM_COMMAND) |
| 1431 | { |
| 1432 | first_win = TUI_SRC_WIN; |
| 1433 | second_win = TUI_DISASM_WIN; |
| 1434 | } |
| 1435 | else |
| 1436 | { |
| 1437 | first_win = TUI_DATA_WIN; |
| 1438 | second_win = tui_source_windows ()[0]; |
| 1439 | } |
| 1440 | /* We could simply add all the heights to obtain the same |
| 1441 | result but below is more explicit since we subtract 1 for |
| 1442 | the line that the first and second windows share, and add |
| 1443 | one for the locator. */ |
| 1444 | total_height = cur_total_height = |
| 1445 | (first_win->height + second_win->height - 1) |
| 1446 | + TUI_CMD_WIN->height + 1; /* Locator. */ |
| 1447 | if (primary_win_info == TUI_CMD_WIN) |
| 1448 | { |
| 1449 | /* Locator included since first & second win share a line. */ |
| 1450 | ok = ((first_win->height + |
| 1451 | second_win->height + diff) >= |
| 1452 | (MIN_WIN_HEIGHT * 2) |
| 1453 | && new_height >= MIN_CMD_WIN_HEIGHT); |
| 1454 | if (ok) |
| 1455 | { |
| 1456 | total_height = new_height + |
| 1457 | (first_win->height + |
| 1458 | second_win->height + diff); |
| 1459 | min_height = MIN_CMD_WIN_HEIGHT; |
| 1460 | } |
| 1461 | } |
| 1462 | else |
| 1463 | { |
| 1464 | min_height = MIN_WIN_HEIGHT; |
| 1465 | |
| 1466 | /* First see if we can increase/decrease the command |
| 1467 | window. And make sure that the command window is at |
| 1468 | least 1 line. */ |
| 1469 | ok = ((TUI_CMD_WIN->height + diff) > 0); |
| 1470 | if (!ok) |
| 1471 | { /* Looks like we have to increase/decrease one of |
| 1472 | the other windows. */ |
| 1473 | if (primary_win_info == first_win) |
| 1474 | ok = (second_win->height + diff) >= min_height; |
| 1475 | else |
| 1476 | ok = (first_win->height + diff) >= min_height; |
| 1477 | } |
| 1478 | if (ok) |
| 1479 | { |
| 1480 | if (primary_win_info == first_win) |
| 1481 | total_height = new_height + |
| 1482 | second_win->height + |
| 1483 | TUI_CMD_WIN->height + diff; |
| 1484 | else |
| 1485 | total_height = new_height + |
| 1486 | first_win->height + |
| 1487 | TUI_CMD_WIN->height + diff; |
| 1488 | } |
| 1489 | } |
| 1490 | /* Now make sure that the proposed total height doesn't |
| 1491 | exceed the old total height. */ |
| 1492 | if (ok) |
| 1493 | ok = (new_height >= min_height |
| 1494 | && total_height <= cur_total_height); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | return ok; |
| 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | static void |
| 1503 | parse_scrolling_args (const char *arg, |
| 1504 | struct tui_win_info **win_to_scroll, |
| 1505 | int *num_to_scroll) |
| 1506 | { |
| 1507 | if (num_to_scroll) |
| 1508 | *num_to_scroll = 0; |
| 1509 | *win_to_scroll = tui_win_with_focus (); |
| 1510 | |
| 1511 | /* First set up the default window to scroll, in case there is no |
| 1512 | window name arg. */ |
| 1513 | if (arg != NULL) |
| 1514 | { |
| 1515 | char *buf_ptr; |
| 1516 | |
| 1517 | /* Process the number of lines to scroll. */ |
| 1518 | std::string copy = arg; |
| 1519 | buf_ptr = ©[0]; |
| 1520 | if (isdigit (*buf_ptr)) |
| 1521 | { |
| 1522 | char *num_str; |
| 1523 | |
| 1524 | num_str = buf_ptr; |
| 1525 | buf_ptr = strchr (buf_ptr, ' '); |
| 1526 | if (buf_ptr != NULL) |
| 1527 | { |
| 1528 | *buf_ptr = (char) 0; |
| 1529 | if (num_to_scroll) |
| 1530 | *num_to_scroll = atoi (num_str); |
| 1531 | buf_ptr++; |
| 1532 | } |
| 1533 | else if (num_to_scroll) |
| 1534 | *num_to_scroll = atoi (num_str); |
| 1535 | } |
| 1536 | |
| 1537 | /* Process the window name if one is specified. */ |
| 1538 | if (buf_ptr != NULL) |
| 1539 | { |
| 1540 | const char *wname; |
| 1541 | |
| 1542 | if (*buf_ptr == ' ') |
| 1543 | while (*(++buf_ptr) == ' ') |
| 1544 | ; |
| 1545 | |
| 1546 | if (*buf_ptr != (char) 0) |
| 1547 | { |
| 1548 | /* Validate the window name. */ |
| 1549 | for (char *p = buf_ptr; *p != '\0'; p++) |
| 1550 | *p = tolower (*p); |
| 1551 | |
| 1552 | wname = buf_ptr; |
| 1553 | } |
| 1554 | else |
| 1555 | wname = "?"; |
| 1556 | |
| 1557 | *win_to_scroll = tui_partial_win_by_name (wname); |
| 1558 | |
| 1559 | if (*win_to_scroll == NULL |
| 1560 | || !(*win_to_scroll)->is_visible) |
| 1561 | error (_("Invalid window specified. \n\ |
| 1562 | The window name specified must be valid and visible.\n")); |
| 1563 | else if (*win_to_scroll == TUI_CMD_WIN) |
| 1564 | *win_to_scroll = tui_source_windows ()[0]; |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | /* Function to initialize gdb commands, for tui window |
| 1570 | manipulation. */ |
| 1571 | |
| 1572 | void |
| 1573 | _initialize_tui_win (void) |
| 1574 | { |
| 1575 | static struct cmd_list_element *tui_setlist; |
| 1576 | static struct cmd_list_element *tui_showlist; |
| 1577 | struct cmd_list_element *cmd; |
| 1578 | |
| 1579 | /* Define the classes of commands. |
| 1580 | They will appear in the help list in the reverse of this order. */ |
| 1581 | add_prefix_cmd ("tui", class_tui, set_tui_cmd, |
| 1582 | _("TUI configuration variables"), |
| 1583 | &tui_setlist, "set tui ", |
| 1584 | 0 /* allow-unknown */, &setlist); |
| 1585 | add_prefix_cmd ("tui", class_tui, show_tui_cmd, |
| 1586 | _("TUI configuration variables"), |
| 1587 | &tui_showlist, "show tui ", |
| 1588 | 0 /* allow-unknown */, &showlist); |
| 1589 | |
| 1590 | add_com ("refresh", class_tui, tui_refresh_all_command, |
| 1591 | _("Refresh the terminal display.")); |
| 1592 | |
| 1593 | cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\ |
| 1594 | Set the width (in characters) of tab stops.\n\ |
| 1595 | Usage: tabset N")); |
| 1596 | deprecate_cmd (cmd, "set tui tab-width"); |
| 1597 | |
| 1598 | cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\ |
| 1599 | Set or modify the height of a specified window.\n" |
| 1600 | WIN_HEIGHT_USAGE |
| 1601 | "Window names are:\n\ |
| 1602 | src : the source window\n\ |
| 1603 | cmd : the command window\n\ |
| 1604 | asm : the disassembly window\n\ |
| 1605 | regs : the register display")); |
| 1606 | add_com_alias ("wh", "winheight", class_tui, 0); |
| 1607 | set_cmd_completer (cmd, winheight_completer); |
| 1608 | add_info ("win", tui_all_windows_info, |
| 1609 | _("List of all displayed windows.")); |
| 1610 | cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\ |
| 1611 | Set focus to named window or next/prev window.\n" |
| 1612 | FOCUS_USAGE |
| 1613 | "Valid Window names are:\n\ |
| 1614 | src : the source window\n\ |
| 1615 | asm : the disassembly window\n\ |
| 1616 | regs : the register display\n\ |
| 1617 | cmd : the command window")); |
| 1618 | add_com_alias ("fs", "focus", class_tui, 0); |
| 1619 | set_cmd_completer (cmd, focus_completer); |
| 1620 | add_com ("+", class_tui, tui_scroll_forward_command, _("\ |
| 1621 | Scroll window forward.\n\ |
| 1622 | Usage: + [WIN] [N]")); |
| 1623 | add_com ("-", class_tui, tui_scroll_backward_command, _("\ |
| 1624 | Scroll window backward.\n\ |
| 1625 | Usage: - [WIN] [N]")); |
| 1626 | add_com ("<", class_tui, tui_scroll_left_command, _("\ |
| 1627 | Scroll window text to the left.\n\ |
| 1628 | Usage: < [WIN] [N]")); |
| 1629 | add_com (">", class_tui, tui_scroll_right_command, _("\ |
| 1630 | Scroll window text to the right.\n\ |
| 1631 | Usage: > [WIN] [N]")); |
| 1632 | |
| 1633 | /* Define the tui control variables. */ |
| 1634 | add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums, |
| 1635 | &tui_border_kind, _("\ |
| 1636 | Set the kind of border for TUI windows."), _("\ |
| 1637 | Show the kind of border for TUI windows."), _("\ |
| 1638 | This variable controls the border of TUI windows:\n\ |
| 1639 | space use a white space\n\ |
| 1640 | ascii use ascii characters + - | for the border\n\ |
| 1641 | acs use the Alternate Character Set"), |
| 1642 | tui_set_var_cmd, |
| 1643 | show_tui_border_kind, |
| 1644 | &tui_setlist, &tui_showlist); |
| 1645 | |
| 1646 | add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums, |
| 1647 | &tui_border_mode, _("\ |
| 1648 | Set the attribute mode to use for the TUI window borders."), _("\ |
| 1649 | Show the attribute mode to use for the TUI window borders."), _("\ |
| 1650 | This variable controls the attributes to use for the window borders:\n\ |
| 1651 | normal normal display\n\ |
| 1652 | standout use highlight mode of terminal\n\ |
| 1653 | reverse use reverse video mode\n\ |
| 1654 | half use half bright\n\ |
| 1655 | half-standout use half bright and standout mode\n\ |
| 1656 | bold use extra bright or bold\n\ |
| 1657 | bold-standout use extra bright or bold with standout mode"), |
| 1658 | tui_set_var_cmd, |
| 1659 | show_tui_border_mode, |
| 1660 | &tui_setlist, &tui_showlist); |
| 1661 | |
| 1662 | add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums, |
| 1663 | &tui_active_border_mode, _("\ |
| 1664 | Set the attribute mode to use for the active TUI window border."), _("\ |
| 1665 | Show the attribute mode to use for the active TUI window border."), _("\ |
| 1666 | This variable controls the attributes to use for the active window border:\n\ |
| 1667 | normal normal display\n\ |
| 1668 | standout use highlight mode of terminal\n\ |
| 1669 | reverse use reverse video mode\n\ |
| 1670 | half use half bright\n\ |
| 1671 | half-standout use half bright and standout mode\n\ |
| 1672 | bold use extra bright or bold\n\ |
| 1673 | bold-standout use extra bright or bold with standout mode"), |
| 1674 | tui_set_var_cmd, |
| 1675 | show_tui_active_border_mode, |
| 1676 | &tui_setlist, &tui_showlist); |
| 1677 | |
| 1678 | add_setshow_zuinteger_cmd ("tab-width", no_class, |
| 1679 | &internal_tab_width, _("\ |
| 1680 | Set the tab width, in characters, for the TUI."), _("\ |
| 1681 | Show the tab witdh, in characters, for the TUI"), _("\ |
| 1682 | This variable controls how many spaces are used to display a tab character."), |
| 1683 | tui_set_tab_width, tui_show_tab_width, |
| 1684 | &tui_setlist, &tui_showlist); |
| 1685 | } |