1 /* TUI data manipulation routines.
3 Copyright (C) 1998-2019 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 struct tui_win_info
*win_with_focus
= NULL
;
44 static struct tui_layout_def layout_def
= {
45 SRC_WIN
, /* DISPLAY_MODE */
48 static int win_resized
= FALSE
;
51 /*********************************
52 ** Static function forward decls
53 **********************************/
54 static void free_content (tui_win_content
,
57 static void free_content_elements (tui_win_content
,
63 /*********************************
65 **********************************/
68 tui_win_is_source_type (enum tui_win_type win_type
)
70 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
74 tui_win_is_auxillary (enum tui_win_type win_type
)
76 return (win_type
> MAX_MAJOR_WINDOWS
);
80 tui_win_has_locator (struct tui_win_info
*win_info
)
82 return (win_info
!= NULL
83 && win_info
->detail
.source_info
.has_locator
);
87 tui_set_win_highlight (struct tui_win_info
*win_info
,
91 win_info
->is_highlighted
= highlight
;
94 /******************************************
95 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
96 ******************************************/
98 /* Answer a whether the terminal window has been resized or not. */
100 tui_win_resized (void)
106 /* Set a whether the terminal window has been resized or not. */
108 tui_set_win_resized_to (int resized
)
110 win_resized
= resized
;
114 /* Answer a pointer to the current layout definition. */
115 struct tui_layout_def
*
116 tui_layout_def (void)
122 /* Answer the window with the logical focus. */
123 struct tui_win_info
*
124 tui_win_with_focus (void)
126 return win_with_focus
;
130 /* Set the window that has the logical focus. */
132 tui_set_win_with_focus (struct tui_win_info
*win_info
)
134 win_with_focus
= win_info
;
138 /* Accessor for the current source window. Usually there is only one
139 source window (either source or disassembly), but both can be
140 displayed at the same time. */
142 tui_source_windows (void)
144 return &source_windows
;
148 /* Clear the list of source windows. Usually there is only one source
149 window (either source or disassembly), but both can be displayed at
152 tui_clear_source_windows (void)
154 source_windows
.list
[0] = NULL
;
155 source_windows
.list
[1] = NULL
;
156 source_windows
.count
= 0;
160 /* Clear the pertinant detail in the source windows. */
162 tui_clear_source_windows_detail (void)
166 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
167 tui_clear_win_detail ((tui_source_windows ())->list
[i
]);
171 /* Add a window to the list of source windows. Usually there is only
172 one source window (either source or disassembly), but both can be
173 displayed at the same time. */
175 tui_add_to_source_windows (struct tui_win_info
*win_info
)
177 if (source_windows
.count
< 2)
178 source_windows
.list
[source_windows
.count
++] = win_info
;
182 /* Clear the pertinant detail in the windows. */
184 tui_clear_win_detail (struct tui_win_info
*win_info
)
186 if (win_info
!= NULL
)
188 switch (win_info
->generic
.type
)
192 win_info
->detail
.source_info
.gdbarch
= NULL
;
193 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
194 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
195 win_info
->detail
.source_info
.horizontal_offset
= 0;
198 wmove (win_info
->generic
.handle
, 0, 0);
201 win_info
->detail
.data_display_info
.data_content
= NULL
;
202 win_info
->detail
.data_display_info
.data_content_count
= 0;
203 win_info
->detail
.data_display_info
.regs_content
= NULL
;
204 win_info
->detail
.data_display_info
.regs_content_count
= 0;
205 win_info
->detail
.data_display_info
.regs_column_count
= 1;
206 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
215 /* Accessor for the source execution info ptr. */
216 struct tui_gen_win_info
*
217 tui_source_exec_info_win_ptr (void)
219 return &exec_info
[0];
223 /* Accessor for the disassem execution info ptr. */
224 struct tui_gen_win_info
*
225 tui_disassem_exec_info_win_ptr (void)
227 return &exec_info
[1];
231 /* Accessor for the locator win info. Answers a pointer to the static
232 locator win info struct. */
233 struct tui_gen_win_info
*
234 tui_locator_win_info_ptr (void)
240 /* Accessor for the term_height. */
242 tui_term_height (void)
248 /* Mutator for the term height. */
250 tui_set_term_height_to (int h
)
256 /* Accessor for the term_width. */
258 tui_term_width (void)
264 /* Mutator for the term_width. */
266 tui_set_term_width_to (int w
)
272 /* Accessor for the current layout. */
274 tui_current_layout (void)
276 return current_layout
;
280 /* Mutator for the current layout. */
282 tui_set_current_layout_to (enum tui_layout_type new_layout
)
284 current_layout
= new_layout
;
288 /*****************************
289 ** OTHER PUBLIC FUNCTIONS
290 *****************************/
293 /* Answer the next window in the list, cycling back to the top if
295 struct tui_win_info
*
296 tui_next_win (struct tui_win_info
*cur_win
)
298 int type
= cur_win
->generic
.type
;
299 struct tui_win_info
*next_win
= NULL
;
301 if (cur_win
->generic
.type
== CMD_WIN
)
304 type
= cur_win
->generic
.type
+ 1;
305 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
307 if (tui_win_list
[type
]
308 && tui_win_list
[type
]->generic
.is_visible
)
309 next_win
= tui_win_list
[type
];
323 /* Answer the prev window in the list, cycling back to the bottom if
325 struct tui_win_info
*
326 tui_prev_win (struct tui_win_info
*cur_win
)
328 int type
= cur_win
->generic
.type
;
329 struct tui_win_info
*prev
= NULL
;
331 if (cur_win
->generic
.type
== SRC_WIN
)
334 type
= cur_win
->generic
.type
- 1;
335 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
337 if (tui_win_list
[type
]
338 && tui_win_list
[type
]->generic
.is_visible
)
339 prev
= tui_win_list
[type
];
353 /* Answer the window represented by name. */
354 struct tui_win_info
*
355 tui_partial_win_by_name (const char *name
)
357 struct tui_win_info
*win_info
= NULL
;
363 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
365 if (tui_win_list
[i
] != 0)
367 const char *cur_name
=
368 tui_win_name (&tui_win_list
[i
]->generic
);
370 if (strlen (name
) <= strlen (cur_name
)
371 && startswith (cur_name
, name
))
372 win_info
= tui_win_list
[i
];
382 /* Answer the name of the window. */
384 tui_win_name (const struct tui_gen_win_info
*win_info
)
386 const char *name
= NULL
;
388 switch (win_info
->type
)
397 name
= DISASSEM_NAME
;
412 tui_initialize_static_data (void)
414 tui_init_generic_part (tui_source_exec_info_win_ptr ());
415 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
416 tui_init_generic_part (tui_locator_win_info_ptr ());
420 struct tui_gen_win_info
*
421 tui_alloc_generic_win_info (void)
423 struct tui_gen_win_info
*win
= XNEW (struct tui_gen_win_info
);
425 tui_init_generic_part (win
);
432 tui_init_generic_part (struct tui_gen_win_info
*win
)
438 win
->viewport_height
=
440 win
->last_visible_line
= 0;
443 win
->content_in_use
=
444 win
->is_visible
= FALSE
;
449 /* init_content_element().
452 init_content_element (struct tui_win_element
*element
,
453 enum tui_win_type type
)
459 element
->which_element
.source
.line
= NULL
;
460 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
461 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
462 element
->which_element
.source
.is_exec_point
= FALSE
;
463 element
->which_element
.source
.has_break
= FALSE
;
466 tui_init_generic_part (&element
->which_element
.data_window
);
467 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
468 element
->which_element
.data_window
.content
=
469 tui_alloc_content (1, DATA_ITEM_WIN
);
470 element
->which_element
.data_window
.content_size
= 1;
473 element
->which_element
.command
.line
= NULL
;
476 element
->which_element
.data
.name
= NULL
;
477 element
->which_element
.data
.type
= TUI_REGISTER
;
478 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
479 element
->which_element
.data
.value
= NULL
;
480 element
->which_element
.data
.highlight
= FALSE
;
481 element
->which_element
.data
.content
= NULL
;
484 element
->which_element
.locator
.full_name
[0] =
485 element
->which_element
.locator
.proc_name
[0] = (char) 0;
486 element
->which_element
.locator
.line_no
= 0;
487 element
->which_element
.locator
.addr
= 0;
490 memset(element
->which_element
.simple_string
, ' ',
491 sizeof(element
->which_element
.simple_string
));
499 init_win_info (struct tui_win_info
*win_info
)
501 tui_init_generic_part (&win_info
->generic
);
502 win_info
->can_highlight
=
503 win_info
->is_highlighted
= FALSE
;
504 switch (win_info
->generic
.type
)
508 win_info
->detail
.source_info
.execution_info
= NULL
;
509 win_info
->detail
.source_info
.has_locator
= FALSE
;
510 win_info
->detail
.source_info
.horizontal_offset
= 0;
511 win_info
->detail
.source_info
.gdbarch
= NULL
;
512 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
513 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
514 win_info
->detail
.source_info
.fullname
= NULL
;
517 win_info
->detail
.data_display_info
.data_content
= NULL
;
518 win_info
->detail
.data_display_info
.data_content_count
= 0;
519 win_info
->detail
.data_display_info
.regs_content
= NULL
;
520 win_info
->detail
.data_display_info
.regs_content_count
= 0;
521 win_info
->detail
.data_display_info
.regs_column_count
= 1;
522 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
523 win_info
->detail
.data_display_info
.current_group
= 0;
531 struct tui_win_info
*
532 tui_alloc_win_info (enum tui_win_type type
)
534 struct tui_win_info
*win_info
= XNEW (struct tui_win_info
);
536 win_info
->generic
.type
= type
;
537 init_win_info (win_info
);
543 /* Allocates the content and elements in a block. */
545 tui_alloc_content (int num_elements
, enum tui_win_type type
)
547 tui_win_content content
;
548 struct tui_win_element
*element_block_ptr
;
551 content
= XNEWVEC (struct tui_win_element
*, num_elements
);
554 * All windows, except the data window, can allocate the
555 * elements in a chunk. The data window cannot because items
556 * can be added/removed from the data display by the user at any
559 if (type
!= DATA_WIN
)
561 element_block_ptr
= XNEWVEC (struct tui_win_element
, num_elements
);
562 for (i
= 0; i
< num_elements
; i
++)
564 content
[i
] = element_block_ptr
;
565 init_content_element (content
[i
], type
);
574 /* Adds the input number of elements to the windows's content. If no
575 content has been allocated yet, alloc_content() is called to do
576 this. The index of the first element added is returned, unless
577 there is a memory allocation error, in which case, (-1) is
580 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
583 struct tui_win_element
*element_ptr
;
586 if (win_info
->content
== NULL
)
588 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
592 index_start
= win_info
->content_size
;
593 if (win_info
->content
!= NULL
)
595 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
597 element_ptr
= XNEW (struct tui_win_element
);
598 win_info
->content
[i
] = element_ptr
;
599 init_content_element (element_ptr
, win_info
->type
);
600 win_info
->content_size
++;
608 tui_free_window (struct tui_win_info
*win_info
)
610 struct tui_gen_win_info
*generic_win
;
612 switch (win_info
->generic
.type
)
616 if (win_info
->detail
.source_info
.fullname
)
618 xfree (win_info
->detail
.source_info
.fullname
);
619 win_info
->detail
.source_info
.fullname
= NULL
;
621 generic_win
= win_info
->detail
.source_info
.execution_info
;
622 if (generic_win
!= NULL
)
624 tui_delete_win (generic_win
->handle
);
625 generic_win
->handle
= NULL
;
626 tui_free_win_content (generic_win
);
630 if (win_info
->generic
.content
!= NULL
)
632 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
633 win_info
->detail
.data_display_info
.regs_content_count
);
634 win_info
->detail
.data_display_info
.regs_content
= NULL
;
635 win_info
->detail
.data_display_info
.regs_content_count
= 0;
636 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
637 win_info
->detail
.data_display_info
.data_content_count
);
638 win_info
->detail
.data_display_info
.data_content
= NULL
;
639 win_info
->detail
.data_display_info
.data_content_count
= 0;
640 win_info
->detail
.data_display_info
.regs_column_count
= 1;
641 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
642 win_info
->generic
.content
= NULL
;
643 win_info
->generic
.content_size
= 0;
649 if (win_info
->generic
.handle
!= NULL
)
651 tui_delete_win (win_info
->generic
.handle
);
652 win_info
->generic
.handle
= NULL
;
653 tui_free_win_content (&win_info
->generic
);
655 if (win_info
->generic
.title
)
656 xfree (win_info
->generic
.title
);
662 tui_free_all_source_wins_content (void)
666 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
668 struct tui_win_info
*win_info
= (tui_source_windows ())->list
[i
];
670 if (win_info
!= NULL
)
672 tui_free_win_content (&(win_info
->generic
));
673 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
680 tui_free_win_content (struct tui_gen_win_info
*win_info
)
682 if (win_info
->content
!= NULL
)
684 free_content (win_info
->content
,
685 win_info
->content_size
,
687 win_info
->content
= NULL
;
689 win_info
->content_size
= 0;
694 tui_free_data_content (tui_win_content content
,
699 /* Remember that data window content elements are of type struct
700 tui_gen_win_info *, each of which whose single element is a data
702 for (i
= 0; i
< content_size
; i
++)
704 struct tui_gen_win_info
*generic_win
705 = &content
[i
]->which_element
.data_window
;
707 if (generic_win
!= NULL
)
709 tui_delete_win (generic_win
->handle
);
710 generic_win
->handle
= NULL
;
711 tui_free_win_content (generic_win
);
714 free_content (content
,
720 /**********************************
721 ** LOCAL STATIC FUNCTIONS **
722 **********************************/
726 free_content (tui_win_content content
,
728 enum tui_win_type win_type
)
732 free_content_elements (content
, content_size
, win_type
);
738 /* free_content_elements().
741 free_content_elements (tui_win_content content
,
743 enum tui_win_type type
)
749 if (type
== DISASSEM_WIN
)
751 /* Free whole source block. */
752 xfree (content
[0]->which_element
.source
.line
);
756 for (i
= 0; i
< content_size
; i
++)
758 struct tui_win_element
*element
;
760 element
= content
[i
];
766 xfree (element
->which_element
.source
.line
);
772 /* Note that data elements are not allocated in
773 a single block, but individually, as
775 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
776 xfree ((void *)element
->which_element
.data
.name
);
777 xfree (element
->which_element
.data
.value
);
778 xfree (element
->which_element
.data
.content
);
782 xfree (element
->which_element
.command
.line
);
790 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
791 xfree (content
[0]); /* Free the element block. */