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 enum tui_win_type 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 enum tui_win_type 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 && strncmp (name
, cur_name
, strlen (name
)) == 0)
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 ((struct tui_gen_win_info
*)
494 &element
->which_element
.data_window
)->content
=
495 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
496 ((struct tui_gen_win_info
*)
497 & element
->which_element
.data_window
)->content_size
= 1;
500 element
->which_element
.command
.line
= (char *) NULL
;
503 element
->which_element
.data
.name
= (char *) NULL
;
504 element
->which_element
.data
.type
= TUI_REGISTER
;
505 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
506 element
->which_element
.data
.value
= NULL
;
507 element
->which_element
.data
.highlight
= FALSE
;
508 element
->which_element
.data
.content
= (char*) NULL
;
511 element
->which_element
.locator
.full_name
[0] =
512 element
->which_element
.locator
.proc_name
[0] = (char) 0;
513 element
->which_element
.locator
.line_no
= 0;
514 element
->which_element
.locator
.addr
= 0;
517 memset(element
->which_element
.simple_string
, ' ',
518 sizeof(element
->which_element
.simple_string
));
526 init_win_info (struct tui_win_info
*win_info
)
528 tui_init_generic_part (&win_info
->generic
);
529 win_info
->can_highlight
=
530 win_info
->is_highlighted
= FALSE
;
531 switch (win_info
->generic
.type
)
535 win_info
->detail
.source_info
.execution_info
536 = (struct tui_gen_win_info
*) NULL
;
537 win_info
->detail
.source_info
.has_locator
= FALSE
;
538 win_info
->detail
.source_info
.horizontal_offset
= 0;
539 win_info
->detail
.source_info
.gdbarch
= NULL
;
540 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
541 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
542 win_info
->detail
.source_info
.fullname
= NULL
;
545 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
546 win_info
->detail
.data_display_info
.data_content_count
= 0;
547 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
548 win_info
->detail
.data_display_info
.regs_content_count
= 0;
549 win_info
->detail
.data_display_info
.regs_display_type
=
551 win_info
->detail
.data_display_info
.regs_column_count
= 1;
552 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
553 win_info
->detail
.data_display_info
.current_group
= 0;
556 win_info
->detail
.command_info
.cur_line
= 0;
557 win_info
->detail
.command_info
.curch
= 0;
560 win_info
->detail
.opaque
= NULL
;
566 struct tui_win_info
*
567 tui_alloc_win_info (enum tui_win_type type
)
569 struct tui_win_info
*win_info
;
571 win_info
= XNEW (struct tui_win_info
);
572 if (win_info
!= NULL
)
574 win_info
->generic
.type
= type
;
575 init_win_info (win_info
);
582 /* Allocates the content and elements in a block. */
584 tui_alloc_content (int num_elements
, enum tui_win_type type
)
586 tui_win_content content
;
587 char *element_block_ptr
;
590 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
594 * All windows, except the data window, can allocate the
595 * elements in a chunk. The data window cannot because items
596 * can be added/removed from the data display by the user at any
599 if (type
!= DATA_WIN
)
602 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
603 if (element_block_ptr
!= NULL
)
605 for (i
= 0; i
< num_elements
; i
++)
607 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
608 init_content_element (content
[i
], type
);
609 element_block_ptr
+= sizeof (struct tui_win_element
);
615 content
= (tui_win_content
) NULL
;
624 /* Adds the input number of elements to the windows's content. If no
625 content has been allocated yet, alloc_content() is called to do
626 this. The index of the first element added is returned, unless
627 there is a memory allocation error, in which case, (-1) is
630 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
633 struct tui_win_element
*element_ptr
;
636 if (win_info
->content
== NULL
)
638 win_info
->content
= (void **) tui_alloc_content (num_elements
,
643 index_start
= win_info
->content_size
;
644 if (win_info
->content
!= NULL
)
646 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
648 if ((element_ptr
= XNEW (struct tui_win_element
)) != NULL
)
650 win_info
->content
[i
] = (void *) element_ptr
;
651 init_content_element (element_ptr
, win_info
->type
);
652 win_info
->content_size
++;
654 else /* Things must be really hosed now! We ran out of
664 /* Delete all curses windows associated with win_info, leaving
665 everything else intact. */
667 tui_del_window (struct tui_win_info
*win_info
)
669 struct tui_gen_win_info
*generic_win
;
671 switch (win_info
->generic
.type
)
675 generic_win
= tui_locator_win_info_ptr ();
676 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
678 tui_delete_win (generic_win
->handle
);
679 generic_win
->handle
= (WINDOW
*) NULL
;
680 generic_win
->is_visible
= FALSE
;
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
= (WINDOW
*) NULL
;
692 generic_win
->is_visible
= FALSE
;
696 if (win_info
->generic
.content
!= NULL
)
698 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
699 win_info
->detail
.data_display_info
.regs_content_count
);
700 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
701 win_info
->detail
.data_display_info
.data_content_count
);
707 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
709 tui_delete_win (win_info
->generic
.handle
);
710 win_info
->generic
.handle
= (WINDOW
*) NULL
;
711 win_info
->generic
.is_visible
= FALSE
;
717 tui_free_window (struct tui_win_info
*win_info
)
719 struct tui_gen_win_info
*generic_win
;
721 switch (win_info
->generic
.type
)
725 generic_win
= tui_locator_win_info_ptr ();
726 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
728 tui_delete_win (generic_win
->handle
);
729 generic_win
->handle
= (WINDOW
*) NULL
;
731 tui_free_win_content (generic_win
);
732 if (win_info
->detail
.source_info
.fullname
)
734 xfree (win_info
->detail
.source_info
.fullname
);
735 win_info
->detail
.source_info
.fullname
= NULL
;
737 generic_win
= win_info
->detail
.source_info
.execution_info
;
738 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
740 tui_delete_win (generic_win
->handle
);
741 generic_win
->handle
= (WINDOW
*) NULL
;
742 tui_free_win_content (generic_win
);
746 if (win_info
->generic
.content
!= NULL
)
748 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
749 win_info
->detail
.data_display_info
.regs_content_count
);
750 win_info
->detail
.data_display_info
.regs_content
=
751 (tui_win_content
) NULL
;
752 win_info
->detail
.data_display_info
.regs_content_count
= 0;
753 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
754 win_info
->detail
.data_display_info
.data_content_count
);
755 win_info
->detail
.data_display_info
.data_content
=
756 (tui_win_content
) NULL
;
757 win_info
->detail
.data_display_info
.data_content_count
= 0;
758 win_info
->detail
.data_display_info
.regs_display_type
=
760 win_info
->detail
.data_display_info
.regs_column_count
= 1;
761 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
762 win_info
->generic
.content
= NULL
;
763 win_info
->generic
.content_size
= 0;
769 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
771 tui_delete_win (win_info
->generic
.handle
);
772 win_info
->generic
.handle
= (WINDOW
*) NULL
;
773 tui_free_win_content (&win_info
->generic
);
775 if (win_info
->generic
.title
)
776 xfree (win_info
->generic
.title
);
782 tui_free_all_source_wins_content (void)
786 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
788 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
790 if (win_info
!= NULL
)
792 tui_free_win_content (&(win_info
->generic
));
793 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
800 tui_free_win_content (struct tui_gen_win_info
*win_info
)
802 if (win_info
->content
!= NULL
)
804 free_content ((tui_win_content
) win_info
->content
,
805 win_info
->content_size
,
807 win_info
->content
= NULL
;
809 win_info
->content_size
= 0;
814 tui_del_data_windows (tui_win_content content
,
819 /* Remember that data window content elements are of type struct
820 tui_gen_win_info *, each of which whose single element is a data
822 for (i
= 0; i
< content_size
; i
++)
824 struct tui_gen_win_info
*generic_win
825 = &content
[i
]->which_element
.data_window
;
827 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
829 tui_delete_win (generic_win
->handle
);
830 generic_win
->handle
= (WINDOW
*) NULL
;
831 generic_win
->is_visible
= FALSE
;
838 tui_free_data_content (tui_win_content content
,
843 /* Remember that data window content elements are of type struct
844 tui_gen_win_info *, each of which whose single element is a data
846 for (i
= 0; i
< content_size
; i
++)
848 struct tui_gen_win_info
*generic_win
849 = &content
[i
]->which_element
.data_window
;
851 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
853 tui_delete_win (generic_win
->handle
);
854 generic_win
->handle
= (WINDOW
*) NULL
;
855 tui_free_win_content (generic_win
);
858 free_content (content
,
864 /**********************************
865 ** LOCAL STATIC FUNCTIONS **
866 **********************************/
870 free_content (tui_win_content content
,
872 enum tui_win_type win_type
)
874 if (content
!= (tui_win_content
) NULL
)
876 free_content_elements (content
, content_size
, win_type
);
882 /* free_content_elements().
885 free_content_elements (tui_win_content content
,
887 enum tui_win_type type
)
889 if (content
!= (tui_win_content
) NULL
)
893 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
895 /* Free whole source block. */
896 xfree (content
[0]->which_element
.source
.line
);
900 for (i
= 0; i
< content_size
; i
++)
902 struct tui_win_element
*element
;
904 element
= content
[i
];
905 if (element
!= (struct tui_win_element
*) NULL
)
913 /* Note that data elements are not allocated in
914 a single block, but individually, as
916 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
917 xfree ((void *)element
->which_element
.data
.name
);
918 xfree (element
->which_element
.data
.value
);
919 xfree (element
->which_element
.data
.content
);
923 xfree (element
->which_element
.command
.line
);
931 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
932 xfree (content
[0]); /* Free the element block. */