* tuiStack.c (tuiUpdateLocatorFilename): Use const char*.
[deliverable/binutils-gdb.git] / gdb / tui / tuiStack.c
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. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "breakpoint.h"
25 #include "frame.h"
26 #include "command.h"
27
28 #include "tui.h"
29 #include "tuiData.h"
30 #include "tuiStack.h"
31 #include "tuiGeneralWin.h"
32 #include "tuiSource.h"
33 #include "tuiSourceWin.h"
34
35
36 /*****************************************
37 ** STATIC LOCAL FUNCTIONS FORWARD DECLS **
38 ******************************************/
39
40 static char *_getFuncNameFromFrame (struct frame_info *);
41 static void _tuiUpdateLocation_command (char *, int);
42
43
44
45 /*****************************************
46 ** PUBLIC FUNCTION **
47 ******************************************/
48
49 /*
50 ** tuiClearLocatorDisplay()
51 */
52 void
53 tuiClearLocatorDisplay (void)
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.
62 */
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 /*
79 ** tuiShowLocatorContent()
80 */
81 void
82 tuiShowLocatorContent (void)
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 /* Update the locator, with the provided arguments. */
111 void
112 tuiSetLocatorInfo (char *fname, char *procname, int lineNo,
113 CORE_ADDR addr, TuiLocatorElementPtr element)
114 {
115 element->fileName[0] = (char) 0;
116 element->procName[0] = (char) 0;
117 strcat_to_buf (element->fileName, MAX_LOCATOR_ELEMENT_LEN, fname);
118 strcat_to_buf (element->procName, MAX_LOCATOR_ELEMENT_LEN, procname);
119 element->lineNo = lineNo;
120 element->addr = addr;
121 }
122
123
124 /*
125 ** tuiUpdateLocatorFilename().
126 ** Update only the filename portion of the locator.
127 */
128 void
129 tuiUpdateLocatorFilename (const char *fileName)
130 {
131 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
132
133 if (locator->content[0] == (Opaque) NULL)
134 tuiSetLocatorContent ((struct frame_info *) NULL);
135 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName[0] = (char) 0;
136 strcat_to_buf (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName,
137 MAX_LOCATOR_ELEMENT_LEN,
138 fileName);
139
140 tuiShowLocatorContent ();
141
142 return;
143 } /* tuiUpdateLocatorFilename */
144
145 /*
146 ** tuiSwitchFilename().
147 ** Update the filename portion of the locator. Clear the other info in locator.
148 ** (elz)
149 */
150 void
151 tuiSwitchFilename (char *fileName)
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
159 tuiSetLocatorInfo (fileName,
160 (char *) NULL,
161 0,
162 (CORE_ADDR) 0,
163 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
164
165 tuiShowLocatorContent ();
166
167 return;
168 } /* tuiSwitchFilename */
169
170
171 /*
172 ** tuiGetLocatorFilename().
173 ** Get the filename portion of the locator.
174 ** (elz)
175 */
176 void
177 tuiGetLocatorFilename (TuiGenWinInfoPtr locator, char **filename)
178 {
179
180 /* the current filename could be non known, in which case the xmalloc would
181 allocate no memory, because the length would be 0 */
182 if (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName)
183 {
184 int name_length =
185 strlen (((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
186
187 (*filename) = (char *) xmalloc (name_length + 1);
188 strcpy ((*filename),
189 ((TuiWinElementPtr) locator->content[0])->whichElement.locator.fileName);
190 }
191
192 return;
193 } /* tuiGetLocatorFilename */
194
195
196 /*
197 ** tuiUpdateLocatorInfoFromFrame().
198 ** Function to update the locator, with the information extracted from frameInfo
199 */
200 void
201 tuiUpdateLocatorInfoFromFrame (struct frame_info *frameInfo,
202 TuiLocatorElementPtr element)
203 {
204 struct symtab_and_line symtabAndLine;
205
206 /* now get the new info */
207 symtabAndLine = find_pc_line (frameInfo->pc,
208 (frameInfo->next != (struct frame_info *) NULL &&
209 !frameInfo->next->signal_handler_caller &&
210 !frame_in_dummy (frameInfo->next)));
211 if (symtabAndLine.symtab && symtabAndLine.symtab->filename)
212 tuiSetLocatorInfo (symtabAndLine.symtab->filename,
213 _getFuncNameFromFrame (frameInfo),
214 symtabAndLine.line,
215 frameInfo->pc,
216 element);
217 else
218 tuiSetLocatorInfo ((char *) NULL,
219 _getFuncNameFromFrame (frameInfo),
220 0,
221 frameInfo->pc,
222 element);
223
224 return;
225 } /* tuiUpdateLocatorInfoFromFrame */
226
227
228 /*
229 ** tuiSetLocatorContent().
230 ** Function to set the content of the locator
231 */
232 void
233 tuiSetLocatorContent (struct frame_info *frameInfo)
234 {
235 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
236 TuiWinElementPtr element;
237 struct symtab_and_line symtabAndLine;
238
239 /* Allocate the element if necessary */
240 if (locator->contentSize <= 0)
241 {
242 TuiWinContent contentPtr;
243
244 if ((locator->content = (OpaquePtr) allocContent (1, locator->type)) == (OpaquePtr) NULL)
245 error ("Unable to Allocate Memory to Display Location.");
246 locator->contentSize = 1;
247 }
248
249 if (frameInfo != (struct frame_info *) NULL)
250 tuiUpdateLocatorInfoFromFrame (frameInfo,
251 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
252 else
253 tuiSetLocatorInfo ((char *) NULL,
254 (char *) NULL,
255 0,
256 (CORE_ADDR) 0,
257 &((TuiWinElementPtr) locator->content[0])->whichElement.locator);
258 return;
259 } /* tuiSetLocatorContent */
260
261
262 /*
263 ** tuiUpdateLocatorDisplay().
264 ** Function to update the locator display
265 */
266 void
267 tuiUpdateLocatorDisplay (struct frame_info *frameInfo)
268 {
269 tuiClearLocatorDisplay ();
270 tuiSetLocatorContent (frameInfo);
271 tuiShowLocatorContent ();
272
273 return;
274 } /* tuiUpdateLocatorDisplay */
275
276
277 /*
278 ** tuiShowFrameInfo().
279 ** Function to print the frame inforrmation for the TUI.
280 */
281 void
282 tuiShowFrameInfo (struct frame_info *fi)
283 {
284 TuiWinInfoPtr winInfo;
285 register int i;
286
287 if (fi)
288 {
289 register int startLine, i;
290 register struct symtab *s;
291 CORE_ADDR low;
292 TuiGenWinInfoPtr locator = locatorWinInfoPtr ();
293 int sourceAlreadyDisplayed;
294
295
296 s = find_pc_symtab (fi->pc);
297 if (s == 0)
298 return;
299
300 startLine = 0;
301 sourceAlreadyDisplayed = tuiSourceIsDisplayed (s->filename);
302 tuiUpdateLocatorDisplay (fi);
303 for (i = 0; i < (sourceWindows ())->count; i++)
304 {
305 TuiWhichElement *item;
306 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
307
308 item = &((TuiWinElementPtr) locator->content[0])->whichElement;
309 if (winInfo == srcWin)
310 {
311 startLine = (item->locator.lineNo -
312 (winInfo->generic.viewportHeight / 2)) + 1;
313 if (startLine <= 0)
314 startLine = 1;
315 }
316 else
317 {
318 if (find_pc_partial_function (fi->pc, (char **) NULL, &low, (CORE_ADDR) NULL) == 0)
319 error ("No function contains program counter for selected frame.\n");
320 else
321 low = tuiGetLowDisassemblyAddress (low, fi->pc);
322 }
323
324 if (winInfo == srcWin)
325 {
326 TuiLineOrAddress l;
327 l.lineNo = startLine;
328 if (!(sourceAlreadyDisplayed
329 && tuiLineIsDisplayed (item->locator.lineNo, winInfo, TRUE)))
330 tuiUpdateSourceWindow (winInfo, s, l, TRUE);
331 else
332 {
333 l.lineNo = item->locator.lineNo;
334 tuiSetIsExecPointAt (l, winInfo);
335 }
336 }
337 else
338 {
339 if (winInfo == disassemWin)
340 {
341 TuiLineOrAddress a;
342 a.addr = low;
343 if (!tuiAddrIsDisplayed (item->locator.addr, winInfo, TRUE))
344 tuiUpdateSourceWindow (winInfo, s, a, TRUE);
345 else
346 {
347 a.addr = item->locator.addr;
348 tuiSetIsExecPointAt (a, winInfo);
349 }
350 }
351 }
352 tuiUpdateExecInfo (winInfo);
353 }
354 }
355 else
356 {
357 tuiUpdateLocatorDisplay (fi);
358 for (i = 0; i < (sourceWindows ())->count; i++)
359 {
360 winInfo = (TuiWinInfoPtr) (sourceWindows ())->list[i];
361 tuiClearSourceContent (winInfo, EMPTY_SOURCE_PROMPT);
362 tuiUpdateExecInfo (winInfo);
363 }
364 }
365
366 return;
367 } /* tuiShowFrameInfo */
368
369 /*
370 ** _initialize_tuiStack().
371 ** Function to initialize gdb commands, for tui window stack manipulation.
372 */
373 void
374 _initialize_tuiStack (void)
375 {
376 add_com ("update", class_tui, _tuiUpdateLocation_command,
377 "Update the source window and locator to display the current execution point.\n");
378 }
379
380
381 /*****************************************
382 ** STATIC LOCAL FUNCTIONS **
383 ******************************************/
384
385 /*
386 ** _getFuncNameFromFrame().
387 */
388 static char *
389 _getFuncNameFromFrame (struct frame_info *frameInfo)
390 {
391 char *funcName = (char *) NULL;
392
393 find_pc_partial_function (frameInfo->pc,
394 &funcName,
395 (CORE_ADDR *) NULL,
396 (CORE_ADDR *) NULL);
397 return funcName;
398 } /* _getFuncNameFromFrame */
399
400
401 /*
402 ** _tuiUpdateLocation_command().
403 ** Command to update the display with the current execution point
404 */
405 static void
406 _tuiUpdateLocation_command (char *arg, int fromTTY)
407 {
408 #ifndef TRY
409 extern void frame_command (char *, int);
410 frame_command ("0", FALSE);
411 #else
412 struct frame_info *curFrame;
413
414 /* Obtain the current execution point */
415 if ((curFrame = get_current_frame ()) != (struct frame_info *) NULL)
416 {
417 struct frame_info *frame;
418 int curLevel = 0;
419
420 for (frame = get_prev_frame (curLevel);
421 (frame != (struct frame_info *) NULL && (frame != curFrame));
422 frame = get_prev_frame (frame))
423 curLevel++;
424
425 if (curFrame != (struct frame_info *) NULL)
426 print_frame_info (frame, curLevel, 0, 1);
427 }
428 #endif
429
430 return;
431 } /* _tuiUpdateLocation_command */
This page took 0.099099 seconds and 5 git commands to generate.