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"
30 #include "tuiSourceWin.h"
33 /*****************************************
34 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
35 ******************************************/
37 static char *_getFuncNameFromFrame (struct frame_info
*);
38 static void _tuiUpdateLocation_command (char *, int);
42 /*****************************************
44 ******************************************/
47 ** tuiClearLocatorDisplay()
51 tuiClearLocatorDisplay (void)
53 tuiClearLocatorDisplay ()
56 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
59 if (locator
->handle
!= (WINDOW
*) NULL
)
61 /* No need to werase, since writing a line of
62 * blanks which we do below, is equivalent.
64 /* werase(locator->handle); */
65 wmove (locator
->handle
, 0, 0);
66 wstandout (locator
->handle
);
67 for (i
= 0; i
< locator
->width
; i
++)
68 waddch (locator
->handle
, ' ');
69 wstandend (locator
->handle
);
70 tuiRefreshWin (locator
);
71 wmove (locator
->handle
, 0, 0);
72 locator
->contentInUse
= FALSE
;
76 } /* tuiClearLocatorDisplay */
80 ** tuiShowLocatorContent()
84 tuiShowLocatorContent (void)
86 tuiShowLocatorContent ()
90 TuiGenWinInfoPtr locator
;
92 locator
= locatorWinInfoPtr ();
94 if (m_genWinPtrNotNull (locator
) && locator
->handle
!= (WINDOW
*) NULL
)
96 string
= displayableWinContentAt (locator
, 0);
97 if (string
!= (char *) NULL
)
99 wmove (locator
->handle
, 0, 0);
100 wstandout (locator
->handle
);
101 waddstr (locator
->handle
, string
);
102 wstandend (locator
->handle
);
103 tuiRefreshWin (locator
);
104 wmove (locator
->handle
, 0, 0);
105 if (string
!= nullStr ())
107 locator
->contentInUse
= TRUE
;
112 } /* tuiShowLocatorContent */
116 ** tuiSetLocatorInfo().
117 ** Function to update the locator, with the provided arguments.
126 TuiLocatorElementPtr element
)
128 tuiSetLocatorInfo (fname
, procname
, lineNo
, addr
, element
)
133 TuiLocatorElementPtr element
;
137 /* first free the old info */
138 if (element
->fileName
)
139 tuiFree (element
->fileName
);
140 if (element
->procName
)
141 tuiFree (element
->procName
);
143 if (fname
== (char *) NULL
)
144 element
->fileName
= fname
;
146 element
->fileName
= tuiStrDup (fname
);
147 if (procname
== (char *) NULL
)
148 element
->procName
= procname
;
150 element
->procName
= tuiStrDup (procname
);
152 element
->fileName
[0] = (char) 0;
153 element
->procName
[0] = (char) 0;
154 strcat_to_buf (element
->fileName
, MAX_LOCATOR_ELEMENT_LEN
, fname
);
155 strcat_to_buf (element
->procName
, MAX_LOCATOR_ELEMENT_LEN
, procname
);
157 element
->lineNo
= lineNo
;
158 element
->addr
= (Opaque
) addr
;
161 } /* tuiSetLocatorInfo */
165 ** tuiUpdateLocatorFilename().
166 ** Update only the filename portion of the locator.
170 tuiUpdateLocatorFilename (
173 tuiUpdateLocatorFilename (fileName
)
177 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
179 if (locator
->content
[0] == (Opaque
) NULL
)
180 tuiSetLocatorContent ((struct frame_info
*) NULL
);
181 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
182 strcat_to_buf (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
,
183 MAX_LOCATOR_ELEMENT_LEN
,
186 tuiShowLocatorContent ();
189 } /* tuiUpdateLocatorFilename */
193 ** tui_vUpdateLocatorFilename().
194 ** Update only the filename portion of the locator with args in a va_list.
198 tui_vUpdateLocatorFilename (
201 tui_vUpdateLocatorFilename (args
)
207 fileName
= va_arg (args
, char *);
208 tuiUpdateLocatorFilename (fileName
);
211 } /* tui_vUpdateLocatorFilename */
215 ** tuiSwitchFilename().
216 ** Update the filename portion of the locator. Clear the other info in locator.
224 tuiSwitchFilename (fileName
)
228 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
230 if (locator
->content
[0] == (Opaque
) NULL
)
231 tuiSetLocatorContent ((struct frame_info
*) NULL
);
232 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
234 tuiSetLocatorInfo (fileName
,
238 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
240 tuiShowLocatorContent ();
243 } /* tuiSwitchFilename */
247 ** tuiGetLocatorFilename().
248 ** Get the filename portion of the locator.
253 tuiGetLocatorFilename (
254 TuiGenWinInfoPtr locator
,
257 tuiGetLocatorFilename (locator
, filename
)
258 TuiGenWinInfoPtr locator
;
263 /* the current filename could be non known, in which case the xmalloc would
264 allocate no memory, because the length would be 0 */
265 if (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
)
268 strlen (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
270 (*filename
) = (char *) xmalloc (name_length
+ 1);
272 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
276 } /* tuiGetLocatorFilename */
280 ** tuiUpdateLocatorInfoFromFrame().
281 ** Function to update the locator, with the information extracted from frameInfo
285 tuiUpdateLocatorInfoFromFrame (
286 struct frame_info
*frameInfo
,
287 TuiLocatorElementPtr element
)
289 tuiUpdateLocatorInfoFromFrame (frameInfo
, element
)
290 struct frame_info
*frameInfo
;
291 TuiLocatorElementPtr element
;
294 struct symtab_and_line symtabAndLine
;
296 /* now get the new info */
297 symtabAndLine
= find_pc_line (frameInfo
->pc
,
298 (frameInfo
->next
!= (struct frame_info
*) NULL
&&
299 !frameInfo
->next
->signal_handler_caller
&&
300 !frame_in_dummy (frameInfo
->next
)));
301 if (symtabAndLine
.symtab
&& symtabAndLine
.symtab
->filename
)
302 tuiSetLocatorInfo (symtabAndLine
.symtab
->filename
,
303 _getFuncNameFromFrame (frameInfo
),
305 (Opaque
) frameInfo
->pc
,
308 tuiSetLocatorInfo ((char *) NULL
,
309 _getFuncNameFromFrame (frameInfo
),
311 (Opaque
) frameInfo
->pc
,
315 } /* tuiUpdateLocatorInfoFromFrame */
319 ** tuiSetLocatorContent().
320 ** Function to set the content of the locator
324 tuiSetLocatorContent (
325 struct frame_info
*frameInfo
)
327 tuiSetLocatorContent (frameInfo
)
328 struct frame_info
*frameInfo
;
331 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
332 TuiWinElementPtr element
;
333 struct symtab_and_line symtabAndLine
;
335 /* Allocate the element if necessary */
336 if (locator
->contentSize
<= 0)
338 TuiWinContent contentPtr
;
340 if ((locator
->content
= (OpaquePtr
) allocContent (1, locator
->type
)) == (OpaquePtr
) NULL
)
341 error ("Unable to Allocate Memory to Display Location.");
342 locator
->contentSize
= 1;
345 if (frameInfo
!= (struct frame_info
*) NULL
)
346 tuiUpdateLocatorInfoFromFrame (frameInfo
,
347 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
349 tuiSetLocatorInfo ((char *) NULL
,
353 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
355 } /* tuiSetLocatorContent */
359 ** tuiUpdateLocatorDisplay().
360 ** Function to update the locator display
364 tuiUpdateLocatorDisplay (
365 struct frame_info
*frameInfo
)
367 tuiUpdateLocatorDisplay (frameInfo
)
368 struct frame_info
*frameInfo
;
371 tuiClearLocatorDisplay ();
372 tuiSetLocatorContent (frameInfo
);
373 tuiShowLocatorContent ();
376 } /* tuiUpdateLocatorDisplay */
380 ** tuiShowFrameInfo().
381 ** Function to print the frame inforrmation for the TUI.
386 struct frame_info
*fi
)
388 tuiShowFrameInfo (fi
)
389 struct frame_info
*fi
;
392 TuiWinInfoPtr winInfo
;
397 register int startLine
, i
;
398 register struct symtab
*s
;
400 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
401 int sourceAlreadyDisplayed
;
404 s
= find_pc_symtab (fi
->pc
);
405 sourceAlreadyDisplayed
= tuiSourceIsDisplayed (s
->filename
);
406 tuiUpdateLocatorDisplay (fi
);
407 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
409 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
410 if (winInfo
== srcWin
)
413 (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.lineNo
-
414 (winInfo
->generic
.viewportHeight
/ 2)) + 1;
420 if (find_pc_partial_function (fi
->pc
, (char **) NULL
, &low
, (CORE_ADDR
) NULL
) == 0)
421 error ("No function contains program counter for selected frame.\n");
423 low
= (CORE_ADDR
) tuiGetLowDisassemblyAddress ((Opaque
) low
, (Opaque
) fi
->pc
);
426 if (winInfo
== srcWin
)
428 if (!(sourceAlreadyDisplayed
&& m_tuiLineDisplayedWithinThreshold (
430 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.lineNo
)))
431 tuiUpdateSourceWindow (winInfo
, s
, (Opaque
) startLine
, TRUE
);
433 tuiSetIsExecPointAt ((Opaque
)
434 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.lineNo
,
439 if (winInfo
== disassemWin
)
441 if (!m_tuiLineDisplayedWithinThreshold (winInfo
,
442 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.addr
))
443 tuiUpdateSourceWindow (winInfo
, s
, (Opaque
) low
, TRUE
);
445 tuiSetIsExecPointAt ((Opaque
)
446 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.addr
,
450 tuiUpdateExecInfo (winInfo
);
455 tuiUpdateLocatorDisplay (fi
);
456 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
458 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
459 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
460 tuiUpdateExecInfo (winInfo
);
465 } /* tuiShowFrameInfo */
469 ** tui_vShowFrameInfo().
470 ** Function to print the frame inforrmation for the TUI with args in a va_list.
477 tui_vShowFrameInfo (args
)
481 struct frame_info
*fi
;
483 fi
= va_arg (args
, struct frame_info
*);
484 tuiShowFrameInfo (fi
);
487 } /* tui_vShowFrameInfo */
491 ** _initialize_tuiStack().
492 ** Function to initialize gdb commands, for tui window stack manipulation.
495 _initialize_tuiStack (void)
499 add_com ("update", class_tui
, _tuiUpdateLocation_command
,
500 "Update the source window and locator to display the current execution point.\n");
504 } /* _initialize_tuiStack */
507 /*****************************************
508 ** STATIC LOCAL FUNCTIONS **
509 ******************************************/
512 ** _getFuncNameFromFrame().
516 _getFuncNameFromFrame (
517 struct frame_info
*frameInfo
)
519 _getFuncNameFromFrame (frameInfo
)
520 struct frame_info
*frameInfo
;
523 char *funcName
= (char *) NULL
;
525 find_pc_partial_function (frameInfo
->pc
,
530 } /* _getFuncNameFromFrame */
534 ** _tuiUpdateLocation_command().
535 ** Command to update the display with the current execution point
539 _tuiUpdateLocation_command (
543 _tuiUpdateLocation_command (arg
, fromTTY
)
549 extern void frame_command (char *, int);
550 frame_command ("0", FALSE
);
552 struct frame_info
*curFrame
;
554 /* Obtain the current execution point */
555 if ((curFrame
= get_current_frame ()) != (struct frame_info
*) NULL
)
557 struct frame_info
*frame
;
560 for (frame
= get_prev_frame (curLevel
);
561 (frame
!= (struct frame_info
*) NULL
&& (frame
!= curFrame
));
562 frame
= get_prev_frame (frame
))
565 if (curFrame
!= (struct frame_info
*) NULL
)
566 print_frame_info (frame
, curLevel
, 0, 1);
571 } /* _tuiUpdateLocation_command */