Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI data manipulation routines. |
f33c6cbf | 2 | |
42a4f53d | 3 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
5 | Contributed by Hewlett-Packard Company. |
6 | ||
7 | This file is part of GDB. | |
8 | ||
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 | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
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. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 21 | |
96ec9981 DJ |
22 | #include "defs.h" |
23 | #include "symtab.h" | |
d7b2e967 AC |
24 | #include "tui/tui.h" |
25 | #include "tui/tui-data.h" | |
26 | #include "tui/tui-wingeneral.h" | |
6a83354a | 27 | #include "gdb_curses.h" |
4e8f7a8b | 28 | |
c906108c SS |
29 | /**************************** |
30 | ** GLOBAL DECLARATIONS | |
31 | ****************************/ | |
7fa29be9 | 32 | struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS]; |
c906108c | 33 | |
c906108c SS |
34 | /*************************** |
35 | ** Private data | |
36 | ****************************/ | |
6ba8e26f AC |
37 | static enum tui_layout_type current_layout = UNDEFINED_LAYOUT; |
38 | static int term_height, term_width; | |
3add462f | 39 | static struct tui_locator_window _locator; |
ad54d15b | 40 | static std::vector<tui_source_window_base *> source_windows; |
e65b5245 | 41 | static struct tui_win_info *win_with_focus = NULL; |
08ef48c5 MS |
42 | static struct tui_layout_def layout_def = { |
43 | SRC_WIN, /* DISPLAY_MODE */ | |
bd7db367 | 44 | }; |
08ef48c5 | 45 | |
6ba8e26f | 46 | static int win_resized = FALSE; |
c906108c SS |
47 | |
48 | ||
c906108c SS |
49 | /********************************* |
50 | ** PUBLIC FUNCTIONS | |
51 | **********************************/ | |
52 | ||
6d012f14 | 53 | int |
6658b1bf | 54 | tui_win_is_auxiliary (enum tui_win_type win_type) |
6d012f14 AC |
55 | { |
56 | return (win_type > MAX_MAJOR_WINDOWS); | |
57 | } | |
58 | ||
c906108c SS |
59 | /****************************************** |
60 | ** ACCESSORS & MUTATORS FOR PRIVATE DATA | |
61 | ******************************************/ | |
62 | ||
1cc6d956 | 63 | /* Answer a whether the terminal window has been resized or not. */ |
c906108c | 64 | int |
dd1abb8c | 65 | tui_win_resized (void) |
c906108c | 66 | { |
6ba8e26f | 67 | return win_resized; |
dd1abb8c | 68 | } |
c906108c SS |
69 | |
70 | ||
1cc6d956 | 71 | /* Set a whether the terminal window has been resized or not. */ |
c906108c | 72 | void |
dd1abb8c | 73 | tui_set_win_resized_to (int resized) |
c906108c | 74 | { |
6ba8e26f | 75 | win_resized = resized; |
dd1abb8c | 76 | } |
c906108c SS |
77 | |
78 | ||
1cc6d956 | 79 | /* Answer a pointer to the current layout definition. */ |
2a8854a7 | 80 | struct tui_layout_def * |
dd1abb8c | 81 | tui_layout_def (void) |
c906108c | 82 | { |
6ba8e26f | 83 | return &layout_def; |
dd1abb8c | 84 | } |
c906108c SS |
85 | |
86 | ||
1cc6d956 | 87 | /* Answer the window with the logical focus. */ |
2a8854a7 | 88 | struct tui_win_info * |
dd1abb8c | 89 | tui_win_with_focus (void) |
c906108c | 90 | { |
6ba8e26f | 91 | return win_with_focus; |
dd1abb8c | 92 | } |
c906108c SS |
93 | |
94 | ||
1cc6d956 | 95 | /* Set the window that has the logical focus. */ |
c906108c | 96 | void |
5b6fe301 | 97 | tui_set_win_with_focus (struct tui_win_info *win_info) |
c906108c | 98 | { |
6ba8e26f | 99 | win_with_focus = win_info; |
dd1abb8c | 100 | } |
c906108c SS |
101 | |
102 | ||
6ba8e26f AC |
103 | /* Accessor for the current source window. Usually there is only one |
104 | source window (either source or disassembly), but both can be | |
105 | displayed at the same time. */ | |
ad54d15b | 106 | std::vector<tui_source_window_base *> & |
b4eb2452 | 107 | tui_source_windows () |
c906108c | 108 | { |
b4eb2452 | 109 | return source_windows; |
dd1abb8c | 110 | } |
c906108c SS |
111 | |
112 | ||
dd1abb8c AC |
113 | /* Clear the list of source windows. Usually there is only one source |
114 | window (either source or disassembly), but both can be displayed at | |
115 | the same time. */ | |
c906108c | 116 | void |
b4eb2452 | 117 | tui_clear_source_windows () |
c906108c | 118 | { |
b4eb2452 | 119 | source_windows.clear (); |
dd1abb8c | 120 | } |
c906108c SS |
121 | |
122 | ||
1cc6d956 | 123 | /* Clear the pertinant detail in the source windows. */ |
c906108c | 124 | void |
b4eb2452 | 125 | tui_clear_source_windows_detail () |
c906108c | 126 | { |
ad54d15b | 127 | for (tui_source_window_base *win : tui_source_windows ()) |
7778b912 | 128 | win->clear_detail (); |
dd1abb8c | 129 | } |
c906108c SS |
130 | |
131 | ||
dd1abb8c AC |
132 | /* Add a window to the list of source windows. Usually there is only |
133 | one source window (either source or disassembly), but both can be | |
134 | displayed at the same time. */ | |
c906108c | 135 | void |
ad54d15b | 136 | tui_add_to_source_windows (struct tui_source_window_base *win_info) |
c906108c | 137 | { |
b4eb2452 TT |
138 | if (source_windows.size () < 2) |
139 | source_windows.push_back (win_info); | |
dd1abb8c | 140 | } |
c906108c | 141 | |
8761a91b TT |
142 | /* See tui-data.h. */ |
143 | ||
144 | void | |
5cf82909 | 145 | tui_source_window_base::clear_detail () |
8761a91b | 146 | { |
e6e41501 TT |
147 | gdbarch = NULL; |
148 | start_line_or_addr.loa = LOA_ADDRESS; | |
149 | start_line_or_addr.u.addr = 0; | |
150 | horizontal_offset = 0; | |
8761a91b TT |
151 | } |
152 | ||
153 | /* See tui-data.h. */ | |
154 | ||
155 | void | |
156 | tui_cmd_window::clear_detail () | |
157 | { | |
cb2ce893 | 158 | wmove (handle, 0, 0); |
8761a91b TT |
159 | } |
160 | ||
161 | /* See tui-data.h. */ | |
162 | ||
163 | void | |
164 | tui_data_window::clear_detail () | |
165 | { | |
21e1c91e | 166 | regs_content.clear (); |
238eb706 | 167 | regs_column_count = 1; |
ceb13a13 | 168 | display_regs = false; |
8761a91b | 169 | } |
c906108c | 170 | |
dd1abb8c AC |
171 | /* Accessor for the locator win info. Answers a pointer to the static |
172 | locator win info struct. */ | |
3add462f | 173 | struct tui_locator_window * |
dd1abb8c | 174 | tui_locator_win_info_ptr (void) |
c906108c SS |
175 | { |
176 | return &_locator; | |
2a8854a7 | 177 | } |
c906108c SS |
178 | |
179 | ||
6ba8e26f | 180 | /* Accessor for the term_height. */ |
c906108c | 181 | int |
dd1abb8c | 182 | tui_term_height (void) |
c906108c | 183 | { |
6ba8e26f | 184 | return term_height; |
dd1abb8c | 185 | } |
c906108c SS |
186 | |
187 | ||
1cc6d956 | 188 | /* Mutator for the term height. */ |
c906108c | 189 | void |
dd1abb8c | 190 | tui_set_term_height_to (int h) |
c906108c | 191 | { |
6ba8e26f | 192 | term_height = h; |
dd1abb8c | 193 | } |
c906108c SS |
194 | |
195 | ||
1cc6d956 | 196 | /* Accessor for the term_width. */ |
c906108c | 197 | int |
dd1abb8c | 198 | tui_term_width (void) |
c906108c | 199 | { |
6ba8e26f | 200 | return term_width; |
dd1abb8c | 201 | } |
c906108c SS |
202 | |
203 | ||
6ba8e26f | 204 | /* Mutator for the term_width. */ |
c906108c | 205 | void |
dd1abb8c | 206 | tui_set_term_width_to (int w) |
c906108c | 207 | { |
6ba8e26f | 208 | term_width = w; |
dd1abb8c | 209 | } |
c906108c SS |
210 | |
211 | ||
1cc6d956 | 212 | /* Accessor for the current layout. */ |
2a8854a7 | 213 | enum tui_layout_type |
dd1abb8c | 214 | tui_current_layout (void) |
c906108c | 215 | { |
6ba8e26f | 216 | return current_layout; |
dd1abb8c | 217 | } |
c906108c SS |
218 | |
219 | ||
dd1abb8c | 220 | /* Mutator for the current layout. */ |
c906108c | 221 | void |
6ba8e26f | 222 | tui_set_current_layout_to (enum tui_layout_type new_layout) |
c906108c | 223 | { |
6ba8e26f | 224 | current_layout = new_layout; |
dd1abb8c | 225 | } |
c906108c SS |
226 | |
227 | ||
c906108c SS |
228 | /***************************** |
229 | ** OTHER PUBLIC FUNCTIONS | |
230 | *****************************/ | |
231 | ||
232 | ||
dd1abb8c AC |
233 | /* Answer the next window in the list, cycling back to the top if |
234 | necessary. */ | |
2a8854a7 | 235 | struct tui_win_info * |
5b6fe301 | 236 | tui_next_win (struct tui_win_info *cur_win) |
c906108c | 237 | { |
cb2ce893 | 238 | int type = cur_win->type; |
e65b5245 | 239 | struct tui_win_info *next_win = NULL; |
c906108c | 240 | |
cb2ce893 | 241 | if (cur_win->type == CMD_WIN) |
c906108c SS |
242 | type = SRC_WIN; |
243 | else | |
cb2ce893 TT |
244 | type = cur_win->type + 1; |
245 | while (type != cur_win->type && (next_win == NULL)) | |
c906108c | 246 | { |
e5908723 | 247 | if (tui_win_list[type] |
cb2ce893 | 248 | && tui_win_list[type]->is_visible) |
6ba8e26f | 249 | next_win = tui_win_list[type]; |
c906108c SS |
250 | else |
251 | { | |
252 | if (type == CMD_WIN) | |
253 | type = SRC_WIN; | |
254 | else | |
255 | type++; | |
256 | } | |
257 | } | |
258 | ||
6ba8e26f AC |
259 | return next_win; |
260 | } | |
c906108c SS |
261 | |
262 | ||
dd1abb8c AC |
263 | /* Answer the prev window in the list, cycling back to the bottom if |
264 | necessary. */ | |
2a8854a7 | 265 | struct tui_win_info * |
5b6fe301 | 266 | tui_prev_win (struct tui_win_info *cur_win) |
c906108c | 267 | { |
cb2ce893 | 268 | int type = cur_win->type; |
e65b5245 | 269 | struct tui_win_info *prev = NULL; |
c906108c | 270 | |
cb2ce893 | 271 | if (cur_win->type == SRC_WIN) |
c906108c SS |
272 | type = CMD_WIN; |
273 | else | |
cb2ce893 TT |
274 | type = cur_win->type - 1; |
275 | while (type != cur_win->type && (prev == NULL)) | |
c906108c | 276 | { |
37715c4c | 277 | if (tui_win_list[type] |
cb2ce893 | 278 | && tui_win_list[type]->is_visible) |
6d012f14 | 279 | prev = tui_win_list[type]; |
c906108c SS |
280 | else |
281 | { | |
282 | if (type == SRC_WIN) | |
283 | type = CMD_WIN; | |
284 | else | |
285 | type--; | |
286 | } | |
287 | } | |
288 | ||
289 | return prev; | |
cb50eddd | 290 | } |
c906108c SS |
291 | |
292 | ||
1cc6d956 | 293 | /* Answer the window represented by name. */ |
2a8854a7 | 294 | struct tui_win_info * |
a121b7c1 | 295 | tui_partial_win_by_name (const char *name) |
c906108c | 296 | { |
e65b5245 | 297 | struct tui_win_info *win_info = NULL; |
c906108c | 298 | |
63a33118 | 299 | if (name != NULL) |
c906108c SS |
300 | { |
301 | int i = 0; | |
302 | ||
6d012f14 | 303 | while (i < MAX_MAJOR_WINDOWS && win_info == NULL) |
c906108c | 304 | { |
6d012f14 | 305 | if (tui_win_list[i] != 0) |
a4b99e53 | 306 | { |
152f3f4b | 307 | const char *cur_name = tui_win_list[i]->name (); |
1c5313c5 | 308 | |
e5908723 | 309 | if (strlen (name) <= strlen (cur_name) |
61012eef | 310 | && startswith (cur_name, name)) |
6d012f14 | 311 | win_info = tui_win_list[i]; |
a4b99e53 | 312 | } |
c906108c SS |
313 | i++; |
314 | } | |
315 | } | |
316 | ||
6d012f14 | 317 | return win_info; |
6ba8e26f | 318 | } |
c906108c SS |
319 | |
320 | ||
c906108c | 321 | void |
31ca4723 | 322 | tui_initialize_static_data () |
c906108c | 323 | { |
31ca4723 | 324 | tui_gen_win_info *win = tui_locator_win_info_ptr (); |
c906108c SS |
325 | win->width = |
326 | win->height = | |
327 | win->origin.x = | |
328 | win->origin.y = | |
6d012f14 | 329 | win->viewport_height = |
6d012f14 | 330 | win->last_visible_line = 0; |
e65b5245 | 331 | win->handle = NULL; |
56122977 TT |
332 | win->content_in_use = FALSE; |
333 | win->is_visible = false; | |
bc6b7f04 SC |
334 | win->title = 0; |
335 | } | |
c906108c SS |
336 | |
337 | ||
33b906ab | 338 | tui_win_info::tui_win_info (enum tui_win_type type) |
cb2ce893 | 339 | : tui_gen_win_info (type) |
c906108c | 340 | { |
6ba8e26f | 341 | } |
c906108c | 342 | |
5cf82909 | 343 | tui_source_window_base::tui_source_window_base (enum tui_win_type type) |
33b906ab TT |
344 | : tui_win_info (type) |
345 | { | |
346 | gdb_assert (type == SRC_WIN || type == DISASSEM_WIN); | |
e6e41501 TT |
347 | start_line_or_addr.loa = LOA_ADDRESS; |
348 | start_line_or_addr.u.addr = 0; | |
33b906ab TT |
349 | } |
350 | ||
f936bca2 | 351 | tui_gen_win_info::~tui_gen_win_info () |
c906108c | 352 | { |
f936bca2 | 353 | if (handle != NULL) |
ee1d42d6 | 354 | { |
f936bca2 TT |
355 | tui_delete_win (handle); |
356 | handle = NULL; | |
ee1d42d6 | 357 | } |
f936bca2 TT |
358 | xfree (title); |
359 | } | |
360 | ||
361 | tui_source_window_base::~tui_source_window_base () | |
362 | { | |
363 | xfree (fullname); | |
364 | delete execution_info; | |
ee1d42d6 | 365 | } |
c906108c | 366 | |
c906108c SS |
367 | /********************************** |
368 | ** LOCAL STATIC FUNCTIONS ** | |
369 | **********************************/ | |
370 | ||
371 | ||
41bcff7f TT |
372 | tui_data_item_window::~tui_data_item_window () |
373 | { | |
41bcff7f TT |
374 | xfree (value); |
375 | xfree (content); | |
376 | } |