1 /* TUI data manipulation routines.
3 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
4 Free Software Foundation, Inc.
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., 51 Franklin Street, Fifth Floor,
23 Boston, MA 02110-1301, 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
= {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 ((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
.loa
= LOA_ADDRESS
;
211 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
212 win_info
->detail
.source_info
.horizontal_offset
= 0;
215 win_info
->detail
.command_info
.cur_line
=
216 win_info
->detail
.command_info
.curch
= 0;
219 win_info
->detail
.data_display_info
.data_content
=
220 (tui_win_content
) NULL
;
221 win_info
->detail
.data_display_info
.data_content_count
= 0;
222 win_info
->detail
.data_display_info
.regs_content
=
223 (tui_win_content
) NULL
;
224 win_info
->detail
.data_display_info
.regs_content_count
= 0;
225 win_info
->detail
.data_display_info
.regs_display_type
=
227 win_info
->detail
.data_display_info
.regs_column_count
= 1;
228 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
237 /* Accessor for the source execution info ptr. */
238 struct tui_gen_win_info
*
239 tui_source_exec_info_win_ptr (void)
241 return &exec_info
[0];
245 /* Accessor for the disassem execution info ptr. */
246 struct tui_gen_win_info
*
247 tui_disassem_exec_info_win_ptr (void)
249 return &exec_info
[1];
253 /* Accessor for the locator win info. Answers a pointer to the static
254 locator win info struct. */
255 struct tui_gen_win_info
*
256 tui_locator_win_info_ptr (void)
262 /* Accessor for the term_height. */
264 tui_term_height (void)
270 /* Mutator for the term height. */
272 tui_set_term_height_to (int h
)
278 /* Accessor for the term_width. */
280 tui_term_width (void)
286 /* Mutator for the term_width. */
288 tui_set_term_width_to (int w
)
294 /* Accessor for the current layout. */
296 tui_current_layout (void)
298 return current_layout
;
302 /* Mutator for the current layout. */
304 tui_set_current_layout_to (enum tui_layout_type new_layout
)
306 current_layout
= new_layout
;
310 /* Set the origin of the window. */
312 set_gen_win_origin (struct tui_gen_win_info
* win_info
, int x
, int y
)
314 win_info
->origin
.x
= x
;
315 win_info
->origin
.y
= y
;
319 /*****************************
320 ** OTHER PUBLIC FUNCTIONS
321 *****************************/
324 /* Answer the next window in the list, cycling back to the top if
326 struct tui_win_info
*
327 tui_next_win (struct tui_win_info
* cur_win
)
329 enum tui_win_type type
= cur_win
->generic
.type
;
330 struct tui_win_info
* next_win
= (struct tui_win_info
*) NULL
;
332 if (cur_win
->generic
.type
== CMD_WIN
)
335 type
= cur_win
->generic
.type
+ 1;
336 while (type
!= cur_win
->generic
.type
&& (next_win
== NULL
))
338 if (tui_win_list
[type
] && tui_win_list
[type
]->generic
.is_visible
)
339 next_win
= tui_win_list
[type
];
353 /* Answer the prev window in the list, cycling back to the bottom if
355 struct tui_win_info
*
356 tui_prev_win (struct tui_win_info
* cur_win
)
358 enum tui_win_type type
= cur_win
->generic
.type
;
359 struct tui_win_info
* prev
= (struct tui_win_info
*) NULL
;
361 if (cur_win
->generic
.type
== SRC_WIN
)
364 type
= cur_win
->generic
.type
- 1;
365 while (type
!= cur_win
->generic
.type
&& (prev
== NULL
))
367 if (tui_win_list
[type
]->generic
.is_visible
)
368 prev
= tui_win_list
[type
];
382 /* Answer the window represented by name. */
383 struct tui_win_info
*
384 tui_partial_win_by_name (char *name
)
386 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
388 if (name
!= (char *) NULL
)
392 while (i
< MAX_MAJOR_WINDOWS
&& win_info
== NULL
)
394 if (tui_win_list
[i
] != 0)
396 char *cur_name
= tui_win_name (&tui_win_list
[i
]->generic
);
397 if (strlen (name
) <= strlen (cur_name
) &&
398 strncmp (name
, cur_name
, strlen (name
)) == 0)
399 win_info
= tui_win_list
[i
];
409 /* Answer the name of the window. */
411 tui_win_name (struct tui_gen_win_info
* win_info
)
413 char *name
= (char *) NULL
;
415 switch (win_info
->type
)
424 name
= DISASSEM_NAME
;
439 tui_initialize_static_data (void)
441 tui_init_generic_part (tui_source_exec_info_win_ptr ());
442 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
443 tui_init_generic_part (tui_locator_win_info_ptr ());
447 struct tui_gen_win_info
*
448 tui_alloc_generic_win_info (void)
450 struct tui_gen_win_info
* win
;
452 if ((win
= (struct tui_gen_win_info
*) xmalloc (
453 sizeof (struct tui_gen_win_info
*))) != (struct tui_gen_win_info
*) NULL
)
454 tui_init_generic_part (win
);
461 tui_init_generic_part (struct tui_gen_win_info
* win
)
467 win
->viewport_height
=
469 win
->last_visible_line
= 0;
470 win
->handle
= (WINDOW
*) NULL
;
472 win
->content_in_use
=
473 win
->is_visible
= FALSE
;
479 ** init_content_element().
482 init_content_element (struct tui_win_element
* element
, enum tui_win_type type
)
484 element
->highlight
= FALSE
;
489 element
->which_element
.source
.line
= (char *) NULL
;
490 element
->which_element
.source
.line_or_addr
.loa
= LOA_LINE
;
491 element
->which_element
.source
.line_or_addr
.u
.line_no
= 0;
492 element
->which_element
.source
.is_exec_point
= FALSE
;
493 element
->which_element
.source
.has_break
= FALSE
;
496 tui_init_generic_part (&element
->which_element
.data_window
);
497 element
->which_element
.data_window
.type
= DATA_ITEM_WIN
;
498 ((struct tui_gen_win_info
*) & element
->which_element
.data_window
)->content
=
499 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
500 ((struct tui_gen_win_info
*)
501 & element
->which_element
.data_window
)->content_size
= 1;
504 element
->which_element
.command
.line
= (char *) NULL
;
507 element
->which_element
.data
.name
= (char *) NULL
;
508 element
->which_element
.data
.type
= TUI_REGISTER
;
509 element
->which_element
.data
.item_no
= UNDEFINED_ITEM
;
510 element
->which_element
.data
.value
= NULL
;
511 element
->which_element
.data
.highlight
= FALSE
;
512 element
->which_element
.data
.content
= (char*) NULL
;
515 element
->which_element
.locator
.file_name
[0] =
516 element
->which_element
.locator
.proc_name
[0] = (char) 0;
517 element
->which_element
.locator
.line_no
= 0;
518 element
->which_element
.locator
.addr
= 0;
521 memset(element
->which_element
.simple_string
, ' ',
522 sizeof(element
->which_element
.simple_string
));
530 init_win_info (struct tui_win_info
* win_info
)
532 tui_init_generic_part (&win_info
->generic
);
533 win_info
->can_highlight
=
534 win_info
->is_highlighted
= FALSE
;
535 switch (win_info
->generic
.type
)
539 win_info
->detail
.source_info
.execution_info
= (struct tui_gen_win_info
*) NULL
;
540 win_info
->detail
.source_info
.has_locator
= FALSE
;
541 win_info
->detail
.source_info
.horizontal_offset
= 0;
542 win_info
->detail
.source_info
.start_line_or_addr
.loa
= LOA_ADDRESS
;
543 win_info
->detail
.source_info
.start_line_or_addr
.u
.addr
= 0;
544 win_info
->detail
.source_info
.filename
= 0;
547 win_info
->detail
.data_display_info
.data_content
= (tui_win_content
) NULL
;
548 win_info
->detail
.data_display_info
.data_content_count
= 0;
549 win_info
->detail
.data_display_info
.regs_content
= (tui_win_content
) NULL
;
550 win_info
->detail
.data_display_info
.regs_content_count
= 0;
551 win_info
->detail
.data_display_info
.regs_display_type
=
553 win_info
->detail
.data_display_info
.regs_column_count
= 1;
554 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
555 win_info
->detail
.data_display_info
.current_group
= 0;
558 win_info
->detail
.command_info
.cur_line
= 0;
559 win_info
->detail
.command_info
.curch
= 0;
562 win_info
->detail
.opaque
= NULL
;
568 struct tui_win_info
*
569 tui_alloc_win_info (enum tui_win_type type
)
571 struct tui_win_info
* win_info
= (struct tui_win_info
*) NULL
;
573 win_info
= (struct tui_win_info
*) xmalloc (sizeof (struct tui_win_info
));
574 if ((win_info
!= NULL
))
576 win_info
->generic
.type
= type
;
577 init_win_info (win_info
);
584 /* Allocates the content and elements in a block. */
586 tui_alloc_content (int num_elements
, enum tui_win_type type
)
588 tui_win_content content
= (tui_win_content
) NULL
;
589 char *element_block_ptr
= (char *) NULL
;
592 if ((content
= (tui_win_content
)
593 xmalloc (sizeof (struct tui_win_element
*) * num_elements
)) != (tui_win_content
) NULL
)
595 ** All windows, except the data window, can allocate the elements
596 ** in a chunk. The data window cannot because items can be
597 ** added/removed from the data display by the user at any time.
599 if (type
!= DATA_WIN
)
601 if ((element_block_ptr
= (char *)
602 xmalloc (sizeof (struct tui_win_element
) * num_elements
)) != (char *) NULL
)
604 for (i
= 0; i
< num_elements
; i
++)
606 content
[i
] = (struct tui_win_element
*) element_block_ptr
;
607 init_content_element (content
[i
], type
);
608 element_block_ptr
+= sizeof (struct tui_win_element
);
614 content
= (tui_win_content
) NULL
;
623 /* Adds the input number of elements to the windows's content. If no
624 content has been allocated yet, alloc_content() is called to do
625 this. The index of the first element added is returned, unless
626 there is a memory allocation error, in which case, (-1) is
629 tui_add_content_elements (struct tui_gen_win_info
* win_info
, int num_elements
)
631 struct tui_win_element
* element_ptr
;
634 if (win_info
->content
== NULL
)
636 win_info
->content
= (void **) tui_alloc_content (num_elements
, win_info
->type
);
640 index_start
= win_info
->content_size
;
641 if (win_info
->content
!= NULL
)
643 for (i
= index_start
; (i
< num_elements
+ index_start
); i
++)
645 if ((element_ptr
= (struct tui_win_element
*)
646 xmalloc (sizeof (struct tui_win_element
))) != (struct tui_win_element
*) NULL
)
648 win_info
->content
[i
] = (void *) element_ptr
;
649 init_content_element (element_ptr
, win_info
->type
);
650 win_info
->content_size
++;
652 else /* things must be really hosed now! We ran out of memory!? */
661 /* Delete all curses windows associated with win_info, leaving everything
664 tui_del_window (struct tui_win_info
* win_info
)
666 struct tui_gen_win_info
* generic_win
;
668 switch (win_info
->generic
.type
)
672 generic_win
= tui_locator_win_info_ptr ();
673 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
675 tui_delete_win (generic_win
->handle
);
676 generic_win
->handle
= (WINDOW
*) NULL
;
677 generic_win
->is_visible
= FALSE
;
679 if (win_info
->detail
.source_info
.filename
)
681 xfree (win_info
->detail
.source_info
.filename
);
682 win_info
->detail
.source_info
.filename
= 0;
684 generic_win
= win_info
->detail
.source_info
.execution_info
;
685 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
687 tui_delete_win (generic_win
->handle
);
688 generic_win
->handle
= (WINDOW
*) NULL
;
689 generic_win
->is_visible
= FALSE
;
693 if (win_info
->generic
.content
!= NULL
)
695 tui_del_data_windows (win_info
->detail
.data_display_info
.regs_content
,
696 win_info
->detail
.data_display_info
.regs_content_count
);
697 tui_del_data_windows (win_info
->detail
.data_display_info
.data_content
,
698 win_info
->detail
.data_display_info
.data_content_count
);
704 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
706 tui_delete_win (win_info
->generic
.handle
);
707 win_info
->generic
.handle
= (WINDOW
*) NULL
;
708 win_info
->generic
.is_visible
= FALSE
;
714 tui_free_window (struct tui_win_info
* win_info
)
716 struct tui_gen_win_info
* generic_win
;
718 switch (win_info
->generic
.type
)
722 generic_win
= tui_locator_win_info_ptr ();
723 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
725 tui_delete_win (generic_win
->handle
);
726 generic_win
->handle
= (WINDOW
*) NULL
;
728 tui_free_win_content (generic_win
);
729 if (win_info
->detail
.source_info
.filename
)
731 xfree (win_info
->detail
.source_info
.filename
);
732 win_info
->detail
.source_info
.filename
= 0;
734 generic_win
= win_info
->detail
.source_info
.execution_info
;
735 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
737 tui_delete_win (generic_win
->handle
);
738 generic_win
->handle
= (WINDOW
*) NULL
;
739 tui_free_win_content (generic_win
);
743 if (win_info
->generic
.content
!= NULL
)
745 tui_free_data_content (win_info
->detail
.data_display_info
.regs_content
,
746 win_info
->detail
.data_display_info
.regs_content_count
);
747 win_info
->detail
.data_display_info
.regs_content
=
748 (tui_win_content
) NULL
;
749 win_info
->detail
.data_display_info
.regs_content_count
= 0;
750 tui_free_data_content (win_info
->detail
.data_display_info
.data_content
,
751 win_info
->detail
.data_display_info
.data_content_count
);
752 win_info
->detail
.data_display_info
.data_content
=
753 (tui_win_content
) NULL
;
754 win_info
->detail
.data_display_info
.data_content_count
= 0;
755 win_info
->detail
.data_display_info
.regs_display_type
=
757 win_info
->detail
.data_display_info
.regs_column_count
= 1;
758 win_info
->detail
.data_display_info
.display_regs
= FALSE
;
759 win_info
->generic
.content
= NULL
;
760 win_info
->generic
.content_size
= 0;
766 if (win_info
->generic
.handle
!= (WINDOW
*) NULL
)
768 tui_delete_win (win_info
->generic
.handle
);
769 win_info
->generic
.handle
= (WINDOW
*) NULL
;
770 tui_free_win_content (&win_info
->generic
);
772 if (win_info
->generic
.title
)
773 xfree (win_info
->generic
.title
);
779 tui_free_all_source_wins_content (void)
783 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
785 struct tui_win_info
* win_info
= (tui_source_windows ())->list
[i
];
787 if (win_info
!= NULL
)
789 tui_free_win_content (&(win_info
->generic
));
790 tui_free_win_content (win_info
->detail
.source_info
.execution_info
);
797 tui_free_win_content (struct tui_gen_win_info
* win_info
)
799 if (win_info
->content
!= NULL
)
801 free_content ((tui_win_content
) win_info
->content
,
802 win_info
->content_size
,
804 win_info
->content
= NULL
;
806 win_info
->content_size
= 0;
811 tui_del_data_windows (tui_win_content content
, int content_size
)
816 ** Remember that data window content elements are of type struct tui_gen_win_info *,
817 ** each of which whose single element is a data element.
819 for (i
= 0; i
< content_size
; i
++)
821 struct tui_gen_win_info
* generic_win
= &content
[i
]->which_element
.data_window
;
823 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
825 tui_delete_win (generic_win
->handle
);
826 generic_win
->handle
= (WINDOW
*) NULL
;
827 generic_win
->is_visible
= FALSE
;
834 tui_free_data_content (tui_win_content content
, int content_size
)
839 ** Remember that data window content elements are of type struct tui_gen_win_info *,
840 ** each of which whose single element is a data element.
842 for (i
= 0; i
< content_size
; i
++)
844 struct tui_gen_win_info
* generic_win
= &content
[i
]->which_element
.data_window
;
846 if (generic_win
!= (struct tui_gen_win_info
*) NULL
)
848 tui_delete_win (generic_win
->handle
);
849 generic_win
->handle
= (WINDOW
*) NULL
;
850 tui_free_win_content (generic_win
);
853 free_content (content
,
859 /**********************************
860 ** LOCAL STATIC FUNCTIONS **
861 **********************************/
865 free_content (tui_win_content content
, int content_size
, enum tui_win_type win_type
)
867 if (content
!= (tui_win_content
) NULL
)
869 free_content_elements (content
, content_size
, win_type
);
876 ** free_content_elements().
879 free_content_elements (tui_win_content content
, int content_size
, enum tui_win_type type
)
881 if (content
!= (tui_win_content
) NULL
)
885 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
887 /* free whole source block */
888 xfree (content
[0]->which_element
.source
.line
);
892 for (i
= 0; i
< content_size
; i
++)
894 struct tui_win_element
* element
;
896 element
= content
[i
];
897 if (element
!= (struct tui_win_element
*) NULL
)
906 ** Note that data elements are not allocated
907 ** in a single block, but individually, as needed.
909 if (element
->which_element
.data
.type
!= TUI_REGISTER
)
910 xfree ((void *)element
->which_element
.data
.name
);
911 xfree (element
->which_element
.data
.value
);
912 xfree (element
->which_element
.data
.content
);
916 xfree (element
->which_element
.command
.line
);
924 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
925 xfree (content
[0]); /* free the element block */