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