Fix typo in gdb.python/py-objfile.exp
[deliverable/binutils-gdb.git] / gdb / tui / tui-data.c
CommitLineData
f377b406 1/* TUI data manipulation routines.
f33c6cbf 2
32d0add0 3 Copyright (C) 1998-2015 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****************************/
6d012f14 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;
5b6fe301 44static struct tui_win_info *win_with_focus = (struct tui_win_info *) 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
AC
194 if (source_windows.count < 2)
195 source_windows.list[source_windows.count++] = (void *) 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:
6d012f14
AC
215 win_info->detail.command_info.cur_line =
216 win_info->detail.command_info.curch = 0;
c906108c
SS
217 break;
218 case DATA_WIN:
6d012f14 219 win_info->detail.data_display_info.data_content =
2a8854a7 220 (tui_win_content) NULL;
6d012f14
AC
221 win_info->detail.data_display_info.data_content_count = 0;
222 win_info->detail.data_display_info.regs_content =
2a8854a7 223 (tui_win_content) NULL;
6d012f14 224 win_info->detail.data_display_info.regs_content_count = 0;
6d012f14
AC
225 win_info->detail.data_display_info.regs_column_count = 1;
226 win_info->detail.data_display_info.display_regs = FALSE;
c906108c
SS
227 break;
228 default:
229 break;
230 }
231 }
6ba8e26f 232}
c906108c
SS
233
234
6ba8e26f 235/* Accessor for the source execution info ptr. */
2a8854a7 236struct tui_gen_win_info *
dd1abb8c 237tui_source_exec_info_win_ptr (void)
c906108c 238{
6ba8e26f
AC
239 return &exec_info[0];
240}
c906108c
SS
241
242
6ba8e26f 243/* Accessor for the disassem execution info ptr. */
2a8854a7 244struct tui_gen_win_info *
dd1abb8c 245tui_disassem_exec_info_win_ptr (void)
c906108c 246{
6ba8e26f
AC
247 return &exec_info[1];
248}
c906108c
SS
249
250
dd1abb8c
AC
251/* Accessor for the locator win info. Answers a pointer to the static
252 locator win info struct. */
2a8854a7 253struct tui_gen_win_info *
dd1abb8c 254tui_locator_win_info_ptr (void)
c906108c
SS
255{
256 return &_locator;
2a8854a7 257}
c906108c
SS
258
259
6ba8e26f 260/* Accessor for the term_height. */
c906108c 261int
dd1abb8c 262tui_term_height (void)
c906108c 263{
6ba8e26f 264 return term_height;
dd1abb8c 265}
c906108c
SS
266
267
1cc6d956 268/* Mutator for the term height. */
c906108c 269void
dd1abb8c 270tui_set_term_height_to (int h)
c906108c 271{
6ba8e26f 272 term_height = h;
dd1abb8c 273}
c906108c
SS
274
275
1cc6d956 276/* Accessor for the term_width. */
c906108c 277int
dd1abb8c 278tui_term_width (void)
c906108c 279{
6ba8e26f 280 return term_width;
dd1abb8c 281}
c906108c
SS
282
283
6ba8e26f 284/* Mutator for the term_width. */
c906108c 285void
dd1abb8c 286tui_set_term_width_to (int w)
c906108c 287{
6ba8e26f 288 term_width = w;
dd1abb8c 289}
c906108c
SS
290
291
1cc6d956 292/* Accessor for the current layout. */
2a8854a7 293enum tui_layout_type
dd1abb8c 294tui_current_layout (void)
c906108c 295{
6ba8e26f 296 return current_layout;
dd1abb8c 297}
c906108c
SS
298
299
dd1abb8c 300/* Mutator for the current layout. */
c906108c 301void
6ba8e26f 302tui_set_current_layout_to (enum tui_layout_type new_layout)
c906108c 303{
6ba8e26f 304 current_layout = new_layout;
dd1abb8c 305}
c906108c
SS
306
307
c906108c
SS
308/*****************************
309** OTHER PUBLIC FUNCTIONS
310*****************************/
311
312
dd1abb8c
AC
313/* Answer the next window in the list, cycling back to the top if
314 necessary. */
2a8854a7 315struct tui_win_info *
5b6fe301 316tui_next_win (struct tui_win_info *cur_win)
c906108c 317{
570dc176 318 int type = cur_win->generic.type;
5b6fe301 319 struct tui_win_info *next_win = (struct tui_win_info *) NULL;
c906108c 320
6ba8e26f 321 if (cur_win->generic.type == CMD_WIN)
c906108c
SS
322 type = SRC_WIN;
323 else
6ba8e26f
AC
324 type = cur_win->generic.type + 1;
325 while (type != cur_win->generic.type && (next_win == NULL))
c906108c 326 {
e5908723
MS
327 if (tui_win_list[type]
328 && tui_win_list[type]->generic.is_visible)
6ba8e26f 329 next_win = tui_win_list[type];
c906108c
SS
330 else
331 {
332 if (type == CMD_WIN)
333 type = SRC_WIN;
334 else
335 type++;
336 }
337 }
338
6ba8e26f
AC
339 return next_win;
340}
c906108c
SS
341
342
dd1abb8c
AC
343/* Answer the prev window in the list, cycling back to the bottom if
344 necessary. */
2a8854a7 345struct tui_win_info *
5b6fe301 346tui_prev_win (struct tui_win_info *cur_win)
c906108c 347{
570dc176 348 int type = cur_win->generic.type;
5b6fe301 349 struct tui_win_info *prev = (struct tui_win_info *) NULL;
c906108c 350
6ba8e26f 351 if (cur_win->generic.type == SRC_WIN)
c906108c
SS
352 type = CMD_WIN;
353 else
6ba8e26f
AC
354 type = cur_win->generic.type - 1;
355 while (type != cur_win->generic.type && (prev == NULL))
c906108c 356 {
37715c4c
TJB
357 if (tui_win_list[type]
358 && tui_win_list[type]->generic.is_visible)
6d012f14 359 prev = tui_win_list[type];
c906108c
SS
360 else
361 {
362 if (type == SRC_WIN)
363 type = CMD_WIN;
364 else
365 type--;
366 }
367 }
368
369 return prev;
cb50eddd 370}
c906108c
SS
371
372
1cc6d956 373/* Answer the window represented by name. */
2a8854a7 374struct tui_win_info *
dd1abb8c 375tui_partial_win_by_name (char *name)
c906108c 376{
5b6fe301 377 struct tui_win_info *win_info = (struct tui_win_info *) NULL;
c906108c
SS
378
379 if (name != (char *) NULL)
380 {
381 int i = 0;
382
6d012f14 383 while (i < MAX_MAJOR_WINDOWS && win_info == NULL)
c906108c 384 {
6d012f14 385 if (tui_win_list[i] != 0)
a4b99e53 386 {
f41cbf58
AB
387 const char *cur_name =
388 tui_win_name (&tui_win_list[i]->generic);
1c5313c5 389
e5908723 390 if (strlen (name) <= strlen (cur_name)
61012eef 391 && startswith (cur_name, name))
6d012f14 392 win_info = tui_win_list[i];
a4b99e53 393 }
c906108c
SS
394 i++;
395 }
396 }
397
6d012f14 398 return win_info;
6ba8e26f 399}
c906108c
SS
400
401
6ba8e26f 402/* Answer the name of the window. */
f41cbf58
AB
403const char *
404tui_win_name (const struct tui_gen_win_info *win_info)
c906108c
SS
405{
406 char *name = (char *) NULL;
407
6d012f14 408 switch (win_info->type)
c906108c
SS
409 {
410 case SRC_WIN:
411 name = SRC_NAME;
412 break;
413 case CMD_WIN:
414 name = CMD_NAME;
415 break;
416 case DISASSEM_WIN:
417 name = DISASSEM_NAME;
418 break;
419 case DATA_WIN:
420 name = DATA_NAME;
421 break;
422 default:
423 name = "";
424 break;
425 }
426
427 return name;
6ba8e26f 428}
c906108c
SS
429
430
c906108c 431void
dd1abb8c 432tui_initialize_static_data (void)
c906108c 433{
dd1abb8c
AC
434 tui_init_generic_part (tui_source_exec_info_win_ptr ());
435 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
436 tui_init_generic_part (tui_locator_win_info_ptr ());
437}
c906108c
SS
438
439
2a8854a7 440struct tui_gen_win_info *
dd1abb8c 441tui_alloc_generic_win_info (void)
c906108c 442{
5b6fe301 443 struct tui_gen_win_info *win;
c906108c 444
70ba0933 445 if ((win = XNEW (struct tui_gen_win_info)) != NULL)
dd1abb8c 446 tui_init_generic_part (win);
c906108c
SS
447
448 return win;
6ba8e26f 449}
c906108c
SS
450
451
c906108c 452void
5b6fe301 453tui_init_generic_part (struct tui_gen_win_info *win)
c906108c
SS
454{
455 win->width =
456 win->height =
457 win->origin.x =
458 win->origin.y =
6d012f14
AC
459 win->viewport_height =
460 win->content_size =
461 win->last_visible_line = 0;
c906108c 462 win->handle = (WINDOW *) NULL;
22940a24 463 win->content = NULL;
6d012f14
AC
464 win->content_in_use =
465 win->is_visible = FALSE;
bc6b7f04
SC
466 win->title = 0;
467}
c906108c
SS
468
469
ef5eab5a 470/* init_content_element().
c5aa993b 471 */
2c0b251b 472static void
08ef48c5
MS
473init_content_element (struct tui_win_element *element,
474 enum tui_win_type type)
c906108c
SS
475{
476 element->highlight = FALSE;
477 switch (type)
478 {
479 case SRC_WIN:
480 case DISASSEM_WIN:
6d012f14 481 element->which_element.source.line = (char *) NULL;
362c05fe
AS
482 element->which_element.source.line_or_addr.loa = LOA_LINE;
483 element->which_element.source.line_or_addr.u.line_no = 0;
6d012f14
AC
484 element->which_element.source.is_exec_point = FALSE;
485 element->which_element.source.has_break = FALSE;
c906108c
SS
486 break;
487 case DATA_WIN:
6d012f14
AC
488 tui_init_generic_part (&element->which_element.data_window);
489 element->which_element.data_window.type = DATA_ITEM_WIN;
63ed8182
PP
490 element->which_element.data_window.content =
491 tui_alloc_content (1, DATA_ITEM_WIN);
492 element->which_element.data_window.content_size = 1;
c906108c
SS
493 break;
494 case CMD_WIN:
6d012f14 495 element->which_element.command.line = (char *) NULL;
c906108c
SS
496 break;
497 case DATA_ITEM_WIN:
6d012f14
AC
498 element->which_element.data.name = (char *) NULL;
499 element->which_element.data.type = TUI_REGISTER;
500 element->which_element.data.item_no = UNDEFINED_ITEM;
501 element->which_element.data.value = NULL;
502 element->which_element.data.highlight = FALSE;
10f59415 503 element->which_element.data.content = (char*) NULL;
c906108c
SS
504 break;
505 case LOCATOR_WIN:
56d397a3 506 element->which_element.locator.full_name[0] =
6d012f14
AC
507 element->which_element.locator.proc_name[0] = (char) 0;
508 element->which_element.locator.line_no = 0;
509 element->which_element.locator.addr = 0;
c906108c
SS
510 break;
511 case EXEC_INFO_WIN:
6d012f14
AC
512 memset(element->which_element.simple_string, ' ',
513 sizeof(element->which_element.simple_string));
c906108c
SS
514 break;
515 default:
516 break;
517 }
6ba8e26f 518}
c906108c 519
2c0b251b 520static void
5b6fe301 521init_win_info (struct tui_win_info *win_info)
c906108c 522{
6d012f14
AC
523 tui_init_generic_part (&win_info->generic);
524 win_info->can_highlight =
525 win_info->is_highlighted = FALSE;
526 switch (win_info->generic.type)
c906108c
SS
527 {
528 case SRC_WIN:
529 case DISASSEM_WIN:
9a2b4c1b
MS
530 win_info->detail.source_info.execution_info
531 = (struct tui_gen_win_info *) NULL;
6d012f14
AC
532 win_info->detail.source_info.has_locator = FALSE;
533 win_info->detail.source_info.horizontal_offset = 0;
13274fc3 534 win_info->detail.source_info.gdbarch = NULL;
362c05fe
AS
535 win_info->detail.source_info.start_line_or_addr.loa = LOA_ADDRESS;
536 win_info->detail.source_info.start_line_or_addr.u.addr = 0;
aa079c93 537 win_info->detail.source_info.fullname = NULL;
c906108c
SS
538 break;
539 case DATA_WIN:
6d012f14
AC
540 win_info->detail.data_display_info.data_content = (tui_win_content) NULL;
541 win_info->detail.data_display_info.data_content_count = 0;
542 win_info->detail.data_display_info.regs_content = (tui_win_content) NULL;
543 win_info->detail.data_display_info.regs_content_count = 0;
6d012f14
AC
544 win_info->detail.data_display_info.regs_column_count = 1;
545 win_info->detail.data_display_info.display_regs = FALSE;
10f59415 546 win_info->detail.data_display_info.current_group = 0;
c906108c
SS
547 break;
548 case CMD_WIN:
6d012f14
AC
549 win_info->detail.command_info.cur_line = 0;
550 win_info->detail.command_info.curch = 0;
c906108c
SS
551 break;
552 default:
6d012f14 553 win_info->detail.opaque = NULL;
c906108c
SS
554 break;
555 }
6ba8e26f 556}
c906108c
SS
557
558
2a8854a7 559struct tui_win_info *
22940a24 560tui_alloc_win_info (enum tui_win_type type)
c906108c 561{
5b6fe301 562 struct tui_win_info *win_info;
c906108c 563
70ba0933 564 win_info = XNEW (struct tui_win_info);
c0645fb5 565 if (win_info != NULL)
c906108c 566 {
6d012f14 567 win_info->generic.type = type;
6ba8e26f 568 init_win_info (win_info);
c906108c
SS
569 }
570
6d012f14 571 return win_info;
6ba8e26f 572}
c906108c
SS
573
574
6ba8e26f 575/* Allocates the content and elements in a block. */
2a8854a7 576tui_win_content
6ba8e26f 577tui_alloc_content (int num_elements, enum tui_win_type type)
c906108c 578{
c0645fb5
MS
579 tui_win_content content;
580 char *element_block_ptr;
c906108c
SS
581 int i;
582
5b6fe301 583 content = xmalloc (sizeof (struct tui_win_element *) *num_elements);
c0645fb5
MS
584 if (content != NULL)
585 {
586 /*
587 * All windows, except the data window, can allocate the
588 * elements in a chunk. The data window cannot because items
589 * can be added/removed from the data display by the user at any
590 * time.
591 */
c906108c
SS
592 if (type != DATA_WIN)
593 {
c0645fb5
MS
594 element_block_ptr =
595 xmalloc (sizeof (struct tui_win_element) * num_elements);
596 if (element_block_ptr != NULL)
c906108c 597 {
6ba8e26f 598 for (i = 0; i < num_elements; i++)
c906108c 599 {
6ba8e26f
AC
600 content[i] = (struct tui_win_element *) element_block_ptr;
601 init_content_element (content[i], type);
602 element_block_ptr += sizeof (struct tui_win_element);
c906108c
SS
603 }
604 }
605 else
606 {
22940a24 607 xfree (content);
2a8854a7 608 content = (tui_win_content) NULL;
c906108c
SS
609 }
610 }
611 }
612
613 return content;
6ba8e26f 614}
c906108c
SS
615
616
dd1abb8c 617/* Adds the input number of elements to the windows's content. If no
6ba8e26f 618 content has been allocated yet, alloc_content() is called to do
dd1abb8c
AC
619 this. The index of the first element added is returned, unless
620 there is a memory allocation error, in which case, (-1) is
621 returned. */
c906108c 622int
08ef48c5
MS
623tui_add_content_elements (struct tui_gen_win_info *win_info,
624 int num_elements)
c906108c 625{
5b6fe301 626 struct tui_win_element *element_ptr;
6ba8e26f 627 int i, index_start;
c906108c 628
6d012f14 629 if (win_info->content == NULL)
c906108c 630 {
63ed8182 631 win_info->content = tui_alloc_content (num_elements, win_info->type);
6ba8e26f 632 index_start = 0;
c906108c
SS
633 }
634 else
6ba8e26f 635 index_start = win_info->content_size;
6d012f14 636 if (win_info->content != NULL)
c906108c 637 {
6ba8e26f 638 for (i = index_start; (i < num_elements + index_start); i++)
c906108c 639 {
70ba0933 640 if ((element_ptr = XNEW (struct tui_win_element)) != NULL)
c906108c 641 {
6ba8e26f
AC
642 win_info->content[i] = (void *) element_ptr;
643 init_content_element (element_ptr, win_info->type);
6d012f14 644 win_info->content_size++;
c906108c 645 }
1cc6d956
MS
646 else /* Things must be really hosed now! We ran out of
647 memory!? */
c906108c
SS
648 return (-1);
649 }
650 }
651
6ba8e26f
AC
652 return index_start;
653}
c906108c
SS
654
655
1cc6d956
MS
656/* Delete all curses windows associated with win_info, leaving
657 everything else intact. */
c906108c 658void
5b6fe301 659tui_del_window (struct tui_win_info *win_info)
c906108c 660{
5b6fe301 661 struct tui_gen_win_info *generic_win;
c906108c 662
6d012f14 663 switch (win_info->generic.type)
c906108c
SS
664 {
665 case SRC_WIN:
666 case DISASSEM_WIN:
6ba8e26f
AC
667 generic_win = tui_locator_win_info_ptr ();
668 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 669 {
6ba8e26f
AC
670 tui_delete_win (generic_win->handle);
671 generic_win->handle = (WINDOW *) NULL;
672 generic_win->is_visible = FALSE;
c906108c 673 }
aa079c93 674 if (win_info->detail.source_info.fullname)
bc6b7f04 675 {
aa079c93
JK
676 xfree (win_info->detail.source_info.fullname);
677 win_info->detail.source_info.fullname = NULL;
bc6b7f04 678 }
6ba8e26f
AC
679 generic_win = win_info->detail.source_info.execution_info;
680 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 681 {
6ba8e26f
AC
682 tui_delete_win (generic_win->handle);
683 generic_win->handle = (WINDOW *) NULL;
684 generic_win->is_visible = FALSE;
c906108c
SS
685 }
686 break;
687 case DATA_WIN:
6d012f14 688 if (win_info->generic.content != NULL)
c906108c 689 {
6d012f14
AC
690 tui_del_data_windows (win_info->detail.data_display_info.regs_content,
691 win_info->detail.data_display_info.regs_content_count);
692 tui_del_data_windows (win_info->detail.data_display_info.data_content,
693 win_info->detail.data_display_info.data_content_count);
c906108c
SS
694 }
695 break;
696 default:
697 break;
698 }
6d012f14 699 if (win_info->generic.handle != (WINDOW *) NULL)
c906108c 700 {
6d012f14
AC
701 tui_delete_win (win_info->generic.handle);
702 win_info->generic.handle = (WINDOW *) NULL;
703 win_info->generic.is_visible = FALSE;
c906108c 704 }
bc6b7f04 705}
c906108c
SS
706
707
c906108c 708void
5b6fe301 709tui_free_window (struct tui_win_info *win_info)
c906108c 710{
5b6fe301 711 struct tui_gen_win_info *generic_win;
c906108c 712
6d012f14 713 switch (win_info->generic.type)
c906108c
SS
714 {
715 case SRC_WIN:
716 case DISASSEM_WIN:
aa079c93 717 if (win_info->detail.source_info.fullname)
bc6b7f04 718 {
aa079c93
JK
719 xfree (win_info->detail.source_info.fullname);
720 win_info->detail.source_info.fullname = NULL;
bc6b7f04 721 }
6ba8e26f
AC
722 generic_win = win_info->detail.source_info.execution_info;
723 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 724 {
6ba8e26f
AC
725 tui_delete_win (generic_win->handle);
726 generic_win->handle = (WINDOW *) NULL;
727 tui_free_win_content (generic_win);
c906108c
SS
728 }
729 break;
730 case DATA_WIN:
6d012f14 731 if (win_info->generic.content != NULL)
c906108c 732 {
6d012f14
AC
733 tui_free_data_content (win_info->detail.data_display_info.regs_content,
734 win_info->detail.data_display_info.regs_content_count);
735 win_info->detail.data_display_info.regs_content =
2a8854a7 736 (tui_win_content) NULL;
6d012f14
AC
737 win_info->detail.data_display_info.regs_content_count = 0;
738 tui_free_data_content (win_info->detail.data_display_info.data_content,
739 win_info->detail.data_display_info.data_content_count);
740 win_info->detail.data_display_info.data_content =
2a8854a7 741 (tui_win_content) NULL;
6d012f14 742 win_info->detail.data_display_info.data_content_count = 0;
6d012f14
AC
743 win_info->detail.data_display_info.regs_column_count = 1;
744 win_info->detail.data_display_info.display_regs = FALSE;
745 win_info->generic.content = NULL;
746 win_info->generic.content_size = 0;
c906108c
SS
747 }
748 break;
749 default:
750 break;
751 }
6d012f14 752 if (win_info->generic.handle != (WINDOW *) NULL)
c906108c 753 {
6d012f14
AC
754 tui_delete_win (win_info->generic.handle);
755 win_info->generic.handle = (WINDOW *) NULL;
756 tui_free_win_content (&win_info->generic);
c906108c 757 }
6d012f14
AC
758 if (win_info->generic.title)
759 xfree (win_info->generic.title);
760 xfree (win_info);
bc6b7f04 761}
c906108c
SS
762
763
c906108c 764void
dd1abb8c 765tui_free_all_source_wins_content (void)
c906108c
SS
766{
767 int i;
768
dd1abb8c 769 for (i = 0; i < (tui_source_windows ())->count; i++)
c906108c 770 {
5b6fe301 771 struct tui_win_info *win_info = (tui_source_windows ())->list[i];
c906108c 772
6d012f14 773 if (win_info != NULL)
c906108c 774 {
6d012f14
AC
775 tui_free_win_content (&(win_info->generic));
776 tui_free_win_content (win_info->detail.source_info.execution_info);
c906108c
SS
777 }
778 }
dd1abb8c 779}
c906108c
SS
780
781
c906108c 782void
5b6fe301 783tui_free_win_content (struct tui_gen_win_info *win_info)
c906108c 784{
6d012f14 785 if (win_info->content != NULL)
c906108c 786 {
6ba8e26f 787 free_content ((tui_win_content) win_info->content,
6d012f14
AC
788 win_info->content_size,
789 win_info->type);
790 win_info->content = NULL;
c906108c 791 }
6d012f14 792 win_info->content_size = 0;
6ba8e26f 793}
c906108c
SS
794
795
c906108c 796void
08ef48c5
MS
797tui_del_data_windows (tui_win_content content,
798 int content_size)
c906108c
SS
799{
800 int i;
801
ef5eab5a
MS
802 /* Remember that data window content elements are of type struct
803 tui_gen_win_info *, each of which whose single element is a data
804 element. */
6ba8e26f 805 for (i = 0; i < content_size; i++)
c906108c 806 {
9a2b4c1b
MS
807 struct tui_gen_win_info *generic_win
808 = &content[i]->which_element.data_window;
c906108c 809
6ba8e26f 810 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 811 {
6ba8e26f
AC
812 tui_delete_win (generic_win->handle);
813 generic_win->handle = (WINDOW *) NULL;
814 generic_win->is_visible = FALSE;
c906108c
SS
815 }
816 }
dd1abb8c 817}
c906108c
SS
818
819
820void
08ef48c5
MS
821tui_free_data_content (tui_win_content content,
822 int content_size)
c906108c
SS
823{
824 int i;
825
ef5eab5a
MS
826 /* Remember that data window content elements are of type struct
827 tui_gen_win_info *, each of which whose single element is a data
828 element. */
6ba8e26f 829 for (i = 0; i < content_size; i++)
c906108c 830 {
9a2b4c1b
MS
831 struct tui_gen_win_info *generic_win
832 = &content[i]->which_element.data_window;
c906108c 833
6ba8e26f 834 if (generic_win != (struct tui_gen_win_info *) NULL)
c906108c 835 {
6ba8e26f
AC
836 tui_delete_win (generic_win->handle);
837 generic_win->handle = (WINDOW *) NULL;
838 tui_free_win_content (generic_win);
c906108c
SS
839 }
840 }
6ba8e26f 841 free_content (content,
08ef48c5
MS
842 content_size,
843 DATA_WIN);
6ba8e26f 844}
c906108c
SS
845
846
847/**********************************
848** LOCAL STATIC FUNCTIONS **
849**********************************/
850
851
c906108c 852static void
08ef48c5
MS
853free_content (tui_win_content content,
854 int content_size,
855 enum tui_win_type win_type)
c906108c 856{
2a8854a7 857 if (content != (tui_win_content) NULL)
c906108c 858 {
6ba8e26f 859 free_content_elements (content, content_size, win_type);
22940a24 860 xfree (content);
c906108c 861 }
6ba8e26f 862}
c906108c
SS
863
864
ef5eab5a 865/* free_content_elements().
c5aa993b 866 */
c906108c 867static void
08ef48c5
MS
868free_content_elements (tui_win_content content,
869 int content_size,
870 enum tui_win_type type)
c906108c 871{
2a8854a7 872 if (content != (tui_win_content) NULL)
c906108c
SS
873 {
874 int i;
875
876 if (type == SRC_WIN || type == DISASSEM_WIN)
877 {
1cc6d956 878 /* Free whole source block. */
6d012f14 879 xfree (content[0]->which_element.source.line);
c906108c
SS
880 }
881 else
882 {
6ba8e26f 883 for (i = 0; i < content_size; i++)
c906108c 884 {
5b6fe301 885 struct tui_win_element *element;
c906108c
SS
886
887 element = content[i];
2a8854a7 888 if (element != (struct tui_win_element *) NULL)
c906108c
SS
889 {
890 switch (type)
891 {
892 case DATA_WIN:
22940a24 893 xfree (element);
c906108c
SS
894 break;
895 case DATA_ITEM_WIN:
ef5eab5a
MS
896 /* Note that data elements are not allocated in
897 a single block, but individually, as
898 needed. */
6d012f14
AC
899 if (element->which_element.data.type != TUI_REGISTER)
900 xfree ((void *)element->which_element.data.name);
901 xfree (element->which_element.data.value);
10f59415 902 xfree (element->which_element.data.content);
22940a24 903 xfree (element);
c906108c
SS
904 break;
905 case CMD_WIN:
6d012f14 906 xfree (element->which_element.command.line);
c906108c
SS
907 break;
908 default:
909 break;
910 }
911 }
912 }
913 }
914 if (type != DATA_WIN && type != DATA_ITEM_WIN)
1cc6d956 915 xfree (content[0]); /* Free the element block. */
c906108c 916 }
6ba8e26f 917}
This page took 1.607304 seconds and 4 git commands to generate.