e2c8a2717ff641f8e5c1914a29a40869d59bd058
[deliverable/binutils-gdb.git] / gdb / tui / tuiStack.c
1 /* TUI display locator.
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
6 Contributed by Hewlett-Packard Company.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
24
25 /* FIXME: cagney/2002-02-28: The GDB coding standard indicates that
26 "defs.h" should be included first. Unfortunatly some systems
27 (currently Debian GNU/Linux) include the <stdbool.h> via <curses.h>
28 and they clash with "bfd.h"'s definiton of true/false. The correct
29 fix is to remove true/false from "bfd.h", however, until that
30 happens, hack around it by including "config.h" and <curses.h>
31 first. */
32
33 #include "config.h"
34 #ifdef HAVE_NCURSES_H
35 #include <ncurses.h>
36 #else
37 #ifdef HAVE_CURSES_H
38 #include <curses.h>
39 #endif
40 #endif
41
42 #include "defs.h"
43 #include "symtab.h"
44 #include "breakpoint.h"
45 #include "frame.h"
46 #include "command.h"
47 #include "top.h"
48
49 #include "tui.h"
50 #include "tuiData.h"
51 #include "tuiStack.h"
52 #include "tuiGeneralWin.h"
53 #include "tuiSource.h"
54 #include "tuiSourceWin.h"
55 #include "tui-file.h"
56
57
58 /* Get a printable name for the function at the address.
59 The symbol name is demangled if demangling is turned on.
60 Returns a pointer to a static area holding the result. */
61 static char* tui_get_function_from_frame (struct frame_info *fi);
62
63 static void tui_update_command (char *, int);
64
65
66 /* Get a printable name for the function at the address.
67 The symbol name is demangled if demangling is turned on.
68 Returns a pointer to a static area holding the result. */
69 static char*
70 tui_get_function_from_frame (struct frame_info *fi)
71 {
72 static char name[256];
73 struct ui_file *stream = tui_sfileopen (256);
74 char *p;
75
76 print_address_symbolic (fi->pc, stream, demangle, "");
77 p = tui_file_get_strbuf (stream);
78
79 /* Use simple heuristics to isolate the function name. The symbol can
80 be demangled and we can have function parameters. Remove them because
81 the status line is too short to display them. */
82 if (*p == '<')
83 p++;
84 strncpy (name, p, sizeof (name));
85 p = strchr (name, '(');
86 if (!p)
87 p = strchr (name, '>');
88 if (p)
89 *p = 0;
90 p = strchr (name, '+');
91 if (p)
92 *p = 0;
93 ui_file_delete (stream);
94 return name;
95 }
96
97 /*
98 ** tuiShowLocatorContent()
99 */
100 void
101 tuiShowLocatorContent (void)
102 {
103 char *string;
104 TuiGenWinInfoPtr locator;
105
106 locator = locatorWinInfoPtr ();
107
108 if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL)
109 {
110 string = displayableWinContentAt (locator, 0);
111 if (string != (char *) NULL)
112 {
113 wmove (locator->handle, 0, 0);
114 wstandout (locator->handle);
115 waddstr (locator->handle, string);
116 wclrtoeol (locator->handle);
117 wstandend (locator->handle);
118 tuiRefreshWin (locator);
119 wmove (locator->handle, 0, 0);
120 if (string != nullStr ())
121 tuiFree (string);
122 locator->contentInUse = TRUE;
123 }
124 }
125
126 return;
127 } /* tuiShowLocatorContent */
128
129
130 /* Update the locator, with the provided arguments. */
131 void
132 tuiSetLocatorInfo (char *fname, char *procname, int lineNo,
133 CORE_ADDR addr, TuiLocatorElementPtr element)
134 {
135 element->fileName[0] = (char) 0;
136 element->procName[0] = (char) 0;
137 strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, fname);
138 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
139 element->lineNo = lineNo;
140 element->addr = addr;
141 }
142
143
144 /*
145 ** tuiUpdateLocatorFilename().
146 ** Update only the filename portion of the locator.
147 */
148 void
149 tuiUpdateLocatorFilename (const char *fileName)
150 {
151 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
152
153 if (locator->content[0] == (Opaque) NULL)
154 tuiSetLocatorContent ((struct frame_info *) NULL);
155 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
156 strcat_to_buf (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName,
157 MAX_LOCATOR_ELEMENT_LEN,
158 fileName);
159
160 tuiShowLocatorContent ();
161
162 return;
163 } /* tuiUpdateLocatorFilename */
164
165 /*
166 ** tuiSwitchFilename().
167 ** Update the filename portion of the locator. Clear the other info in locator.
168 ** (elz)
169 */
170 void
171 tuiSwitchFilename (char *fileName)
172 {
173 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
174
175 if (locator->content[0] == (Opaque) NULL)
176 tuiSetLocatorContent ((struct frame_info *) NULL);
177 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
178
179 tuiSetLocatorInfo (fileName,
180 (char *) NULL,
181 0,
182 (CORE_ADDR) 0,
183 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
184
185 tuiShowLocatorContent ();
186
187 return;
188 } /* tuiSwitchFilename */
189
190 /*
191 ** tuiUpdateLocatorInfoFromFrame().
192 ** Function to update the locator, with the information extracted from frameInfo
193 */
194 void
195 tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo,
196 TuiLocatorElementPtr element)
197 {
198 struct symtab_and_line symtabAndLine;
199
200 /* now get the new info */
201 symtabAndLine = find_pc_line (frameInfo->pc,
202 (frameInfo->next != (struct frame_info *) NULL &&
203 !frameInfo->next->signal_handler_caller &&
204 !frame_in_dummy (frameInfo->next)));
205 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
206 tuiSetLocatorInfo (symtabAndLine.symtab->filename,
207 tui_get_function_from_frame (frameInfo),
208 symtabAndLine.line,
209 frameInfo->pc,
210 element);
211 else
212 tuiSetLocatorInfo ((char *) NULL,
213 tui_get_function_from_frame (frameInfo),
214 0,
215 frameInfo->pc,
216 element);
217
218 return;
219 } /* tuiUpdateLocatorInfoFromFrame */
220
221
222 /*
223 ** tuiSetLocatorContent().
224 ** Function to set the content of the locator
225 */
226 void
227 tuiSetLocatorContent (struct frame_info *frameInfo)
228 {
229 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
230 TuiWinElementPtr element;
231 struct symtab_and_line symtabAndLine;
232
233 /* Allocate the element if necessary */
234 if (locator->contentSize <= 0)
235 {
236 TuiWinContent contentPtr;
237
238 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
239 error ("Unable to Allocate Memory to Display Location.");
240 locator->contentSize = 1;
241 }
242
243 if (frameInfo != (struct frame_info *) NULL)
244 tuiUpdateLocatorInfoFromFrame (frameInfo,
245 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
246 else
247 tuiSetLocatorInfo ((char *) NULL,
248 (char *) NULL,
249 0,
250 (CORE_ADDR) 0,
251 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
252 return;
253 } /* tuiSetLocatorContent */
254
255 /*
256 ** tuiShowFrameInfo().
257 ** Function to print the frame inforrmation for the TUI.
258 */
259 void
260 tuiShowFrameInfo (struct frame_info *fi)
261 {
262 TuiWinInfoPtr winInfo;
263 register int i;
264
265 if (fi)
266 {
267 register int startLine, i;
268 register struct symtab *s;
269 CORE_ADDR low;
270 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
271 int sourceAlreadyDisplayed;
272
273
274 s = find_pc_symtab (fi->pc);
275 if (s == 0)
276 return;
277
278 startLine = 0;
279 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
280 tuiSetLocatorContent (fi);
281 tuiShowLocatorContent ();
282 for (i = 0; i < (sourceWindows ())->count; i++)
283 {
284 TuiWhichElement *item;
285 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
286
287 item = &((TuiWinElementPtr) locator->content[0])->whichElement;
288 if (winInfo == srcWin)
289 {
290 startLine = (item->locator.lineNo -
291 (winInfo->generic.viewportHeight / 2)) + 1;
292 if (startLine <= 0)
293 startLine = 1;
294 }
295 else
296 {
297 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
298 error ("No function contains program counter for selected frame.\n");
299 else
300 low = tuiGetLowDisassemblyAddress (low, fi->pc);
301 }
302
303 if (winInfo == srcWin)
304 {
305 TuiLineOrAddress l;
306 l.lineNo = startLine;
307 if (!(sourceAlreadyDisplayed
308 && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE)))
309 tuiUpdateSourceWindow (winInfo, s, l, TRUE);
310 else
311 {
312 l.lineNo = item->locator.lineNo;
313 tuiSetIsExecPointAt (l, winInfo);
314 }
315 }
316 else
317 {
318 if (winInfo == disassemWin)
319 {
320 TuiLineOrAddress a;
321 a.addr = low;
322 if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE))
323 tuiUpdateSourceWindow (winInfo, s, a, TRUE);
324 else
325 {
326 a.addr = item->locator.addr;
327 tuiSetIsExecPointAt (a, winInfo);
328 }
329 }
330 }
331 tuiUpdateExecInfo (winInfo);
332 }
333 }
334 else
335 {
336 tuiSetLocatorContent (fi);
337 tuiShowLocatorContent ();
338 for (i = 0; i < (sourceWindows ())->count; i++)
339 {
340 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
341 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
342 tuiUpdateExecInfo (winInfo);
343 }
344 }
345
346 return;
347 } /* tuiShowFrameInfo */
348
349 /* Function to initialize gdb commands, for tui window stack manipulation. */
350 void
351 _initialize_tuiStack (void)
352 {
353 add_com ("update", class_tui, tui_update_command,
354 "Update the source window and locator to display the current "
355 "execution point.\n");
356 }
357
358 /* Command to update the display with the current execution point. */
359 static void
360 tui_update_command (char *arg, int from_tty)
361 {
362 char cmd[sizeof("frame 0")];
363
364 strcpy (cmd, "frame 0");
365 execute_command (cmd, from_tty);
366 }
This page took 0.036836 seconds and 4 git commands to generate.