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
= NULL
;
45 static struct tui_layout_def layout_def
= {
46 SRC_WIN
, /* DISPLAY_MODE */
49 static int win_resized
= FALSE
;
52 /*********************************
53 ** Static function forward decls
54 **********************************/
55 static void free_content (tui_win_content
,
58 static void free_content_elements (tui_win_content
,
64 /*********************************
66 **********************************/
69 tui_win_is_source_type (enum tui_win_type win_type
)
71 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
75 tui_win_is_auxillary (enum tui_win_type win_type
)
77 return (win_type
> MAX_MAJOR_WINDOWS
);
81 tui_win_has_locator (struct tui_win_info
*win_info
)
83 return (win_info
!= NULL
84 && win_info
->detail
.source_info
.has_locator
);
88 tui_set_win_highlight (struct tui_win_info
*win_info
,
92 win_info
->is_highlighted
= highlight
;
95 /******************************************
96 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
97 ******************************************/
99 /* Answer a whether the terminal window has been resized or not. */
101 tui_win_resized (void)
107 /* Set a whether the terminal window has been resized or not. */
109 tui_set_win_resized_to (int resized
)
111 win_resized
= resized
;
115 /* Answer a pointer to the current layout definition. */
116 struct tui_layout_def
*
117 tui_layout_def (void)
123 /* Answer the window with the logical focus. */
124 struct tui_win_info
*
125 tui_win_with_focus (void)
127 return win_with_focus
;
131 /* Set the window that has the logical focus. */
133 tui_set_win_with_focus (struct tui_win_info
*win_info
)
135 win_with_focus
= win_info
;
139 /* Answer the length in chars, of tabs. */
141 tui_default_tab_len (void)
143 return default_tab_len
;
147 /* Set the length in chars, of tabs. */
149 tui_set_default_tab_len (int len
)
151 default_tab_len
= len
;
155 /* Accessor for the current source window. Usually there is only one
156 source window (either source or disassembly), but both can be
157 displayed at the same time. */
159 tui_source_windows (void)
161 return &source_windows
;
165 /* Clear the list of source windows. Usually there is only one source
166 window (either source or disassembly), but both can be displayed at
169 tui_clear_source_windows (void)
171 source_windows
.list
[0] = NULL
;
172 source_windows
.list
[1] = NULL
;
173 source_windows
.count
= 0;
177 /* Clear the pertinant detail in the source windows. */
179 tui_clear_source_windows_detail (void)
183 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
184 tui_clear_win_detail ((tui_source_windows ())->list
[i
]);
188 /* Add a window to the list of source windows. Usually there is only
189 one source window (either source or disassembly), but both can be
190 displayed at the same time. */
192 tui_add_to_source_windows (struct tui_win_info
*win_info
)
194 if (source_windows
.count
< 2)
195 source_windows
.list
[source_windows
.count
++] = (void *) win_info
;
199 /* Clear the pertinant detail in the windows. */
201 tui_clear_win_detail (struct tui_win_info
*win_info
)
203 if (win_info
!= NULL
)
205 switch (win_info
->generic
.type
)
209 win_info
->detail
.source_info
.gdbarch
= NULL
;
210 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
211 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
212 win_info
->detail
.source_info
.horizontal_offset
= 0;
215 wmove (win_info
->generic
.handle
, 0, 0);
218 win_info
->detail
.data_display_info
.data_content
=
219 (tui_win_content
) NULL
;
220 win_info
->detail
.data_display_info
.data_content_count
= 0;
221 win_info
->detail
.data_display_info
.regs_content
=
222 (tui_win_content
) NULL
;
223 win_info
->detail
.data_display_info
.regs_content_count
= 0;
224 win_info
->detail
.data_display_info
.regs_column_count
= 1;
225 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
234 /* Accessor for the source execution info ptr. */
235 struct tui_gen_win_info
*
236 tui_source_exec_info_win_ptr (void)
238 return &exec_info
[0];
242 /* Accessor for the disassem execution info ptr. */
243 struct tui_gen_win_info
*
244 tui_disassem_exec_info_win_ptr (void)
246 return &exec_info
[1];
250 /* Accessor for the locator win info. Answers a pointer to the static
251 locator win info struct. */
252 struct tui_gen_win_info
*
253 tui_locator_win_info_ptr (void)
259 /* Accessor for the term_height. */
261 tui_term_height (void)
267 /* Mutator for the term height. */
269 tui_set_term_height_to (int h
)
275 /* Accessor for the term_width. */
277 tui_term_width (void)
283 /* Mutator for the term_width. */
285 tui_set_term_width_to (int w
)
291 /* Accessor for the current layout. */
293 tui_current_layout (void)
295 return current_layout
;
299 /* Mutator for the current layout. */
301 tui_set_current_layout_to (enum tui_layout_type new_layout
)
303 current_layout
= new_layout
;
307 /*****************************
308 ** OTHER PUBLIC FUNCTIONS
309 *****************************/
312 /* Answer the next window in the list, cycling back to the top if
314 struct tui_win_info
*
315 tui_next_win (struct tui_win_info
*cur_win
)
317 int type
= cur_win
->generic
.type
;
318 struct tui_win_info
*next_win
= NULL
;
320 if (cur_win
->generic
.type
== CMD_WIN
)
323 type
= cur_win
->generic
.type
+ 1;
324 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
326 if (tui_win_list
[type
]
327 && tui_win_list
[type
]->generic
.is_visible
)
328 next_win
= tui_win_list
[type
];
342 /* Answer the prev window in the list, cycling back to the bottom if
344 struct tui_win_info
*
345 tui_prev_win (struct tui_win_info
*cur_win
)
347 int type
= cur_win
->generic
.type
;
348 struct tui_win_info
*prev
= NULL
;
350 if (cur_win
->generic
.type
== SRC_WIN
)
353 type
= cur_win
->generic
.type
- 1;
354 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
356 if (tui_win_list
[type
]
357 && tui_win_list
[type
]->generic
.is_visible
)
358 prev
= tui_win_list
[type
];
372 /* Answer the window represented by name. */
373 struct tui_win_info
*
374 tui_partial_win_by_name (char *name
)
376 struct tui_win_info
*win_info
= NULL
;
378 if (name
!= (char *) NULL
)
382 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
384 if (tui_win_list
[i
] != 0)
386 const char *cur_name
=
387 tui_win_name (&tui_win_list
[i
]->generic
);
389 if (strlen (name
) <= strlen (cur_name
)
390 && startswith (cur_name
, name
))
391 win_info
= tui_win_list
[i
];
401 /* Answer the name of the window. */
403 tui_win_name (const struct tui_gen_win_info
*win_info
)
405 const char *name
= NULL
;
407 switch (win_info
->type
)
416 name
= DISASSEM_NAME
;
431 tui_initialize_static_data (void)
433 tui_init_generic_part (tui_source_exec_info_win_ptr ());
434 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
435 tui_init_generic_part (tui_locator_win_info_ptr ());
439 struct tui_gen_win_info
*
440 tui_alloc_generic_win_info (void)
442 struct tui_gen_win_info
*win
= XNEW (struct tui_gen_win_info
);
445 tui_init_generic_part (win
);
452 tui_init_generic_part (struct tui_gen_win_info
*win
)
458 win
->viewport_height
=
460 win
->last_visible_line
= 0;
463 win
->content_in_use
=
464 win
->is_visible
= FALSE
;
469 /* init_content_element().
472 init_content_element (struct tui_win_element
*element
,
473 enum tui_win_type type
)
475 element
->highlight
= FALSE
;
480 element
->which_element
.source
.line
= NULL
;
481 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
482 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
483 element
->which_element
.source
.is_exec_point
= FALSE
;
484 element
->which_element
.source
.has_break
= FALSE
;
487 tui_init_generic_part (&element
->which_element
.data_window
);
488 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
489 element
->which_element
.data_window
.content
=
490 tui_alloc_content (1, DATA_ITEM_WIN
);
491 element
->which_element
.data_window
.content_size
= 1;
494 element
->which_element
.command
.line
= NULL
;
497 element
->which_element
.data
.name
= NULL
;
498 element
->which_element
.data
.type
= TUI_REGISTER
;
499 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
500 element
->which_element
.data
.value
= NULL
;
501 element
->which_element
.data
.highlight
= FALSE
;
502 element
->which_element
.data
.content
= NULL
;
505 element
->which_element
.locator
.full_name
[0] =
506 element
->which_element
.locator
.proc_name
[0] = (char) 0;
507 element
->which_element
.locator
.line_no
= 0;
508 element
->which_element
.locator
.addr
= 0;
511 memset(element
->which_element
.simple_string
, ' ',
512 sizeof(element
->which_element
.simple_string
));
520 init_win_info (struct tui_win_info
*win_info
)
522 tui_init_generic_part (&win_info
->generic
);
523 win_info
->can_highlight
=
524 win_info
->is_highlighted
= FALSE
;
525 switch (win_info
->generic
.type
)
529 win_info
->detail
.source_info
.execution_info
530 = (struct tui_gen_win_info
*) NULL
;
531 win_info
->detail
.source_info
.has_locator
= FALSE
;
532 win_info
->detail
.source_info
.horizontal_offset
= 0;
533 win_info
->detail
.source_info
.gdbarch
= NULL
;
534 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
535 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
536 win_info
->detail
.source_info
.fullname
= NULL
;
539 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
540 win_info
->detail
.data_display_info
.data_content_count
= 0;
541 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
542 win_info
->detail
.data_display_info
.regs_content_count
= 0;
543 win_info
->detail
.data_display_info
.regs_column_count
= 1;
544 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
545 win_info
->detail
.data_display_info
.current_group
= 0;
550 win_info
->detail
.opaque
= NULL
;
556 struct tui_win_info
*
557 tui_alloc_win_info (enum tui_win_type type
)
559 struct tui_win_info
*win_info
= XNEW (struct tui_win_info
);
561 if (win_info
!= NULL
)
563 win_info
->generic
.type
= type
;
564 init_win_info (win_info
);
571 /* Allocates the content and elements in a block. */
573 tui_alloc_content (int num_elements
, enum tui_win_type type
)
575 tui_win_content content
;
576 char *element_block_ptr
;
579 content
= XNEWVEC (struct tui_win_element
*, num_elements
);
583 * All windows, except the data window, can allocate the
584 * elements in a chunk. The data window cannot because items
585 * can be added/removed from the data display by the user at any
588 if (type
!= DATA_WIN
)
591 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
592 if (element_block_ptr
!= NULL
)
594 for (i
= 0; i
< num_elements
; i
++)
596 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
597 init_content_element (content
[i
], type
);
598 element_block_ptr
+= sizeof (struct tui_win_element
);
604 content
= (tui_win_content
) NULL
;
613 /* Adds the input number of elements to the windows's content. If no
614 content has been allocated yet, alloc_content() is called to do
615 this. The index of the first element added is returned, unless
616 there is a memory allocation error, in which case, (-1) is
619 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
622 struct tui_win_element
*element_ptr
;
625 if (win_info
->content
== NULL
)
627 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
631 index_start
= win_info
->content_size
;
632 if (win_info
->content
!= NULL
)
634 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
636 element_ptr
= XNEW (struct tui_win_element
);
637 if (element_ptr
!= NULL
)
639 win_info
->content
[i
] = (void *) element_ptr
;
640 init_content_element (element_ptr
, win_info
->type
);
641 win_info
->content_size
++;
643 else /* Things must be really hosed now! We ran out of
653 /* Delete all curses windows associated with win_info, leaving
654 everything else intact. */
656 tui_del_window (struct tui_win_info
*win_info
)
658 struct tui_gen_win_info
*generic_win
;
660 switch (win_info
->generic
.type
)
664 generic_win
= tui_locator_win_info_ptr ();
665 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
667 tui_delete_win (generic_win
->handle
);
668 generic_win
->handle
= NULL
;
669 generic_win
->is_visible
= FALSE
;
671 if (win_info
->detail
.source_info
.fullname
)
673 xfree (win_info
->detail
.source_info
.fullname
);
674 win_info
->detail
.source_info
.fullname
= NULL
;
676 generic_win
= win_info
->detail
.source_info
.execution_info
;
677 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
679 tui_delete_win (generic_win
->handle
);
680 generic_win
->handle
= NULL
;
681 generic_win
->is_visible
= FALSE
;
685 if (win_info
->generic
.content
!= NULL
)
687 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
688 win_info
->detail
.data_display_info
.regs_content_count
);
689 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
690 win_info
->detail
.data_display_info
.data_content_count
);
696 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
698 tui_delete_win (win_info
->generic
.handle
);
699 win_info
->generic
.handle
= NULL
;
700 win_info
->generic
.is_visible
= FALSE
;
706 tui_free_window (struct tui_win_info
*win_info
)
708 struct tui_gen_win_info
*generic_win
;
710 switch (win_info
->generic
.type
)
714 if (win_info
->detail
.source_info
.fullname
)
716 xfree (win_info
->detail
.source_info
.fullname
);
717 win_info
->detail
.source_info
.fullname
= NULL
;
719 generic_win
= win_info
->detail
.source_info
.execution_info
;
720 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
722 tui_delete_win (generic_win
->handle
);
723 generic_win
->handle
= NULL
;
724 tui_free_win_content (generic_win
);
728 if (win_info
->generic
.content
!= NULL
)
730 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
731 win_info
->detail
.data_display_info
.regs_content_count
);
732 win_info
->detail
.data_display_info
.regs_content
=
733 (tui_win_content
) NULL
;
734 win_info
->detail
.data_display_info
.regs_content_count
= 0;
735 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
736 win_info
->detail
.data_display_info
.data_content_count
);
737 win_info
->detail
.data_display_info
.data_content
=
738 (tui_win_content
) NULL
;
739 win_info
->detail
.data_display_info
.data_content_count
= 0;
740 win_info
->detail
.data_display_info
.regs_column_count
= 1;
741 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
742 win_info
->generic
.content
= NULL
;
743 win_info
->generic
.content_size
= 0;
749 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
751 tui_delete_win (win_info
->generic
.handle
);
752 win_info
->generic
.handle
= NULL
;
753 tui_free_win_content (&win_info
->generic
);
755 if (win_info
->generic
.title
)
756 xfree (win_info
->generic
.title
);
762 tui_free_all_source_wins_content (void)
766 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
768 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
770 if (win_info
!= NULL
)
772 tui_free_win_content (&(win_info
->generic
));
773 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
780 tui_free_win_content (struct tui_gen_win_info
*win_info
)
782 if (win_info
->content
!= NULL
)
784 free_content ((tui_win_content
) win_info
->content
,
785 win_info
->content_size
,
787 win_info
->content
= NULL
;
789 win_info
->content_size
= 0;
794 tui_del_data_windows (tui_win_content content
,
799 /* Remember that data window content elements are of type struct
800 tui_gen_win_info *, each of which whose single element is a data
802 for (i
= 0; i
< content_size
; i
++)
804 struct tui_gen_win_info
*generic_win
805 = &content
[i
]->which_element
.data_window
;
807 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
809 tui_delete_win (generic_win
->handle
);
810 generic_win
->handle
= NULL
;
811 generic_win
->is_visible
= FALSE
;
818 tui_free_data_content (tui_win_content content
,
823 /* Remember that data window content elements are of type struct
824 tui_gen_win_info *, each of which whose single element is a data
826 for (i
= 0; i
< content_size
; i
++)
828 struct tui_gen_win_info
*generic_win
829 = &content
[i
]->which_element
.data_window
;
831 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
833 tui_delete_win (generic_win
->handle
);
834 generic_win
->handle
= NULL
;
835 tui_free_win_content (generic_win
);
838 free_content (content
,
844 /**********************************
845 ** LOCAL STATIC FUNCTIONS **
846 **********************************/
850 free_content (tui_win_content content
,
852 enum tui_win_type win_type
)
854 if (content
!= (tui_win_content
) NULL
)
856 free_content_elements (content
, content_size
, win_type
);
862 /* free_content_elements().
865 free_content_elements (tui_win_content content
,
867 enum tui_win_type type
)
869 if (content
!= (tui_win_content
) NULL
)
873 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
875 /* Free whole source block. */
876 xfree (content
[0]->which_element
.source
.line
);
880 for (i
= 0; i
< content_size
; i
++)
882 struct tui_win_element
*element
;
884 element
= content
[i
];
885 if (element
!= (struct tui_win_element
*) NULL
)
893 /* Note that data elements are not allocated in
894 a single block, but individually, as
896 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
897 xfree ((void *)element
->which_element
.data
.name
);
898 xfree (element
->which_element
.data
.value
);
899 xfree (element
->which_element
.data
.content
);
903 xfree (element
->which_element
.command
.line
);
911 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
912 xfree (content
[0]); /* Free the element block. */