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