1 /* TUI display locator.
3 Copyright 1998, 1999, 2000, 2001, 2002 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. */
25 /* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26 "defs.h" should be included first. Unfortunatly some systems
27 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28 and they clash with "bfd.h"'s definiton of true/false. The correct
29 fix is to remove true/false from "bfd.h", however, until that
30 happens, hack around it by including "config.h" and <curses.h>
44 #include "breakpoint.h"
52 #include "tuiGeneralWin.h"
53 #include "tuiSource.h"
54 #include "tuiSourceWin.h"
58 /* Get a printable name for the function at the address.
59 The symbol name is demangled if demangling is turned on.
60 Returns a pointer to a static area holding the result. */
61 static char* tui_get_function_from_frame (struct frame_info
*fi
);
63 static void tui_update_command (char *, int);
66 /* Get a printable name for the function at the address.
67 The symbol name is demangled if demangling is turned on.
68 Returns a pointer to a static area holding the result. */
70 tui_get_function_from_frame (struct frame_info
*fi
)
72 static char name
[256];
73 struct ui_file
*stream
= tui_sfileopen (256);
76 print_address_symbolic (fi
->pc
, stream
, demangle
, "");
77 p
= tui_file_get_strbuf (stream
);
79 /* Use simple heuristics to isolate the function name. The symbol can
80 be demangled and we can have function parameters. Remove them because
81 the status line is too short to display them. */
84 strncpy (name
, p
, sizeof (name
));
85 p
= strchr (name
, '(');
87 p
= strchr (name
, '>');
90 p
= strchr (name
, '+');
93 ui_file_delete (stream
);
98 ** tuiShowLocatorContent()
101 tuiShowLocatorContent (void)
104 TuiGenWinInfoPtr locator
;
106 locator
= locatorWinInfoPtr ();
108 if (m_genWinPtrNotNull (locator
) && locator
->handle
!= (WINDOW
*) NULL
)
110 string
= displayableWinContentAt (locator
, 0);
111 if (string
!= (char *) NULL
)
113 wmove (locator
->handle
, 0, 0);
114 wstandout (locator
->handle
);
115 waddstr (locator
->handle
, string
);
116 wclrtoeol (locator
->handle
);
117 wstandend (locator
->handle
);
118 tuiRefreshWin (locator
);
119 wmove (locator
->handle
, 0, 0);
120 if (string
!= nullStr ())
122 locator
->contentInUse
= TRUE
;
127 } /* tuiShowLocatorContent */
130 /* Update the locator, with the provided arguments. */
132 tuiSetLocatorInfo (char *fname
, char *procname
, int lineNo
,
133 CORE_ADDR addr
, TuiLocatorElementPtr element
)
135 element
->fileName
[0] = (char) 0;
136 element
->procName
[0] = (char) 0;
137 strcat_to_buf (element
->fileName
, MAX_LOCATOR_ELEMENT_LEN
, fname
);
138 strcat_to_buf (element
->procName
, MAX_LOCATOR_ELEMENT_LEN
, procname
);
139 element
->lineNo
= lineNo
;
140 element
->addr
= addr
;
145 ** tuiUpdateLocatorFilename().
146 ** Update only the filename portion of the locator.
149 tuiUpdateLocatorFilename (const char *fileName
)
151 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
153 if (locator
->content
[0] == (Opaque
) NULL
)
154 tuiSetLocatorContent ((struct frame_info
*) NULL
);
155 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
156 strcat_to_buf (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
,
157 MAX_LOCATOR_ELEMENT_LEN
,
160 tuiShowLocatorContent ();
163 } /* tuiUpdateLocatorFilename */
166 ** tuiSwitchFilename().
167 ** Update the filename portion of the locator. Clear the other info in locator.
171 tuiSwitchFilename (char *fileName
)
173 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
175 if (locator
->content
[0] == (Opaque
) NULL
)
176 tuiSetLocatorContent ((struct frame_info
*) NULL
);
177 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
[0] = (char) 0;
179 tuiSetLocatorInfo (fileName
,
183 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
185 tuiShowLocatorContent ();
188 } /* tuiSwitchFilename */
192 ** tuiGetLocatorFilename().
193 ** Get the filename portion of the locator.
197 tuiGetLocatorFilename (TuiGenWinInfoPtr locator
, char **filename
)
200 /* the current filename could be non known, in which case the xmalloc would
201 allocate no memory, because the length would be 0 */
202 if (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
)
205 strlen (((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
207 (*filename
) = (char *) xmalloc (name_length
+ 1);
209 ((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
.fileName
);
213 } /* tuiGetLocatorFilename */
217 ** tuiUpdateLocatorInfoFromFrame().
218 ** Function to update the locator, with the information extracted from frameInfo
221 tuiUpdateLocatorInfoFromFrame (struct frame_info
*frameInfo
,
222 TuiLocatorElementPtr element
)
224 struct symtab_and_line symtabAndLine
;
226 /* now get the new info */
227 symtabAndLine
= find_pc_line (frameInfo
->pc
,
228 (frameInfo
->next
!= (struct frame_info
*) NULL
&&
229 !frameInfo
->next
->signal_handler_caller
&&
230 !frame_in_dummy (frameInfo
->next
)));
231 if (symtabAndLine
.symtab
&& symtabAndLine
.symtab
->filename
)
232 tuiSetLocatorInfo (symtabAndLine
.symtab
->filename
,
233 tui_get_function_from_frame (frameInfo
),
238 tuiSetLocatorInfo ((char *) NULL
,
239 tui_get_function_from_frame (frameInfo
),
245 } /* tuiUpdateLocatorInfoFromFrame */
249 ** tuiSetLocatorContent().
250 ** Function to set the content of the locator
253 tuiSetLocatorContent (struct frame_info
*frameInfo
)
255 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
256 TuiWinElementPtr element
;
257 struct symtab_and_line symtabAndLine
;
259 /* Allocate the element if necessary */
260 if (locator
->contentSize
<= 0)
262 TuiWinContent contentPtr
;
264 if ((locator
->content
= (OpaquePtr
) allocContent (1, locator
->type
)) == (OpaquePtr
) NULL
)
265 error ("Unable to Allocate Memory to Display Location.");
266 locator
->contentSize
= 1;
269 if (frameInfo
!= (struct frame_info
*) NULL
)
270 tuiUpdateLocatorInfoFromFrame (frameInfo
,
271 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
273 tuiSetLocatorInfo ((char *) NULL
,
277 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
279 } /* tuiSetLocatorContent */
283 ** tuiUpdateLocatorDisplay().
284 ** Function to update the locator display
287 tuiUpdateLocatorDisplay (struct frame_info
*frameInfo
)
289 tuiSetLocatorContent (frameInfo
);
290 tuiShowLocatorContent ();
293 } /* tuiUpdateLocatorDisplay */
297 ** tuiShowFrameInfo().
298 ** Function to print the frame inforrmation for the TUI.
301 tuiShowFrameInfo (struct frame_info
*fi
)
303 TuiWinInfoPtr winInfo
;
308 register int startLine
, i
;
309 register struct symtab
*s
;
311 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
312 int sourceAlreadyDisplayed
;
315 s
= find_pc_symtab (fi
->pc
);
320 sourceAlreadyDisplayed
= tuiSourceIsDisplayed (s
->filename
);
321 tuiUpdateLocatorDisplay (fi
);
322 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
324 TuiWhichElement
*item
;
325 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
327 item
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
;
328 if (winInfo
== srcWin
)
330 startLine
= (item
->locator
.lineNo
-
331 (winInfo
->generic
.viewportHeight
/ 2)) + 1;
337 if (find_pc_partial_function (fi
->pc
, (char **) NULL
, &low
, (CORE_ADDR
) NULL
) == 0)
338 error ("No function contains program counter for selected frame.\n");
340 low
= tuiGetLowDisassemblyAddress (low
, fi
->pc
);
343 if (winInfo
== srcWin
)
346 l
.lineNo
= startLine
;
347 if (!(sourceAlreadyDisplayed
348 && tuiLineIsDisplayed (item
->locator
.lineNo
, winInfo
, TRUE
)))
349 tuiUpdateSourceWindow (winInfo
, s
, l
, TRUE
);
352 l
.lineNo
= item
->locator
.lineNo
;
353 tuiSetIsExecPointAt (l
, winInfo
);
358 if (winInfo
== disassemWin
)
362 if (!tuiAddrIsDisplayed (item
->locator
.addr
, winInfo
, TRUE
))
363 tuiUpdateSourceWindow (winInfo
, s
, a
, TRUE
);
366 a
.addr
= item
->locator
.addr
;
367 tuiSetIsExecPointAt (a
, winInfo
);
371 tuiUpdateExecInfo (winInfo
);
376 tuiUpdateLocatorDisplay (fi
);
377 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
379 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
380 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
381 tuiUpdateExecInfo (winInfo
);
386 } /* tuiShowFrameInfo */
388 /* Function to initialize gdb commands, for tui window stack manipulation. */
390 _initialize_tuiStack (void)
392 add_com ("update", class_tui
, tui_update_command
,
393 "Update the source window and locator to display the current "
394 "execution point.\n");
397 /* Command to update the display with the current execution point. */
399 tui_update_command (char *arg
, int from_tty
)
401 char cmd
[sizeof("frame 0")];
403 strcpy (cmd
, "frame 0");
404 execute_command (cmd
, from_tty
);