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 */
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 win_info
->detail
.command_info
.cur_line
=
216 win_info
->detail
.command_info
.curch
= 0;
219 win_info
->detail
.data_display_info
.data_content
=
220 (tui_win_content
) NULL
;
221 win_info
->detail
.data_display_info
.data_content_count
= 0;
222 win_info
->detail
.data_display_info
.regs_content
=
223 (tui_win_content
) NULL
;
224 win_info
->detail
.data_display_info
.regs_content_count
= 0;
225 win_info
->detail
.data_display_info
.regs_column_count
= 1;
226 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
235 /* Accessor for the source execution info ptr. */
236 struct tui_gen_win_info
*
237 tui_source_exec_info_win_ptr (void)
239 return &exec_info
[0];
243 /* Accessor for the disassem execution info ptr. */
244 struct tui_gen_win_info
*
245 tui_disassem_exec_info_win_ptr (void)
247 return &exec_info
[1];
251 /* Accessor for the locator win info. Answers a pointer to the static
252 locator win info struct. */
253 struct tui_gen_win_info
*
254 tui_locator_win_info_ptr (void)
260 /* Accessor for the term_height. */
262 tui_term_height (void)
268 /* Mutator for the term height. */
270 tui_set_term_height_to (int h
)
276 /* Accessor for the term_width. */
278 tui_term_width (void)
284 /* Mutator for the term_width. */
286 tui_set_term_width_to (int w
)
292 /* Accessor for the current layout. */
294 tui_current_layout (void)
296 return current_layout
;
300 /* Mutator for the current layout. */
302 tui_set_current_layout_to (enum tui_layout_type new_layout
)
304 current_layout
= new_layout
;
308 /*****************************
309 ** OTHER PUBLIC FUNCTIONS
310 *****************************/
313 /* Answer the next window in the list, cycling back to the top if
315 struct tui_win_info
*
316 tui_next_win (struct tui_win_info
*cur_win
)
318 int type
= cur_win
->generic
.type
;
319 struct tui_win_info
*next_win
= (struct tui_win_info
*) NULL
;
321 if (cur_win
->generic
.type
== CMD_WIN
)
324 type
= cur_win
->generic
.type
+ 1;
325 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
327 if (tui_win_list
[type
]
328 && tui_win_list
[type
]->generic
.is_visible
)
329 next_win
= tui_win_list
[type
];
343 /* Answer the prev window in the list, cycling back to the bottom if
345 struct tui_win_info
*
346 tui_prev_win (struct tui_win_info
*cur_win
)
348 int type
= cur_win
->generic
.type
;
349 struct tui_win_info
*prev
= (struct tui_win_info
*) NULL
;
351 if (cur_win
->generic
.type
== SRC_WIN
)
354 type
= cur_win
->generic
.type
- 1;
355 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
357 if (tui_win_list
[type
]
358 && tui_win_list
[type
]->generic
.is_visible
)
359 prev
= tui_win_list
[type
];
373 /* Answer the window represented by name. */
374 struct tui_win_info
*
375 tui_partial_win_by_name (char *name
)
377 struct tui_win_info
*win_info
= (struct tui_win_info
*) NULL
;
379 if (name
!= (char *) NULL
)
383 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
385 if (tui_win_list
[i
] != 0)
387 const char *cur_name
=
388 tui_win_name (&tui_win_list
[i
]->generic
);
390 if (strlen (name
) <= strlen (cur_name
)
391 && startswith (cur_name
, name
))
392 win_info
= tui_win_list
[i
];
402 /* Answer the name of the window. */
404 tui_win_name (const struct tui_gen_win_info
*win_info
)
406 char *name
= (char *) NULL
;
408 switch (win_info
->type
)
417 name
= DISASSEM_NAME
;
432 tui_initialize_static_data (void)
434 tui_init_generic_part (tui_source_exec_info_win_ptr ());
435 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
436 tui_init_generic_part (tui_locator_win_info_ptr ());
440 struct tui_gen_win_info
*
441 tui_alloc_generic_win_info (void)
443 struct tui_gen_win_info
*win
;
445 if ((win
= XNEW (struct tui_gen_win_info
)) != NULL
)
446 tui_init_generic_part (win
);
453 tui_init_generic_part (struct tui_gen_win_info
*win
)
459 win
->viewport_height
=
461 win
->last_visible_line
= 0;
462 win
->handle
= (WINDOW
*) NULL
;
464 win
->content_in_use
=
465 win
->is_visible
= FALSE
;
470 /* init_content_element().
473 init_content_element (struct tui_win_element
*element
,
474 enum tui_win_type type
)
476 element
->highlight
= FALSE
;
481 element
->which_element
.source
.line
= (char *) NULL
;
482 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
483 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
484 element
->which_element
.source
.is_exec_point
= FALSE
;
485 element
->which_element
.source
.has_break
= FALSE
;
488 tui_init_generic_part (&element
->which_element
.data_window
);
489 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
490 element
->which_element
.data_window
.content
=
491 tui_alloc_content (1, DATA_ITEM_WIN
);
492 element
->which_element
.data_window
.content_size
= 1;
495 element
->which_element
.command
.line
= (char *) NULL
;
498 element
->which_element
.data
.name
= (char *) NULL
;
499 element
->which_element
.data
.type
= TUI_REGISTER
;
500 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
501 element
->which_element
.data
.value
= NULL
;
502 element
->which_element
.data
.highlight
= FALSE
;
503 element
->which_element
.data
.content
= (char*) NULL
;
506 element
->which_element
.locator
.full_name
[0] =
507 element
->which_element
.locator
.proc_name
[0] = (char) 0;
508 element
->which_element
.locator
.line_no
= 0;
509 element
->which_element
.locator
.addr
= 0;
512 memset(element
->which_element
.simple_string
, ' ',
513 sizeof(element
->which_element
.simple_string
));
521 init_win_info (struct tui_win_info
*win_info
)
523 tui_init_generic_part (&win_info
->generic
);
524 win_info
->can_highlight
=
525 win_info
->is_highlighted
= FALSE
;
526 switch (win_info
->generic
.type
)
530 win_info
->detail
.source_info
.execution_info
531 = (struct tui_gen_win_info
*) NULL
;
532 win_info
->detail
.source_info
.has_locator
= FALSE
;
533 win_info
->detail
.source_info
.horizontal_offset
= 0;
534 win_info
->detail
.source_info
.gdbarch
= NULL
;
535 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
536 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
537 win_info
->detail
.source_info
.fullname
= NULL
;
540 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
541 win_info
->detail
.data_display_info
.data_content_count
= 0;
542 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
543 win_info
->detail
.data_display_info
.regs_content_count
= 0;
544 win_info
->detail
.data_display_info
.regs_column_count
= 1;
545 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
546 win_info
->detail
.data_display_info
.current_group
= 0;
549 win_info
->detail
.command_info
.cur_line
= 0;
550 win_info
->detail
.command_info
.curch
= 0;
553 win_info
->detail
.opaque
= NULL
;
559 struct tui_win_info
*
560 tui_alloc_win_info (enum tui_win_type type
)
562 struct tui_win_info
*win_info
;
564 win_info
= XNEW (struct tui_win_info
);
565 if (win_info
!= NULL
)
567 win_info
->generic
.type
= type
;
568 init_win_info (win_info
);
575 /* Allocates the content and elements in a block. */
577 tui_alloc_content (int num_elements
, enum tui_win_type type
)
579 tui_win_content content
;
580 char *element_block_ptr
;
583 content
= xmalloc (sizeof (struct tui_win_element
*) *num_elements
);
587 * All windows, except the data window, can allocate the
588 * elements in a chunk. The data window cannot because items
589 * can be added/removed from the data display by the user at any
592 if (type
!= DATA_WIN
)
595 xmalloc (sizeof (struct tui_win_element
) * num_elements
);
596 if (element_block_ptr
!= NULL
)
598 for (i
= 0; i
< num_elements
; i
++)
600 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
601 init_content_element (content
[i
], type
);
602 element_block_ptr
+= sizeof (struct tui_win_element
);
608 content
= (tui_win_content
) NULL
;
617 /* Adds the input number of elements to the windows's content. If no
618 content has been allocated yet, alloc_content() is called to do
619 this. The index of the first element added is returned, unless
620 there is a memory allocation error, in which case, (-1) is
623 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
626 struct tui_win_element
*element_ptr
;
629 if (win_info
->content
== NULL
)
631 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
635 index_start
= win_info
->content_size
;
636 if (win_info
->content
!= NULL
)
638 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
640 if ((element_ptr
= XNEW (struct tui_win_element
)) != NULL
)
642 win_info
->content
[i
] = (void *) element_ptr
;
643 init_content_element (element_ptr
, win_info
->type
);
644 win_info
->content_size
++;
646 else /* Things must be really hosed now! We ran out of
656 /* Delete all curses windows associated with win_info, leaving
657 everything else intact. */
659 tui_del_window (struct tui_win_info
*win_info
)
661 struct tui_gen_win_info
*generic_win
;
663 switch (win_info
->generic
.type
)
667 generic_win
= tui_locator_win_info_ptr ();
668 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
670 tui_delete_win (generic_win
->handle
);
671 generic_win
->handle
= (WINDOW
*) NULL
;
672 generic_win
->is_visible
= FALSE
;
674 if (win_info
->detail
.source_info
.fullname
)
676 xfree (win_info
->detail
.source_info
.fullname
);
677 win_info
->detail
.source_info
.fullname
= NULL
;
679 generic_win
= win_info
->detail
.source_info
.execution_info
;
680 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
682 tui_delete_win (generic_win
->handle
);
683 generic_win
->handle
= (WINDOW
*) NULL
;
684 generic_win
->is_visible
= FALSE
;
688 if (win_info
->generic
.content
!= NULL
)
690 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
691 win_info
->detail
.data_display_info
.regs_content_count
);
692 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
693 win_info
->detail
.data_display_info
.data_content_count
);
699 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
701 tui_delete_win (win_info
->generic
.handle
);
702 win_info
->generic
.handle
= (WINDOW
*) NULL
;
703 win_info
->generic
.is_visible
= FALSE
;
709 tui_free_window (struct tui_win_info
*win_info
)
711 struct tui_gen_win_info
*generic_win
;
713 switch (win_info
->generic
.type
)
717 if (win_info
->detail
.source_info
.fullname
)
719 xfree (win_info
->detail
.source_info
.fullname
);
720 win_info
->detail
.source_info
.fullname
= NULL
;
722 generic_win
= win_info
->detail
.source_info
.execution_info
;
723 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
725 tui_delete_win (generic_win
->handle
);
726 generic_win
->handle
= (WINDOW
*) NULL
;
727 tui_free_win_content (generic_win
);
731 if (win_info
->generic
.content
!= NULL
)
733 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
734 win_info
->detail
.data_display_info
.regs_content_count
);
735 win_info
->detail
.data_display_info
.regs_content
=
736 (tui_win_content
) NULL
;
737 win_info
->detail
.data_display_info
.regs_content_count
= 0;
738 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
739 win_info
->detail
.data_display_info
.data_content_count
);
740 win_info
->detail
.data_display_info
.data_content
=
741 (tui_win_content
) NULL
;
742 win_info
->detail
.data_display_info
.data_content_count
= 0;
743 win_info
->detail
.data_display_info
.regs_column_count
= 1;
744 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
745 win_info
->generic
.content
= NULL
;
746 win_info
->generic
.content_size
= 0;
752 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
754 tui_delete_win (win_info
->generic
.handle
);
755 win_info
->generic
.handle
= (WINDOW
*) NULL
;
756 tui_free_win_content (&win_info
->generic
);
758 if (win_info
->generic
.title
)
759 xfree (win_info
->generic
.title
);
765 tui_free_all_source_wins_content (void)
769 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
771 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
773 if (win_info
!= NULL
)
775 tui_free_win_content (&(win_info
->generic
));
776 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
783 tui_free_win_content (struct tui_gen_win_info
*win_info
)
785 if (win_info
->content
!= NULL
)
787 free_content ((tui_win_content
) win_info
->content
,
788 win_info
->content_size
,
790 win_info
->content
= NULL
;
792 win_info
->content_size
= 0;
797 tui_del_data_windows (tui_win_content content
,
802 /* Remember that data window content elements are of type struct
803 tui_gen_win_info *, each of which whose single element is a data
805 for (i
= 0; i
< content_size
; i
++)
807 struct tui_gen_win_info
*generic_win
808 = &content
[i
]->which_element
.data_window
;
810 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
812 tui_delete_win (generic_win
->handle
);
813 generic_win
->handle
= (WINDOW
*) NULL
;
814 generic_win
->is_visible
= FALSE
;
821 tui_free_data_content (tui_win_content content
,
826 /* Remember that data window content elements are of type struct
827 tui_gen_win_info *, each of which whose single element is a data
829 for (i
= 0; i
< content_size
; i
++)
831 struct tui_gen_win_info
*generic_win
832 = &content
[i
]->which_element
.data_window
;
834 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
836 tui_delete_win (generic_win
->handle
);
837 generic_win
->handle
= (WINDOW
*) NULL
;
838 tui_free_win_content (generic_win
);
841 free_content (content
,
847 /**********************************
848 ** LOCAL STATIC FUNCTIONS **
849 **********************************/
853 free_content (tui_win_content content
,
855 enum tui_win_type win_type
)
857 if (content
!= (tui_win_content
) NULL
)
859 free_content_elements (content
, content_size
, win_type
);
865 /* free_content_elements().
868 free_content_elements (tui_win_content content
,
870 enum tui_win_type type
)
872 if (content
!= (tui_win_content
) NULL
)
876 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
878 /* Free whole source block. */
879 xfree (content
[0]->which_element
.source
.line
);
883 for (i
= 0; i
< content_size
; i
++)
885 struct tui_win_element
*element
;
887 element
= content
[i
];
888 if (element
!= (struct tui_win_element
*) NULL
)
896 /* Note that data elements are not allocated in
897 a single block, but individually, as
899 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
900 xfree ((void *)element
->which_element
.data
.name
);
901 xfree (element
->which_element
.data
.value
);
902 xfree (element
->which_element
.data
.content
);
906 xfree (element
->which_element
.command
.line
);
914 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
915 xfree (content
[0]); /* Free the element block. */