]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/tui/tui-data.c
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / tui / tui-data.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf 2
e2882c85 3 Copyright (C) 1998-2018 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;
2a8854a7 39static struct tui_gen_win_info _locator;
6ba8e26f 40static struct tui_gen_win_info exec_info[2];
5b6fe301 41static struct tui_win_info *src_win_list[2];
96c1eda2 42static struct tui_list source_windows = {src_win_list, 0};
6ba8e26f 43static int default_tab_len = DEFAULT_TAB_LEN;
e65b5245 44static struct tui_win_info *win_with_focus = NULL;
08ef48c5
MS
45static struct tui_layout_def layout_def = {
46 SRC_WIN, /* DISPLAY_MODE */
7bd0be3a 47 FALSE}; /* SPLIT */
08ef48c5 48
6ba8e26f 49static int win_resized = FALSE;
c906108c
SS
50
51
52/*********************************
53** Static function forward decls
54**********************************/
08ef48c5
MS
55static void free_content (tui_win_content,
56 int,
57 enum tui_win_type);
58static void free_content_elements (tui_win_content,
59 int,
60 enum tui_win_type);
c906108c
SS
61
62
63
64/*********************************
65** PUBLIC FUNCTIONS
66**********************************/
67
6d012f14
AC
68int
69tui_win_is_source_type (enum tui_win_type win_type)
70{
71 return (win_type == SRC_WIN || win_type == DISASSEM_WIN);
72}
73
74int
75tui_win_is_auxillary (enum tui_win_type win_type)
76{
77 return (win_type > MAX_MAJOR_WINDOWS);
78}
79
80int
81tui_win_has_locator (struct tui_win_info *win_info)
82{
08ef48c5 83 return (win_info != NULL
6d012f14
AC
84 && win_info->detail.source_info.has_locator);
85}
86
87void
08ef48c5
MS
88tui_set_win_highlight (struct tui_win_info *win_info,
89 int highlight)
6d012f14
AC
90{
91 if (win_info != NULL)
92 win_info->is_highlighted = highlight;
93}
94
c906108c
SS
95/******************************************
96** ACCESSORS & MUTATORS FOR PRIVATE DATA
97******************************************/
98
1cc6d956 99/* Answer a whether the terminal window has been resized or not. */
c906108c 100int
dd1abb8c 101tui_win_resized (void)
c906108c 102{
6ba8e26f 103 return win_resized;
dd1abb8c 104}
c906108c
SS
105
106
1cc6d956 107/* Set a whether the terminal window has been resized or not. */
c906108c 108void
dd1abb8c 109tui_set_win_resized_to (int resized)
c906108c 110{
6ba8e26f 111 win_resized = resized;
dd1abb8c 112}
c906108c
SS
113
114
1cc6d956 115/* Answer a pointer to the current layout definition. */
2a8854a7 116struct tui_layout_def *
dd1abb8c 117tui_layout_def (void)
c906108c 118{
6ba8e26f 119 return &layout_def;
dd1abb8c 120}
c906108c
SS
121
122
1cc6d956 123/* Answer the window with the logical focus. */
2a8854a7 124struct tui_win_info *
dd1abb8c 125tui_win_with_focus (void)
c906108c 126{
6ba8e26f 127 return win_with_focus;
dd1abb8c 128}
c906108c
SS
129
130
1cc6d956 131/* Set the window that has the logical focus. */
c906108c 132void
5b6fe301 133tui_set_win_with_focus (struct tui_win_info *win_info)
c906108c 134{
6ba8e26f 135 win_with_focus = win_info;
dd1abb8c 136}
c906108c
SS
137
138
1cc6d956 139/* Answer the length in chars, of tabs. */
c906108c 140int
dd1abb8c 141tui_default_tab_len (void)
c906108c 142{
6ba8e26f 143 return default_tab_len;
dd1abb8c 144}
c906108c
SS
145
146
1cc6d956 147/* Set the length in chars, of tabs. */
c906108c 148void
dd1abb8c 149tui_set_default_tab_len (int len)
c906108c 150{
6ba8e26f 151 default_tab_len = len;
dd1abb8c 152}
c906108c
SS
153
154
6ba8e26f
AC
155/* Accessor for the current source window. Usually there is only one
156 source window (either source or disassembly), but both can be
157 displayed at the same time. */
2a8854a7 158struct tui_list *
dd1abb8c 159tui_source_windows (void)
c906108c 160{
6ba8e26f 161 return &source_windows;
dd1abb8c 162}
c906108c
SS
163
164
dd1abb8c
AC
165/* Clear the list of source windows. Usually there is only one source
166 window (either source or disassembly), but both can be displayed at
167 the same time. */
c906108c 168void
dd1abb8c 169tui_clear_source_windows (void)
c906108c 170{
6ba8e26f
AC
171 source_windows.list[0] = NULL;
172 source_windows.list[1] = NULL;
173 source_windows.count = 0;
dd1abb8c 174}
c906108c
SS
175
176
1cc6d956 177/* Clear the pertinant detail in the source windows. */
c906108c 178void
dd1abb8c 179tui_clear_source_windows_detail (void)
c906108c
SS
180{
181 int i;
182
dd1abb8c 183 for (i = 0; i < (tui_source_windows ())->count; i++)
96c1eda2 184 tui_clear_win_detail ((tui_source_windows ())->list[i]);
dd1abb8c 185}
c906108c
SS
186
187
dd1abb8c
AC
188/* Add a window to the list of source windows. Usually there is only
189 one source window (either source or disassembly), but both can be
190 displayed at the same time. */
c906108c 191void
5b6fe301 192tui_add_to_source_windows (struct tui_win_info *win_info)
c906108c 193{
6ba8e26f 194 if (source_windows.count < 2)
f4ee58bd 195 source_windows.list[source_windows.count++] = win_info;
dd1abb8c 196}
c906108c
SS
197
198
1cc6d956 199/* Clear the pertinant detail in the windows. */
c906108c 200void
5b6fe301 201tui_clear_win_detail (struct tui_win_info *win_info)
c906108c 202{
6d012f14 203 if (win_info != NULL)
c906108c 204 {
6d012f14 205 switch (win_info->generic.type)
c906108c
SS
206 {
207 case SRC_WIN:
208 case DISASSEM_WIN:
13274fc3 209 win_info->detail.source_info.gdbarch = NULL;
362c05fe
AS
210 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
211 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
6d012f14 212 win_info->detail.source_info.horizontal_offset = 0;
c906108c
SS
213 break;
214 case CMD_WIN:
6f1cb6ea 215 wmove (win_info->generic.handle, 0, 0);
c906108c
SS
216 break;
217 case DATA_WIN:
6d012f14 218 win_info->detail.data_display_info.data_content =
2a8854a7 219 (tui_win_content) NULL;
6d012f14
AC
220 win_info->detail.data_display_info.data_content_count = 0;
221 win_info->detail.data_display_info.regs_content =
2a8854a7 222 (tui_win_content) NULL;
6d012f14 223 win_info->detail.data_display_info.regs_content_count = 0;
6d012f14
AC
224 win_info->detail.data_display_info.regs_column_count = 1;
225 win_info->detail.data_display_info.display_regs = FALSE;
c906108c
SS
226 break;
227 default:
228 break;
229 }
230 }
6ba8e26f 231}
c906108c
SS
232
233
6ba8e26f 234/* Accessor for the source execution info ptr. */
2a8854a7 235struct tui_gen_win_info *
dd1abb8c 236tui_source_exec_info_win_ptr (void)
c906108c 237{
6ba8e26f
AC
238 return &exec_info[0];
239}
c906108c
SS
240
241
6ba8e26f 242/* Accessor for the disassem execution info ptr. */
2a8854a7 243struct tui_gen_win_info *
dd1abb8c 244tui_disassem_exec_info_win_ptr (void)
c906108c 245{
6ba8e26f
AC
246 return &exec_info[1];
247}
c906108c
SS
248
249
dd1abb8c
AC
250/* Accessor for the locator win info. Answers a pointer to the static
251 locator win info struct. */
2a8854a7 252struct tui_gen_win_info *
dd1abb8c 253tui_locator_win_info_ptr (void)
c906108c
SS
254{
255 return &_locator;
2a8854a7 256}
c906108c
SS
257
258
6ba8e26f 259/* Accessor for the term_height. */
c906108c 260int
dd1abb8c 261tui_term_height (void)
c906108c 262{
6ba8e26f 263 return term_height;
dd1abb8c 264}
c906108c
SS
265
266
1cc6d956 267/* Mutator for the term height. */
c906108c 268void
dd1abb8c 269tui_set_term_height_to (int h)
c906108c 270{
6ba8e26f 271 term_height = h;
dd1abb8c 272}
c906108c
SS
273
274
1cc6d956 275/* Accessor for the term_width. */
c906108c 276int
dd1abb8c 277tui_term_width (void)
c906108c 278{
6ba8e26f 279 return term_width;
dd1abb8c 280}
c906108c
SS
281
282
6ba8e26f 283/* Mutator for the term_width. */
c906108c 284void
dd1abb8c 285tui_set_term_width_to (int w)
c906108c 286{
6ba8e26f 287 term_width = w;
dd1abb8c 288}
c906108c
SS
289
290
1cc6d956 291/* Accessor for the current layout. */
2a8854a7 292enum tui_layout_type
dd1abb8c 293tui_current_layout (void)
c906108c 294{
6ba8e26f 295 return current_layout;
dd1abb8c 296}
c906108c
SS
297
298
dd1abb8c 299/* Mutator for the current layout. */
c906108c 300void
6ba8e26f 301tui_set_current_layout_to (enum tui_layout_type new_layout)
c906108c 302{
6ba8e26f 303 current_layout = new_layout;
dd1abb8c 304}
c906108c
SS
305
306
c906108c
SS
307/*****************************
308** OTHER PUBLIC FUNCTIONS
309*****************************/
310
311
dd1abb8c
AC
312/* Answer the next window in the list, cycling back to the top if
313 necessary. */
2a8854a7 314struct tui_win_info *
5b6fe301 315tui_next_win (struct tui_win_info *cur_win)
c906108c 316{
570dc176 317 int type = cur_win->generic.type;
e65b5245 318 struct tui_win_info *next_win = NULL;
c906108c 319
6ba8e26f 320 if (cur_win->generic.type == CMD_WIN)
c906108c
SS
321 type = SRC_WIN;
322 else
6ba8e26f
AC
323 type = cur_win->generic.type + 1;
324 while (type != cur_win->generic.type && (next_win == NULL))
c906108c 325 {
e5908723
MS
326 if (tui_win_list[type]
327 && tui_win_list[type]->generic.is_visible)
6ba8e26f 328 next_win = tui_win_list[type];
c906108c
SS
329 else
330 {
331 if (type == CMD_WIN)
332 type = SRC_WIN;
333 else
334 type++;
335 }
336 }
337
6ba8e26f
AC
338 return next_win;
339}
c906108c
SS
340
341
dd1abb8c
AC
342/* Answer the prev window in the list, cycling back to the bottom if
343 necessary. */
2a8854a7 344struct tui_win_info *
5b6fe301 345tui_prev_win (struct tui_win_info *cur_win)
c906108c 346{
570dc176 347 int type = cur_win->generic.type;
e65b5245 348 struct tui_win_info *prev = NULL;
c906108c 349
6ba8e26f 350 if (cur_win->generic.type == SRC_WIN)
c906108c
SS
351 type = CMD_WIN;
352 else
6ba8e26f
AC
353 type = cur_win->generic.type - 1;
354 while (type != cur_win->generic.type && (prev == NULL))
c906108c 355 {
37715c4c
TJB
356 if (tui_win_list[type]
357 && tui_win_list[type]->generic.is_visible)
6d012f14 358 prev = tui_win_list[type];
c906108c
SS
359 else
360 {
361 if (type == SRC_WIN)
362 type = CMD_WIN;
363 else
364 type--;
365 }
366 }
367
368 return prev;
cb50eddd 369}
c906108c
SS
370
371
1cc6d956 372/* Answer the window represented by name. */
2a8854a7 373struct tui_win_info *
a121b7c1 374tui_partial_win_by_name (const char *name)
c906108c 375{
e65b5245 376 struct tui_win_info *win_info = NULL;
c906108c
SS
377
378 if (name != (char *) NULL)
379 {
380 int i = 0;
381
6d012f14 382 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
c906108c 383 {
6d012f14 384 if (tui_win_list[i] != 0)
a4b99e53 385 {
f41cbf58
AB
386 const char *cur_name =
387 tui_win_name (&tui_win_list[i]->generic);
1c5313c5 388
e5908723 389 if (strlen (name) <= strlen (cur_name)
61012eef 390 && startswith (cur_name, name))
6d012f14 391 win_info = tui_win_list[i];
a4b99e53 392 }
c906108c
SS
393 i++;
394 }
395 }
396
6d012f14 397 return win_info;
6ba8e26f 398}
c906108c
SS
399
400
6ba8e26f 401/* Answer the name of the window. */
f41cbf58
AB
402const char *
403tui_win_name (const struct tui_gen_win_info *win_info)
c906108c 404{
136765ea 405 const char *name = NULL;
c906108c 406
6d012f14 407 switch (win_info->type)
c906108c
SS
408 {
409 case SRC_WIN:
410 name = SRC_NAME;
411 break;
412 case CMD_WIN:
413 name = CMD_NAME;
414 break;
415 case DISASSEM_WIN:
416 name = DISASSEM_NAME;
417 break;
418 case DATA_WIN:
419 name = DATA_NAME;
420 break;
421 default:
422 name = "";
423 break;
424 }
425
426 return name;
6ba8e26f 427}
c906108c
SS
428
429
c906108c 430void
dd1abb8c 431tui_initialize_static_data (void)
c906108c 432{
dd1abb8c
AC
433 tui_init_generic_part (tui_source_exec_info_win_ptr ());
434 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
435 tui_init_generic_part (tui_locator_win_info_ptr ());
436}
c906108c
SS
437
438
2a8854a7 439struct tui_gen_win_info *
dd1abb8c 440tui_alloc_generic_win_info (void)
c906108c 441{
8d749320 442 struct tui_gen_win_info *win = XNEW (struct tui_gen_win_info);
c906108c 443
8d749320 444 if (win != NULL)
dd1abb8c 445 tui_init_generic_part (win);
c906108c
SS
446
447 return win;
6ba8e26f 448}
c906108c
SS
449
450
c906108c 451void
5b6fe301 452tui_init_generic_part (struct tui_gen_win_info *win)
c906108c
SS
453{
454 win->width =
455 win->height =
456 win->origin.x =
457 win->origin.y =
6d012f14
AC
458 win->viewport_height =
459 win->content_size =
460 win->last_visible_line = 0;
e65b5245 461 win->handle = NULL;
22940a24 462 win->content = NULL;
6d012f14
AC
463 win->content_in_use =
464 win->is_visible = FALSE;
bc6b7f04
SC
465 win->title = 0;
466}
c906108c
SS
467
468
ef5eab5a 469/* init_content_element().
c5aa993b 470 */
2c0b251b 471static void
08ef48c5
MS
472init_content_element (struct tui_win_element *element,
473 enum tui_win_type type)
c906108c
SS
474{
475 element->highlight = FALSE;
476 switch (type)
477 {
478 case SRC_WIN:
479 case DISASSEM_WIN:
e65b5245 480 element->which_element.source.line = NULL;
362c05fe
AS
481 element->which_element.source.line_or_addr.loa = LOA_LINE;
482 element->which_element.source.line_or_addr.u.line_no = 0;
6d012f14
AC
483 element->which_element.source.is_exec_point = FALSE;
484 element->which_element.source.has_break = FALSE;
c906108c
SS
485 break;
486 case DATA_WIN:
6d012f14
AC
487 tui_init_generic_part (&element->which_element.data_window);
488 element->which_element.data_window.type = DATA_ITEM_WIN;
63ed8182
PP
489 element->which_element.data_window.content =
490 tui_alloc_content (1, DATA_ITEM_WIN);
491 element->which_element.data_window.content_size = 1;
c906108c
SS
492 break;
493 case CMD_WIN:
e65b5245 494 element->which_element.command.line = NULL;
c906108c
SS
495 break;
496 case DATA_ITEM_WIN:
e65b5245 497 element->which_element.data.name = NULL;
6d012f14
AC
498 element->which_element.data.type = TUI_REGISTER;
499 element->which_element.data.item_no = UNDEFINED_ITEM;
500 element->which_element.data.value = NULL;
501 element->which_element.data.highlight = FALSE;
e65b5245 502 element->which_element.data.content = NULL;
c906108c
SS
503 break;
504 case LOCATOR_WIN:
56d397a3 505 element->which_element.locator.full_name[0] =
6d012f14
AC
506 element->which_element.locator.proc_name[0] = (char) 0;
507 element->which_element.locator.line_no = 0;
508 element->which_element.locator.addr = 0;
c906108c
SS
509 break;
510 case EXEC_INFO_WIN:
6d012f14
AC
511 memset(element->which_element.simple_string, ' ',
512 sizeof(element->which_element.simple_string));
c906108c
SS
513 break;
514 default:
515 break;
516 }
6ba8e26f 517}
c906108c 518
2c0b251b 519static void
5b6fe301 520init_win_info (struct tui_win_info *win_info)
c906108c 521{
6d012f14
AC
522 tui_init_generic_part (&win_info->generic);
523 win_info->can_highlight =
524 win_info->is_highlighted = FALSE;
525 switch (win_info->generic.type)
c906108c
SS
526 {
527 case SRC_WIN:
528 case DISASSEM_WIN:
9a2b4c1b
MS
529 win_info->detail.source_info.execution_info
530 = (struct tui_gen_win_info *) NULL;
6d012f14
AC
531 win_info->detail.source_info.has_locator = FALSE;
532 win_info->detail.source_info.horizontal_offset = 0;
13274fc3 533 win_info->detail.source_info.gdbarch = NULL;
362c05fe
AS
534 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
535 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
aa079c93 536 win_info->detail.source_info.fullname = NULL;
c906108c
SS
537 break;
538 case DATA_WIN:
6d012f14
AC
539 win_info->detail.data_display_info.data_content = (tui_win_content) NULL;
540 win_info->detail.data_display_info.data_content_count = 0;
541 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL;
542 win_info->detail.data_display_info.regs_content_count = 0;
6d012f14
AC
543 win_info->detail.data_display_info.regs_column_count = 1;
544 win_info->detail.data_display_info.display_regs = FALSE;
10f59415 545 win_info->detail.data_display_info.current_group = 0;
c906108c
SS
546 break;
547 case CMD_WIN:
c906108c
SS
548 break;
549 default:
6d012f14 550 win_info->detail.opaque = NULL;
c906108c
SS
551 break;
552 }
6ba8e26f 553}
c906108c
SS
554
555
2a8854a7 556struct tui_win_info *
22940a24 557tui_alloc_win_info (enum tui_win_type type)
c906108c 558{
8d749320 559 struct tui_win_info *win_info = XNEW (struct tui_win_info);
c906108c 560
c0645fb5 561 if (win_info != NULL)
c906108c 562 {
6d012f14 563 win_info->generic.type = type;
6ba8e26f 564 init_win_info (win_info);
c906108c
SS
565 }
566
6d012f14 567 return win_info;
6ba8e26f 568}
c906108c
SS
569
570
6ba8e26f 571/* Allocates the content and elements in a block. */
2a8854a7 572tui_win_content
6ba8e26f 573tui_alloc_content (int num_elements, enum tui_win_type type)
c906108c 574{
c0645fb5 575 tui_win_content content;
7acd011b 576 struct tui_win_element *element_block_ptr;
c906108c
SS
577 int i;
578
8d749320 579 content = XNEWVEC (struct tui_win_element *, num_elements);
7acd011b
SM
580
581 /*
582 * All windows, except the data window, can allocate the
583 * elements in a chunk. The data window cannot because items
584 * can be added/removed from the data display by the user at any
585 * time.
586 */
587 if (type != DATA_WIN)
c0645fb5 588 {
7acd011b
SM
589 element_block_ptr = XNEWVEC (struct tui_win_element, num_elements);
590 for (i = 0; i < num_elements; i++)
c906108c 591 {
7acd011b
SM
592 content[i] = element_block_ptr;
593 init_content_element (content[i], type);
594 element_block_ptr++;
c906108c
SS
595 }
596 }
597
598 return content;
6ba8e26f 599}
c906108c
SS
600
601
dd1abb8c 602/* Adds the input number of elements to the windows's content. If no
6ba8e26f 603 content has been allocated yet, alloc_content() is called to do
dd1abb8c
AC
604 this. The index of the first element added is returned, unless
605 there is a memory allocation error, in which case, (-1) is
606 returned. */
c906108c 607int
08ef48c5
MS
608tui_add_content_elements (struct tui_gen_win_info *win_info,
609 int num_elements)
c906108c 610{
5b6fe301 611 struct tui_win_element *element_ptr;
6ba8e26f 612 int i, index_start;
c906108c 613
6d012f14 614 if (win_info->content == NULL)
c906108c 615 {
63ed8182 616 win_info->content = tui_alloc_content (num_elements, win_info->type);
6ba8e26f 617 index_start = 0;
c906108c
SS
618 }
619 else
6ba8e26f 620 index_start = win_info->content_size;
6d012f14 621 if (win_info->content != NULL)
c906108c 622 {
6ba8e26f 623 for (i = index_start; (i < num_elements + index_start); i++)
c906108c 624 {
8d749320
SM
625 element_ptr = XNEW (struct tui_win_element);
626 if (element_ptr != NULL)
c906108c 627 {
f4ee58bd 628 win_info->content[i] = element_ptr;
6ba8e26f 629 init_content_element (element_ptr, win_info->type);
6d012f14 630 win_info->content_size++;
c906108c 631 }
1cc6d956
MS
632 else /* Things must be really hosed now! We ran out of
633 memory!? */
c906108c
SS
634 return (-1);
635 }
636 }
637
6ba8e26f
AC
638 return index_start;
639}
c906108c
SS
640
641
1cc6d956
MS
642/* Delete all curses windows associated with win_info, leaving
643 everything else intact. */
c906108c 644void
5b6fe301 645tui_del_window (struct tui_win_info *win_info)
c906108c 646{
5b6fe301 647 struct tui_gen_win_info *generic_win;
c906108c 648
6d012f14 649 switch (win_info->generic.type)
c906108c
SS
650 {
651 case SRC_WIN:
652 case DISASSEM_WIN:
6ba8e26f
AC
653 generic_win = tui_locator_win_info_ptr ();
654 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 655 {
6ba8e26f 656 tui_delete_win (generic_win->handle);
e65b5245 657 generic_win->handle = NULL;
6ba8e26f 658 generic_win->is_visible = FALSE;
c906108c 659 }
aa079c93 660 if (win_info->detail.source_info.fullname)
bc6b7f04 661 {
aa079c93
JK
662 xfree (win_info->detail.source_info.fullname);
663 win_info->detail.source_info.fullname = NULL;
bc6b7f04 664 }
6ba8e26f
AC
665 generic_win = win_info->detail.source_info.execution_info;
666 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 667 {
6ba8e26f 668 tui_delete_win (generic_win->handle);
e65b5245 669 generic_win->handle = NULL;
6ba8e26f 670 generic_win->is_visible = FALSE;
c906108c
SS
671 }
672 break;
673 case DATA_WIN:
6d012f14 674 if (win_info->generic.content != NULL)
c906108c 675 {
6d012f14
AC
676 tui_del_data_windows (win_info->detail.data_display_info.regs_content,
677 win_info->detail.data_display_info.regs_content_count);
678 tui_del_data_windows (win_info->detail.data_display_info.data_content,
679 win_info->detail.data_display_info.data_content_count);
c906108c
SS
680 }
681 break;
682 default:
683 break;
684 }
6d012f14 685 if (win_info->generic.handle != (WINDOW *) NULL)
c906108c 686 {
6d012f14 687 tui_delete_win (win_info->generic.handle);
e65b5245 688 win_info->generic.handle = NULL;
6d012f14 689 win_info->generic.is_visible = FALSE;
c906108c 690 }
bc6b7f04 691}
c906108c
SS
692
693
c906108c 694void
5b6fe301 695tui_free_window (struct tui_win_info *win_info)
c906108c 696{
5b6fe301 697 struct tui_gen_win_info *generic_win;
c906108c 698
6d012f14 699 switch (win_info->generic.type)
c906108c
SS
700 {
701 case SRC_WIN:
702 case DISASSEM_WIN:
aa079c93 703 if (win_info->detail.source_info.fullname)
bc6b7f04 704 {
aa079c93
JK
705 xfree (win_info->detail.source_info.fullname);
706 win_info->detail.source_info.fullname = NULL;
bc6b7f04 707 }
6ba8e26f
AC
708 generic_win = win_info->detail.source_info.execution_info;
709 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 710 {
6ba8e26f 711 tui_delete_win (generic_win->handle);
e65b5245 712 generic_win->handle = NULL;
6ba8e26f 713 tui_free_win_content (generic_win);
c906108c
SS
714 }
715 break;
716 case DATA_WIN:
6d012f14 717 if (win_info->generic.content != NULL)
c906108c 718 {
6d012f14
AC
719 tui_free_data_content (win_info->detail.data_display_info.regs_content,
720 win_info->detail.data_display_info.regs_content_count);
721 win_info->detail.data_display_info.regs_content =
2a8854a7 722 (tui_win_content) NULL;
6d012f14
AC
723 win_info->detail.data_display_info.regs_content_count = 0;
724 tui_free_data_content (win_info->detail.data_display_info.data_content,
725 win_info->detail.data_display_info.data_content_count);
726 win_info->detail.data_display_info.data_content =
2a8854a7 727 (tui_win_content) NULL;
6d012f14 728 win_info->detail.data_display_info.data_content_count = 0;
6d012f14
AC
729 win_info->detail.data_display_info.regs_column_count = 1;
730 win_info->detail.data_display_info.display_regs = FALSE;
731 win_info->generic.content = NULL;
732 win_info->generic.content_size = 0;
c906108c
SS
733 }
734 break;
735 default:
736 break;
737 }
6d012f14 738 if (win_info->generic.handle != (WINDOW *) NULL)
c906108c 739 {
6d012f14 740 tui_delete_win (win_info->generic.handle);
e65b5245 741 win_info->generic.handle = NULL;
6d012f14 742 tui_free_win_content (&win_info->generic);
c906108c 743 }
6d012f14
AC
744 if (win_info->generic.title)
745 xfree (win_info->generic.title);
746 xfree (win_info);
bc6b7f04 747}
c906108c
SS
748
749
c906108c 750void
dd1abb8c 751tui_free_all_source_wins_content (void)
c906108c
SS
752{
753 int i;
754
dd1abb8c 755 for (i = 0; i < (tui_source_windows ())->count; i++)
c906108c 756 {
5b6fe301 757 struct tui_win_info *win_info = (tui_source_windows ())->list[i];
c906108c 758
6d012f14 759 if (win_info != NULL)
c906108c 760 {
6d012f14
AC
761 tui_free_win_content (&(win_info->generic));
762 tui_free_win_content (win_info->detail.source_info.execution_info);
c906108c
SS
763 }
764 }
dd1abb8c 765}
c906108c
SS
766
767
c906108c 768void
5b6fe301 769tui_free_win_content (struct tui_gen_win_info *win_info)
c906108c 770{
6d012f14 771 if (win_info->content != NULL)
c906108c 772 {
6ba8e26f 773 free_content ((tui_win_content) win_info->content,
6d012f14
AC
774 win_info->content_size,
775 win_info->type);
776 win_info->content = NULL;
c906108c 777 }
6d012f14 778 win_info->content_size = 0;
6ba8e26f 779}
c906108c
SS
780
781
c906108c 782void
08ef48c5
MS
783tui_del_data_windows (tui_win_content content,
784 int content_size)
c906108c
SS
785{
786 int i;
787
ef5eab5a
MS
788 /* Remember that data window content elements are of type struct
789 tui_gen_win_info *, each of which whose single element is a data
790 element. */
6ba8e26f 791 for (i = 0; i < content_size; i++)
c906108c 792 {
9a2b4c1b
MS
793 struct tui_gen_win_info *generic_win
794 = &content[i]->which_element.data_window;
c906108c 795
6ba8e26f 796 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 797 {
6ba8e26f 798 tui_delete_win (generic_win->handle);
e65b5245 799 generic_win->handle = NULL;
6ba8e26f 800 generic_win->is_visible = FALSE;
c906108c
SS
801 }
802 }
dd1abb8c 803}
c906108c
SS
804
805
806void
08ef48c5
MS
807tui_free_data_content (tui_win_content content,
808 int content_size)
c906108c
SS
809{
810 int i;
811
ef5eab5a
MS
812 /* Remember that data window content elements are of type struct
813 tui_gen_win_info *, each of which whose single element is a data
814 element. */
6ba8e26f 815 for (i = 0; i < content_size; i++)
c906108c 816 {
9a2b4c1b
MS
817 struct tui_gen_win_info *generic_win
818 = &content[i]->which_element.data_window;
c906108c 819
6ba8e26f 820 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 821 {
6ba8e26f 822 tui_delete_win (generic_win->handle);
e65b5245 823 generic_win->handle = NULL;
6ba8e26f 824 tui_free_win_content (generic_win);
c906108c
SS
825 }
826 }
6ba8e26f 827 free_content (content,
08ef48c5
MS
828 content_size,
829 DATA_WIN);
6ba8e26f 830}
c906108c
SS
831
832
833/**********************************
834** LOCAL STATIC FUNCTIONS **
835**********************************/
836
837
c906108c 838static void
08ef48c5
MS
839free_content (tui_win_content content,
840 int content_size,
841 enum tui_win_type win_type)
c906108c 842{
2a8854a7 843 if (content != (tui_win_content) NULL)
c906108c 844 {
6ba8e26f 845 free_content_elements (content, content_size, win_type);
22940a24 846 xfree (content);
c906108c 847 }
6ba8e26f 848}
c906108c
SS
849
850
ef5eab5a 851/* free_content_elements().
c5aa993b 852 */
c906108c 853static void
08ef48c5
MS
854free_content_elements (tui_win_content content,
855 int content_size,
856 enum tui_win_type type)
c906108c 857{
2a8854a7 858 if (content != (tui_win_content) NULL)
c906108c
SS
859 {
860 int i;
861
862 if (type == SRC_WIN || type == DISASSEM_WIN)
863 {
1cc6d956 864 /* Free whole source block. */
6d012f14 865 xfree (content[0]->which_element.source.line);
c906108c
SS
866 }
867 else
868 {
6ba8e26f 869 for (i = 0; i < content_size; i++)
c906108c 870 {
5b6fe301 871 struct tui_win_element *element;
c906108c
SS
872
873 element = content[i];
2a8854a7 874 if (element != (struct tui_win_element *) NULL)
c906108c
SS
875 {
876 switch (type)
877 {
878 case DATA_WIN:
22940a24 879 xfree (element);
c906108c
SS
880 break;
881 case DATA_ITEM_WIN:
ef5eab5a
MS
882 /* Note that data elements are not allocated in
883 a single block, but individually, as
884 needed. */
6d012f14
AC
885 if (element->which_element.data.type != TUI_REGISTER)
886 xfree ((void *)element->which_element.data.name);
887 xfree (element->which_element.data.value);
10f59415 888 xfree (element->which_element.data.content);
22940a24 889 xfree (element);
c906108c
SS
890 break;
891 case CMD_WIN:
6d012f14 892 xfree (element->which_element.command.line);
c906108c
SS
893 break;
894 default:
895 break;
896 }
897 }
898 }
899 }
900 if (type != DATA_WIN && type != DATA_ITEM_WIN)
1cc6d956 901 xfree (content[0]); /* Free the element block. */
c906108c 902 }
6ba8e26f 903}