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 */
110 /* Update the locator, with the provided arguments. */
112 tuiSetLocatorInfo (char *fname
, char *procname
, int lineNo
,
113 CORE_ADDR addr
, TuiLocatorElementPtr element
)
115 element
->fileName
[0] = (char) 0;
116 element
->procName
[0] = (char) 0;
117 strcat_to_buf (element
->fileName
, MAX_LOCATOR_ELEMENT_LEN
, fname
);
118 strcat_to_buf (element
->procName
, MAX_LOCATOR_ELEMENT_LEN
, procname
);
119 element
->lineNo
= lineNo
;
120 element
->addr
= addr
;
125 ** tuiUpdateLocatorFilename().
126 ** Update only the filename portion of the locator.
129 tuiUpdateLocatorFilename (char *fileName
)
131 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
133 if (locator
->content
[0] == (Opaque
) NULL
)
134 tuiSetLocatorContent ((struct frame_info
*) NULL
);
135 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
136 strcat_to_buf (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
,
137 MAX_LOCATOR_ELEMENT_LEN
,
140 tuiShowLocatorContent ();
143 } /* tuiUpdateLocatorFilename */
146 ** tuiSwitchFilename().
147 ** Update the filename portion of the locator. Clear the other info in locator.
151 tuiSwitchFilename (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;
159 tuiSetLocatorInfo (fileName
,
163 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
165 tuiShowLocatorContent ();
168 } /* tuiSwitchFilename */
172 ** tuiGetLocatorFilename().
173 ** Get the filename portion of the locator.
177 tuiGetLocatorFilename (TuiGenWinInfoPtr locator
, char **filename
)
180 /* the current filename could be non known, in which case the xmalloc would
181 allocate no memory, because the length would be 0 */
182 if (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
)
185 strlen (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
187 (*filename
) = (char *) xmalloc (name_length
+ 1);
189 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
193 } /* tuiGetLocatorFilename */
197 ** tuiUpdateLocatorInfoFromFrame().
198 ** Function to update the locator, with the information extracted from frameInfo
201 tuiUpdateLocatorInfoFromFrame (struct frame_info
*frameInfo
,
202 TuiLocatorElementPtr element
)
204 struct symtab_and_line symtabAndLine
;
206 /* now get the new info */
207 symtabAndLine
= find_pc_line (frameInfo
->pc
,
208 (frameInfo
->next
!= (struct frame_info
*) NULL
&&
209 !frameInfo
->next
->signal_handler_caller
&&
210 !frame_in_dummy (frameInfo
->next
)));
211 if (symtabAndLine
.symtab
&& symtabAndLine
.symtab
->filename
)
212 tuiSetLocatorInfo (symtabAndLine
.symtab
->filename
,
213 _getFuncNameFromFrame (frameInfo
),
218 tuiSetLocatorInfo ((char *) NULL
,
219 _getFuncNameFromFrame (frameInfo
),
225 } /* tuiUpdateLocatorInfoFromFrame */
229 ** tuiSetLocatorContent().
230 ** Function to set the content of the locator
233 tuiSetLocatorContent (struct frame_info
*frameInfo
)
235 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
236 TuiWinElementPtr element
;
237 struct symtab_and_line symtabAndLine
;
239 /* Allocate the element if necessary */
240 if (locator
->contentSize
<= 0)
242 TuiWinContent contentPtr
;
244 if ((locator
->content
= (OpaquePtr
) allocContent (1, locator
->type
)) == (OpaquePtr
) NULL
)
245 error ("Unable to Allocate Memory to Display Location.");
246 locator
->contentSize
= 1;
249 if (frameInfo
!= (struct frame_info
*) NULL
)
250 tuiUpdateLocatorInfoFromFrame (frameInfo
,
251 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
253 tuiSetLocatorInfo ((char *) NULL
,
257 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
259 } /* tuiSetLocatorContent */
263 ** tuiUpdateLocatorDisplay().
264 ** Function to update the locator display
267 tuiUpdateLocatorDisplay (struct frame_info
*frameInfo
)
269 tuiClearLocatorDisplay ();
270 tuiSetLocatorContent (frameInfo
);
271 tuiShowLocatorContent ();
274 } /* tuiUpdateLocatorDisplay */
278 ** tuiShowFrameInfo().
279 ** Function to print the frame inforrmation for the TUI.
282 tuiShowFrameInfo (struct frame_info
*fi
)
284 TuiWinInfoPtr winInfo
;
289 register int startLine
, i
;
290 register struct symtab
*s
;
292 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
293 int sourceAlreadyDisplayed
;
296 s
= find_pc_symtab (fi
->pc
);
301 sourceAlreadyDisplayed
= tuiSourceIsDisplayed (s
->filename
);
302 tuiUpdateLocatorDisplay (fi
);
303 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
305 TuiWhichElement
*item
;
306 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
308 item
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
;
309 if (winInfo
== srcWin
)
311 startLine
= (item
->locator
.lineNo
-
312 (winInfo
->generic
.viewportHeight
/ 2)) + 1;
318 if (find_pc_partial_function (fi
->pc
, (char **) NULL
, &low
, (CORE_ADDR
) NULL
) == 0)
319 error ("No function contains program counter for selected frame.\n");
321 low
= tuiGetLowDisassemblyAddress (low
, fi
->pc
);
324 if (winInfo
== srcWin
)
327 l
.lineNo
= startLine
;
328 if (!(sourceAlreadyDisplayed
329 && tuiLineIsDisplayed (item
->locator
.lineNo
, winInfo
, TRUE
)))
330 tuiUpdateSourceWindow (winInfo
, s
, l
, TRUE
);
333 l
.lineNo
= item
->locator
.lineNo
;
334 tuiSetIsExecPointAt (l
, winInfo
);
339 if (winInfo
== disassemWin
)
343 if (!tuiAddrIsDisplayed (item
->locator
.addr
, winInfo
, TRUE
))
344 tuiUpdateSourceWindow (winInfo
, s
, a
, TRUE
);
347 a
.addr
= item
->locator
.addr
;
348 tuiSetIsExecPointAt (a
, winInfo
);
352 tuiUpdateExecInfo (winInfo
);
357 tuiUpdateLocatorDisplay (fi
);
358 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
360 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
361 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
362 tuiUpdateExecInfo (winInfo
);
367 } /* tuiShowFrameInfo */
370 ** _initialize_tuiStack().
371 ** Function to initialize gdb commands, for tui window stack manipulation.
374 _initialize_tuiStack (void)
376 add_com ("update", class_tui
, _tuiUpdateLocation_command
,
377 "Update the source window and locator to display the current execution point.\n");
381 /*****************************************
382 ** STATIC LOCAL FUNCTIONS **
383 ******************************************/
386 ** _getFuncNameFromFrame().
389 _getFuncNameFromFrame (struct frame_info
*frameInfo
)
391 char *funcName
= (char *) NULL
;
393 find_pc_partial_function (frameInfo
->pc
,
398 } /* _getFuncNameFromFrame */
402 ** _tuiUpdateLocation_command().
403 ** Command to update the display with the current execution point
406 _tuiUpdateLocation_command (char *arg
, int fromTTY
)
409 extern void frame_command (char *, int);
410 frame_command ("0", FALSE
);
412 struct frame_info
*curFrame
;
414 /* Obtain the current execution point */
415 if ((curFrame
= get_current_frame ()) != (struct frame_info
*) NULL
)
417 struct frame_info
*frame
;
420 for (frame
= get_prev_frame (curLevel
);
421 (frame
!= (struct frame_info
*) NULL
&& (frame
!= curFrame
));
422 frame
= get_prev_frame (frame
))
425 if (curFrame
!= (struct frame_info
*) NULL
)
426 print_frame_info (frame
, curLevel
, 0, 1);
431 } /* _tuiUpdateLocation_command */