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