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