1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2018 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 struct tui_win_info *src_win_list[2];
42 static struct tui_list source_windows = {src_win_list, 0};
43 static struct tui_win_info *win_with_focus = NULL;
44 static struct tui_layout_def layout_def = {
45 SRC_WIN, /* DISPLAY_MODE */
48 static int win_resized = FALSE;
51 /*********************************
52 ** Static function forward decls
53 **********************************/
54 static void free_content (tui_win_content,
57 static void free_content_elements (tui_win_content,
63 /*********************************
65 **********************************/
68 tui_win_is_source_type (enum tui_win_type win_type)
70 return (win_type == SRC_WIN || win_type == DISASSEM_WIN);
74 tui_win_is_auxillary (enum tui_win_type win_type)
76 return (win_type > MAX_MAJOR_WINDOWS);
80 tui_win_has_locator (struct tui_win_info *win_info)
82 return (win_info != NULL
83 && win_info->detail.source_info.has_locator);
87 tui_set_win_highlight (struct tui_win_info *win_info,
91 win_info->is_highlighted = highlight;
94 /******************************************
95 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
96 ******************************************/
98 /* Answer a whether the terminal window has been resized or not. */
100 tui_win_resized (void)
106 /* Set a whether the terminal window has been resized or not. */
108 tui_set_win_resized_to (int resized)
110 win_resized = resized;
114 /* Answer a pointer to the current layout definition. */
115 struct tui_layout_def *
116 tui_layout_def (void)
122 /* Answer the window with the logical focus. */
123 struct tui_win_info *
124 tui_win_with_focus (void)
126 return win_with_focus;
130 /* Set the window that has the logical focus. */
132 tui_set_win_with_focus (struct tui_win_info *win_info)
134 win_with_focus = win_info;
138 /* Accessor for the current source window. Usually there is only one
139 source window (either source or disassembly), but both can be
140 displayed at the same time. */
142 tui_source_windows (void)
144 return &source_windows;
148 /* Clear the list of source windows. Usually there is only one source
149 window (either source or disassembly), but both can be displayed at
152 tui_clear_source_windows (void)
154 source_windows.list[0] = NULL;
155 source_windows.list[1] = NULL;
156 source_windows.count = 0;
160 /* Clear the pertinant detail in the source windows. */
162 tui_clear_source_windows_detail (void)
166 for (i = 0; i < (tui_source_windows ())->count; i++)
167 tui_clear_win_detail ((tui_source_windows ())->list[i]);
171 /* Add a window to the list of source windows. Usually there is only
172 one source window (either source or disassembly), but both can be
173 displayed at the same time. */
175 tui_add_to_source_windows (struct tui_win_info *win_info)
177 if (source_windows.count < 2)
178 source_windows.list[source_windows.count++] = win_info;
182 /* Clear the pertinant detail in the windows. */
184 tui_clear_win_detail (struct tui_win_info *win_info)
186 if (win_info != NULL)
188 switch (win_info->generic.type)
192 win_info->detail.source_info.gdbarch = NULL;
193 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
194 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
195 win_info->detail.source_info.horizontal_offset = 0;
198 wmove (win_info->generic.handle, 0, 0);
201 win_info->detail.data_display_info.data_content =
202 (tui_win_content) NULL;
203 win_info->detail.data_display_info.data_content_count = 0;
204 win_info->detail.data_display_info.regs_content =
205 (tui_win_content) NULL;
206 win_info->detail.data_display_info.regs_content_count = 0;
207 win_info->detail.data_display_info.regs_column_count = 1;
208 win_info->detail.data_display_info.display_regs = FALSE;
217 /* Accessor for the source execution info ptr. */
218 struct tui_gen_win_info *
219 tui_source_exec_info_win_ptr (void)
221 return &exec_info[0];
225 /* Accessor for the disassem execution info ptr. */
226 struct tui_gen_win_info *
227 tui_disassem_exec_info_win_ptr (void)
229 return &exec_info[1];
233 /* Accessor for the locator win info. Answers a pointer to the static
234 locator win info struct. */
235 struct tui_gen_win_info *
236 tui_locator_win_info_ptr (void)
242 /* Accessor for the term_height. */
244 tui_term_height (void)
250 /* Mutator for the term height. */
252 tui_set_term_height_to (int h)
258 /* Accessor for the term_width. */
260 tui_term_width (void)
266 /* Mutator for the term_width. */
268 tui_set_term_width_to (int w)
274 /* Accessor for the current layout. */
276 tui_current_layout (void)
278 return current_layout;
282 /* Mutator for the current layout. */
284 tui_set_current_layout_to (enum tui_layout_type new_layout)
286 current_layout = new_layout;
290 /*****************************
291 ** OTHER PUBLIC FUNCTIONS
292 *****************************/
295 /* Answer the next window in the list, cycling back to the top if
297 struct tui_win_info *
298 tui_next_win (struct tui_win_info *cur_win)
300 int type = cur_win->generic.type;
301 struct tui_win_info *next_win = NULL;
303 if (cur_win->generic.type == CMD_WIN)
306 type = cur_win->generic.type + 1;
307 while (type != cur_win->generic.type && (next_win == NULL))
309 if (tui_win_list[type]
310 && tui_win_list[type]->generic.is_visible)
311 next_win = tui_win_list[type];
325 /* Answer the prev window in the list, cycling back to the bottom if
327 struct tui_win_info *
328 tui_prev_win (struct tui_win_info *cur_win)
330 int type = cur_win->generic.type;
331 struct tui_win_info *prev = NULL;
333 if (cur_win->generic.type == SRC_WIN)
336 type = cur_win->generic.type - 1;
337 while (type != cur_win->generic.type && (prev == NULL))
339 if (tui_win_list[type]
340 && tui_win_list[type]->generic.is_visible)
341 prev = tui_win_list[type];
355 /* Answer the window represented by name. */
356 struct tui_win_info *
357 tui_partial_win_by_name (const char *name)
359 struct tui_win_info *win_info = NULL;
365 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
367 if (tui_win_list[i] != 0)
369 const char *cur_name =
370 tui_win_name (&tui_win_list[i]->generic);
372 if (strlen (name) <= strlen (cur_name)
373 && startswith (cur_name, name))
374 win_info = tui_win_list[i];
384 /* Answer the name of the window. */
386 tui_win_name (const struct tui_gen_win_info *win_info)
388 const char *name = NULL;
390 switch (win_info->type)
399 name = DISASSEM_NAME;
414 tui_initialize_static_data (void)
416 tui_init_generic_part (tui_source_exec_info_win_ptr ());
417 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
418 tui_init_generic_part (tui_locator_win_info_ptr ());
422 struct tui_gen_win_info *
423 tui_alloc_generic_win_info (void)
425 struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info);
428 tui_init_generic_part (win);
435 tui_init_generic_part (struct tui_gen_win_info *win)
441 win->viewport_height =
443 win->last_visible_line = 0;
446 win->content_in_use =
447 win->is_visible = FALSE;
452 /* init_content_element().
455 init_content_element (struct tui_win_element *element,
456 enum tui_win_type type)
462 element->which_element.source.line = NULL;
463 element->which_element.source.line_or_addr.loa = LOA_LINE;
464 element->which_element.source.line_or_addr.u.line_no = 0;
465 element->which_element.source.is_exec_point = FALSE;
466 element->which_element.source.has_break = FALSE;
469 tui_init_generic_part (&element->which_element.data_window);
470 element->which_element.data_window.type = DATA_ITEM_WIN;
471 element->which_element.data_window.content =
472 tui_alloc_content (1, DATA_ITEM_WIN);
473 element->which_element.data_window.content_size = 1;
476 element->which_element.command.line = NULL;
479 element->which_element.data.name = NULL;
480 element->which_element.data.type = TUI_REGISTER;
481 element->which_element.data.item_no = UNDEFINED_ITEM;
482 element->which_element.data.value = NULL;
483 element->which_element.data.highlight = FALSE;
484 element->which_element.data.content = NULL;
487 element->which_element.locator.full_name[0] =
488 element->which_element.locator.proc_name[0] = (char) 0;
489 element->which_element.locator.line_no = 0;
490 element->which_element.locator.addr = 0;
493 memset(element->which_element.simple_string, ' ',
494 sizeof(element->which_element.simple_string));
502 init_win_info (struct tui_win_info *win_info)
504 tui_init_generic_part (&win_info->generic);
505 win_info->can_highlight =
506 win_info->is_highlighted = FALSE;
507 switch (win_info->generic.type)
511 win_info->detail.source_info.execution_info
512 = (struct tui_gen_win_info *) NULL;
513 win_info->detail.source_info.has_locator = FALSE;
514 win_info->detail.source_info.horizontal_offset = 0;
515 win_info->detail.source_info.gdbarch = NULL;
516 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
517 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
518 win_info->detail.source_info.fullname = NULL;
521 win_info->detail.data_display_info.data_content = (tui_win_content) NULL;
522 win_info->detail.data_display_info.data_content_count = 0;
523 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL;
524 win_info->detail.data_display_info.regs_content_count = 0;
525 win_info->detail.data_display_info.regs_column_count = 1;
526 win_info->detail.data_display_info.display_regs = FALSE;
527 win_info->detail.data_display_info.current_group = 0;
535 struct tui_win_info *
536 tui_alloc_win_info (enum tui_win_type type)
538 struct tui_win_info *win_info = XNEW (struct tui_win_info);
540 if (win_info != NULL)
542 win_info->generic.type = type;
543 init_win_info (win_info);
550 /* Allocates the content and elements in a block. */
552 tui_alloc_content (int num_elements, enum tui_win_type type)
554 tui_win_content content;
555 struct tui_win_element *element_block_ptr;
558 content = XNEWVEC (struct tui_win_element *, num_elements);
561 * All windows, except the data window, can allocate the
562 * elements in a chunk. The data window cannot because items
563 * can be added/removed from the data display by the user at any
566 if (type != DATA_WIN)
568 element_block_ptr = XNEWVEC (struct tui_win_element, num_elements);
569 for (i = 0; i < num_elements; i++)
571 content[i] = element_block_ptr;
572 init_content_element (content[i], type);
581 /* Adds the input number of elements to the windows's content. If no
582 content has been allocated yet, alloc_content() is called to do
583 this. The index of the first element added is returned, unless
584 there is a memory allocation error, in which case, (-1) is
587 tui_add_content_elements (struct tui_gen_win_info *win_info,
590 struct tui_win_element *element_ptr;
593 if (win_info->content == NULL)
595 win_info->content = tui_alloc_content (num_elements, win_info->type);
599 index_start = win_info->content_size;
600 if (win_info->content != NULL)
602 for (i = index_start; (i < num_elements + index_start); i++)
604 element_ptr = XNEW (struct tui_win_element);
605 if (element_ptr != NULL)
607 win_info->content[i] = element_ptr;
608 init_content_element (element_ptr, win_info->type);
609 win_info->content_size++;
611 else /* Things must be really hosed now! We ran out of
621 /* Delete all curses windows associated with win_info, leaving
622 everything else intact. */
624 tui_del_window (struct tui_win_info *win_info)
626 struct tui_gen_win_info *generic_win;
628 switch (win_info->generic.type)
632 generic_win = tui_locator_win_info_ptr ();
633 if (generic_win != (struct tui_gen_win_info *) NULL)
635 tui_delete_win (generic_win->handle);
636 generic_win->handle = NULL;
637 generic_win->is_visible = FALSE;
639 if (win_info->detail.source_info.fullname)
641 xfree (win_info->detail.source_info.fullname);
642 win_info->detail.source_info.fullname = NULL;
644 generic_win = win_info->detail.source_info.execution_info;
645 if (generic_win != (struct tui_gen_win_info *) NULL)
647 tui_delete_win (generic_win->handle);
648 generic_win->handle = NULL;
649 generic_win->is_visible = FALSE;
653 if (win_info->generic.content != NULL)
655 tui_del_data_windows (win_info->detail.data_display_info.regs_content,
656 win_info->detail.data_display_info.regs_content_count);
657 tui_del_data_windows (win_info->detail.data_display_info.data_content,
658 win_info->detail.data_display_info.data_content_count);
664 if (win_info->generic.handle != (WINDOW *) NULL)
666 tui_delete_win (win_info->generic.handle);
667 win_info->generic.handle = NULL;
668 win_info->generic.is_visible = FALSE;
674 tui_free_window (struct tui_win_info *win_info)
676 struct tui_gen_win_info *generic_win;
678 switch (win_info->generic.type)
682 if (win_info->detail.source_info.fullname)
684 xfree (win_info->detail.source_info.fullname);
685 win_info->detail.source_info.fullname = NULL;
687 generic_win = win_info->detail.source_info.execution_info;
688 if (generic_win != (struct tui_gen_win_info *) NULL)
690 tui_delete_win (generic_win->handle);
691 generic_win->handle = NULL;
692 tui_free_win_content (generic_win);
696 if (win_info->generic.content != NULL)
698 tui_free_data_content (win_info->detail.data_display_info.regs_content,
699 win_info->detail.data_display_info.regs_content_count);
700 win_info->detail.data_display_info.regs_content =
701 (tui_win_content) NULL;
702 win_info->detail.data_display_info.regs_content_count = 0;
703 tui_free_data_content (win_info->detail.data_display_info.data_content,
704 win_info->detail.data_display_info.data_content_count);
705 win_info->detail.data_display_info.data_content =
706 (tui_win_content) NULL;
707 win_info->detail.data_display_info.data_content_count = 0;
708 win_info->detail.data_display_info.regs_column_count = 1;
709 win_info->detail.data_display_info.display_regs = FALSE;
710 win_info->generic.content = NULL;
711 win_info->generic.content_size = 0;
717 if (win_info->generic.handle != (WINDOW *) NULL)
719 tui_delete_win (win_info->generic.handle);
720 win_info->generic.handle = NULL;
721 tui_free_win_content (&win_info->generic);
723 if (win_info->generic.title)
724 xfree (win_info->generic.title);
730 tui_free_all_source_wins_content (void)
734 for (i = 0; i < (tui_source_windows ())->count; i++)
736 struct tui_win_info *win_info = (tui_source_windows ())->list[i];
738 if (win_info != NULL)
740 tui_free_win_content (&(win_info->generic));
741 tui_free_win_content (win_info->detail.source_info.execution_info);
748 tui_free_win_content (struct tui_gen_win_info *win_info)
750 if (win_info->content != NULL)
752 free_content (win_info->content,
753 win_info->content_size,
755 win_info->content = NULL;
757 win_info->content_size = 0;
762 tui_del_data_windows (tui_win_content content,
767 /* Remember that data window content elements are of type struct
768 tui_gen_win_info *, each of which whose single element is a data
770 for (i = 0; i < content_size; i++)
772 struct tui_gen_win_info *generic_win
773 = &content[i]->which_element.data_window;
775 if (generic_win != (struct tui_gen_win_info *) NULL)
777 tui_delete_win (generic_win->handle);
778 generic_win->handle = NULL;
779 generic_win->is_visible = FALSE;
786 tui_free_data_content (tui_win_content content,
791 /* Remember that data window content elements are of type struct
792 tui_gen_win_info *, each of which whose single element is a data
794 for (i = 0; i < content_size; i++)
796 struct tui_gen_win_info *generic_win
797 = &content[i]->which_element.data_window;
799 if (generic_win != (struct tui_gen_win_info *) NULL)
801 tui_delete_win (generic_win->handle);
802 generic_win->handle = NULL;
803 tui_free_win_content (generic_win);
806 free_content (content,
812 /**********************************
813 ** LOCAL STATIC FUNCTIONS **
814 **********************************/
818 free_content (tui_win_content content,
820 enum tui_win_type win_type)
822 if (content != (tui_win_content) NULL)
824 free_content_elements (content, content_size, win_type);
830 /* free_content_elements().
833 free_content_elements (tui_win_content content,
835 enum tui_win_type type)
837 if (content != (tui_win_content) NULL)
841 if (type == SRC_WIN || type == DISASSEM_WIN)
843 /* Free whole source block. */
844 xfree (content[0]->which_element.source.line);
848 for (i = 0; i < content_size; i++)
850 struct tui_win_element *element;
852 element = content[i];
853 if (element != (struct tui_win_element *) NULL)
861 /* Note that data elements are not allocated in
862 a single block, but individually, as
864 if (element->which_element.data.type != TUI_REGISTER)
865 xfree ((void *)element->which_element.data.name);
866 xfree (element->which_element.data.value);
867 xfree (element->which_element.data.content);
871 xfree (element->which_element.command.line);
879 if (type != DATA_WIN && type != DATA_ITEM_WIN)
880 xfree (content[0]); /* Free the element block. */