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