1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2004, 2006-2012 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"
28 #include "gdb_string.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 /* Set the origin of the window. */
316 set_gen_win_origin (struct tui_gen_win_info
*win_info
,
319 win_info
->origin
.x
= x
;
320 win_info
->origin
.y
= y
;
324 /*****************************
325 ** OTHER PUBLIC FUNCTIONS
326 *****************************/
329 /* Answer the next window in the list, cycling back to the top if
331 struct tui_win_info
*
332 tui_next_win (struct tui_win_info
*cur_win
)
334 enum tui_win_type type
= cur_win
->generic
.type
;
335 struct tui_win_info
*next_win
= (struct tui_win_info
*) NULL
;
337 if (cur_win
->generic
.type
== CMD_WIN
)
340 type
= cur_win
->generic
.type
+ 1;
341 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
343 if (tui_win_list
[type
]
344 && tui_win_list
[type
]->generic
.is_visible
)
345 next_win
= tui_win_list
[type
];
359 /* Answer the prev window in the list, cycling back to the bottom if
361 struct tui_win_info
*
362 tui_prev_win (struct tui_win_info
*cur_win
)
364 enum tui_win_type type
= cur_win
->generic
.type
;
365 struct tui_win_info
*prev
= (struct tui_win_info
*) NULL
;
367 if (cur_win
->generic
.type
== SRC_WIN
)
370 type
= cur_win
->generic
.type
- 1;
371 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
373 if (tui_win_list
[type
]
374 && tui_win_list
[type
]->generic
.is_visible
)
375 prev
= tui_win_list
[type
];
389 /* Answer the window represented by name. */
390 struct tui_win_info
*
391 tui_partial_win_by_name (char *name
)
393 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
395 if (name
!= (char *) NULL
)
399 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
401 if (tui_win_list
[i
] != 0)
403 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
405 if (strlen (name
) <= strlen (cur_name
)
406 && strncmp (name
, cur_name
, strlen (name
)) == 0)
407 win_info
= tui_win_list
[i
];
417 /* Answer the name of the window. */
419 tui_win_name (struct tui_gen_win_info
*win_info
)
421 char *name
= (char *) NULL
;
423 switch (win_info
->type
)
432 name
= DISASSEM_NAME
;
447 tui_initialize_static_data (void)
449 tui_init_generic_part (tui_source_exec_info_win_ptr ());
450 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
451 tui_init_generic_part (tui_locator_win_info_ptr ());
455 struct tui_gen_win_info
*
456 tui_alloc_generic_win_info (void)
458 struct tui_gen_win_info
*win
;
460 if ((win
= XMALLOC (struct tui_gen_win_info
)) != NULL
)
461 tui_init_generic_part (win
);
468 tui_init_generic_part (struct tui_gen_win_info
*win
)
474 win
->viewport_height
=
476 win
->last_visible_line
= 0;
477 win
->handle
= (WINDOW
*) NULL
;
479 win
->content_in_use
=
480 win
->is_visible
= FALSE
;
485 /* init_content_element().
488 init_content_element (struct tui_win_element
*element
,
489 enum tui_win_type type
)
491 element
->highlight
= FALSE
;
496 element
->which_element
.source
.line
= (char *) NULL
;
497 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
498 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
499 element
->which_element
.source
.is_exec_point
= FALSE
;
500 element
->which_element
.source
.has_break
= FALSE
;
503 tui_init_generic_part (&element
->which_element
.data_window
);
504 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
505 ((struct tui_gen_win_info
*)
506 &element
->which_element
.data_window
)->content
=
507 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
508 ((struct tui_gen_win_info
*)
509 & element
->which_element
.data_window
)->content_size
= 1;
512 element
->which_element
.command
.line
= (char *) NULL
;
515 element
->which_element
.data
.name
= (char *) NULL
;
516 element
->which_element
.data
.type
= TUI_REGISTER
;
517 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
518 element
->which_element
.data
.value
= NULL
;
519 element
->which_element
.data
.highlight
= FALSE
;
520 element
->which_element
.data
.content
= (char*) NULL
;
523 element
->which_element
.locator
.file_name
[0] =
524 element
->which_element
.locator
.proc_name
[0] = (char) 0;
525 element
->which_element
.locator
.line_no
= 0;
526 element
->which_element
.locator
.addr
= 0;
529 memset(element
->which_element
.simple_string
, ' ',
530 sizeof(element
->which_element
.simple_string
));
538 init_win_info (struct tui_win_info
*win_info
)
540 tui_init_generic_part (&win_info
->generic
);
541 win_info
->can_highlight
=
542 win_info
->is_highlighted
= FALSE
;
543 switch (win_info
->generic
.type
)
547 win_info
->detail
.source_info
.execution_info
548 = (struct tui_gen_win_info
*) NULL
;
549 win_info
->detail
.source_info
.has_locator
= FALSE
;
550 win_info
->detail
.source_info
.horizontal_offset
= 0;
551 win_info
->detail
.source_info
.gdbarch
= NULL
;
552 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
553 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
554 win_info
->detail
.source_info
.filename
= 0;
557 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
558 win_info
->detail
.data_display_info
.data_content_count
= 0;
559 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
560 win_info
->detail
.data_display_info
.regs_content_count
= 0;
561 win_info
->detail
.data_display_info
.regs_display_type
=
563 win_info
->detail
.data_display_info
.regs_column_count
= 1;
564 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
565 win_info
->detail
.data_display_info
.current_group
= 0;
568 win_info
->detail
.command_info
.cur_line
= 0;
569 win_info
->detail
.command_info
.curch
= 0;
572 win_info
->detail
.opaque
= NULL
;
578 struct tui_win_info
*
579 tui_alloc_win_info (enum tui_win_type type
)
581 struct tui_win_info
*win_info
;
583 win_info
= XMALLOC (struct tui_win_info
);
584 if (win_info
!= NULL
)
586 win_info
->generic
.type
= type
;
587 init_win_info (win_info
);
594 /* Allocates the content and elements in a block. */
596 tui_alloc_content (int num_elements
, enum tui_win_type type
)
598 tui_win_content content
;
599 char *element_block_ptr
;
602 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
606 * All windows, except the data window, can allocate the
607 * elements in a chunk. The data window cannot because items
608 * can be added/removed from the data display by the user at any
611 if (type
!= DATA_WIN
)
614 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
615 if (element_block_ptr
!= NULL
)
617 for (i
= 0; i
< num_elements
; i
++)
619 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
620 init_content_element (content
[i
], type
);
621 element_block_ptr
+= sizeof (struct tui_win_element
);
627 content
= (tui_win_content
) NULL
;
636 /* Adds the input number of elements to the windows's content. If no
637 content has been allocated yet, alloc_content() is called to do
638 this. The index of the first element added is returned, unless
639 there is a memory allocation error, in which case, (-1) is
642 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
645 struct tui_win_element
*element_ptr
;
648 if (win_info
->content
== NULL
)
650 win_info
->content
= (void **) tui_alloc_content (num_elements
,
655 index_start
= win_info
->content_size
;
656 if (win_info
->content
!= NULL
)
658 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
660 if ((element_ptr
= XMALLOC (struct tui_win_element
)) != NULL
)
662 win_info
->content
[i
] = (void *) element_ptr
;
663 init_content_element (element_ptr
, win_info
->type
);
664 win_info
->content_size
++;
666 else /* Things must be really hosed now! We ran out of
676 /* Delete all curses windows associated with win_info, leaving
677 everything else intact. */
679 tui_del_window (struct tui_win_info
*win_info
)
681 struct tui_gen_win_info
*generic_win
;
683 switch (win_info
->generic
.type
)
687 generic_win
= tui_locator_win_info_ptr ();
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
;
694 if (win_info
->detail
.source_info
.filename
)
696 xfree (win_info
->detail
.source_info
.filename
);
697 win_info
->detail
.source_info
.filename
= 0;
699 generic_win
= win_info
->detail
.source_info
.execution_info
;
700 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
702 tui_delete_win (generic_win
->handle
);
703 generic_win
->handle
= (WINDOW
*) NULL
;
704 generic_win
->is_visible
= FALSE
;
708 if (win_info
->generic
.content
!= NULL
)
710 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
711 win_info
->detail
.data_display_info
.regs_content_count
);
712 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
713 win_info
->detail
.data_display_info
.data_content_count
);
719 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
721 tui_delete_win (win_info
->generic
.handle
);
722 win_info
->generic
.handle
= (WINDOW
*) NULL
;
723 win_info
->generic
.is_visible
= FALSE
;
729 tui_free_window (struct tui_win_info
*win_info
)
731 struct tui_gen_win_info
*generic_win
;
733 switch (win_info
->generic
.type
)
737 generic_win
= tui_locator_win_info_ptr ();
738 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
740 tui_delete_win (generic_win
->handle
);
741 generic_win
->handle
= (WINDOW
*) NULL
;
743 tui_free_win_content (generic_win
);
744 if (win_info
->detail
.source_info
.filename
)
746 xfree (win_info
->detail
.source_info
.filename
);
747 win_info
->detail
.source_info
.filename
= 0;
749 generic_win
= win_info
->detail
.source_info
.execution_info
;
750 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
752 tui_delete_win (generic_win
->handle
);
753 generic_win
->handle
= (WINDOW
*) NULL
;
754 tui_free_win_content (generic_win
);
758 if (win_info
->generic
.content
!= NULL
)
760 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
761 win_info
->detail
.data_display_info
.regs_content_count
);
762 win_info
->detail
.data_display_info
.regs_content
=
763 (tui_win_content
) NULL
;
764 win_info
->detail
.data_display_info
.regs_content_count
= 0;
765 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
766 win_info
->detail
.data_display_info
.data_content_count
);
767 win_info
->detail
.data_display_info
.data_content
=
768 (tui_win_content
) NULL
;
769 win_info
->detail
.data_display_info
.data_content_count
= 0;
770 win_info
->detail
.data_display_info
.regs_display_type
=
772 win_info
->detail
.data_display_info
.regs_column_count
= 1;
773 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
774 win_info
->generic
.content
= NULL
;
775 win_info
->generic
.content_size
= 0;
781 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
783 tui_delete_win (win_info
->generic
.handle
);
784 win_info
->generic
.handle
= (WINDOW
*) NULL
;
785 tui_free_win_content (&win_info
->generic
);
787 if (win_info
->generic
.title
)
788 xfree (win_info
->generic
.title
);
794 tui_free_all_source_wins_content (void)
798 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
800 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
802 if (win_info
!= NULL
)
804 tui_free_win_content (&(win_info
->generic
));
805 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
812 tui_free_win_content (struct tui_gen_win_info
*win_info
)
814 if (win_info
->content
!= NULL
)
816 free_content ((tui_win_content
) win_info
->content
,
817 win_info
->content_size
,
819 win_info
->content
= NULL
;
821 win_info
->content_size
= 0;
826 tui_del_data_windows (tui_win_content content
,
831 /* Remember that data window content elements are of type struct
832 tui_gen_win_info *, each of which whose single element is a data
834 for (i
= 0; i
< content_size
; i
++)
836 struct tui_gen_win_info
*generic_win
837 = &content
[i
]->which_element
.data_window
;
839 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
841 tui_delete_win (generic_win
->handle
);
842 generic_win
->handle
= (WINDOW
*) NULL
;
843 generic_win
->is_visible
= FALSE
;
850 tui_free_data_content (tui_win_content content
,
855 /* Remember that data window content elements are of type struct
856 tui_gen_win_info *, each of which whose single element is a data
858 for (i
= 0; i
< content_size
; i
++)
860 struct tui_gen_win_info
*generic_win
861 = &content
[i
]->which_element
.data_window
;
863 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
865 tui_delete_win (generic_win
->handle
);
866 generic_win
->handle
= (WINDOW
*) NULL
;
867 tui_free_win_content (generic_win
);
870 free_content (content
,
876 /**********************************
877 ** LOCAL STATIC FUNCTIONS **
878 **********************************/
882 free_content (tui_win_content content
,
884 enum tui_win_type win_type
)
886 if (content
!= (tui_win_content
) NULL
)
888 free_content_elements (content
, content_size
, win_type
);
894 /* free_content_elements().
897 free_content_elements (tui_win_content content
,
899 enum tui_win_type type
)
901 if (content
!= (tui_win_content
) NULL
)
905 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
907 /* Free whole source block. */
908 xfree (content
[0]->which_element
.source
.line
);
912 for (i
= 0; i
< content_size
; i
++)
914 struct tui_win_element
*element
;
916 element
= content
[i
];
917 if (element
!= (struct tui_win_element
*) NULL
)
925 /* Note that data elements are not allocated in
926 a single block, but individually, as
928 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
929 xfree ((void *)element
->which_element
.data
.name
);
930 xfree (element
->which_element
.data
.value
);
931 xfree (element
->which_element
.data
.content
);
935 xfree (element
->which_element
.command
.line
);
943 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
944 xfree (content
[0]); /* Free the element block. */