1 /* TUI data manipulation routines.
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
6 Contributed by Hewlett-Packard Company.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
28 #include "tui/tui-data.h"
29 #include "tui/tui-wingeneral.h"
31 #include "gdb_string.h"
32 #include "gdb_curses.h"
34 /****************************
35 ** GLOBAL DECLARATIONS
36 ****************************/
37 struct tui_win_info
*(tui_win_list
[MAX_MAJOR_WINDOWS
]);
39 /***************************
41 ****************************/
42 static enum tui_layout_type current_layout
= UNDEFINED_LAYOUT
;
43 static int term_height
, term_width
;
44 static struct tui_gen_win_info _locator
;
45 static struct tui_gen_win_info exec_info
[2];
46 static struct tui_win_info
* src_win_list
[2];
47 static struct tui_list source_windows
= {(void **) src_win_list
, 0};
48 static int default_tab_len
= DEFAULT_TAB_LEN
;
49 static struct tui_win_info
* win_with_focus
= (struct tui_win_info
*) NULL
;
50 static struct tui_layout_def layout_def
=
51 {SRC_WIN
, /* DISPLAY_MODE */
53 TUI_UNDEFINED_REGS
, /* REGS_DISPLAY_TYPE */
54 TUI_SFLOAT_REGS
}; /* FLOAT_REGS_DISPLAY_TYPE */
55 static int win_resized
= FALSE
;
58 /*********************************
59 ** Static function forward decls
60 **********************************/
61 static void free_content (tui_win_content
, int, enum tui_win_type
);
62 static void free_content_elements (tui_win_content
, int, enum tui_win_type
);
66 /*********************************
68 **********************************/
71 tui_win_is_source_type (enum tui_win_type win_type
)
73 return (win_type
== SRC_WIN
|| win_type
== DISASSEM_WIN
);
77 tui_win_is_auxillary (enum tui_win_type win_type
)
79 return (win_type
> MAX_MAJOR_WINDOWS
);
83 tui_win_has_locator (struct tui_win_info
*win_info
)
85 return (win_info
!= NULL \
86 && win_info
->detail
.source_info
.has_locator
);
90 tui_set_win_highlight (struct tui_win_info
*win_info
, int highlight
)
93 win_info
->is_highlighted
= highlight
;
96 /******************************************
97 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
98 ******************************************/
100 /* Answer a whether the terminal window has been resized or not. */
102 tui_win_resized (void)
108 /* Set a whether the terminal window has been resized or not. */
110 tui_set_win_resized_to (int resized
)
112 win_resized
= resized
;
116 /* Answer a pointer to the current layout definition. */
117 struct tui_layout_def
*
118 tui_layout_def (void)
124 /* Answer the window with the logical focus. */
125 struct tui_win_info
*
126 tui_win_with_focus (void)
128 return win_with_focus
;
132 /* Set the window that has the logical focus. */
134 tui_set_win_with_focus (struct tui_win_info
* win_info
)
136 win_with_focus
= win_info
;
140 /* Answer the length in chars, of tabs. */
142 tui_default_tab_len (void)
144 return default_tab_len
;
148 /* Set the length in chars, of tabs. */
150 tui_set_default_tab_len (int len
)
152 default_tab_len
= len
;
156 /* Accessor for the current source window. Usually there is only one
157 source window (either source or disassembly), but both can be
158 displayed at the same time. */
160 tui_source_windows (void)
162 return &source_windows
;
166 /* Clear the list of source windows. Usually there is only one source
167 window (either source or disassembly), but both can be displayed at
170 tui_clear_source_windows (void)
172 source_windows
.list
[0] = NULL
;
173 source_windows
.list
[1] = NULL
;
174 source_windows
.count
= 0;
178 /* Clear the pertinant detail in the source windows. */
180 tui_clear_source_windows_detail (void)
184 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
185 tui_clear_win_detail ((struct tui_win_info
*) (tui_source_windows ())->list
[i
]);
189 /* Add a window to the list of source windows. Usually there is only
190 one source window (either source or disassembly), but both can be
191 displayed at the same time. */
193 tui_add_to_source_windows (struct tui_win_info
* win_info
)
195 if (source_windows
.count
< 2)
196 source_windows
.list
[source_windows
.count
++] = (void *) win_info
;
200 /* Clear the pertinant detail in the windows. */
202 tui_clear_win_detail (struct tui_win_info
* win_info
)
204 if (win_info
!= NULL
)
206 switch (win_info
->generic
.type
)
210 win_info
->detail
.source_info
.start_line_or_addr
.addr
= 0;
211 win_info
->detail
.source_info
.horizontal_offset
= 0;
214 win_info
->detail
.command_info
.cur_line
=
215 win_info
->detail
.command_info
.curch
= 0;
218 win_info
->detail
.data_display_info
.data_content
=
219 (tui_win_content
) NULL
;
220 win_info
->detail
.data_display_info
.data_content_count
= 0;
221 win_info
->detail
.data_display_info
.regs_content
=
222 (tui_win_content
) NULL
;
223 win_info
->detail
.data_display_info
.regs_content_count
= 0;
224 win_info
->detail
.data_display_info
.regs_display_type
=
226 win_info
->detail
.data_display_info
.regs_column_count
= 1;
227 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
236 /* Accessor for the source execution info ptr. */
237 struct tui_gen_win_info
*
238 tui_source_exec_info_win_ptr (void)
240 return &exec_info
[0];
244 /* Accessor for the disassem execution info ptr. */
245 struct tui_gen_win_info
*
246 tui_disassem_exec_info_win_ptr (void)
248 return &exec_info
[1];
252 /* Accessor for the locator win info. Answers a pointer to the static
253 locator win info struct. */
254 struct tui_gen_win_info
*
255 tui_locator_win_info_ptr (void)
261 /* Accessor for the term_height. */
263 tui_term_height (void)
269 /* Mutator for the term height. */
271 tui_set_term_height_to (int h
)
277 /* Accessor for the term_width. */
279 tui_term_width (void)
285 /* Mutator for the term_width. */
287 tui_set_term_width_to (int w
)
293 /* Accessor for the current layout. */
295 tui_current_layout (void)
297 return current_layout
;
301 /* Mutator for the current layout. */
303 tui_set_current_layout_to (enum tui_layout_type new_layout
)
305 current_layout
= new_layout
;
309 /* Set the origin of the window. */
311 set_gen_win_origin (struct tui_gen_win_info
* win_info
, int x
, int y
)
313 win_info
->origin
.x
= x
;
314 win_info
->origin
.y
= y
;
318 /*****************************
319 ** OTHER PUBLIC FUNCTIONS
320 *****************************/
323 /* Answer the next window in the list, cycling back to the top if
325 struct tui_win_info
*
326 tui_next_win (struct tui_win_info
* cur_win
)
328 enum tui_win_type type
= cur_win
->generic
.type
;
329 struct tui_win_info
* next_win
= (struct tui_win_info
*) NULL
;
331 if (cur_win
->generic
.type
== CMD_WIN
)
334 type
= cur_win
->generic
.type
+ 1;
335 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
337 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
338 next_win
= tui_win_list
[type
];
352 /* Answer the prev window in the list, cycling back to the bottom if
354 struct tui_win_info
*
355 tui_prev_win (struct tui_win_info
* cur_win
)
357 enum tui_win_type type
= cur_win
->generic
.type
;
358 struct tui_win_info
* prev
= (struct tui_win_info
*) NULL
;
360 if (cur_win
->generic
.type
== SRC_WIN
)
363 type
= cur_win
->generic
.type
- 1;
364 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
366 if (tui_win_list
[type
]->generic
.is_visible
)
367 prev
= tui_win_list
[type
];
381 /* Answer the window represented by name. */
382 struct tui_win_info
*
383 tui_partial_win_by_name (char *name
)
385 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
387 if (name
!= (char *) NULL
)
391 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
393 if (tui_win_list
[i
] != 0)
395 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
396 if (strlen (name
) <= strlen (cur_name
) &&
397 strncmp (name
, cur_name
, strlen (name
)) == 0)
398 win_info
= tui_win_list
[i
];
408 /* Answer the name of the window. */
410 tui_win_name (struct tui_gen_win_info
* win_info
)
412 char *name
= (char *) NULL
;
414 switch (win_info
->type
)
423 name
= DISASSEM_NAME
;
438 tui_initialize_static_data (void)
440 tui_init_generic_part (tui_source_exec_info_win_ptr ());
441 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
442 tui_init_generic_part (tui_locator_win_info_ptr ());
446 struct tui_gen_win_info
*
447 tui_alloc_generic_win_info (void)
449 struct tui_gen_win_info
* win
;
451 if ((win
= (struct tui_gen_win_info
*) xmalloc (
452 sizeof (struct tui_gen_win_info
*))) != (struct tui_gen_win_info
*) NULL
)
453 tui_init_generic_part (win
);
460 tui_init_generic_part (struct tui_gen_win_info
* win
)
466 win
->viewport_height
=
468 win
->last_visible_line
= 0;
469 win
->handle
= (WINDOW
*) NULL
;
471 win
->content_in_use
=
472 win
->is_visible
= FALSE
;
478 ** init_content_element().
481 init_content_element (struct tui_win_element
* element
, enum tui_win_type type
)
483 element
->highlight
= FALSE
;
488 element
->which_element
.source
.line
= (char *) NULL
;
489 element
->which_element
.source
.line_or_addr
.line_no
= 0;
490 element
->which_element
.source
.is_exec_point
= FALSE
;
491 element
->which_element
.source
.has_break
= FALSE
;
494 tui_init_generic_part (&element
->which_element
.data_window
);
495 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
496 ((struct tui_gen_win_info
*) & element
->which_element
.data_window
)->content
=
497 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
498 ((struct tui_gen_win_info
*)
499 & element
->which_element
.data_window
)->content_size
= 1;
502 element
->which_element
.command
.line
= (char *) NULL
;
505 element
->which_element
.data
.name
= (char *) NULL
;
506 element
->which_element
.data
.type
= TUI_REGISTER
;
507 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
508 element
->which_element
.data
.value
= NULL
;
509 element
->which_element
.data
.highlight
= FALSE
;
512 element
->which_element
.locator
.file_name
[0] =
513 element
->which_element
.locator
.proc_name
[0] = (char) 0;
514 element
->which_element
.locator
.line_no
= 0;
515 element
->which_element
.locator
.addr
= 0;
518 memset(element
->which_element
.simple_string
, ' ',
519 sizeof(element
->which_element
.simple_string
));
527 init_win_info (struct tui_win_info
* win_info
)
529 tui_init_generic_part (&win_info
->generic
);
530 win_info
->can_highlight
=
531 win_info
->is_highlighted
= FALSE
;
532 switch (win_info
->generic
.type
)
536 win_info
->detail
.source_info
.execution_info
= (struct tui_gen_win_info
*) NULL
;
537 win_info
->detail
.source_info
.has_locator
= FALSE
;
538 win_info
->detail
.source_info
.horizontal_offset
= 0;
539 win_info
->detail
.source_info
.start_line_or_addr
.addr
= 0;
540 win_info
->detail
.source_info
.filename
= 0;
543 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
544 win_info
->detail
.data_display_info
.data_content_count
= 0;
545 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
546 win_info
->detail
.data_display_info
.regs_content_count
= 0;
547 win_info
->detail
.data_display_info
.regs_display_type
=
549 win_info
->detail
.data_display_info
.regs_column_count
= 1;
550 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
553 win_info
->detail
.command_info
.cur_line
= 0;
554 win_info
->detail
.command_info
.curch
= 0;
557 win_info
->detail
.opaque
= NULL
;
563 struct tui_win_info
*
564 tui_alloc_win_info (enum tui_win_type type
)
566 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
568 win_info
= (struct tui_win_info
*) xmalloc (sizeof (struct tui_win_info
));
569 if ((win_info
!= NULL
))
571 win_info
->generic
.type
= type
;
572 init_win_info (win_info
);
579 /* Allocates the content and elements in a block. */
581 tui_alloc_content (int num_elements
, enum tui_win_type type
)
583 tui_win_content content
= (tui_win_content
) NULL
;
584 char *element_block_ptr
= (char *) NULL
;
587 if ((content
= (tui_win_content
)
588 xmalloc (sizeof (struct tui_win_element
*) * num_elements
)) != (tui_win_content
) NULL
)
590 ** All windows, except the data window, can allocate the elements
591 ** in a chunk. The data window cannot because items can be
592 ** added/removed from the data display by the user at any time.
594 if (type
!= DATA_WIN
)
596 if ((element_block_ptr
= (char *)
597 xmalloc (sizeof (struct tui_win_element
) * num_elements
)) != (char *) NULL
)
599 for (i
= 0; i
< num_elements
; i
++)
601 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
602 init_content_element (content
[i
], type
);
603 element_block_ptr
+= sizeof (struct tui_win_element
);
609 content
= (tui_win_content
) NULL
;
618 /* Adds the input number of elements to the windows's content. If no
619 content has been allocated yet, alloc_content() is called to do
620 this. The index of the first element added is returned, unless
621 there is a memory allocation error, in which case, (-1) is
624 tui_add_content_elements (struct tui_gen_win_info
* win_info
, int num_elements
)
626 struct tui_win_element
* element_ptr
;
629 if (win_info
->content
== NULL
)
631 win_info
->content
= (void **) tui_alloc_content (num_elements
, win_info
->type
);
635 index_start
= win_info
->content_size
;
636 if (win_info
->content
!= NULL
)
638 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
640 if ((element_ptr
= (struct tui_win_element
*)
641 xmalloc (sizeof (struct tui_win_element
))) != (struct tui_win_element
*) NULL
)
643 win_info
->content
[i
] = (void *) element_ptr
;
644 init_content_element (element_ptr
, win_info
->type
);
645 win_info
->content_size
++;
647 else /* things must be really hosed now! We ran out of memory!? */
656 /* Delete all curses windows associated with win_info, leaving everything
659 tui_del_window (struct tui_win_info
* win_info
)
661 struct tui_gen_win_info
* generic_win
;
663 switch (win_info
->generic
.type
)
667 generic_win
= tui_locator_win_info_ptr ();
668 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
670 tui_delete_win (generic_win
->handle
);
671 generic_win
->handle
= (WINDOW
*) NULL
;
672 generic_win
->is_visible
= FALSE
;
674 if (win_info
->detail
.source_info
.filename
)
676 xfree (win_info
->detail
.source_info
.filename
);
677 win_info
->detail
.source_info
.filename
= 0;
679 generic_win
= win_info
->detail
.source_info
.execution_info
;
680 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
682 tui_delete_win (generic_win
->handle
);
683 generic_win
->handle
= (WINDOW
*) NULL
;
684 generic_win
->is_visible
= FALSE
;
688 if (win_info
->generic
.content
!= NULL
)
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
);
699 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
701 tui_delete_win (win_info
->generic
.handle
);
702 win_info
->generic
.handle
= (WINDOW
*) NULL
;
703 win_info
->generic
.is_visible
= FALSE
;
709 tui_free_window (struct tui_win_info
* win_info
)
711 struct tui_gen_win_info
* generic_win
;
713 switch (win_info
->generic
.type
)
717 generic_win
= tui_locator_win_info_ptr ();
718 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
720 tui_delete_win (generic_win
->handle
);
721 generic_win
->handle
= (WINDOW
*) NULL
;
723 tui_free_win_content (generic_win
);
724 if (win_info
->detail
.source_info
.filename
)
726 xfree (win_info
->detail
.source_info
.filename
);
727 win_info
->detail
.source_info
.filename
= 0;
729 generic_win
= win_info
->detail
.source_info
.execution_info
;
730 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
732 tui_delete_win (generic_win
->handle
);
733 generic_win
->handle
= (WINDOW
*) NULL
;
734 tui_free_win_content (generic_win
);
738 if (win_info
->generic
.content
!= NULL
)
740 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
741 win_info
->detail
.data_display_info
.regs_content_count
);
742 win_info
->detail
.data_display_info
.regs_content
=
743 (tui_win_content
) NULL
;
744 win_info
->detail
.data_display_info
.regs_content_count
= 0;
745 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
746 win_info
->detail
.data_display_info
.data_content_count
);
747 win_info
->detail
.data_display_info
.data_content
=
748 (tui_win_content
) NULL
;
749 win_info
->detail
.data_display_info
.data_content_count
= 0;
750 win_info
->detail
.data_display_info
.regs_display_type
=
752 win_info
->detail
.data_display_info
.regs_column_count
= 1;
753 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
754 win_info
->generic
.content
= NULL
;
755 win_info
->generic
.content_size
= 0;
761 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
763 tui_delete_win (win_info
->generic
.handle
);
764 win_info
->generic
.handle
= (WINDOW
*) NULL
;
765 tui_free_win_content (&win_info
->generic
);
767 if (win_info
->generic
.title
)
768 xfree (win_info
->generic
.title
);
774 tui_free_all_source_wins_content (void)
778 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
780 struct tui_win_info
* win_info
= (struct tui_win_info
*) (tui_source_windows ())->list
[i
];
782 if (win_info
!= NULL
)
784 tui_free_win_content (&(win_info
->generic
));
785 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
792 tui_free_win_content (struct tui_gen_win_info
* win_info
)
794 if (win_info
->content
!= NULL
)
796 free_content ((tui_win_content
) win_info
->content
,
797 win_info
->content_size
,
799 win_info
->content
= NULL
;
801 win_info
->content_size
= 0;
806 tui_del_data_windows (tui_win_content content
, int content_size
)
811 ** Remember that data window content elements are of type struct tui_gen_win_info *,
812 ** each of which whose single element is a data element.
814 for (i
= 0; i
< content_size
; i
++)
816 struct tui_gen_win_info
* generic_win
= &content
[i
]->which_element
.data_window
;
818 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
820 tui_delete_win (generic_win
->handle
);
821 generic_win
->handle
= (WINDOW
*) NULL
;
822 generic_win
->is_visible
= FALSE
;
829 tui_free_data_content (tui_win_content content
, int content_size
)
834 ** Remember that data window content elements are of type struct tui_gen_win_info *,
835 ** each of which whose single element is a data element.
837 for (i
= 0; i
< content_size
; i
++)
839 struct tui_gen_win_info
* generic_win
= &content
[i
]->which_element
.data_window
;
841 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
843 tui_delete_win (generic_win
->handle
);
844 generic_win
->handle
= (WINDOW
*) NULL
;
845 tui_free_win_content (generic_win
);
848 free_content (content
,
854 /**********************************
855 ** LOCAL STATIC FUNCTIONS **
856 **********************************/
860 free_content (tui_win_content content
, int content_size
, enum tui_win_type win_type
)
862 if (content
!= (tui_win_content
) NULL
)
864 free_content_elements (content
, content_size
, win_type
);
871 ** free_content_elements().
874 free_content_elements (tui_win_content content
, int content_size
, enum tui_win_type type
)
876 if (content
!= (tui_win_content
) NULL
)
880 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
882 /* free whole source block */
883 xfree (content
[0]->which_element
.source
.line
);
887 for (i
= 0; i
< content_size
; i
++)
889 struct tui_win_element
* element
;
891 element
= content
[i
];
892 if (element
!= (struct tui_win_element
*) NULL
)
901 ** Note that data elements are not allocated
902 ** in a single block, but individually, as needed.
904 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
905 xfree ((void *)element
->which_element
.data
.name
);
906 xfree (element
->which_element
.data
.value
);
910 xfree (element
->which_element
.command
.line
);
918 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
919 xfree (content
[0]); /* free the element block */