* tuiDisassem.c (tuiVerticalDisassemScroll): Use CORE_ADDR.
[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"
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
40static char *_getFuncNameFromFrame (struct frame_info *);
41static void _tuiUpdateLocation_command (char *, int);
c906108c
SS
42
43
44
45/*****************************************
46** PUBLIC FUNCTION **
47******************************************/
48
49/*
c5aa993b
JM
50 ** tuiClearLocatorDisplay()
51 */
c906108c 52void
c906108c 53tuiClearLocatorDisplay (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 81void
c906108c 82tuiShowLocatorContent (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
110/*
c5aa993b
JM
111 ** tuiSetLocatorInfo().
112 ** Function to update the locator, with the provided arguments.
113 */
c906108c 114void
eca6576c 115tuiSetLocatorInfo (char *fname, char *procname, int lineNo,
c774cec6 116 CORE_ADDR addr, TuiLocatorElementPtr element)
c906108c
SS
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;
c774cec6 140 element->addr = addr;
c906108c
SS
141
142 return;
143} /* tuiSetLocatorInfo */
144
145
146/*
c5aa993b
JM
147 ** tuiUpdateLocatorFilename().
148 ** Update only the filename portion of the locator.
149 */
c906108c 150void
eca6576c 151tuiUpdateLocatorFilename (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 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/*
c5aa993b
JM
169 ** tui_vUpdateLocatorFilename().
170 ** Update only the filename portion of the locator with args in a va_list.
171 */
c906108c 172void
eca6576c 173tui_vUpdateLocatorFilename (va_list args)
c906108c
SS
174{
175 char *fileName;
176
177 fileName = va_arg (args, char *);
178 tuiUpdateLocatorFilename (fileName);
179
180 return;
181} /* tui_vUpdateLocatorFilename */
182
183
184/*
c5aa993b
JM
185 ** tuiSwitchFilename().
186 ** Update the filename portion of the locator. Clear the other info in locator.
187 ** (elz)
188 */
c906108c 189void
eca6576c 190tuiSwitchFilename (char *fileName)
c906108c
SS
191{
192 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
193
194 if (locator->content[0] == (Opaque) NULL)
195 tuiSetLocatorContent ((struct frame_info *) NULL);
196 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
197
198 tuiSetLocatorInfo (fileName,
199 (char *) NULL,
200 0,
c774cec6 201 (CORE_ADDR) 0,
c906108c
SS
202 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
203
204 tuiShowLocatorContent ();
205
206 return;
207} /* tuiSwitchFilename */
208
209
210/*
c5aa993b
JM
211 ** tuiGetLocatorFilename().
212 ** Get the filename portion of the locator.
213 ** (elz)
214 */
c906108c 215void
eca6576c 216tuiGetLocatorFilename (TuiGenWinInfoPtr locator, char **filename)
c906108c
SS
217{
218
219 /* the current filename could be non known, in which case the xmalloc would
220 allocate no memory, because the length would be 0 */
221 if (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName)
222 {
223 int name_length =
224 strlen (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
225
226 (*filename) = (char *) xmalloc (name_length + 1);
227 strcpy ((*filename),
228 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
229 }
230
231 return;
232} /* tuiGetLocatorFilename */
233
234
235/*
c5aa993b
JM
236 ** tuiUpdateLocatorInfoFromFrame().
237 ** Function to update the locator, with the information extracted from frameInfo
238 */
c906108c 239void
eca6576c
SC
240tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo,
241 TuiLocatorElementPtr element)
c906108c
SS
242{
243 struct symtab_and_line symtabAndLine;
244
245 /* now get the new info */
246 symtabAndLine = find_pc_line (frameInfo->pc,
247 (frameInfo->next != (struct frame_info *) NULL &&
248 !frameInfo->next->signal_handler_caller &&
249 !frame_in_dummy (frameInfo->next)));
250 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
251 tuiSetLocatorInfo (symtabAndLine.symtab->filename,
252 _getFuncNameFromFrame (frameInfo),
253 symtabAndLine.line,
c774cec6 254 frameInfo->pc,
c906108c
SS
255 element);
256 else
257 tuiSetLocatorInfo ((char *) NULL,
258 _getFuncNameFromFrame (frameInfo),
259 0,
c774cec6 260 frameInfo->pc,
c906108c
SS
261 element);
262
263 return;
264} /* tuiUpdateLocatorInfoFromFrame */
265
266
267/*
c5aa993b
JM
268 ** tuiSetLocatorContent().
269 ** Function to set the content of the locator
270 */
c906108c 271void
eca6576c 272tuiSetLocatorContent (struct frame_info *frameInfo)
c906108c
SS
273{
274 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
275 TuiWinElementPtr element;
276 struct symtab_and_line symtabAndLine;
277
278 /* Allocate the element if necessary */
279 if (locator->contentSize <= 0)
280 {
281 TuiWinContent contentPtr;
282
283 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
284 error ("Unable to Allocate Memory to Display Location.");
285 locator->contentSize = 1;
286 }
287
288 if (frameInfo != (struct frame_info *) NULL)
289 tuiUpdateLocatorInfoFromFrame (frameInfo,
290 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
291 else
292 tuiSetLocatorInfo ((char *) NULL,
293 (char *) NULL,
294 0,
c774cec6 295 (CORE_ADDR) 0,
c906108c
SS
296 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
297 return;
298} /* tuiSetLocatorContent */
299
300
301/*
c5aa993b
JM
302 ** tuiUpdateLocatorDisplay().
303 ** Function to update the locator display
304 */
c906108c 305void
eca6576c 306tuiUpdateLocatorDisplay (struct frame_info *frameInfo)
c906108c
SS
307{
308 tuiClearLocatorDisplay ();
309 tuiSetLocatorContent (frameInfo);
310 tuiShowLocatorContent ();
311
312 return;
313} /* tuiUpdateLocatorDisplay */
314
315
316/*
c5aa993b
JM
317 ** tuiShowFrameInfo().
318 ** Function to print the frame inforrmation for the TUI.
319 */
c906108c 320void
eca6576c 321tuiShowFrameInfo (struct frame_info *fi)
c906108c
SS
322{
323 TuiWinInfoPtr winInfo;
324 register int i;
325
326 if (fi)
327 {
328 register int startLine, i;
329 register struct symtab *s;
330 CORE_ADDR low;
331 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
332 int sourceAlreadyDisplayed;
333
334
335 s = find_pc_symtab (fi->pc);
75fd9bc1
SC
336 if (s == 0)
337 return;
338
c906108c
SS
339 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
340 tuiUpdateLocatorDisplay (fi);
341 for (i = 0; i < (sourceWindows ())->count; i++)
342 {
343 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
344 if (winInfo == srcWin)
345 {
346 startLine =
347 (((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo -
348 (winInfo->generic.viewportHeight / 2)) + 1;
349 if (startLine <= 0)
350 startLine = 1;
351 }
352 else
353 {
354 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
355 error ("No function contains program counter for selected frame.\n");
356 else
c774cec6 357 low = tuiGetLowDisassemblyAddress (low, fi->pc);
c906108c
SS
358 }
359
360 if (winInfo == srcWin)
361 {
362 if (!(sourceAlreadyDisplayed && m_tuiLineDisplayedWithinThreshold (
363 winInfo,
364 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo)))
365 tuiUpdateSourceWindow (winInfo, s, (Opaque) startLine, TRUE);
366 else
367 tuiSetIsExecPointAt ((Opaque)
368 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.lineNo,
369 winInfo);
370 }
371 else
372 {
373 if (winInfo == disassemWin)
374 {
375 if (!m_tuiLineDisplayedWithinThreshold (winInfo,
376 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr))
377 tuiUpdateSourceWindow (winInfo, s, (Opaque) low, TRUE);
378 else
379 tuiSetIsExecPointAt ((Opaque)
380 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.addr,
381 winInfo);
382 }
383 }
384 tuiUpdateExecInfo (winInfo);
385 }
386 }
387 else
388 {
389 tuiUpdateLocatorDisplay (fi);
390 for (i = 0; i < (sourceWindows ())->count; i++)
391 {
392 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
393 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
394 tuiUpdateExecInfo (winInfo);
395 }
396 }
397
398 return;
399} /* tuiShowFrameInfo */
400
401
402/*
c5aa993b
JM
403 ** tui_vShowFrameInfo().
404 ** Function to print the frame inforrmation for the TUI with args in a va_list.
405 */
c906108c 406void
eca6576c 407tui_vShowFrameInfo (va_list args)
c906108c
SS
408{
409 struct frame_info *fi;
410
411 fi = va_arg (args, struct frame_info *);
412 tuiShowFrameInfo (fi);
413
414 return;
415} /* tui_vShowFrameInfo */
416
417
418/*
c5aa993b
JM
419 ** _initialize_tuiStack().
420 ** Function to initialize gdb commands, for tui window stack manipulation.
421 */
c906108c 422void
fba45db2 423_initialize_tuiStack (void)
c906108c
SS
424{
425 if (tui_version)
426 {
427 add_com ("update", class_tui, _tuiUpdateLocation_command,
428 "Update the source window and locator to display the current execution point.\n");
429 }
430
431 return;
432} /* _initialize_tuiStack */
433
434
435/*****************************************
436** STATIC LOCAL FUNCTIONS **
437******************************************/
438
439/*
c5aa993b
JM
440 ** _getFuncNameFromFrame().
441 */
c906108c 442static char *
eca6576c 443_getFuncNameFromFrame (struct frame_info *frameInfo)
c906108c
SS
444{
445 char *funcName = (char *) NULL;
446
447 find_pc_partial_function (frameInfo->pc,
448 &funcName,
449 (CORE_ADDR *) NULL,
450 (CORE_ADDR *) NULL);
451 return funcName;
452} /* _getFuncNameFromFrame */
453
454
455/*
c5aa993b
JM
456 ** _tuiUpdateLocation_command().
457 ** Command to update the display with the current execution point
458 */
c906108c 459static void
eca6576c 460_tuiUpdateLocation_command (char *arg, int fromTTY)
c906108c
SS
461{
462#ifndef TRY
a14ed312 463extern void frame_command (char *, int);
c906108c
SS
464 frame_command ("0", FALSE);
465#else
466 struct frame_info *curFrame;
467
468 /* Obtain the current execution point */
469 if ((curFrame = get_current_frame ()) != (struct frame_info *) NULL)
470 {
471 struct frame_info *frame;
472 int curLevel = 0;
473
474 for (frame = get_prev_frame (curLevel);
475 (frame != (struct frame_info *) NULL && (frame != curFrame));
476 frame = get_prev_frame (frame))
477 curLevel++;
478
479 if (curFrame != (struct frame_info *) NULL)
480 print_frame_info (frame, curLevel, 0, 1);
481 }
482#endif
483
484 return;
485} /* _tuiUpdateLocation_command */
This page took 0.146937 seconds and 4 git commands to generate.