| 1 | /* TUI layout window management. |
| 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 | #include "defs.h" |
| 23 | #include "arch-utils.h" |
| 24 | #include "command.h" |
| 25 | #include "symtab.h" |
| 26 | #include "frame.h" |
| 27 | #include "source.h" |
| 28 | #include <ctype.h> |
| 29 | |
| 30 | #include "tui/tui.h" |
| 31 | #include "tui/tui-data.h" |
| 32 | #include "tui/tui-windata.h" |
| 33 | #include "tui/tui-wingeneral.h" |
| 34 | #include "tui/tui-stack.h" |
| 35 | #include "tui/tui-regs.h" |
| 36 | #include "tui/tui-win.h" |
| 37 | #include "tui/tui-winsource.h" |
| 38 | #include "tui/tui-disasm.h" |
| 39 | #include "tui/tui-layout.h" |
| 40 | #include "gdb_curses.h" |
| 41 | |
| 42 | /******************************* |
| 43 | ** Static Local Decls |
| 44 | ********************************/ |
| 45 | static void show_layout (enum tui_layout_type); |
| 46 | static void init_gen_win_info (struct tui_gen_win_info *, |
| 47 | enum tui_win_type, |
| 48 | int, int, int, int); |
| 49 | static void *init_and_make_win (void *, enum tui_win_type, |
| 50 | int, int, int, int, int); |
| 51 | static void show_source_or_disasm_and_command (enum tui_layout_type); |
| 52 | static struct tui_win_info *make_source_or_disasm_window (enum tui_win_type, |
| 53 | int, int); |
| 54 | static struct tui_win_info *make_command_window (int, int); |
| 55 | static struct tui_win_info *make_source_window (int, int); |
| 56 | static struct tui_win_info *make_disasm_window (int, int); |
| 57 | static void make_data_window (struct tui_win_info **, int, int); |
| 58 | static void show_source_command (void); |
| 59 | static void show_disasm_command (void); |
| 60 | static void show_source_disasm_command (void); |
| 61 | static void show_data (enum tui_layout_type); |
| 62 | static enum tui_layout_type next_layout (void); |
| 63 | static enum tui_layout_type prev_layout (void); |
| 64 | static void tui_layout_command (const char *, int); |
| 65 | static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *); |
| 66 | |
| 67 | |
| 68 | /*************************************** |
| 69 | ** DEFINITIONS |
| 70 | ***************************************/ |
| 71 | |
| 72 | #define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n" |
| 73 | |
| 74 | /* Show the screen layout defined. */ |
| 75 | static void |
| 76 | show_layout (enum tui_layout_type layout) |
| 77 | { |
| 78 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 79 | |
| 80 | if (layout != cur_layout) |
| 81 | { |
| 82 | /* Since the new layout may cause changes in window size, we |
| 83 | should free the content and reallocate on next display of |
| 84 | source/asm. */ |
| 85 | tui_free_all_source_wins_content (); |
| 86 | tui_clear_source_windows (); |
| 87 | if (layout == SRC_DATA_COMMAND |
| 88 | || layout == DISASSEM_DATA_COMMAND) |
| 89 | { |
| 90 | show_data (layout); |
| 91 | tui_refresh_all (tui_win_list); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | /* First make the current layout be invisible. */ |
| 96 | tui_make_all_invisible (); |
| 97 | tui_make_invisible (tui_locator_win_info_ptr ()); |
| 98 | |
| 99 | switch (layout) |
| 100 | { |
| 101 | /* Now show the new layout. */ |
| 102 | case SRC_COMMAND: |
| 103 | show_source_command (); |
| 104 | tui_add_to_source_windows (TUI_SRC_WIN); |
| 105 | break; |
| 106 | case DISASSEM_COMMAND: |
| 107 | show_disasm_command (); |
| 108 | tui_add_to_source_windows (TUI_DISASM_WIN); |
| 109 | break; |
| 110 | case SRC_DISASSEM_COMMAND: |
| 111 | show_source_disasm_command (); |
| 112 | tui_add_to_source_windows (TUI_SRC_WIN); |
| 113 | tui_add_to_source_windows (TUI_DISASM_WIN); |
| 114 | break; |
| 115 | default: |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND, |
| 124 | SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */ |
| 125 | enum tui_status |
| 126 | tui_set_layout (enum tui_layout_type layout_type) |
| 127 | { |
| 128 | enum tui_status status = TUI_SUCCESS; |
| 129 | |
| 130 | if (layout_type != UNDEFINED_LAYOUT) |
| 131 | { |
| 132 | enum tui_layout_type cur_layout = tui_current_layout (), |
| 133 | new_layout = UNDEFINED_LAYOUT; |
| 134 | int regs_populate = FALSE; |
| 135 | struct gdbarch *gdbarch; |
| 136 | CORE_ADDR addr; |
| 137 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
| 138 | struct tui_layout_def *layout_def = tui_layout_def (); |
| 139 | |
| 140 | extract_display_start_addr (&gdbarch, &addr); |
| 141 | |
| 142 | new_layout = layout_type; |
| 143 | |
| 144 | regs_populate = (new_layout == SRC_DATA_COMMAND |
| 145 | || new_layout == DISASSEM_DATA_COMMAND); |
| 146 | if (new_layout != cur_layout) |
| 147 | { |
| 148 | show_layout (new_layout); |
| 149 | |
| 150 | /* Now determine where focus should be. */ |
| 151 | if (win_with_focus != TUI_CMD_WIN) |
| 152 | { |
| 153 | switch (new_layout) |
| 154 | { |
| 155 | case SRC_COMMAND: |
| 156 | tui_set_win_focus_to (TUI_SRC_WIN); |
| 157 | layout_def->display_mode = SRC_WIN; |
| 158 | layout_def->split = FALSE; |
| 159 | break; |
| 160 | case DISASSEM_COMMAND: |
| 161 | /* The previous layout was not showing code. |
| 162 | This can happen if there is no source |
| 163 | available: |
| 164 | |
| 165 | 1. if the source file is in another dir OR |
| 166 | 2. if target was compiled without -g |
| 167 | We still want to show the assembly though! */ |
| 168 | |
| 169 | tui_get_begin_asm_address (&gdbarch, &addr); |
| 170 | tui_set_win_focus_to (TUI_DISASM_WIN); |
| 171 | layout_def->display_mode = DISASSEM_WIN; |
| 172 | layout_def->split = FALSE; |
| 173 | break; |
| 174 | case SRC_DISASSEM_COMMAND: |
| 175 | /* The previous layout was not showing code. |
| 176 | This can happen if there is no source |
| 177 | available: |
| 178 | |
| 179 | 1. if the source file is in another dir OR |
| 180 | 2. if target was compiled without -g |
| 181 | We still want to show the assembly though! */ |
| 182 | |
| 183 | tui_get_begin_asm_address (&gdbarch, &addr); |
| 184 | if (win_with_focus == TUI_SRC_WIN) |
| 185 | tui_set_win_focus_to (TUI_SRC_WIN); |
| 186 | else |
| 187 | tui_set_win_focus_to (TUI_DISASM_WIN); |
| 188 | layout_def->split = TRUE; |
| 189 | break; |
| 190 | case SRC_DATA_COMMAND: |
| 191 | if (win_with_focus != TUI_DATA_WIN) |
| 192 | tui_set_win_focus_to (TUI_SRC_WIN); |
| 193 | else |
| 194 | tui_set_win_focus_to (TUI_DATA_WIN); |
| 195 | layout_def->display_mode = SRC_WIN; |
| 196 | layout_def->split = FALSE; |
| 197 | break; |
| 198 | case DISASSEM_DATA_COMMAND: |
| 199 | /* The previous layout was not showing code. |
| 200 | This can happen if there is no source |
| 201 | available: |
| 202 | |
| 203 | 1. if the source file is in another dir OR |
| 204 | 2. if target was compiled without -g |
| 205 | We still want to show the assembly though! */ |
| 206 | |
| 207 | tui_get_begin_asm_address (&gdbarch, &addr); |
| 208 | if (win_with_focus != TUI_DATA_WIN) |
| 209 | tui_set_win_focus_to (TUI_DISASM_WIN); |
| 210 | else |
| 211 | tui_set_win_focus_to (TUI_DATA_WIN); |
| 212 | layout_def->display_mode = DISASSEM_WIN; |
| 213 | layout_def->split = FALSE; |
| 214 | break; |
| 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | /* |
| 220 | * Now update the window content. |
| 221 | */ |
| 222 | if (!regs_populate |
| 223 | && (new_layout == SRC_DATA_COMMAND |
| 224 | || new_layout == DISASSEM_DATA_COMMAND)) |
| 225 | tui_display_all_data (); |
| 226 | |
| 227 | tui_update_source_windows_with_addr (gdbarch, addr); |
| 228 | |
| 229 | if (regs_populate) |
| 230 | tui_show_registers (TUI_DATA_WIN->current_group); |
| 231 | } |
| 232 | } |
| 233 | else |
| 234 | status = TUI_FAILURE; |
| 235 | |
| 236 | return status; |
| 237 | } |
| 238 | |
| 239 | /* Add the specified window to the layout in a logical way. This |
| 240 | means setting up the most logical layout given the window to be |
| 241 | added. */ |
| 242 | void |
| 243 | tui_add_win_to_layout (enum tui_win_type type) |
| 244 | { |
| 245 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 246 | |
| 247 | switch (type) |
| 248 | { |
| 249 | case SRC_WIN: |
| 250 | if (cur_layout != SRC_COMMAND |
| 251 | && cur_layout != SRC_DISASSEM_COMMAND |
| 252 | && cur_layout != SRC_DATA_COMMAND) |
| 253 | { |
| 254 | tui_clear_source_windows_detail (); |
| 255 | if (cur_layout == DISASSEM_DATA_COMMAND) |
| 256 | show_layout (SRC_DATA_COMMAND); |
| 257 | else |
| 258 | show_layout (SRC_COMMAND); |
| 259 | } |
| 260 | break; |
| 261 | case DISASSEM_WIN: |
| 262 | if (cur_layout != DISASSEM_COMMAND |
| 263 | && cur_layout != SRC_DISASSEM_COMMAND |
| 264 | && cur_layout != DISASSEM_DATA_COMMAND) |
| 265 | { |
| 266 | tui_clear_source_windows_detail (); |
| 267 | if (cur_layout == SRC_DATA_COMMAND) |
| 268 | show_layout (DISASSEM_DATA_COMMAND); |
| 269 | else |
| 270 | show_layout (DISASSEM_COMMAND); |
| 271 | } |
| 272 | break; |
| 273 | case DATA_WIN: |
| 274 | if (cur_layout != SRC_DATA_COMMAND |
| 275 | && cur_layout != DISASSEM_DATA_COMMAND) |
| 276 | { |
| 277 | if (cur_layout == DISASSEM_COMMAND) |
| 278 | show_layout (DISASSEM_DATA_COMMAND); |
| 279 | else |
| 280 | show_layout (SRC_DATA_COMMAND); |
| 281 | } |
| 282 | break; |
| 283 | default: |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /* Answer the height of a window. If it hasn't been created yet, |
| 290 | answer what the height of a window would be based upon its type and |
| 291 | the layout. */ |
| 292 | int |
| 293 | tui_default_win_height (enum tui_win_type type, |
| 294 | enum tui_layout_type layout) |
| 295 | { |
| 296 | int h; |
| 297 | |
| 298 | if (tui_win_list[type] != NULL) |
| 299 | h = tui_win_list[type]->generic.height; |
| 300 | else |
| 301 | { |
| 302 | switch (layout) |
| 303 | { |
| 304 | case SRC_COMMAND: |
| 305 | case DISASSEM_COMMAND: |
| 306 | if (TUI_CMD_WIN == NULL) |
| 307 | h = tui_term_height () / 2; |
| 308 | else |
| 309 | h = tui_term_height () - TUI_CMD_WIN->generic.height; |
| 310 | break; |
| 311 | case SRC_DISASSEM_COMMAND: |
| 312 | case SRC_DATA_COMMAND: |
| 313 | case DISASSEM_DATA_COMMAND: |
| 314 | if (TUI_CMD_WIN == NULL) |
| 315 | h = tui_term_height () / 3; |
| 316 | else |
| 317 | h = (tui_term_height () - TUI_CMD_WIN->generic.height) / 2; |
| 318 | break; |
| 319 | default: |
| 320 | h = 0; |
| 321 | break; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return h; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | /* Answer the height of a window. If it hasn't been created yet, |
| 330 | answer what the height of a window would be based upon its type and |
| 331 | the layout. */ |
| 332 | int |
| 333 | tui_default_win_viewport_height (enum tui_win_type type, |
| 334 | enum tui_layout_type layout) |
| 335 | { |
| 336 | int h; |
| 337 | |
| 338 | h = tui_default_win_height (type, layout); |
| 339 | |
| 340 | if (tui_win_list[type] == TUI_CMD_WIN) |
| 341 | h -= 1; |
| 342 | else |
| 343 | h -= 2; |
| 344 | |
| 345 | return h; |
| 346 | } |
| 347 | |
| 348 | /* Complete possible layout names. TEXT is the complete text entered so |
| 349 | far, WORD is the word currently being completed. */ |
| 350 | |
| 351 | static void |
| 352 | layout_completer (struct cmd_list_element *ignore, |
| 353 | completion_tracker &tracker, |
| 354 | const char *text, const char *word) |
| 355 | { |
| 356 | static const char *layout_names [] = |
| 357 | { "src", "asm", "split", "regs", "next", "prev", NULL }; |
| 358 | |
| 359 | complete_on_enum (tracker, layout_names, text, word); |
| 360 | } |
| 361 | |
| 362 | /* Function to initialize gdb commands, for tui window layout |
| 363 | manipulation. */ |
| 364 | |
| 365 | void |
| 366 | _initialize_tui_layout (void) |
| 367 | { |
| 368 | struct cmd_list_element *cmd; |
| 369 | |
| 370 | cmd = add_com ("layout", class_tui, tui_layout_command, _("\ |
| 371 | Change the layout of windows.\n\ |
| 372 | Usage: layout prev | next | LAYOUT-NAME\n\ |
| 373 | Layout names are:\n\ |
| 374 | src : Displays source and command windows.\n\ |
| 375 | asm : Displays disassembly and command windows.\n\ |
| 376 | split : Displays source, disassembly and command windows.\n\ |
| 377 | regs : Displays register window. If existing layout\n\ |
| 378 | is source/command or assembly/command, the \n\ |
| 379 | register window is displayed. If the\n\ |
| 380 | source/assembly/command (split) is displayed, \n\ |
| 381 | the register window is displayed with \n\ |
| 382 | the window that has current logical focus.")); |
| 383 | set_cmd_completer (cmd, layout_completer); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | /************************* |
| 388 | ** STATIC LOCAL FUNCTIONS |
| 389 | **************************/ |
| 390 | |
| 391 | |
| 392 | /* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or |
| 393 | REGS. */ |
| 394 | enum tui_status |
| 395 | tui_set_layout_by_name (const char *layout_name) |
| 396 | { |
| 397 | enum tui_status status = TUI_SUCCESS; |
| 398 | |
| 399 | if (layout_name != NULL) |
| 400 | { |
| 401 | int i; |
| 402 | enum tui_layout_type new_layout = UNDEFINED_LAYOUT; |
| 403 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 404 | |
| 405 | std::string copy = layout_name; |
| 406 | for (i = 0; i < copy.size (); i++) |
| 407 | copy[i] = toupper (copy[i]); |
| 408 | const char *buf_ptr = copy.c_str (); |
| 409 | |
| 410 | /* First check for ambiguous input. */ |
| 411 | if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S') |
| 412 | { |
| 413 | warning (_("Ambiguous command input.")); |
| 414 | status = TUI_FAILURE; |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | if (subset_compare (buf_ptr, "SRC")) |
| 419 | new_layout = SRC_COMMAND; |
| 420 | else if (subset_compare (buf_ptr, "ASM")) |
| 421 | new_layout = DISASSEM_COMMAND; |
| 422 | else if (subset_compare (buf_ptr, "SPLIT")) |
| 423 | new_layout = SRC_DISASSEM_COMMAND; |
| 424 | else if (subset_compare (buf_ptr, "REGS")) |
| 425 | { |
| 426 | if (cur_layout == SRC_COMMAND |
| 427 | || cur_layout == SRC_DATA_COMMAND) |
| 428 | new_layout = SRC_DATA_COMMAND; |
| 429 | else |
| 430 | new_layout = DISASSEM_DATA_COMMAND; |
| 431 | } |
| 432 | else if (subset_compare (buf_ptr, "NEXT")) |
| 433 | new_layout = next_layout (); |
| 434 | else if (subset_compare (buf_ptr, "PREV")) |
| 435 | new_layout = prev_layout (); |
| 436 | else |
| 437 | status = TUI_FAILURE; |
| 438 | |
| 439 | if (status == TUI_SUCCESS) |
| 440 | { |
| 441 | /* Make sure the curses mode is enabled. */ |
| 442 | tui_enable (); |
| 443 | tui_set_layout (new_layout); |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | else |
| 448 | status = TUI_FAILURE; |
| 449 | |
| 450 | return status; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | static void |
| 455 | extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p) |
| 456 | { |
| 457 | enum tui_layout_type cur_layout = tui_current_layout (); |
| 458 | struct gdbarch *gdbarch = get_current_arch (); |
| 459 | CORE_ADDR addr; |
| 460 | CORE_ADDR pc; |
| 461 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
| 462 | |
| 463 | switch (cur_layout) |
| 464 | { |
| 465 | case SRC_COMMAND: |
| 466 | case SRC_DATA_COMMAND: |
| 467 | gdbarch = TUI_SRC_WIN->gdbarch; |
| 468 | find_line_pc (cursal.symtab, |
| 469 | TUI_SRC_WIN->start_line_or_addr.u.line_no, |
| 470 | &pc); |
| 471 | addr = pc; |
| 472 | break; |
| 473 | case DISASSEM_COMMAND: |
| 474 | case SRC_DISASSEM_COMMAND: |
| 475 | case DISASSEM_DATA_COMMAND: |
| 476 | gdbarch = TUI_DISASM_WIN->gdbarch; |
| 477 | addr = TUI_DISASM_WIN->start_line_or_addr.u.addr; |
| 478 | break; |
| 479 | default: |
| 480 | addr = 0; |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | *gdbarch_p = gdbarch; |
| 485 | *addr_p = addr; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | static void |
| 490 | tui_layout_command (const char *arg, int from_tty) |
| 491 | { |
| 492 | /* Switch to the selected layout. */ |
| 493 | if (tui_set_layout_by_name (arg) != TUI_SUCCESS) |
| 494 | warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE); |
| 495 | } |
| 496 | |
| 497 | /* Answer the previous layout to cycle to. */ |
| 498 | static enum tui_layout_type |
| 499 | next_layout (void) |
| 500 | { |
| 501 | int new_layout; |
| 502 | |
| 503 | new_layout = tui_current_layout (); |
| 504 | if (new_layout == UNDEFINED_LAYOUT) |
| 505 | new_layout = SRC_COMMAND; |
| 506 | else |
| 507 | { |
| 508 | new_layout++; |
| 509 | if (new_layout == UNDEFINED_LAYOUT) |
| 510 | new_layout = SRC_COMMAND; |
| 511 | } |
| 512 | |
| 513 | return (enum tui_layout_type) new_layout; |
| 514 | } |
| 515 | |
| 516 | |
| 517 | /* Answer the next layout to cycle to. */ |
| 518 | static enum tui_layout_type |
| 519 | prev_layout (void) |
| 520 | { |
| 521 | int new_layout; |
| 522 | |
| 523 | new_layout = tui_current_layout (); |
| 524 | if (new_layout == SRC_COMMAND) |
| 525 | new_layout = DISASSEM_DATA_COMMAND; |
| 526 | else |
| 527 | { |
| 528 | new_layout--; |
| 529 | if (new_layout == UNDEFINED_LAYOUT) |
| 530 | new_layout = DISASSEM_DATA_COMMAND; |
| 531 | } |
| 532 | |
| 533 | return (enum tui_layout_type) new_layout; |
| 534 | } |
| 535 | |
| 536 | |
| 537 | |
| 538 | static struct tui_win_info * |
| 539 | make_command_window (int height, int origin_y) |
| 540 | { |
| 541 | struct tui_win_info *result |
| 542 | = (struct tui_win_info *) init_and_make_win (NULL, |
| 543 | CMD_WIN, |
| 544 | height, |
| 545 | tui_term_width (), |
| 546 | 0, |
| 547 | origin_y, |
| 548 | DONT_BOX_WINDOW); |
| 549 | result->can_highlight = false; |
| 550 | return result; |
| 551 | } |
| 552 | |
| 553 | |
| 554 | /* make_source_window(). |
| 555 | */ |
| 556 | static struct tui_win_info * |
| 557 | make_source_window (int height, int origin_y) |
| 558 | { |
| 559 | return make_source_or_disasm_window (SRC_WIN, height, origin_y); |
| 560 | } /* make_source_window */ |
| 561 | |
| 562 | |
| 563 | /* make_disasm_window(). |
| 564 | */ |
| 565 | static struct tui_win_info * |
| 566 | make_disasm_window (int height, int origin_y) |
| 567 | { |
| 568 | return make_source_or_disasm_window (DISASSEM_WIN, height, origin_y); |
| 569 | } /* make_disasm_window */ |
| 570 | |
| 571 | |
| 572 | static void |
| 573 | make_data_window (struct tui_win_info **win_info_ptr, |
| 574 | int height, int origin_y) |
| 575 | { |
| 576 | *win_info_ptr |
| 577 | = (struct tui_win_info *) init_and_make_win (*win_info_ptr, |
| 578 | DATA_WIN, |
| 579 | height, |
| 580 | tui_term_width (), |
| 581 | 0, |
| 582 | origin_y, |
| 583 | BOX_WINDOW); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | |
| 588 | /* Show the Source/Command layout. */ |
| 589 | static void |
| 590 | show_source_command (void) |
| 591 | { |
| 592 | show_source_or_disasm_and_command (SRC_COMMAND); |
| 593 | } |
| 594 | |
| 595 | |
| 596 | /* Show the Dissassem/Command layout. */ |
| 597 | static void |
| 598 | show_disasm_command (void) |
| 599 | { |
| 600 | show_source_or_disasm_and_command (DISASSEM_COMMAND); |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /* Show the Source/Disassem/Command layout. */ |
| 605 | static void |
| 606 | show_source_disasm_command (void) |
| 607 | { |
| 608 | if (tui_current_layout () != SRC_DISASSEM_COMMAND) |
| 609 | { |
| 610 | int cmd_height, src_height, asm_height; |
| 611 | |
| 612 | if (TUI_CMD_WIN != NULL) |
| 613 | cmd_height = TUI_CMD_WIN->generic.height; |
| 614 | else |
| 615 | cmd_height = tui_term_height () / 3; |
| 616 | |
| 617 | src_height = (tui_term_height () - cmd_height) / 2; |
| 618 | asm_height = tui_term_height () - (src_height + cmd_height); |
| 619 | |
| 620 | if (TUI_SRC_WIN == NULL) |
| 621 | tui_win_list[SRC_WIN] = make_source_window (src_height, 0); |
| 622 | else |
| 623 | { |
| 624 | init_gen_win_info (&TUI_SRC_WIN->generic, |
| 625 | TUI_SRC_WIN->generic.type, |
| 626 | src_height, |
| 627 | TUI_SRC_WIN->generic.width, |
| 628 | TUI_SRC_WIN->execution_info->width, |
| 629 | 0); |
| 630 | TUI_SRC_WIN->can_highlight = true; |
| 631 | init_gen_win_info (TUI_SRC_WIN->execution_info, |
| 632 | EXEC_INFO_WIN, |
| 633 | src_height, |
| 634 | 3, |
| 635 | 0, |
| 636 | 0); |
| 637 | tui_make_visible (&TUI_SRC_WIN->generic); |
| 638 | tui_make_visible (TUI_SRC_WIN->execution_info); |
| 639 | TUI_SRC_WIN->m_has_locator = false; |
| 640 | } |
| 641 | |
| 642 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
| 643 | |
| 644 | tui_show_source_content (TUI_SRC_WIN); |
| 645 | if (TUI_DISASM_WIN == NULL) |
| 646 | { |
| 647 | tui_win_list[DISASSEM_WIN] |
| 648 | = make_disasm_window (asm_height, src_height - 1); |
| 649 | locator |
| 650 | = ((struct tui_gen_win_info *) |
| 651 | init_and_make_win (locator, |
| 652 | LOCATOR_WIN, |
| 653 | 2 /* 1 */ , |
| 654 | tui_term_width (), |
| 655 | 0, |
| 656 | (src_height + asm_height) - 1, |
| 657 | DONT_BOX_WINDOW)); |
| 658 | } |
| 659 | else |
| 660 | { |
| 661 | init_gen_win_info (locator, |
| 662 | LOCATOR_WIN, |
| 663 | 2 /* 1 */ , |
| 664 | tui_term_width (), |
| 665 | 0, |
| 666 | (src_height + asm_height) - 1); |
| 667 | TUI_DISASM_WIN->m_has_locator = true; |
| 668 | init_gen_win_info (&TUI_DISASM_WIN->generic, |
| 669 | TUI_DISASM_WIN->generic.type, |
| 670 | asm_height, |
| 671 | TUI_DISASM_WIN->generic.width, |
| 672 | TUI_DISASM_WIN->execution_info->width, |
| 673 | src_height - 1); |
| 674 | init_gen_win_info (TUI_DISASM_WIN->execution_info, |
| 675 | EXEC_INFO_WIN, |
| 676 | asm_height, |
| 677 | 3, |
| 678 | 0, |
| 679 | src_height - 1); |
| 680 | TUI_DISASM_WIN->can_highlight = true; |
| 681 | tui_make_visible (&TUI_DISASM_WIN->generic); |
| 682 | tui_make_visible (TUI_DISASM_WIN->execution_info); |
| 683 | } |
| 684 | TUI_SRC_WIN->m_has_locator = false; |
| 685 | TUI_DISASM_WIN->m_has_locator = true; |
| 686 | tui_make_visible (locator); |
| 687 | tui_show_locator_content (); |
| 688 | tui_show_source_content (TUI_DISASM_WIN); |
| 689 | |
| 690 | if (TUI_CMD_WIN == NULL) |
| 691 | tui_win_list[CMD_WIN] |
| 692 | = make_command_window (cmd_height, tui_term_height () - cmd_height); |
| 693 | else |
| 694 | { |
| 695 | init_gen_win_info (&TUI_CMD_WIN->generic, |
| 696 | TUI_CMD_WIN->generic.type, |
| 697 | TUI_CMD_WIN->generic.height, |
| 698 | TUI_CMD_WIN->generic.width, |
| 699 | 0, |
| 700 | TUI_CMD_WIN->generic.origin.y); |
| 701 | TUI_CMD_WIN->can_highlight = false; |
| 702 | tui_make_visible (&TUI_CMD_WIN->generic); |
| 703 | } |
| 704 | tui_refresh_win (&TUI_CMD_WIN->generic); |
| 705 | tui_set_current_layout_to (SRC_DISASSEM_COMMAND); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | |
| 710 | /* Show the Source/Data/Command or the Dissassembly/Data/Command |
| 711 | layout. */ |
| 712 | static void |
| 713 | show_data (enum tui_layout_type new_layout) |
| 714 | { |
| 715 | int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height); |
| 716 | int src_height, data_height; |
| 717 | enum tui_win_type win_type; |
| 718 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
| 719 | |
| 720 | |
| 721 | data_height = total_height / 2; |
| 722 | src_height = total_height - data_height; |
| 723 | tui_make_all_invisible (); |
| 724 | tui_make_invisible (locator); |
| 725 | make_data_window (&tui_win_list[DATA_WIN], data_height, 0); |
| 726 | TUI_DATA_WIN->can_highlight = true; |
| 727 | if (new_layout == SRC_DATA_COMMAND) |
| 728 | win_type = SRC_WIN; |
| 729 | else |
| 730 | win_type = DISASSEM_WIN; |
| 731 | |
| 732 | tui_source_window_base *base; |
| 733 | if (tui_win_list[win_type] == NULL) |
| 734 | { |
| 735 | if (win_type == SRC_WIN) |
| 736 | tui_win_list[win_type] |
| 737 | = make_source_window (src_height, data_height - 1); |
| 738 | else |
| 739 | tui_win_list[win_type] |
| 740 | = make_disasm_window (src_height, data_height - 1); |
| 741 | locator |
| 742 | = ((struct tui_gen_win_info *) |
| 743 | init_and_make_win (locator, |
| 744 | LOCATOR_WIN, |
| 745 | 2 /* 1 */ , |
| 746 | tui_term_width (), |
| 747 | 0, |
| 748 | total_height - 1, |
| 749 | DONT_BOX_WINDOW)); |
| 750 | base = (tui_source_window_base *) tui_win_list[win_type]; |
| 751 | } |
| 752 | else |
| 753 | { |
| 754 | base = (tui_source_window_base *) tui_win_list[win_type]; |
| 755 | init_gen_win_info (&tui_win_list[win_type]->generic, |
| 756 | tui_win_list[win_type]->generic.type, |
| 757 | src_height, |
| 758 | tui_win_list[win_type]->generic.width, |
| 759 | base->execution_info->width, |
| 760 | data_height - 1); |
| 761 | init_gen_win_info (base->execution_info, |
| 762 | EXEC_INFO_WIN, |
| 763 | src_height, |
| 764 | 3, |
| 765 | 0, |
| 766 | data_height - 1); |
| 767 | tui_make_visible (&tui_win_list[win_type]->generic); |
| 768 | tui_make_visible (base->execution_info); |
| 769 | init_gen_win_info (locator, |
| 770 | LOCATOR_WIN, |
| 771 | 2 /* 1 */ , |
| 772 | tui_term_width (), |
| 773 | 0, |
| 774 | total_height - 1); |
| 775 | } |
| 776 | base->m_has_locator = true; |
| 777 | tui_make_visible (locator); |
| 778 | tui_show_locator_content (); |
| 779 | tui_add_to_source_windows |
| 780 | ((tui_source_window_base *) tui_win_list[win_type]); |
| 781 | tui_set_current_layout_to (new_layout); |
| 782 | } |
| 783 | |
| 784 | /* init_gen_win_info(). |
| 785 | */ |
| 786 | static void |
| 787 | init_gen_win_info (struct tui_gen_win_info *win_info, |
| 788 | enum tui_win_type type, |
| 789 | int height, int width, |
| 790 | int origin_x, int origin_y) |
| 791 | { |
| 792 | int h = height; |
| 793 | |
| 794 | win_info->type = type; |
| 795 | win_info->width = width; |
| 796 | win_info->height = h; |
| 797 | if (h > 1) |
| 798 | { |
| 799 | win_info->viewport_height = h - 1; |
| 800 | if (win_info->type != CMD_WIN) |
| 801 | win_info->viewport_height--; |
| 802 | } |
| 803 | else |
| 804 | win_info->viewport_height = 1; |
| 805 | win_info->origin.x = origin_x; |
| 806 | win_info->origin.y = origin_y; |
| 807 | |
| 808 | return; |
| 809 | } /* init_gen_win_info */ |
| 810 | |
| 811 | /* init_and_make_win(). |
| 812 | */ |
| 813 | static void * |
| 814 | init_and_make_win (void *opaque_win_info, |
| 815 | enum tui_win_type win_type, |
| 816 | int height, int width, |
| 817 | int origin_x, int origin_y, |
| 818 | int box_it) |
| 819 | { |
| 820 | struct tui_gen_win_info *generic; |
| 821 | |
| 822 | if (opaque_win_info == NULL) |
| 823 | { |
| 824 | if (tui_win_is_auxillary (win_type)) |
| 825 | opaque_win_info = (void *) tui_alloc_generic_win_info (); |
| 826 | else |
| 827 | opaque_win_info = (void *) tui_alloc_win_info (win_type); |
| 828 | } |
| 829 | if (tui_win_is_auxillary (win_type)) |
| 830 | generic = (struct tui_gen_win_info *) opaque_win_info; |
| 831 | else |
| 832 | generic = &((struct tui_win_info *) opaque_win_info)->generic; |
| 833 | |
| 834 | init_gen_win_info (generic, win_type, height, width, origin_x, origin_y); |
| 835 | if (!tui_win_is_auxillary (win_type)) |
| 836 | { |
| 837 | if (generic->type == CMD_WIN) |
| 838 | ((struct tui_win_info *) opaque_win_info)->can_highlight = false; |
| 839 | else |
| 840 | ((struct tui_win_info *) opaque_win_info)->can_highlight = true; |
| 841 | } |
| 842 | tui_make_window (generic, box_it); |
| 843 | |
| 844 | return opaque_win_info; |
| 845 | } |
| 846 | |
| 847 | |
| 848 | static struct tui_win_info * |
| 849 | make_source_or_disasm_window (enum tui_win_type type, |
| 850 | int height, int origin_y) |
| 851 | { |
| 852 | struct tui_gen_win_info *execution_info = NULL; |
| 853 | |
| 854 | /* Create the exeuction info window. */ |
| 855 | if (type == SRC_WIN) |
| 856 | execution_info = tui_source_exec_info_win_ptr (); |
| 857 | else |
| 858 | execution_info = tui_disassem_exec_info_win_ptr (); |
| 859 | execution_info |
| 860 | = ((struct tui_gen_win_info *) |
| 861 | init_and_make_win (execution_info, |
| 862 | EXEC_INFO_WIN, |
| 863 | height, |
| 864 | 3, |
| 865 | 0, |
| 866 | origin_y, |
| 867 | DONT_BOX_WINDOW)); |
| 868 | |
| 869 | /* Now create the source window. */ |
| 870 | struct tui_source_window_base *result |
| 871 | = ((struct tui_source_window_base *) |
| 872 | init_and_make_win (NULL, |
| 873 | type, |
| 874 | height, |
| 875 | tui_term_width () - execution_info->width, |
| 876 | execution_info->width, |
| 877 | origin_y, |
| 878 | BOX_WINDOW)); |
| 879 | result->execution_info = execution_info; |
| 880 | return result; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | /* Show the Source/Command or the Disassem layout. */ |
| 885 | static void |
| 886 | show_source_or_disasm_and_command (enum tui_layout_type layout_type) |
| 887 | { |
| 888 | if (tui_current_layout () != layout_type) |
| 889 | { |
| 890 | struct tui_win_info **win_info_ptr; |
| 891 | int src_height, cmd_height; |
| 892 | struct tui_gen_win_info *locator = tui_locator_win_info_ptr (); |
| 893 | |
| 894 | if (TUI_CMD_WIN != NULL) |
| 895 | cmd_height = TUI_CMD_WIN->generic.height; |
| 896 | else |
| 897 | cmd_height = tui_term_height () / 3; |
| 898 | src_height = tui_term_height () - cmd_height; |
| 899 | |
| 900 | if (layout_type == SRC_COMMAND) |
| 901 | win_info_ptr = &tui_win_list[SRC_WIN]; |
| 902 | else |
| 903 | win_info_ptr = &tui_win_list[DISASSEM_WIN]; |
| 904 | |
| 905 | tui_source_window_base *base; |
| 906 | if ((*win_info_ptr) == NULL) |
| 907 | { |
| 908 | if (layout_type == SRC_COMMAND) |
| 909 | *win_info_ptr = make_source_window (src_height - 1, 0); |
| 910 | else |
| 911 | *win_info_ptr = make_disasm_window (src_height - 1, 0); |
| 912 | locator |
| 913 | = ((struct tui_gen_win_info *) |
| 914 | init_and_make_win (locator, |
| 915 | LOCATOR_WIN, |
| 916 | 2 /* 1 */ , |
| 917 | tui_term_width (), |
| 918 | 0, |
| 919 | src_height - 1, |
| 920 | DONT_BOX_WINDOW)); |
| 921 | base = (tui_source_window_base *) *win_info_ptr; |
| 922 | } |
| 923 | else |
| 924 | { |
| 925 | base = (tui_source_window_base *) *win_info_ptr; |
| 926 | init_gen_win_info (locator, |
| 927 | LOCATOR_WIN, |
| 928 | 2 /* 1 */ , |
| 929 | tui_term_width (), |
| 930 | 0, |
| 931 | src_height - 1); |
| 932 | base->m_has_locator = true; |
| 933 | init_gen_win_info (&(*win_info_ptr)->generic, |
| 934 | (*win_info_ptr)->generic.type, |
| 935 | src_height - 1, |
| 936 | (*win_info_ptr)->generic.width, |
| 937 | base->execution_info->width, |
| 938 | 0); |
| 939 | init_gen_win_info (base->execution_info, |
| 940 | EXEC_INFO_WIN, |
| 941 | src_height - 1, |
| 942 | 3, |
| 943 | 0, |
| 944 | 0); |
| 945 | base->can_highlight = true; |
| 946 | tui_make_visible (&(*win_info_ptr)->generic); |
| 947 | tui_make_visible (base->execution_info); |
| 948 | } |
| 949 | |
| 950 | base->m_has_locator = true; |
| 951 | tui_make_visible (locator); |
| 952 | tui_show_locator_content (); |
| 953 | tui_show_source_content (*win_info_ptr); |
| 954 | |
| 955 | if (TUI_CMD_WIN == NULL) |
| 956 | { |
| 957 | tui_win_list[CMD_WIN] = make_command_window (cmd_height, |
| 958 | src_height); |
| 959 | tui_refresh_win (&TUI_CMD_WIN->generic); |
| 960 | } |
| 961 | else |
| 962 | { |
| 963 | init_gen_win_info (&TUI_CMD_WIN->generic, |
| 964 | TUI_CMD_WIN->generic.type, |
| 965 | TUI_CMD_WIN->generic.height, |
| 966 | TUI_CMD_WIN->generic.width, |
| 967 | TUI_CMD_WIN->generic.origin.x, |
| 968 | TUI_CMD_WIN->generic.origin.y); |
| 969 | TUI_CMD_WIN->can_highlight = false; |
| 970 | tui_make_visible (&TUI_CMD_WIN->generic); |
| 971 | } |
| 972 | tui_set_current_layout_to (layout_type); |
| 973 | } |
| 974 | } |