* tuiIO.c (CTRL_CHAR): Redefine and use readline 4.3 definition.
[deliverable/binutils-gdb.git] / gdb / tui / tuiStack.c
CommitLineData
f377b406 1/* TUI display locator.
f33c6cbf
AC
2
3 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation,
4 Inc.
5
f377b406
SC
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. */
c906108c 24
f33c6cbf
AC
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
4e8f7a8b
DJ
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
c906108c
SS
42#include "defs.h"
43#include "symtab.h"
44#include "breakpoint.h"
45#include "frame.h"
75fd9bc1 46#include "command.h"
7563e053 47#include "top.h"
c906108c
SS
48
49#include "tui.h"
50#include "tuiData.h"
51#include "tuiStack.h"
75fd9bc1
SC
52#include "tuiGeneralWin.h"
53#include "tuiSource.h"
c906108c 54#include "tuiSourceWin.h"
5564c769 55#include "tui-file.h"
c906108c
SS
56
57
5564c769
SC
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. */
61static char* tui_get_function_from_frame (struct frame_info *fi);
c906108c 62
2e17b763
SC
63/* Set the filename portion of the locator. */
64static void tui_set_locator_filename (const char *filename);
65
66/* Update the locator, with the provided arguments. */
67static void tui_set_locator_info (const char *filename, const char *procname,
7d6dd1e9 68 int lineno, CORE_ADDR addr);
2e17b763 69
7563e053 70static void tui_update_command (char *, int);
7d6dd1e9 71\f
c906108c 72
5564c769
SC
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. */
76static char*
77tui_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}
c906108c 103
c906108c 104/*
c5aa993b
JM
105 ** tuiShowLocatorContent()
106 */
c906108c 107void
c906108c 108tuiShowLocatorContent (void)
c906108c
SS
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);
3a42771a 123 wclrtoeol (locator->handle);
c906108c
SS
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
2e17b763
SC
136/* Set the filename portion of the locator. */
137static void
138tui_set_locator_filename (const char *filename)
139{
140 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
141 TuiLocatorElementPtr element;
142
143 if (locator->content[0] == (Opaque) NULL)
7d6dd1e9
SC
144 {
145 tui_set_locator_info (filename, NULL, 0, 0);
146 return;
147 }
2e17b763
SC
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}
c906108c 153
c7c228ed 154/* Update the locator, with the provided arguments. */
2e17b763
SC
155static void
156tui_set_locator_info (const char *filename, const char *procname, int lineno,
7d6dd1e9 157 CORE_ADDR addr)
c906108c 158{
7d6dd1e9
SC
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;
c906108c 170 element->procName[0] = (char) 0;
c906108c 171 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
2e17b763 172 element->lineNo = lineno;
c774cec6 173 element->addr = addr;
2e17b763 174 tui_set_locator_filename (filename);
c7c228ed 175}
c906108c 176
2e17b763 177/* Update only the filename portion of the locator. */
c906108c 178void
2e17b763 179tuiUpdateLocatorFilename (const char *filename)
c906108c 180{
2e17b763 181 tui_set_locator_filename (filename);
c906108c 182 tuiShowLocatorContent ();
2e17b763 183}
c906108c 184
7d6dd1e9 185/* Function to print the frame information for the TUI. */
c906108c 186void
eca6576c 187tuiShowFrameInfo (struct frame_info *fi)
c906108c
SS
188{
189 TuiWinInfoPtr winInfo;
190 register int i;
191
192 if (fi)
193 {
194 register int startLine, i;
c906108c
SS
195 CORE_ADDR low;
196 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
197 int sourceAlreadyDisplayed;
7d6dd1e9
SC
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);
d059f789 211 tuiShowLocatorContent ();
7d6dd1e9 212 startLine = 0;
c906108c
SS
213 for (i = 0; i < (sourceWindows ())->count; i++)
214 {
a4b99e53 215 TuiWhichElement *item;
c906108c 216 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
a4b99e53
SC
217
218 item = &((TuiWinElementPtr) locator->content[0])->whichElement;
c906108c
SS
219 if (winInfo == srcWin)
220 {
a4b99e53
SC
221 startLine = (item->locator.lineNo -
222 (winInfo->generic.viewportHeight / 2)) + 1;
c906108c
SS
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
c774cec6 231 low = tuiGetLowDisassemblyAddress (low, fi->pc);
c906108c
SS
232 }
233
234 if (winInfo == srcWin)
235 {
a4b99e53
SC
236 TuiLineOrAddress l;
237 l.lineNo = startLine;
238 if (!(sourceAlreadyDisplayed
239 && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE)))
7d6dd1e9 240 tuiUpdateSourceWindow (winInfo, sal.symtab, l, TRUE);
c906108c 241 else
a4b99e53
SC
242 {
243 l.lineNo = item->locator.lineNo;
244 tuiSetIsExecPointAt (l, winInfo);
245 }
c906108c
SS
246 }
247 else
248 {
249 if (winInfo == disassemWin)
250 {
a4b99e53
SC
251 TuiLineOrAddress a;
252 a.addr = low;
253 if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE))
7d6dd1e9 254 tuiUpdateSourceWindow (winInfo, sal.symtab, a, TRUE);
c906108c 255 else
a4b99e53
SC
256 {
257 a.addr = item->locator.addr;
258 tuiSetIsExecPointAt (a, winInfo);
259 }
c906108c
SS
260 }
261 }
262 tuiUpdateExecInfo (winInfo);
263 }
264 }
265 else
266 {
7d6dd1e9 267 tui_set_locator_info (NULL, NULL, 0, (CORE_ADDR) 0);
d059f789 268 tuiShowLocatorContent ();
c906108c
SS
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 }
7d6dd1e9 276}
c906108c 277
7563e053 278/* Function to initialize gdb commands, for tui window stack manipulation. */
c906108c 279void
fba45db2 280_initialize_tuiStack (void)
c906108c 281{
7563e053
SC
282 add_com ("update", class_tui, tui_update_command,
283 "Update the source window and locator to display the current "
284 "execution point.\n");
41783295 285}
c906108c 286
7563e053 287/* Command to update the display with the current execution point. */
c906108c 288static void
7563e053 289tui_update_command (char *arg, int from_tty)
c906108c 290{
7563e053 291 char cmd[sizeof("frame 0")];
c906108c 292
7563e053
SC
293 strcpy (cmd, "frame 0");
294 execute_command (cmd, from_tty);
295}
This page took 0.266413 seconds and 4 git commands to generate.