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