1 /* TUI data manipulation routines.
3 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation,
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"
39 /****************************
40 ** GLOBAL DECLARATIONS
41 ****************************/
42 struct tui_win_info
*(winList
[MAX_MAJOR_WINDOWS
]);
44 /***************************
46 ****************************/
47 static enum tui_layout_type _currentLayout
= UNDEFINED_LAYOUT
;
48 static int _termHeight
, _termWidth
;
49 static struct tui_gen_win_info _locator
;
50 static struct tui_gen_win_info _execInfo
[2];
51 static struct tui_win_info
* _srcWinList
[2];
52 static struct tui_list _sourceWindows
= {(void **) _srcWinList
, 0};
53 static int _defaultTabLen
= DEFAULT_TAB_LEN
;
54 static struct tui_win_info
* _winWithFocus
= (struct tui_win_info
*) NULL
;
55 static struct tui_layout_def _layoutDef
=
56 {SRC_WIN
, /* displayMode */
58 TUI_UNDEFINED_REGS
, /* regsDisplayType */
59 TUI_SFLOAT_REGS
}; /* floatRegsDisplayType */
60 static int _winResized
= FALSE
;
63 /*********************************
64 ** Static function forward decls
65 **********************************/
66 static void freeContent (tui_win_content
, int, enum tui_win_type
);
67 static void freeContentElements (tui_win_content
, int, enum tui_win_type
);
71 /*********************************
73 **********************************/
75 /******************************************
76 ** ACCESSORS & MUTATORS FOR PRIVATE DATA
77 ******************************************/
79 /* Answer a whether the terminal window has been resized or not. */
81 tui_win_resized (void)
87 /* Set a whether the terminal window has been resized or not. */
89 tui_set_win_resized_to (int resized
)
91 _winResized
= resized
;
95 /* Answer a pointer to the current layout definition. */
96 struct tui_layout_def
*
103 /* Answer the window with the logical focus. */
104 struct tui_win_info
*
105 tui_win_with_focus (void)
107 return _winWithFocus
;
111 /* Set the window that has the logical focus. */
113 tui_set_win_with_focus (struct tui_win_info
* winInfo
)
115 _winWithFocus
= winInfo
;
119 /* Answer the length in chars, of tabs. */
121 tui_default_tab_len (void)
123 return _defaultTabLen
;
127 /* Set the length in chars, of tabs. */
129 tui_set_default_tab_len (int len
)
131 _defaultTabLen
= len
;
136 ** currentSourceWin()
137 ** Accessor for the current source window. Usually there is only
138 ** one source window (either source or disassembly), but both can
139 ** be displayed at the same time.
142 tui_source_windows (void)
144 return &_sourceWindows
;
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
152 tui_clear_source_windows (void)
154 _sourceWindows
.list
[0] = NULL
;
155 _sourceWindows
.list
[1] = NULL
;
156 _sourceWindows
.count
= 0;
160 /* Clear the pertinant detail in the source windows. */
162 tui_clear_source_windows_detail (void)
166 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
167 tui_clear_win_detail ((struct tui_win_info
*) (tui_source_windows ())->list
[i
]);
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. */
175 tui_add_to_source_windows (struct tui_win_info
* winInfo
)
177 if (_sourceWindows
.count
< 2)
178 _sourceWindows
.list
[_sourceWindows
.count
++] = (void *) winInfo
;
182 /* Clear the pertinant detail in the windows. */
184 tui_clear_win_detail (struct tui_win_info
* winInfo
)
186 if (m_winPtrNotNull (winInfo
))
188 switch (winInfo
->generic
.type
)
192 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
= 0;
193 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
196 winInfo
->detail
.commandInfo
.curLine
=
197 winInfo
->detail
.commandInfo
.curch
= 0;
200 winInfo
->detail
.dataDisplayInfo
.dataContent
=
201 (tui_win_content
) NULL
;
202 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
203 winInfo
->detail
.dataDisplayInfo
.regsContent
=
204 (tui_win_content
) NULL
;
205 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
206 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
208 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
209 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
217 } /* clearWinDetail */
221 ** sourceExecInfoPtr().
222 ** Accessor for the source execution info ptr.
224 struct tui_gen_win_info
*
225 tui_source_exec_info_win_ptr (void)
227 return &_execInfo
[0];
228 } /* sourceExecInfoWinPtr */
232 ** disassemExecInfoPtr().
233 ** Accessor for the disassem execution info ptr.
235 struct tui_gen_win_info
*
236 tui_disassem_exec_info_win_ptr (void)
238 return &_execInfo
[1];
239 } /* disassemExecInfoWinPtr */
242 /* Accessor for the locator win info. Answers a pointer to the static
243 locator win info struct. */
244 struct tui_gen_win_info
*
245 tui_locator_win_info_ptr (void)
251 /* Accessor for the termHeight. */
253 tui_term_height (void)
259 /* Mutator for the term height. */
261 tui_set_term_height_to (int h
)
267 /* Accessor for the termWidth. */
269 tui_term_width (void)
275 /* Mutator for the termWidth. */
277 tui_set_term_width_to (int w
)
283 /* Accessor for the current layout. */
285 tui_current_layout (void)
287 return _currentLayout
;
291 /* Mutator for the current layout. */
293 tui_set_current_layout_to (enum tui_layout_type newLayout
)
295 _currentLayout
= newLayout
;
300 ** setGenWinOrigin().
301 ** Set the origin of the window
304 setGenWinOrigin (struct tui_gen_win_info
* winInfo
, int x
, int y
)
306 winInfo
->origin
.x
= x
;
307 winInfo
->origin
.y
= y
;
310 } /* setGenWinOrigin */
313 /*****************************
314 ** OTHER PUBLIC FUNCTIONS
315 *****************************/
318 /* Answer the next window in the list, cycling back to the top if
320 struct tui_win_info
*
321 tui_next_win (struct tui_win_info
* curWin
)
323 enum tui_win_type type
= curWin
->generic
.type
;
324 struct tui_win_info
* nextWin
= (struct tui_win_info
*) NULL
;
326 if (curWin
->generic
.type
== CMD_WIN
)
329 type
= curWin
->generic
.type
+ 1;
330 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (nextWin
))
332 if (winList
[type
] && winList
[type
]->generic
.isVisible
)
333 nextWin
= winList
[type
];
347 /* Answer the prev window in the list, cycling back to the bottom if
349 struct tui_win_info
*
350 tui_prev_win (struct tui_win_info
* curWin
)
352 enum tui_win_type type
= curWin
->generic
.type
;
353 struct tui_win_info
* prev
= (struct tui_win_info
*) NULL
;
355 if (curWin
->generic
.type
== SRC_WIN
)
358 type
= curWin
->generic
.type
- 1;
359 while (type
!= curWin
->generic
.type
&& m_winPtrIsNull (prev
))
361 if (winList
[type
]->generic
.isVisible
)
362 prev
= winList
[type
];
376 /* Answer the window represented by name. */
377 struct tui_win_info
*
378 tui_partial_win_by_name (char *name
)
380 struct tui_win_info
* winInfo
= (struct tui_win_info
*) NULL
;
382 if (name
!= (char *) NULL
)
386 while (i
< MAX_MAJOR_WINDOWS
&& m_winPtrIsNull (winInfo
))
390 char *curName
= tui_win_name (&winList
[i
]->generic
);
391 if (strlen (name
) <= strlen (curName
) &&
392 strncmp (name
, curName
, strlen (name
)) == 0)
393 winInfo
= winList
[i
];
400 } /* partialWinByName */
405 ** Answer the name of the window
408 tui_win_name (struct tui_gen_win_info
* winInfo
)
410 char *name
= (char *) NULL
;
412 switch (winInfo
->type
)
421 name
= DISASSEM_NAME
;
436 tui_initialize_static_data (void)
438 tui_init_generic_part (tui_source_exec_info_win_ptr ());
439 tui_init_generic_part (tui_disassem_exec_info_win_ptr ());
440 tui_init_generic_part (tui_locator_win_info_ptr ());
444 struct tui_gen_win_info
*
445 tui_alloc_generic_win_info (void)
447 struct tui_gen_win_info
* win
;
449 if ((win
= (struct tui_gen_win_info
*) xmalloc (
450 sizeof (struct tui_gen_win_info
*))) != (struct tui_gen_win_info
*) NULL
)
451 tui_init_generic_part (win
);
454 } /* allocGenericWinInfo */
458 ** initGenericPart().
461 tui_init_generic_part (struct tui_gen_win_info
* win
)
467 win
->viewportHeight
=
469 win
->lastVisibleLine
= 0;
470 win
->handle
= (WINDOW
*) NULL
;
473 win
->isVisible
= FALSE
;
479 ** initContentElement().
482 initContentElement (struct tui_win_element
* element
, enum tui_win_type type
)
484 element
->highlight
= FALSE
;
489 element
->whichElement
.source
.line
= (char *) NULL
;
490 element
->whichElement
.source
.lineOrAddr
.lineNo
= 0;
491 element
->whichElement
.source
.isExecPoint
= FALSE
;
492 element
->whichElement
.source
.hasBreak
= FALSE
;
495 tui_init_generic_part (&element
->whichElement
.dataWindow
);
496 element
->whichElement
.dataWindow
.type
= DATA_ITEM_WIN
;
497 ((struct tui_gen_win_info
*) & element
->whichElement
.dataWindow
)->content
=
498 (void **) tui_alloc_content (1, DATA_ITEM_WIN
);
499 ((struct tui_gen_win_info
*)
500 & element
->whichElement
.dataWindow
)->contentSize
= 1;
503 element
->whichElement
.command
.line
= (char *) NULL
;
506 element
->whichElement
.data
.name
= (char *) NULL
;
507 element
->whichElement
.data
.type
= TUI_REGISTER
;
508 element
->whichElement
.data
.itemNo
= UNDEFINED_ITEM
;
509 element
->whichElement
.data
.value
= NULL
;
510 element
->whichElement
.data
.highlight
= FALSE
;
513 element
->whichElement
.locator
.fileName
[0] =
514 element
->whichElement
.locator
.procName
[0] = (char) 0;
515 element
->whichElement
.locator
.lineNo
= 0;
516 element
->whichElement
.locator
.addr
= 0;
519 memset(element
->whichElement
.simpleString
, ' ',
520 sizeof(element
->whichElement
.simpleString
));
526 } /* initContentElement */
532 initWinInfo (struct tui_win_info
* winInfo
)
534 tui_init_generic_part (&winInfo
->generic
);
535 winInfo
->canHighlight
=
536 winInfo
->isHighlighted
= FALSE
;
537 switch (winInfo
->generic
.type
)
541 winInfo
->detail
.sourceInfo
.executionInfo
= (struct tui_gen_win_info
*) NULL
;
542 winInfo
->detail
.sourceInfo
.hasLocator
= FALSE
;
543 winInfo
->detail
.sourceInfo
.horizontalOffset
= 0;
544 winInfo
->detail
.sourceInfo
.startLineOrAddr
.addr
= 0;
545 winInfo
->detail
.sourceInfo
.filename
= 0;
548 winInfo
->detail
.dataDisplayInfo
.dataContent
= (tui_win_content
) NULL
;
549 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
550 winInfo
->detail
.dataDisplayInfo
.regsContent
= (tui_win_content
) NULL
;
551 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
552 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
554 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
555 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
558 winInfo
->detail
.commandInfo
.curLine
= 0;
559 winInfo
->detail
.commandInfo
.curch
= 0;
562 winInfo
->detail
.opaque
= NULL
;
570 struct tui_win_info
*
571 tui_alloc_win_info (enum tui_win_type type
)
573 struct tui_win_info
* winInfo
= (struct tui_win_info
*) NULL
;
575 winInfo
= (struct tui_win_info
*) xmalloc (sizeof (struct tui_win_info
));
576 if (m_winPtrNotNull (winInfo
))
578 winInfo
->generic
.type
= type
;
579 initWinInfo (winInfo
);
588 ** Allocates the content and elements in a block.
591 tui_alloc_content (int numElements
, enum tui_win_type type
)
593 tui_win_content content
= (tui_win_content
) NULL
;
594 char *elementBlockPtr
= (char *) NULL
;
597 if ((content
= (tui_win_content
)
598 xmalloc (sizeof (struct tui_win_element
*) * numElements
)) != (tui_win_content
) NULL
)
600 ** All windows, except the data window, can allocate the elements
601 ** in a chunk. The data window cannot because items can be
602 ** added/removed from the data display by the user at any time.
604 if (type
!= DATA_WIN
)
606 if ((elementBlockPtr
= (char *)
607 xmalloc (sizeof (struct tui_win_element
) * numElements
)) != (char *) NULL
)
609 for (i
= 0; i
< numElements
; i
++)
611 content
[i
] = (struct tui_win_element
*) elementBlockPtr
;
612 initContentElement (content
[i
], type
);
613 elementBlockPtr
+= sizeof (struct tui_win_element
);
619 content
= (tui_win_content
) NULL
;
628 /* Adds the input number of elements to the windows's content. If no
629 content has been allocated yet, allocContent() is called to do
630 this. The index of the first element added is returned, unless
631 there is a memory allocation error, in which case, (-1) is
634 tui_add_content_elements (struct tui_gen_win_info
* winInfo
, int numElements
)
636 struct tui_win_element
* elementPtr
;
639 if (winInfo
->content
== NULL
)
641 winInfo
->content
= (void **) tui_alloc_content (numElements
, winInfo
->type
);
645 indexStart
= winInfo
->contentSize
;
646 if (winInfo
->content
!= NULL
)
648 for (i
= indexStart
; (i
< numElements
+ indexStart
); i
++)
650 if ((elementPtr
= (struct tui_win_element
*)
651 xmalloc (sizeof (struct tui_win_element
))) != (struct tui_win_element
*) NULL
)
653 winInfo
->content
[i
] = (void *) elementPtr
;
654 initContentElement (elementPtr
, winInfo
->type
);
655 winInfo
->contentSize
++;
657 else /* things must be really hosed now! We ran out of memory!? */
663 } /* addContentElements */
666 /* Delete all curses windows associated with winInfo, leaving everything
669 tuiDelWindow (struct tui_win_info
* winInfo
)
671 struct tui_gen_win_info
* genericWin
;
673 switch (winInfo
->generic
.type
)
677 genericWin
= tui_locator_win_info_ptr ();
678 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
680 tui_delete_win (genericWin
->handle
);
681 genericWin
->handle
= (WINDOW
*) NULL
;
682 genericWin
->isVisible
= FALSE
;
684 if (winInfo
->detail
.sourceInfo
.filename
)
686 xfree (winInfo
->detail
.sourceInfo
.filename
);
687 winInfo
->detail
.sourceInfo
.filename
= 0;
689 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
690 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
692 tui_delete_win (genericWin
->handle
);
693 genericWin
->handle
= (WINDOW
*) NULL
;
694 genericWin
->isVisible
= FALSE
;
698 if (winInfo
->generic
.content
!= NULL
)
700 tui_del_data_windows (winInfo
->detail
.dataDisplayInfo
.regsContent
,
701 winInfo
->detail
.dataDisplayInfo
.regsContentCount
);
702 tui_del_data_windows (winInfo
->detail
.dataDisplayInfo
.dataContent
,
703 winInfo
->detail
.dataDisplayInfo
.dataContentCount
);
709 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
711 tui_delete_win (winInfo
->generic
.handle
);
712 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
713 winInfo
->generic
.isVisible
= FALSE
;
719 tui_free_window (struct tui_win_info
* winInfo
)
721 struct tui_gen_win_info
* genericWin
;
723 switch (winInfo
->generic
.type
)
727 genericWin
= tui_locator_win_info_ptr ();
728 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
730 tui_delete_win (genericWin
->handle
);
731 genericWin
->handle
= (WINDOW
*) NULL
;
733 tui_free_win_content (genericWin
);
734 if (winInfo
->detail
.sourceInfo
.filename
)
736 xfree (winInfo
->detail
.sourceInfo
.filename
);
737 winInfo
->detail
.sourceInfo
.filename
= 0;
739 genericWin
= winInfo
->detail
.sourceInfo
.executionInfo
;
740 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
742 tui_delete_win (genericWin
->handle
);
743 genericWin
->handle
= (WINDOW
*) NULL
;
744 tui_free_win_content (genericWin
);
748 if (winInfo
->generic
.content
!= NULL
)
750 tui_free_data_content (winInfo
->detail
.dataDisplayInfo
.regsContent
,
751 winInfo
->detail
.dataDisplayInfo
.regsContentCount
);
752 winInfo
->detail
.dataDisplayInfo
.regsContent
=
753 (tui_win_content
) NULL
;
754 winInfo
->detail
.dataDisplayInfo
.regsContentCount
= 0;
755 tui_free_data_content (winInfo
->detail
.dataDisplayInfo
.dataContent
,
756 winInfo
->detail
.dataDisplayInfo
.dataContentCount
);
757 winInfo
->detail
.dataDisplayInfo
.dataContent
=
758 (tui_win_content
) NULL
;
759 winInfo
->detail
.dataDisplayInfo
.dataContentCount
= 0;
760 winInfo
->detail
.dataDisplayInfo
.regsDisplayType
=
762 winInfo
->detail
.dataDisplayInfo
.regsColumnCount
= 1;
763 winInfo
->detail
.dataDisplayInfo
.displayRegs
= FALSE
;
764 winInfo
->generic
.content
= NULL
;
765 winInfo
->generic
.contentSize
= 0;
771 if (winInfo
->generic
.handle
!= (WINDOW
*) NULL
)
773 tui_delete_win (winInfo
->generic
.handle
);
774 winInfo
->generic
.handle
= (WINDOW
*) NULL
;
775 tui_free_win_content (&winInfo
->generic
);
777 if (winInfo
->generic
.title
)
778 xfree (winInfo
->generic
.title
);
784 tui_free_all_source_wins_content (void)
788 for (i
= 0; i
< (tui_source_windows ())->count
; i
++)
790 struct tui_win_info
* winInfo
= (struct tui_win_info
*) (tui_source_windows ())->list
[i
];
792 if (m_winPtrNotNull (winInfo
))
794 tui_free_win_content (&(winInfo
->generic
));
795 tui_free_win_content (winInfo
->detail
.sourceInfo
.executionInfo
);
802 tui_free_win_content (struct tui_gen_win_info
* winInfo
)
804 if (winInfo
->content
!= NULL
)
806 freeContent ((tui_win_content
) winInfo
->content
,
807 winInfo
->contentSize
,
809 winInfo
->content
= NULL
;
811 winInfo
->contentSize
= 0;
814 } /* freeWinContent */
818 tui_del_data_windows (tui_win_content content
, int contentSize
)
823 ** Remember that data window content elements are of type struct tui_gen_win_info *,
824 ** each of which whose single element is a data element.
826 for (i
= 0; i
< contentSize
; i
++)
828 struct tui_gen_win_info
* genericWin
= &content
[i
]->whichElement
.dataWindow
;
830 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
832 tui_delete_win (genericWin
->handle
);
833 genericWin
->handle
= (WINDOW
*) NULL
;
834 genericWin
->isVisible
= FALSE
;
841 tui_free_data_content (tui_win_content content
, int contentSize
)
846 ** Remember that data window content elements are of type struct tui_gen_win_info *,
847 ** each of which whose single element is a data element.
849 for (i
= 0; i
< contentSize
; i
++)
851 struct tui_gen_win_info
* genericWin
= &content
[i
]->whichElement
.dataWindow
;
853 if (genericWin
!= (struct tui_gen_win_info
*) NULL
)
855 tui_delete_win (genericWin
->handle
);
856 genericWin
->handle
= (WINDOW
*) NULL
;
857 tui_free_win_content (genericWin
);
860 freeContent (content
,
865 } /* freeDataContent */
868 /**********************************
869 ** LOCAL STATIC FUNCTIONS **
870 **********************************/
877 freeContent (tui_win_content content
, int contentSize
, enum tui_win_type winType
)
879 if (content
!= (tui_win_content
) NULL
)
881 freeContentElements (content
, contentSize
, winType
);
890 ** freeContentElements().
893 freeContentElements (tui_win_content content
, int contentSize
, enum tui_win_type type
)
895 if (content
!= (tui_win_content
) NULL
)
899 if (type
== SRC_WIN
|| type
== DISASSEM_WIN
)
901 /* free whole source block */
902 xfree (content
[0]->whichElement
.source
.line
);
906 for (i
= 0; i
< contentSize
; i
++)
908 struct tui_win_element
* element
;
910 element
= content
[i
];
911 if (element
!= (struct tui_win_element
*) NULL
)
920 ** Note that data elements are not allocated
921 ** in a single block, but individually, as needed.
923 if (element
->whichElement
.data
.type
!= TUI_REGISTER
)
924 xfree ((void *)element
->whichElement
.data
.name
);
925 xfree (element
->whichElement
.data
.value
);
929 xfree (element
->whichElement
.command
.line
);
937 if (type
!= DATA_WIN
&& type
!= DATA_ITEM_WIN
)
938 xfree (content
[0]); /* free the element block */
942 } /* freeContentElements */