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