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 (LOCATOR_WIN
);
40 static struct tui_gen_win_info
source_win (EXEC_INFO_WIN
);
41 static struct tui_gen_win_info
disasm_win (EXEC_INFO_WIN
);
42 static std::vector
<tui_source_window_base
*> source_windows
;
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_auxillary (enum tui_win_type win_type
)
70 return (win_type
> MAX_MAJOR_WINDOWS
);
73 /******************************************
74 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
75 ******************************************/
77 /* Answer a whether the terminal window has been resized or not. */
79 tui_win_resized (void)
85 /* Set a whether the terminal window has been resized or not. */
87 tui_set_win_resized_to (int resized
)
89 win_resized
= resized
;
93 /* Answer a pointer to the current layout definition. */
94 struct tui_layout_def
*
101 /* Answer the window with the logical focus. */
102 struct tui_win_info
*
103 tui_win_with_focus (void)
105 return win_with_focus
;
109 /* Set the window that has the logical focus. */
111 tui_set_win_with_focus (struct tui_win_info
*win_info
)
113 win_with_focus
= win_info
;
117 /* Accessor for the current source window. Usually there is only one
118 source window (either source or disassembly), but both can be
119 displayed at the same time. */
120 std::vector
<tui_source_window_base
*> &
121 tui_source_windows ()
123 return source_windows
;
127 /* Clear the list of source windows. Usually there is only one source
128 window (either source or disassembly), but both can be displayed at
131 tui_clear_source_windows ()
133 source_windows
.clear ();
137 /* Clear the pertinant detail in the source windows. */
139 tui_clear_source_windows_detail ()
141 for (tui_source_window_base
*win
: tui_source_windows ())
142 win
->clear_detail ();
146 /* Add a window to the list of source windows. Usually there is only
147 one source window (either source or disassembly), but both can be
148 displayed at the same time. */
150 tui_add_to_source_windows (struct tui_source_window_base
*win_info
)
152 if (source_windows
.size () < 2)
153 source_windows
.push_back (win_info
);
156 /* See tui-data.h. */
159 tui_source_window_base::clear_detail ()
162 start_line_or_addr
.loa
= LOA_ADDRESS
;
163 start_line_or_addr
.u
.addr
= 0;
164 horizontal_offset
= 0;
167 /* See tui-data.h. */
170 tui_cmd_window::clear_detail ()
172 wmove (handle
, 0, 0);
175 /* See tui-data.h. */
178 tui_data_window::clear_detail ()
181 data_content_count
= 0;
183 regs_content_count
= 0;
184 regs_column_count
= 1;
185 display_regs
= false;
188 /* Accessor for the source execution info ptr. */
189 struct tui_gen_win_info
*
190 tui_source_exec_info_win_ptr (void)
196 /* Accessor for the disassem execution info ptr. */
197 struct tui_gen_win_info
*
198 tui_disassem_exec_info_win_ptr (void)
204 /* Accessor for the locator win info. Answers a pointer to the static
205 locator win info struct. */
206 struct tui_gen_win_info
*
207 tui_locator_win_info_ptr (void)
213 /* Accessor for the term_height. */
215 tui_term_height (void)
221 /* Mutator for the term height. */
223 tui_set_term_height_to (int h
)
229 /* Accessor for the term_width. */
231 tui_term_width (void)
237 /* Mutator for the term_width. */
239 tui_set_term_width_to (int w
)
245 /* Accessor for the current layout. */
247 tui_current_layout (void)
249 return current_layout
;
253 /* Mutator for the current layout. */
255 tui_set_current_layout_to (enum tui_layout_type new_layout
)
257 current_layout
= new_layout
;
261 /*****************************
262 ** OTHER PUBLIC FUNCTIONS
263 *****************************/
266 /* Answer the next window in the list, cycling back to the top if
268 struct tui_win_info
*
269 tui_next_win (struct tui_win_info
*cur_win
)
271 int type
= cur_win
->type
;
272 struct tui_win_info
*next_win
= NULL
;
274 if (cur_win
->type
== CMD_WIN
)
277 type
= cur_win
->type
+ 1;
278 while (type
!= cur_win
->type
&& (next_win
== NULL
))
280 if (tui_win_list
[type
]
281 && tui_win_list
[type
]->is_visible
)
282 next_win
= tui_win_list
[type
];
296 /* Answer the prev window in the list, cycling back to the bottom if
298 struct tui_win_info
*
299 tui_prev_win (struct tui_win_info
*cur_win
)
301 int type
= cur_win
->type
;
302 struct tui_win_info
*prev
= NULL
;
304 if (cur_win
->type
== SRC_WIN
)
307 type
= cur_win
->type
- 1;
308 while (type
!= cur_win
->type
&& (prev
== NULL
))
310 if (tui_win_list
[type
]
311 && tui_win_list
[type
]->is_visible
)
312 prev
= tui_win_list
[type
];
326 /* Answer the window represented by name. */
327 struct tui_win_info
*
328 tui_partial_win_by_name (const char *name
)
330 struct tui_win_info
*win_info
= NULL
;
336 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
338 if (tui_win_list
[i
] != 0)
340 const char *cur_name
= tui_win_name (tui_win_list
[i
]);
342 if (strlen (name
) <= strlen (cur_name
)
343 && startswith (cur_name
, name
))
344 win_info
= tui_win_list
[i
];
354 /* Answer the name of the window. */
356 tui_win_name (const struct tui_gen_win_info
*win_info
)
358 const char *name
= NULL
;
360 switch (win_info
->type
)
369 name
= DISASSEM_NAME
;
384 tui_initialize_static_data (void)
386 tui_init_generic_part (tui_source_exec_info_win_ptr ());
387 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
388 tui_init_generic_part (tui_locator_win_info_ptr ());
393 tui_init_generic_part (struct tui_gen_win_info
*win
)
399 win
->viewport_height
=
401 win
->last_visible_line
= 0;
404 win
->content_in_use
= FALSE
;
405 win
->is_visible
= false;
410 /* init_content_element().
413 init_content_element (struct tui_win_element
*element
,
414 enum tui_win_type type
)
420 element
->which_element
.source
.line
= NULL
;
421 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
422 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
423 element
->which_element
.source
.is_exec_point
= FALSE
;
424 element
->which_element
.source
.has_break
= FALSE
;
427 element
->which_element
.data_window
= new struct tui_gen_win_info (DATA_ITEM_WIN
);
428 element
->which_element
.data_window
->content
=
429 tui_alloc_content (1, DATA_ITEM_WIN
);
430 element
->which_element
.data_window
->content_size
= 1;
433 element
->which_element
.command
.line
= NULL
;
436 element
->which_element
.data
.name
= NULL
;
437 element
->which_element
.data
.type
= TUI_REGISTER
;
438 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
439 element
->which_element
.data
.value
= NULL
;
440 element
->which_element
.data
.highlight
= FALSE
;
441 element
->which_element
.data
.content
= NULL
;
444 element
->which_element
.locator
.full_name
[0] =
445 element
->which_element
.locator
.proc_name
[0] = (char) 0;
446 element
->which_element
.locator
.line_no
= 0;
447 element
->which_element
.locator
.addr
= 0;
450 memset(element
->which_element
.simple_string
, ' ',
451 sizeof(element
->which_element
.simple_string
));
458 tui_win_info::tui_win_info (enum tui_win_type type
)
459 : tui_gen_win_info (type
)
463 tui_source_window_base::tui_source_window_base (enum tui_win_type type
)
464 : tui_win_info (type
)
466 gdb_assert (type
== SRC_WIN
|| type
== DISASSEM_WIN
);
467 start_line_or_addr
.loa
= LOA_ADDRESS
;
468 start_line_or_addr
.u
.addr
= 0;
471 struct tui_win_info
*
472 tui_alloc_win_info (enum tui_win_type type
)
477 return new tui_source_window ();
480 return new tui_disasm_window ();
483 return new tui_data_window ();
486 return new tui_cmd_window ();
489 gdb_assert_not_reached (_("Unhandled window type"));
493 /* Allocates the content and elements in a block. */
495 tui_alloc_content (int num_elements
, enum tui_win_type type
)
497 tui_win_content content
;
498 struct tui_win_element
*element_block_ptr
;
501 content
= XNEWVEC (struct tui_win_element
*, num_elements
);
504 * All windows, except the data window, can allocate the
505 * elements in a chunk. The data window cannot because items
506 * can be added/removed from the data display by the user at any
509 if (type
!= DATA_WIN
)
511 element_block_ptr
= XNEWVEC (struct tui_win_element
, num_elements
);
512 for (i
= 0; i
< num_elements
; i
++)
514 content
[i
] = element_block_ptr
;
515 init_content_element (content
[i
], type
);
524 /* Adds the input number of elements to the windows's content. If no
525 content has been allocated yet, alloc_content() is called to do
526 this. The index of the first element added is returned, unless
527 there is a memory allocation error, in which case, (-1) is
530 tui_add_content_elements (struct tui_gen_win_info
*win_info
,
533 struct tui_win_element
*element_ptr
;
536 if (win_info
->content
== NULL
)
538 win_info
->content
= tui_alloc_content (num_elements
, win_info
->type
);
542 index_start
= win_info
->content_size
;
543 if (win_info
->content
!= NULL
)
545 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
547 element_ptr
= XNEW (struct tui_win_element
);
548 win_info
->content
[i
] = element_ptr
;
549 init_content_element (element_ptr
, win_info
->type
);
550 win_info
->content_size
++;
557 tui_source_window_base::~tui_source_window_base ()
560 struct tui_gen_win_info
*generic_win
= execution_info
;
561 if (generic_win
!= NULL
)
563 tui_delete_win (generic_win
->handle
);
564 generic_win
->handle
= NULL
;
565 tui_free_win_content (generic_win
);
569 tui_data_window::~tui_data_window ()
573 tui_free_data_content (regs_content
, regs_content_count
);
575 regs_content_count
= 0;
576 tui_free_data_content (data_content
, data_content_count
);
578 data_content_count
= 0;
579 regs_column_count
= 1;
580 display_regs
= false;
586 tui_win_info::~tui_win_info ()
590 tui_delete_win (handle
);
592 tui_free_win_content (this);
600 tui_free_all_source_wins_content ()
602 for (tui_source_window_base
*win_info
: tui_source_windows ())
604 tui_free_win_content (win_info
);
605 tui_free_win_content (win_info
->execution_info
);
611 tui_free_win_content (struct tui_gen_win_info
*win_info
)
613 if (win_info
->content
!= NULL
)
615 free_content (win_info
->content
,
616 win_info
->content_size
,
618 win_info
->content
= NULL
;
620 win_info
->content_size
= 0;
625 tui_free_data_content (tui_win_content content
,
630 /* Remember that data window content elements are of type struct
631 tui_gen_win_info *, each of which whose single element is a data
633 for (i
= 0; i
< content_size
; i
++)
635 struct tui_gen_win_info
*generic_win
636 = content
[i
]->which_element
.data_window
;
638 if (generic_win
!= NULL
)
640 tui_delete_win (generic_win
->handle
);
641 generic_win
->handle
= NULL
;
642 tui_free_win_content (generic_win
);
645 free_content (content
,
651 /**********************************
652 ** LOCAL STATIC FUNCTIONS **
653 **********************************/
657 free_content (tui_win_content content
,
659 enum tui_win_type win_type
)
663 free_content_elements (content
, content_size
, win_type
);
669 /* free_content_elements().
672 free_content_elements (tui_win_content content
,
674 enum tui_win_type type
)
680 if (type
== DISASSEM_WIN
)
682 /* Free whole source block. */
683 xfree (content
[0]->which_element
.source
.line
);
687 for (i
= 0; i
< content_size
; i
++)
689 struct tui_win_element
*element
;
691 element
= content
[i
];
697 xfree (element
->which_element
.source
.line
);
700 delete element
->which_element
.data_window
;
704 /* Note that data elements are not allocated in
705 a single block, but individually, as
707 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
708 xfree ((void *)element
->which_element
.data
.name
);
709 xfree (element
->which_element
.data
.value
);
710 xfree (element
->which_element
.data
.content
);
714 xfree (element
->which_element
.command
.line
);
722 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
723 xfree (content
[0]); /* Free the element block. */