1 /* TUI data manipulation routines.
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008,
4 2009, 2010 Free Software Foundation, Inc.
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "tui/tui-data.h"
27 #include "tui/tui-wingeneral.h"
29 #include "gdb_string.h"
30 #include "gdb_curses.h"
32 /****************************
33 ** GLOBAL DECLARATIONS
34 ****************************/
35 struct tui_win_info
*(tui_win_list
[MAX_MAJOR_WINDOWS
]);
37 /***************************
39 ****************************/
40 static enum tui_layout_type current_layout
= UNDEFINED_LAYOUT
;
41 static int term_height
, term_width
;
42 static struct tui_gen_win_info _locator
;
43 static struct tui_gen_win_info exec_info
[2];
44 static struct tui_win_info
*src_win_list
[2];
45 static struct tui_list source_windows
= {src_win_list
, 0};
46 static int default_tab_len
= DEFAULT_TAB_LEN
;
47 static struct tui_win_info
*win_with_focus
= (struct tui_win_info
*) NULL
;
48 static struct tui_layout_def layout_def
= {
49 SRC_WIN
, /* DISPLAY_MODE */
51 TUI_UNDEFINED_REGS
, /* REGS_DISPLAY_TYPE */
52 TUI_SFLOAT_REGS
}; /* FLOAT_REGS_DISPLAY_TYPE */
54 static int win_resized
= FALSE
;
57 /*********************************
58 ** Static function forward decls
59 **********************************/
60 static void free_content (tui_win_content
,
63 static void free_content_elements (tui_win_content
,
69 /*********************************
71 **********************************/
74 tui_win_is_source_type (enum tui_win_type win_type
)
76 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
80 tui_win_is_auxillary (enum tui_win_type win_type
)
82 return (win_type
> MAX_MAJOR_WINDOWS
);
86 tui_win_has_locator (struct tui_win_info
*win_info
)
88 return (win_info
!= NULL
89 && win_info
->detail
.source_info
.has_locator
);
93 tui_set_win_highlight (struct tui_win_info
*win_info
,
97 win_info
->is_highlighted
= highlight
;
100 /******************************************
101 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
102 ******************************************/
104 /* Answer a whether the terminal window has been resized or not. */
106 tui_win_resized (void)
112 /* Set a whether the terminal window has been resized or not. */
114 tui_set_win_resized_to (int resized
)
116 win_resized
= resized
;
120 /* Answer a pointer to the current layout definition. */
121 struct tui_layout_def
*
122 tui_layout_def (void)
128 /* Answer the window with the logical focus. */
129 struct tui_win_info
*
130 tui_win_with_focus (void)
132 return win_with_focus
;
136 /* Set the window that has the logical focus. */
138 tui_set_win_with_focus (struct tui_win_info
*win_info
)
140 win_with_focus
= win_info
;
144 /* Answer the length in chars, of tabs. */
146 tui_default_tab_len (void)
148 return default_tab_len
;
152 /* Set the length in chars, of tabs. */
154 tui_set_default_tab_len (int len
)
156 default_tab_len
= len
;
160 /* Accessor for the current source window. Usually there is only one
161 source window (either source or disassembly), but both can be
162 displayed at the same time. */
164 tui_source_windows (void)
166 return &source_windows
;
170 /* Clear the list of source windows. Usually there is only one source
171 window (either source or disassembly), but both can be displayed at
174 tui_clear_source_windows (void)
176 source_windows
.list
[0] = NULL
;
177 source_windows
.list
[1] = NULL
;
178 source_windows
.count
= 0;
182 /* Clear the pertinant detail in the source windows. */
184 tui_clear_source_windows_detail (void)
188 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
189 tui_clear_win_detail ((tui_source_windows ())->list
[i
]);
193 /* Add a window to the list of source windows. Usually there is only
194 one source window (either source or disassembly), but both can be
195 displayed at the same time. */
197 tui_add_to_source_windows (struct tui_win_info
*win_info
)
199 if (source_windows
.count
< 2)
200 source_windows
.list
[source_windows
.count
++] = (void *) win_info
;
204 /* Clear the pertinant detail in the windows. */
206 tui_clear_win_detail (struct tui_win_info
*win_info
)
208 if (win_info
!= NULL
)
210 switch (win_info
->generic
.type
)
214 win_info
->detail
.source_info
.gdbarch
= NULL
;
215 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
216 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
217 win_info
->detail
.source_info
.horizontal_offset
= 0;
220 win_info
->detail
.command_info
.cur_line
=
221 win_info
->detail
.command_info
.curch
= 0;
224 win_info
->detail
.data_display_info
.data_content
=
225 (tui_win_content
) NULL
;
226 win_info
->detail
.data_display_info
.data_content_count
= 0;
227 win_info
->detail
.data_display_info
.regs_content
=
228 (tui_win_content
) NULL
;
229 win_info
->detail
.data_display_info
.regs_content_count
= 0;
230 win_info
->detail
.data_display_info
.regs_display_type
=
232 win_info
->detail
.data_display_info
.regs_column_count
= 1;
233 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
242 /* Accessor for the source execution info ptr. */
243 struct tui_gen_win_info
*
244 tui_source_exec_info_win_ptr (void)
246 return &exec_info
[0];
250 /* Accessor for the disassem execution info ptr. */
251 struct tui_gen_win_info
*
252 tui_disassem_exec_info_win_ptr (void)
254 return &exec_info
[1];
258 /* Accessor for the locator win info. Answers a pointer to the static
259 locator win info struct. */
260 struct tui_gen_win_info
*
261 tui_locator_win_info_ptr (void)
267 /* Accessor for the term_height. */
269 tui_term_height (void)
275 /* Mutator for the term height. */
277 tui_set_term_height_to (int h
)
283 /* Accessor for the term_width. */
285 tui_term_width (void)
291 /* Mutator for the term_width. */
293 tui_set_term_width_to (int w
)
299 /* Accessor for the current layout. */
301 tui_current_layout (void)
303 return current_layout
;
307 /* Mutator for the current layout. */
309 tui_set_current_layout_to (enum tui_layout_type new_layout
)
311 current_layout
= new_layout
;
315 /* Set the origin of the window. */
317 set_gen_win_origin (struct tui_gen_win_info
*win_info
,
320 win_info
->origin
.x
= x
;
321 win_info
->origin
.y
= y
;
325 /*****************************
326 ** OTHER PUBLIC FUNCTIONS
327 *****************************/
330 /* Answer the next window in the list, cycling back to the top if
332 struct tui_win_info
*
333 tui_next_win (struct tui_win_info
*cur_win
)
335 enum tui_win_type type
= cur_win
->generic
.type
;
336 struct tui_win_info
*next_win
= (struct tui_win_info
*) NULL
;
338 if (cur_win
->generic
.type
== CMD_WIN
)
341 type
= cur_win
->generic
.type
+ 1;
342 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
344 if (tui_win_list
[type
]
345 && tui_win_list
[type
]->generic
.is_visible
)
346 next_win
= tui_win_list
[type
];
360 /* Answer the prev window in the list, cycling back to the bottom if
362 struct tui_win_info
*
363 tui_prev_win (struct tui_win_info
*cur_win
)
365 enum tui_win_type type
= cur_win
->generic
.type
;
366 struct tui_win_info
*prev
= (struct tui_win_info
*) NULL
;
368 if (cur_win
->generic
.type
== SRC_WIN
)
371 type
= cur_win
->generic
.type
- 1;
372 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
374 if (tui_win_list
[type
]
375 && tui_win_list
[type
]->generic
.is_visible
)
376 prev
= tui_win_list
[type
];
390 /* Answer the window represented by name. */
391 struct tui_win_info
*
392 tui_partial_win_by_name (char *name
)
394 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
396 if (name
!= (char *) NULL
)
400 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
402 if (tui_win_list
[i
] != 0)
404 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
406 if (strlen (name
) <= strlen (cur_name
)
407 && strncmp (name
, cur_name
, strlen (name
)) == 0)
408 win_info
= tui_win_list
[i
];
418 /* Answer the name of the window. */
420 tui_win_name (struct tui_gen_win_info
*win_info
)
422 char *name
= (char *) NULL
;
424 switch (win_info
->type
)
433 name
= DISASSEM_NAME
;
448 tui_initialize_static_data (void)
450 tui_init_generic_part (tui_source_exec_info_win_ptr ());
451 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
452 tui_init_generic_part (tui_locator_win_info_ptr ());
456 struct tui_gen_win_info
*
457 tui_alloc_generic_win_info (void)
459 struct tui_gen_win_info
*win
;
461 if ((win
= XMALLOC (struct tui_gen_win_info
)) != NULL
)
462 tui_init_generic_part (win
);
469 tui_init_generic_part (struct tui_gen_win_info
*win
)
475 win
->viewport_height
=
477 win
->last_visible_line
= 0;
478 win
->handle
= (WINDOW
*) NULL
;
480 win
->content_in_use
=
481 win
->is_visible
= FALSE
;
486 /* init_content_element().
489 init_content_element (struct tui_win_element
*element
,
490 enum tui_win_type type
)
492 element
->highlight
= FALSE
;
497 element
->which_element
.source
.line
= (char *) NULL
;
498 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
499 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
500 element
->which_element
.source
.is_exec_point
= FALSE
;
501 element
->which_element
.source
.has_break
= FALSE
;
504 tui_init_generic_part (&element
->which_element
.data_window
);
505 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
506 ((struct tui_gen_win_info
*) & 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
= (struct tui_gen_win_info
*) NULL
;
548 win_info
->detail
.source_info
.has_locator
= FALSE
;
549 win_info
->detail
.source_info
.horizontal_offset
= 0;
550 win_info
->detail
.source_info
.gdbarch
= NULL
;
551 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
552 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
553 win_info
->detail
.source_info
.filename
= 0;
556 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
557 win_info
->detail
.data_display_info
.data_content_count
= 0;
558 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
559 win_info
->detail
.data_display_info
.regs_content_count
= 0;
560 win_info
->detail
.data_display_info
.regs_display_type
=
562 win_info
->detail
.data_display_info
.regs_column_count
= 1;
563 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
564 win_info
->detail
.data_display_info
.current_group
= 0;
567 win_info
->detail
.command_info
.cur_line
= 0;
568 win_info
->detail
.command_info
.curch
= 0;
571 win_info
->detail
.opaque
= NULL
;
577 struct tui_win_info
*
578 tui_alloc_win_info (enum tui_win_type type
)
580 struct tui_win_info
*win_info
;
582 win_info
= XMALLOC (struct tui_win_info
);
583 if (win_info
!= NULL
)
585 win_info
->generic
.type
= type
;
586 init_win_info (win_info
);
593 /* Allocates the content and elements in a block. */
595 tui_alloc_content (int num_elements
, enum tui_win_type type
)
597 tui_win_content content
;
598 char *element_block_ptr
;
601 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
605 * All windows, except the data window, can allocate the
606 * elements in a chunk. The data window cannot because items
607 * can be added/removed from the data display by the user at any
610 if (type
!= DATA_WIN
)
613 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
614 if (element_block_ptr
!= NULL
)
616 for (i
= 0; i
< num_elements
; i
++)
618 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
619 init_content_element (content
[i
], type
);
620 element_block_ptr
+= sizeof (struct tui_win_element
);
626 content
= (tui_win_content
) NULL
;
635 /* Adds the input number of elements to the windows's content. If no
636 content has been allocated yet, alloc_content() is called to do
637 this. The index of the first element added is returned, unless
638 there is a memory allocation error, in which case, (-1) is
641 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
644 struct tui_win_element
*element_ptr
;
647 if (win_info
->content
== NULL
)
649 win_info
->content
= (void **) tui_alloc_content (num_elements
, win_info
->type
);
653 index_start
= win_info
->content_size
;
654 if (win_info
->content
!= NULL
)
656 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
658 if ((element_ptr
= XMALLOC (struct tui_win_element
)) != NULL
)
660 win_info
->content
[i
] = (void *) element_ptr
;
661 init_content_element (element_ptr
, win_info
->type
);
662 win_info
->content_size
++;
664 else /* Things must be really hosed now! We ran out of
674 /* Delete all curses windows associated with win_info, leaving
675 everything else intact. */
677 tui_del_window (struct tui_win_info
*win_info
)
679 struct tui_gen_win_info
*generic_win
;
681 switch (win_info
->generic
.type
)
685 generic_win
= tui_locator_win_info_ptr ();
686 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
688 tui_delete_win (generic_win
->handle
);
689 generic_win
->handle
= (WINDOW
*) NULL
;
690 generic_win
->is_visible
= FALSE
;
692 if (win_info
->detail
.source_info
.filename
)
694 xfree (win_info
->detail
.source_info
.filename
);
695 win_info
->detail
.source_info
.filename
= 0;
697 generic_win
= win_info
->detail
.source_info
.execution_info
;
698 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
700 tui_delete_win (generic_win
->handle
);
701 generic_win
->handle
= (WINDOW
*) NULL
;
702 generic_win
->is_visible
= FALSE
;
706 if (win_info
->generic
.content
!= NULL
)
708 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
709 win_info
->detail
.data_display_info
.regs_content_count
);
710 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
711 win_info
->detail
.data_display_info
.data_content_count
);
717 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
719 tui_delete_win (win_info
->generic
.handle
);
720 win_info
->generic
.handle
= (WINDOW
*) NULL
;
721 win_info
->generic
.is_visible
= FALSE
;
727 tui_free_window (struct tui_win_info
*win_info
)
729 struct tui_gen_win_info
*generic_win
;
731 switch (win_info
->generic
.type
)
735 generic_win
= tui_locator_win_info_ptr ();
736 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
738 tui_delete_win (generic_win
->handle
);
739 generic_win
->handle
= (WINDOW
*) NULL
;
741 tui_free_win_content (generic_win
);
742 if (win_info
->detail
.source_info
.filename
)
744 xfree (win_info
->detail
.source_info
.filename
);
745 win_info
->detail
.source_info
.filename
= 0;
747 generic_win
= win_info
->detail
.source_info
.execution_info
;
748 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
750 tui_delete_win (generic_win
->handle
);
751 generic_win
->handle
= (WINDOW
*) NULL
;
752 tui_free_win_content (generic_win
);
756 if (win_info
->generic
.content
!= NULL
)
758 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
759 win_info
->detail
.data_display_info
.regs_content_count
);
760 win_info
->detail
.data_display_info
.regs_content
=
761 (tui_win_content
) NULL
;
762 win_info
->detail
.data_display_info
.regs_content_count
= 0;
763 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
764 win_info
->detail
.data_display_info
.data_content_count
);
765 win_info
->detail
.data_display_info
.data_content
=
766 (tui_win_content
) NULL
;
767 win_info
->detail
.data_display_info
.data_content_count
= 0;
768 win_info
->detail
.data_display_info
.regs_display_type
=
770 win_info
->detail
.data_display_info
.regs_column_count
= 1;
771 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
772 win_info
->generic
.content
= NULL
;
773 win_info
->generic
.content_size
= 0;
779 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
781 tui_delete_win (win_info
->generic
.handle
);
782 win_info
->generic
.handle
= (WINDOW
*) NULL
;
783 tui_free_win_content (&win_info
->generic
);
785 if (win_info
->generic
.title
)
786 xfree (win_info
->generic
.title
);
792 tui_free_all_source_wins_content (void)
796 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
798 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
800 if (win_info
!= NULL
)
802 tui_free_win_content (&(win_info
->generic
));
803 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
810 tui_free_win_content (struct tui_gen_win_info
*win_info
)
812 if (win_info
->content
!= NULL
)
814 free_content ((tui_win_content
) win_info
->content
,
815 win_info
->content_size
,
817 win_info
->content
= NULL
;
819 win_info
->content_size
= 0;
824 tui_del_data_windows (tui_win_content content
,
829 /* Remember that data window content elements are of type struct
830 tui_gen_win_info *, each of which whose single element is a data
832 for (i
= 0; i
< content_size
; i
++)
834 struct tui_gen_win_info
*generic_win
= &content
[i
]->which_element
.data_window
;
836 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
838 tui_delete_win (generic_win
->handle
);
839 generic_win
->handle
= (WINDOW
*) NULL
;
840 generic_win
->is_visible
= FALSE
;
847 tui_free_data_content (tui_win_content content
,
852 /* Remember that data window content elements are of type struct
853 tui_gen_win_info *, each of which whose single element is a data
855 for (i
= 0; i
< content_size
; i
++)
857 struct tui_gen_win_info
*generic_win
= &content
[i
]->which_element
.data_window
;
859 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
861 tui_delete_win (generic_win
->handle
);
862 generic_win
->handle
= (WINDOW
*) NULL
;
863 tui_free_win_content (generic_win
);
866 free_content (content
,
872 /**********************************
873 ** LOCAL STATIC FUNCTIONS **
874 **********************************/
878 free_content (tui_win_content content
,
880 enum tui_win_type win_type
)
882 if (content
!= (tui_win_content
) NULL
)
884 free_content_elements (content
, content_size
, win_type
);
890 /* free_content_elements().
893 free_content_elements (tui_win_content content
,
895 enum tui_win_type type
)
897 if (content
!= (tui_win_content
) NULL
)
901 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
903 /* Free whole source block. */
904 xfree (content
[0]->which_element
.source
.line
);
908 for (i
= 0; i
< content_size
; i
++)
910 struct tui_win_element
*element
;
912 element
= content
[i
];
913 if (element
!= (struct tui_win_element
*) NULL
)
921 /* Note that data elements are not allocated in
922 a single block, but individually, as
924 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
925 xfree ((void *)element
->which_element
.data
.name
);
926 xfree (element
->which_element
.data
.value
);
927 xfree (element
->which_element
.data
.content
);
931 xfree (element
->which_element
.command
.line
);
939 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
940 xfree (content
[0]); /* Free the element block. */