Use bool for is_exec_point
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
1 /* TUI data manipulation routines.
2
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
4
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "tui/tui.h"
25 #include "tui/tui-data.h"
26 #include "tui/tui-wingeneral.h"
27 #include "gdb_curses.h"
28
29 /****************************
30 ** GLOBAL DECLARATIONS
31 ****************************/
32 struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
33
34 /***************************
35 ** Private data
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 */
44 };
45
46 static int win_resized = FALSE;
47
48
49 /*********************************
50 ** Static function forward decls
51 **********************************/
52 static void free_content (tui_win_content,
53 int,
54 enum tui_win_type);
55 static void free_content_elements (tui_win_content,
56 int,
57 enum tui_win_type);
58
59
60
61 /*********************************
62 ** PUBLIC FUNCTIONS
63 **********************************/
64
65 int
66 tui_win_is_auxiliary (enum tui_win_type win_type)
67 {
68 return (win_type > MAX_MAJOR_WINDOWS);
69 }
70
71 /******************************************
72 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
73 ******************************************/
74
75 /* Answer a whether the terminal window has been resized or not. */
76 int
77 tui_win_resized (void)
78 {
79 return win_resized;
80 }
81
82
83 /* Set a whether the terminal window has been resized or not. */
84 void
85 tui_set_win_resized_to (int resized)
86 {
87 win_resized = resized;
88 }
89
90
91 /* Answer a pointer to the current layout definition. */
92 struct tui_layout_def *
93 tui_layout_def (void)
94 {
95 return &layout_def;
96 }
97
98
99 /* Answer the window with the logical focus. */
100 struct tui_win_info *
101 tui_win_with_focus (void)
102 {
103 return win_with_focus;
104 }
105
106
107 /* Set the window that has the logical focus. */
108 void
109 tui_set_win_with_focus (struct tui_win_info *win_info)
110 {
111 win_with_focus = win_info;
112 }
113
114
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 ()
120 {
121 return source_windows;
122 }
123
124
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
127 the same time. */
128 void
129 tui_clear_source_windows ()
130 {
131 source_windows.clear ();
132 }
133
134
135 /* Clear the pertinant detail in the source windows. */
136 void
137 tui_clear_source_windows_detail ()
138 {
139 for (tui_source_window_base *win : tui_source_windows ())
140 win->clear_detail ();
141 }
142
143
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. */
147 void
148 tui_add_to_source_windows (struct tui_source_window_base *win_info)
149 {
150 if (source_windows.size () < 2)
151 source_windows.push_back (win_info);
152 }
153
154 /* See tui-data.h. */
155
156 void
157 tui_source_window_base::clear_detail ()
158 {
159 gdbarch = NULL;
160 start_line_or_addr.loa = LOA_ADDRESS;
161 start_line_or_addr.u.addr = 0;
162 horizontal_offset = 0;
163 }
164
165 /* See tui-data.h. */
166
167 void
168 tui_cmd_window::clear_detail ()
169 {
170 wmove (handle, 0, 0);
171 }
172
173 /* See tui-data.h. */
174
175 void
176 tui_data_window::clear_detail ()
177 {
178 regs_content.clear ();
179 regs_column_count = 1;
180 display_regs = false;
181 }
182
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)
187 {
188 return &_locator;
189 }
190
191
192 /* Accessor for the term_height. */
193 int
194 tui_term_height (void)
195 {
196 return term_height;
197 }
198
199
200 /* Mutator for the term height. */
201 void
202 tui_set_term_height_to (int h)
203 {
204 term_height = h;
205 }
206
207
208 /* Accessor for the term_width. */
209 int
210 tui_term_width (void)
211 {
212 return term_width;
213 }
214
215
216 /* Mutator for the term_width. */
217 void
218 tui_set_term_width_to (int w)
219 {
220 term_width = w;
221 }
222
223
224 /* Accessor for the current layout. */
225 enum tui_layout_type
226 tui_current_layout (void)
227 {
228 return current_layout;
229 }
230
231
232 /* Mutator for the current layout. */
233 void
234 tui_set_current_layout_to (enum tui_layout_type new_layout)
235 {
236 current_layout = new_layout;
237 }
238
239
240 /*****************************
241 ** OTHER PUBLIC FUNCTIONS
242 *****************************/
243
244
245 /* Answer the next window in the list, cycling back to the top if
246 necessary. */
247 struct tui_win_info *
248 tui_next_win (struct tui_win_info *cur_win)
249 {
250 int type = cur_win->type;
251 struct tui_win_info *next_win = NULL;
252
253 if (cur_win->type == CMD_WIN)
254 type = SRC_WIN;
255 else
256 type = cur_win->type + 1;
257 while (type != cur_win->type && (next_win == NULL))
258 {
259 if (tui_win_list[type]
260 && tui_win_list[type]->is_visible)
261 next_win = tui_win_list[type];
262 else
263 {
264 if (type == CMD_WIN)
265 type = SRC_WIN;
266 else
267 type++;
268 }
269 }
270
271 return next_win;
272 }
273
274
275 /* Answer the prev window in the list, cycling back to the bottom if
276 necessary. */
277 struct tui_win_info *
278 tui_prev_win (struct tui_win_info *cur_win)
279 {
280 int type = cur_win->type;
281 struct tui_win_info *prev = NULL;
282
283 if (cur_win->type == SRC_WIN)
284 type = CMD_WIN;
285 else
286 type = cur_win->type - 1;
287 while (type != cur_win->type && (prev == NULL))
288 {
289 if (tui_win_list[type]
290 && tui_win_list[type]->is_visible)
291 prev = tui_win_list[type];
292 else
293 {
294 if (type == SRC_WIN)
295 type = CMD_WIN;
296 else
297 type--;
298 }
299 }
300
301 return prev;
302 }
303
304
305 /* Answer the window represented by name. */
306 struct tui_win_info *
307 tui_partial_win_by_name (const char *name)
308 {
309 struct tui_win_info *win_info = NULL;
310
311 if (name != NULL)
312 {
313 int i = 0;
314
315 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
316 {
317 if (tui_win_list[i] != 0)
318 {
319 const char *cur_name = tui_win_list[i]->name ();
320
321 if (strlen (name) <= strlen (cur_name)
322 && startswith (cur_name, name))
323 win_info = tui_win_list[i];
324 }
325 i++;
326 }
327 }
328
329 return win_info;
330 }
331
332
333 void
334 tui_initialize_static_data ()
335 {
336 tui_gen_win_info *win = tui_locator_win_info_ptr ();
337 win->width =
338 win->height =
339 win->origin.x =
340 win->origin.y =
341 win->viewport_height =
342 win->content_size =
343 win->last_visible_line = 0;
344 win->handle = NULL;
345 win->content = NULL;
346 win->content_in_use = FALSE;
347 win->is_visible = false;
348 win->title = 0;
349 }
350
351
352 /* init_content_element().
353 */
354 static void
355 init_content_element (struct tui_win_element *element,
356 enum tui_win_type type)
357 {
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);
363
364 switch (type)
365 {
366 case SRC_WIN:
367 case DISASSEM_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;
373 break;
374 default:
375 break;
376 }
377 }
378
379 tui_win_info::tui_win_info (enum tui_win_type type)
380 : tui_gen_win_info (type)
381 {
382 }
383
384 tui_source_window_base::tui_source_window_base (enum tui_win_type type)
385 : tui_win_info (type)
386 {
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;
390 }
391
392 /* Allocates the content and elements in a block. */
393 tui_win_content
394 tui_alloc_content (int num_elements, enum tui_win_type type)
395 {
396 tui_win_content content;
397 struct tui_win_element *element_block_ptr;
398 int i;
399
400 gdb_assert (type != EXEC_INFO_WIN);
401 gdb_assert (type != LOCATOR_WIN);
402
403 content = XNEWVEC (struct tui_win_element *, num_elements);
404
405 /*
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
409 * time.
410 */
411 if (type != DATA_WIN)
412 {
413 element_block_ptr = XNEWVEC (struct tui_win_element, num_elements);
414 for (i = 0; i < num_elements; i++)
415 {
416 content[i] = element_block_ptr;
417 init_content_element (content[i], type);
418 element_block_ptr++;
419 }
420 }
421
422 return content;
423 }
424
425
426 tui_gen_win_info::~tui_gen_win_info ()
427 {
428 if (handle != NULL)
429 {
430 tui_delete_win (handle);
431 handle = NULL;
432 tui_free_win_content (this);
433 }
434 xfree (title);
435 }
436
437 tui_source_window_base::~tui_source_window_base ()
438 {
439 xfree (fullname);
440 delete execution_info;
441 }
442
443 tui_data_window::~tui_data_window ()
444 {
445 if (content != NULL)
446 {
447 regs_column_count = 1;
448 display_regs = false;
449 content = NULL;
450 content_size = 0;
451 }
452 }
453
454 void
455 tui_free_all_source_wins_content ()
456 {
457 for (tui_source_window_base *win_info : tui_source_windows ())
458 {
459 tui_free_win_content (win_info);
460 tui_free_win_content (win_info->execution_info);
461 }
462 }
463
464
465 void
466 tui_free_win_content (struct tui_gen_win_info *win_info)
467 {
468 if (win_info->content != NULL)
469 {
470 free_content (win_info->content,
471 win_info->content_size,
472 win_info->type);
473 win_info->content = NULL;
474 }
475 win_info->content_size = 0;
476 }
477
478
479 /**********************************
480 ** LOCAL STATIC FUNCTIONS **
481 **********************************/
482
483
484 static void
485 free_content (tui_win_content content,
486 int content_size,
487 enum tui_win_type win_type)
488 {
489 if (content != NULL)
490 {
491 free_content_elements (content, content_size, win_type);
492 xfree (content);
493 }
494 }
495
496
497 tui_data_item_window::~tui_data_item_window ()
498 {
499 xfree (value);
500 xfree (content);
501 }
502
503 /* free_content_elements().
504 */
505 static void
506 free_content_elements (tui_win_content content,
507 int content_size,
508 enum tui_win_type type)
509 {
510 if (content != NULL)
511 {
512 int i;
513
514 if (type == DISASSEM_WIN)
515 {
516 /* Free whole source block. */
517 xfree (content[0]->which_element.source.line);
518 }
519 else
520 {
521 for (i = 0; i < content_size; i++)
522 {
523 struct tui_win_element *element;
524
525 element = content[i];
526 if (element != NULL)
527 {
528 switch (type)
529 {
530 case SRC_WIN:
531 xfree (element->which_element.source.line);
532 break;
533 default:
534 break;
535 }
536 }
537 }
538 }
539 if (type != DATA_WIN && type != DATA_ITEM_WIN)
540 xfree (content[0]); /* Free the element block. */
541 }
542 }
This page took 0.040668 seconds and 5 git commands to generate.