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