]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-layout.c
*** empty log message ***
[thirdparty/binutils-gdb.git] / gdb / tui / tui-layout.c
CommitLineData
f377b406 1/* TUI layout window management.
f33c6cbf 2
55fb0713
AC
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
4 Foundation, Inc.
f33c6cbf 5
f377b406 6 Contributed by Hewlett-Packard Company.
c906108c 7
f377b406
SC
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
c906108c
SS
24
25#include "defs.h"
26#include "command.h"
27#include "symtab.h"
28#include "frame.h"
52575520 29#include "source.h"
84b1e7c7 30#include <ctype.h>
c906108c 31
d7b2e967
AC
32#include "tui/tui.h"
33#include "tui/tui-data.h"
34#include "tui/tui-windata.h"
35#include "tui/tui-wingeneral.h"
36#include "tui/tui-stack.h"
37#include "tui/tui-regs.h"
38#include "tui/tui-win.h"
39#include "tui/tui-winsource.h"
40#include "tui/tui-disasm.h"
c906108c 41
96ec9981
DJ
42#ifdef HAVE_NCURSES_H
43#include <ncurses.h>
44#else
45#ifdef HAVE_CURSES_H
46#include <curses.h>
47#endif
48#endif
49
c906108c
SS
50/*******************************
51** Static Local Decls
52********************************/
2a8854a7 53static void showLayout (enum tui_layout_type);
22940a24
AC
54static void _initGenWinInfo (struct tui_gen_win_info *, enum tui_win_type, int, int, int, int);
55static void _initAndMakeWin (void **, enum tui_win_type, int, int, int, int, int);
2a8854a7 56static void _showSourceOrDisassemAndCommand (enum tui_layout_type);
22940a24 57static void _makeSourceOrDisassemWindow (struct tui_win_info * *, enum tui_win_type, int, int);
2a8854a7
AC
58static void _makeCommandWindow (struct tui_win_info * *, int, int);
59static void _makeSourceWindow (struct tui_win_info * *, int, int);
60static void _makeDisassemWindow (struct tui_win_info * *, int, int);
61static void _makeDataWindow (struct tui_win_info * *, int, int);
a14ed312
KB
62static void _showSourceCommand (void);
63static void _showDisassemCommand (void);
64static void _showSourceDisassemCommand (void);
2a8854a7
AC
65static void _showData (enum tui_layout_type);
66static enum tui_layout_type _nextLayout (void);
67static enum tui_layout_type _prevLayout (void);
a14ed312
KB
68static void _tuiLayout_command (char *, int);
69static void _tuiToggleLayout_command (char *, int);
a14ed312 70static void _tuiToggleSplitLayout_command (char *, int);
c774cec6 71static CORE_ADDR _extractDisplayStartAddr (void);
2a8854a7 72static void _tuiHandleXDBLayout (struct tui_layout_def *);
c906108c
SS
73
74
75/***************************************
76** DEFINITIONS
77***************************************/
78
79#define LAYOUT_USAGE "Usage: layout prev | next | <layout_name> \n"
80
c7037be1
SC
81/* Show the screen layout defined. */
82static void
2a8854a7 83showLayout (enum tui_layout_type layout)
c906108c 84{
2a8854a7 85 enum tui_layout_type curLayout = tui_current_layout ();
c906108c
SS
86
87 if (layout != curLayout)
88 {
89 /*
c5aa993b
JM
90 ** Since the new layout may cause changes in window size, we
91 ** should free the content and reallocate on next display of
92 ** source/asm
93 */
dd1abb8c
AC
94 tui_free_all_source_wins_content ();
95 tui_clear_source_windows ();
c906108c
SS
96 if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
97 {
98 _showData (layout);
6d012f14 99 tui_refresh_all (tui_win_list);
c906108c
SS
100 }
101 else
102 {
103 /* First make the current layout be invisible */
ec7d9e56 104 tui_make_all_invisible ();
dd1abb8c 105 tui_make_invisible (tui_locator_win_info_ptr ());
c906108c
SS
106
107 switch (layout)
108 {
109 /* Now show the new layout */
110 case SRC_COMMAND:
111 _showSourceCommand ();
6d012f14 112 tui_add_to_source_windows (TUI_SRC_WIN);
c906108c
SS
113 break;
114 case DISASSEM_COMMAND:
115 _showDisassemCommand ();
6d012f14 116 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
117 break;
118 case SRC_DISASSEM_COMMAND:
119 _showSourceDisassemCommand ();
6d012f14
AC
120 tui_add_to_source_windows (TUI_SRC_WIN);
121 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
122 break;
123 default:
124 break;
125 }
126 }
127 }
bc712bbf 128}
c906108c
SS
129
130
080ce8c0
AC
131/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
132 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
133 If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
134 UNDEFINED_LAYOUT, then the data window is populated according to
6d012f14 135 regs_display_type. */
080ce8c0
AC
136enum tui_status
137tui_set_layout (enum tui_layout_type layoutType,
6d012f14 138 enum tui_register_display_type regs_display_type)
c906108c 139{
22940a24 140 enum tui_status status = TUI_SUCCESS;
c906108c 141
6d012f14 142 if (layoutType != UNDEFINED_LAYOUT || regs_display_type != TUI_UNDEFINED_REGS)
c906108c 143 {
2a8854a7 144 enum tui_layout_type curLayout = tui_current_layout (), newLayout = UNDEFINED_LAYOUT;
c906108c 145 int regsPopulate = FALSE;
c774cec6 146 CORE_ADDR addr = _extractDisplayStartAddr ();
2a8854a7
AC
147 struct tui_win_info * newWinWithFocus = (struct tui_win_info *) NULL;
148 struct tui_win_info * winWithFocus = tui_win_with_focus ();
149 struct tui_layout_def * layoutDef = tui_layout_def ();
c906108c
SS
150
151
152 if (layoutType == UNDEFINED_LAYOUT &&
6d012f14 153 regs_display_type != TUI_UNDEFINED_REGS)
c906108c
SS
154 {
155 if (curLayout == SRC_DISASSEM_COMMAND)
156 newLayout = DISASSEM_DATA_COMMAND;
157 else if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
158 newLayout = SRC_DATA_COMMAND;
159 else if (curLayout == DISASSEM_COMMAND ||
160 curLayout == DISASSEM_DATA_COMMAND)
161 newLayout = DISASSEM_DATA_COMMAND;
162 }
163 else
164 newLayout = layoutType;
165
166 regsPopulate = (newLayout == SRC_DATA_COMMAND ||
167 newLayout == DISASSEM_DATA_COMMAND ||
6d012f14
AC
168 regs_display_type != TUI_UNDEFINED_REGS);
169 if (newLayout != curLayout || regs_display_type != TUI_UNDEFINED_REGS)
c906108c
SS
170 {
171 if (newLayout != curLayout)
172 {
c906108c
SS
173 showLayout (newLayout);
174 /*
c5aa993b
JM
175 ** Now determine where focus should be
176 */
6d012f14 177 if (winWithFocus != TUI_CMD_WIN)
c906108c
SS
178 {
179 switch (newLayout)
180 {
181 case SRC_COMMAND:
6d012f14
AC
182 tui_set_win_focus_to (TUI_SRC_WIN);
183 layoutDef->display_mode = SRC_WIN;
c906108c
SS
184 layoutDef->split = FALSE;
185 break;
186 case DISASSEM_COMMAND:
187 /* the previous layout was not showing
c5aa993b
JM
188 ** code. this can happen if there is no
189 ** source available:
190 ** 1. if the source file is in another dir OR
191 ** 2. if target was compiled without -g
192 ** We still want to show the assembly though!
193 */
65f05602 194 addr = tui_get_begin_asm_address ();
6d012f14
AC
195 tui_set_win_focus_to (TUI_DISASM_WIN);
196 layoutDef->display_mode = DISASSEM_WIN;
c906108c
SS
197 layoutDef->split = FALSE;
198 break;
199 case SRC_DISASSEM_COMMAND:
200 /* the previous layout was not showing
c5aa993b
JM
201 ** code. this can happen if there is no
202 ** source available:
203 ** 1. if the source file is in another dir OR
204 ** 2. if target was compiled without -g
205 ** We still want to show the assembly though!
206 */
65f05602 207 addr = tui_get_begin_asm_address ();
6d012f14
AC
208 if (winWithFocus == TUI_SRC_WIN)
209 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 210 else
6d012f14 211 tui_set_win_focus_to (TUI_DISASM_WIN);
c906108c
SS
212 layoutDef->split = TRUE;
213 break;
214 case SRC_DATA_COMMAND:
6d012f14
AC
215 if (winWithFocus != TUI_DATA_WIN)
216 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 217 else
6d012f14
AC
218 tui_set_win_focus_to (TUI_DATA_WIN);
219 layoutDef->display_mode = SRC_WIN;
c906108c
SS
220 layoutDef->split = FALSE;
221 break;
222 case DISASSEM_DATA_COMMAND:
223 /* the previous layout was not showing
c5aa993b
JM
224 ** code. this can happen if there is no
225 ** source available:
226 ** 1. if the source file is in another dir OR
227 ** 2. if target was compiled without -g
228 ** We still want to show the assembly though!
229 */
65f05602 230 addr = tui_get_begin_asm_address ();
6d012f14
AC
231 if (winWithFocus != TUI_DATA_WIN)
232 tui_set_win_focus_to (TUI_DISASM_WIN);
c906108c 233 else
6d012f14
AC
234 tui_set_win_focus_to (TUI_DATA_WIN);
235 layoutDef->display_mode = DISASSEM_WIN;
c906108c
SS
236 layoutDef->split = FALSE;
237 break;
238 default:
239 break;
240 }
241 }
2a8854a7 242 if (newWinWithFocus != (struct tui_win_info *) NULL)
a21fcd8f 243 tui_set_win_focus_to (newWinWithFocus);
c906108c 244 /*
c5aa993b
JM
245 ** Now update the window content
246 */
c906108c
SS
247 if (!regsPopulate &&
248 (newLayout == SRC_DATA_COMMAND ||
249 newLayout == DISASSEM_DATA_COMMAND))
edae1ccf 250 tui_display_all_data ();
c906108c 251
f80bda8e 252 tui_update_source_windows_with_addr (addr);
c906108c
SS
253 }
254 if (regsPopulate)
255 {
6d012f14
AC
256 layoutDef->regs_display_type =
257 (regs_display_type == TUI_UNDEFINED_REGS ?
258 TUI_GENERAL_REGS : regs_display_type);
259 tui_show_registers (layoutDef->regs_display_type);
c906108c
SS
260 }
261 }
262 }
263 else
264 status = TUI_FAILURE;
265
266 return status;
bc712bbf 267}
c906108c 268
080ce8c0
AC
269/* Add the specified window to the layout in a logical way. This
270 means setting up the most logical layout given the window to be
271 added. */
c906108c 272void
080ce8c0 273tui_add_win_to_layout (enum tui_win_type type)
c906108c 274{
2a8854a7 275 enum tui_layout_type curLayout = tui_current_layout ();
c906108c
SS
276
277 switch (type)
278 {
279 case SRC_WIN:
280 if (curLayout != SRC_COMMAND &&
281 curLayout != SRC_DISASSEM_COMMAND &&
282 curLayout != SRC_DATA_COMMAND)
283 {
dd1abb8c 284 tui_clear_source_windows_detail ();
c906108c
SS
285 if (curLayout == DISASSEM_DATA_COMMAND)
286 showLayout (SRC_DATA_COMMAND);
287 else
288 showLayout (SRC_COMMAND);
289 }
290 break;
291 case DISASSEM_WIN:
292 if (curLayout != DISASSEM_COMMAND &&
293 curLayout != SRC_DISASSEM_COMMAND &&
294 curLayout != DISASSEM_DATA_COMMAND)
295 {
dd1abb8c 296 tui_clear_source_windows_detail ();
c906108c
SS
297 if (curLayout == SRC_DATA_COMMAND)
298 showLayout (DISASSEM_DATA_COMMAND);
299 else
300 showLayout (DISASSEM_COMMAND);
301 }
302 break;
303 case DATA_WIN:
304 if (curLayout != SRC_DATA_COMMAND &&
305 curLayout != DISASSEM_DATA_COMMAND)
306 {
307 if (curLayout == DISASSEM_COMMAND)
308 showLayout (DISASSEM_DATA_COMMAND);
309 else
310 showLayout (SRC_DATA_COMMAND);
311 }
312 break;
313 default:
314 break;
315 }
316
317 return;
318} /* tuiAddWinToLayout */
319
320
c906108c 321/*
c5aa993b
JM
322 ** tuiDefaultWinHeight().
323 ** Answer the height of a window. If it hasn't been created yet,
324 ** answer what the height of a window would be based upon its
325 ** type and the layout.
326 */
c906108c 327int
22940a24 328tuiDefaultWinHeight (enum tui_win_type type, enum tui_layout_type layout)
c906108c
SS
329{
330 int h;
331
6d012f14
AC
332 if (tui_win_list[type] != (struct tui_win_info *) NULL)
333 h = tui_win_list[type]->generic.height;
c906108c
SS
334 else
335 {
336 switch (layout)
337 {
338 case SRC_COMMAND:
339 case DISASSEM_COMMAND:
6d012f14 340 if (TUI_CMD_WIN == NULL)
dd1abb8c 341 h = tui_term_height () / 2;
c906108c 342 else
6d012f14 343 h = tui_term_height () - TUI_CMD_WIN->generic.height;
c906108c
SS
344 break;
345 case SRC_DISASSEM_COMMAND:
346 case SRC_DATA_COMMAND:
347 case DISASSEM_DATA_COMMAND:
6d012f14 348 if (TUI_CMD_WIN == NULL)
dd1abb8c 349 h = tui_term_height () / 3;
c906108c 350 else
6d012f14 351 h = (tui_term_height () - TUI_CMD_WIN->generic.height) / 2;
c906108c
SS
352 break;
353 default:
354 h = 0;
355 break;
356 }
357 }
358
359 return h;
360} /* tuiDefaultWinHeight */
361
362
080ce8c0
AC
363/* Answer the height of a window. If it hasn't been created yet,
364 answer what the height of a window would be based upon its type and
365 the layout. */
c906108c 366int
080ce8c0
AC
367tui_default_win_viewport_height (enum tui_win_type type,
368 enum tui_layout_type layout)
c906108c
SS
369{
370 int h;
371
372 h = tuiDefaultWinHeight (type, layout);
373
6d012f14 374 if (tui_win_list[type] == TUI_CMD_WIN)
c906108c
SS
375 h -= 1;
376 else
377 h -= 2;
378
379 return h;
380} /* tuiDefaultWinViewportHeight */
381
382
383/*
c5aa993b
JM
384 ** _initialize_tuiLayout().
385 ** Function to initialize gdb commands, for tui window layout
386 ** manipulation.
387 */
c906108c 388void
fba45db2 389_initialize_tuiLayout (void)
c906108c 390{
41783295
SC
391 add_com ("layout", class_tui, _tuiLayout_command,
392 "Change the layout of windows.\n\
c906108c
SS
393Usage: layout prev | next | <layout_name> \n\
394Layout names are:\n\
395 src : Displays source and command windows.\n\
396 asm : Displays disassembly and command windows.\n\
397 split : Displays source, disassembly and command windows.\n\
398 regs : Displays register window. If existing layout\n\
399 is source/command or assembly/command, the \n\
400 register window is displayed. If the\n\
401 source/assembly/command (split) is displayed, \n\
402 the register window is displayed with \n\
403 the window that has current logical focus.\n");
41783295
SC
404 if (xdb_commands)
405 {
406 add_com ("td", class_tui, _tuiToggleLayout_command,
407 "Toggle between Source/Command and Disassembly/Command layouts.\n");
408 add_com ("ts", class_tui, _tuiToggleSplitLayout_command,
409 "Toggle between Source/Command or Disassembly/Command and \n\
c906108c 410Source/Disassembly/Command layouts.\n");
c906108c 411 }
41783295 412}
c906108c
SS
413
414
415/*************************
416** STATIC LOCAL FUNCTIONS
417**************************/
418
419
420/*
c5aa993b
JM
421 ** _tuiSetLayoutTo()
422 ** Function to set the layout to SRC, ASM, SPLIT, NEXT, PREV, DATA, REGS,
423 ** $REGS, $GREGS, $FREGS, $SREGS.
424 */
22940a24 425enum tui_status
080ce8c0 426tui_set_layout_for_display_command (const char *layoutName)
c906108c 427{
22940a24 428 enum tui_status status = TUI_SUCCESS;
c906108c
SS
429
430 if (layoutName != (char *) NULL)
431 {
432 register int i;
433 register char *bufPtr;
2a8854a7
AC
434 enum tui_layout_type newLayout = UNDEFINED_LAYOUT;
435 enum tui_register_display_type dpyType = TUI_UNDEFINED_REGS;
436 enum tui_layout_type curLayout = tui_current_layout ();
c906108c 437
19eb139b 438 bufPtr = (char *) xstrdup (layoutName);
c906108c
SS
439 for (i = 0; (i < strlen (layoutName)); i++)
440 bufPtr[i] = toupper (bufPtr[i]);
441
442 /* First check for ambiguous input */
443 if (strlen (bufPtr) <= 1 && (*bufPtr == 'S' || *bufPtr == '$'))
444 {
445 warning ("Ambiguous command input.\n");
446 status = TUI_FAILURE;
447 }
448 else
449 {
0963fc96 450 if (subset_compare (bufPtr, "SRC"))
c906108c 451 newLayout = SRC_COMMAND;
0963fc96 452 else if (subset_compare (bufPtr, "ASM"))
c906108c 453 newLayout = DISASSEM_COMMAND;
0963fc96 454 else if (subset_compare (bufPtr, "SPLIT"))
c906108c 455 newLayout = SRC_DISASSEM_COMMAND;
0963fc96
SC
456 else if (subset_compare (bufPtr, "REGS") ||
457 subset_compare (bufPtr, TUI_GENERAL_SPECIAL_REGS_NAME) ||
458 subset_compare (bufPtr, TUI_GENERAL_REGS_NAME) ||
459 subset_compare (bufPtr, TUI_FLOAT_REGS_NAME) ||
460 subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c
SS
461 {
462 if (curLayout == SRC_COMMAND || curLayout == SRC_DATA_COMMAND)
463 newLayout = SRC_DATA_COMMAND;
464 else
465 newLayout = DISASSEM_DATA_COMMAND;
466
467/* could ifdef out the following code. when compile with -z, there are null
468 pointer references that cause a core dump if 'layout regs' is the first
469 layout command issued by the user. HP has asked us to hook up this code
470 - edie epstein
471 */
0963fc96 472 if (subset_compare (bufPtr, TUI_FLOAT_REGS_NAME))
c906108c 473 {
6d012f14 474 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
c906108c 475 TUI_SFLOAT_REGS &&
6d012f14 476 TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
c906108c
SS
477 TUI_DFLOAT_REGS)
478 dpyType = TUI_SFLOAT_REGS;
479 else
480 dpyType =
6d012f14 481 TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c 482 }
0963fc96 483 else if (subset_compare (bufPtr,
c906108c
SS
484 TUI_GENERAL_SPECIAL_REGS_NAME))
485 dpyType = TUI_GENERAL_AND_SPECIAL_REGS;
0963fc96 486 else if (subset_compare (bufPtr, TUI_GENERAL_REGS_NAME))
c906108c 487 dpyType = TUI_GENERAL_REGS;
0963fc96 488 else if (subset_compare (bufPtr, TUI_SPECIAL_REGS_NAME))
c906108c 489 dpyType = TUI_SPECIAL_REGS;
6d012f14 490 else if (TUI_DATA_WIN)
c906108c 491 {
6d012f14 492 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
c906108c
SS
493 TUI_UNDEFINED_REGS)
494 dpyType =
6d012f14 495 TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c
SS
496 else
497 dpyType = TUI_GENERAL_REGS;
498 }
499
500/* end of potential ifdef
501 */
502
503/* if ifdefed out code above, then assume that the user wishes to display the
504 general purpose registers
505 */
506
507/* dpyType = TUI_GENERAL_REGS;
508 */
509 }
0963fc96 510 else if (subset_compare (bufPtr, "NEXT"))
c906108c 511 newLayout = _nextLayout ();
0963fc96 512 else if (subset_compare (bufPtr, "PREV"))
c906108c
SS
513 newLayout = _prevLayout ();
514 else
515 status = TUI_FAILURE;
b8c9b27d 516 xfree (bufPtr);
c906108c 517
080ce8c0 518 tui_set_layout (newLayout, dpyType);
c906108c
SS
519 }
520 }
521 else
522 status = TUI_FAILURE;
523
524 return status;
e8b915dc 525}
c906108c
SS
526
527
c774cec6 528static CORE_ADDR
c906108c 529_extractDisplayStartAddr (void)
c906108c 530{
2a8854a7 531 enum tui_layout_type curLayout = tui_current_layout ();
c774cec6 532 CORE_ADDR addr;
84b1e7c7 533 CORE_ADDR pc;
52575520 534 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c
SS
535
536 switch (curLayout)
537 {
538 case SRC_COMMAND:
539 case SRC_DATA_COMMAND:
52575520 540 find_line_pc (cursal.symtab,
6d012f14 541 TUI_SRC_WIN->detail.source_info.start_line_or_addr.line_no,
84b1e7c7 542 &pc);
c774cec6 543 addr = pc;
c906108c
SS
544 break;
545 case DISASSEM_COMMAND:
546 case SRC_DISASSEM_COMMAND:
547 case DISASSEM_DATA_COMMAND:
6d012f14 548 addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.addr;
c906108c
SS
549 break;
550 default:
c774cec6 551 addr = 0;
c906108c
SS
552 break;
553 }
554
555 return addr;
556} /* _extractDisplayStartAddr */
557
558
559static void
2a8854a7 560_tuiHandleXDBLayout (struct tui_layout_def * layoutDef)
c906108c
SS
561{
562 if (layoutDef->split)
563 {
080ce8c0 564 tui_set_layout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
6d012f14 565 tui_set_win_focus_to (tui_win_list[layoutDef->display_mode]);
c906108c
SS
566 }
567 else
568 {
6d012f14 569 if (layoutDef->display_mode == SRC_WIN)
080ce8c0 570 tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
c906108c 571 else
6d012f14 572 tui_set_layout (DISASSEM_DATA_COMMAND, layoutDef->regs_display_type);
c906108c
SS
573 }
574
575
576 return;
577} /* _tuiHandleXDBLayout */
578
579
580static void
eca6576c 581_tuiToggleLayout_command (char *arg, int fromTTY)
c906108c 582{
2a8854a7 583 struct tui_layout_def * layoutDef = tui_layout_def ();
c906108c 584
19eb139b
SC
585 /* Make sure the curses mode is enabled. */
586 tui_enable ();
6d012f14
AC
587 if (layoutDef->display_mode == SRC_WIN)
588 layoutDef->display_mode = DISASSEM_WIN;
c906108c 589 else
6d012f14 590 layoutDef->display_mode = SRC_WIN;
c906108c
SS
591
592 if (!layoutDef->split)
593 _tuiHandleXDBLayout (layoutDef);
594
e8b915dc 595}
c906108c
SS
596
597
598static void
eca6576c 599_tuiToggleSplitLayout_command (char *arg, int fromTTY)
c906108c 600{
2a8854a7 601 struct tui_layout_def * layoutDef = tui_layout_def ();
c906108c 602
19eb139b
SC
603 /* Make sure the curses mode is enabled. */
604 tui_enable ();
c906108c
SS
605 layoutDef->split = (!layoutDef->split);
606 _tuiHandleXDBLayout (layoutDef);
607
e8b915dc 608}
c906108c
SS
609
610
611static void
eca6576c 612_tuiLayout_command (char *arg, int fromTTY)
c906108c 613{
19eb139b
SC
614 /* Make sure the curses mode is enabled. */
615 tui_enable ();
616
617 /* Switch to the selected layout. */
080ce8c0 618 if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
84b1e7c7 619 warning ("Invalid layout specified.\n%s", LAYOUT_USAGE);
c906108c 620
e8b915dc 621}
c906108c
SS
622
623/*
c5aa993b
JM
624 ** _nextLayout().
625 ** Answer the previous layout to cycle to.
626 */
2a8854a7 627static enum tui_layout_type
c906108c 628_nextLayout (void)
c906108c 629{
2a8854a7 630 enum tui_layout_type newLayout;
c906108c 631
dd1abb8c 632 newLayout = tui_current_layout ();
c906108c
SS
633 if (newLayout == UNDEFINED_LAYOUT)
634 newLayout = SRC_COMMAND;
635 else
636 {
637 newLayout++;
638 if (newLayout == UNDEFINED_LAYOUT)
639 newLayout = SRC_COMMAND;
640 }
641
642 return newLayout;
643} /* _nextLayout */
644
645
646/*
c5aa993b
JM
647 ** _prevLayout().
648 ** Answer the next layout to cycle to.
649 */
2a8854a7 650static enum tui_layout_type
c906108c 651_prevLayout (void)
c906108c 652{
2a8854a7 653 enum tui_layout_type newLayout;
c906108c 654
dd1abb8c 655 newLayout = tui_current_layout ();
c906108c
SS
656 if (newLayout == SRC_COMMAND)
657 newLayout = DISASSEM_DATA_COMMAND;
658 else
659 {
660 newLayout--;
661 if (newLayout == UNDEFINED_LAYOUT)
662 newLayout = DISASSEM_DATA_COMMAND;
663 }
664
665 return newLayout;
666} /* _prevLayout */
667
668
669
670/*
c5aa993b
JM
671 ** _makeCommandWindow().
672 */
c906108c 673static void
2a8854a7 674_makeCommandWindow (struct tui_win_info * * winInfoPtr, int height, int originY)
c906108c 675{
22940a24 676 _initAndMakeWin ((void **) winInfoPtr,
c906108c
SS
677 CMD_WIN,
678 height,
dd1abb8c 679 tui_term_width (),
c906108c
SS
680 0,
681 originY,
682 DONT_BOX_WINDOW);
683
6d012f14 684 (*winInfoPtr)->can_highlight = FALSE;
c906108c
SS
685
686 return;
687} /* _makeCommandWindow */
688
689
690/*
c5aa993b
JM
691 ** _makeSourceWindow().
692 */
c906108c 693static void
2a8854a7 694_makeSourceWindow (struct tui_win_info * * winInfoPtr, int height, int originY)
c906108c
SS
695{
696 _makeSourceOrDisassemWindow (winInfoPtr, SRC_WIN, height, originY);
697
698 return;
699} /* _makeSourceWindow */
700
701
702/*
c5aa993b
JM
703 ** _makeDisassemWindow().
704 */
c906108c 705static void
2a8854a7 706_makeDisassemWindow (struct tui_win_info * * winInfoPtr, int height, int originY)
c906108c
SS
707{
708 _makeSourceOrDisassemWindow (winInfoPtr, DISASSEM_WIN, height, originY);
709
710 return;
711} /* _makeDisassemWindow */
712
713
714/*
c5aa993b
JM
715 ** _makeDataWindow().
716 */
c906108c 717static void
2a8854a7 718_makeDataWindow (struct tui_win_info * * winInfoPtr, int height, int originY)
c906108c 719{
22940a24 720 _initAndMakeWin ((void **) winInfoPtr,
c906108c
SS
721 DATA_WIN,
722 height,
dd1abb8c 723 tui_term_width (),
c906108c
SS
724 0,
725 originY,
726 BOX_WINDOW);
727
728 return;
729} /* _makeDataWindow */
730
731
732
733/*
c5aa993b
JM
734 ** _showSourceCommand().
735 ** Show the Source/Command layout
736 */
c906108c 737static void
c906108c 738_showSourceCommand (void)
c906108c
SS
739{
740 _showSourceOrDisassemAndCommand (SRC_COMMAND);
741
742 return;
743} /* _showSourceCommand */
744
745
746/*
c5aa993b
JM
747 ** _showDisassemCommand().
748 ** Show the Dissassem/Command layout
749 */
c906108c 750static void
c906108c 751_showDisassemCommand (void)
c906108c
SS
752{
753 _showSourceOrDisassemAndCommand (DISASSEM_COMMAND);
754
755 return;
756} /* _showDisassemCommand */
757
758
759/*
c5aa993b
JM
760 ** _showSourceDisassemCommand().
761 ** Show the Source/Disassem/Command layout
762 */
c906108c 763static void
c906108c 764_showSourceDisassemCommand (void)
c906108c 765{
dd1abb8c 766 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
c906108c
SS
767 {
768 int cmdHeight, srcHeight, asmHeight;
769
6d012f14
AC
770 if (TUI_CMD_WIN != NULL)
771 cmdHeight = TUI_CMD_WIN->generic.height;
c906108c 772 else
dd1abb8c 773 cmdHeight = tui_term_height () / 3;
c906108c 774
dd1abb8c
AC
775 srcHeight = (tui_term_height () - cmdHeight) / 2;
776 asmHeight = tui_term_height () - (srcHeight + cmdHeight);
c906108c 777
6d012f14
AC
778 if (TUI_SRC_WIN == NULL)
779 _makeSourceWindow (&TUI_SRC_WIN, srcHeight, 0);
c906108c
SS
780 else
781 {
6d012f14
AC
782 _initGenWinInfo (&TUI_SRC_WIN->generic,
783 TUI_SRC_WIN->generic.type,
c906108c 784 srcHeight,
6d012f14
AC
785 TUI_SRC_WIN->generic.width,
786 TUI_SRC_WIN->detail.source_info.execution_info->width,
c906108c 787 0);
6d012f14
AC
788 TUI_SRC_WIN->can_highlight = TRUE;
789 _initGenWinInfo (TUI_SRC_WIN->detail.source_info.execution_info,
c906108c
SS
790 EXEC_INFO_WIN,
791 srcHeight,
792 3,
793 0,
794 0);
6d012f14
AC
795 tui_make_visible (&TUI_SRC_WIN->generic);
796 tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
797 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
c906108c 798 }
6d012f14 799 if (TUI_SRC_WIN != NULL)
c906108c 800 {
2a8854a7 801 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
c906108c 802
6d012f14
AC
803 tui_show_source_content (TUI_SRC_WIN);
804 if (TUI_DISASM_WIN == NULL)
c906108c 805 {
6d012f14 806 _makeDisassemWindow (&TUI_DISASM_WIN, asmHeight, srcHeight - 1);
22940a24 807 _initAndMakeWin ((void **) & locator,
c906108c
SS
808 LOCATOR_WIN,
809 2 /* 1 */ ,
dd1abb8c 810 tui_term_width (),
c906108c
SS
811 0,
812 (srcHeight + asmHeight) - 1,
813 DONT_BOX_WINDOW);
814 }
815 else
816 {
817 _initGenWinInfo (locator,
818 LOCATOR_WIN,
819 2 /* 1 */ ,
dd1abb8c 820 tui_term_width (),
c906108c
SS
821 0,
822 (srcHeight + asmHeight) - 1);
6d012f14 823 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
c906108c 824 _initGenWinInfo (
6d012f14
AC
825 &TUI_DISASM_WIN->generic,
826 TUI_DISASM_WIN->generic.type,
c906108c 827 asmHeight,
6d012f14
AC
828 TUI_DISASM_WIN->generic.width,
829 TUI_DISASM_WIN->detail.source_info.execution_info->width,
c906108c 830 srcHeight - 1);
6d012f14 831 _initGenWinInfo (TUI_DISASM_WIN->detail.source_info.execution_info,
c906108c
SS
832 EXEC_INFO_WIN,
833 asmHeight,
834 3,
835 0,
836 srcHeight - 1);
6d012f14
AC
837 TUI_DISASM_WIN->can_highlight = TRUE;
838 tui_make_visible (&TUI_DISASM_WIN->generic);
839 tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
c906108c 840 }
6d012f14 841 if (TUI_DISASM_WIN != NULL)
c906108c 842 {
6d012f14
AC
843 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
844 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
ec7d9e56 845 tui_make_visible (locator);
47d3492a 846 tui_show_locator_content ();
6d012f14 847 tui_show_source_content (TUI_DISASM_WIN);
c906108c 848
6d012f14
AC
849 if (TUI_CMD_WIN == NULL)
850 _makeCommandWindow (&TUI_CMD_WIN,
c906108c 851 cmdHeight,
dd1abb8c 852 tui_term_height () - cmdHeight);
c906108c
SS
853 else
854 {
6d012f14
AC
855 _initGenWinInfo (&TUI_CMD_WIN->generic,
856 TUI_CMD_WIN->generic.type,
857 TUI_CMD_WIN->generic.height,
858 TUI_CMD_WIN->generic.width,
c906108c 859 0,
6d012f14
AC
860 TUI_CMD_WIN->generic.origin.y);
861 TUI_CMD_WIN->can_highlight = FALSE;
862 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c 863 }
6d012f14
AC
864 if (TUI_CMD_WIN != NULL)
865 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
866 }
867 }
dd1abb8c 868 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
c906108c
SS
869 }
870
871 return;
872} /* _showSourceDisassemCommand */
873
874
875/*
c5aa993b
JM
876 ** _showData().
877 ** Show the Source/Data/Command or the Dissassembly/Data/Command layout
878 */
c906108c 879static void
2a8854a7 880_showData (enum tui_layout_type newLayout)
c906108c 881{
6d012f14 882 int totalHeight = (tui_term_height () - TUI_CMD_WIN->generic.height);
c906108c 883 int srcHeight, dataHeight;
22940a24 884 enum tui_win_type winType;
2a8854a7 885 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
c906108c
SS
886
887
888 dataHeight = totalHeight / 2;
889 srcHeight = totalHeight - dataHeight;
ec7d9e56
AC
890 tui_make_all_invisible ();
891 tui_make_invisible (locator);
6d012f14
AC
892 _makeDataWindow (&TUI_DATA_WIN, dataHeight, 0);
893 TUI_DATA_WIN->can_highlight = TRUE;
c906108c
SS
894 if (newLayout == SRC_DATA_COMMAND)
895 winType = SRC_WIN;
896 else
897 winType = DISASSEM_WIN;
6d012f14 898 if (tui_win_list[winType] == NULL)
c906108c
SS
899 {
900 if (winType == SRC_WIN)
6d012f14 901 _makeSourceWindow (&tui_win_list[winType], srcHeight, dataHeight - 1);
c906108c 902 else
6d012f14 903 _makeDisassemWindow (&tui_win_list[winType], srcHeight, dataHeight - 1);
22940a24 904 _initAndMakeWin ((void **) & locator,
c906108c
SS
905 LOCATOR_WIN,
906 2 /* 1 */ ,
dd1abb8c 907 tui_term_width (),
c906108c
SS
908 0,
909 totalHeight - 1,
910 DONT_BOX_WINDOW);
911 }
912 else
913 {
6d012f14
AC
914 _initGenWinInfo (&tui_win_list[winType]->generic,
915 tui_win_list[winType]->generic.type,
c906108c 916 srcHeight,
6d012f14
AC
917 tui_win_list[winType]->generic.width,
918 tui_win_list[winType]->detail.source_info.execution_info->width,
c906108c 919 dataHeight - 1);
6d012f14 920 _initGenWinInfo (tui_win_list[winType]->detail.source_info.execution_info,
c906108c
SS
921 EXEC_INFO_WIN,
922 srcHeight,
923 3,
924 0,
925 dataHeight - 1);
6d012f14
AC
926 tui_make_visible (&tui_win_list[winType]->generic);
927 tui_make_visible (tui_win_list[winType]->detail.source_info.execution_info);
c906108c
SS
928 _initGenWinInfo (locator,
929 LOCATOR_WIN,
930 2 /* 1 */ ,
dd1abb8c 931 tui_term_width (),
c906108c
SS
932 0,
933 totalHeight - 1);
934 }
6d012f14 935 tui_win_list[winType]->detail.source_info.has_locator = TRUE;
ec7d9e56 936 tui_make_visible (locator);
47d3492a 937 tui_show_locator_content ();
6d012f14 938 tui_add_to_source_windows (tui_win_list[winType]);
dd1abb8c 939 tui_set_current_layout_to (newLayout);
c906108c
SS
940
941 return;
942} /* _showData */
943
944/*
c5aa993b
JM
945 ** _initGenWinInfo().
946 */
c906108c 947static void
22940a24 948_initGenWinInfo (struct tui_gen_win_info * winInfo, enum tui_win_type type,
eca6576c 949 int height, int width, int originX, int originY)
c906108c
SS
950{
951 int h = height;
952
953 winInfo->type = type;
954 winInfo->width = width;
955 winInfo->height = h;
956 if (h > 1)
957 {
6d012f14 958 winInfo->viewport_height = h - 1;
c906108c 959 if (winInfo->type != CMD_WIN)
6d012f14 960 winInfo->viewport_height--;
c906108c
SS
961 }
962 else
6d012f14 963 winInfo->viewport_height = 1;
c906108c
SS
964 winInfo->origin.x = originX;
965 winInfo->origin.y = originY;
966
967 return;
968} /* _initGenWinInfo */
969
970/*
c5aa993b
JM
971 ** _initAndMakeWin().
972 */
c906108c 973static void
22940a24 974_initAndMakeWin (void ** winInfoPtr, enum tui_win_type winType,
eca6576c 975 int height, int width, int originX, int originY, int boxIt)
c906108c 976{
22940a24 977 void *opaqueWinInfo = *winInfoPtr;
2a8854a7 978 struct tui_gen_win_info * generic;
c906108c 979
22940a24 980 if (opaqueWinInfo == NULL)
c906108c 981 {
6d012f14 982 if (tui_win_is_auxillary (winType))
22940a24 983 opaqueWinInfo = (void *) tui_alloc_generic_win_info ();
c906108c 984 else
22940a24 985 opaqueWinInfo = (void *) tui_alloc_win_info (winType);
c906108c 986 }
6d012f14 987 if (tui_win_is_auxillary (winType))
2a8854a7 988 generic = (struct tui_gen_win_info *) opaqueWinInfo;
c906108c 989 else
2a8854a7 990 generic = &((struct tui_win_info *) opaqueWinInfo)->generic;
c906108c 991
22940a24 992 if (opaqueWinInfo != NULL)
c906108c
SS
993 {
994 _initGenWinInfo (generic, winType, height, width, originX, originY);
6d012f14 995 if (!tui_win_is_auxillary (winType))
c906108c
SS
996 {
997 if (generic->type == CMD_WIN)
6d012f14 998 ((struct tui_win_info *) opaqueWinInfo)->can_highlight = FALSE;
c906108c 999 else
6d012f14 1000 ((struct tui_win_info *) opaqueWinInfo)->can_highlight = TRUE;
c906108c 1001 }
ec7d9e56 1002 tui_make_window (generic, boxIt);
c906108c
SS
1003 }
1004 *winInfoPtr = opaqueWinInfo;
bc712bbf 1005}
c906108c
SS
1006
1007
1008/*
c5aa993b
JM
1009 ** _makeSourceOrDisassemWindow().
1010 */
c906108c 1011static void
22940a24 1012_makeSourceOrDisassemWindow (struct tui_win_info * * winInfoPtr, enum tui_win_type type,
eca6576c 1013 int height, int originY)
c906108c 1014{
6d012f14 1015 struct tui_gen_win_info * execution_info = (struct tui_gen_win_info *) NULL;
c906108c
SS
1016
1017 /*
c5aa993b
JM
1018 ** Create the exeuction info window.
1019 */
c906108c 1020 if (type == SRC_WIN)
6d012f14 1021 execution_info = tui_source_exec_info_win_ptr ();
c906108c 1022 else
6d012f14
AC
1023 execution_info = tui_disassem_exec_info_win_ptr ();
1024 _initAndMakeWin ((void **) & execution_info,
c906108c
SS
1025 EXEC_INFO_WIN,
1026 height,
1027 3,
1028 0,
1029 originY,
1030 DONT_BOX_WINDOW);
1031 /*
c5aa993b
JM
1032 ** Now create the source window.
1033 */
22940a24 1034 _initAndMakeWin ((void **) winInfoPtr,
c906108c
SS
1035 type,
1036 height,
6d012f14
AC
1037 tui_term_width () - execution_info->width,
1038 execution_info->width,
c906108c
SS
1039 originY,
1040 BOX_WINDOW);
1041
6d012f14 1042 (*winInfoPtr)->detail.source_info.execution_info = execution_info;
c906108c
SS
1043
1044 return;
1045} /* _makeSourceOrDisassemWindow */
1046
1047
1048/*
c5aa993b
JM
1049 ** _showSourceOrDisassemAndCommand().
1050 ** Show the Source/Command or the Disassem layout
1051 */
c906108c 1052static void
2a8854a7 1053_showSourceOrDisassemAndCommand (enum tui_layout_type layoutType)
c906108c 1054{
dd1abb8c 1055 if (tui_current_layout () != layoutType)
c906108c 1056 {
2a8854a7 1057 struct tui_win_info * *winInfoPtr;
c906108c 1058 int srcHeight, cmdHeight;
2a8854a7 1059 struct tui_gen_win_info * locator = tui_locator_win_info_ptr ();
c906108c 1060
6d012f14
AC
1061 if (TUI_CMD_WIN != NULL)
1062 cmdHeight = TUI_CMD_WIN->generic.height;
c906108c 1063 else
dd1abb8c
AC
1064 cmdHeight = tui_term_height () / 3;
1065 srcHeight = tui_term_height () - cmdHeight;
c906108c
SS
1066
1067
1068 if (layoutType == SRC_COMMAND)
6d012f14 1069 winInfoPtr = &TUI_SRC_WIN;
c906108c 1070 else
6d012f14 1071 winInfoPtr = &TUI_DISASM_WIN;
c906108c 1072
6d012f14 1073 if ((*winInfoPtr) == NULL)
c906108c
SS
1074 {
1075 if (layoutType == SRC_COMMAND)
1076 _makeSourceWindow (winInfoPtr, srcHeight - 1, 0);
1077 else
1078 _makeDisassemWindow (winInfoPtr, srcHeight - 1, 0);
22940a24 1079 _initAndMakeWin ((void **) & locator,
c906108c
SS
1080 LOCATOR_WIN,
1081 2 /* 1 */ ,
dd1abb8c 1082 tui_term_width (),
c906108c
SS
1083 0,
1084 srcHeight - 1,
1085 DONT_BOX_WINDOW);
1086 }
1087 else
1088 {
1089 _initGenWinInfo (locator,
1090 LOCATOR_WIN,
1091 2 /* 1 */ ,
dd1abb8c 1092 tui_term_width (),
c906108c
SS
1093 0,
1094 srcHeight - 1);
6d012f14 1095 (*winInfoPtr)->detail.source_info.has_locator = TRUE;
c906108c
SS
1096 _initGenWinInfo (
1097 &(*winInfoPtr)->generic,
1098 (*winInfoPtr)->generic.type,
1099 srcHeight - 1,
1100 (*winInfoPtr)->generic.width,
6d012f14 1101 (*winInfoPtr)->detail.source_info.execution_info->width,
c906108c 1102 0);
6d012f14 1103 _initGenWinInfo ((*winInfoPtr)->detail.source_info.execution_info,
c906108c
SS
1104 EXEC_INFO_WIN,
1105 srcHeight - 1,
1106 3,
1107 0,
1108 0);
6d012f14 1109 (*winInfoPtr)->can_highlight = TRUE;
ec7d9e56 1110 tui_make_visible (&(*winInfoPtr)->generic);
6d012f14 1111 tui_make_visible ((*winInfoPtr)->detail.source_info.execution_info);
c906108c 1112 }
6d012f14 1113 if ((*winInfoPtr) != NULL)
c906108c 1114 {
6d012f14 1115 (*winInfoPtr)->detail.source_info.has_locator = TRUE;
ec7d9e56 1116 tui_make_visible (locator);
47d3492a 1117 tui_show_locator_content ();
f80bda8e 1118 tui_show_source_content (*winInfoPtr);
c906108c 1119
6d012f14 1120 if (TUI_CMD_WIN == NULL)
c906108c 1121 {
6d012f14
AC
1122 _makeCommandWindow (&TUI_CMD_WIN, cmdHeight, srcHeight);
1123 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
1124 }
1125 else
1126 {
6d012f14
AC
1127 _initGenWinInfo (&TUI_CMD_WIN->generic,
1128 TUI_CMD_WIN->generic.type,
1129 TUI_CMD_WIN->generic.height,
1130 TUI_CMD_WIN->generic.width,
1131 TUI_CMD_WIN->generic.origin.x,
1132 TUI_CMD_WIN->generic.origin.y);
1133 TUI_CMD_WIN->can_highlight = FALSE;
1134 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c
SS
1135 }
1136 }
dd1abb8c 1137 tui_set_current_layout_to (layoutType);
c906108c
SS
1138 }
1139
1140 return;
1141} /* _showSourceOrDisassemAndCommand */