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" |
c906108c SS |
47 | |
48 | #include "tui.h" | |
49 | #include "tuiData.h" | |
50 | #include "tuiStack.h" | |
75fd9bc1 SC |
51 | #include "tuiGeneralWin.h" |
52 | #include "tuiSource.h" | |
c906108c SS |
53 | #include "tuiSourceWin.h" |
54 | ||
55 | ||
56 | /***************************************** | |
57 | ** STATIC LOCAL FUNCTIONS FORWARD DECLS ** | |
58 | ******************************************/ | |
59 | ||
a14ed312 KB |
60 | static char *_getFuncNameFromFrame (struct frame_info *); |
61 | static void _tuiUpdateLocation_command (char *, int); | |
c906108c SS |
62 | |
63 | ||
64 | ||
65 | /***************************************** | |
66 | ** PUBLIC FUNCTION ** | |
67 | ******************************************/ | |
68 | ||
69 | /* | |
c5aa993b JM |
70 | ** tuiClearLocatorDisplay() |
71 | */ | |
c906108c | 72 | void |
c906108c | 73 | tuiClearLocatorDisplay (void) |
c906108c SS |
74 | { |
75 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
76 | int i; | |
77 | ||
78 | if (locator->handle != (WINDOW *) NULL) | |
79 | { | |
80 | /* No need to werase, since writing a line of | |
81 | * blanks which we do below, is equivalent. | |
c5aa993b | 82 | */ |
c906108c SS |
83 | /* werase(locator->handle); */ |
84 | wmove (locator->handle, 0, 0); | |
85 | wstandout (locator->handle); | |
86 | for (i = 0; i < locator->width; i++) | |
87 | waddch (locator->handle, ' '); | |
88 | wstandend (locator->handle); | |
89 | tuiRefreshWin (locator); | |
90 | wmove (locator->handle, 0, 0); | |
91 | locator->contentInUse = FALSE; | |
92 | } | |
93 | ||
94 | return; | |
95 | } /* tuiClearLocatorDisplay */ | |
96 | ||
97 | ||
98 | /* | |
c5aa993b JM |
99 | ** tuiShowLocatorContent() |
100 | */ | |
c906108c | 101 | void |
c906108c | 102 | tuiShowLocatorContent (void) |
c906108c SS |
103 | { |
104 | char *string; | |
105 | TuiGenWinInfoPtr locator; | |
106 | ||
107 | locator = locatorWinInfoPtr (); | |
108 | ||
109 | if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL) | |
110 | { | |
111 | string = displayableWinContentAt (locator, 0); | |
112 | if (string != (char *) NULL) | |
113 | { | |
114 | wmove (locator->handle, 0, 0); | |
115 | wstandout (locator->handle); | |
116 | waddstr (locator->handle, string); | |
117 | wstandend (locator->handle); | |
118 | tuiRefreshWin (locator); | |
119 | wmove (locator->handle, 0, 0); | |
120 | if (string != nullStr ()) | |
121 | tuiFree (string); | |
122 | locator->contentInUse = TRUE; | |
123 | } | |
124 | } | |
125 | ||
126 | return; | |
127 | } /* tuiShowLocatorContent */ | |
128 | ||
129 | ||
c7c228ed | 130 | /* Update the locator, with the provided arguments. */ |
c906108c | 131 | void |
eca6576c | 132 | tuiSetLocatorInfo (char *fname, char *procname, int lineNo, |
c774cec6 | 133 | CORE_ADDR addr, TuiLocatorElementPtr element) |
c906108c | 134 | { |
c906108c SS |
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); | |
c906108c | 139 | element->lineNo = lineNo; |
c774cec6 | 140 | element->addr = addr; |
c7c228ed | 141 | } |
c906108c SS |
142 | |
143 | ||
144 | /* | |
c5aa993b JM |
145 | ** tuiUpdateLocatorFilename(). |
146 | ** Update only the filename portion of the locator. | |
147 | */ | |
c906108c | 148 | void |
c6f60bcd | 149 | tuiUpdateLocatorFilename (const char *fileName) |
c906108c SS |
150 | { |
151 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
152 | ||
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, | |
158 | fileName); | |
159 | ||
160 | tuiShowLocatorContent (); | |
161 | ||
162 | return; | |
163 | } /* tuiUpdateLocatorFilename */ | |
164 | ||
c906108c | 165 | /* |
c5aa993b JM |
166 | ** tuiSwitchFilename(). |
167 | ** Update the filename portion of the locator. Clear the other info in locator. | |
168 | ** (elz) | |
169 | */ | |
c906108c | 170 | void |
eca6576c | 171 | tuiSwitchFilename (char *fileName) |
c906108c SS |
172 | { |
173 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
174 | ||
175 | if (locator->content[0] == (Opaque) NULL) | |
176 | tuiSetLocatorContent ((struct frame_info *) NULL); | |
177 | ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0; | |
178 | ||
179 | tuiSetLocatorInfo (fileName, | |
180 | (char *) NULL, | |
181 | 0, | |
c774cec6 | 182 | (CORE_ADDR) 0, |
c906108c SS |
183 | &((TuiWinElementPtr) locator->content[0])->whichElement.locator); |
184 | ||
185 | tuiShowLocatorContent (); | |
186 | ||
187 | return; | |
188 | } /* tuiSwitchFilename */ | |
189 | ||
190 | ||
191 | /* | |
c5aa993b JM |
192 | ** tuiGetLocatorFilename(). |
193 | ** Get the filename portion of the locator. | |
194 | ** (elz) | |
195 | */ | |
c906108c | 196 | void |
eca6576c | 197 | tuiGetLocatorFilename (TuiGenWinInfoPtr locator, char **filename) |
c906108c SS |
198 | { |
199 | ||
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) | |
203 | { | |
204 | int name_length = | |
205 | strlen (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName); | |
206 | ||
207 | (*filename) = (char *) xmalloc (name_length + 1); | |
208 | strcpy ((*filename), | |
209 | ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName); | |
210 | } | |
211 | ||
212 | return; | |
213 | } /* tuiGetLocatorFilename */ | |
214 | ||
215 | ||
216 | /* | |
c5aa993b JM |
217 | ** tuiUpdateLocatorInfoFromFrame(). |
218 | ** Function to update the locator, with the information extracted from frameInfo | |
219 | */ | |
c906108c | 220 | void |
eca6576c SC |
221 | tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo, |
222 | TuiLocatorElementPtr element) | |
c906108c SS |
223 | { |
224 | struct symtab_and_line symtabAndLine; | |
225 | ||
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 | _getFuncNameFromFrame (frameInfo), | |
234 | symtabAndLine.line, | |
c774cec6 | 235 | frameInfo->pc, |
c906108c SS |
236 | element); |
237 | else | |
238 | tuiSetLocatorInfo ((char *) NULL, | |
239 | _getFuncNameFromFrame (frameInfo), | |
240 | 0, | |
c774cec6 | 241 | frameInfo->pc, |
c906108c SS |
242 | element); |
243 | ||
244 | return; | |
245 | } /* tuiUpdateLocatorInfoFromFrame */ | |
246 | ||
247 | ||
248 | /* | |
c5aa993b JM |
249 | ** tuiSetLocatorContent(). |
250 | ** Function to set the content of the locator | |
251 | */ | |
c906108c | 252 | void |
eca6576c | 253 | tuiSetLocatorContent (struct frame_info *frameInfo) |
c906108c SS |
254 | { |
255 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
256 | TuiWinElementPtr element; | |
257 | struct symtab_and_line symtabAndLine; | |
258 | ||
259 | /* Allocate the element if necessary */ | |
260 | if (locator->contentSize <= 0) | |
261 | { | |
262 | TuiWinContent contentPtr; | |
263 | ||
264 | if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL) | |
265 | error ("Unable to Allocate Memory to Display Location."); | |
266 | locator->contentSize = 1; | |
267 | } | |
268 | ||
269 | if (frameInfo != (struct frame_info *) NULL) | |
270 | tuiUpdateLocatorInfoFromFrame (frameInfo, | |
271 | &((TuiWinElementPtr) locator->content[0])->whichElement.locator); | |
272 | else | |
273 | tuiSetLocatorInfo ((char *) NULL, | |
274 | (char *) NULL, | |
275 | 0, | |
c774cec6 | 276 | (CORE_ADDR) 0, |
c906108c SS |
277 | &((TuiWinElementPtr) locator->content[0])->whichElement.locator); |
278 | return; | |
279 | } /* tuiSetLocatorContent */ | |
280 | ||
281 | ||
282 | /* | |
c5aa993b JM |
283 | ** tuiUpdateLocatorDisplay(). |
284 | ** Function to update the locator display | |
285 | */ | |
c906108c | 286 | void |
eca6576c | 287 | tuiUpdateLocatorDisplay (struct frame_info *frameInfo) |
c906108c SS |
288 | { |
289 | tuiClearLocatorDisplay (); | |
290 | tuiSetLocatorContent (frameInfo); | |
291 | tuiShowLocatorContent (); | |
292 | ||
293 | return; | |
294 | } /* tuiUpdateLocatorDisplay */ | |
295 | ||
296 | ||
297 | /* | |
c5aa993b JM |
298 | ** tuiShowFrameInfo(). |
299 | ** Function to print the frame inforrmation for the TUI. | |
300 | */ | |
c906108c | 301 | void |
eca6576c | 302 | tuiShowFrameInfo (struct frame_info *fi) |
c906108c SS |
303 | { |
304 | TuiWinInfoPtr winInfo; | |
305 | register int i; | |
306 | ||
307 | if (fi) | |
308 | { | |
309 | register int startLine, i; | |
310 | register struct symtab *s; | |
311 | CORE_ADDR low; | |
312 | TuiGenWinInfoPtr locator = locatorWinInfoPtr (); | |
313 | int sourceAlreadyDisplayed; | |
314 | ||
315 | ||
316 | s = find_pc_symtab (fi->pc); | |
75fd9bc1 SC |
317 | if (s == 0) |
318 | return; | |
319 | ||
a4b99e53 | 320 | startLine = 0; |
c906108c SS |
321 | sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename); |
322 | tuiUpdateLocatorDisplay (fi); | |
323 | for (i = 0; i < (sourceWindows ())->count; i++) | |
324 | { | |
a4b99e53 | 325 | TuiWhichElement *item; |
c906108c | 326 | winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i]; |
a4b99e53 SC |
327 | |
328 | item = &((TuiWinElementPtr) locator->content[0])->whichElement; | |
c906108c SS |
329 | if (winInfo == srcWin) |
330 | { | |
a4b99e53 SC |
331 | startLine = (item->locator.lineNo - |
332 | (winInfo->generic.viewportHeight / 2)) + 1; | |
c906108c SS |
333 | if (startLine <= 0) |
334 | startLine = 1; | |
335 | } | |
336 | else | |
337 | { | |
338 | if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0) | |
339 | error ("No function contains program counter for selected frame.\n"); | |
340 | else | |
c774cec6 | 341 | low = tuiGetLowDisassemblyAddress (low, fi->pc); |
c906108c SS |
342 | } |
343 | ||
344 | if (winInfo == srcWin) | |
345 | { | |
a4b99e53 SC |
346 | TuiLineOrAddress l; |
347 | l.lineNo = startLine; | |
348 | if (!(sourceAlreadyDisplayed | |
349 | && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE))) | |
350 | tuiUpdateSourceWindow (winInfo, s, l, TRUE); | |
c906108c | 351 | else |
a4b99e53 SC |
352 | { |
353 | l.lineNo = item->locator.lineNo; | |
354 | tuiSetIsExecPointAt (l, winInfo); | |
355 | } | |
c906108c SS |
356 | } |
357 | else | |
358 | { | |
359 | if (winInfo == disassemWin) | |
360 | { | |
a4b99e53 SC |
361 | TuiLineOrAddress a; |
362 | a.addr = low; | |
363 | if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE)) | |
364 | tuiUpdateSourceWindow (winInfo, s, a, TRUE); | |
c906108c | 365 | else |
a4b99e53 SC |
366 | { |
367 | a.addr = item->locator.addr; | |
368 | tuiSetIsExecPointAt (a, winInfo); | |
369 | } | |
c906108c SS |
370 | } |
371 | } | |
372 | tuiUpdateExecInfo (winInfo); | |
373 | } | |
374 | } | |
375 | else | |
376 | { | |
377 | tuiUpdateLocatorDisplay (fi); | |
378 | for (i = 0; i < (sourceWindows ())->count; i++) | |
379 | { | |
380 | winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i]; | |
381 | tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT); | |
382 | tuiUpdateExecInfo (winInfo); | |
383 | } | |
384 | } | |
385 | ||
386 | return; | |
387 | } /* tuiShowFrameInfo */ | |
388 | ||
c906108c | 389 | /* |
c5aa993b JM |
390 | ** _initialize_tuiStack(). |
391 | ** Function to initialize gdb commands, for tui window stack manipulation. | |
392 | */ | |
c906108c | 393 | void |
fba45db2 | 394 | _initialize_tuiStack (void) |
c906108c | 395 | { |
41783295 SC |
396 | add_com ("update", class_tui, _tuiUpdateLocation_command, |
397 | "Update the source window and locator to display the current execution point.\n"); | |
398 | } | |
c906108c SS |
399 | |
400 | ||
401 | /***************************************** | |
402 | ** STATIC LOCAL FUNCTIONS ** | |
403 | ******************************************/ | |
404 | ||
405 | /* | |
c5aa993b JM |
406 | ** _getFuncNameFromFrame(). |
407 | */ | |
c906108c | 408 | static char * |
eca6576c | 409 | _getFuncNameFromFrame (struct frame_info *frameInfo) |
c906108c SS |
410 | { |
411 | char *funcName = (char *) NULL; | |
412 | ||
413 | find_pc_partial_function (frameInfo->pc, | |
414 | &funcName, | |
415 | (CORE_ADDR *) NULL, | |
416 | (CORE_ADDR *) NULL); | |
417 | return funcName; | |
418 | } /* _getFuncNameFromFrame */ | |
419 | ||
420 | ||
421 | /* | |
c5aa993b JM |
422 | ** _tuiUpdateLocation_command(). |
423 | ** Command to update the display with the current execution point | |
424 | */ | |
c906108c | 425 | static void |
eca6576c | 426 | _tuiUpdateLocation_command (char *arg, int fromTTY) |
c906108c SS |
427 | { |
428 | #ifndef TRY | |
a14ed312 | 429 | extern void frame_command (char *, int); |
c906108c SS |
430 | frame_command ("0", FALSE); |
431 | #else | |
432 | struct frame_info *curFrame; | |
433 | ||
434 | /* Obtain the current execution point */ | |
435 | if ((curFrame = get_current_frame ()) != (struct frame_info *) NULL) | |
436 | { | |
437 | struct frame_info *frame; | |
438 | int curLevel = 0; | |
439 | ||
440 | for (frame = get_prev_frame (curLevel); | |
441 | (frame != (struct frame_info *) NULL && (frame != curFrame)); | |
442 | frame = get_prev_frame (frame)) | |
443 | curLevel++; | |
444 | ||
445 | if (curFrame != (struct frame_info *) NULL) | |
446 | print_frame_info (frame, curLevel, 0, 1); | |
447 | } | |
448 | #endif | |
449 | ||
450 | return; | |
451 | } /* _tuiUpdateLocation_command */ |