Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI display locator. |
f33c6cbf AC |
2 | |
3 | Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, | |
4 | Inc. | |
5 | ||
f377b406 SC |
6 | Contributed by Hewlett-Packard Company. |
7 | ||
8 | This file is part of GDB. | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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. */ | |
c906108c | 24 | |
f33c6cbf AC |
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> | |
31 | first. */ | |
32 | ||
4e8f7a8b DJ |
33 | #include "config.h" |
34 | #ifdef HAVE_NCURSES_H | |
35 | #include <ncurses.h> | |
36 | #else | |
37 | #ifdef HAVE_CURSES_H | |
38 | #include <curses.h> | |
39 | #endif | |
40 | #endif | |
41 | ||
c906108c SS |
42 | #include "defs.h" |
43 | #include "symtab.h" | |
44 | #include "breakpoint.h" | |
45 | #include "frame.h" | |
75fd9bc1 | 46 | #include "command.h" |
7563e053 | 47 | #include "top.h" |
c906108c SS |
48 | |
49 | #include "tui.h" | |
50 | #include "tuiData.h" | |
51 | #include "tuiStack.h" | |
75fd9bc1 SC |
52 | #include "tuiGeneralWin.h" |
53 | #include "tuiSource.h" | |
c906108c | 54 | #include "tuiSourceWin.h" |
5564c769 | 55 | #include "tui-file.h" |
c906108c SS |
56 | |
57 | ||
5564c769 SC |
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); | |
c906108c | 62 | |
2e17b763 SC |
63 | /* Set the filename portion of the locator. */ |
64 | static void tui_set_locator_filename (const char *filename); | |
65 | ||
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); | |
70 | ||
7563e053 | 71 | static void tui_update_command (char *, int); |
c906108c | 72 | |
2e17b763 SC |
73 | /* Function to set the content of the locator. */ |
74 | static void tuiSetLocatorContent (struct frame_info *frameInfo); | |
c906108c | 75 | |
5564c769 SC |
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. */ | |
79 | static char* | |
80 | tui_get_function_from_frame (struct frame_info *fi) | |
81 | { | |
82 | static char name[256]; | |
83 | struct ui_file *stream = tui_sfileopen (256); | |
84 | char *p; | |
85 | ||
86 | print_address_symbolic (fi->pc, stream, demangle, ""); | |
87 | p = tui_file_get_strbuf (stream); | |
88 | ||
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. */ | |
92 | if (*p == '<') | |
93 | p++; | |
94 | strncpy (name, p, sizeof (name)); | |
95 | p = strchr (name, '('); | |
96 | if (!p) | |
97 | p = strchr (name, '>'); | |
98 | if (p) | |
99 | *p = 0; | |
100 | p = strchr (name, '+'); | |
101 | if (p) | |
102 | *p = 0; | |
103 | ui_file_delete (stream); | |
104 | return name; | |
105 | } | |
c906108c | 106 | |
c906108c | 107 | /* |
c5aa993b JM |
108 | ** tuiShowLocatorContent() |
109 | */ | |
c906108c | 110 | void |
c906108c | 111 | tuiShowLocatorContent (void) |
c906108c SS |
112 | { |
113 | char *string; | |
114 | TuiGenWinInfoPtr locator; | |
115 | ||
116 | locator = locatorWinInfoPtr (); | |
117 | ||
118 | if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL) | |
119 | { | |
120 | string = displayableWinContentAt (locator, 0); | |
121 | if (string != (char *) NULL) | |
122 | { | |
123 | wmove (locator->handle, 0, 0); | |
124 | wstandout (locator->handle); | |
125 | waddstr (locator->handle, string); | |
3a42771a | 126 | wclrtoeol (locator->handle); |
c906108c SS |
127 | wstandend (locator->handle); |
128 | tuiRefreshWin (locator); | |
129 | wmove (locator->handle, 0, 0); | |
130 | if (string != nullStr ()) | |
131 | tuiFree (string); | |
132 | locator->contentInUse = TRUE; | |
133 | } | |
134 | } | |
135 | ||
136 | return; | |
137 | } /* tuiShowLocatorContent */ | |
138 | ||
2e17b763 SC |
139 | /* Set the filename portion of the locator. */ |
140 | static void | |
141 | tui_set_locator_filename (const char *filename) | |
142 | { | |
143 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
144 | TuiLocatorElementPtr element; | |
145 | ||
146 | if (locator->content[0] == (Opaque) NULL) | |
147 | tuiSetLocatorContent ((struct frame_info *) NULL); | |
148 | ||
149 | element = &((TuiWinElementPtr) locator->content[0])->whichElement.locator; | |
150 | element->fileName[0] = 0; | |
151 | strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, filename); | |
152 | } | |
c906108c | 153 | |
c7c228ed | 154 | /* Update the locator, with the provided arguments. */ |
2e17b763 SC |
155 | static void |
156 | tui_set_locator_info (const char *filename, const char *procname, int lineno, | |
157 | CORE_ADDR addr, TuiLocatorElementPtr element) | |
c906108c | 158 | { |
c906108c | 159 | element->procName[0] = (char) 0; |
c906108c | 160 | strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname); |
2e17b763 | 161 | element->lineNo = lineno; |
c774cec6 | 162 | element->addr = addr; |
2e17b763 | 163 | tui_set_locator_filename (filename); |
c7c228ed | 164 | } |
c906108c SS |
165 | |
166 | ||
2e17b763 | 167 | /* Update only the filename portion of the locator. */ |
c906108c | 168 | void |
2e17b763 | 169 | tuiUpdateLocatorFilename (const char *filename) |
c906108c | 170 | { |
2e17b763 | 171 | tui_set_locator_filename (filename); |
c906108c | 172 | tuiShowLocatorContent (); |
2e17b763 | 173 | } |
c906108c | 174 | |
c906108c | 175 | /* |
c5aa993b JM |
176 | ** tuiUpdateLocatorInfoFromFrame(). |
177 | ** Function to update the locator, with the information extracted from frameInfo | |
178 | */ | |
2e17b763 | 179 | static void |
eca6576c SC |
180 | tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo, |
181 | TuiLocatorElementPtr element) | |
c906108c SS |
182 | { |
183 | struct symtab_and_line symtabAndLine; | |
184 | ||
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) | |
2e17b763 SC |
191 | tui_set_locator_info (symtabAndLine.symtab->filename, |
192 | tui_get_function_from_frame (frameInfo), | |
193 | symtabAndLine.line, | |
194 | frameInfo->pc, | |
195 | element); | |
c906108c | 196 | else |
2e17b763 SC |
197 | tui_set_locator_info ((char *) NULL, |
198 | tui_get_function_from_frame (frameInfo), | |
199 | 0, | |
200 | frameInfo->pc, | |
201 | element); | |
c906108c SS |
202 | |
203 | return; | |
204 | } /* tuiUpdateLocatorInfoFromFrame */ | |
205 | ||
206 | ||
2e17b763 SC |
207 | /* Function to set the content of the locator. */ |
208 | static void | |
eca6576c | 209 | tuiSetLocatorContent (struct frame_info *frameInfo) |
c906108c SS |
210 | { |
211 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
212 | TuiWinElementPtr element; | |
213 | struct symtab_and_line symtabAndLine; | |
214 | ||
215 | /* Allocate the element if necessary */ | |
216 | if (locator->contentSize <= 0) | |
217 | { | |
218 | TuiWinContent contentPtr; | |
219 | ||
220 | if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL) | |
221 | error ("Unable to Allocate Memory to Display Location."); | |
222 | locator->contentSize = 1; | |
223 | } | |
224 | ||
225 | if (frameInfo != (struct frame_info *) NULL) | |
226 | tuiUpdateLocatorInfoFromFrame (frameInfo, | |
227 | &((TuiWinElementPtr) locator->content[0])->whichElement.locator); | |
228 | else | |
2e17b763 SC |
229 | tui_set_locator_info ((char *) NULL, |
230 | (char *) NULL, | |
231 | 0, | |
232 | (CORE_ADDR) 0, | |
c906108c SS |
233 | &((TuiWinElementPtr) locator->content[0])->whichElement.locator); |
234 | return; | |
235 | } /* tuiSetLocatorContent */ | |
236 | ||
c906108c | 237 | /* |
c5aa993b JM |
238 | ** tuiShowFrameInfo(). |
239 | ** Function to print the frame inforrmation for the TUI. | |
240 | */ | |
c906108c | 241 | void |
eca6576c | 242 | tuiShowFrameInfo (struct frame_info *fi) |
c906108c SS |
243 | { |
244 | TuiWinInfoPtr winInfo; | |
245 | register int i; | |
246 | ||
247 | if (fi) | |
248 | { | |
249 | register int startLine, i; | |
250 | register struct symtab *s; | |
251 | CORE_ADDR low; | |
252 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
253 | int sourceAlreadyDisplayed; | |
254 | ||
255 | ||
256 | s = find_pc_symtab (fi->pc); | |
75fd9bc1 SC |
257 | if (s == 0) |
258 | return; | |
259 | ||
a4b99e53 | 260 | startLine = 0; |
c906108c | 261 | sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename); |
d059f789 SC |
262 | tuiSetLocatorContent (fi); |
263 | tuiShowLocatorContent (); | |
c906108c SS |
264 | for (i = 0; i < (sourceWindows ())->count; i++) |
265 | { | |
a4b99e53 | 266 | TuiWhichElement *item; |
c906108c | 267 | winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i]; |
a4b99e53 SC |
268 | |
269 | item = &((TuiWinElementPtr) locator->content[0])->whichElement; | |
c906108c SS |
270 | if (winInfo == srcWin) |
271 | { | |
a4b99e53 SC |
272 | startLine = (item->locator.lineNo - |
273 | (winInfo->generic.viewportHeight / 2)) + 1; | |
c906108c SS |
274 | if (startLine <= 0) |
275 | startLine = 1; | |
276 | } | |
277 | else | |
278 | { | |
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"); | |
281 | else | |
c774cec6 | 282 | low = tuiGetLowDisassemblyAddress (low, fi->pc); |
c906108c SS |
283 | } |
284 | ||
285 | if (winInfo == srcWin) | |
286 | { | |
a4b99e53 SC |
287 | TuiLineOrAddress l; |
288 | l.lineNo = startLine; | |
289 | if (!(sourceAlreadyDisplayed | |
290 | && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE))) | |
291 | tuiUpdateSourceWindow (winInfo, s, l, TRUE); | |
c906108c | 292 | else |
a4b99e53 SC |
293 | { |
294 | l.lineNo = item->locator.lineNo; | |
295 | tuiSetIsExecPointAt (l, winInfo); | |
296 | } | |
c906108c SS |
297 | } |
298 | else | |
299 | { | |
300 | if (winInfo == disassemWin) | |
301 | { | |
a4b99e53 SC |
302 | TuiLineOrAddress a; |
303 | a.addr = low; | |
304 | if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE)) | |
305 | tuiUpdateSourceWindow (winInfo, s, a, TRUE); | |
c906108c | 306 | else |
a4b99e53 SC |
307 | { |
308 | a.addr = item->locator.addr; | |
309 | tuiSetIsExecPointAt (a, winInfo); | |
310 | } | |
c906108c SS |
311 | } |
312 | } | |
313 | tuiUpdateExecInfo (winInfo); | |
314 | } | |
315 | } | |
316 | else | |
317 | { | |
d059f789 SC |
318 | tuiSetLocatorContent (fi); |
319 | tuiShowLocatorContent (); | |
c906108c SS |
320 | for (i = 0; i < (sourceWindows ())->count; i++) |
321 | { | |
322 | winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i]; | |
323 | tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT); | |
324 | tuiUpdateExecInfo (winInfo); | |
325 | } | |
326 | } | |
327 | ||
328 | return; | |
329 | } /* tuiShowFrameInfo */ | |
330 | ||
7563e053 | 331 | /* Function to initialize gdb commands, for tui window stack manipulation. */ |
c906108c | 332 | void |
fba45db2 | 333 | _initialize_tuiStack (void) |
c906108c | 334 | { |
7563e053 SC |
335 | add_com ("update", class_tui, tui_update_command, |
336 | "Update the source window and locator to display the current " | |
337 | "execution point.\n"); | |
41783295 | 338 | } |
c906108c | 339 | |
7563e053 | 340 | /* Command to update the display with the current execution point. */ |
c906108c | 341 | static void |
7563e053 | 342 | tui_update_command (char *arg, int from_tty) |
c906108c | 343 | { |
7563e053 | 344 | char cmd[sizeof("frame 0")]; |
c906108c | 345 | |
7563e053 SC |
346 | strcpy (cmd, "frame 0"); |
347 | execute_command (cmd, from_tty); | |
348 | } |