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