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