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 /* Set the filename portion of the locator. */
64 static void tui_set_locator_filename (const char *filename
);
66 /* Update the locator, with the provided arguments. */
67 static void tui_set_locator_info (const char *filename
, const char *procname
,
68 int lineno
, CORE_ADDR addr
,
69 TuiLocatorElementPtr element
);
71 static void tui_update_command (char *, int);
73 /* Function to set the content of the locator. */
74 static void tuiSetLocatorContent (struct frame_info
*frameInfo
);
76 /* Get a printable name for the function at the address.
77 The symbol name is demangled if demangling is turned on.
78 Returns a pointer to a static area holding the result. */
80 tui_get_function_from_frame (struct frame_info
*fi
)
82 static char name
[256];
83 struct ui_file
*stream
= tui_sfileopen (256);
86 print_address_symbolic (fi
->pc
, stream
, demangle
, "");
87 p
= tui_file_get_strbuf (stream
);
89 /* Use simple heuristics to isolate the function name. The symbol can
90 be demangled and we can have function parameters. Remove them because
91 the status line is too short to display them. */
94 strncpy (name
, p
, sizeof (name
));
95 p
= strchr (name
, '(');
97 p
= strchr (name
, '>');
100 p
= strchr (name
, '+');
103 ui_file_delete (stream
);
108 ** tuiShowLocatorContent()
111 tuiShowLocatorContent (void)
114 TuiGenWinInfoPtr locator
;
116 locator
= locatorWinInfoPtr ();
118 if (m_genWinPtrNotNull (locator
) && locator
->handle
!= (WINDOW
*) NULL
)
120 string
= displayableWinContentAt (locator
, 0);
121 if (string
!= (char *) NULL
)
123 wmove (locator
->handle
, 0, 0);
124 wstandout (locator
->handle
);
125 waddstr (locator
->handle
, string
);
126 wclrtoeol (locator
->handle
);
127 wstandend (locator
->handle
);
128 tuiRefreshWin (locator
);
129 wmove (locator
->handle
, 0, 0);
130 if (string
!= nullStr ())
132 locator
->contentInUse
= TRUE
;
137 } /* tuiShowLocatorContent */
139 /* Set the filename portion of the locator. */
141 tui_set_locator_filename (const char *filename
)
143 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
144 TuiLocatorElementPtr element
;
146 if (locator
->content
[0] == (Opaque
) NULL
)
147 tuiSetLocatorContent ((struct frame_info
*) NULL
);
149 element
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
;
150 element
->fileName
[0] = 0;
151 strcat_to_buf (element
->fileName
, MAX_LOCATOR_ELEMENT_LEN
, filename
);
154 /* Update the locator, with the provided arguments. */
156 tui_set_locator_info (const char *filename
, const char *procname
, int lineno
,
157 CORE_ADDR addr
, TuiLocatorElementPtr element
)
159 element
->procName
[0] = (char) 0;
160 strcat_to_buf (element
->procName
, MAX_LOCATOR_ELEMENT_LEN
, procname
);
161 element
->lineNo
= lineno
;
162 element
->addr
= addr
;
163 tui_set_locator_filename (filename
);
167 /* Update only the filename portion of the locator. */
169 tuiUpdateLocatorFilename (const char *filename
)
171 tui_set_locator_filename (filename
);
172 tuiShowLocatorContent ();
176 ** tuiUpdateLocatorInfoFromFrame().
177 ** Function to update the locator, with the information extracted from frameInfo
180 tuiUpdateLocatorInfoFromFrame (struct frame_info
*frameInfo
,
181 TuiLocatorElementPtr element
)
183 struct symtab_and_line symtabAndLine
;
185 /* now get the new info */
186 symtabAndLine
= find_pc_line (frameInfo
->pc
,
187 (frameInfo
->next
!= (struct frame_info
*) NULL
&&
188 !frameInfo
->next
->signal_handler_caller
&&
189 !frame_in_dummy (frameInfo
->next
)));
190 if (symtabAndLine
.symtab
&& symtabAndLine
.symtab
->filename
)
191 tui_set_locator_info (symtabAndLine
.symtab
->filename
,
192 tui_get_function_from_frame (frameInfo
),
197 tui_set_locator_info ((char *) NULL
,
198 tui_get_function_from_frame (frameInfo
),
204 } /* tuiUpdateLocatorInfoFromFrame */
207 /* Function to set the content of the locator. */
209 tuiSetLocatorContent (struct frame_info
*frameInfo
)
211 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
212 TuiWinElementPtr element
;
213 struct symtab_and_line symtabAndLine
;
215 /* Allocate the element if necessary */
216 if (locator
->contentSize
<= 0)
218 TuiWinContent contentPtr
;
220 if ((locator
->content
= (OpaquePtr
) allocContent (1, locator
->type
)) == (OpaquePtr
) NULL
)
221 error ("Unable to Allocate Memory to Display Location.");
222 locator
->contentSize
= 1;
225 if (frameInfo
!= (struct frame_info
*) NULL
)
226 tuiUpdateLocatorInfoFromFrame (frameInfo
,
227 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
229 tui_set_locator_info ((char *) NULL
,
233 &((TuiWinElementPtr
) locator
->content
[0])->whichElement
.locator
);
235 } /* tuiSetLocatorContent */
238 ** tuiShowFrameInfo().
239 ** Function to print the frame inforrmation for the TUI.
242 tuiShowFrameInfo (struct frame_info
*fi
)
244 TuiWinInfoPtr winInfo
;
249 register int startLine
, i
;
250 register struct symtab
*s
;
252 TuiGenWinInfoPtr locator
= locatorWinInfoPtr ();
253 int sourceAlreadyDisplayed
;
256 s
= find_pc_symtab (fi
->pc
);
261 sourceAlreadyDisplayed
= tuiSourceIsDisplayed (s
->filename
);
262 tuiSetLocatorContent (fi
);
263 tuiShowLocatorContent ();
264 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
266 TuiWhichElement
*item
;
267 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
269 item
= &((TuiWinElementPtr
) locator
->content
[0])->whichElement
;
270 if (winInfo
== srcWin
)
272 startLine
= (item
->locator
.lineNo
-
273 (winInfo
->generic
.viewportHeight
/ 2)) + 1;
279 if (find_pc_partial_function (fi
->pc
, (char **) NULL
, &low
, (CORE_ADDR
) NULL
) == 0)
280 error ("No function contains program counter for selected frame.\n");
282 low
= tuiGetLowDisassemblyAddress (low
, fi
->pc
);
285 if (winInfo
== srcWin
)
288 l
.lineNo
= startLine
;
289 if (!(sourceAlreadyDisplayed
290 && tuiLineIsDisplayed (item
->locator
.lineNo
, winInfo
, TRUE
)))
291 tuiUpdateSourceWindow (winInfo
, s
, l
, TRUE
);
294 l
.lineNo
= item
->locator
.lineNo
;
295 tuiSetIsExecPointAt (l
, winInfo
);
300 if (winInfo
== disassemWin
)
304 if (!tuiAddrIsDisplayed (item
->locator
.addr
, winInfo
, TRUE
))
305 tuiUpdateSourceWindow (winInfo
, s
, a
, TRUE
);
308 a
.addr
= item
->locator
.addr
;
309 tuiSetIsExecPointAt (a
, winInfo
);
313 tuiUpdateExecInfo (winInfo
);
318 tuiSetLocatorContent (fi
);
319 tuiShowLocatorContent ();
320 for (i
= 0; i
< (sourceWindows ())->count
; i
++)
322 winInfo
= (TuiWinInfoPtr
) (sourceWindows ())->list
[i
];
323 tuiClearSourceContent (winInfo
, EMPTY_SOURCE_PROMPT
);
324 tuiUpdateExecInfo (winInfo
);
329 } /* tuiShowFrameInfo */
331 /* Function to initialize gdb commands, for tui window stack manipulation. */
333 _initialize_tuiStack (void)
335 add_com ("update", class_tui
, tui_update_command
,
336 "Update the source window and locator to display the current "
337 "execution point.\n");
340 /* Command to update the display with the current execution point. */
342 tui_update_command (char *arg
, int from_tty
)
344 char cmd
[sizeof("frame 0")];
346 strcpy (cmd
, "frame 0");
347 execute_command (cmd
, from_tty
);