1 /* TUI display locator.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Hewlett-Packard Company.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "breakpoint.h"
31 #include "tuiGeneralWin.h"
32 #include "tuiSource.h"
33 #include "tuiSourceWin.h"
36 /*****************************************
37 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
38 ******************************************/
40 static char *_getFuncNameFromFrame (struct frame_info
*);
41 static void _tuiUpdateLocation_command (char *, int);
45 /*****************************************
47 ******************************************/
50 ** tuiClearLocatorDisplay()
53 tuiClearLocatorDisplay (void)
55 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
58 if (locator
->handle
!= (WINDOW
*) NULL
)
60 /* No need to werase, since writing a line of
61 * blanks which we do below, is equivalent.
63 /* werase(locator->handle); */
64 wmove (locator
->handle
, 0, 0);
65 wstandout (locator
->handle
);
66 for (i
= 0; i
< locator
->width
; i
++)
67 waddch (locator
->handle
, ' ');
68 wstandend (locator
->handle
);
69 tuiRefreshWin (locator
);
70 wmove (locator
->handle
, 0, 0);
71 locator
->contentInUse
= FALSE
;
75 } /* tuiClearLocatorDisplay */
79 ** tuiShowLocatorContent()
82 tuiShowLocatorContent (void)
85 TuiGenWinInfoPtr locator
;
87 locator
= locatorWinInfoPtr ();
89 if (m_genWinPtrNotNull (locator
) && locator
->handle
!= (WINDOW
*) NULL
)
91 string
= displayableWinContentAt (locator
, 0);
92 if (string
!= (char *) NULL
)
94 wmove (locator
->handle
, 0, 0);
95 wstandout (locator
->handle
);
96 waddstr (locator
->handle
, string
);
97 wstandend (locator
->handle
);
98 tuiRefreshWin (locator
);
99 wmove (locator
->handle
, 0, 0);
100 if (string
!= nullStr ())
102 locator
->contentInUse
= TRUE
;
107 } /* tuiShowLocatorContent */
111 ** tuiSetLocatorInfo().
112 ** Function to update the locator, with the provided arguments.
115 tuiSetLocatorInfo (char *fname
, char *procname
, int lineNo
,
116 CORE_ADDR addr
, TuiLocatorElementPtr element
)
119 /* first free the old info */
120 if (element
->fileName
)
121 tuiFree (element
->fileName
);
122 if (element
->procName
)
123 tuiFree (element
->procName
);
125 if (fname
== (char *) NULL
)
126 element
->fileName
= fname
;
128 element
->fileName
= tuiStrDup (fname
);
129 if (procname
== (char *) NULL
)
130 element
->procName
= procname
;
132 element
->procName
= tuiStrDup (procname
);
134 element
->fileName
[0] = (char) 0;
135 element
->procName
[0] = (char) 0;
136 strcat_to_buf (element
->fileName
, MAX_LOCATOR_ELEMENT_LEN
, fname
);
137 strcat_to_buf (element
->procName
, MAX_LOCATOR_ELEMENT_LEN
, procname
);
139 element
->lineNo
= lineNo
;
140 element
->addr
= addr
;
143 } /* tuiSetLocatorInfo */
147 ** tuiUpdateLocatorFilename().
148 ** Update only the filename portion of the locator.
151 tuiUpdateLocatorFilename (char *fileName
)
153 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
155 if (locator
->content
[0] == (Opaque
) NULL
)
156 tuiSetLocatorContent ((struct frame_info
*) NULL
);
157 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
158 strcat_to_buf (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
,
159 MAX_LOCATOR_ELEMENT_LEN
,
162 tuiShowLocatorContent ();
165 } /* tuiUpdateLocatorFilename */
168 ** tuiSwitchFilename().
169 ** Update the filename portion of the locator. Clear the other info in locator.
173 tuiSwitchFilename (char *fileName
)
175 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
177 if (locator
->content
[0] == (Opaque
) NULL
)
178 tuiSetLocatorContent ((struct frame_info
*) NULL
);
179 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
181 tuiSetLocatorInfo (fileName
,
185 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
187 tuiShowLocatorContent ();
190 } /* tuiSwitchFilename */
194 ** tuiGetLocatorFilename().
195 ** Get the filename portion of the locator.
199 tuiGetLocatorFilename (TuiGenWinInfoPtr locator
, char **filename
)
202 /* the current filename could be non known, in which case the xmalloc would
203 allocate no memory, because the length would be 0 */
204 if (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
)
207 strlen (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
209 (*filename
) = (char *) xmalloc (name_length
+ 1);
211 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
215 } /* tuiGetLocatorFilename */
219 ** tuiUpdateLocatorInfoFromFrame().
220 ** Function to update the locator, with the information extracted from frameInfo
223 tuiUpdateLocatorInfoFromFrame (struct frame_info
*frameInfo
,
224 TuiLocatorElementPtr element
)
226 struct symtab_and_line symtabAndLine
;
228 /* now get the new info */
229 symtabAndLine
= find_pc_line (frameInfo
->pc
,
230 (frameInfo
->next
!= (struct frame_info
*) NULL
&&
231 !frameInfo
->next
->signal_handler_caller
&&
232 !frame_in_dummy (frameInfo
->next
)));
233 if (symtabAndLine
.symtab
&& symtabAndLine
.symtab
->filename
)
234 tuiSetLocatorInfo (symtabAndLine
.symtab
->filename
,
235 _getFuncNameFromFrame (frameInfo
),
240 tuiSetLocatorInfo ((char *) NULL
,
241 _getFuncNameFromFrame (frameInfo
),
247 } /* tuiUpdateLocatorInfoFromFrame */
251 ** tuiSetLocatorContent().
252 ** Function to set the content of the locator
255 tuiSetLocatorContent (struct frame_info
*frameInfo
)
257 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
258 TuiWinElementPtr element
;
259 struct symtab_and_line symtabAndLine
;
261 /* Allocate the element if necessary */
262 if (locator
->contentSize
<= 0)
264 TuiWinContent contentPtr
;
266 if ((locator
->content
= (OpaquePtr
) allocContent (1, locator
->type
)) == (OpaquePtr
) NULL
)
267 error ("Unable to Allocate Memory to Display Location.");
268 locator
->contentSize
= 1;
271 if (frameInfo
!= (struct frame_info
*) NULL
)
272 tuiUpdateLocatorInfoFromFrame (frameInfo
,
273 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
275 tuiSetLocatorInfo ((char *) NULL
,
279 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
281 } /* tuiSetLocatorContent */
285 ** tuiUpdateLocatorDisplay().
286 ** Function to update the locator display
289 tuiUpdateLocatorDisplay (struct frame_info
*frameInfo
)
291 tuiClearLocatorDisplay ();
292 tuiSetLocatorContent (frameInfo
);
293 tuiShowLocatorContent ();
296 } /* tuiUpdateLocatorDisplay */
300 ** tuiShowFrameInfo().
301 ** Function to print the frame inforrmation for the TUI.
304 tuiShowFrameInfo (struct frame_info
*fi
)
306 TuiWinInfoPtr winInfo
;
311 register int startLine
, i
;
312 register struct symtab
*s
;
314 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
315 int sourceAlreadyDisplayed
;
318 s
= find_pc_symtab (fi
->pc
);
323 sourceAlreadyDisplayed
= tuiSourceIsDisplayed (s
->filename
);
324 tuiUpdateLocatorDisplay (fi
);
325 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
327 TuiWhichElement
*item
;
328 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
330 item
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
;
331 if (winInfo
== srcWin
)
333 startLine
= (item
->locator
.lineNo
-
334 (winInfo
->generic
.viewportHeight
/ 2)) + 1;
340 if (find_pc_partial_function (fi
->pc
, (char **) NULL
, &low
, (CORE_ADDR
) NULL
) == 0)
341 error ("No function contains program counter for selected frame.\n");
343 low
= tuiGetLowDisassemblyAddress (low
, fi
->pc
);
346 if (winInfo
== srcWin
)
349 l
.lineNo
= startLine
;
350 if (!(sourceAlreadyDisplayed
351 && tuiLineIsDisplayed (item
->locator
.lineNo
, winInfo
, TRUE
)))
352 tuiUpdateSourceWindow (winInfo
, s
, l
, TRUE
);
355 l
.lineNo
= item
->locator
.lineNo
;
356 tuiSetIsExecPointAt (l
, winInfo
);
361 if (winInfo
== disassemWin
)
365 if (!tuiAddrIsDisplayed (item
->locator
.addr
, winInfo
, TRUE
))
366 tuiUpdateSourceWindow (winInfo
, s
, a
, TRUE
);
369 a
.addr
= item
->locator
.addr
;
370 tuiSetIsExecPointAt (a
, winInfo
);
374 tuiUpdateExecInfo (winInfo
);
379 tuiUpdateLocatorDisplay (fi
);
380 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
382 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
383 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
384 tuiUpdateExecInfo (winInfo
);
389 } /* tuiShowFrameInfo */
392 ** _initialize_tuiStack().
393 ** Function to initialize gdb commands, for tui window stack manipulation.
396 _initialize_tuiStack (void)
398 add_com ("update", class_tui
, _tuiUpdateLocation_command
,
399 "Update the source window and locator to display the current execution point.\n");
403 /*****************************************
404 ** STATIC LOCAL FUNCTIONS **
405 ******************************************/
408 ** _getFuncNameFromFrame().
411 _getFuncNameFromFrame (struct frame_info
*frameInfo
)
413 char *funcName
= (char *) NULL
;
415 find_pc_partial_function (frameInfo
->pc
,
420 } /* _getFuncNameFromFrame */
424 ** _tuiUpdateLocation_command().
425 ** Command to update the display with the current execution point
428 _tuiUpdateLocation_command (char *arg
, int fromTTY
)
431 extern void frame_command (char *, int);
432 frame_command ("0", FALSE
);
434 struct frame_info
*curFrame
;
436 /* Obtain the current execution point */
437 if ((curFrame
= get_current_frame ()) != (struct frame_info
*) NULL
)
439 struct frame_info
*frame
;
442 for (frame
= get_prev_frame (curLevel
);
443 (frame
!= (struct frame_info
*) NULL
&& (frame
!= curFrame
));
444 frame
= get_prev_frame (frame
))
447 if (curFrame
!= (struct frame_info
*) NULL
)
448 print_frame_info (frame
, curLevel
, 0, 1);
453 } /* _tuiUpdateLocation_command */