* tuiWin.c, tuiWin.h, tui.c, tui.h, tuiCommand.c: Add FSF copyright.
[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
27 #include "tui.h"
28 #include "tuiData.h"
29 #include "tuiStack.h"
30 #include "tuiSourceWin.h"
31
32
33 /*****************************************
34 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
35 ******************************************/
36
37 static char *_getFuncNameFromFrame (struct frame_info *);
38 static void _tuiUpdateLocation_command (char *, int);
39
40
41
42 /*****************************************
43 ** PUBLIC FUNCTION **
44 ******************************************/
45
46 /*
47 ** tuiClearLocatorDisplay()
48 */
49 void
50 #ifdef __STDC__
51 tuiClearLocatorDisplay (void)
52 #else
53 tuiClearLocatorDisplay ()
54 #endif
55 {
56 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
57 int i;
58
59 if (locator->handle != (WINDOW *) NULL)
60 {
61 /* No need to werase, since writing a line of
62 * blanks which we do below, is equivalent.
63 */
64 /* werase(locator->handle); */
65 wmove (locator->handle, 0, 0);
66 wstandout (locator->handle);
67 for (i = 0; i < locator->width; i++)
68 waddch (locator->handle, ' ');
69 wstandend (locator->handle);
70 tuiRefreshWin (locator);
71 wmove (locator->handle, 0, 0);
72 locator->contentInUse = FALSE;
73 }
74
75 return;
76 } /* tuiClearLocatorDisplay */
77
78
79 /*
80 ** tuiShowLocatorContent()
81 */
82 void
83 #ifdef __STDC__
84 tuiShowLocatorContent (void)
85 #else
86 tuiShowLocatorContent ()
87 #endif
88 {
89 char *string;
90 TuiGenWinInfoPtr locator;
91
92 locator = locatorWinInfoPtr ();
93
94 if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL)
95 {
96 string = displayableWinContentAt (locator, 0);
97 if (string != (char *) NULL)
98 {
99 wmove (locator->handle, 0, 0);
100 wstandout (locator->handle);
101 waddstr (locator->handle, string);
102 wstandend (locator->handle);
103 tuiRefreshWin (locator);
104 wmove (locator->handle, 0, 0);
105 if (string != nullStr ())
106 tuiFree (string);
107 locator->contentInUse = TRUE;
108 }
109 }
110
111 return;
112 } /* tuiShowLocatorContent */
113
114
115 /*
116 ** tuiSetLocatorInfo().
117 ** Function to update the locator, with the provided arguments.
118 */
119 void
120 #ifdef __STDC__
121 tuiSetLocatorInfo (
122 char *fname,
123 char *procname,
124 int lineNo,
125 Opaque addr,
126 TuiLocatorElementPtr element)
127 #else
128 tuiSetLocatorInfo (fname, procname, lineNo, addr, element)
129 char *fname;
130 char *procname;
131 int lineNo;
132 Opaque addr;
133 TuiLocatorElementPtr element;
134 #endif
135 {
136 #ifdef COMMENT
137 /* first free the old info */
138 if (element->fileName)
139 tuiFree (element->fileName);
140 if (element->procName)
141 tuiFree (element->procName);
142
143 if (fname == (char *) NULL)
144 element->fileName = fname;
145 else
146 element->fileName = tuiStrDup (fname);
147 if (procname == (char *) NULL)
148 element->procName = procname;
149 else
150 element->procName = tuiStrDup (procname);
151 #else
152 element->fileName[0] = (char) 0;
153 element->procName[0] = (char) 0;
154 strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, fname);
155 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
156 #endif
157 element->lineNo = lineNo;
158 element->addr = (Opaque) addr;
159
160 return;
161 } /* tuiSetLocatorInfo */
162
163
164 /*
165 ** tuiUpdateLocatorFilename().
166 ** Update only the filename portion of the locator.
167 */
168 void
169 #ifdef __STDC__
170 tuiUpdateLocatorFilename (
171 char *fileName)
172 #else
173 tuiUpdateLocatorFilename (fileName)
174 char *fileName;
175 #endif
176 {
177 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
178
179 if (locator->content[0] == (Opaque) NULL)
180 tuiSetLocatorContent ((struct frame_info *) NULL);
181 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
182 strcat_to_buf (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName,
183 MAX_LOCATOR_ELEMENT_LEN,
184 fileName);
185
186 tuiShowLocatorContent ();
187
188 return;
189 } /* tuiUpdateLocatorFilename */
190
191
192 /*
193 ** tui_vUpdateLocatorFilename().
194 ** Update only the filename portion of the locator with args in a va_list.
195 */
196 void
197 #ifdef __STDC__
198 tui_vUpdateLocatorFilename (
199 va_list args)
200 #else
201 tui_vUpdateLocatorFilename (args)
202 va_list args;
203 #endif
204 {
205 char *fileName;
206
207 fileName = va_arg (args, char *);
208 tuiUpdateLocatorFilename (fileName);
209
210 return;
211 } /* tui_vUpdateLocatorFilename */
212
213
214 /*
215 ** tuiSwitchFilename().
216 ** Update the filename portion of the locator. Clear the other info in locator.
217 ** (elz)
218 */
219 void
220 #ifdef __STDC__
221 tuiSwitchFilename (
222 char *fileName)
223 #else
224 tuiSwitchFilename (fileName)
225 char *fileName;
226 #endif
227 {
228 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
229
230 if (locator->content[0] == (Opaque) NULL)
231 tuiSetLocatorContent ((struct frame_info *) NULL);
232 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
233
234 tuiSetLocatorInfo (fileName,
235 (char *) NULL,
236 0,
237 (Opaque) NULL,
238 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
239
240 tuiShowLocatorContent ();
241
242 return;
243 } /* tuiSwitchFilename */
244
245
246 /*
247 ** tuiGetLocatorFilename().
248 ** Get the filename portion of the locator.
249 ** (elz)
250 */
251 void
252 #ifdef __STDC__
253 tuiGetLocatorFilename (
254 TuiGenWinInfoPtr locator,
255 char **filename)
256 #else
257 tuiGetLocatorFilename (locator, filename)
258 TuiGenWinInfoPtr locator;
259 char **filename;
260 #endif
261 {
262
263 /* the current filename could be non known, in which case the xmalloc would
264 allocate no memory, because the length would be 0 */
265 if (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName)
266 {
267 int name_length =
268 strlen (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
269
270 (*filename) = (char *) xmalloc (name_length + 1);
271 strcpy ((*filename),
272 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
273 }
274
275 return;
276 } /* tuiGetLocatorFilename */
277
278
279 /*
280 ** tuiUpdateLocatorInfoFromFrame().
281 ** Function to update the locator, with the information extracted from frameInfo
282 */
283 void
284 #ifdef __STDC__
285 tuiUpdateLocatorInfoFromFrame (
286 struct frame_info *frameInfo,
287 TuiLocatorElementPtr element)
288 #else
289 tuiUpdateLocatorInfoFromFrame (frameInfo, element)
290 struct frame_info *frameInfo;
291 TuiLocatorElementPtr element;
292 #endif
293 {
294 struct symtab_and_line symtabAndLine;
295
296 /* now get the new info */
297 symtabAndLine = find_pc_line (frameInfo->pc,
298 (frameInfo->next != (struct frame_info *) NULL &&
299 !frameInfo->next->signal_handler_caller &&
300 !frame_in_dummy (frameInfo->next)));
301 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
302 tuiSetLocatorInfo (symtabAndLine.symtab->filename,
303 _getFuncNameFromFrame (frameInfo),
304 symtabAndLine.line,
305 (Opaque) frameInfo->pc,
306 element);
307 else
308 tuiSetLocatorInfo ((char *) NULL,
309 _getFuncNameFromFrame (frameInfo),
310 0,
311 (Opaque) frameInfo->pc,
312 element);
313
314 return;
315 } /* tuiUpdateLocatorInfoFromFrame */
316
317
318 /*
319 ** tuiSetLocatorContent().
320 ** Function to set the content of the locator
321 */
322 void
323 #ifdef __STDC__
324 tuiSetLocatorContent (
325 struct frame_info *frameInfo)
326 #else
327 tuiSetLocatorContent (frameInfo)
328 struct frame_info *frameInfo;
329 #endif
330 {
331 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
332 TuiWinElementPtr element;
333 struct symtab_and_line symtabAndLine;
334
335 /* Allocate the element if necessary */
336 if (locator->contentSize <= 0)
337 {
338 TuiWinContent contentPtr;
339
340 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
341 error ("Unable to Allocate Memory to Display Location.");
342 locator->contentSize = 1;
343 }
344
345 if (frameInfo != (struct frame_info *) NULL)
346 tuiUpdateLocatorInfoFromFrame (frameInfo,
347 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
348 else
349 tuiSetLocatorInfo ((char *) NULL,
350 (char *) NULL,
351 0,
352 (Opaque) NULL,
353 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
354 return;
355 } /* tuiSetLocatorContent */
356
357
358 /*
359 ** tuiUpdateLocatorDisplay().
360 ** Function to update the locator display
361 */
362 void
363 #ifdef __STDC__
364 tuiUpdateLocatorDisplay (
365 struct frame_info *frameInfo)
366 #else
367 tuiUpdateLocatorDisplay (frameInfo)
368 struct frame_info *frameInfo;
369 #endif
370 {
371 tuiClearLocatorDisplay ();
372 tuiSetLocatorContent (frameInfo);
373 tuiShowLocatorContent ();
374
375 return;
376 } /* tuiUpdateLocatorDisplay */
377
378
379 /*
380 ** tuiShowFrameInfo().
381 ** Function to print the frame inforrmation for the TUI.
382 */
383 void
384 #ifdef __STDC__
385 tuiShowFrameInfo (
386 struct frame_info *fi)
387 #else
388 tuiShowFrameInfo (fi)
389 struct frame_info *fi;
390 #endif
391 {
392 TuiWinInfoPtr winInfo;
393 register int i;
394
395 if (fi)
396 {
397 register int startLine, i;
398 register struct symtab *s;
399 CORE_ADDR low;
400 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
401 int sourceAlreadyDisplayed;
402
403
404 s = find_pc_symtab (fi->pc);
405 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
406 tuiUpdateLocatorDisplay (fi);
407 for (i = 0; i < (sourceWindows ())->count; i++)
408 {
409 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
410 if (winInfo == srcWin)
411 {
412 startLine =
413 (((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo -
414 (winInfo->generic.viewportHeight / 2)) + 1;
415 if (startLine <= 0)
416 startLine = 1;
417 }
418 else
419 {
420 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
421 error ("No function contains program counter for selected frame.\n");
422 else
423 low = (CORE_ADDR) tuiGetLowDisassemblyAddress ((Opaque) low, (Opaque) fi->pc);
424 }
425
426 if (winInfo == srcWin)
427 {
428 if (!(sourceAlreadyDisplayed && m_tuiLineDisplayedWithinThreshold (
429 winInfo,
430 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo)))
431 tuiUpdateSourceWindow (winInfo, s, (Opaque) startLine, TRUE);
432 else
433 tuiSetIsExecPointAt ((Opaque)
434 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo,
435 winInfo);
436 }
437 else
438 {
439 if (winInfo == disassemWin)
440 {
441 if (!m_tuiLineDisplayedWithinThreshold (winInfo,
442 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr))
443 tuiUpdateSourceWindow (winInfo, s, (Opaque) low, TRUE);
444 else
445 tuiSetIsExecPointAt ((Opaque)
446 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr,
447 winInfo);
448 }
449 }
450 tuiUpdateExecInfo (winInfo);
451 }
452 }
453 else
454 {
455 tuiUpdateLocatorDisplay (fi);
456 for (i = 0; i < (sourceWindows ())->count; i++)
457 {
458 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
459 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
460 tuiUpdateExecInfo (winInfo);
461 }
462 }
463
464 return;
465 } /* tuiShowFrameInfo */
466
467
468 /*
469 ** tui_vShowFrameInfo().
470 ** Function to print the frame inforrmation for the TUI with args in a va_list.
471 */
472 void
473 #ifdef __STDC__
474 tui_vShowFrameInfo (
475 va_list args)
476 #else
477 tui_vShowFrameInfo (args)
478 va_list args;
479 #endif
480 {
481 struct frame_info *fi;
482
483 fi = va_arg (args, struct frame_info *);
484 tuiShowFrameInfo (fi);
485
486 return;
487 } /* tui_vShowFrameInfo */
488
489
490 /*
491 ** _initialize_tuiStack().
492 ** Function to initialize gdb commands, for tui window stack manipulation.
493 */
494 void
495 _initialize_tuiStack (void)
496 {
497 if (tui_version)
498 {
499 add_com ("update", class_tui, _tuiUpdateLocation_command,
500 "Update the source window and locator to display the current execution point.\n");
501 }
502
503 return;
504 } /* _initialize_tuiStack */
505
506
507 /*****************************************
508 ** STATIC LOCAL FUNCTIONS **
509 ******************************************/
510
511 /*
512 ** _getFuncNameFromFrame().
513 */
514 static char *
515 #ifdef __STDC__
516 _getFuncNameFromFrame (
517 struct frame_info *frameInfo)
518 #else
519 _getFuncNameFromFrame (frameInfo)
520 struct frame_info *frameInfo;
521 #endif
522 {
523 char *funcName = (char *) NULL;
524
525 find_pc_partial_function (frameInfo->pc,
526 &funcName,
527 (CORE_ADDR *) NULL,
528 (CORE_ADDR *) NULL);
529 return funcName;
530 } /* _getFuncNameFromFrame */
531
532
533 /*
534 ** _tuiUpdateLocation_command().
535 ** Command to update the display with the current execution point
536 */
537 static void
538 #ifdef __STDC__
539 _tuiUpdateLocation_command (
540 char *arg,
541 int fromTTY)
542 #else
543 _tuiUpdateLocation_command (arg, fromTTY)
544 char *arg;
545 int fromTTY;
546 #endif
547 {
548 #ifndef TRY
549 extern void frame_command (char *, int);
550 frame_command ("0", FALSE);
551 #else
552 struct frame_info *curFrame;
553
554 /* Obtain the current execution point */
555 if ((curFrame = get_current_frame ()) != (struct frame_info *) NULL)
556 {
557 struct frame_info *frame;
558 int curLevel = 0;
559
560 for (frame = get_prev_frame (curLevel);
561 (frame != (struct frame_info *) NULL && (frame != curFrame));
562 frame = get_prev_frame (frame))
563 curLevel++;
564
565 if (curFrame != (struct frame_info *) NULL)
566 print_frame_info (frame, curLevel, 0, 1);
567 }
568 #endif
569
570 return;
571 } /* _tuiUpdateLocation_command */
This page took 0.04293 seconds and 4 git commands to generate.