1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2014 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"
29 #include "gdb_curses.h"
31 /****************************
32 ** GLOBAL DECLARATIONS
33 ****************************/
34 struct tui_win_info
*(tui_win_list
[MAX_MAJOR_WINDOWS
]);
36 /***************************
38 ****************************/
39 static enum tui_layout_type current_layout
= UNDEFINED_LAYOUT
;
40 static int term_height
, term_width
;
41 static struct tui_gen_win_info _locator
;
42 static struct tui_gen_win_info exec_info
[2];
43 static struct tui_win_info
*src_win_list
[2];
44 static struct tui_list source_windows
= {src_win_list
, 0};
45 static int default_tab_len
= DEFAULT_TAB_LEN
;
46 static struct tui_win_info
*win_with_focus
= (struct tui_win_info
*) NULL
;
47 static struct tui_layout_def layout_def
= {
48 SRC_WIN
, /* DISPLAY_MODE */
50 TUI_UNDEFINED_REGS
, /* REGS_DISPLAY_TYPE */
51 TUI_SFLOAT_REGS
}; /* FLOAT_REGS_DISPLAY_TYPE */
53 static int win_resized
= FALSE
;
56 /*********************************
57 ** Static function forward decls
58 **********************************/
59 static void free_content (tui_win_content
,
62 static void free_content_elements (tui_win_content
,
68 /*********************************
70 **********************************/
73 tui_win_is_source_type (enum tui_win_type win_type
)
75 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
79 tui_win_is_auxillary (enum tui_win_type win_type
)
81 return (win_type
> MAX_MAJOR_WINDOWS
);
85 tui_win_has_locator (struct tui_win_info
*win_info
)
87 return (win_info
!= NULL
88 && win_info
->detail
.source_info
.has_locator
);
92 tui_set_win_highlight (struct tui_win_info
*win_info
,
96 win_info
->is_highlighted
= highlight
;
99 /******************************************
100 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
101 ******************************************/
103 /* Answer a whether the terminal window has been resized or not. */
105 tui_win_resized (void)
111 /* Set a whether the terminal window has been resized or not. */
113 tui_set_win_resized_to (int resized
)
115 win_resized
= resized
;
119 /* Answer a pointer to the current layout definition. */
120 struct tui_layout_def
*
121 tui_layout_def (void)
127 /* Answer the window with the logical focus. */
128 struct tui_win_info
*
129 tui_win_with_focus (void)
131 return win_with_focus
;
135 /* Set the window that has the logical focus. */
137 tui_set_win_with_focus (struct tui_win_info
*win_info
)
139 win_with_focus
= win_info
;
143 /* Answer the length in chars, of tabs. */
145 tui_default_tab_len (void)
147 return default_tab_len
;
151 /* Set the length in chars, of tabs. */
153 tui_set_default_tab_len (int len
)
155 default_tab_len
= len
;
159 /* Accessor for the current source window. Usually there is only one
160 source window (either source or disassembly), but both can be
161 displayed at the same time. */
163 tui_source_windows (void)
165 return &source_windows
;
169 /* Clear the list of source windows. Usually there is only one source
170 window (either source or disassembly), but both can be displayed at
173 tui_clear_source_windows (void)
175 source_windows
.list
[0] = NULL
;
176 source_windows
.list
[1] = NULL
;
177 source_windows
.count
= 0;
181 /* Clear the pertinant detail in the source windows. */
183 tui_clear_source_windows_detail (void)
187 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
188 tui_clear_win_detail ((tui_source_windows ())->list
[i
]);
192 /* Add a window to the list of source windows. Usually there is only
193 one source window (either source or disassembly), but both can be
194 displayed at the same time. */
196 tui_add_to_source_windows (struct tui_win_info
*win_info
)
198 if (source_windows
.count
< 2)
199 source_windows
.list
[source_windows
.count
++] = (void *) win_info
;
203 /* Clear the pertinant detail in the windows. */
205 tui_clear_win_detail (struct tui_win_info
*win_info
)
207 if (win_info
!= NULL
)
209 switch (win_info
->generic
.type
)
213 win_info
->detail
.source_info
.gdbarch
= NULL
;
214 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
215 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
216 win_info
->detail
.source_info
.horizontal_offset
= 0;
219 win_info
->detail
.command_info
.cur_line
=
220 win_info
->detail
.command_info
.curch
= 0;
223 win_info
->detail
.data_display_info
.data_content
=
224 (tui_win_content
) NULL
;
225 win_info
->detail
.data_display_info
.data_content_count
= 0;
226 win_info
->detail
.data_display_info
.regs_content
=
227 (tui_win_content
) NULL
;
228 win_info
->detail
.data_display_info
.regs_content_count
= 0;
229 win_info
->detail
.data_display_info
.regs_display_type
=
231 win_info
->detail
.data_display_info
.regs_column_count
= 1;
232 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
241 /* Accessor for the source execution info ptr. */
242 struct tui_gen_win_info
*
243 tui_source_exec_info_win_ptr (void)
245 return &exec_info
[0];
249 /* Accessor for the disassem execution info ptr. */
250 struct tui_gen_win_info
*
251 tui_disassem_exec_info_win_ptr (void)
253 return &exec_info
[1];
257 /* Accessor for the locator win info. Answers a pointer to the static
258 locator win info struct. */
259 struct tui_gen_win_info
*
260 tui_locator_win_info_ptr (void)
266 /* Accessor for the term_height. */
268 tui_term_height (void)
274 /* Mutator for the term height. */
276 tui_set_term_height_to (int h
)
282 /* Accessor for the term_width. */
284 tui_term_width (void)
290 /* Mutator for the term_width. */
292 tui_set_term_width_to (int w
)
298 /* Accessor for the current layout. */
300 tui_current_layout (void)
302 return current_layout
;
306 /* Mutator for the current layout. */
308 tui_set_current_layout_to (enum tui_layout_type new_layout
)
310 current_layout
= new_layout
;
314 /*****************************
315 ** OTHER PUBLIC FUNCTIONS
316 *****************************/
319 /* Answer the next window in the list, cycling back to the top if
321 struct tui_win_info
*
322 tui_next_win (struct tui_win_info
*cur_win
)
324 enum tui_win_type type
= cur_win
->generic
.type
;
325 struct tui_win_info
*next_win
= (struct tui_win_info
*) NULL
;
327 if (cur_win
->generic
.type
== CMD_WIN
)
330 type
= cur_win
->generic
.type
+ 1;
331 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
333 if (tui_win_list
[type
]
334 && tui_win_list
[type
]->generic
.is_visible
)
335 next_win
= tui_win_list
[type
];
349 /* Answer the prev window in the list, cycling back to the bottom if
351 struct tui_win_info
*
352 tui_prev_win (struct tui_win_info
*cur_win
)
354 enum tui_win_type type
= cur_win
->generic
.type
;
355 struct tui_win_info
*prev
= (struct tui_win_info
*) NULL
;
357 if (cur_win
->generic
.type
== SRC_WIN
)
360 type
= cur_win
->generic
.type
- 1;
361 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
363 if (tui_win_list
[type
]
364 && tui_win_list
[type
]->generic
.is_visible
)
365 prev
= tui_win_list
[type
];
379 /* Answer the window represented by name. */
380 struct tui_win_info
*
381 tui_partial_win_by_name (char *name
)
383 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
385 if (name
!= (char *) NULL
)
389 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
391 if (tui_win_list
[i
] != 0)
393 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
395 if (strlen (name
) <= strlen (cur_name
)
396 && strncmp (name
, cur_name
, strlen (name
)) == 0)
397 win_info
= tui_win_list
[i
];
407 /* Answer the name of the window. */
409 tui_win_name (struct tui_gen_win_info
*win_info
)
411 char *name
= (char *) NULL
;
413 switch (win_info
->type
)
422 name
= DISASSEM_NAME
;
437 tui_initialize_static_data (void)
439 tui_init_generic_part (tui_source_exec_info_win_ptr ());
440 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
441 tui_init_generic_part (tui_locator_win_info_ptr ());
445 struct tui_gen_win_info
*
446 tui_alloc_generic_win_info (void)
448 struct tui_gen_win_info
*win
;
450 if ((win
= XNEW (struct tui_gen_win_info
)) != NULL
)
451 tui_init_generic_part (win
);
458 tui_init_generic_part (struct tui_gen_win_info
*win
)
464 win
->viewport_height
=
466 win
->last_visible_line
= 0;
467 win
->handle
= (WINDOW
*) NULL
;
469 win
->content_in_use
=
470 win
->is_visible
= FALSE
;
475 /* init_content_element().
478 init_content_element (struct tui_win_element
*element
,
479 enum tui_win_type type
)
481 element
->highlight
= FALSE
;
486 element
->which_element
.source
.line
= (char *) NULL
;
487 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
488 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
489 element
->which_element
.source
.is_exec_point
= FALSE
;
490 element
->which_element
.source
.has_break
= FALSE
;
493 tui_init_generic_part (&element
->which_element
.data_window
);
494 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
495 ((struct tui_gen_win_info
*)
496 &element
->which_element
.data_window
)->content
=
497 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
498 ((struct tui_gen_win_info
*)
499 & element
->which_element
.data_window
)->content_size
= 1;
502 element
->which_element
.command
.line
= (char *) NULL
;
505 element
->which_element
.data
.name
= (char *) NULL
;
506 element
->which_element
.data
.type
= TUI_REGISTER
;
507 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
508 element
->which_element
.data
.value
= NULL
;
509 element
->which_element
.data
.highlight
= FALSE
;
510 element
->which_element
.data
.content
= (char*) NULL
;
513 element
->which_element
.locator
.full_name
[0] =
514 element
->which_element
.locator
.proc_name
[0] = (char) 0;
515 element
->which_element
.locator
.line_no
= 0;
516 element
->which_element
.locator
.addr
= 0;
519 memset(element
->which_element
.simple_string
, ' ',
520 sizeof(element
->which_element
.simple_string
));
528 init_win_info (struct tui_win_info
*win_info
)
530 tui_init_generic_part (&win_info
->generic
);
531 win_info
->can_highlight
=
532 win_info
->is_highlighted
= FALSE
;
533 switch (win_info
->generic
.type
)
537 win_info
->detail
.source_info
.execution_info
538 = (struct tui_gen_win_info
*) NULL
;
539 win_info
->detail
.source_info
.has_locator
= FALSE
;
540 win_info
->detail
.source_info
.horizontal_offset
= 0;
541 win_info
->detail
.source_info
.gdbarch
= NULL
;
542 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
543 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
544 win_info
->detail
.source_info
.fullname
= NULL
;
547 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
548 win_info
->detail
.data_display_info
.data_content_count
= 0;
549 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
550 win_info
->detail
.data_display_info
.regs_content_count
= 0;
551 win_info
->detail
.data_display_info
.regs_display_type
=
553 win_info
->detail
.data_display_info
.regs_column_count
= 1;
554 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
555 win_info
->detail
.data_display_info
.current_group
= 0;
558 win_info
->detail
.command_info
.cur_line
= 0;
559 win_info
->detail
.command_info
.curch
= 0;
562 win_info
->detail
.opaque
= NULL
;
568 struct tui_win_info
*
569 tui_alloc_win_info (enum tui_win_type type
)
571 struct tui_win_info
*win_info
;
573 win_info
= XNEW (struct tui_win_info
);
574 if (win_info
!= NULL
)
576 win_info
->generic
.type
= type
;
577 init_win_info (win_info
);
584 /* Allocates the content and elements in a block. */
586 tui_alloc_content (int num_elements
, enum tui_win_type type
)
588 tui_win_content content
;
589 char *element_block_ptr
;
592 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
596 * All windows, except the data window, can allocate the
597 * elements in a chunk. The data window cannot because items
598 * can be added/removed from the data display by the user at any
601 if (type
!= DATA_WIN
)
604 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
605 if (element_block_ptr
!= NULL
)
607 for (i
= 0; i
< num_elements
; i
++)
609 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
610 init_content_element (content
[i
], type
);
611 element_block_ptr
+= sizeof (struct tui_win_element
);
617 content
= (tui_win_content
) NULL
;
626 /* Adds the input number of elements to the windows's content. If no
627 content has been allocated yet, alloc_content() is called to do
628 this. The index of the first element added is returned, unless
629 there is a memory allocation error, in which case, (-1) is
632 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
635 struct tui_win_element
*element_ptr
;
638 if (win_info
->content
== NULL
)
640 win_info
->content
= (void **) tui_alloc_content (num_elements
,
645 index_start
= win_info
->content_size
;
646 if (win_info
->content
!= NULL
)
648 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
650 if ((element_ptr
= XNEW (struct tui_win_element
)) != NULL
)
652 win_info
->content
[i
] = (void *) element_ptr
;
653 init_content_element (element_ptr
, win_info
->type
);
654 win_info
->content_size
++;
656 else /* Things must be really hosed now! We ran out of
666 /* Delete all curses windows associated with win_info, leaving
667 everything else intact. */
669 tui_del_window (struct tui_win_info
*win_info
)
671 struct tui_gen_win_info
*generic_win
;
673 switch (win_info
->generic
.type
)
677 generic_win
= tui_locator_win_info_ptr ();
678 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
680 tui_delete_win (generic_win
->handle
);
681 generic_win
->handle
= (WINDOW
*) NULL
;
682 generic_win
->is_visible
= FALSE
;
684 if (win_info
->detail
.source_info
.fullname
)
686 xfree (win_info
->detail
.source_info
.fullname
);
687 win_info
->detail
.source_info
.fullname
= NULL
;
689 generic_win
= win_info
->detail
.source_info
.execution_info
;
690 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
692 tui_delete_win (generic_win
->handle
);
693 generic_win
->handle
= (WINDOW
*) NULL
;
694 generic_win
->is_visible
= FALSE
;
698 if (win_info
->generic
.content
!= NULL
)
700 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
701 win_info
->detail
.data_display_info
.regs_content_count
);
702 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
703 win_info
->detail
.data_display_info
.data_content_count
);
709 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
711 tui_delete_win (win_info
->generic
.handle
);
712 win_info
->generic
.handle
= (WINDOW
*) NULL
;
713 win_info
->generic
.is_visible
= FALSE
;
719 tui_free_window (struct tui_win_info
*win_info
)
721 struct tui_gen_win_info
*generic_win
;
723 switch (win_info
->generic
.type
)
727 generic_win
= tui_locator_win_info_ptr ();
728 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
730 tui_delete_win (generic_win
->handle
);
731 generic_win
->handle
= (WINDOW
*) NULL
;
733 tui_free_win_content (generic_win
);
734 if (win_info
->detail
.source_info
.fullname
)
736 xfree (win_info
->detail
.source_info
.fullname
);
737 win_info
->detail
.source_info
.fullname
= NULL
;
739 generic_win
= win_info
->detail
.source_info
.execution_info
;
740 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
742 tui_delete_win (generic_win
->handle
);
743 generic_win
->handle
= (WINDOW
*) NULL
;
744 tui_free_win_content (generic_win
);
748 if (win_info
->generic
.content
!= NULL
)
750 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
751 win_info
->detail
.data_display_info
.regs_content_count
);
752 win_info
->detail
.data_display_info
.regs_content
=
753 (tui_win_content
) NULL
;
754 win_info
->detail
.data_display_info
.regs_content_count
= 0;
755 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
756 win_info
->detail
.data_display_info
.data_content_count
);
757 win_info
->detail
.data_display_info
.data_content
=
758 (tui_win_content
) NULL
;
759 win_info
->detail
.data_display_info
.data_content_count
= 0;
760 win_info
->detail
.data_display_info
.regs_display_type
=
762 win_info
->detail
.data_display_info
.regs_column_count
= 1;
763 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
764 win_info
->generic
.content
= NULL
;
765 win_info
->generic
.content_size
= 0;
771 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
773 tui_delete_win (win_info
->generic
.handle
);
774 win_info
->generic
.handle
= (WINDOW
*) NULL
;
775 tui_free_win_content (&win_info
->generic
);
777 if (win_info
->generic
.title
)
778 xfree (win_info
->generic
.title
);
784 tui_free_all_source_wins_content (void)
788 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
790 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
792 if (win_info
!= NULL
)
794 tui_free_win_content (&(win_info
->generic
));
795 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
802 tui_free_win_content (struct tui_gen_win_info
*win_info
)
804 if (win_info
->content
!= NULL
)
806 free_content ((tui_win_content
) win_info
->content
,
807 win_info
->content_size
,
809 win_info
->content
= NULL
;
811 win_info
->content_size
= 0;
816 tui_del_data_windows (tui_win_content content
,
821 /* Remember that data window content elements are of type struct
822 tui_gen_win_info *, each of which whose single element is a data
824 for (i
= 0; i
< content_size
; i
++)
826 struct tui_gen_win_info
*generic_win
827 = &content
[i
]->which_element
.data_window
;
829 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
831 tui_delete_win (generic_win
->handle
);
832 generic_win
->handle
= (WINDOW
*) NULL
;
833 generic_win
->is_visible
= FALSE
;
840 tui_free_data_content (tui_win_content content
,
845 /* Remember that data window content elements are of type struct
846 tui_gen_win_info *, each of which whose single element is a data
848 for (i
= 0; i
< content_size
; i
++)
850 struct tui_gen_win_info
*generic_win
851 = &content
[i
]->which_element
.data_window
;
853 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
855 tui_delete_win (generic_win
->handle
);
856 generic_win
->handle
= (WINDOW
*) NULL
;
857 tui_free_win_content (generic_win
);
860 free_content (content
,
866 /**********************************
867 ** LOCAL STATIC FUNCTIONS **
868 **********************************/
872 free_content (tui_win_content content
,
874 enum tui_win_type win_type
)
876 if (content
!= (tui_win_content
) NULL
)
878 free_content_elements (content
, content_size
, win_type
);
884 /* free_content_elements().
887 free_content_elements (tui_win_content content
,
889 enum tui_win_type type
)
891 if (content
!= (tui_win_content
) NULL
)
895 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
897 /* Free whole source block. */
898 xfree (content
[0]->which_element
.source
.line
);
902 for (i
= 0; i
< content_size
; i
++)
904 struct tui_win_element
*element
;
906 element
= content
[i
];
907 if (element
!= (struct tui_win_element
*) NULL
)
915 /* Note that data elements are not allocated in
916 a single block, but individually, as
918 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
919 xfree ((void *)element
->which_element
.data
.name
);
920 xfree (element
->which_element
.data
.value
);
921 xfree (element
->which_element
.data
.content
);
925 xfree (element
->which_element
.command
.line
);
933 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
934 xfree (content
[0]); /* Free the element block. */