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_locator_window _locator
;
40 static std::vector
<tui_source_window_base
*> source_windows
;
41 static struct tui_win_info
*win_with_focus
= NULL
;
42 static struct tui_layout_def layout_def
= {
43 SRC_WIN
, /* DISPLAY_MODE */
46 static int win_resized
= FALSE
;
49 /*********************************
50 ** Static function forward decls
51 **********************************/
52 static void free_content (tui_win_content
,
55 static void free_content_elements (tui_win_content
,
61 /*********************************
63 **********************************/
66 tui_win_is_auxillary (enum tui_win_type win_type
)
68 return (win_type
> MAX_MAJOR_WINDOWS
);
71 /******************************************
72 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
73 ******************************************/
75 /* Answer a whether the terminal window has been resized or not. */
77 tui_win_resized (void)
83 /* Set a whether the terminal window has been resized or not. */
85 tui_set_win_resized_to (int resized
)
87 win_resized
= resized
;
91 /* Answer a pointer to the current layout definition. */
92 struct tui_layout_def
*
99 /* Answer the window with the logical focus. */
100 struct tui_win_info
*
101 tui_win_with_focus (void)
103 return win_with_focus
;
107 /* Set the window that has the logical focus. */
109 tui_set_win_with_focus (struct tui_win_info
*win_info
)
111 win_with_focus
= win_info
;
115 /* Accessor for the current source window. Usually there is only one
116 source window (either source or disassembly), but both can be
117 displayed at the same time. */
118 std::vector
<tui_source_window_base
*> &
119 tui_source_windows ()
121 return source_windows
;
125 /* Clear the list of source windows. Usually there is only one source
126 window (either source or disassembly), but both can be displayed at
129 tui_clear_source_windows ()
131 source_windows
.clear ();
135 /* Clear the pertinant detail in the source windows. */
137 tui_clear_source_windows_detail ()
139 for (tui_source_window_base
*win
: tui_source_windows ())
140 win
->clear_detail ();
144 /* Add a window to the list of source windows. Usually there is only
145 one source window (either source or disassembly), but both can be
146 displayed at the same time. */
148 tui_add_to_source_windows (struct tui_source_window_base
*win_info
)
150 if (source_windows
.size () < 2)
151 source_windows
.push_back (win_info
);
154 /* See tui-data.h. */
157 tui_source_window_base::clear_detail ()
160 start_line_or_addr
.loa
= LOA_ADDRESS
;
161 start_line_or_addr
.u
.addr
= 0;
162 horizontal_offset
= 0;
165 /* See tui-data.h. */
168 tui_cmd_window::clear_detail ()
170 wmove (handle
, 0, 0);
173 /* See tui-data.h. */
176 tui_data_window::clear_detail ()
178 regs_content
.clear ();
179 regs_column_count
= 1;
180 display_regs
= false;
183 /* Accessor for the locator win info. Answers a pointer to the static
184 locator win info struct. */
185 struct tui_locator_window
*
186 tui_locator_win_info_ptr (void)
192 /* Accessor for the term_height. */
194 tui_term_height (void)
200 /* Mutator for the term height. */
202 tui_set_term_height_to (int h
)
208 /* Accessor for the term_width. */
210 tui_term_width (void)
216 /* Mutator for the term_width. */
218 tui_set_term_width_to (int w
)
224 /* Accessor for the current layout. */
226 tui_current_layout (void)
228 return current_layout
;
232 /* Mutator for the current layout. */
234 tui_set_current_layout_to (enum tui_layout_type new_layout
)
236 current_layout
= new_layout
;
240 /*****************************
241 ** OTHER PUBLIC FUNCTIONS
242 *****************************/
245 /* Answer the next window in the list, cycling back to the top if
247 struct tui_win_info
*
248 tui_next_win (struct tui_win_info
*cur_win
)
250 int type
= cur_win
->type
;
251 struct tui_win_info
*next_win
= NULL
;
253 if (cur_win
->type
== CMD_WIN
)
256 type
= cur_win
->type
+ 1;
257 while (type
!= cur_win
->type
&& (next_win
== NULL
))
259 if (tui_win_list
[type
]
260 && tui_win_list
[type
]->is_visible
)
261 next_win
= tui_win_list
[type
];
275 /* Answer the prev window in the list, cycling back to the bottom if
277 struct tui_win_info
*
278 tui_prev_win (struct tui_win_info
*cur_win
)
280 int type
= cur_win
->type
;
281 struct tui_win_info
*prev
= NULL
;
283 if (cur_win
->type
== SRC_WIN
)
286 type
= cur_win
->type
- 1;
287 while (type
!= cur_win
->type
&& (prev
== NULL
))
289 if (tui_win_list
[type
]
290 && tui_win_list
[type
]->is_visible
)
291 prev
= tui_win_list
[type
];
305 /* Answer the window represented by name. */
306 struct tui_win_info
*
307 tui_partial_win_by_name (const char *name
)
309 struct tui_win_info
*win_info
= NULL
;
315 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
317 if (tui_win_list
[i
] != 0)
319 const char *cur_name
= tui_win_list
[i
]->name ();
321 if (strlen (name
) <= strlen (cur_name
)
322 && startswith (cur_name
, name
))
323 win_info
= tui_win_list
[i
];
334 tui_initialize_static_data ()
336 tui_gen_win_info
*win
= tui_locator_win_info_ptr ();
341 win
->viewport_height
=
343 win
->last_visible_line
= 0;
346 win
->content_in_use
= FALSE
;
347 win
->is_visible
= false;
352 /* init_content_element().
355 init_content_element (struct tui_win_element
*element
,
356 enum tui_win_type type
)
358 gdb_assert (type
!= EXEC_INFO_WIN
);
359 gdb_assert (type
!= LOCATOR_WIN
);
360 gdb_assert (type
!= CMD_WIN
);
361 gdb_assert (type
!= DATA_ITEM_WIN
);
362 gdb_assert (type
!= DATA_WIN
);
368 element
->which_element
.source
.line
= NULL
;
369 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
370 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
371 element
->which_element
.source
.is_exec_point
= FALSE
;
372 element
->which_element
.source
.has_break
= FALSE
;
379 tui_win_info::tui_win_info (enum tui_win_type type
)
380 : tui_gen_win_info (type
)
384 tui_source_window_base::tui_source_window_base (enum tui_win_type type
)
385 : tui_win_info (type
)
387 gdb_assert (type
== SRC_WIN
|| type
== DISASSEM_WIN
);
388 start_line_or_addr
.loa
= LOA_ADDRESS
;
389 start_line_or_addr
.u
.addr
= 0;
392 /* Allocates the content and elements in a block. */
394 tui_alloc_content (int num_elements
, enum tui_win_type type
)
396 tui_win_content content
;
397 struct tui_win_element
*element_block_ptr
;
400 gdb_assert (type
!= EXEC_INFO_WIN
);
401 gdb_assert (type
!= LOCATOR_WIN
);
403 content
= XNEWVEC (struct tui_win_element
*, num_elements
);
406 * All windows, except the data window, can allocate the
407 * elements in a chunk. The data window cannot because items
408 * can be added/removed from the data display by the user at any
411 if (type
!= DATA_WIN
)
413 element_block_ptr
= XNEWVEC (struct tui_win_element
, num_elements
);
414 for (i
= 0; i
< num_elements
; i
++)
416 content
[i
] = element_block_ptr
;
417 init_content_element (content
[i
], type
);
426 tui_gen_win_info::~tui_gen_win_info ()
430 tui_delete_win (handle
);
432 tui_free_win_content (this);
437 tui_source_window_base::~tui_source_window_base ()
440 delete execution_info
;
443 tui_data_window::~tui_data_window ()
447 regs_column_count
= 1;
448 display_regs
= false;
455 tui_free_all_source_wins_content ()
457 for (tui_source_window_base
*win_info
: tui_source_windows ())
459 tui_free_win_content (win_info
);
460 tui_free_win_content (win_info
->execution_info
);
466 tui_free_win_content (struct tui_gen_win_info
*win_info
)
468 if (win_info
->content
!= NULL
)
470 free_content (win_info
->content
,
471 win_info
->content_size
,
473 win_info
->content
= NULL
;
475 win_info
->content_size
= 0;
479 /**********************************
480 ** LOCAL STATIC FUNCTIONS **
481 **********************************/
485 free_content (tui_win_content content
,
487 enum tui_win_type win_type
)
491 free_content_elements (content
, content_size
, win_type
);
497 tui_data_item_window::~tui_data_item_window ()
503 /* free_content_elements().
506 free_content_elements (tui_win_content content
,
508 enum tui_win_type type
)
514 if (type
== DISASSEM_WIN
)
516 /* Free whole source block. */
517 xfree (content
[0]->which_element
.source
.line
);
521 for (i
= 0; i
< content_size
; i
++)
523 struct tui_win_element
*element
;
525 element
= content
[i
];
531 xfree (element
->which_element
.source
.line
);
539 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
540 xfree (content
[0]); /* Free the element block. */