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