Remove struct tui_point
[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 30#include "tui/tui.h"
ce38393b 31#include "tui/tui-command.h"
d7b2e967 32#include "tui/tui-data.h"
d7b2e967
AC
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"
bfad4537 40#include "tui/tui-source.h"
6a83354a 41#include "gdb_curses.h"
96ec9981 42
6ba8e26f 43static void show_layout (enum tui_layout_type);
6ba8e26f 44static void show_source_or_disasm_and_command (enum tui_layout_type);
6ba8e26f
AC
45static void show_source_command (void);
46static void show_disasm_command (void);
47static void show_source_disasm_command (void);
48static void show_data (enum tui_layout_type);
49static enum tui_layout_type next_layout (void);
50static enum tui_layout_type prev_layout (void);
0b39b52e 51static void tui_layout_command (const char *, int);
13274fc3 52static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
c906108c
SS
53
54
62cf57fe
TT
55static enum tui_layout_type current_layout = UNDEFINED_LAYOUT;
56
57/* Accessor for the current layout. */
58enum tui_layout_type
59tui_current_layout (void)
60{
61 return current_layout;
62}
63
c906108c 64
c7037be1
SC
65/* Show the screen layout defined. */
66static void
6ba8e26f 67show_layout (enum tui_layout_type layout)
c906108c 68{
6ba8e26f 69 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 70
6ba8e26f 71 if (layout != cur_layout)
c906108c 72 {
3f3ffe54 73 tui_make_all_invisible ();
cc0c3ffb 74 switch (layout)
c906108c 75 {
cc0c3ffb
TT
76 case SRC_DATA_COMMAND:
77 case DISASSEM_DATA_COMMAND:
6ba8e26f 78 show_data (layout);
cc0c3ffb
TT
79 break;
80 /* Now show the new layout. */
81 case SRC_COMMAND:
82 show_source_command ();
cc0c3ffb
TT
83 break;
84 case DISASSEM_COMMAND:
85 show_disasm_command ();
cc0c3ffb
TT
86 break;
87 case SRC_DISASSEM_COMMAND:
88 show_source_disasm_command ();
cc0c3ffb
TT
89 break;
90 default:
91 break;
c906108c 92 }
fede5273 93
ed2c82c3 94 current_layout = layout;
fede5273 95 tui_delete_invisible_windows ();
c906108c 96 }
bc712bbf 97}
c906108c
SS
98
99
080ce8c0 100/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
7bd0be3a 101 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND. */
b7fbad91 102void
7bd0be3a 103tui_set_layout (enum tui_layout_type layout_type)
c906108c 104{
b7fbad91 105 gdb_assert (layout_type != UNDEFINED_LAYOUT);
c906108c 106
b7fbad91
TT
107 enum tui_layout_type cur_layout = tui_current_layout ();
108 struct gdbarch *gdbarch;
109 CORE_ADDR addr;
110 struct tui_win_info *win_with_focus = tui_win_with_focus ();
c906108c 111
b7fbad91 112 extract_display_start_addr (&gdbarch, &addr);
c906108c 113
b7fbad91 114 enum tui_layout_type new_layout = layout_type;
c906108c 115
b7fbad91
TT
116 if (new_layout != cur_layout)
117 {
118 show_layout (new_layout);
ef5eab5a 119
b7fbad91
TT
120 /* Now determine where focus should be. */
121 if (win_with_focus != TUI_CMD_WIN)
122 {
123 switch (new_layout)
7bd0be3a 124 {
b7fbad91
TT
125 case SRC_COMMAND:
126 tui_set_win_focus_to (TUI_SRC_WIN);
b7fbad91
TT
127 break;
128 case DISASSEM_COMMAND:
129 /* The previous layout was not showing code.
130 This can happen if there is no source
131 available:
132
133 1. if the source file is in another dir OR
134 2. if target was compiled without -g
135 We still want to show the assembly though! */
136
137 tui_get_begin_asm_address (&gdbarch, &addr);
138 tui_set_win_focus_to (TUI_DISASM_WIN);
b7fbad91
TT
139 break;
140 case SRC_DISASSEM_COMMAND:
141 /* The previous layout was not showing code.
142 This can happen if there is no source
143 available:
144
145 1. if the source file is in another dir OR
146 2. if target was compiled without -g
147 We still want to show the assembly though! */
148
149 tui_get_begin_asm_address (&gdbarch, &addr);
150 if (win_with_focus == TUI_SRC_WIN)
151 tui_set_win_focus_to (TUI_SRC_WIN);
152 else
153 tui_set_win_focus_to (TUI_DISASM_WIN);
154 break;
155 case SRC_DATA_COMMAND:
156 if (win_with_focus != TUI_DATA_WIN)
157 tui_set_win_focus_to (TUI_SRC_WIN);
158 else
159 tui_set_win_focus_to (TUI_DATA_WIN);
b7fbad91
TT
160 break;
161 case DISASSEM_DATA_COMMAND:
162 /* The previous layout was not showing code.
163 This can happen if there is no source
164 available:
165
166 1. if the source file is in another dir OR
167 2. if target was compiled without -g
168 We still want to show the assembly though! */
169
170 tui_get_begin_asm_address (&gdbarch, &addr);
171 if (win_with_focus != TUI_DATA_WIN)
172 tui_set_win_focus_to (TUI_DISASM_WIN);
173 else
174 tui_set_win_focus_to (TUI_DATA_WIN);
b7fbad91
TT
175 break;
176 default:
177 break;
c906108c 178 }
c906108c 179 }
b7fbad91
TT
180 /*
181 * Now update the window content.
182 */
183 tui_update_source_windows_with_addr (gdbarch, addr);
184 if (new_layout == SRC_DATA_COMMAND
185 || new_layout == DISASSEM_DATA_COMMAND)
89df7f90 186 TUI_DATA_WIN->show_registers (TUI_DATA_WIN->get_current_group ());
c906108c 187 }
bc712bbf 188}
c906108c 189
080ce8c0
AC
190/* Add the specified window to the layout in a logical way. This
191 means setting up the most logical layout given the window to be
192 added. */
c906108c 193void
080ce8c0 194tui_add_win_to_layout (enum tui_win_type type)
c906108c 195{
6ba8e26f 196 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c
SS
197
198 switch (type)
199 {
200 case SRC_WIN:
e5908723
MS
201 if (cur_layout != SRC_COMMAND
202 && cur_layout != SRC_DISASSEM_COMMAND
203 && cur_layout != SRC_DATA_COMMAND)
c906108c 204 {
6ba8e26f
AC
205 if (cur_layout == DISASSEM_DATA_COMMAND)
206 show_layout (SRC_DATA_COMMAND);
c906108c 207 else
6ba8e26f 208 show_layout (SRC_COMMAND);
c906108c
SS
209 }
210 break;
211 case DISASSEM_WIN:
e5908723
MS
212 if (cur_layout != DISASSEM_COMMAND
213 && cur_layout != SRC_DISASSEM_COMMAND
214 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 215 {
6ba8e26f
AC
216 if (cur_layout == SRC_DATA_COMMAND)
217 show_layout (DISASSEM_DATA_COMMAND);
c906108c 218 else
6ba8e26f 219 show_layout (DISASSEM_COMMAND);
c906108c
SS
220 }
221 break;
222 case DATA_WIN:
e5908723
MS
223 if (cur_layout != SRC_DATA_COMMAND
224 && cur_layout != DISASSEM_DATA_COMMAND)
c906108c 225 {
6ba8e26f
AC
226 if (cur_layout == DISASSEM_COMMAND)
227 show_layout (DISASSEM_DATA_COMMAND);
c906108c 228 else
6ba8e26f 229 show_layout (SRC_DATA_COMMAND);
c906108c
SS
230 }
231 break;
232 default:
233 break;
234 }
6ba8e26f 235}
c906108c 236
a0145030
AB
237/* Complete possible layout names. TEXT is the complete text entered so
238 far, WORD is the word currently being completed. */
239
eb3ff9a5 240static void
a0145030 241layout_completer (struct cmd_list_element *ignore,
eb3ff9a5 242 completion_tracker &tracker,
a0145030
AB
243 const char *text, const char *word)
244{
245 static const char *layout_names [] =
246 { "src", "asm", "split", "regs", "next", "prev", NULL };
247
eb3ff9a5 248 complete_on_enum (tracker, layout_names, text, word);
a0145030
AB
249}
250
7bd0be3a
AB
251/* Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, or
252 REGS. */
0379b883
TT
253static void
254tui_layout_command (const char *layout_name, int from_tty)
c906108c 255{
0379b883
TT
256 enum tui_layout_type new_layout = UNDEFINED_LAYOUT;
257 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 258
78e8cb91 259 if (layout_name == NULL || *layout_name == '\0')
0379b883 260 error (_("Usage: layout prev | next | LAYOUT-NAME"));
c906108c 261
0379b883 262 /* First check for ambiguous input. */
78e8cb91 263 if (strcmp (layout_name, "s") == 0)
0379b883 264 error (_("Ambiguous command input."));
c906108c 265
78e8cb91 266 if (subset_compare (layout_name, "src"))
0379b883 267 new_layout = SRC_COMMAND;
78e8cb91 268 else if (subset_compare (layout_name, "asm"))
0379b883 269 new_layout = DISASSEM_COMMAND;
78e8cb91 270 else if (subset_compare (layout_name, "split"))
0379b883 271 new_layout = SRC_DISASSEM_COMMAND;
78e8cb91 272 else if (subset_compare (layout_name, "regs"))
0379b883
TT
273 {
274 if (cur_layout == SRC_COMMAND
275 || cur_layout == SRC_DATA_COMMAND)
276 new_layout = SRC_DATA_COMMAND;
277 else
278 new_layout = DISASSEM_DATA_COMMAND;
c906108c 279 }
78e8cb91 280 else if (subset_compare (layout_name, "next"))
0379b883 281 new_layout = next_layout ();
78e8cb91 282 else if (subset_compare (layout_name, "prev"))
0379b883 283 new_layout = prev_layout ();
c906108c 284 else
0379b883 285 error (_("Unrecognized layout: %s"), layout_name);
c906108c 286
0379b883
TT
287 /* Make sure the curses mode is enabled. */
288 tui_enable ();
289 tui_set_layout (new_layout);
e8b915dc 290}
c906108c
SS
291
292
13274fc3
UW
293static void
294extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
c906108c 295{
6ba8e26f 296 enum tui_layout_type cur_layout = tui_current_layout ();
957b8b5a 297 struct gdbarch *gdbarch = get_current_arch ();
c774cec6 298 CORE_ADDR addr;
84b1e7c7 299 CORE_ADDR pc;
52575520 300 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c 301
6ba8e26f 302 switch (cur_layout)
c906108c
SS
303 {
304 case SRC_COMMAND:
305 case SRC_DATA_COMMAND:
e6e41501 306 gdbarch = TUI_SRC_WIN->gdbarch;
52575520 307 find_line_pc (cursal.symtab,
e6e41501 308 TUI_SRC_WIN->start_line_or_addr.u.line_no,
84b1e7c7 309 &pc);
c774cec6 310 addr = pc;
c906108c
SS
311 break;
312 case DISASSEM_COMMAND:
313 case SRC_DISASSEM_COMMAND:
314 case DISASSEM_DATA_COMMAND:
e6e41501
TT
315 gdbarch = TUI_DISASM_WIN->gdbarch;
316 addr = TUI_DISASM_WIN->start_line_or_addr.u.addr;
c906108c
SS
317 break;
318 default:
c774cec6 319 addr = 0;
c906108c
SS
320 break;
321 }
322
13274fc3
UW
323 *gdbarch_p = gdbarch;
324 *addr_p = addr;
6ba8e26f 325}
c906108c
SS
326
327
6ba8e26f 328/* Answer the previous layout to cycle to. */
2a8854a7 329static enum tui_layout_type
6ba8e26f 330next_layout (void)
c906108c 331{
570dc176 332 int new_layout;
c906108c 333
6ba8e26f
AC
334 new_layout = tui_current_layout ();
335 if (new_layout == UNDEFINED_LAYOUT)
336 new_layout = SRC_COMMAND;
c906108c
SS
337 else
338 {
6ba8e26f
AC
339 new_layout++;
340 if (new_layout == UNDEFINED_LAYOUT)
341 new_layout = SRC_COMMAND;
c906108c
SS
342 }
343
570dc176 344 return (enum tui_layout_type) new_layout;
6ba8e26f 345}
c906108c
SS
346
347
6ba8e26f 348/* Answer the next layout to cycle to. */
2a8854a7 349static enum tui_layout_type
6ba8e26f 350prev_layout (void)
c906108c 351{
570dc176 352 int new_layout;
c906108c 353
6ba8e26f
AC
354 new_layout = tui_current_layout ();
355 if (new_layout == SRC_COMMAND)
356 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
357 else
358 {
6ba8e26f
AC
359 new_layout--;
360 if (new_layout == UNDEFINED_LAYOUT)
361 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
362 }
363
570dc176 364 return (enum tui_layout_type) new_layout;
6ba8e26f 365}
c906108c 366
6ba8e26f 367/* Show the Source/Command layout. */
c906108c 368static void
6ba8e26f 369show_source_command (void)
c906108c 370{
6ba8e26f
AC
371 show_source_or_disasm_and_command (SRC_COMMAND);
372}
c906108c
SS
373
374
6ba8e26f 375/* Show the Dissassem/Command layout. */
c906108c 376static void
6ba8e26f 377show_disasm_command (void)
c906108c 378{
6ba8e26f
AC
379 show_source_or_disasm_and_command (DISASSEM_COMMAND);
380}
c906108c
SS
381
382
6ba8e26f 383/* Show the Source/Disassem/Command layout. */
c906108c 384static void
6ba8e26f 385show_source_disasm_command (void)
c906108c 386{
cc0c3ffb 387 int cmd_height, src_height, asm_height;
c906108c 388
cc0c3ffb
TT
389 if (TUI_CMD_WIN != NULL)
390 cmd_height = TUI_CMD_WIN->height;
391 else
392 cmd_height = tui_term_height () / 3;
c906108c 393
cc0c3ffb
TT
394 src_height = (tui_term_height () - cmd_height) / 2;
395 asm_height = tui_term_height () - (src_height + cmd_height);
c906108c 396
cc0c3ffb
TT
397 if (TUI_SRC_WIN == NULL)
398 tui_win_list[SRC_WIN] = new tui_source_window ();
ee556432
TT
399 TUI_SRC_WIN->resize (src_height,
400 tui_term_width (),
401 0,
402 0);
cc0c3ffb
TT
403
404 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
405 gdb_assert (locator != nullptr);
406
cc0c3ffb
TT
407 if (TUI_DISASM_WIN == NULL)
408 tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
ee556432
TT
409 TUI_DISASM_WIN->resize (asm_height,
410 tui_term_width (),
411 0,
412 src_height - 1);
1b935acf
TT
413 locator->resize (1, tui_term_width (),
414 0, (src_height + asm_height) - 1);
cc0c3ffb
TT
415
416 if (TUI_CMD_WIN == NULL)
417 tui_win_list[CMD_WIN] = new tui_cmd_window ();
ee556432
TT
418 TUI_CMD_WIN->resize (cmd_height,
419 tui_term_width (),
420 0,
421 tui_term_height () - cmd_height);
6ba8e26f 422}
c906108c
SS
423
424
6ba8e26f
AC
425/* Show the Source/Data/Command or the Dissassembly/Data/Command
426 layout. */
c906108c 427static void
6ba8e26f 428show_data (enum tui_layout_type new_layout)
c906108c 429{
cb2ce893 430 int total_height = (tui_term_height () - TUI_CMD_WIN->height);
6ba8e26f
AC
431 int src_height, data_height;
432 enum tui_win_type win_type;
c906108c 433
3add462f
TT
434 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
435 gdb_assert (locator != nullptr);
c906108c 436
6ba8e26f
AC
437 data_height = total_height / 2;
438 src_height = total_height - data_height;
098f9ed4 439 if (tui_win_list[DATA_WIN] == nullptr)
09129226 440 tui_win_list[DATA_WIN] = new tui_data_window ();
ee556432 441 tui_win_list[DATA_WIN]->resize (data_height, tui_term_width (), 0, 0);
098f9ed4 442
6ba8e26f
AC
443 if (new_layout == SRC_DATA_COMMAND)
444 win_type = SRC_WIN;
c906108c 445 else
6ba8e26f 446 win_type = DISASSEM_WIN;
e6e41501 447
6ba8e26f 448 if (tui_win_list[win_type] == NULL)
c906108c 449 {
6ba8e26f 450 if (win_type == SRC_WIN)
4a8a5e84 451 tui_win_list[win_type] = new tui_source_window ();
c906108c 452 else
4a8a5e84 453 tui_win_list[win_type] = new tui_disasm_window ();
c906108c 454 }
4a8a5e84 455
ee556432
TT
456 tui_win_list[win_type]->resize (src_height,
457 tui_term_width (),
458 0,
459 data_height - 1);
1b935acf
TT
460 locator->resize (1, tui_term_width (),
461 0, total_height - 1);
db502012
TT
462 TUI_CMD_WIN->resize (TUI_CMD_WIN->height, tui_term_width (),
463 0, total_height);
6ba8e26f 464}
c906108c 465
d6ba6a11 466void
ee556432
TT
467tui_gen_win_info::resize (int height_, int width_,
468 int origin_x_, int origin_y_)
c906108c 469{
cdaa6eb4 470 if (width == width_ && height == height_
fb3184d8 471 && x == origin_x_ && y == origin_y_
cdaa6eb4
TT
472 && handle != nullptr)
473 return;
474
d6ba6a11 475 width = width_;
db502012
TT
476 height = height_;
477 if (height > 1)
478 viewport_height = height - 2;
c906108c 479 else
d6ba6a11 480 viewport_height = 1;
fb3184d8
TT
481 x = origin_x_;
482 y = origin_y_;
db502012
TT
483
484 if (handle != nullptr)
485 {
486#ifdef HAVE_WRESIZE
7523da63 487 wresize (handle.get (), height, width);
fb3184d8 488 mvwin (handle.get (), y, x);
7523da63 489 wmove (handle.get (), 0, 0);
db502012 490#else
7523da63 491 handle.reset (nullptr);
db502012
TT
492#endif
493 }
494
495 if (handle == nullptr)
ab0e1f1a 496 make_window ();
3df505f6
TT
497
498 rerender ();
d6ba6a11 499}
c906108c 500
1cc6d956 501/* Show the Source/Command or the Disassem layout. */
c906108c 502static void
6ba8e26f 503show_source_or_disasm_and_command (enum tui_layout_type layout_type)
c906108c 504{
cc0c3ffb
TT
505 struct tui_source_window_base *win_info;
506 int src_height, cmd_height;
507 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
508 gdb_assert (locator != nullptr);
509
510 if (TUI_CMD_WIN != NULL)
511 cmd_height = TUI_CMD_WIN->height;
512 else
513 cmd_height = tui_term_height () / 3;
514 src_height = tui_term_height () - cmd_height;
515
516 if (layout_type == SRC_COMMAND)
c906108c 517 {
cc0c3ffb
TT
518 if (tui_win_list[SRC_WIN] == nullptr)
519 tui_win_list[SRC_WIN] = new tui_source_window ();
520 win_info = TUI_SRC_WIN;
521 }
522 else
523 {
524 if (tui_win_list[DISASSEM_WIN] == nullptr)
525 tui_win_list[DISASSEM_WIN] = new tui_disasm_window ();
526 win_info = TUI_DISASM_WIN;
527 }
c906108c 528
1b935acf
TT
529 locator->resize (1, tui_term_width (),
530 0, src_height - 1);
ee556432
TT
531 win_info->resize (src_height - 1,
532 tui_term_width (),
533 0,
534 0);
c906108c 535
cc0c3ffb
TT
536 if (TUI_CMD_WIN == NULL)
537 tui_win_list[CMD_WIN] = new tui_cmd_window ();
ee556432
TT
538 TUI_CMD_WIN->resize (cmd_height,
539 tui_term_width (),
540 0,
541 src_height);
6ba8e26f 542}
d9fcefd5
TT
543
544\f
545
546/* Function to initialize gdb commands, for tui window layout
547 manipulation. */
548
549void
550_initialize_tui_layout (void)
551{
552 struct cmd_list_element *cmd;
553
554 cmd = add_com ("layout", class_tui, tui_layout_command, _("\
555Change the layout of windows.\n\
556Usage: layout prev | next | LAYOUT-NAME\n\
557Layout names are:\n\
558 src : Displays source and command windows.\n\
559 asm : Displays disassembly and command windows.\n\
560 split : Displays source, disassembly and command windows.\n\
561 regs : Displays register window. If existing layout\n\
562 is source/command or assembly/command, the \n\
563 register window is displayed. If the\n\
564 source/assembly/command (split) is displayed, \n\
565 the register window is displayed with \n\
566 the window that has current logical focus."));
567 set_cmd_completer (cmd, layout_completer);
568}
This page took 2.197539 seconds and 4 git commands to generate.