1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2015 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 int default_tab_len
= DEFAULT_TAB_LEN
;
44 static struct tui_win_info
*win_with_focus
= (struct tui_win_info
*) NULL
;
45 static struct tui_layout_def layout_def
= {
46 SRC_WIN
, /* DISPLAY_MODE */
48 TUI_UNDEFINED_REGS
, /* REGS_DISPLAY_TYPE */
49 TUI_SFLOAT_REGS
}; /* FLOAT_REGS_DISPLAY_TYPE */
51 static int win_resized
= FALSE
;
54 /*********************************
55 ** Static function forward decls
56 **********************************/
57 static void free_content (tui_win_content
,
60 static void free_content_elements (tui_win_content
,
66 /*********************************
68 **********************************/
71 tui_win_is_source_type (enum tui_win_type win_type
)
73 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
77 tui_win_is_auxillary (enum tui_win_type win_type
)
79 return (win_type
> MAX_MAJOR_WINDOWS
);
83 tui_win_has_locator (struct tui_win_info
*win_info
)
85 return (win_info
!= NULL
86 && win_info
->detail
.source_info
.has_locator
);
90 tui_set_win_highlight (struct tui_win_info
*win_info
,
94 win_info
->is_highlighted
= highlight
;
97 /******************************************
98 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
99 ******************************************/
101 /* Answer a whether the terminal window has been resized or not. */
103 tui_win_resized (void)
109 /* Set a whether the terminal window has been resized or not. */
111 tui_set_win_resized_to (int resized
)
113 win_resized
= resized
;
117 /* Answer a pointer to the current layout definition. */
118 struct tui_layout_def
*
119 tui_layout_def (void)
125 /* Answer the window with the logical focus. */
126 struct tui_win_info
*
127 tui_win_with_focus (void)
129 return win_with_focus
;
133 /* Set the window that has the logical focus. */
135 tui_set_win_with_focus (struct tui_win_info
*win_info
)
137 win_with_focus
= win_info
;
141 /* Answer the length in chars, of tabs. */
143 tui_default_tab_len (void)
145 return default_tab_len
;
149 /* Set the length in chars, of tabs. */
151 tui_set_default_tab_len (int len
)
153 default_tab_len
= len
;
157 /* Accessor for the current source window. Usually there is only one
158 source window (either source or disassembly), but both can be
159 displayed at the same time. */
161 tui_source_windows (void)
163 return &source_windows
;
167 /* Clear the list of source windows. Usually there is only one source
168 window (either source or disassembly), but both can be displayed at
171 tui_clear_source_windows (void)
173 source_windows
.list
[0] = NULL
;
174 source_windows
.list
[1] = NULL
;
175 source_windows
.count
= 0;
179 /* Clear the pertinant detail in the source windows. */
181 tui_clear_source_windows_detail (void)
185 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
186 tui_clear_win_detail ((tui_source_windows ())->list
[i
]);
190 /* Add a window to the list of source windows. Usually there is only
191 one source window (either source or disassembly), but both can be
192 displayed at the same time. */
194 tui_add_to_source_windows (struct tui_win_info
*win_info
)
196 if (source_windows
.count
< 2)
197 source_windows
.list
[source_windows
.count
++] = (void *) win_info
;
201 /* Clear the pertinant detail in the windows. */
203 tui_clear_win_detail (struct tui_win_info
*win_info
)
205 if (win_info
!= NULL
)
207 switch (win_info
->generic
.type
)
211 win_info
->detail
.source_info
.gdbarch
= NULL
;
212 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
213 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
214 win_info
->detail
.source_info
.horizontal_offset
= 0;
217 win_info
->detail
.command_info
.cur_line
=
218 win_info
->detail
.command_info
.curch
= 0;
221 win_info
->detail
.data_display_info
.data_content
=
222 (tui_win_content
) NULL
;
223 win_info
->detail
.data_display_info
.data_content_count
= 0;
224 win_info
->detail
.data_display_info
.regs_content
=
225 (tui_win_content
) NULL
;
226 win_info
->detail
.data_display_info
.regs_content_count
= 0;
227 win_info
->detail
.data_display_info
.regs_display_type
=
229 win_info
->detail
.data_display_info
.regs_column_count
= 1;
230 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
239 /* Accessor for the source execution info ptr. */
240 struct tui_gen_win_info
*
241 tui_source_exec_info_win_ptr (void)
243 return &exec_info
[0];
247 /* Accessor for the disassem execution info ptr. */
248 struct tui_gen_win_info
*
249 tui_disassem_exec_info_win_ptr (void)
251 return &exec_info
[1];
255 /* Accessor for the locator win info. Answers a pointer to the static
256 locator win info struct. */
257 struct tui_gen_win_info
*
258 tui_locator_win_info_ptr (void)
264 /* Accessor for the term_height. */
266 tui_term_height (void)
272 /* Mutator for the term height. */
274 tui_set_term_height_to (int h
)
280 /* Accessor for the term_width. */
282 tui_term_width (void)
288 /* Mutator for the term_width. */
290 tui_set_term_width_to (int w
)
296 /* Accessor for the current layout. */
298 tui_current_layout (void)
300 return current_layout
;
304 /* Mutator for the current layout. */
306 tui_set_current_layout_to (enum tui_layout_type new_layout
)
308 current_layout
= new_layout
;
312 /*****************************
313 ** OTHER PUBLIC FUNCTIONS
314 *****************************/
317 /* Answer the next window in the list, cycling back to the top if
319 struct tui_win_info
*
320 tui_next_win (struct tui_win_info
*cur_win
)
322 int type
= cur_win
->generic
.type
;
323 struct tui_win_info
*next_win
= (struct tui_win_info
*) NULL
;
325 if (cur_win
->generic
.type
== CMD_WIN
)
328 type
= cur_win
->generic
.type
+ 1;
329 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
331 if (tui_win_list
[type
]
332 && tui_win_list
[type
]->generic
.is_visible
)
333 next_win
= tui_win_list
[type
];
347 /* Answer the prev window in the list, cycling back to the bottom if
349 struct tui_win_info
*
350 tui_prev_win (struct tui_win_info
*cur_win
)
352 int type
= cur_win
->generic
.type
;
353 struct tui_win_info
*prev
= (struct tui_win_info
*) NULL
;
355 if (cur_win
->generic
.type
== SRC_WIN
)
358 type
= cur_win
->generic
.type
- 1;
359 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
361 if (tui_win_list
[type
]
362 && tui_win_list
[type
]->generic
.is_visible
)
363 prev
= tui_win_list
[type
];
377 /* Answer the window represented by name. */
378 struct tui_win_info
*
379 tui_partial_win_by_name (char *name
)
381 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
383 if (name
!= (char *) NULL
)
387 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
389 if (tui_win_list
[i
] != 0)
391 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
393 if (strlen (name
) <= strlen (cur_name
)
394 && startswith (cur_name
, name
))
395 win_info
= tui_win_list
[i
];
405 /* Answer the name of the window. */
407 tui_win_name (struct tui_gen_win_info
*win_info
)
409 char *name
= (char *) NULL
;
411 switch (win_info
->type
)
420 name
= DISASSEM_NAME
;
435 tui_initialize_static_data (void)
437 tui_init_generic_part (tui_source_exec_info_win_ptr ());
438 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
439 tui_init_generic_part (tui_locator_win_info_ptr ());
443 struct tui_gen_win_info
*
444 tui_alloc_generic_win_info (void)
446 struct tui_gen_win_info
*win
;
448 if ((win
= XNEW (struct tui_gen_win_info
)) != NULL
)
449 tui_init_generic_part (win
);
456 tui_init_generic_part (struct tui_gen_win_info
*win
)
462 win
->viewport_height
=
464 win
->last_visible_line
= 0;
465 win
->handle
= (WINDOW
*) NULL
;
467 win
->content_in_use
=
468 win
->is_visible
= FALSE
;
473 /* init_content_element().
476 init_content_element (struct tui_win_element
*element
,
477 enum tui_win_type type
)
479 element
->highlight
= FALSE
;
484 element
->which_element
.source
.line
= (char *) NULL
;
485 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
486 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
487 element
->which_element
.source
.is_exec_point
= FALSE
;
488 element
->which_element
.source
.has_break
= FALSE
;
491 tui_init_generic_part (&element
->which_element
.data_window
);
492 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
493 element
->which_element
.data_window
.content
=
494 tui_alloc_content (1, DATA_ITEM_WIN
);
495 element
->which_element
.data_window
.content_size
= 1;
498 element
->which_element
.command
.line
= (char *) NULL
;
501 element
->which_element
.data
.name
= (char *) NULL
;
502 element
->which_element
.data
.type
= TUI_REGISTER
;
503 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
504 element
->which_element
.data
.value
= NULL
;
505 element
->which_element
.data
.highlight
= FALSE
;
506 element
->which_element
.data
.content
= (char*) NULL
;
509 element
->which_element
.locator
.full_name
[0] =
510 element
->which_element
.locator
.proc_name
[0] = (char) 0;
511 element
->which_element
.locator
.line_no
= 0;
512 element
->which_element
.locator
.addr
= 0;
515 memset(element
->which_element
.simple_string
, ' ',
516 sizeof(element
->which_element
.simple_string
));
524 init_win_info (struct tui_win_info
*win_info
)
526 tui_init_generic_part (&win_info
->generic
);
527 win_info
->can_highlight
=
528 win_info
->is_highlighted
= FALSE
;
529 switch (win_info
->generic
.type
)
533 win_info
->detail
.source_info
.execution_info
534 = (struct tui_gen_win_info
*) NULL
;
535 win_info
->detail
.source_info
.has_locator
= FALSE
;
536 win_info
->detail
.source_info
.horizontal_offset
= 0;
537 win_info
->detail
.source_info
.gdbarch
= NULL
;
538 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
539 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
540 win_info
->detail
.source_info
.fullname
= NULL
;
543 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
544 win_info
->detail
.data_display_info
.data_content_count
= 0;
545 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
546 win_info
->detail
.data_display_info
.regs_content_count
= 0;
547 win_info
->detail
.data_display_info
.regs_display_type
=
549 win_info
->detail
.data_display_info
.regs_column_count
= 1;
550 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
551 win_info
->detail
.data_display_info
.current_group
= 0;
554 win_info
->detail
.command_info
.cur_line
= 0;
555 win_info
->detail
.command_info
.curch
= 0;
558 win_info
->detail
.opaque
= NULL
;
564 struct tui_win_info
*
565 tui_alloc_win_info (enum tui_win_type type
)
567 struct tui_win_info
*win_info
;
569 win_info
= XNEW (struct tui_win_info
);
570 if (win_info
!= NULL
)
572 win_info
->generic
.type
= type
;
573 init_win_info (win_info
);
580 /* Allocates the content and elements in a block. */
582 tui_alloc_content (int num_elements
, enum tui_win_type type
)
584 tui_win_content content
;
585 char *element_block_ptr
;
588 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
592 * All windows, except the data window, can allocate the
593 * elements in a chunk. The data window cannot because items
594 * can be added/removed from the data display by the user at any
597 if (type
!= DATA_WIN
)
600 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
601 if (element_block_ptr
!= NULL
)
603 for (i
= 0; i
< num_elements
; i
++)
605 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
606 init_content_element (content
[i
], type
);
607 element_block_ptr
+= sizeof (struct tui_win_element
);
613 content
= (tui_win_content
) NULL
;
622 /* Adds the input number of elements to the windows's content. If no
623 content has been allocated yet, alloc_content() is called to do
624 this. The index of the first element added is returned, unless
625 there is a memory allocation error, in which case, (-1) is
628 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
631 struct tui_win_element
*element_ptr
;
634 if (win_info
->content
== NULL
)
636 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
640 index_start
= win_info
->content_size
;
641 if (win_info
->content
!= NULL
)
643 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
645 if ((element_ptr
= XNEW (struct tui_win_element
)) != NULL
)
647 win_info
->content
[i
] = (void *) element_ptr
;
648 init_content_element (element_ptr
, win_info
->type
);
649 win_info
->content_size
++;
651 else /* Things must be really hosed now! We ran out of
661 /* Delete all curses windows associated with win_info, leaving
662 everything else intact. */
664 tui_del_window (struct tui_win_info
*win_info
)
666 struct tui_gen_win_info
*generic_win
;
668 switch (win_info
->generic
.type
)
672 generic_win
= tui_locator_win_info_ptr ();
673 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
675 tui_delete_win (generic_win
->handle
);
676 generic_win
->handle
= (WINDOW
*) NULL
;
677 generic_win
->is_visible
= FALSE
;
679 if (win_info
->detail
.source_info
.fullname
)
681 xfree (win_info
->detail
.source_info
.fullname
);
682 win_info
->detail
.source_info
.fullname
= NULL
;
684 generic_win
= win_info
->detail
.source_info
.execution_info
;
685 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
687 tui_delete_win (generic_win
->handle
);
688 generic_win
->handle
= (WINDOW
*) NULL
;
689 generic_win
->is_visible
= FALSE
;
693 if (win_info
->generic
.content
!= NULL
)
695 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
696 win_info
->detail
.data_display_info
.regs_content_count
);
697 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
698 win_info
->detail
.data_display_info
.data_content_count
);
704 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
706 tui_delete_win (win_info
->generic
.handle
);
707 win_info
->generic
.handle
= (WINDOW
*) NULL
;
708 win_info
->generic
.is_visible
= FALSE
;
714 tui_free_window (struct tui_win_info
*win_info
)
716 struct tui_gen_win_info
*generic_win
;
718 switch (win_info
->generic
.type
)
722 if (win_info
->detail
.source_info
.fullname
)
724 xfree (win_info
->detail
.source_info
.fullname
);
725 win_info
->detail
.source_info
.fullname
= NULL
;
727 generic_win
= win_info
->detail
.source_info
.execution_info
;
728 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
730 tui_delete_win (generic_win
->handle
);
731 generic_win
->handle
= (WINDOW
*) NULL
;
732 tui_free_win_content (generic_win
);
736 if (win_info
->generic
.content
!= NULL
)
738 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
739 win_info
->detail
.data_display_info
.regs_content_count
);
740 win_info
->detail
.data_display_info
.regs_content
=
741 (tui_win_content
) NULL
;
742 win_info
->detail
.data_display_info
.regs_content_count
= 0;
743 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
744 win_info
->detail
.data_display_info
.data_content_count
);
745 win_info
->detail
.data_display_info
.data_content
=
746 (tui_win_content
) NULL
;
747 win_info
->detail
.data_display_info
.data_content_count
= 0;
748 win_info
->detail
.data_display_info
.regs_display_type
=
750 win_info
->detail
.data_display_info
.regs_column_count
= 1;
751 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
752 win_info
->generic
.content
= NULL
;
753 win_info
->generic
.content_size
= 0;
759 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
761 tui_delete_win (win_info
->generic
.handle
);
762 win_info
->generic
.handle
= (WINDOW
*) NULL
;
763 tui_free_win_content (&win_info
->generic
);
765 if (win_info
->generic
.title
)
766 xfree (win_info
->generic
.title
);
772 tui_free_all_source_wins_content (void)
776 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
778 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
780 if (win_info
!= NULL
)
782 tui_free_win_content (&(win_info
->generic
));
783 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
790 tui_free_win_content (struct tui_gen_win_info
*win_info
)
792 if (win_info
->content
!= NULL
)
794 free_content ((tui_win_content
) win_info
->content
,
795 win_info
->content_size
,
797 win_info
->content
= NULL
;
799 win_info
->content_size
= 0;
804 tui_del_data_windows (tui_win_content content
,
809 /* Remember that data window content elements are of type struct
810 tui_gen_win_info *, each of which whose single element is a data
812 for (i
= 0; i
< content_size
; i
++)
814 struct tui_gen_win_info
*generic_win
815 = &content
[i
]->which_element
.data_window
;
817 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
819 tui_delete_win (generic_win
->handle
);
820 generic_win
->handle
= (WINDOW
*) NULL
;
821 generic_win
->is_visible
= FALSE
;
828 tui_free_data_content (tui_win_content content
,
833 /* Remember that data window content elements are of type struct
834 tui_gen_win_info *, each of which whose single element is a data
836 for (i
= 0; i
< content_size
; i
++)
838 struct tui_gen_win_info
*generic_win
839 = &content
[i
]->which_element
.data_window
;
841 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
843 tui_delete_win (generic_win
->handle
);
844 generic_win
->handle
= (WINDOW
*) NULL
;
845 tui_free_win_content (generic_win
);
848 free_content (content
,
854 /**********************************
855 ** LOCAL STATIC FUNCTIONS **
856 **********************************/
860 free_content (tui_win_content content
,
862 enum tui_win_type win_type
)
864 if (content
!= (tui_win_content
) NULL
)
866 free_content_elements (content
, content_size
, win_type
);
872 /* free_content_elements().
875 free_content_elements (tui_win_content content
,
877 enum tui_win_type type
)
879 if (content
!= (tui_win_content
) NULL
)
883 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
885 /* Free whole source block. */
886 xfree (content
[0]->which_element
.source
.line
);
890 for (i
= 0; i
< content_size
; i
++)
892 struct tui_win_element
*element
;
894 element
= content
[i
];
895 if (element
!= (struct tui_win_element
*) NULL
)
903 /* Note that data elements are not allocated in
904 a single block, but individually, as
906 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
907 xfree ((void *)element
->which_element
.data
.name
);
908 xfree (element
->which_element
.data
.value
);
909 xfree (element
->which_element
.data
.content
);
913 xfree (element
->which_element
.command
.line
);
921 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
922 xfree (content
[0]); /* Free the element block. */