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