* tuiWin.c (_parseScrollingArgs): Fix uninitialized variable.
[deliverable/binutils-gdb.git] / gdb / tui / tuiStack.c
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. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "breakpoint.h"
25 #include "frame.h"
26 #include "command.h"
27
28 #include "tui.h"
29 #include "tuiData.h"
30 #include "tuiStack.h"
31 #include "tuiGeneralWin.h"
32 #include "tuiSource.h"
33 #include "tuiSourceWin.h"
34
35
36 /*****************************************
37 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
38 ******************************************/
39
40 static char *_getFuncNameFromFrame (struct frame_info *);
41 static void _tuiUpdateLocation_command (char *, int);
42
43
44
45 /*****************************************
46 ** PUBLIC FUNCTION **
47 ******************************************/
48
49 /*
50 ** tuiClearLocatorDisplay()
51 */
52 void
53 tuiClearLocatorDisplay (void)
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.
62 */
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 /*
79 ** tuiShowLocatorContent()
80 */
81 void
82 tuiShowLocatorContent (void)
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
110 /*
111 ** tuiSetLocatorInfo().
112 ** Function to update the locator, with the provided arguments.
113 */
114 void
115 tuiSetLocatorInfo (char *fname, char *procname, int lineNo,
116 CORE_ADDR addr, TuiLocatorElementPtr element)
117 {
118 #ifdef COMMENT
119 /* first free the old info */
120 if (element->fileName)
121 tuiFree (element->fileName);
122 if (element->procName)
123 tuiFree (element->procName);
124
125 if (fname == (char *) NULL)
126 element->fileName = fname;
127 else
128 element->fileName = tuiStrDup (fname);
129 if (procname == (char *) NULL)
130 element->procName = procname;
131 else
132 element->procName = tuiStrDup (procname);
133 #else
134 element->fileName[0] = (char) 0;
135 element->procName[0] = (char) 0;
136 strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, fname);
137 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
138 #endif
139 element->lineNo = lineNo;
140 element->addr = addr;
141
142 return;
143 } /* tuiSetLocatorInfo */
144
145
146 /*
147 ** tuiUpdateLocatorFilename().
148 ** Update only the filename portion of the locator.
149 */
150 void
151 tuiUpdateLocatorFilename (char *fileName)
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 strcat_to_buf (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName,
159 MAX_LOCATOR_ELEMENT_LEN,
160 fileName);
161
162 tuiShowLocatorContent ();
163
164 return;
165 } /* tuiUpdateLocatorFilename */
166
167 /*
168 ** tuiSwitchFilename().
169 ** Update the filename portion of the locator. Clear the other info in locator.
170 ** (elz)
171 */
172 void
173 tuiSwitchFilename (char *fileName)
174 {
175 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
176
177 if (locator->content[0] == (Opaque) NULL)
178 tuiSetLocatorContent ((struct frame_info *) NULL);
179 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
180
181 tuiSetLocatorInfo (fileName,
182 (char *) NULL,
183 0,
184 (CORE_ADDR) 0,
185 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
186
187 tuiShowLocatorContent ();
188
189 return;
190 } /* tuiSwitchFilename */
191
192
193 /*
194 ** tuiGetLocatorFilename().
195 ** Get the filename portion of the locator.
196 ** (elz)
197 */
198 void
199 tuiGetLocatorFilename (TuiGenWinInfoPtr locator, char **filename)
200 {
201
202 /* the current filename could be non known, in which case the xmalloc would
203 allocate no memory, because the length would be 0 */
204 if (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName)
205 {
206 int name_length =
207 strlen (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
208
209 (*filename) = (char *) xmalloc (name_length + 1);
210 strcpy ((*filename),
211 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
212 }
213
214 return;
215 } /* tuiGetLocatorFilename */
216
217
218 /*
219 ** tuiUpdateLocatorInfoFromFrame().
220 ** Function to update the locator, with the information extracted from frameInfo
221 */
222 void
223 tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo,
224 TuiLocatorElementPtr element)
225 {
226 struct symtab_and_line symtabAndLine;
227
228 /* now get the new info */
229 symtabAndLine = find_pc_line (frameInfo->pc,
230 (frameInfo->next != (struct frame_info *) NULL &&
231 !frameInfo->next->signal_handler_caller &&
232 !frame_in_dummy (frameInfo->next)));
233 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
234 tuiSetLocatorInfo (symtabAndLine.symtab->filename,
235 _getFuncNameFromFrame (frameInfo),
236 symtabAndLine.line,
237 frameInfo->pc,
238 element);
239 else
240 tuiSetLocatorInfo ((char *) NULL,
241 _getFuncNameFromFrame (frameInfo),
242 0,
243 frameInfo->pc,
244 element);
245
246 return;
247 } /* tuiUpdateLocatorInfoFromFrame */
248
249
250 /*
251 ** tuiSetLocatorContent().
252 ** Function to set the content of the locator
253 */
254 void
255 tuiSetLocatorContent (struct frame_info *frameInfo)
256 {
257 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
258 TuiWinElementPtr element;
259 struct symtab_and_line symtabAndLine;
260
261 /* Allocate the element if necessary */
262 if (locator->contentSize <= 0)
263 {
264 TuiWinContent contentPtr;
265
266 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
267 error ("Unable to Allocate Memory to Display Location.");
268 locator->contentSize = 1;
269 }
270
271 if (frameInfo != (struct frame_info *) NULL)
272 tuiUpdateLocatorInfoFromFrame (frameInfo,
273 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
274 else
275 tuiSetLocatorInfo ((char *) NULL,
276 (char *) NULL,
277 0,
278 (CORE_ADDR) 0,
279 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
280 return;
281 } /* tuiSetLocatorContent */
282
283
284 /*
285 ** tuiUpdateLocatorDisplay().
286 ** Function to update the locator display
287 */
288 void
289 tuiUpdateLocatorDisplay (struct frame_info *frameInfo)
290 {
291 tuiClearLocatorDisplay ();
292 tuiSetLocatorContent (frameInfo);
293 tuiShowLocatorContent ();
294
295 return;
296 } /* tuiUpdateLocatorDisplay */
297
298
299 /*
300 ** tuiShowFrameInfo().
301 ** Function to print the frame inforrmation for the TUI.
302 */
303 void
304 tuiShowFrameInfo (struct frame_info *fi)
305 {
306 TuiWinInfoPtr winInfo;
307 register int i;
308
309 if (fi)
310 {
311 register int startLine, i;
312 register struct symtab *s;
313 CORE_ADDR low;
314 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
315 int sourceAlreadyDisplayed;
316
317
318 s = find_pc_symtab (fi->pc);
319 if (s == 0)
320 return;
321
322 startLine = 0;
323 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
324 tuiUpdateLocatorDisplay (fi);
325 for (i = 0; i < (sourceWindows ())->count; i++)
326 {
327 TuiWhichElement *item;
328 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
329
330 item = &((TuiWinElementPtr) locator->content[0])->whichElement;
331 if (winInfo == srcWin)
332 {
333 startLine = (item->locator.lineNo -
334 (winInfo->generic.viewportHeight / 2)) + 1;
335 if (startLine <= 0)
336 startLine = 1;
337 }
338 else
339 {
340 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
341 error ("No function contains program counter for selected frame.\n");
342 else
343 low = tuiGetLowDisassemblyAddress (low, fi->pc);
344 }
345
346 if (winInfo == srcWin)
347 {
348 TuiLineOrAddress l;
349 l.lineNo = startLine;
350 if (!(sourceAlreadyDisplayed
351 && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE)))
352 tuiUpdateSourceWindow (winInfo, s, l, TRUE);
353 else
354 {
355 l.lineNo = item->locator.lineNo;
356 tuiSetIsExecPointAt (l, winInfo);
357 }
358 }
359 else
360 {
361 if (winInfo == disassemWin)
362 {
363 TuiLineOrAddress a;
364 a.addr = low;
365 if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE))
366 tuiUpdateSourceWindow (winInfo, s, a, TRUE);
367 else
368 {
369 a.addr = item->locator.addr;
370 tuiSetIsExecPointAt (a, winInfo);
371 }
372 }
373 }
374 tuiUpdateExecInfo (winInfo);
375 }
376 }
377 else
378 {
379 tuiUpdateLocatorDisplay (fi);
380 for (i = 0; i < (sourceWindows ())->count; i++)
381 {
382 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
383 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
384 tuiUpdateExecInfo (winInfo);
385 }
386 }
387
388 return;
389 } /* tuiShowFrameInfo */
390
391 /*
392 ** _initialize_tuiStack().
393 ** Function to initialize gdb commands, for tui window stack manipulation.
394 */
395 void
396 _initialize_tuiStack (void)
397 {
398 add_com ("update", class_tui, _tuiUpdateLocation_command,
399 "Update the source window and locator to display the current execution point.\n");
400 }
401
402
403 /*****************************************
404 ** STATIC LOCAL FUNCTIONS **
405 ******************************************/
406
407 /*
408 ** _getFuncNameFromFrame().
409 */
410 static char *
411 _getFuncNameFromFrame (struct frame_info *frameInfo)
412 {
413 char *funcName = (char *) NULL;
414
415 find_pc_partial_function (frameInfo->pc,
416 &funcName,
417 (CORE_ADDR *) NULL,
418 (CORE_ADDR *) NULL);
419 return funcName;
420 } /* _getFuncNameFromFrame */
421
422
423 /*
424 ** _tuiUpdateLocation_command().
425 ** Command to update the display with the current execution point
426 */
427 static void
428 _tuiUpdateLocation_command (char *arg, int fromTTY)
429 {
430 #ifndef TRY
431 extern void frame_command (char *, int);
432 frame_command ("0", FALSE);
433 #else
434 struct frame_info *curFrame;
435
436 /* Obtain the current execution point */
437 if ((curFrame = get_current_frame ()) != (struct frame_info *) NULL)
438 {
439 struct frame_info *frame;
440 int curLevel = 0;
441
442 for (frame = get_prev_frame (curLevel);
443 (frame != (struct frame_info *) NULL && (frame != curFrame));
444 frame = get_prev_frame (frame))
445 curLevel++;
446
447 if (curFrame != (struct frame_info *) NULL)
448 print_frame_info (frame, curLevel, 0, 1);
449 }
450 #endif
451
452 return;
453 } /* _tuiUpdateLocation_command */
This page took 0.038607 seconds and 4 git commands to generate.