1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "tui/tui-data.h"
26 #include "tui/tui-wingeneral.h"
27 #include "gdb_curses.h"
29 /****************************
30 ** GLOBAL DECLARATIONS
31 ****************************/
32 struct tui_win_info
*tui_win_list
[MAX_MAJOR_WINDOWS
];
34 /***************************
36 ****************************/
37 static enum tui_layout_type current_layout
= UNDEFINED_LAYOUT
;
38 static int term_height
, term_width
;
39 static struct tui_gen_win_info _locator
;
40 static struct tui_gen_win_info exec_info
[2];
41 static std::vector
<tui_win_info
*> source_windows
;
42 static struct tui_win_info
*win_with_focus
= NULL
;
43 static struct tui_layout_def layout_def
= {
44 SRC_WIN
, /* DISPLAY_MODE */
47 static int win_resized
= FALSE
;
50 /*********************************
51 ** Static function forward decls
52 **********************************/
53 static void free_content (tui_win_content
,
56 static void free_content_elements (tui_win_content
,
62 /*********************************
64 **********************************/
67 tui_win_is_source_type (enum tui_win_type win_type
)
69 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
73 tui_win_is_auxillary (enum tui_win_type win_type
)
75 return (win_type
> MAX_MAJOR_WINDOWS
);
79 tui_set_win_highlight (struct tui_win_info
*win_info
,
83 win_info
->is_highlighted
= highlight
;
86 /******************************************
87 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
88 ******************************************/
90 /* Answer a whether the terminal window has been resized or not. */
92 tui_win_resized (void)
98 /* Set a whether the terminal window has been resized or not. */
100 tui_set_win_resized_to (int resized
)
102 win_resized
= resized
;
106 /* Answer a pointer to the current layout definition. */
107 struct tui_layout_def
*
108 tui_layout_def (void)
114 /* Answer the window with the logical focus. */
115 struct tui_win_info
*
116 tui_win_with_focus (void)
118 return win_with_focus
;
122 /* Set the window that has the logical focus. */
124 tui_set_win_with_focus (struct tui_win_info
*win_info
)
126 win_with_focus
= win_info
;
130 /* Accessor for the current source window. Usually there is only one
131 source window (either source or disassembly), but both can be
132 displayed at the same time. */
133 std::vector
<tui_win_info
*> &
134 tui_source_windows ()
136 return source_windows
;
140 /* Clear the list of source windows. Usually there is only one source
141 window (either source or disassembly), but both can be displayed at
144 tui_clear_source_windows ()
146 source_windows
.clear ();
150 /* Clear the pertinant detail in the source windows. */
152 tui_clear_source_windows_detail ()
154 for (tui_win_info
*win
: tui_source_windows ())
155 win
->clear_detail ();
159 /* Add a window to the list of source windows. Usually there is only
160 one source window (either source or disassembly), but both can be
161 displayed at the same time. */
163 tui_add_to_source_windows (struct tui_win_info
*win_info
)
165 if (source_windows
.size () < 2)
166 source_windows
.push_back (win_info
);
169 /* See tui-data.h. */
172 tui_source_window_base::clear_detail ()
175 start_line_or_addr
.loa
= LOA_ADDRESS
;
176 start_line_or_addr
.u
.addr
= 0;
177 horizontal_offset
= 0;
180 /* See tui-data.h. */
183 tui_cmd_window::clear_detail ()
185 wmove (generic
.handle
, 0, 0);
188 /* See tui-data.h. */
191 tui_data_window::clear_detail ()
194 data_content_count
= 0;
196 regs_content_count
= 0;
197 regs_column_count
= 1;
198 display_regs
= false;
201 /* Accessor for the source execution info ptr. */
202 struct tui_gen_win_info
*
203 tui_source_exec_info_win_ptr (void)
205 return &exec_info
[0];
209 /* Accessor for the disassem execution info ptr. */
210 struct tui_gen_win_info
*
211 tui_disassem_exec_info_win_ptr (void)
213 return &exec_info
[1];
217 /* Accessor for the locator win info. Answers a pointer to the static
218 locator win info struct. */
219 struct tui_gen_win_info
*
220 tui_locator_win_info_ptr (void)
226 /* Accessor for the term_height. */
228 tui_term_height (void)
234 /* Mutator for the term height. */
236 tui_set_term_height_to (int h
)
242 /* Accessor for the term_width. */
244 tui_term_width (void)
250 /* Mutator for the term_width. */
252 tui_set_term_width_to (int w
)
258 /* Accessor for the current layout. */
260 tui_current_layout (void)
262 return current_layout
;
266 /* Mutator for the current layout. */
268 tui_set_current_layout_to (enum tui_layout_type new_layout
)
270 current_layout
= new_layout
;
274 /*****************************
275 ** OTHER PUBLIC FUNCTIONS
276 *****************************/
279 /* Answer the next window in the list, cycling back to the top if
281 struct tui_win_info
*
282 tui_next_win (struct tui_win_info
*cur_win
)
284 int type
= cur_win
->generic
.type
;
285 struct tui_win_info
*next_win
= NULL
;
287 if (cur_win
->generic
.type
== CMD_WIN
)
290 type
= cur_win
->generic
.type
+ 1;
291 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
293 if (tui_win_list
[type
]
294 && tui_win_list
[type
]->generic
.is_visible
)
295 next_win
= tui_win_list
[type
];
309 /* Answer the prev window in the list, cycling back to the bottom if
311 struct tui_win_info
*
312 tui_prev_win (struct tui_win_info
*cur_win
)
314 int type
= cur_win
->generic
.type
;
315 struct tui_win_info
*prev
= NULL
;
317 if (cur_win
->generic
.type
== SRC_WIN
)
320 type
= cur_win
->generic
.type
- 1;
321 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
323 if (tui_win_list
[type
]
324 && tui_win_list
[type
]->generic
.is_visible
)
325 prev
= tui_win_list
[type
];
339 /* Answer the window represented by name. */
340 struct tui_win_info
*
341 tui_partial_win_by_name (const char *name
)
343 struct tui_win_info
*win_info
= NULL
;
349 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
351 if (tui_win_list
[i
] != 0)
353 const char *cur_name
=
354 tui_win_name (&tui_win_list
[i
]->generic
);
356 if (strlen (name
) <= strlen (cur_name
)
357 && startswith (cur_name
, name
))
358 win_info
= tui_win_list
[i
];
368 /* Answer the name of the window. */
370 tui_win_name (const struct tui_gen_win_info
*win_info
)
372 const char *name
= NULL
;
374 switch (win_info
->type
)
383 name
= DISASSEM_NAME
;
398 tui_initialize_static_data (void)
400 tui_init_generic_part (tui_source_exec_info_win_ptr ());
401 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
402 tui_init_generic_part (tui_locator_win_info_ptr ());
406 struct tui_gen_win_info
*
407 tui_alloc_generic_win_info (void)
409 struct tui_gen_win_info
*win
= XNEW (struct tui_gen_win_info
);
411 tui_init_generic_part (win
);
418 tui_init_generic_part (struct tui_gen_win_info
*win
)
424 win
->viewport_height
=
426 win
->last_visible_line
= 0;
429 win
->content_in_use
=
430 win
->is_visible
= FALSE
;
435 /* init_content_element().
438 init_content_element (struct tui_win_element
*element
,
439 enum tui_win_type type
)
445 element
->which_element
.source
.line
= NULL
;
446 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
447 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
448 element
->which_element
.source
.is_exec_point
= FALSE
;
449 element
->which_element
.source
.has_break
= FALSE
;
452 tui_init_generic_part (&element
->which_element
.data_window
);
453 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
454 element
->which_element
.data_window
.content
=
455 tui_alloc_content (1, DATA_ITEM_WIN
);
456 element
->which_element
.data_window
.content_size
= 1;
459 element
->which_element
.command
.line
= NULL
;
462 element
->which_element
.data
.name
= NULL
;
463 element
->which_element
.data
.type
= TUI_REGISTER
;
464 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
465 element
->which_element
.data
.value
= NULL
;
466 element
->which_element
.data
.highlight
= FALSE
;
467 element
->which_element
.data
.content
= NULL
;
470 element
->which_element
.locator
.full_name
[0] =
471 element
->which_element
.locator
.proc_name
[0] = (char) 0;
472 element
->which_element
.locator
.line_no
= 0;
473 element
->which_element
.locator
.addr
= 0;
476 memset(element
->which_element
.simple_string
, ' ',
477 sizeof(element
->which_element
.simple_string
));
484 tui_win_info::tui_win_info (enum tui_win_type type
)
487 tui_init_generic_part (&generic
);
490 tui_source_window_base::tui_source_window_base (enum tui_win_type type
)
491 : tui_win_info (type
)
493 gdb_assert (type
== SRC_WIN
|| type
== DISASSEM_WIN
);
494 start_line_or_addr
.loa
= LOA_ADDRESS
;
495 start_line_or_addr
.u
.addr
= 0;
498 struct tui_win_info
*
499 tui_alloc_win_info (enum tui_win_type type
)
504 return new tui_source_window ();
507 return new tui_disasm_window ();
510 return new tui_data_window ();
513 return new tui_cmd_window ();
516 gdb_assert_not_reached (_("Unhandled window type"));
520 /* Allocates the content and elements in a block. */
522 tui_alloc_content (int num_elements
, enum tui_win_type type
)
524 tui_win_content content
;
525 struct tui_win_element
*element_block_ptr
;
528 content
= XNEWVEC (struct tui_win_element
*, num_elements
);
531 * All windows, except the data window, can allocate the
532 * elements in a chunk. The data window cannot because items
533 * can be added/removed from the data display by the user at any
536 if (type
!= DATA_WIN
)
538 element_block_ptr
= XNEWVEC (struct tui_win_element
, num_elements
);
539 for (i
= 0; i
< num_elements
; i
++)
541 content
[i
] = element_block_ptr
;
542 init_content_element (content
[i
], type
);
551 /* Adds the input number of elements to the windows's content. If no
552 content has been allocated yet, alloc_content() is called to do
553 this. The index of the first element added is returned, unless
554 there is a memory allocation error, in which case, (-1) is
557 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
560 struct tui_win_element
*element_ptr
;
563 if (win_info
->content
== NULL
)
565 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
569 index_start
= win_info
->content_size
;
570 if (win_info
->content
!= NULL
)
572 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
574 element_ptr
= XNEW (struct tui_win_element
);
575 win_info
->content
[i
] = element_ptr
;
576 init_content_element (element_ptr
, win_info
->type
);
577 win_info
->content_size
++;
584 tui_source_window_base::~tui_source_window_base ()
587 struct tui_gen_win_info
*generic_win
= execution_info
;
588 if (generic_win
!= NULL
)
590 tui_delete_win (generic_win
->handle
);
591 generic_win
->handle
= NULL
;
592 tui_free_win_content (generic_win
);
596 tui_data_window::~tui_data_window ()
598 if (generic
.content
!= NULL
)
600 tui_free_data_content (regs_content
, regs_content_count
);
602 regs_content_count
= 0;
603 tui_free_data_content (data_content
, data_content_count
);
605 data_content_count
= 0;
606 regs_column_count
= 1;
607 display_regs
= false;
608 generic
.content
= NULL
;
609 generic
.content_size
= 0;
613 tui_win_info::~tui_win_info ()
615 if (generic
.handle
!= NULL
)
617 tui_delete_win (generic
.handle
);
618 generic
.handle
= NULL
;
619 tui_free_win_content (&generic
);
622 xfree (generic
.title
);
627 tui_free_all_source_wins_content ()
629 for (tui_win_info
*win_info
: tui_source_windows ())
631 tui_free_win_content (&(win_info
->generic
));
632 tui_source_window_base
*base
= (tui_source_window_base
*) win_info
;
633 tui_free_win_content (base
->execution_info
);
639 tui_free_win_content (struct tui_gen_win_info
*win_info
)
641 if (win_info
->content
!= NULL
)
643 free_content (win_info
->content
,
644 win_info
->content_size
,
646 win_info
->content
= NULL
;
648 win_info
->content_size
= 0;
653 tui_free_data_content (tui_win_content content
,
658 /* Remember that data window content elements are of type struct
659 tui_gen_win_info *, each of which whose single element is a data
661 for (i
= 0; i
< content_size
; i
++)
663 struct tui_gen_win_info
*generic_win
664 = &content
[i
]->which_element
.data_window
;
666 if (generic_win
!= NULL
)
668 tui_delete_win (generic_win
->handle
);
669 generic_win
->handle
= NULL
;
670 tui_free_win_content (generic_win
);
673 free_content (content
,
679 /**********************************
680 ** LOCAL STATIC FUNCTIONS **
681 **********************************/
685 free_content (tui_win_content content
,
687 enum tui_win_type win_type
)
691 free_content_elements (content
, content_size
, win_type
);
697 /* free_content_elements().
700 free_content_elements (tui_win_content content
,
702 enum tui_win_type type
)
708 if (type
== DISASSEM_WIN
)
710 /* Free whole source block. */
711 xfree (content
[0]->which_element
.source
.line
);
715 for (i
= 0; i
< content_size
; i
++)
717 struct tui_win_element
*element
;
719 element
= content
[i
];
725 xfree (element
->which_element
.source
.line
);
731 /* Note that data elements are not allocated in
732 a single block, but individually, as
734 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
735 xfree ((void *)element
->which_element
.data
.name
);
736 xfree (element
->which_element
.data
.value
);
737 xfree (element
->which_element
.data
.content
);
741 xfree (element
->which_element
.command
.line
);
749 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
750 xfree (content
[0]); /* Free the element block. */