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