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