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