2007-08-14 Michael Snyder <msnyder@access-company.com>
[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 51static void show_source_or_disasm_and_command (enum tui_layout_type);
5b6fe301
MS
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);
6ba8e26f
AC
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 83 {
ef5eab5a
MS
84 /* Since the new layout may cause changes in window size, we
85 should free the content and reallocate on next display of
86 source/asm. */
dd1abb8c
AC
87 tui_free_all_source_wins_content ();
88 tui_clear_source_windows ();
c906108c
SS
89 if (layout == SRC_DATA_COMMAND || layout == DISASSEM_DATA_COMMAND)
90 {
6ba8e26f 91 show_data (layout);
6d012f14 92 tui_refresh_all (tui_win_list);
c906108c
SS
93 }
94 else
95 {
1cc6d956 96 /* First make the current layout be invisible. */
ec7d9e56 97 tui_make_all_invisible ();
dd1abb8c 98 tui_make_invisible (tui_locator_win_info_ptr ());
c906108c
SS
99
100 switch (layout)
101 {
1cc6d956 102 /* Now show the new layout. */
c906108c 103 case SRC_COMMAND:
6ba8e26f 104 show_source_command ();
6d012f14 105 tui_add_to_source_windows (TUI_SRC_WIN);
c906108c
SS
106 break;
107 case DISASSEM_COMMAND:
6ba8e26f 108 show_disasm_command ();
6d012f14 109 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
110 break;
111 case SRC_DISASSEM_COMMAND:
6ba8e26f 112 show_source_disasm_command ();
6d012f14
AC
113 tui_add_to_source_windows (TUI_SRC_WIN);
114 tui_add_to_source_windows (TUI_DISASM_WIN);
c906108c
SS
115 break;
116 default:
117 break;
118 }
119 }
120 }
bc712bbf 121}
c906108c
SS
122
123
080ce8c0
AC
124/* Function to set the layout to SRC_COMMAND, DISASSEM_COMMAND,
125 SRC_DISASSEM_COMMAND, SRC_DATA_COMMAND, or DISASSEM_DATA_COMMAND.
126 If the layout is SRC_DATA_COMMAND, DISASSEM_DATA_COMMAND, or
127 UNDEFINED_LAYOUT, then the data window is populated according to
6d012f14 128 regs_display_type. */
080ce8c0 129enum tui_status
6ba8e26f 130tui_set_layout (enum tui_layout_type layout_type,
6d012f14 131 enum tui_register_display_type regs_display_type)
c906108c 132{
22940a24 133 enum tui_status status = TUI_SUCCESS;
c906108c 134
6ba8e26f 135 if (layout_type != UNDEFINED_LAYOUT || regs_display_type != TUI_UNDEFINED_REGS)
c906108c 136 {
6ba8e26f
AC
137 enum tui_layout_type cur_layout = tui_current_layout (), new_layout = UNDEFINED_LAYOUT;
138 int regs_populate = FALSE;
139 CORE_ADDR addr = extract_display_start_addr ();
5b6fe301
MS
140 struct tui_win_info *win_with_focus = tui_win_with_focus ();
141 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c
SS
142
143
6ba8e26f 144 if (layout_type == UNDEFINED_LAYOUT &&
6d012f14 145 regs_display_type != TUI_UNDEFINED_REGS)
c906108c 146 {
6ba8e26f
AC
147 if (cur_layout == SRC_DISASSEM_COMMAND)
148 new_layout = DISASSEM_DATA_COMMAND;
149 else if (cur_layout == SRC_COMMAND || cur_layout == SRC_DATA_COMMAND)
150 new_layout = SRC_DATA_COMMAND;
151 else if (cur_layout == DISASSEM_COMMAND ||
152 cur_layout == DISASSEM_DATA_COMMAND)
153 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
154 }
155 else
6ba8e26f 156 new_layout = layout_type;
c906108c 157
6ba8e26f
AC
158 regs_populate = (new_layout == SRC_DATA_COMMAND ||
159 new_layout == DISASSEM_DATA_COMMAND ||
6d012f14 160 regs_display_type != TUI_UNDEFINED_REGS);
6ba8e26f 161 if (new_layout != cur_layout || regs_display_type != TUI_UNDEFINED_REGS)
c906108c 162 {
6ba8e26f 163 if (new_layout != cur_layout)
c906108c 164 {
6ba8e26f 165 show_layout (new_layout);
ef5eab5a
MS
166
167 /* Now determine where focus should be. */
6ba8e26f 168 if (win_with_focus != TUI_CMD_WIN)
c906108c 169 {
6ba8e26f 170 switch (new_layout)
c906108c
SS
171 {
172 case SRC_COMMAND:
6d012f14 173 tui_set_win_focus_to (TUI_SRC_WIN);
6ba8e26f
AC
174 layout_def->display_mode = SRC_WIN;
175 layout_def->split = FALSE;
c906108c
SS
176 break;
177 case DISASSEM_COMMAND:
ef5eab5a
MS
178 /* The previous layout was not showing code.
179 This can happen if there is no source
180 available:
181
182 1. if the source file is in another dir OR
183 2. if target was compiled without -g
184 We still want to show the assembly though! */
185
65f05602 186 addr = tui_get_begin_asm_address ();
6d012f14 187 tui_set_win_focus_to (TUI_DISASM_WIN);
6ba8e26f
AC
188 layout_def->display_mode = DISASSEM_WIN;
189 layout_def->split = FALSE;
c906108c
SS
190 break;
191 case SRC_DISASSEM_COMMAND:
ef5eab5a
MS
192 /* The previous layout was not showing code.
193 This can happen if there is no source
194 available:
195
196 1. if the source file is in another dir OR
197 2. if target was compiled without -g
198 We still want to show the assembly though! */
199
65f05602 200 addr = tui_get_begin_asm_address ();
6ba8e26f 201 if (win_with_focus == TUI_SRC_WIN)
6d012f14 202 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 203 else
6d012f14 204 tui_set_win_focus_to (TUI_DISASM_WIN);
6ba8e26f 205 layout_def->split = TRUE;
c906108c
SS
206 break;
207 case SRC_DATA_COMMAND:
6ba8e26f 208 if (win_with_focus != TUI_DATA_WIN)
6d012f14 209 tui_set_win_focus_to (TUI_SRC_WIN);
c906108c 210 else
6d012f14 211 tui_set_win_focus_to (TUI_DATA_WIN);
6ba8e26f
AC
212 layout_def->display_mode = SRC_WIN;
213 layout_def->split = FALSE;
c906108c
SS
214 break;
215 case DISASSEM_DATA_COMMAND:
ef5eab5a
MS
216 /* The previous layout was not showing code.
217 This can happen if there is no source
218 available:
219
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 419
1cc6d956 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 444
1cc6d956
MS
445 /* Could ifdef out the following code. when compile with
446 -z, there are null pointer references that cause a
447 core dump if 'layout regs' is the first layout
448 command issued by the user. HP has asked us to hook
449 up this code. - edie epstein */
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
1cc6d956
MS
478 /* End of potential ifdef.
479 */
c906108c 480
1cc6d956
MS
481 /* If ifdefed out code above, then assume that the user
482 wishes to display the general purpose registers .
483 */
c906108c 484
1cc6d956 485 /* dpy_type = TUI_GENERAL_REGS; */
c906108c 486 }
6ba8e26f
AC
487 else if (subset_compare (buf_ptr, "NEXT"))
488 new_layout = next_layout ();
489 else if (subset_compare (buf_ptr, "PREV"))
490 new_layout = prev_layout ();
c906108c
SS
491 else
492 status = TUI_FAILURE;
c906108c 493
6ba8e26f 494 tui_set_layout (new_layout, dpy_type);
c906108c 495 }
3e40160c 496 xfree (buf_ptr);
c906108c
SS
497 }
498 else
499 status = TUI_FAILURE;
500
501 return status;
e8b915dc 502}
c906108c
SS
503
504
c774cec6 505static CORE_ADDR
6ba8e26f 506extract_display_start_addr (void)
c906108c 507{
6ba8e26f 508 enum tui_layout_type cur_layout = tui_current_layout ();
c774cec6 509 CORE_ADDR addr;
84b1e7c7 510 CORE_ADDR pc;
52575520 511 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c 512
6ba8e26f 513 switch (cur_layout)
c906108c
SS
514 {
515 case SRC_COMMAND:
516 case SRC_DATA_COMMAND:
52575520 517 find_line_pc (cursal.symtab,
362c05fe 518 TUI_SRC_WIN->detail.source_info.start_line_or_addr.u.line_no,
84b1e7c7 519 &pc);
c774cec6 520 addr = pc;
c906108c
SS
521 break;
522 case DISASSEM_COMMAND:
523 case SRC_DISASSEM_COMMAND:
524 case DISASSEM_DATA_COMMAND:
362c05fe 525 addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr;
c906108c
SS
526 break;
527 default:
c774cec6 528 addr = 0;
c906108c
SS
529 break;
530 }
531
532 return addr;
6ba8e26f 533}
c906108c
SS
534
535
536static void
5b6fe301 537tui_handle_xdb_layout (struct tui_layout_def *layout_def)
c906108c 538{
6ba8e26f 539 if (layout_def->split)
c906108c 540 {
080ce8c0 541 tui_set_layout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
6ba8e26f 542 tui_set_win_focus_to (tui_win_list[layout_def->display_mode]);
c906108c
SS
543 }
544 else
545 {
6ba8e26f 546 if (layout_def->display_mode == SRC_WIN)
080ce8c0 547 tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
c906108c 548 else
6ba8e26f 549 tui_set_layout (DISASSEM_DATA_COMMAND, layout_def->regs_display_type);
c906108c 550 }
6ba8e26f 551}
c906108c
SS
552
553
554static void
6ba8e26f 555tui_toggle_layout_command (char *arg, int from_tty)
c906108c 556{
5b6fe301 557 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 558
19eb139b
SC
559 /* Make sure the curses mode is enabled. */
560 tui_enable ();
6ba8e26f
AC
561 if (layout_def->display_mode == SRC_WIN)
562 layout_def->display_mode = DISASSEM_WIN;
c906108c 563 else
6ba8e26f 564 layout_def->display_mode = SRC_WIN;
c906108c 565
6ba8e26f
AC
566 if (!layout_def->split)
567 tui_handle_xdb_layout (layout_def);
e8b915dc 568}
c906108c
SS
569
570
571static void
6ba8e26f 572tui_toggle_split_layout_command (char *arg, int from_tty)
c906108c 573{
5b6fe301 574 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 575
19eb139b
SC
576 /* Make sure the curses mode is enabled. */
577 tui_enable ();
6ba8e26f
AC
578 layout_def->split = (!layout_def->split);
579 tui_handle_xdb_layout (layout_def);
e8b915dc 580}
c906108c
SS
581
582
583static void
6ba8e26f 584tui_layout_command (char *arg, int from_tty)
c906108c 585{
19eb139b
SC
586 /* Make sure the curses mode is enabled. */
587 tui_enable ();
588
589 /* Switch to the selected layout. */
080ce8c0 590 if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
8a3fe4f8 591 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
c906108c 592
e8b915dc 593}
c906108c 594
6ba8e26f 595/* Answer the previous layout to cycle to. */
2a8854a7 596static enum tui_layout_type
6ba8e26f 597next_layout (void)
c906108c 598{
6ba8e26f 599 enum tui_layout_type new_layout;
c906108c 600
6ba8e26f
AC
601 new_layout = tui_current_layout ();
602 if (new_layout == UNDEFINED_LAYOUT)
603 new_layout = SRC_COMMAND;
c906108c
SS
604 else
605 {
6ba8e26f
AC
606 new_layout++;
607 if (new_layout == UNDEFINED_LAYOUT)
608 new_layout = SRC_COMMAND;
c906108c
SS
609 }
610
6ba8e26f
AC
611 return new_layout;
612}
c906108c
SS
613
614
6ba8e26f 615/* Answer the next layout to cycle to. */
2a8854a7 616static enum tui_layout_type
6ba8e26f 617prev_layout (void)
c906108c 618{
6ba8e26f 619 enum tui_layout_type new_layout;
c906108c 620
6ba8e26f
AC
621 new_layout = tui_current_layout ();
622 if (new_layout == SRC_COMMAND)
623 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
624 else
625 {
6ba8e26f
AC
626 new_layout--;
627 if (new_layout == UNDEFINED_LAYOUT)
628 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
629 }
630
6ba8e26f
AC
631 return new_layout;
632}
c906108c
SS
633
634
635
c906108c 636static void
5b6fe301 637make_command_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
c906108c 638{
d5d6fca5
DJ
639 *win_info_ptr = init_and_make_win (*win_info_ptr,
640 CMD_WIN,
641 height,
642 tui_term_width (),
643 0,
644 origin_y,
645 DONT_BOX_WINDOW);
c906108c 646
6ba8e26f
AC
647 (*win_info_ptr)->can_highlight = FALSE;
648}
c906108c
SS
649
650
ef5eab5a 651/* make_source_window().
c5aa993b 652 */
c906108c 653static void
5b6fe301 654make_source_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
c906108c 655{
6ba8e26f 656 make_source_or_disasm_window (win_info_ptr, SRC_WIN, height, origin_y);
c906108c
SS
657
658 return;
6ba8e26f 659} /* make_source_window */
c906108c
SS
660
661
ef5eab5a 662/* make_disasm_window().
c5aa993b 663 */
c906108c 664static void
5b6fe301 665make_disasm_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
c906108c 666{
6ba8e26f 667 make_source_or_disasm_window (win_info_ptr, DISASSEM_WIN, height, origin_y);
c906108c
SS
668
669 return;
6ba8e26f 670} /* make_disasm_window */
c906108c
SS
671
672
c906108c 673static void
5b6fe301 674make_data_window (struct tui_win_info **win_info_ptr, int height, int origin_y)
c906108c 675{
d5d6fca5
DJ
676 *win_info_ptr = init_and_make_win (*win_info_ptr,
677 DATA_WIN,
678 height,
679 tui_term_width (),
680 0,
681 origin_y,
682 BOX_WINDOW);
6ba8e26f 683}
c906108c
SS
684
685
686
6ba8e26f 687/* Show the Source/Command layout. */
c906108c 688static void
6ba8e26f 689show_source_command (void)
c906108c 690{
6ba8e26f
AC
691 show_source_or_disasm_and_command (SRC_COMMAND);
692}
c906108c
SS
693
694
6ba8e26f 695/* Show the Dissassem/Command layout. */
c906108c 696static void
6ba8e26f 697show_disasm_command (void)
c906108c 698{
6ba8e26f
AC
699 show_source_or_disasm_and_command (DISASSEM_COMMAND);
700}
c906108c
SS
701
702
6ba8e26f 703/* Show the Source/Disassem/Command layout. */
c906108c 704static void
6ba8e26f 705show_source_disasm_command (void)
c906108c 706{
dd1abb8c 707 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
c906108c 708 {
6ba8e26f 709 int cmd_height, src_height, asm_height;
c906108c 710
6d012f14 711 if (TUI_CMD_WIN != NULL)
6ba8e26f 712 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 713 else
6ba8e26f 714 cmd_height = tui_term_height () / 3;
c906108c 715
6ba8e26f
AC
716 src_height = (tui_term_height () - cmd_height) / 2;
717 asm_height = tui_term_height () - (src_height + cmd_height);
c906108c 718
6d012f14 719 if (TUI_SRC_WIN == NULL)
6ba8e26f 720 make_source_window (&TUI_SRC_WIN, src_height, 0);
c906108c
SS
721 else
722 {
6ba8e26f 723 init_gen_win_info (&TUI_SRC_WIN->generic,
6d012f14 724 TUI_SRC_WIN->generic.type,
6ba8e26f 725 src_height,
6d012f14
AC
726 TUI_SRC_WIN->generic.width,
727 TUI_SRC_WIN->detail.source_info.execution_info->width,
c906108c 728 0);
6d012f14 729 TUI_SRC_WIN->can_highlight = TRUE;
6ba8e26f 730 init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info,
c906108c 731 EXEC_INFO_WIN,
6ba8e26f 732 src_height,
c906108c
SS
733 3,
734 0,
735 0);
6d012f14
AC
736 tui_make_visible (&TUI_SRC_WIN->generic);
737 tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
738 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
c906108c 739 }
6d012f14 740 if (TUI_SRC_WIN != NULL)
c906108c 741 {
5b6fe301 742 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 743
6d012f14
AC
744 tui_show_source_content (TUI_SRC_WIN);
745 if (TUI_DISASM_WIN == NULL)
c906108c 746 {
6ba8e26f 747 make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1);
d5d6fca5
DJ
748 locator = init_and_make_win (locator,
749 LOCATOR_WIN,
750 2 /* 1 */ ,
751 tui_term_width (),
752 0,
753 (src_height + asm_height) - 1,
754 DONT_BOX_WINDOW);
c906108c
SS
755 }
756 else
757 {
6ba8e26f 758 init_gen_win_info (locator,
c906108c
SS
759 LOCATOR_WIN,
760 2 /* 1 */ ,
dd1abb8c 761 tui_term_width (),
c906108c 762 0,
6ba8e26f 763 (src_height + asm_height) - 1);
6d012f14 764 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
6ba8e26f 765 init_gen_win_info (
6d012f14
AC
766 &TUI_DISASM_WIN->generic,
767 TUI_DISASM_WIN->generic.type,
6ba8e26f 768 asm_height,
6d012f14
AC
769 TUI_DISASM_WIN->generic.width,
770 TUI_DISASM_WIN->detail.source_info.execution_info->width,
6ba8e26f
AC
771 src_height - 1);
772 init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info,
c906108c 773 EXEC_INFO_WIN,
6ba8e26f 774 asm_height,
c906108c
SS
775 3,
776 0,
6ba8e26f 777 src_height - 1);
6d012f14
AC
778 TUI_DISASM_WIN->can_highlight = TRUE;
779 tui_make_visible (&TUI_DISASM_WIN->generic);
780 tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
c906108c 781 }
6d012f14 782 if (TUI_DISASM_WIN != NULL)
c906108c 783 {
6d012f14
AC
784 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
785 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
ec7d9e56 786 tui_make_visible (locator);
47d3492a 787 tui_show_locator_content ();
6d012f14 788 tui_show_source_content (TUI_DISASM_WIN);
c906108c 789
6d012f14 790 if (TUI_CMD_WIN == NULL)
6ba8e26f
AC
791 make_command_window (&TUI_CMD_WIN,
792 cmd_height,
793 tui_term_height () - cmd_height);
c906108c
SS
794 else
795 {
6ba8e26f 796 init_gen_win_info (&TUI_CMD_WIN->generic,
6d012f14
AC
797 TUI_CMD_WIN->generic.type,
798 TUI_CMD_WIN->generic.height,
799 TUI_CMD_WIN->generic.width,
c906108c 800 0,
6d012f14
AC
801 TUI_CMD_WIN->generic.origin.y);
802 TUI_CMD_WIN->can_highlight = FALSE;
803 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c 804 }
6d012f14
AC
805 if (TUI_CMD_WIN != NULL)
806 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
807 }
808 }
dd1abb8c 809 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
c906108c 810 }
6ba8e26f 811}
c906108c
SS
812
813
6ba8e26f
AC
814/* Show the Source/Data/Command or the Dissassembly/Data/Command
815 layout. */
c906108c 816static void
6ba8e26f 817show_data (enum tui_layout_type new_layout)
c906108c 818{
6ba8e26f
AC
819 int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height);
820 int src_height, data_height;
821 enum tui_win_type win_type;
5b6fe301 822 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c
SS
823
824
6ba8e26f
AC
825 data_height = total_height / 2;
826 src_height = total_height - data_height;
ec7d9e56
AC
827 tui_make_all_invisible ();
828 tui_make_invisible (locator);
6ba8e26f 829 make_data_window (&TUI_DATA_WIN, data_height, 0);
6d012f14 830 TUI_DATA_WIN->can_highlight = TRUE;
6ba8e26f
AC
831 if (new_layout == SRC_DATA_COMMAND)
832 win_type = SRC_WIN;
c906108c 833 else
6ba8e26f
AC
834 win_type = DISASSEM_WIN;
835 if (tui_win_list[win_type] == NULL)
c906108c 836 {
6ba8e26f
AC
837 if (win_type == SRC_WIN)
838 make_source_window (&tui_win_list[win_type], src_height, data_height - 1);
c906108c 839 else
6ba8e26f 840 make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1);
d5d6fca5
DJ
841 locator = init_and_make_win (locator,
842 LOCATOR_WIN,
843 2 /* 1 */ ,
844 tui_term_width (),
845 0,
846 total_height - 1,
847 DONT_BOX_WINDOW);
c906108c
SS
848 }
849 else
850 {
6ba8e26f
AC
851 init_gen_win_info (&tui_win_list[win_type]->generic,
852 tui_win_list[win_type]->generic.type,
853 src_height,
854 tui_win_list[win_type]->generic.width,
855 tui_win_list[win_type]->detail.source_info.execution_info->width,
856 data_height - 1);
857 init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info,
c906108c 858 EXEC_INFO_WIN,
6ba8e26f 859 src_height,
c906108c
SS
860 3,
861 0,
6ba8e26f
AC
862 data_height - 1);
863 tui_make_visible (&tui_win_list[win_type]->generic);
864 tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info);
865 init_gen_win_info (locator,
c906108c
SS
866 LOCATOR_WIN,
867 2 /* 1 */ ,
dd1abb8c 868 tui_term_width (),
c906108c 869 0,
6ba8e26f 870 total_height - 1);
c906108c 871 }
6ba8e26f 872 tui_win_list[win_type]->detail.source_info.has_locator = TRUE;
ec7d9e56 873 tui_make_visible (locator);
47d3492a 874 tui_show_locator_content ();
6ba8e26f
AC
875 tui_add_to_source_windows (tui_win_list[win_type]);
876 tui_set_current_layout_to (new_layout);
877}
c906108c 878
ef5eab5a 879/* init_gen_win_info().
c5aa993b 880 */
c906108c 881static void
5b6fe301 882init_gen_win_info (struct tui_gen_win_info *win_info, enum tui_win_type type,
6ba8e26f 883 int height, int width, int origin_x, int origin_y)
c906108c
SS
884{
885 int h = height;
886
6ba8e26f
AC
887 win_info->type = type;
888 win_info->width = width;
889 win_info->height = h;
c906108c
SS
890 if (h > 1)
891 {
6ba8e26f
AC
892 win_info->viewport_height = h - 1;
893 if (win_info->type != CMD_WIN)
894 win_info->viewport_height--;
c906108c
SS
895 }
896 else
6ba8e26f
AC
897 win_info->viewport_height = 1;
898 win_info->origin.x = origin_x;
899 win_info->origin.y = origin_y;
c906108c
SS
900
901 return;
6ba8e26f 902} /* init_gen_win_info */
c906108c 903
ef5eab5a 904/* init_and_make_win().
c5aa993b 905 */
d5d6fca5
DJ
906static void *
907init_and_make_win (void *opaque_win_info, enum tui_win_type win_type,
908 int height, int width, int origin_x, int origin_y,
909 int box_it)
c906108c 910{
5b6fe301 911 struct tui_gen_win_info *generic;
c906108c 912
6ba8e26f 913 if (opaque_win_info == NULL)
c906108c 914 {
6ba8e26f
AC
915 if (tui_win_is_auxillary (win_type))
916 opaque_win_info = (void *) tui_alloc_generic_win_info ();
c906108c 917 else
6ba8e26f 918 opaque_win_info = (void *) tui_alloc_win_info (win_type);
c906108c 919 }
6ba8e26f
AC
920 if (tui_win_is_auxillary (win_type))
921 generic = (struct tui_gen_win_info *) opaque_win_info;
c906108c 922 else
6ba8e26f 923 generic = &((struct tui_win_info *) opaque_win_info)->generic;
c906108c 924
6ba8e26f 925 if (opaque_win_info != NULL)
c906108c 926 {
6ba8e26f
AC
927 init_gen_win_info (generic, win_type, height, width, origin_x, origin_y);
928 if (!tui_win_is_auxillary (win_type))
c906108c
SS
929 {
930 if (generic->type == CMD_WIN)
6ba8e26f 931 ((struct tui_win_info *) opaque_win_info)->can_highlight = FALSE;
c906108c 932 else
6ba8e26f 933 ((struct tui_win_info *) opaque_win_info)->can_highlight = TRUE;
c906108c 934 }
6ba8e26f 935 tui_make_window (generic, box_it);
c906108c 936 }
d5d6fca5 937 return opaque_win_info;
bc712bbf 938}
c906108c
SS
939
940
c906108c 941static void
5b6fe301 942make_source_or_disasm_window (struct tui_win_info **win_info_ptr, enum tui_win_type type,
6ba8e26f 943 int height, int origin_y)
c906108c 944{
5b6fe301 945 struct tui_gen_win_info *execution_info = (struct tui_gen_win_info *) NULL;
c906108c 946
ef5eab5a 947 /* Create the exeuction info window. */
c906108c 948 if (type == SRC_WIN)
6d012f14 949 execution_info = tui_source_exec_info_win_ptr ();
c906108c 950 else
6d012f14 951 execution_info = tui_disassem_exec_info_win_ptr ();
d5d6fca5
DJ
952 execution_info = init_and_make_win (execution_info,
953 EXEC_INFO_WIN,
954 height,
955 3,
956 0,
957 origin_y,
958 DONT_BOX_WINDOW);
ef5eab5a
MS
959
960 /* Now create the source window. */
d5d6fca5
DJ
961 *win_info_ptr = init_and_make_win (*win_info_ptr,
962 type,
963 height,
964 tui_term_width () - execution_info->width,
965 execution_info->width,
966 origin_y,
967 BOX_WINDOW);
c906108c 968
6ba8e26f
AC
969 (*win_info_ptr)->detail.source_info.execution_info = execution_info;
970}
c906108c
SS
971
972
1cc6d956 973/* Show the Source/Command or the Disassem layout. */
c906108c 974static void
6ba8e26f 975show_source_or_disasm_and_command (enum tui_layout_type layout_type)
c906108c 976{
6ba8e26f 977 if (tui_current_layout () != layout_type)
c906108c 978 {
5b6fe301 979 struct tui_win_info **win_info_ptr;
6ba8e26f 980 int src_height, cmd_height;
5b6fe301 981 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 982
6d012f14 983 if (TUI_CMD_WIN != NULL)
6ba8e26f 984 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 985 else
6ba8e26f
AC
986 cmd_height = tui_term_height () / 3;
987 src_height = tui_term_height () - cmd_height;
c906108c
SS
988
989
6ba8e26f
AC
990 if (layout_type == SRC_COMMAND)
991 win_info_ptr = &TUI_SRC_WIN;
c906108c 992 else
6ba8e26f 993 win_info_ptr = &TUI_DISASM_WIN;
c906108c 994
6ba8e26f 995 if ((*win_info_ptr) == NULL)
c906108c 996 {
6ba8e26f
AC
997 if (layout_type == SRC_COMMAND)
998 make_source_window (win_info_ptr, src_height - 1, 0);
c906108c 999 else
6ba8e26f 1000 make_disasm_window (win_info_ptr, src_height - 1, 0);
d5d6fca5
DJ
1001 locator = init_and_make_win (locator,
1002 LOCATOR_WIN,
1003 2 /* 1 */ ,
1004 tui_term_width (),
1005 0,
1006 src_height - 1,
1007 DONT_BOX_WINDOW);
c906108c
SS
1008 }
1009 else
1010 {
6ba8e26f 1011 init_gen_win_info (locator,
c906108c
SS
1012 LOCATOR_WIN,
1013 2 /* 1 */ ,
dd1abb8c 1014 tui_term_width (),
c906108c 1015 0,
6ba8e26f
AC
1016 src_height - 1);
1017 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
1018 init_gen_win_info (
1019 &(*win_info_ptr)->generic,
1020 (*win_info_ptr)->generic.type,
1021 src_height - 1,
1022 (*win_info_ptr)->generic.width,
1023 (*win_info_ptr)->detail.source_info.execution_info->width,
c906108c 1024 0);
6ba8e26f 1025 init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info,
c906108c 1026 EXEC_INFO_WIN,
6ba8e26f 1027 src_height - 1,
c906108c
SS
1028 3,
1029 0,
1030 0);
6ba8e26f
AC
1031 (*win_info_ptr)->can_highlight = TRUE;
1032 tui_make_visible (&(*win_info_ptr)->generic);
1033 tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info);
c906108c 1034 }
6ba8e26f 1035 if ((*win_info_ptr) != NULL)
c906108c 1036 {
6ba8e26f 1037 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
ec7d9e56 1038 tui_make_visible (locator);
47d3492a 1039 tui_show_locator_content ();
6ba8e26f 1040 tui_show_source_content (*win_info_ptr);
c906108c 1041
6d012f14 1042 if (TUI_CMD_WIN == NULL)
c906108c 1043 {
6ba8e26f 1044 make_command_window (&TUI_CMD_WIN, cmd_height, src_height);
6d012f14 1045 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
1046 }
1047 else
1048 {
6ba8e26f 1049 init_gen_win_info (&TUI_CMD_WIN->generic,
6d012f14
AC
1050 TUI_CMD_WIN->generic.type,
1051 TUI_CMD_WIN->generic.height,
1052 TUI_CMD_WIN->generic.width,
1053 TUI_CMD_WIN->generic.origin.x,
1054 TUI_CMD_WIN->generic.origin.y);
1055 TUI_CMD_WIN->can_highlight = FALSE;
1056 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c
SS
1057 }
1058 }
6ba8e26f 1059 tui_set_current_layout_to (layout_type);
c906108c 1060 }
6ba8e26f 1061}
This page took 0.771526 seconds and 4 git commands to generate.