Remove command from tui_which_element
[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
AC
65int
66tui_win_is_auxillary (enum tui_win_type win_type)
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{
238eb706
TT
178 data_content = NULL;
179 data_content_count = 0;
180 regs_content = NULL;
181 regs_content_count = 0;
182 regs_column_count = 1;
ceb13a13 183 display_regs = false;
8761a91b 184}
c906108c 185
dd1abb8c
AC
186/* Accessor for the locator win info. Answers a pointer to the static
187 locator win info struct. */
3add462f 188struct tui_locator_window *
dd1abb8c 189tui_locator_win_info_ptr (void)
c906108c
SS
190{
191 return &_locator;
2a8854a7 192}
c906108c
SS
193
194
6ba8e26f 195/* Accessor for the term_height. */
c906108c 196int
dd1abb8c 197tui_term_height (void)
c906108c 198{
6ba8e26f 199 return term_height;
dd1abb8c 200}
c906108c
SS
201
202
1cc6d956 203/* Mutator for the term height. */
c906108c 204void
dd1abb8c 205tui_set_term_height_to (int h)
c906108c 206{
6ba8e26f 207 term_height = h;
dd1abb8c 208}
c906108c
SS
209
210
1cc6d956 211/* Accessor for the term_width. */
c906108c 212int
dd1abb8c 213tui_term_width (void)
c906108c 214{
6ba8e26f 215 return term_width;
dd1abb8c 216}
c906108c
SS
217
218
6ba8e26f 219/* Mutator for the term_width. */
c906108c 220void
dd1abb8c 221tui_set_term_width_to (int w)
c906108c 222{
6ba8e26f 223 term_width = w;
dd1abb8c 224}
c906108c
SS
225
226
1cc6d956 227/* Accessor for the current layout. */
2a8854a7 228enum tui_layout_type
dd1abb8c 229tui_current_layout (void)
c906108c 230{
6ba8e26f 231 return current_layout;
dd1abb8c 232}
c906108c
SS
233
234
dd1abb8c 235/* Mutator for the current layout. */
c906108c 236void
6ba8e26f 237tui_set_current_layout_to (enum tui_layout_type new_layout)
c906108c 238{
6ba8e26f 239 current_layout = new_layout;
dd1abb8c 240}
c906108c
SS
241
242
c906108c
SS
243/*****************************
244** OTHER PUBLIC FUNCTIONS
245*****************************/
246
247
dd1abb8c
AC
248/* Answer the next window in the list, cycling back to the top if
249 necessary. */
2a8854a7 250struct tui_win_info *
5b6fe301 251tui_next_win (struct tui_win_info *cur_win)
c906108c 252{
cb2ce893 253 int type = cur_win->type;
e65b5245 254 struct tui_win_info *next_win = NULL;
c906108c 255
cb2ce893 256 if (cur_win->type == CMD_WIN)
c906108c
SS
257 type = SRC_WIN;
258 else
cb2ce893
TT
259 type = cur_win->type + 1;
260 while (type != cur_win->type && (next_win == NULL))
c906108c 261 {
e5908723 262 if (tui_win_list[type]
cb2ce893 263 && tui_win_list[type]->is_visible)
6ba8e26f 264 next_win = tui_win_list[type];
c906108c
SS
265 else
266 {
267 if (type == CMD_WIN)
268 type = SRC_WIN;
269 else
270 type++;
271 }
272 }
273
6ba8e26f
AC
274 return next_win;
275}
c906108c
SS
276
277
dd1abb8c
AC
278/* Answer the prev window in the list, cycling back to the bottom if
279 necessary. */
2a8854a7 280struct tui_win_info *
5b6fe301 281tui_prev_win (struct tui_win_info *cur_win)
c906108c 282{
cb2ce893 283 int type = cur_win->type;
e65b5245 284 struct tui_win_info *prev = NULL;
c906108c 285
cb2ce893 286 if (cur_win->type == SRC_WIN)
c906108c
SS
287 type = CMD_WIN;
288 else
cb2ce893
TT
289 type = cur_win->type - 1;
290 while (type != cur_win->type && (prev == NULL))
c906108c 291 {
37715c4c 292 if (tui_win_list[type]
cb2ce893 293 && tui_win_list[type]->is_visible)
6d012f14 294 prev = tui_win_list[type];
c906108c
SS
295 else
296 {
297 if (type == SRC_WIN)
298 type = CMD_WIN;
299 else
300 type--;
301 }
302 }
303
304 return prev;
cb50eddd 305}
c906108c
SS
306
307
1cc6d956 308/* Answer the window represented by name. */
2a8854a7 309struct tui_win_info *
a121b7c1 310tui_partial_win_by_name (const char *name)
c906108c 311{
e65b5245 312 struct tui_win_info *win_info = NULL;
c906108c 313
63a33118 314 if (name != NULL)
c906108c
SS
315 {
316 int i = 0;
317
6d012f14 318 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
c906108c 319 {
6d012f14 320 if (tui_win_list[i] != 0)
a4b99e53 321 {
152f3f4b 322 const char *cur_name = tui_win_list[i]->name ();
1c5313c5 323
e5908723 324 if (strlen (name) <= strlen (cur_name)
61012eef 325 && startswith (cur_name, name))
6d012f14 326 win_info = tui_win_list[i];
a4b99e53 327 }
c906108c
SS
328 i++;
329 }
330 }
331
6d012f14 332 return win_info;
6ba8e26f 333}
c906108c
SS
334
335
c906108c 336void
dd1abb8c 337tui_initialize_static_data (void)
c906108c 338{
dd1abb8c
AC
339 tui_init_generic_part (tui_locator_win_info_ptr ());
340}
c906108c
SS
341
342
c906108c 343void
5b6fe301 344tui_init_generic_part (struct tui_gen_win_info *win)
c906108c
SS
345{
346 win->width =
347 win->height =
348 win->origin.x =
349 win->origin.y =
6d012f14
AC
350 win->viewport_height =
351 win->content_size =
352 win->last_visible_line = 0;
e65b5245 353 win->handle = NULL;
22940a24 354 win->content = NULL;
56122977
TT
355 win->content_in_use = FALSE;
356 win->is_visible = false;
bc6b7f04
SC
357 win->title = 0;
358}
c906108c
SS
359
360
ef5eab5a 361/* init_content_element().
c5aa993b 362 */
2c0b251b 363static void
08ef48c5
MS
364init_content_element (struct tui_win_element *element,
365 enum tui_win_type type)
c906108c 366{
489e9d8b 367 gdb_assert (type != EXEC_INFO_WIN);
3add462f 368 gdb_assert (type != LOCATOR_WIN);
dd835f8b 369 gdb_assert (type != CMD_WIN);
489e9d8b 370
c906108c
SS
371 switch (type)
372 {
373 case SRC_WIN:
374 case DISASSEM_WIN:
e65b5245 375 element->which_element.source.line = NULL;
362c05fe
AS
376 element->which_element.source.line_or_addr.loa = LOA_LINE;
377 element->which_element.source.line_or_addr.u.line_no = 0;
6d012f14
AC
378 element->which_element.source.is_exec_point = FALSE;
379 element->which_element.source.has_break = FALSE;
c906108c
SS
380 break;
381 case DATA_WIN:
ab313b35 382 element->which_element.data_window = new struct tui_gen_win_info (DATA_ITEM_WIN);
dc2c33e4 383 element->which_element.data_window->content =
63ed8182 384 tui_alloc_content (1, DATA_ITEM_WIN);
dc2c33e4 385 element->which_element.data_window->content_size = 1;
c906108c 386 break;
c906108c 387 case DATA_ITEM_WIN:
e65b5245 388 element->which_element.data.name = NULL;
6d012f14
AC
389 element->which_element.data.type = TUI_REGISTER;
390 element->which_element.data.item_no = UNDEFINED_ITEM;
391 element->which_element.data.value = NULL;
392 element->which_element.data.highlight = FALSE;
e65b5245 393 element->which_element.data.content = NULL;
c906108c 394 break;
c906108c
SS
395 default:
396 break;
397 }
6ba8e26f 398}
c906108c 399
33b906ab 400tui_win_info::tui_win_info (enum tui_win_type type)
cb2ce893 401 : tui_gen_win_info (type)
c906108c 402{
6ba8e26f 403}
c906108c 404
5cf82909 405tui_source_window_base::tui_source_window_base (enum tui_win_type type)
33b906ab
TT
406 : tui_win_info (type)
407{
408 gdb_assert (type == SRC_WIN || type == DISASSEM_WIN);
e6e41501
TT
409 start_line_or_addr.loa = LOA_ADDRESS;
410 start_line_or_addr.u.addr = 0;
33b906ab
TT
411}
412
6ba8e26f 413/* Allocates the content and elements in a block. */
2a8854a7 414tui_win_content
6ba8e26f 415tui_alloc_content (int num_elements, enum tui_win_type type)
c906108c 416{
c0645fb5 417 tui_win_content content;
7acd011b 418 struct tui_win_element *element_block_ptr;
c906108c
SS
419 int i;
420
489e9d8b 421 gdb_assert (type != EXEC_INFO_WIN);
3add462f 422 gdb_assert (type != LOCATOR_WIN);
489e9d8b 423
8d749320 424 content = XNEWVEC (struct tui_win_element *, num_elements);
7acd011b
SM
425
426 /*
427 * All windows, except the data window, can allocate the
428 * elements in a chunk. The data window cannot because items
429 * can be added/removed from the data display by the user at any
430 * time.
431 */
432 if (type != DATA_WIN)
c0645fb5 433 {
7acd011b
SM
434 element_block_ptr = XNEWVEC (struct tui_win_element, num_elements);
435 for (i = 0; i < num_elements; i++)
c906108c 436 {
7acd011b
SM
437 content[i] = element_block_ptr;
438 init_content_element (content[i], type);
439 element_block_ptr++;
c906108c
SS
440 }
441 }
442
443 return content;
6ba8e26f 444}
c906108c
SS
445
446
dd1abb8c 447/* Adds the input number of elements to the windows's content. If no
6ba8e26f 448 content has been allocated yet, alloc_content() is called to do
dd1abb8c
AC
449 this. The index of the first element added is returned, unless
450 there is a memory allocation error, in which case, (-1) is
451 returned. */
c906108c 452int
08ef48c5
MS
453tui_add_content_elements (struct tui_gen_win_info *win_info,
454 int num_elements)
c906108c 455{
5b6fe301 456 struct tui_win_element *element_ptr;
6ba8e26f 457 int i, index_start;
c906108c 458
6d012f14 459 if (win_info->content == NULL)
c906108c 460 {
63ed8182 461 win_info->content = tui_alloc_content (num_elements, win_info->type);
6ba8e26f 462 index_start = 0;
c906108c
SS
463 }
464 else
6ba8e26f 465 index_start = win_info->content_size;
6d012f14 466 if (win_info->content != NULL)
c906108c 467 {
6ba8e26f 468 for (i = index_start; (i < num_elements + index_start); i++)
c906108c 469 {
8d749320 470 element_ptr = XNEW (struct tui_win_element);
730ead81
TT
471 win_info->content[i] = element_ptr;
472 init_content_element (element_ptr, win_info->type);
473 win_info->content_size++;
c906108c
SS
474 }
475 }
476
6ba8e26f
AC
477 return index_start;
478}
c906108c 479
f936bca2 480tui_gen_win_info::~tui_gen_win_info ()
c906108c 481{
f936bca2 482 if (handle != NULL)
ee1d42d6 483 {
f936bca2
TT
484 tui_delete_win (handle);
485 handle = NULL;
486 tui_free_win_content (this);
ee1d42d6 487 }
f936bca2
TT
488 xfree (title);
489}
490
491tui_source_window_base::~tui_source_window_base ()
492{
493 xfree (fullname);
494 delete execution_info;
ee1d42d6 495}
c906108c 496
ee1d42d6
TT
497tui_data_window::~tui_data_window ()
498{
cb2ce893 499 if (content != NULL)
c906108c 500 {
238eb706
TT
501 tui_free_data_content (regs_content, regs_content_count);
502 regs_content = NULL;
503 regs_content_count = 0;
504 tui_free_data_content (data_content, data_content_count);
505 data_content = NULL;
506 data_content_count = 0;
507 regs_column_count = 1;
ceb13a13 508 display_regs = false;
cb2ce893
TT
509 content = NULL;
510 content_size = 0;
c906108c 511 }
ee1d42d6
TT
512}
513
c906108c 514void
b4eb2452 515tui_free_all_source_wins_content ()
c906108c 516{
ad54d15b 517 for (tui_source_window_base *win_info : tui_source_windows ())
c906108c 518 {
cb2ce893 519 tui_free_win_content (win_info);
ad54d15b 520 tui_free_win_content (win_info->execution_info);
c906108c 521 }
dd1abb8c 522}
c906108c
SS
523
524
c906108c 525void
5b6fe301 526tui_free_win_content (struct tui_gen_win_info *win_info)
c906108c 527{
6d012f14 528 if (win_info->content != NULL)
c906108c 529 {
63a33118 530 free_content (win_info->content,
6d012f14
AC
531 win_info->content_size,
532 win_info->type);
533 win_info->content = NULL;
c906108c 534 }
6d012f14 535 win_info->content_size = 0;
6ba8e26f 536}
c906108c
SS
537
538
c906108c 539void
08ef48c5
MS
540tui_free_data_content (tui_win_content content,
541 int content_size)
c906108c
SS
542{
543 int i;
544
ef5eab5a
MS
545 /* Remember that data window content elements are of type struct
546 tui_gen_win_info *, each of which whose single element is a data
547 element. */
6ba8e26f 548 for (i = 0; i < content_size; i++)
c906108c 549 {
9a2b4c1b 550 struct tui_gen_win_info *generic_win
dc2c33e4 551 = content[i]->which_element.data_window;
c906108c 552
cafb3438 553 if (generic_win != NULL)
c906108c 554 {
6ba8e26f 555 tui_delete_win (generic_win->handle);
e65b5245 556 generic_win->handle = NULL;
6ba8e26f 557 tui_free_win_content (generic_win);
c906108c
SS
558 }
559 }
6ba8e26f 560 free_content (content,
08ef48c5
MS
561 content_size,
562 DATA_WIN);
6ba8e26f 563}
c906108c
SS
564
565
566/**********************************
567** LOCAL STATIC FUNCTIONS **
568**********************************/
569
570
c906108c 571static void
08ef48c5
MS
572free_content (tui_win_content content,
573 int content_size,
574 enum tui_win_type win_type)
c906108c 575{
d04b44a1 576 if (content != NULL)
c906108c 577 {
6ba8e26f 578 free_content_elements (content, content_size, win_type);
22940a24 579 xfree (content);
c906108c 580 }
6ba8e26f 581}
c906108c
SS
582
583
ef5eab5a 584/* free_content_elements().
c5aa993b 585 */
c906108c 586static void
08ef48c5
MS
587free_content_elements (tui_win_content content,
588 int content_size,
589 enum tui_win_type type)
c906108c 590{
d04b44a1 591 if (content != NULL)
c906108c
SS
592 {
593 int i;
594
62f29fda 595 if (type == DISASSEM_WIN)
c906108c 596 {
1cc6d956 597 /* Free whole source block. */
6d012f14 598 xfree (content[0]->which_element.source.line);
c906108c
SS
599 }
600 else
601 {
6ba8e26f 602 for (i = 0; i < content_size; i++)
c906108c 603 {
5b6fe301 604 struct tui_win_element *element;
c906108c
SS
605
606 element = content[i];
cafb3438 607 if (element != NULL)
c906108c
SS
608 {
609 switch (type)
610 {
62f29fda
TT
611 case SRC_WIN:
612 xfree (element->which_element.source.line);
613 break;
c906108c 614 case DATA_WIN:
ab313b35 615 delete element->which_element.data_window;
22940a24 616 xfree (element);
c906108c
SS
617 break;
618 case DATA_ITEM_WIN:
ef5eab5a
MS
619 /* Note that data elements are not allocated in
620 a single block, but individually, as
621 needed. */
6d012f14
AC
622 if (element->which_element.data.type != TUI_REGISTER)
623 xfree ((void *)element->which_element.data.name);
624 xfree (element->which_element.data.value);
10f59415 625 xfree (element->which_element.data.content);
22940a24 626 xfree (element);
c906108c 627 break;
c906108c
SS
628 default:
629 break;
630 }
631 }
632 }
633 }
634 if (type != DATA_WIN && type != DATA_ITEM_WIN)
1cc6d956 635 xfree (content[0]); /* Free the element block. */
c906108c 636 }
6ba8e26f 637}
This page took 2.935399 seconds and 4 git commands to generate.