24ccf157b163571a530714d5b7af4073863d1517
[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 /* Set the filename portion of the locator. */
64 static void tui_set_locator_filename (const char *filename);
65
66 /* Update the locator, with the provided arguments. */
67 static void tui_set_locator_info (const char *filename, const char *procname,
68 int lineno, CORE_ADDR addr,
69 TuiLocatorElementPtr element);
70
71 static void tui_update_command (char *, int);
72
73 /* Function to set the content of the locator. */
74 static void tuiSetLocatorContent (struct frame_info *frameInfo);
75
76 /* Get a printable name for the function at the address.
77 The symbol name is demangled if demangling is turned on.
78 Returns a pointer to a static area holding the result. */
79 static char*
80 tui_get_function_from_frame (struct frame_info *fi)
81 {
82 static char name[256];
83 struct ui_file *stream = tui_sfileopen (256);
84 char *p;
85
86 print_address_symbolic (fi->pc, stream, demangle, "");
87 p = tui_file_get_strbuf (stream);
88
89 /* Use simple heuristics to isolate the function name. The symbol can
90 be demangled and we can have function parameters. Remove them because
91 the status line is too short to display them. */
92 if (*p == '<')
93 p++;
94 strncpy (name, p, sizeof (name));
95 p = strchr (name, '(');
96 if (!p)
97 p = strchr (name, '>');
98 if (p)
99 *p = 0;
100 p = strchr (name, '+');
101 if (p)
102 *p = 0;
103 ui_file_delete (stream);
104 return name;
105 }
106
107 /*
108 ** tuiShowLocatorContent()
109 */
110 void
111 tuiShowLocatorContent (void)
112 {
113 char *string;
114 TuiGenWinInfoPtr locator;
115
116 locator = locatorWinInfoPtr ();
117
118 if (m_genWinPtrNotNull (locator) && locator->handle != (WINDOW *) NULL)
119 {
120 string = displayableWinContentAt (locator, 0);
121 if (string != (char *) NULL)
122 {
123 wmove (locator->handle, 0, 0);
124 wstandout (locator->handle);
125 waddstr (locator->handle, string);
126 wclrtoeol (locator->handle);
127 wstandend (locator->handle);
128 tuiRefreshWin (locator);
129 wmove (locator->handle, 0, 0);
130 if (string != nullStr ())
131 tuiFree (string);
132 locator->contentInUse = TRUE;
133 }
134 }
135
136 return;
137 } /* tuiShowLocatorContent */
138
139 /* Set the filename portion of the locator. */
140 static void
141 tui_set_locator_filename (const char *filename)
142 {
143 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
144 TuiLocatorElementPtr element;
145
146 if (locator->content[0] == (Opaque) NULL)
147 tuiSetLocatorContent ((struct frame_info *) NULL);
148
149 element = &((TuiWinElementPtr) locator->content[0])->whichElement.locator;
150 element->fileName[0] = 0;
151 strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, filename);
152 }
153
154 /* Update the locator, with the provided arguments. */
155 static void
156 tui_set_locator_info (const char *filename, const char *procname, int lineno,
157 CORE_ADDR addr, TuiLocatorElementPtr element)
158 {
159 element->procName[0] = (char) 0;
160 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
161 element->lineNo = lineno;
162 element->addr = addr;
163 tui_set_locator_filename (filename);
164 }
165
166
167 /* Update only the filename portion of the locator. */
168 void
169 tuiUpdateLocatorFilename (const char *filename)
170 {
171 tui_set_locator_filename (filename);
172 tuiShowLocatorContent ();
173 }
174
175 /*
176 ** tuiUpdateLocatorInfoFromFrame().
177 ** Function to update the locator, with the information extracted from frameInfo
178 */
179 static void
180 tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo,
181 TuiLocatorElementPtr element)
182 {
183 struct symtab_and_line symtabAndLine;
184
185 /* now get the new info */
186 symtabAndLine = find_pc_line (frameInfo->pc,
187 (frameInfo->next != (struct frame_info *) NULL &&
188 !frameInfo->next->signal_handler_caller &&
189 !frame_in_dummy (frameInfo->next)));
190 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
191 tui_set_locator_info (symtabAndLine.symtab->filename,
192 tui_get_function_from_frame (frameInfo),
193 symtabAndLine.line,
194 frameInfo->pc,
195 element);
196 else
197 tui_set_locator_info ((char *) NULL,
198 tui_get_function_from_frame (frameInfo),
199 0,
200 frameInfo->pc,
201 element);
202
203 return;
204 } /* tuiUpdateLocatorInfoFromFrame */
205
206
207 /* Function to set the content of the locator. */
208 static void
209 tuiSetLocatorContent (struct frame_info *frameInfo)
210 {
211 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
212 TuiWinElementPtr element;
213 struct symtab_and_line symtabAndLine;
214
215 /* Allocate the element if necessary */
216 if (locator->contentSize <= 0)
217 {
218 TuiWinContent contentPtr;
219
220 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
221 error ("Unable to Allocate Memory to Display Location.");
222 locator->contentSize = 1;
223 }
224
225 if (frameInfo != (struct frame_info *) NULL)
226 tuiUpdateLocatorInfoFromFrame (frameInfo,
227 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
228 else
229 tui_set_locator_info ((char *) NULL,
230 (char *) NULL,
231 0,
232 (CORE_ADDR) 0,
233 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
234 return;
235 } /* tuiSetLocatorContent */
236
237 /*
238 ** tuiShowFrameInfo().
239 ** Function to print the frame inforrmation for the TUI.
240 */
241 void
242 tuiShowFrameInfo (struct frame_info *fi)
243 {
244 TuiWinInfoPtr winInfo;
245 register int i;
246
247 if (fi)
248 {
249 register int startLine, i;
250 register struct symtab *s;
251 CORE_ADDR low;
252 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
253 int sourceAlreadyDisplayed;
254
255
256 s = find_pc_symtab (fi->pc);
257 if (s == 0)
258 return;
259
260 startLine = 0;
261 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
262 tuiSetLocatorContent (fi);
263 tuiShowLocatorContent ();
264 for (i = 0; i < (sourceWindows ())->count; i++)
265 {
266 TuiWhichElement *item;
267 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
268
269 item = &((TuiWinElementPtr) locator->content[0])->whichElement;
270 if (winInfo == srcWin)
271 {
272 startLine = (item->locator.lineNo -
273 (winInfo->generic.viewportHeight / 2)) + 1;
274 if (startLine <= 0)
275 startLine = 1;
276 }
277 else
278 {
279 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
280 error ("No function contains program counter for selected frame.\n");
281 else
282 low = tuiGetLowDisassemblyAddress (low, fi->pc);
283 }
284
285 if (winInfo == srcWin)
286 {
287 TuiLineOrAddress l;
288 l.lineNo = startLine;
289 if (!(sourceAlreadyDisplayed
290 && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE)))
291 tuiUpdateSourceWindow (winInfo, s, l, TRUE);
292 else
293 {
294 l.lineNo = item->locator.lineNo;
295 tuiSetIsExecPointAt (l, winInfo);
296 }
297 }
298 else
299 {
300 if (winInfo == disassemWin)
301 {
302 TuiLineOrAddress a;
303 a.addr = low;
304 if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE))
305 tuiUpdateSourceWindow (winInfo, s, a, TRUE);
306 else
307 {
308 a.addr = item->locator.addr;
309 tuiSetIsExecPointAt (a, winInfo);
310 }
311 }
312 }
313 tuiUpdateExecInfo (winInfo);
314 }
315 }
316 else
317 {
318 tuiSetLocatorContent (fi);
319 tuiShowLocatorContent ();
320 for (i = 0; i < (sourceWindows ())->count; i++)
321 {
322 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
323 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
324 tuiUpdateExecInfo (winInfo);
325 }
326 }
327
328 return;
329 } /* tuiShowFrameInfo */
330
331 /* Function to initialize gdb commands, for tui window stack manipulation. */
332 void
333 _initialize_tuiStack (void)
334 {
335 add_com ("update", class_tui, tui_update_command,
336 "Update the source window and locator to display the current "
337 "execution point.\n");
338 }
339
340 /* Command to update the display with the current execution point. */
341 static void
342 tui_update_command (char *arg, int from_tty)
343 {
344 char cmd[sizeof("frame 0")];
345
346 strcpy (cmd, "frame 0");
347 execute_command (cmd, from_tty);
348 }
This page took 0.044721 seconds and 4 git commands to generate.