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