Use memmove to copy overlap memory.
[deliverable/binutils-gdb.git] / gdb / tui / tui-layout.c
CommitLineData
f377b406 1/* TUI layout window management.
f33c6cbf 2
4c38e0a4
JB
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009,
4 2010 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 {
e5908723
MS
471 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type != TUI_SFLOAT_REGS
472 && TUI_DATA_WIN->detail.data_display_info.regs_display_type != TUI_DFLOAT_REGS)
6ba8e26f 473 dpy_type = TUI_SFLOAT_REGS;
c906108c 474 else
6ba8e26f 475 dpy_type =
6d012f14 476 TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c 477 }
6ba8e26f 478 else if (subset_compare (buf_ptr,
c906108c 479 TUI_GENERAL_SPECIAL_REGS_NAME))
6ba8e26f
AC
480 dpy_type = TUI_GENERAL_AND_SPECIAL_REGS;
481 else if (subset_compare (buf_ptr, TUI_GENERAL_REGS_NAME))
482 dpy_type = TUI_GENERAL_REGS;
483 else if (subset_compare (buf_ptr, TUI_SPECIAL_REGS_NAME))
484 dpy_type = TUI_SPECIAL_REGS;
6d012f14 485 else if (TUI_DATA_WIN)
c906108c 486 {
6d012f14 487 if (TUI_DATA_WIN->detail.data_display_info.regs_display_type !=
c906108c 488 TUI_UNDEFINED_REGS)
6ba8e26f 489 dpy_type =
6d012f14 490 TUI_DATA_WIN->detail.data_display_info.regs_display_type;
c906108c 491 else
6ba8e26f 492 dpy_type = TUI_GENERAL_REGS;
c906108c
SS
493 }
494
1cc6d956
MS
495 /* End of potential ifdef.
496 */
c906108c 497
1cc6d956
MS
498 /* If ifdefed out code above, then assume that the user
499 wishes to display the general purpose registers .
500 */
c906108c 501
1cc6d956 502 /* dpy_type = TUI_GENERAL_REGS; */
c906108c 503 }
6ba8e26f
AC
504 else if (subset_compare (buf_ptr, "NEXT"))
505 new_layout = next_layout ();
506 else if (subset_compare (buf_ptr, "PREV"))
507 new_layout = prev_layout ();
c906108c
SS
508 else
509 status = TUI_FAILURE;
c906108c 510
6ba8e26f 511 tui_set_layout (new_layout, dpy_type);
c906108c 512 }
3e40160c 513 xfree (buf_ptr);
c906108c
SS
514 }
515 else
516 status = TUI_FAILURE;
517
518 return status;
e8b915dc 519}
c906108c
SS
520
521
13274fc3
UW
522static void
523extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
c906108c 524{
6ba8e26f 525 enum tui_layout_type cur_layout = tui_current_layout ();
957b8b5a 526 struct gdbarch *gdbarch = get_current_arch ();
c774cec6 527 CORE_ADDR addr;
84b1e7c7 528 CORE_ADDR pc;
52575520 529 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
c906108c 530
6ba8e26f 531 switch (cur_layout)
c906108c
SS
532 {
533 case SRC_COMMAND:
534 case SRC_DATA_COMMAND:
13274fc3 535 gdbarch = TUI_SRC_WIN->detail.source_info.gdbarch;
52575520 536 find_line_pc (cursal.symtab,
362c05fe 537 TUI_SRC_WIN->detail.source_info.start_line_or_addr.u.line_no,
84b1e7c7 538 &pc);
c774cec6 539 addr = pc;
c906108c
SS
540 break;
541 case DISASSEM_COMMAND:
542 case SRC_DISASSEM_COMMAND:
543 case DISASSEM_DATA_COMMAND:
13274fc3 544 gdbarch = TUI_DISASM_WIN->detail.source_info.gdbarch;
362c05fe 545 addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.u.addr;
c906108c
SS
546 break;
547 default:
c774cec6 548 addr = 0;
c906108c
SS
549 break;
550 }
551
13274fc3
UW
552 *gdbarch_p = gdbarch;
553 *addr_p = addr;
6ba8e26f 554}
c906108c
SS
555
556
557static void
5b6fe301 558tui_handle_xdb_layout (struct tui_layout_def *layout_def)
c906108c 559{
6ba8e26f 560 if (layout_def->split)
c906108c 561 {
080ce8c0 562 tui_set_layout (SRC_DISASSEM_COMMAND, TUI_UNDEFINED_REGS);
6ba8e26f 563 tui_set_win_focus_to (tui_win_list[layout_def->display_mode]);
c906108c
SS
564 }
565 else
566 {
6ba8e26f 567 if (layout_def->display_mode == SRC_WIN)
080ce8c0 568 tui_set_layout (SRC_COMMAND, TUI_UNDEFINED_REGS);
c906108c 569 else
6ba8e26f 570 tui_set_layout (DISASSEM_DATA_COMMAND, layout_def->regs_display_type);
c906108c 571 }
6ba8e26f 572}
c906108c
SS
573
574
575static void
6ba8e26f 576tui_toggle_layout_command (char *arg, int from_tty)
c906108c 577{
5b6fe301 578 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 579
19eb139b
SC
580 /* Make sure the curses mode is enabled. */
581 tui_enable ();
6ba8e26f
AC
582 if (layout_def->display_mode == SRC_WIN)
583 layout_def->display_mode = DISASSEM_WIN;
c906108c 584 else
6ba8e26f 585 layout_def->display_mode = SRC_WIN;
c906108c 586
6ba8e26f
AC
587 if (!layout_def->split)
588 tui_handle_xdb_layout (layout_def);
e8b915dc 589}
c906108c
SS
590
591
592static void
6ba8e26f 593tui_toggle_split_layout_command (char *arg, int from_tty)
c906108c 594{
5b6fe301 595 struct tui_layout_def *layout_def = tui_layout_def ();
c906108c 596
19eb139b
SC
597 /* Make sure the curses mode is enabled. */
598 tui_enable ();
6ba8e26f
AC
599 layout_def->split = (!layout_def->split);
600 tui_handle_xdb_layout (layout_def);
e8b915dc 601}
c906108c
SS
602
603
604static void
6ba8e26f 605tui_layout_command (char *arg, int from_tty)
c906108c 606{
19eb139b
SC
607 /* Make sure the curses mode is enabled. */
608 tui_enable ();
609
610 /* Switch to the selected layout. */
080ce8c0 611 if (tui_set_layout_for_display_command (arg) != TUI_SUCCESS)
8a3fe4f8 612 warning (_("Invalid layout specified.\n%s"), LAYOUT_USAGE);
c906108c 613
e8b915dc 614}
c906108c 615
6ba8e26f 616/* Answer the previous layout to cycle to. */
2a8854a7 617static enum tui_layout_type
6ba8e26f 618next_layout (void)
c906108c 619{
6ba8e26f 620 enum tui_layout_type new_layout;
c906108c 621
6ba8e26f
AC
622 new_layout = tui_current_layout ();
623 if (new_layout == UNDEFINED_LAYOUT)
624 new_layout = SRC_COMMAND;
c906108c
SS
625 else
626 {
6ba8e26f
AC
627 new_layout++;
628 if (new_layout == UNDEFINED_LAYOUT)
629 new_layout = SRC_COMMAND;
c906108c
SS
630 }
631
6ba8e26f
AC
632 return new_layout;
633}
c906108c
SS
634
635
6ba8e26f 636/* Answer the next layout to cycle to. */
2a8854a7 637static enum tui_layout_type
6ba8e26f 638prev_layout (void)
c906108c 639{
6ba8e26f 640 enum tui_layout_type new_layout;
c906108c 641
6ba8e26f
AC
642 new_layout = tui_current_layout ();
643 if (new_layout == SRC_COMMAND)
644 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
645 else
646 {
6ba8e26f
AC
647 new_layout--;
648 if (new_layout == UNDEFINED_LAYOUT)
649 new_layout = DISASSEM_DATA_COMMAND;
c906108c
SS
650 }
651
6ba8e26f
AC
652 return new_layout;
653}
c906108c
SS
654
655
656
c906108c 657static void
08ef48c5
MS
658make_command_window (struct tui_win_info **win_info_ptr,
659 int height, int origin_y)
c906108c 660{
d5d6fca5
DJ
661 *win_info_ptr = init_and_make_win (*win_info_ptr,
662 CMD_WIN,
663 height,
664 tui_term_width (),
665 0,
666 origin_y,
667 DONT_BOX_WINDOW);
c906108c 668
6ba8e26f
AC
669 (*win_info_ptr)->can_highlight = FALSE;
670}
c906108c
SS
671
672
ef5eab5a 673/* make_source_window().
c5aa993b 674 */
c906108c 675static void
08ef48c5
MS
676make_source_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, SRC_WIN, height, origin_y);
c906108c
SS
680
681 return;
6ba8e26f 682} /* make_source_window */
c906108c
SS
683
684
ef5eab5a 685/* make_disasm_window().
c5aa993b 686 */
c906108c 687static void
08ef48c5
MS
688make_disasm_window (struct tui_win_info **win_info_ptr,
689 int height, int origin_y)
c906108c 690{
6ba8e26f 691 make_source_or_disasm_window (win_info_ptr, DISASSEM_WIN, height, origin_y);
c906108c
SS
692
693 return;
6ba8e26f 694} /* make_disasm_window */
c906108c
SS
695
696
c906108c 697static void
08ef48c5
MS
698make_data_window (struct tui_win_info **win_info_ptr,
699 int height, int origin_y)
c906108c 700{
d5d6fca5
DJ
701 *win_info_ptr = init_and_make_win (*win_info_ptr,
702 DATA_WIN,
703 height,
704 tui_term_width (),
705 0,
706 origin_y,
707 BOX_WINDOW);
6ba8e26f 708}
c906108c
SS
709
710
711
6ba8e26f 712/* Show the Source/Command layout. */
c906108c 713static void
6ba8e26f 714show_source_command (void)
c906108c 715{
6ba8e26f
AC
716 show_source_or_disasm_and_command (SRC_COMMAND);
717}
c906108c
SS
718
719
6ba8e26f 720/* Show the Dissassem/Command layout. */
c906108c 721static void
6ba8e26f 722show_disasm_command (void)
c906108c 723{
6ba8e26f
AC
724 show_source_or_disasm_and_command (DISASSEM_COMMAND);
725}
c906108c
SS
726
727
6ba8e26f 728/* Show the Source/Disassem/Command layout. */
c906108c 729static void
6ba8e26f 730show_source_disasm_command (void)
c906108c 731{
dd1abb8c 732 if (tui_current_layout () != SRC_DISASSEM_COMMAND)
c906108c 733 {
6ba8e26f 734 int cmd_height, src_height, asm_height;
c906108c 735
6d012f14 736 if (TUI_CMD_WIN != NULL)
6ba8e26f 737 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 738 else
6ba8e26f 739 cmd_height = tui_term_height () / 3;
c906108c 740
6ba8e26f
AC
741 src_height = (tui_term_height () - cmd_height) / 2;
742 asm_height = tui_term_height () - (src_height + cmd_height);
c906108c 743
6d012f14 744 if (TUI_SRC_WIN == NULL)
6ba8e26f 745 make_source_window (&TUI_SRC_WIN, src_height, 0);
c906108c
SS
746 else
747 {
6ba8e26f 748 init_gen_win_info (&TUI_SRC_WIN->generic,
08ef48c5
MS
749 TUI_SRC_WIN->generic.type,
750 src_height,
751 TUI_SRC_WIN->generic.width,
752 TUI_SRC_WIN->detail.source_info.execution_info->width,
753 0);
6d012f14 754 TUI_SRC_WIN->can_highlight = TRUE;
6ba8e26f 755 init_gen_win_info (TUI_SRC_WIN->detail.source_info.execution_info,
08ef48c5
MS
756 EXEC_INFO_WIN,
757 src_height,
758 3,
759 0,
760 0);
6d012f14
AC
761 tui_make_visible (&TUI_SRC_WIN->generic);
762 tui_make_visible (TUI_SRC_WIN->detail.source_info.execution_info);
763 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;;
c906108c 764 }
6d012f14 765 if (TUI_SRC_WIN != NULL)
c906108c 766 {
5b6fe301 767 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 768
6d012f14
AC
769 tui_show_source_content (TUI_SRC_WIN);
770 if (TUI_DISASM_WIN == NULL)
c906108c 771 {
6ba8e26f 772 make_disasm_window (&TUI_DISASM_WIN, asm_height, src_height - 1);
d5d6fca5
DJ
773 locator = init_and_make_win (locator,
774 LOCATOR_WIN,
775 2 /* 1 */ ,
776 tui_term_width (),
777 0,
778 (src_height + asm_height) - 1,
779 DONT_BOX_WINDOW);
c906108c
SS
780 }
781 else
782 {
6ba8e26f 783 init_gen_win_info (locator,
08ef48c5
MS
784 LOCATOR_WIN,
785 2 /* 1 */ ,
786 tui_term_width (),
787 0,
788 (src_height + asm_height) - 1);
6d012f14 789 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
08ef48c5
MS
790 init_gen_win_info (&TUI_DISASM_WIN->generic,
791 TUI_DISASM_WIN->generic.type,
792 asm_height,
793 TUI_DISASM_WIN->generic.width,
794 TUI_DISASM_WIN->detail.source_info.execution_info->width,
795 src_height - 1);
6ba8e26f 796 init_gen_win_info (TUI_DISASM_WIN->detail.source_info.execution_info,
08ef48c5
MS
797 EXEC_INFO_WIN,
798 asm_height,
799 3,
800 0,
801 src_height - 1);
6d012f14
AC
802 TUI_DISASM_WIN->can_highlight = TRUE;
803 tui_make_visible (&TUI_DISASM_WIN->generic);
804 tui_make_visible (TUI_DISASM_WIN->detail.source_info.execution_info);
c906108c 805 }
6d012f14 806 if (TUI_DISASM_WIN != NULL)
c906108c 807 {
6d012f14
AC
808 TUI_SRC_WIN->detail.source_info.has_locator = FALSE;
809 TUI_DISASM_WIN->detail.source_info.has_locator = TRUE;
ec7d9e56 810 tui_make_visible (locator);
47d3492a 811 tui_show_locator_content ();
6d012f14 812 tui_show_source_content (TUI_DISASM_WIN);
c906108c 813
6d012f14 814 if (TUI_CMD_WIN == NULL)
6ba8e26f 815 make_command_window (&TUI_CMD_WIN,
08ef48c5
MS
816 cmd_height,
817 tui_term_height () - cmd_height);
c906108c
SS
818 else
819 {
6ba8e26f 820 init_gen_win_info (&TUI_CMD_WIN->generic,
08ef48c5
MS
821 TUI_CMD_WIN->generic.type,
822 TUI_CMD_WIN->generic.height,
823 TUI_CMD_WIN->generic.width,
824 0,
825 TUI_CMD_WIN->generic.origin.y);
6d012f14
AC
826 TUI_CMD_WIN->can_highlight = FALSE;
827 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c 828 }
6d012f14
AC
829 if (TUI_CMD_WIN != NULL)
830 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
831 }
832 }
dd1abb8c 833 tui_set_current_layout_to (SRC_DISASSEM_COMMAND);
c906108c 834 }
6ba8e26f 835}
c906108c
SS
836
837
6ba8e26f
AC
838/* Show the Source/Data/Command or the Dissassembly/Data/Command
839 layout. */
c906108c 840static void
6ba8e26f 841show_data (enum tui_layout_type new_layout)
c906108c 842{
6ba8e26f
AC
843 int total_height = (tui_term_height () - TUI_CMD_WIN->generic.height);
844 int src_height, data_height;
845 enum tui_win_type win_type;
5b6fe301 846 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c
SS
847
848
6ba8e26f
AC
849 data_height = total_height / 2;
850 src_height = total_height - data_height;
ec7d9e56
AC
851 tui_make_all_invisible ();
852 tui_make_invisible (locator);
6ba8e26f 853 make_data_window (&TUI_DATA_WIN, data_height, 0);
6d012f14 854 TUI_DATA_WIN->can_highlight = TRUE;
6ba8e26f
AC
855 if (new_layout == SRC_DATA_COMMAND)
856 win_type = SRC_WIN;
c906108c 857 else
6ba8e26f
AC
858 win_type = DISASSEM_WIN;
859 if (tui_win_list[win_type] == NULL)
c906108c 860 {
6ba8e26f
AC
861 if (win_type == SRC_WIN)
862 make_source_window (&tui_win_list[win_type], src_height, data_height - 1);
c906108c 863 else
6ba8e26f 864 make_disasm_window (&tui_win_list[win_type], src_height, data_height - 1);
d5d6fca5
DJ
865 locator = init_and_make_win (locator,
866 LOCATOR_WIN,
867 2 /* 1 */ ,
868 tui_term_width (),
869 0,
870 total_height - 1,
871 DONT_BOX_WINDOW);
c906108c
SS
872 }
873 else
874 {
6ba8e26f 875 init_gen_win_info (&tui_win_list[win_type]->generic,
08ef48c5
MS
876 tui_win_list[win_type]->generic.type,
877 src_height,
878 tui_win_list[win_type]->generic.width,
879 tui_win_list[win_type]->detail.source_info.execution_info->width,
880 data_height - 1);
6ba8e26f 881 init_gen_win_info (tui_win_list[win_type]->detail.source_info.execution_info,
08ef48c5
MS
882 EXEC_INFO_WIN,
883 src_height,
884 3,
885 0,
886 data_height - 1);
6ba8e26f
AC
887 tui_make_visible (&tui_win_list[win_type]->generic);
888 tui_make_visible (tui_win_list[win_type]->detail.source_info.execution_info);
889 init_gen_win_info (locator,
08ef48c5
MS
890 LOCATOR_WIN,
891 2 /* 1 */ ,
892 tui_term_width (),
893 0,
894 total_height - 1);
c906108c 895 }
6ba8e26f 896 tui_win_list[win_type]->detail.source_info.has_locator = TRUE;
ec7d9e56 897 tui_make_visible (locator);
47d3492a 898 tui_show_locator_content ();
6ba8e26f
AC
899 tui_add_to_source_windows (tui_win_list[win_type]);
900 tui_set_current_layout_to (new_layout);
901}
c906108c 902
ef5eab5a 903/* init_gen_win_info().
c5aa993b 904 */
c906108c 905static void
08ef48c5
MS
906init_gen_win_info (struct tui_gen_win_info *win_info,
907 enum tui_win_type type,
908 int height, int width,
909 int origin_x, int origin_y)
c906108c
SS
910{
911 int h = height;
912
6ba8e26f
AC
913 win_info->type = type;
914 win_info->width = width;
915 win_info->height = h;
c906108c
SS
916 if (h > 1)
917 {
6ba8e26f
AC
918 win_info->viewport_height = h - 1;
919 if (win_info->type != CMD_WIN)
920 win_info->viewport_height--;
c906108c
SS
921 }
922 else
6ba8e26f
AC
923 win_info->viewport_height = 1;
924 win_info->origin.x = origin_x;
925 win_info->origin.y = origin_y;
c906108c
SS
926
927 return;
6ba8e26f 928} /* init_gen_win_info */
c906108c 929
ef5eab5a 930/* init_and_make_win().
c5aa993b 931 */
d5d6fca5 932static void *
08ef48c5
MS
933init_and_make_win (void *opaque_win_info,
934 enum tui_win_type win_type,
935 int height, int width,
936 int origin_x, int origin_y,
d5d6fca5 937 int box_it)
c906108c 938{
5b6fe301 939 struct tui_gen_win_info *generic;
c906108c 940
6ba8e26f 941 if (opaque_win_info == NULL)
c906108c 942 {
6ba8e26f
AC
943 if (tui_win_is_auxillary (win_type))
944 opaque_win_info = (void *) tui_alloc_generic_win_info ();
c906108c 945 else
6ba8e26f 946 opaque_win_info = (void *) tui_alloc_win_info (win_type);
c906108c 947 }
6ba8e26f
AC
948 if (tui_win_is_auxillary (win_type))
949 generic = (struct tui_gen_win_info *) opaque_win_info;
c906108c 950 else
6ba8e26f 951 generic = &((struct tui_win_info *) opaque_win_info)->generic;
c906108c 952
6ba8e26f 953 if (opaque_win_info != NULL)
c906108c 954 {
6ba8e26f
AC
955 init_gen_win_info (generic, win_type, height, width, origin_x, origin_y);
956 if (!tui_win_is_auxillary (win_type))
c906108c
SS
957 {
958 if (generic->type == CMD_WIN)
6ba8e26f 959 ((struct tui_win_info *) opaque_win_info)->can_highlight = FALSE;
c906108c 960 else
6ba8e26f 961 ((struct tui_win_info *) opaque_win_info)->can_highlight = TRUE;
c906108c 962 }
6ba8e26f 963 tui_make_window (generic, box_it);
c906108c 964 }
d5d6fca5 965 return opaque_win_info;
bc712bbf 966}
c906108c
SS
967
968
c906108c 969static void
08ef48c5
MS
970make_source_or_disasm_window (struct tui_win_info **win_info_ptr,
971 enum tui_win_type type,
972 int height, int origin_y)
c906108c 973{
5b6fe301 974 struct tui_gen_win_info *execution_info = (struct tui_gen_win_info *) NULL;
c906108c 975
ef5eab5a 976 /* Create the exeuction info window. */
c906108c 977 if (type == SRC_WIN)
6d012f14 978 execution_info = tui_source_exec_info_win_ptr ();
c906108c 979 else
6d012f14 980 execution_info = tui_disassem_exec_info_win_ptr ();
d5d6fca5
DJ
981 execution_info = init_and_make_win (execution_info,
982 EXEC_INFO_WIN,
983 height,
984 3,
985 0,
986 origin_y,
987 DONT_BOX_WINDOW);
ef5eab5a
MS
988
989 /* Now create the source window. */
d5d6fca5
DJ
990 *win_info_ptr = init_and_make_win (*win_info_ptr,
991 type,
992 height,
993 tui_term_width () - execution_info->width,
994 execution_info->width,
995 origin_y,
996 BOX_WINDOW);
c906108c 997
6ba8e26f
AC
998 (*win_info_ptr)->detail.source_info.execution_info = execution_info;
999}
c906108c
SS
1000
1001
1cc6d956 1002/* Show the Source/Command or the Disassem layout. */
c906108c 1003static void
6ba8e26f 1004show_source_or_disasm_and_command (enum tui_layout_type layout_type)
c906108c 1005{
6ba8e26f 1006 if (tui_current_layout () != layout_type)
c906108c 1007 {
5b6fe301 1008 struct tui_win_info **win_info_ptr;
6ba8e26f 1009 int src_height, cmd_height;
5b6fe301 1010 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
c906108c 1011
6d012f14 1012 if (TUI_CMD_WIN != NULL)
6ba8e26f 1013 cmd_height = TUI_CMD_WIN->generic.height;
c906108c 1014 else
6ba8e26f
AC
1015 cmd_height = tui_term_height () / 3;
1016 src_height = tui_term_height () - cmd_height;
c906108c 1017
6ba8e26f
AC
1018 if (layout_type == SRC_COMMAND)
1019 win_info_ptr = &TUI_SRC_WIN;
c906108c 1020 else
6ba8e26f 1021 win_info_ptr = &TUI_DISASM_WIN;
c906108c 1022
6ba8e26f 1023 if ((*win_info_ptr) == NULL)
c906108c 1024 {
6ba8e26f
AC
1025 if (layout_type == SRC_COMMAND)
1026 make_source_window (win_info_ptr, src_height - 1, 0);
c906108c 1027 else
6ba8e26f 1028 make_disasm_window (win_info_ptr, src_height - 1, 0);
d5d6fca5
DJ
1029 locator = init_and_make_win (locator,
1030 LOCATOR_WIN,
1031 2 /* 1 */ ,
1032 tui_term_width (),
1033 0,
1034 src_height - 1,
1035 DONT_BOX_WINDOW);
c906108c
SS
1036 }
1037 else
1038 {
6ba8e26f 1039 init_gen_win_info (locator,
08ef48c5
MS
1040 LOCATOR_WIN,
1041 2 /* 1 */ ,
1042 tui_term_width (),
1043 0,
1044 src_height - 1);
6ba8e26f 1045 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
08ef48c5
MS
1046 init_gen_win_info (&(*win_info_ptr)->generic,
1047 (*win_info_ptr)->generic.type,
1048 src_height - 1,
1049 (*win_info_ptr)->generic.width,
1050 (*win_info_ptr)->detail.source_info.execution_info->width,
1051 0);
6ba8e26f 1052 init_gen_win_info ((*win_info_ptr)->detail.source_info.execution_info,
08ef48c5
MS
1053 EXEC_INFO_WIN,
1054 src_height - 1,
1055 3,
1056 0,
1057 0);
6ba8e26f
AC
1058 (*win_info_ptr)->can_highlight = TRUE;
1059 tui_make_visible (&(*win_info_ptr)->generic);
1060 tui_make_visible ((*win_info_ptr)->detail.source_info.execution_info);
c906108c 1061 }
6ba8e26f 1062 if ((*win_info_ptr) != NULL)
c906108c 1063 {
6ba8e26f 1064 (*win_info_ptr)->detail.source_info.has_locator = TRUE;
ec7d9e56 1065 tui_make_visible (locator);
47d3492a 1066 tui_show_locator_content ();
6ba8e26f 1067 tui_show_source_content (*win_info_ptr);
c906108c 1068
6d012f14 1069 if (TUI_CMD_WIN == NULL)
c906108c 1070 {
6ba8e26f 1071 make_command_window (&TUI_CMD_WIN, cmd_height, src_height);
6d012f14 1072 tui_refresh_win (&TUI_CMD_WIN->generic);
c906108c
SS
1073 }
1074 else
1075 {
6ba8e26f 1076 init_gen_win_info (&TUI_CMD_WIN->generic,
08ef48c5
MS
1077 TUI_CMD_WIN->generic.type,
1078 TUI_CMD_WIN->generic.height,
1079 TUI_CMD_WIN->generic.width,
1080 TUI_CMD_WIN->generic.origin.x,
1081 TUI_CMD_WIN->generic.origin.y);
6d012f14
AC
1082 TUI_CMD_WIN->can_highlight = FALSE;
1083 tui_make_visible (&TUI_CMD_WIN->generic);
c906108c
SS
1084 }
1085 }
6ba8e26f 1086 tui_set_current_layout_to (layout_type);
c906108c 1087 }
6ba8e26f 1088}
This page took 1.016017 seconds and 4 git commands to generate.