Rename common to gdbsupport
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.c
CommitLineData
f377b406 1/* TUI layout window management.
f33c6cbf 2
42a4f53d 3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
f33c6cbf 4
f377b406 5 Contributed by Hewlett-Packard Company.
c906108c 6
f377b406
SC
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
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
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
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
957b8b5a 23#include "arch-utils.h"
c906108c
SS
24#include "command.h"
25#include "symtab.h"
26#include "frame.h"
52575520 27#include "source.h"
84b1e7c7 28#include <ctype.h>
c906108c 29
d7b2e967
AC
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"
2c0b251b 39#include "tui/tui-layout.h"
6a83354a 40#include "gdb_curses.h"
96ec9981 41
c906108c
SS
42/*******************************
43** Static Local Decls
44********************************/
6ba8e26f 45static void show_layout (enum tui_layout_type);
d6ba6a11
TT
46static tui_gen_win_info *init_and_make_win (tui_gen_win_info *,
47 enum tui_win_type,
17374de4
TT
48 int, int, int, int,
49 enum tui_box);
6ba8e26f 50static void show_source_or_disasm_and_command (enum tui_layout_type);
0ed69eda
TT
51static struct tui_win_info *make_source_or_disasm_window (enum tui_win_type,
52 int, int);
82432e10 53static struct tui_win_info *make_command_window (int, int);
0ed69eda
TT
54static struct tui_win_info *make_source_window (int, int);
55static struct tui_win_info *make_disasm_window (int, int);
5b6fe301 56static void make_data_window (struct tui_win_info **, int, int);
6ba8e26f
AC
57static void show_source_command (void);
58static void show_disasm_command (void);
59static void show_source_disasm_command (void);
60static void show_data (enum tui_layout_type);
61static enum tui_layout_type next_layout (void);
62static enum tui_layout_type prev_layout (void);
0b39b52e 63static void tui_layout_command (const char *, int);
13274fc3 64static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
c906108c
SS
65
66
67/***************************************
68** DEFINITIONS
69***************************************/
70
71#define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n"
72
c7037be1
SC
73/* Show the screen layout defined. */
74static void
6ba8e26f 75show_layout (enum tui_layout_type layout)
c906108c 76{
6ba8e26f 77 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 78
6ba8e26f 79 if (layout != cur_layout)
c906108c 80 {
ef5eab5a
MS
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. */
dd1abb8c 84 tui_clear_source_windows ();
e5908723
MS
85 if (layout == SRC_DATA_COMMAND
86 || layout == DISASSEM_DATA_COMMAND)
c906108c 87 {
6ba8e26f 88 show_data (layout);
6d012f14 89 tui_refresh_all (tui_win_list);
c906108c
SS
90 }
91 else
92 {
1cc6d956 93 /* First make the current layout be invisible. */
ec7d9e56 94 tui_make_all_invisible ();
dd1abb8c 95 tui_make_invisible (tui_locator_win_info_ptr ());
c906108c
SS
96
97 switch (layout)
98 {
1cc6d956 99 /* Now show the new layout. */
c906108c 100 case SRC_COMMAND:
6ba8e26f 101 show_source_command ();
6d012f14 102 tui_add_to_source_windows (TUI_SRC_WIN);
c906108c
SS
103 break;
104 case DISASSEM_COMMAND:
6ba8e26f 105 show_disasm_command ();
6d012f14 106 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
107 break;
108 case SRC_DISASSEM_COMMAND:
6ba8e26f 109 show_source_disasm_command ();
6d012f14
AC
110 tui_add_to_source_windows (TUI_SRC_WIN);
111 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
112 break;
113 default:
114 break;
115 }
116 }
117 }
bc712bbf 118}
c906108c
SS
119
120
080ce8c0 121/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
7bd0be3a 122 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */
080ce8c0 123enum tui_status
7bd0be3a 124tui_set_layout (enum tui_layout_type layout_type)
c906108c 125{
22940a24 126 enum tui_status status = TUI_SUCCESS;
c906108c 127
7bd0be3a 128 if (layout_type != UNDEFINED_LAYOUT)
c906108c 129 {
e5908723
MS
130 enum tui_layout_type cur_layout = tui_current_layout (),
131 new_layout = UNDEFINED_LAYOUT;
6ba8e26f 132 int regs_populate = FALSE;
13274fc3
UW
133 struct gdbarch *gdbarch;
134 CORE_ADDR addr;
5b6fe301
MS
135 struct tui_win_info *win_with_focus = tui_win_with_focus ();
136 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 137
13274fc3 138 extract_display_start_addr (&gdbarch, &addr);
c906108c 139
7bd0be3a 140 new_layout = layout_type;
c906108c 141
7bd0be3a
AB
142 regs_populate = (new_layout == SRC_DATA_COMMAND
143 || new_layout == DISASSEM_DATA_COMMAND);
144 if (new_layout != cur_layout)
c906108c 145 {
7bd0be3a 146 show_layout (new_layout);
ef5eab5a 147
7bd0be3a
AB
148 /* Now determine where focus should be. */
149 if (win_with_focus != TUI_CMD_WIN)
150 {
151 switch (new_layout)
c906108c 152 {
7bd0be3a
AB
153 case SRC_COMMAND:
154 tui_set_win_focus_to (TUI_SRC_WIN);
155 layout_def->display_mode = SRC_WIN;
7bd0be3a
AB
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;
7bd0be3a
AB
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);
7bd0be3a
AB
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;
7bd0be3a
AB
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;
7bd0be3a
AB
207 break;
208 default:
209 break;
c906108c 210 }
c906108c 211 }
7bd0be3a
AB
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_display_all_data ();
219
220 tui_update_source_windows_with_addr (gdbarch, addr);
221
6ba8e26f 222 if (regs_populate)
238eb706 223 tui_show_registers (TUI_DATA_WIN->current_group);
c906108c
SS
224 }
225 }
226 else
227 status = TUI_FAILURE;
228
229 return status;
bc712bbf 230}
c906108c 231
080ce8c0
AC
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. */
c906108c 235void
080ce8c0 236tui_add_win_to_layout (enum tui_win_type type)
c906108c 237{
6ba8e26f 238 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c
SS
239
240 switch (type)
241 {
242 case SRC_WIN:
e5908723
MS
243 if (cur_layout != SRC_COMMAND
244 && cur_layout != SRC_DISASSEM_COMMAND
245 && cur_layout != SRC_DATA_COMMAND)
c906108c 246 {
dd1abb8c 247 tui_clear_source_windows_detail ();
6ba8e26f
AC
248 if (cur_layout == DISASSEM_DATA_COMMAND)
249 show_layout (SRC_DATA_COMMAND);
c906108c 250 else
6ba8e26f 251 show_layout (SRC_COMMAND);
c906108c
SS
252 }
253 break;
254 case DISASSEM_WIN:
e5908723
MS
255 if (cur_layout != DISASSEM_COMMAND
256 && cur_layout != SRC_DISASSEM_COMMAND
257 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 258 {
dd1abb8c 259 tui_clear_source_windows_detail ();
6ba8e26f
AC
260 if (cur_layout == SRC_DATA_COMMAND)
261 show_layout (DISASSEM_DATA_COMMAND);
c906108c 262 else
6ba8e26f 263 show_layout (DISASSEM_COMMAND);
c906108c
SS
264 }
265 break;
266 case DATA_WIN:
e5908723
MS
267 if (cur_layout != SRC_DATA_COMMAND
268 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 269 {
6ba8e26f
AC
270 if (cur_layout == DISASSEM_COMMAND)
271 show_layout (DISASSEM_DATA_COMMAND);
c906108c 272 else
6ba8e26f 273 show_layout (SRC_DATA_COMMAND);
c906108c
SS
274 }
275 break;
276 default:
277 break;
278 }
6ba8e26f 279}
c906108c
SS
280
281
6ba8e26f
AC
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. */
c906108c 285int
08ef48c5
MS
286tui_default_win_height (enum tui_win_type type,
287 enum tui_layout_type layout)
c906108c
SS
288{
289 int h;
290
cafb3438 291 if (tui_win_list[type] != NULL)
cb2ce893 292 h = tui_win_list[type]->height;
c906108c
SS
293 else
294 {
295 switch (layout)
296 {
297 case SRC_COMMAND:
298 case DISASSEM_COMMAND:
6d012f14 299 if (TUI_CMD_WIN == NULL)
dd1abb8c 300 h = tui_term_height () / 2;
c906108c 301 else
cb2ce893 302 h = tui_term_height () - TUI_CMD_WIN->height;
c906108c
SS
303 break;
304 case SRC_DISASSEM_COMMAND:
305 case SRC_DATA_COMMAND:
306 case DISASSEM_DATA_COMMAND:
6d012f14 307 if (TUI_CMD_WIN == NULL)
dd1abb8c 308 h = tui_term_height () / 3;
c906108c 309 else
cb2ce893 310 h = (tui_term_height () - TUI_CMD_WIN->height) / 2;
c906108c
SS
311 break;
312 default:
313 h = 0;
314 break;
315 }
316 }
317
318 return h;
6ba8e26f 319}
c906108c
SS
320
321
080ce8c0
AC
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. */
c906108c 325int
080ce8c0
AC
326tui_default_win_viewport_height (enum tui_win_type type,
327 enum tui_layout_type layout)
c906108c
SS
328{
329 int h;
330
6ba8e26f 331 h = tui_default_win_height (type, layout);
c906108c 332
6d012f14 333 if (tui_win_list[type] == TUI_CMD_WIN)
c906108c
SS
334 h -= 1;
335 else
336 h -= 2;
337
338 return h;
6ba8e26f 339}
c906108c 340
a0145030
AB
341/* Complete possible layout names. TEXT is the complete text entered so
342 far, WORD is the word currently being completed. */
343
eb3ff9a5 344static void
a0145030 345layout_completer (struct cmd_list_element *ignore,
eb3ff9a5 346 completion_tracker &tracker,
a0145030
AB
347 const char *text, const char *word)
348{
349 static const char *layout_names [] =
350 { "src", "asm", "split", "regs", "next", "prev", NULL };
351
eb3ff9a5 352 complete_on_enum (tracker, layout_names, text, word);
a0145030
AB
353}
354
6ba8e26f
AC
355/* Function to initialize gdb commands, for tui window layout
356 manipulation. */
2c0b251b 357
c906108c 358void
6ba8e26f 359_initialize_tui_layout (void)
c906108c 360{
a0145030
AB
361 struct cmd_list_element *cmd;
362
363 cmd = add_com ("layout", class_tui, tui_layout_command, _("\
1bedd215 364Change the layout of windows.\n\
bf212be1 365Usage: layout prev | next | LAYOUT-NAME\n\
c906108c
SS
366Layout 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\
89549d7f 375 the window that has current logical focus."));
a0145030 376 set_cmd_completer (cmd, layout_completer);
41783295 377}
c906108c
SS
378
379
380/*************************
381** STATIC LOCAL FUNCTIONS
382**************************/
383
384
7bd0be3a
AB
385/* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
386 REGS. */
22940a24 387enum tui_status
7bd0be3a 388tui_set_layout_by_name (const char *layout_name)
c906108c 389{
22940a24 390 enum tui_status status = TUI_SUCCESS;
c906108c 391
63a33118 392 if (layout_name != NULL)
c906108c 393 {
d02c80cd 394 int i;
6ba8e26f 395 enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
6ba8e26f 396 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 397
f71c8822
TT
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 ();
c906108c 402
1cc6d956 403 /* First check for ambiguous input. */
7bd0be3a 404 if (strlen (buf_ptr) <= 1 && *buf_ptr == 'S')
c906108c 405 {
8a3fe4f8 406 warning (_("Ambiguous command input."));
c906108c
SS
407 status = TUI_FAILURE;
408 }
409 else
410 {
6ba8e26f
AC
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;
7bd0be3a 417 else if (subset_compare (buf_ptr, "REGS"))
c906108c 418 {
7bd0be3a 419 if (cur_layout == SRC_COMMAND
e5908723 420 || cur_layout == SRC_DATA_COMMAND)
6ba8e26f 421 new_layout = SRC_DATA_COMMAND;
c906108c 422 else
6ba8e26f 423 new_layout = DISASSEM_DATA_COMMAND;
c906108c 424 }
6ba8e26f
AC
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 ();
c906108c
SS
429 else
430 status = TUI_FAILURE;
c906108c 431
880d1e40
AB
432 if (status == TUI_SUCCESS)
433 {
434 /* Make sure the curses mode is enabled. */
435 tui_enable ();
436 tui_set_layout (new_layout);
437 }
c906108c
SS
438 }
439 }
440 else
441 status = TUI_FAILURE;
442
443 return status;
e8b915dc 444}
c906108c
SS
445
446
13274fc3
UW
447static void
448extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
c906108c 449{
6ba8e26f 450 enum tui_layout_type cur_layout = tui_current_layout ();
957b8b5a 451 struct gdbarch *gdbarch = get_current_arch ();
c774cec6 452 CORE_ADDR addr;
84b1e7c7 453 CORE_ADDR pc;
52575520 454 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c 455
6ba8e26f 456 switch (cur_layout)
c906108c
SS
457 {
458 case SRC_COMMAND:
459 case SRC_DATA_COMMAND:
e6e41501 460 gdbarch = TUI_SRC_WIN->gdbarch;
52575520 461 find_line_pc (cursal.symtab,
e6e41501 462 TUI_SRC_WIN->start_line_or_addr.u.line_no,
84b1e7c7 463 &pc);
c774cec6 464 addr = pc;
c906108c
SS
465 break;
466 case DISASSEM_COMMAND:
467 case SRC_DISASSEM_COMMAND:
468 case DISASSEM_DATA_COMMAND:
e6e41501
TT
469 gdbarch = TUI_DISASM_WIN->gdbarch;
470 addr = TUI_DISASM_WIN->start_line_or_addr.u.addr;
c906108c
SS
471 break;
472 default:
c774cec6 473 addr = 0;
c906108c
SS
474 break;
475 }
476
13274fc3
UW
477 *gdbarch_p = gdbarch;
478 *addr_p = addr;
6ba8e26f 479}
c906108c
SS
480
481
c906108c 482static void
0b39b52e 483tui_layout_command (const char *arg, int from_tty)
c906108c 484{
19eb139b 485 /* Switch to the selected layout. */
7bd0be3a 486 if (tui_set_layout_by_name (arg) != TUI_SUCCESS)
8a3fe4f8 487 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
e8b915dc 488}
c906108c 489
6ba8e26f 490/* Answer the previous layout to cycle to. */
2a8854a7 491static enum tui_layout_type
6ba8e26f 492next_layout (void)
c906108c 493{
570dc176 494 int new_layout;
c906108c 495
6ba8e26f
AC
496 new_layout = tui_current_layout ();
497 if (new_layout == UNDEFINED_LAYOUT)
498 new_layout = SRC_COMMAND;
c906108c
SS
499 else
500 {
6ba8e26f
AC
501 new_layout++;
502 if (new_layout == UNDEFINED_LAYOUT)
503 new_layout = SRC_COMMAND;
c906108c
SS
504 }
505
570dc176 506 return (enum tui_layout_type) new_layout;
6ba8e26f 507}
c906108c
SS
508
509
6ba8e26f 510/* Answer the next layout to cycle to. */
2a8854a7 511static enum tui_layout_type
6ba8e26f 512prev_layout (void)
c906108c 513{
570dc176 514 int new_layout;
c906108c 515
6ba8e26f
AC
516 new_layout = tui_current_layout ();
517 if (new_layout == SRC_COMMAND)
518 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
519 else
520 {
6ba8e26f
AC
521 new_layout--;
522 if (new_layout == UNDEFINED_LAYOUT)
523 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
524 }
525
570dc176 526 return (enum tui_layout_type) new_layout;
6ba8e26f 527}
c906108c
SS
528
529
530
82432e10
TT
531static struct tui_win_info *
532make_command_window (int height, int origin_y)
c906108c 533{
82432e10
TT
534 struct tui_win_info *result
535 = (struct tui_win_info *) init_and_make_win (NULL,
19ba03f4
SM
536 CMD_WIN,
537 height,
538 tui_term_width (),
539 0,
540 origin_y,
541 DONT_BOX_WINDOW);
82432e10 542 return result;
6ba8e26f 543}
c906108c
SS
544
545
ef5eab5a 546/* make_source_window().
c5aa993b 547 */
0ed69eda
TT
548static struct tui_win_info *
549make_source_window (int height, int origin_y)
c906108c 550{
0ed69eda 551 return make_source_or_disasm_window (SRC_WIN, height, origin_y);
6ba8e26f 552} /* make_source_window */
c906108c
SS
553
554
ef5eab5a 555/* make_disasm_window().
c5aa993b 556 */
0ed69eda
TT
557static struct tui_win_info *
558make_disasm_window (int height, int origin_y)
c906108c 559{
0ed69eda 560 return make_source_or_disasm_window (DISASSEM_WIN, height, origin_y);
6ba8e26f 561} /* make_disasm_window */
c906108c
SS
562
563
c906108c 564static void
08ef48c5
MS
565make_data_window (struct tui_win_info **win_info_ptr,
566 int height, int origin_y)
c906108c 567{
19ba03f4
SM
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);
6ba8e26f 576}
c906108c
SS
577
578
579
6ba8e26f 580/* Show the Source/Command layout. */
c906108c 581static void
6ba8e26f 582show_source_command (void)
c906108c 583{
6ba8e26f
AC
584 show_source_or_disasm_and_command (SRC_COMMAND);
585}
c906108c
SS
586
587
6ba8e26f 588/* Show the Dissassem/Command layout. */
c906108c 589static void
6ba8e26f 590show_disasm_command (void)
c906108c 591{
6ba8e26f
AC
592 show_source_or_disasm_and_command (DISASSEM_COMMAND);
593}
c906108c
SS
594
595
6ba8e26f 596/* Show the Source/Disassem/Command layout. */
c906108c 597static void
6ba8e26f 598show_source_disasm_command (void)
c906108c 599{
dd1abb8c 600 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
c906108c 601 {
6ba8e26f 602 int cmd_height, src_height, asm_height;
c906108c 603
6d012f14 604 if (TUI_CMD_WIN != NULL)
cb2ce893 605 cmd_height = TUI_CMD_WIN->height;
c906108c 606 else
6ba8e26f 607 cmd_height = tui_term_height () / 3;
c906108c 608
6ba8e26f
AC
609 src_height = (tui_term_height () - cmd_height) / 2;
610 asm_height = tui_term_height () - (src_height + cmd_height);
c906108c 611
6d012f14 612 if (TUI_SRC_WIN == NULL)
e6e41501 613 tui_win_list[SRC_WIN] = make_source_window (src_height, 0);
c906108c
SS
614 else
615 {
d6ba6a11
TT
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);
cb2ce893 626 tui_make_visible (TUI_SRC_WIN);
e6e41501
TT
627 tui_make_visible (TUI_SRC_WIN->execution_info);
628 TUI_SRC_WIN->m_has_locator = false;
c906108c 629 }
c906108c 630
3add462f
TT
631 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
632 gdb_assert (locator != nullptr);
82432e10
TT
633
634 tui_show_source_content (TUI_SRC_WIN);
635 if (TUI_DISASM_WIN == NULL)
636 {
e6e41501
TT
637 tui_win_list[DISASSEM_WIN]
638 = make_disasm_window (asm_height, src_height - 1);
3add462f
TT
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);
82432e10
TT
646 }
647 else
648 {
d6ba6a11
TT
649 locator->reset (LOCATOR_WIN,
650 2 /* 1 */ ,
651 tui_term_width (),
652 0,
653 (src_height + asm_height) - 1);
e6e41501 654 TUI_DISASM_WIN->m_has_locator = true;
d6ba6a11
TT
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);
cb2ce893 665 tui_make_visible (TUI_DISASM_WIN);
e6e41501 666 tui_make_visible (TUI_DISASM_WIN->execution_info);
82432e10 667 }
e6e41501
TT
668 TUI_SRC_WIN->m_has_locator = false;
669 TUI_DISASM_WIN->m_has_locator = true;
82432e10
TT
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)
81491aa0
TT
675 tui_win_list[CMD_WIN]
676 = make_command_window (cmd_height, tui_term_height () - cmd_height);
82432e10
TT
677 else
678 {
d6ba6a11
TT
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);
cb2ce893 684 tui_make_visible (TUI_CMD_WIN);
c906108c 685 }
5b81daba 686 TUI_CMD_WIN->refresh_window ();
dd1abb8c 687 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
c906108c 688 }
6ba8e26f 689}
c906108c
SS
690
691
6ba8e26f
AC
692/* Show the Source/Data/Command or the Dissassembly/Data/Command
693 layout. */
c906108c 694static void
6ba8e26f 695show_data (enum tui_layout_type new_layout)
c906108c 696{
cb2ce893 697 int total_height = (tui_term_height () - TUI_CMD_WIN->height);
6ba8e26f
AC
698 int src_height, data_height;
699 enum tui_win_type win_type;
c906108c 700
3add462f
TT
701 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
702 gdb_assert (locator != nullptr);
c906108c 703
6ba8e26f
AC
704 data_height = total_height / 2;
705 src_height = total_height - data_height;
ec7d9e56
AC
706 tui_make_all_invisible ();
707 tui_make_invisible (locator);
238eb706 708 make_data_window (&tui_win_list[DATA_WIN], data_height, 0);
6ba8e26f
AC
709 if (new_layout == SRC_DATA_COMMAND)
710 win_type = SRC_WIN;
c906108c 711 else
6ba8e26f 712 win_type = DISASSEM_WIN;
e6e41501
TT
713
714 tui_source_window_base *base;
6ba8e26f 715 if (tui_win_list[win_type] == NULL)
c906108c 716 {
6ba8e26f 717 if (win_type == SRC_WIN)
0ed69eda
TT
718 tui_win_list[win_type]
719 = make_source_window (src_height, data_height - 1);
c906108c 720 else
0ed69eda
TT
721 tui_win_list[win_type]
722 = make_disasm_window (src_height, data_height - 1);
3add462f 723 init_and_make_win (locator,
d6ba6a11
TT
724 LOCATOR_WIN,
725 2 /* 1 */ ,
726 tui_term_width (),
727 0,
728 total_height - 1,
729 DONT_BOX_WINDOW);
e6e41501 730 base = (tui_source_window_base *) tui_win_list[win_type];
c906108c
SS
731 }
732 else
733 {
e6e41501 734 base = (tui_source_window_base *) tui_win_list[win_type];
d6ba6a11
TT
735 tui_win_list[win_type]->reset (tui_win_list[win_type]->type,
736 src_height,
737 tui_win_list[win_type]->width,
738 base->execution_info->width,
739 data_height - 1);
740 base->execution_info->reset (EXEC_INFO_WIN,
741 src_height,
742 3,
743 0,
744 data_height - 1);
cb2ce893 745 tui_make_visible (tui_win_list[win_type]);
e6e41501 746 tui_make_visible (base->execution_info);
d6ba6a11
TT
747 locator->reset (LOCATOR_WIN,
748 2 /* 1 */ ,
749 tui_term_width (),
750 0,
751 total_height - 1);
c906108c 752 }
e6e41501 753 base->m_has_locator = true;
ec7d9e56 754 tui_make_visible (locator);
47d3492a 755 tui_show_locator_content ();
ad54d15b
TT
756 tui_add_to_source_windows
757 ((tui_source_window_base *) tui_win_list[win_type]);
6ba8e26f
AC
758 tui_set_current_layout_to (new_layout);
759}
c906108c 760
d6ba6a11
TT
761void
762tui_gen_win_info::reset (enum tui_win_type win_type,
763 int height_, int width_,
764 int origin_x_, int origin_y_)
c906108c 765{
d6ba6a11
TT
766 int h = height_;
767
768 gdb_assert (type == win_type);
c906108c 769
d6ba6a11
TT
770 width = width_;
771 height = h;
c906108c
SS
772 if (h > 1)
773 {
d6ba6a11
TT
774 viewport_height = h - 1;
775 if (type != CMD_WIN)
776 viewport_height--;
c906108c
SS
777 }
778 else
d6ba6a11
TT
779 viewport_height = 1;
780 origin.x = origin_x_;
781 origin.y = origin_y_;
782}
c906108c 783
ef5eab5a 784/* init_and_make_win().
c5aa993b 785 */
d6ba6a11
TT
786static tui_gen_win_info *
787init_and_make_win (tui_gen_win_info *win_info,
08ef48c5
MS
788 enum tui_win_type win_type,
789 int height, int width,
790 int origin_x, int origin_y,
17374de4 791 enum tui_box box_it)
c906108c 792{
d6ba6a11 793 if (win_info == NULL)
c906108c 794 {
c3fabb7d
TT
795 switch (win_type)
796 {
797 case SRC_WIN:
798 win_info = new tui_source_window ();
799 break;
800
801 case DISASSEM_WIN:
802 win_info = new tui_disasm_window ();
803 break;
804
805 case DATA_WIN:
806 win_info = new tui_data_window ();
807 break;
808
809 case CMD_WIN:
810 win_info = new tui_cmd_window ();
811 break;
812
489e9d8b
TT
813 case EXEC_INFO_WIN:
814 win_info = new tui_exec_info_window ();
815 break;
816
c3fabb7d 817 default:
fb54fa76 818 gdb_assert_not_reached (_("unhandled window type"));
c3fabb7d 819 }
c906108c 820 }
c906108c 821
d6ba6a11
TT
822 win_info->reset (win_type, height, width, origin_x, origin_y);
823 tui_make_window (win_info, box_it);
ec328aa5 824
d6ba6a11 825 return win_info;
bc712bbf 826}
c906108c
SS
827
828
0ed69eda
TT
829static struct tui_win_info *
830make_source_or_disasm_window (enum tui_win_type type,
08ef48c5 831 int height, int origin_y)
c906108c 832{
489e9d8b
TT
833 struct tui_exec_info_window *execution_info
834 = (tui_exec_info_window *) init_and_make_win (nullptr,
835 EXEC_INFO_WIN,
836 height,
837 3,
838 0,
839 origin_y,
840 DONT_BOX_WINDOW);
ef5eab5a
MS
841
842 /* Now create the source window. */
e6e41501
TT
843 struct tui_source_window_base *result
844 = ((struct tui_source_window_base *)
0ed69eda 845 init_and_make_win (NULL,
19ba03f4
SM
846 type,
847 height,
848 tui_term_width () - execution_info->width,
849 execution_info->width,
850 origin_y,
851 BOX_WINDOW));
e6e41501 852 result->execution_info = execution_info;
0ed69eda 853 return result;
6ba8e26f 854}
c906108c
SS
855
856
1cc6d956 857/* Show the Source/Command or the Disassem layout. */
c906108c 858static void
6ba8e26f 859show_source_or_disasm_and_command (enum tui_layout_type layout_type)
c906108c 860{
6ba8e26f 861 if (tui_current_layout () != layout_type)
c906108c 862 {
5b6fe301 863 struct tui_win_info **win_info_ptr;
6ba8e26f 864 int src_height, cmd_height;
3add462f
TT
865 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
866 gdb_assert (locator != nullptr);
c906108c 867
6d012f14 868 if (TUI_CMD_WIN != NULL)
cb2ce893 869 cmd_height = TUI_CMD_WIN->height;
c906108c 870 else
6ba8e26f
AC
871 cmd_height = tui_term_height () / 3;
872 src_height = tui_term_height () - cmd_height;
c906108c 873
6ba8e26f 874 if (layout_type == SRC_COMMAND)
e6e41501 875 win_info_ptr = &tui_win_list[SRC_WIN];
c906108c 876 else
e6e41501 877 win_info_ptr = &tui_win_list[DISASSEM_WIN];
c906108c 878
e6e41501 879 tui_source_window_base *base;
6ba8e26f 880 if ((*win_info_ptr) == NULL)
c906108c 881 {
6ba8e26f 882 if (layout_type == SRC_COMMAND)
0ed69eda 883 *win_info_ptr = make_source_window (src_height - 1, 0);
c906108c 884 else
0ed69eda 885 *win_info_ptr = make_disasm_window (src_height - 1, 0);
3add462f
TT
886 init_and_make_win (locator,
887 LOCATOR_WIN,
888 2 /* 1 */ ,
889 tui_term_width (),
890 0,
891 src_height - 1,
892 DONT_BOX_WINDOW);
e6e41501 893 base = (tui_source_window_base *) *win_info_ptr;
c906108c
SS
894 }
895 else
896 {
e6e41501 897 base = (tui_source_window_base *) *win_info_ptr;
d6ba6a11
TT
898 locator->reset (LOCATOR_WIN,
899 2 /* 1 */ ,
900 tui_term_width (),
901 0,
902 src_height - 1);
e6e41501 903 base->m_has_locator = true;
d6ba6a11
TT
904 (*win_info_ptr)->reset ((*win_info_ptr)->type,
905 src_height - 1,
906 (*win_info_ptr)->width,
907 base->execution_info->width,
908 0);
909 base->execution_info->reset (EXEC_INFO_WIN,
910 src_height - 1,
911 3,
912 0,
913 0);
cb2ce893 914 tui_make_visible (*win_info_ptr);
e6e41501 915 tui_make_visible (base->execution_info);
c906108c 916 }
c906108c 917
6a0ee02c
TT
918 base->m_has_locator = true;
919 tui_make_visible (locator);
920 tui_show_locator_content ();
7908abbf 921 tui_show_source_content (base);
6a0ee02c
TT
922
923 if (TUI_CMD_WIN == NULL)
924 {
925 tui_win_list[CMD_WIN] = make_command_window (cmd_height,
926 src_height);
5b81daba 927 TUI_CMD_WIN->refresh_window ();
6a0ee02c
TT
928 }
929 else
930 {
d6ba6a11
TT
931 TUI_CMD_WIN->reset (TUI_CMD_WIN->type,
932 TUI_CMD_WIN->height,
933 TUI_CMD_WIN->width,
934 TUI_CMD_WIN->origin.x,
935 TUI_CMD_WIN->origin.y);
cb2ce893 936 tui_make_visible (TUI_CMD_WIN);
c906108c 937 }
6ba8e26f 938 tui_set_current_layout_to (layout_type);
c906108c 939 }
6ba8e26f 940}
This page took 2.035363 seconds and 4 git commands to generate.