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