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