1e93f7393Sniklas /* Print and select stack frames for GDB, the GNU debugger.
2b725ae77Skettenis
3b725ae77Skettenis Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4b725ae77Skettenis 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
5b725ae77Skettenis Software Foundation, Inc.
6e93f7393Sniklas
7e93f7393Sniklas This file is part of GDB.
8e93f7393Sniklas
9e93f7393Sniklas This program is free software; you can redistribute it and/or modify
10e93f7393Sniklas it under the terms of the GNU General Public License as published by
11e93f7393Sniklas the Free Software Foundation; either version 2 of the License, or
12e93f7393Sniklas (at your option) any later version.
13e93f7393Sniklas
14e93f7393Sniklas This program is distributed in the hope that it will be useful,
15e93f7393Sniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
16e93f7393Sniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17e93f7393Sniklas GNU General Public License for more details.
18e93f7393Sniklas
19e93f7393Sniklas You should have received a copy of the GNU General Public License
20e93f7393Sniklas along with this program; if not, write to the Free Software
21b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
22b725ae77Skettenis Boston, MA 02111-1307, USA. */
23e93f7393Sniklas
24b725ae77Skettenis #include <ctype.h>
25e93f7393Sniklas #include "defs.h"
26e93f7393Sniklas #include "gdb_string.h"
27e93f7393Sniklas #include "value.h"
28e93f7393Sniklas #include "symtab.h"
29e93f7393Sniklas #include "gdbtypes.h"
30e93f7393Sniklas #include "expression.h"
31e93f7393Sniklas #include "language.h"
32e93f7393Sniklas #include "frame.h"
33e93f7393Sniklas #include "gdbcmd.h"
34e93f7393Sniklas #include "gdbcore.h"
35e93f7393Sniklas #include "target.h"
36b725ae77Skettenis #include "source.h"
37e93f7393Sniklas #include "breakpoint.h"
38e93f7393Sniklas #include "demangle.h"
39e93f7393Sniklas #include "inferior.h"
40e93f7393Sniklas #include "annotate.h"
41b725ae77Skettenis #include "ui-out.h"
42b725ae77Skettenis #include "block.h"
43b725ae77Skettenis #include "stack.h"
44b725ae77Skettenis #include "gdb_assert.h"
45b725ae77Skettenis #include "dictionary.h"
46b725ae77Skettenis #include "reggroups.h"
47b725ae77Skettenis #include "regcache.h"
48e93f7393Sniklas
49b725ae77Skettenis /* Prototypes for exported functions. */
50e93f7393Sniklas
51b725ae77Skettenis void args_info (char *, int);
52e93f7393Sniklas
53b725ae77Skettenis void locals_info (char *, int);
54e93f7393Sniklas
55*63addd46Skettenis void (*deprecated_selected_frame_level_changed_hook) (int);
56e93f7393Sniklas
57b725ae77Skettenis void _initialize_stack (void);
58e93f7393Sniklas
59b725ae77Skettenis /* Prototypes for local functions. */
60e93f7393Sniklas
61b725ae77Skettenis static void down_command (char *, int);
62e93f7393Sniklas
63b725ae77Skettenis static void down_silently_base (char *);
64e93f7393Sniklas
65b725ae77Skettenis static void down_silently_command (char *, int);
66e93f7393Sniklas
67b725ae77Skettenis static void up_command (char *, int);
68e93f7393Sniklas
69b725ae77Skettenis static void up_silently_base (char *);
70e93f7393Sniklas
71b725ae77Skettenis static void up_silently_command (char *, int);
72e93f7393Sniklas
73b725ae77Skettenis void frame_command (char *, int);
74e93f7393Sniklas
75b725ae77Skettenis static void current_frame_command (char *, int);
76e93f7393Sniklas
77b725ae77Skettenis static void print_frame_arg_vars (struct frame_info *, struct ui_file *);
78b725ae77Skettenis
79b725ae77Skettenis static void catch_info (char *, int);
80b725ae77Skettenis
81b725ae77Skettenis static void args_plus_locals_info (char *, int);
82b725ae77Skettenis
83b725ae77Skettenis static void print_frame_label_vars (struct frame_info *, int,
84b725ae77Skettenis struct ui_file *);
85b725ae77Skettenis
86b725ae77Skettenis static void print_frame_local_vars (struct frame_info *, int,
87b725ae77Skettenis struct ui_file *);
88b725ae77Skettenis
89b725ae77Skettenis static int print_block_frame_labels (struct block *, int *,
90b725ae77Skettenis struct ui_file *);
91b725ae77Skettenis
92b725ae77Skettenis static int print_block_frame_locals (struct block *,
93e93f7393Sniklas struct frame_info *,
94b725ae77Skettenis int,
95b725ae77Skettenis struct ui_file *);
96e93f7393Sniklas
97b725ae77Skettenis static void print_frame (struct frame_info *fi,
98*63addd46Skettenis int print_level,
99*63addd46Skettenis enum print_what print_what,
100*63addd46Skettenis int print_args,
101b725ae77Skettenis struct symtab_and_line sal);
102e93f7393Sniklas
103b725ae77Skettenis static void backtrace_command (char *, int);
104e93f7393Sniklas
105b725ae77Skettenis struct frame_info *parse_frame_specification (char *);
106b725ae77Skettenis
107b725ae77Skettenis static void frame_info (char *, int);
108e93f7393Sniklas
109e93f7393Sniklas extern int addressprint; /* Print addresses, or stay symbolic only? */
110e93f7393Sniklas
111e93f7393Sniklas /* Zero means do things normally; we are interacting directly with the
112e93f7393Sniklas user. One means print the full filename and linenumber when a
113e93f7393Sniklas frame is printed, and do so in a format emacs18/emacs19.22 can
114e93f7393Sniklas parse. Two means print similar annotations, but in many more
115e93f7393Sniklas cases and in a slightly different syntax. */
116e93f7393Sniklas
117e93f7393Sniklas int annotation_level = 0;
118e93f7393Sniklas
119b725ae77Skettenis
120b725ae77Skettenis struct print_stack_frame_args
121b725ae77Skettenis {
122e93f7393Sniklas struct frame_info *fi;
123*63addd46Skettenis int print_level;
124*63addd46Skettenis enum print_what print_what;
125*63addd46Skettenis int print_args;
126e93f7393Sniklas };
127e93f7393Sniklas
128b725ae77Skettenis /* Show or print the frame arguments.
129b725ae77Skettenis Pass the args the way catch_errors wants them. */
130e93f7393Sniklas static int
print_stack_frame_stub(void * args)131b725ae77Skettenis print_stack_frame_stub (void *args)
132e93f7393Sniklas {
133e93f7393Sniklas struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
134e93f7393Sniklas
135*63addd46Skettenis print_frame_info (p->fi, p->print_level, p->print_what, p->print_args);
136e93f7393Sniklas return 0;
137e93f7393Sniklas }
138e93f7393Sniklas
139*63addd46Skettenis /* Show or print a stack frame FI briefly. The output is format
140*63addd46Skettenis according to PRINT_LEVEL and PRINT_WHAT printing the frame's
141*63addd46Skettenis relative level, function name, argument list, and file name and
142*63addd46Skettenis line number. If the frame's PC is not at the beginning of the
143*63addd46Skettenis source line, the actual PC is printed at the beginning. */
144e93f7393Sniklas
145e93f7393Sniklas void
print_stack_frame(struct frame_info * fi,int print_level,enum print_what print_what)146*63addd46Skettenis print_stack_frame (struct frame_info *fi, int print_level,
147*63addd46Skettenis enum print_what print_what)
148e93f7393Sniklas {
149e93f7393Sniklas struct print_stack_frame_args args;
150e93f7393Sniklas
151e93f7393Sniklas args.fi = fi;
152*63addd46Skettenis args.print_level = print_level;
153*63addd46Skettenis args.print_what = print_what;
154*63addd46Skettenis args.print_args = 1;
155e93f7393Sniklas
156e93f7393Sniklas catch_errors (print_stack_frame_stub, (char *) &args, "", RETURN_MASK_ALL);
157e93f7393Sniklas }
158e93f7393Sniklas
159b725ae77Skettenis struct print_args_args
160b725ae77Skettenis {
161e93f7393Sniklas struct symbol *func;
162e93f7393Sniklas struct frame_info *fi;
163b725ae77Skettenis struct ui_file *stream;
164e93f7393Sniklas };
165e93f7393Sniklas
166b725ae77Skettenis static int print_args_stub (void *);
167b725ae77Skettenis
168b725ae77Skettenis /* Print nameless args on STREAM.
169b725ae77Skettenis FI is the frameinfo for this frame, START is the offset
170b725ae77Skettenis of the first nameless arg, and NUM is the number of nameless args to
171b725ae77Skettenis print. FIRST is nonzero if this is the first argument (not just
172b725ae77Skettenis the first nameless arg). */
173b725ae77Skettenis
174b725ae77Skettenis static void
print_frame_nameless_args(struct frame_info * fi,long start,int num,int first,struct ui_file * stream)175b725ae77Skettenis print_frame_nameless_args (struct frame_info *fi, long start, int num,
176b725ae77Skettenis int first, struct ui_file *stream)
177b725ae77Skettenis {
178b725ae77Skettenis int i;
179b725ae77Skettenis CORE_ADDR argsaddr;
180b725ae77Skettenis long arg_value;
181b725ae77Skettenis
182b725ae77Skettenis for (i = 0; i < num; i++)
183b725ae77Skettenis {
184b725ae77Skettenis QUIT;
185b725ae77Skettenis argsaddr = get_frame_args_address (fi);
186b725ae77Skettenis if (!argsaddr)
187b725ae77Skettenis return;
188b725ae77Skettenis arg_value = read_memory_integer (argsaddr + start, sizeof (int));
189b725ae77Skettenis if (!first)
190b725ae77Skettenis fprintf_filtered (stream, ", ");
191b725ae77Skettenis fprintf_filtered (stream, "%ld", arg_value);
192b725ae77Skettenis first = 0;
193b725ae77Skettenis start += sizeof (int);
194b725ae77Skettenis }
195b725ae77Skettenis }
196b725ae77Skettenis
197b725ae77Skettenis /* Print the arguments of a stack frame, given the function FUNC
198b725ae77Skettenis running in that frame (as a symbol), the info on the frame,
199b725ae77Skettenis and the number of args according to the stack frame (or -1 if unknown). */
200b725ae77Skettenis
201b725ae77Skettenis /* References here and elsewhere to "number of args according to the
202b725ae77Skettenis stack frame" appear in all cases to refer to "number of ints of args
203b725ae77Skettenis according to the stack frame". At least for VAX, i386, isi. */
204b725ae77Skettenis
205b725ae77Skettenis static void
print_frame_args(struct symbol * func,struct frame_info * fi,int num,struct ui_file * stream)206b725ae77Skettenis print_frame_args (struct symbol *func, struct frame_info *fi, int num,
207b725ae77Skettenis struct ui_file *stream)
208b725ae77Skettenis {
209b725ae77Skettenis struct block *b = NULL;
210b725ae77Skettenis int first = 1;
211b725ae77Skettenis struct dict_iterator iter;
212b725ae77Skettenis struct symbol *sym;
213b725ae77Skettenis struct value *val;
214b725ae77Skettenis /* Offset of next stack argument beyond the one we have seen that is
215b725ae77Skettenis at the highest offset.
216b725ae77Skettenis -1 if we haven't come to a stack argument yet. */
217b725ae77Skettenis long highest_offset = -1;
218b725ae77Skettenis int arg_size;
219b725ae77Skettenis /* Number of ints of arguments that we have printed so far. */
220b725ae77Skettenis int args_printed = 0;
221b725ae77Skettenis struct cleanup *old_chain, *list_chain;
222b725ae77Skettenis struct ui_stream *stb;
223b725ae77Skettenis
224b725ae77Skettenis stb = ui_out_stream_new (uiout);
225b725ae77Skettenis old_chain = make_cleanup_ui_out_stream_delete (stb);
226b725ae77Skettenis
227b725ae77Skettenis if (func)
228b725ae77Skettenis {
229b725ae77Skettenis b = SYMBOL_BLOCK_VALUE (func);
230b725ae77Skettenis
231b725ae77Skettenis ALL_BLOCK_SYMBOLS (b, iter, sym)
232b725ae77Skettenis {
233b725ae77Skettenis QUIT;
234b725ae77Skettenis
235b725ae77Skettenis /* Keep track of the highest stack argument offset seen, and
236b725ae77Skettenis skip over any kinds of symbols we don't care about. */
237b725ae77Skettenis
238b725ae77Skettenis switch (SYMBOL_CLASS (sym))
239b725ae77Skettenis {
240b725ae77Skettenis case LOC_ARG:
241b725ae77Skettenis case LOC_REF_ARG:
242b725ae77Skettenis {
243b725ae77Skettenis long current_offset = SYMBOL_VALUE (sym);
244b725ae77Skettenis arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
245b725ae77Skettenis
246b725ae77Skettenis /* Compute address of next argument by adding the size of
247b725ae77Skettenis this argument and rounding to an int boundary. */
248b725ae77Skettenis current_offset =
249b725ae77Skettenis ((current_offset + arg_size + sizeof (int) - 1)
250b725ae77Skettenis & ~(sizeof (int) - 1));
251b725ae77Skettenis
252b725ae77Skettenis /* If this is the highest offset seen yet, set highest_offset. */
253b725ae77Skettenis if (highest_offset == -1
254b725ae77Skettenis || (current_offset > highest_offset))
255b725ae77Skettenis highest_offset = current_offset;
256b725ae77Skettenis
257b725ae77Skettenis /* Add the number of ints we're about to print to args_printed. */
258b725ae77Skettenis args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
259b725ae77Skettenis }
260b725ae77Skettenis
261b725ae77Skettenis /* We care about types of symbols, but don't need to keep track of
262b725ae77Skettenis stack offsets in them. */
263b725ae77Skettenis case LOC_REGPARM:
264b725ae77Skettenis case LOC_REGPARM_ADDR:
265b725ae77Skettenis case LOC_LOCAL_ARG:
266b725ae77Skettenis case LOC_BASEREG_ARG:
267b725ae77Skettenis case LOC_COMPUTED_ARG:
268b725ae77Skettenis break;
269b725ae77Skettenis
270b725ae77Skettenis /* Other types of symbols we just skip over. */
271b725ae77Skettenis default:
272b725ae77Skettenis continue;
273b725ae77Skettenis }
274b725ae77Skettenis
275b725ae77Skettenis /* We have to look up the symbol because arguments can have
276b725ae77Skettenis two entries (one a parameter, one a local) and the one we
277b725ae77Skettenis want is the local, which lookup_symbol will find for us.
278b725ae77Skettenis This includes gcc1 (not gcc2) on the sparc when passing a
279b725ae77Skettenis small structure and gcc2 when the argument type is float
280b725ae77Skettenis and it is passed as a double and converted to float by
281b725ae77Skettenis the prologue (in the latter case the type of the LOC_ARG
282b725ae77Skettenis symbol is double and the type of the LOC_LOCAL symbol is
283b725ae77Skettenis float). */
284b725ae77Skettenis /* But if the parameter name is null, don't try it.
285b725ae77Skettenis Null parameter names occur on the RS/6000, for traceback tables.
286b725ae77Skettenis FIXME, should we even print them? */
287b725ae77Skettenis
288b725ae77Skettenis if (*DEPRECATED_SYMBOL_NAME (sym))
289b725ae77Skettenis {
290b725ae77Skettenis struct symbol *nsym;
291b725ae77Skettenis nsym = lookup_symbol
292b725ae77Skettenis (DEPRECATED_SYMBOL_NAME (sym),
293b725ae77Skettenis b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL);
294b725ae77Skettenis if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
295b725ae77Skettenis {
296b725ae77Skettenis /* There is a LOC_ARG/LOC_REGISTER pair. This means that
297b725ae77Skettenis it was passed on the stack and loaded into a register,
298b725ae77Skettenis or passed in a register and stored in a stack slot.
299b725ae77Skettenis GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
300b725ae77Skettenis
301b725ae77Skettenis Reasons for using the LOC_ARG:
302b725ae77Skettenis (1) because find_saved_registers may be slow for remote
303b725ae77Skettenis debugging,
304b725ae77Skettenis (2) because registers are often re-used and stack slots
305b725ae77Skettenis rarely (never?) are. Therefore using the stack slot is
306b725ae77Skettenis much less likely to print garbage.
307b725ae77Skettenis
308b725ae77Skettenis Reasons why we might want to use the LOC_REGISTER:
309b725ae77Skettenis (1) So that the backtrace prints the same value as
310b725ae77Skettenis "print foo". I see no compelling reason why this needs
311b725ae77Skettenis to be the case; having the backtrace print the value which
312b725ae77Skettenis was passed in, and "print foo" print the value as modified
313b725ae77Skettenis within the called function, makes perfect sense to me.
314b725ae77Skettenis
315b725ae77Skettenis Additional note: It might be nice if "info args" displayed
316b725ae77Skettenis both values.
317b725ae77Skettenis One more note: There is a case with sparc structure passing
318b725ae77Skettenis where we need to use the LOC_REGISTER, but this is dealt with
319b725ae77Skettenis by creating a single LOC_REGPARM in symbol reading. */
320b725ae77Skettenis
321b725ae77Skettenis /* Leave sym (the LOC_ARG) alone. */
322b725ae77Skettenis ;
323b725ae77Skettenis }
324b725ae77Skettenis else
325b725ae77Skettenis sym = nsym;
326b725ae77Skettenis }
327b725ae77Skettenis
328b725ae77Skettenis /* Print the current arg. */
329b725ae77Skettenis if (!first)
330b725ae77Skettenis ui_out_text (uiout, ", ");
331b725ae77Skettenis ui_out_wrap_hint (uiout, " ");
332b725ae77Skettenis
333b725ae77Skettenis annotate_arg_begin ();
334b725ae77Skettenis
335b725ae77Skettenis list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
336b725ae77Skettenis fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (sym),
337b725ae77Skettenis SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
338b725ae77Skettenis ui_out_field_stream (uiout, "name", stb);
339b725ae77Skettenis annotate_arg_name_end ();
340b725ae77Skettenis ui_out_text (uiout, "=");
341b725ae77Skettenis
342b725ae77Skettenis /* Avoid value_print because it will deref ref parameters. We just
343b725ae77Skettenis want to print their addresses. Print ??? for args whose address
344b725ae77Skettenis we do not know. We pass 2 as "recurse" to val_print because our
345b725ae77Skettenis standard indentation here is 4 spaces, and val_print indents
346b725ae77Skettenis 2 for each recurse. */
347b725ae77Skettenis val = read_var_value (sym, fi);
348b725ae77Skettenis
349b725ae77Skettenis annotate_arg_value (val == NULL ? NULL : VALUE_TYPE (val));
350b725ae77Skettenis
351b725ae77Skettenis if (val)
352b725ae77Skettenis {
353b725ae77Skettenis val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
354b725ae77Skettenis VALUE_ADDRESS (val),
355b725ae77Skettenis stb->stream, 0, 0, 2, Val_no_prettyprint);
356b725ae77Skettenis ui_out_field_stream (uiout, "value", stb);
357b725ae77Skettenis }
358b725ae77Skettenis else
359b725ae77Skettenis ui_out_text (uiout, "???");
360b725ae77Skettenis
361b725ae77Skettenis /* Invoke ui_out_tuple_end. */
362b725ae77Skettenis do_cleanups (list_chain);
363b725ae77Skettenis
364b725ae77Skettenis annotate_arg_end ();
365b725ae77Skettenis
366b725ae77Skettenis first = 0;
367b725ae77Skettenis }
368b725ae77Skettenis }
369b725ae77Skettenis
370b725ae77Skettenis /* Don't print nameless args in situations where we don't know
371b725ae77Skettenis enough about the stack to find them. */
372b725ae77Skettenis if (num != -1)
373b725ae77Skettenis {
374b725ae77Skettenis long start;
375b725ae77Skettenis
376b725ae77Skettenis if (highest_offset == -1)
377b725ae77Skettenis start = FRAME_ARGS_SKIP;
378b725ae77Skettenis else
379b725ae77Skettenis start = highest_offset;
380b725ae77Skettenis
381b725ae77Skettenis print_frame_nameless_args (fi, start, num - args_printed,
382b725ae77Skettenis first, stream);
383b725ae77Skettenis }
384b725ae77Skettenis do_cleanups (old_chain);
385b725ae77Skettenis }
386e93f7393Sniklas
387e93f7393Sniklas /* Pass the args the way catch_errors wants them. */
388e93f7393Sniklas
389e93f7393Sniklas static int
print_args_stub(void * args)390b725ae77Skettenis print_args_stub (void *args)
391e93f7393Sniklas {
392e93f7393Sniklas int numargs;
393e93f7393Sniklas struct print_args_args *p = (struct print_args_args *) args;
394e93f7393Sniklas
395b725ae77Skettenis if (FRAME_NUM_ARGS_P ())
396b725ae77Skettenis {
397b725ae77Skettenis numargs = FRAME_NUM_ARGS (p->fi);
398b725ae77Skettenis gdb_assert (numargs >= 0);
399b725ae77Skettenis }
400b725ae77Skettenis else
401b725ae77Skettenis numargs = -1;
402b725ae77Skettenis print_frame_args (p->func, p->fi, numargs, p->stream);
403e93f7393Sniklas return 0;
404e93f7393Sniklas }
405e93f7393Sniklas
406b725ae77Skettenis /* Print information about a frame for frame "fi" at level "level".
407b725ae77Skettenis Used in "where" output, also used to emit breakpoint or step
408b725ae77Skettenis messages.
409b725ae77Skettenis LEVEL is the level of the frame, or -1 if it is the
410b725ae77Skettenis innermost frame but we don't want to print the level.
411b725ae77Skettenis The meaning of the SOURCE argument is:
412b725ae77Skettenis SRC_LINE: Print only source line
413b725ae77Skettenis LOCATION: Print only location
414b725ae77Skettenis LOC_AND_SRC: Print location and source line. */
415e93f7393Sniklas
416e93f7393Sniklas void
print_frame_info(struct frame_info * fi,int print_level,enum print_what print_what,int print_args)417*63addd46Skettenis print_frame_info (struct frame_info *fi, int print_level,
418*63addd46Skettenis enum print_what print_what, int print_args)
419e93f7393Sniklas {
420e93f7393Sniklas struct symtab_and_line sal;
421b725ae77Skettenis int source_print;
422b725ae77Skettenis int location_print;
423e93f7393Sniklas
424b725ae77Skettenis if (get_frame_type (fi) == DUMMY_FRAME
425b725ae77Skettenis || get_frame_type (fi) == SIGTRAMP_FRAME)
426e93f7393Sniklas {
427b725ae77Skettenis struct cleanup *uiout_cleanup
428b725ae77Skettenis = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
429b725ae77Skettenis
430*63addd46Skettenis annotate_frame_begin (print_level ? frame_relative_level (fi) : 0,
431*63addd46Skettenis get_frame_pc (fi));
432e93f7393Sniklas
433e93f7393Sniklas /* Do this regardless of SOURCE because we don't have any source
434e93f7393Sniklas to list for this frame. */
435*63addd46Skettenis if (print_level)
436b725ae77Skettenis {
437b725ae77Skettenis ui_out_text (uiout, "#");
438*63addd46Skettenis ui_out_field_fmt_int (uiout, 2, ui_left, "level",
439*63addd46Skettenis frame_relative_level (fi));
440e93f7393Sniklas }
441b725ae77Skettenis if (ui_out_is_mi_like_p (uiout))
442e93f7393Sniklas {
443b725ae77Skettenis annotate_frame_address ();
444b725ae77Skettenis ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
445b725ae77Skettenis annotate_frame_address_end ();
446b725ae77Skettenis }
447e93f7393Sniklas
448b725ae77Skettenis if (get_frame_type (fi) == DUMMY_FRAME)
449b725ae77Skettenis {
450b725ae77Skettenis annotate_function_call ();
451b725ae77Skettenis ui_out_field_string (uiout, "func", "<function called from gdb>");
452b725ae77Skettenis }
453b725ae77Skettenis else if (get_frame_type (fi) == SIGTRAMP_FRAME)
454b725ae77Skettenis {
455e93f7393Sniklas annotate_signal_handler_caller ();
456b725ae77Skettenis ui_out_field_string (uiout, "func", "<signal handler called>");
457b725ae77Skettenis }
458b725ae77Skettenis ui_out_text (uiout, "\n");
459e93f7393Sniklas annotate_frame_end ();
460b725ae77Skettenis
461b725ae77Skettenis do_cleanups (uiout_cleanup);
462e93f7393Sniklas return;
463e93f7393Sniklas }
464e93f7393Sniklas
465e93f7393Sniklas /* If fi is not the innermost frame, that normally means that fi->pc
466b725ae77Skettenis points to *after* the call instruction, and we want to get the
467b725ae77Skettenis line containing the call, never the next line. But if the next
468b725ae77Skettenis frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
469b725ae77Skettenis was not entered as the result of a call, and we want to get the
470b725ae77Skettenis line containing fi->pc. */
471b725ae77Skettenis find_frame_sal (fi, &sal);
472e93f7393Sniklas
473*63addd46Skettenis location_print = (print_what == LOCATION
474*63addd46Skettenis || print_what == LOC_AND_ADDRESS
475*63addd46Skettenis || print_what == SRC_AND_LOC);
476b725ae77Skettenis
477b725ae77Skettenis if (location_print || !sal.symtab)
478*63addd46Skettenis print_frame (fi, print_level, print_what, print_args, sal);
479b725ae77Skettenis
480*63addd46Skettenis source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
481b725ae77Skettenis
482b725ae77Skettenis if (sal.symtab)
483b725ae77Skettenis set_current_source_symtab_and_line (&sal);
484b725ae77Skettenis
485b725ae77Skettenis if (source_print && sal.symtab)
486b725ae77Skettenis {
487b725ae77Skettenis struct symtab_and_line cursal;
488b725ae77Skettenis int done = 0;
489*63addd46Skettenis int mid_statement = ((print_what == SRC_LINE)
490*63addd46Skettenis && (get_frame_pc (fi) != sal.pc));
491b725ae77Skettenis
492b725ae77Skettenis if (annotation_level)
493b725ae77Skettenis done = identify_source_line (sal.symtab, sal.line, mid_statement,
494b725ae77Skettenis get_frame_pc (fi));
495b725ae77Skettenis if (!done)
496b725ae77Skettenis {
497*63addd46Skettenis if (deprecated_print_frame_info_listing_hook)
498*63addd46Skettenis deprecated_print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0);
499b725ae77Skettenis else
500b725ae77Skettenis {
501b725ae77Skettenis /* We used to do this earlier, but that is clearly
502b725ae77Skettenis wrong. This function is used by many different
503b725ae77Skettenis parts of gdb, including normal_stop in infrun.c,
504b725ae77Skettenis which uses this to print out the current PC
505b725ae77Skettenis when we stepi/nexti into the middle of a source
506b725ae77Skettenis line. Only the command line really wants this
507b725ae77Skettenis behavior. Other UIs probably would like the
508b725ae77Skettenis ability to decide for themselves if it is desired. */
509b725ae77Skettenis if (addressprint && mid_statement)
510b725ae77Skettenis {
511b725ae77Skettenis ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
512b725ae77Skettenis ui_out_text (uiout, "\t");
513b725ae77Skettenis }
514b725ae77Skettenis
515b725ae77Skettenis print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
516b725ae77Skettenis }
517b725ae77Skettenis }
518b725ae77Skettenis /* Make sure we have at least a default source file */
519b725ae77Skettenis set_default_source_symtab_and_line ();
520b725ae77Skettenis cursal = get_current_source_symtab_and_line ();
521b725ae77Skettenis cursal.line = max (sal.line - get_lines_to_list () / 2, 1);
522b725ae77Skettenis set_current_source_symtab_and_line (&cursal);
523b725ae77Skettenis }
524b725ae77Skettenis
525*63addd46Skettenis if (print_what != LOCATION)
526b725ae77Skettenis set_default_breakpoint (1, get_frame_pc (fi), sal.symtab, sal.line);
527b725ae77Skettenis
528b725ae77Skettenis annotate_frame_end ();
529b725ae77Skettenis
530b725ae77Skettenis gdb_flush (gdb_stdout);
531b725ae77Skettenis }
532b725ae77Skettenis
533b725ae77Skettenis static void
print_frame(struct frame_info * fi,int print_level,enum print_what print_what,int print_args,struct symtab_and_line sal)534b725ae77Skettenis print_frame (struct frame_info *fi,
535*63addd46Skettenis int print_level,
536*63addd46Skettenis enum print_what print_what,
537*63addd46Skettenis int print_args,
538b725ae77Skettenis struct symtab_and_line sal)
539b725ae77Skettenis {
540b725ae77Skettenis struct symbol *func;
541b725ae77Skettenis char *funname = 0;
542b725ae77Skettenis enum language funlang = language_unknown;
543b725ae77Skettenis struct ui_stream *stb;
544b725ae77Skettenis struct cleanup *old_chain;
545b725ae77Skettenis struct cleanup *list_chain;
546b725ae77Skettenis
547b725ae77Skettenis stb = ui_out_stream_new (uiout);
548b725ae77Skettenis old_chain = make_cleanup_ui_out_stream_delete (stb);
549b725ae77Skettenis
550b725ae77Skettenis func = find_pc_function (get_frame_address_in_block (fi));
551e93f7393Sniklas if (func)
552e93f7393Sniklas {
553e93f7393Sniklas /* In certain pathological cases, the symtabs give the wrong
554e93f7393Sniklas function (when we are in the first function in a file which
555e93f7393Sniklas is compiled without debugging symbols, the previous function
556e93f7393Sniklas is compiled with debugging symbols, and the "foo.o" symbol
557e93f7393Sniklas that is supposed to tell us where the file with debugging symbols
558e93f7393Sniklas ends has been truncated by ar because it is longer than 15
559e93f7393Sniklas characters). This also occurs if the user uses asm() to create
560e93f7393Sniklas a function but not stabs for it (in a file compiled -g).
561e93f7393Sniklas
562e93f7393Sniklas So look in the minimal symbol tables as well, and if it comes
563e93f7393Sniklas up with a larger address for the function use that instead.
564e93f7393Sniklas I don't think this can ever cause any problems; there shouldn't
565e93f7393Sniklas be any minimal symbols in the middle of a function; if this is
566e93f7393Sniklas ever changed many parts of GDB will need to be changed (and we'll
567e93f7393Sniklas create a find_pc_minimal_function or some such). */
568e93f7393Sniklas
569b725ae77Skettenis struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi));
570e93f7393Sniklas if (msymbol != NULL
571e93f7393Sniklas && (SYMBOL_VALUE_ADDRESS (msymbol)
572e93f7393Sniklas > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
573e93f7393Sniklas {
574e93f7393Sniklas /* We also don't know anything about the function besides
575e93f7393Sniklas its address and name. */
576e93f7393Sniklas func = 0;
577b725ae77Skettenis funname = DEPRECATED_SYMBOL_NAME (msymbol);
578e93f7393Sniklas funlang = SYMBOL_LANGUAGE (msymbol);
579e93f7393Sniklas }
580e93f7393Sniklas else
581e93f7393Sniklas {
582b725ae77Skettenis /* I'd like to use SYMBOL_PRINT_NAME() here, to display the
583b725ae77Skettenis demangled name that we already have stored in the symbol
584b725ae77Skettenis table, but we stored a version with DMGL_PARAMS turned
585b725ae77Skettenis on, and here we don't want to display parameters. So call
586b725ae77Skettenis the demangler again, with DMGL_ANSI only. (Yes, I know
587b725ae77Skettenis that printf_symbol_filtered() will again try to demangle
588b725ae77Skettenis the name on the fly, but the issue is that if
589b725ae77Skettenis cplus_demangle() fails here, it'll fail there too. So we
590b725ae77Skettenis want to catch the failure ("demangled==NULL" case below)
591b725ae77Skettenis here, while we still have our hands on the function
592b725ae77Skettenis symbol.) */
593b725ae77Skettenis char *demangled;
594b725ae77Skettenis funname = DEPRECATED_SYMBOL_NAME (func);
595e93f7393Sniklas funlang = SYMBOL_LANGUAGE (func);
596b725ae77Skettenis if (funlang == language_cplus)
597b725ae77Skettenis {
598b725ae77Skettenis demangled = cplus_demangle (funname, DMGL_ANSI);
599b725ae77Skettenis if (demangled == NULL)
600b725ae77Skettenis /* If the demangler fails, try the demangled name from
601b725ae77Skettenis the symbol table. This'll have parameters, but
602b725ae77Skettenis that's preferable to diplaying a mangled name. */
603b725ae77Skettenis funname = SYMBOL_PRINT_NAME (func);
604b725ae77Skettenis }
605e93f7393Sniklas }
606e93f7393Sniklas }
607e93f7393Sniklas else
608e93f7393Sniklas {
609b725ae77Skettenis struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi));
610e93f7393Sniklas if (msymbol != NULL)
611e93f7393Sniklas {
612b725ae77Skettenis funname = DEPRECATED_SYMBOL_NAME (msymbol);
613e93f7393Sniklas funlang = SYMBOL_LANGUAGE (msymbol);
614e93f7393Sniklas }
615e93f7393Sniklas }
616e93f7393Sniklas
617*63addd46Skettenis annotate_frame_begin (print_level ? frame_relative_level (fi) : 0,
618*63addd46Skettenis get_frame_pc (fi));
619b725ae77Skettenis
620b725ae77Skettenis list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
621e93f7393Sniklas
622*63addd46Skettenis if (print_level)
623b725ae77Skettenis {
624b725ae77Skettenis ui_out_text (uiout, "#");
625*63addd46Skettenis ui_out_field_fmt_int (uiout, 2, ui_left, "level",
626*63addd46Skettenis frame_relative_level (fi));
627b725ae77Skettenis }
628e93f7393Sniklas if (addressprint)
629b725ae77Skettenis if (get_frame_pc (fi) != sal.pc
630b725ae77Skettenis || !sal.symtab
631*63addd46Skettenis || print_what == LOC_AND_ADDRESS)
632e93f7393Sniklas {
633e93f7393Sniklas annotate_frame_address ();
634b725ae77Skettenis ui_out_field_core_addr (uiout, "addr", get_frame_pc (fi));
635e93f7393Sniklas annotate_frame_address_end ();
636b725ae77Skettenis ui_out_text (uiout, " in ");
637e93f7393Sniklas }
638e93f7393Sniklas annotate_frame_function_name ();
639b725ae77Skettenis fprintf_symbol_filtered (stb->stream, funname ? funname : "??", funlang,
640e93f7393Sniklas DMGL_ANSI);
641b725ae77Skettenis ui_out_field_stream (uiout, "func", stb);
642b725ae77Skettenis ui_out_wrap_hint (uiout, " ");
643e93f7393Sniklas annotate_frame_args ();
644b725ae77Skettenis
645b725ae77Skettenis ui_out_text (uiout, " (");
646*63addd46Skettenis if (print_args)
647e93f7393Sniklas {
648e93f7393Sniklas struct print_args_args args;
649b725ae77Skettenis struct cleanup *args_list_chain;
650e93f7393Sniklas args.fi = fi;
651e93f7393Sniklas args.func = func;
652b725ae77Skettenis args.stream = gdb_stdout;
653b725ae77Skettenis args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
654b725ae77Skettenis catch_errors (print_args_stub, &args, "", RETURN_MASK_ALL);
655b725ae77Skettenis /* FIXME: args must be a list. If one argument is a string it will
656b725ae77Skettenis have " that will not be properly escaped. */
657b725ae77Skettenis /* Invoke ui_out_tuple_end. */
658b725ae77Skettenis do_cleanups (args_list_chain);
659e93f7393Sniklas QUIT;
660e93f7393Sniklas }
661b725ae77Skettenis ui_out_text (uiout, ")");
662e93f7393Sniklas if (sal.symtab && sal.symtab->filename)
663e93f7393Sniklas {
664e93f7393Sniklas annotate_frame_source_begin ();
665b725ae77Skettenis ui_out_wrap_hint (uiout, " ");
666b725ae77Skettenis ui_out_text (uiout, " at ");
667e93f7393Sniklas annotate_frame_source_file ();
668b725ae77Skettenis ui_out_field_string (uiout, "file", sal.symtab->filename);
669e93f7393Sniklas annotate_frame_source_file_end ();
670b725ae77Skettenis ui_out_text (uiout, ":");
671e93f7393Sniklas annotate_frame_source_line ();
672b725ae77Skettenis ui_out_field_int (uiout, "line", sal.line);
673e93f7393Sniklas annotate_frame_source_end ();
674e93f7393Sniklas }
675e93f7393Sniklas
676e93f7393Sniklas #ifdef PC_SOLIB
677b725ae77Skettenis if (!funname || (!sal.symtab || !sal.symtab->filename))
678e93f7393Sniklas {
679b725ae77Skettenis char *lib = PC_SOLIB (get_frame_pc (fi));
680e93f7393Sniklas if (lib)
681e93f7393Sniklas {
682e93f7393Sniklas annotate_frame_where ();
683b725ae77Skettenis ui_out_wrap_hint (uiout, " ");
684b725ae77Skettenis ui_out_text (uiout, " from ");
685b725ae77Skettenis ui_out_field_string (uiout, "from", lib);
686e93f7393Sniklas }
687e93f7393Sniklas }
688b725ae77Skettenis #endif /* PC_SOLIB */
689e93f7393Sniklas
690b725ae77Skettenis /* do_cleanups will call ui_out_tuple_end() for us. */
691b725ae77Skettenis do_cleanups (list_chain);
692b725ae77Skettenis ui_out_text (uiout, "\n");
693b725ae77Skettenis do_cleanups (old_chain);
694b725ae77Skettenis }
695b725ae77Skettenis
696b725ae77Skettenis /* Show the frame info. If this is the tui, it will be shown in
697b725ae77Skettenis the source display otherwise, nothing is done */
698b725ae77Skettenis void
show_stack_frame(struct frame_info * fi)699b725ae77Skettenis show_stack_frame (struct frame_info *fi)
700e93f7393Sniklas {
701e93f7393Sniklas }
702b725ae77Skettenis
703e93f7393Sniklas
704e93f7393Sniklas /* Read a frame specification in whatever the appropriate format is.
705e93f7393Sniklas Call error() if the specification is in any way invalid (i.e.
706e93f7393Sniklas this function never returns NULL). */
707e93f7393Sniklas
708b725ae77Skettenis struct frame_info *
parse_frame_specification(char * frame_exp)709b725ae77Skettenis parse_frame_specification (char *frame_exp)
710e93f7393Sniklas {
711e93f7393Sniklas int numargs = 0;
712e93f7393Sniklas #define MAXARGS 4
713e93f7393Sniklas CORE_ADDR args[MAXARGS];
714b725ae77Skettenis int level;
715e93f7393Sniklas
716e93f7393Sniklas if (frame_exp)
717e93f7393Sniklas {
718e93f7393Sniklas char *addr_string, *p;
719e93f7393Sniklas struct cleanup *tmp_cleanup;
720e93f7393Sniklas
721b725ae77Skettenis while (*frame_exp == ' ')
722b725ae77Skettenis frame_exp++;
723e93f7393Sniklas
724e93f7393Sniklas while (*frame_exp)
725e93f7393Sniklas {
726e93f7393Sniklas if (numargs > MAXARGS)
727e93f7393Sniklas error ("Too many args in frame specification");
728e93f7393Sniklas /* Parse an argument. */
729e93f7393Sniklas for (p = frame_exp; *p && *p != ' '; p++)
730e93f7393Sniklas ;
731e93f7393Sniklas addr_string = savestring (frame_exp, p - frame_exp);
732e93f7393Sniklas
733e93f7393Sniklas {
734b725ae77Skettenis struct value *vp;
735b725ae77Skettenis
736b725ae77Skettenis tmp_cleanup = make_cleanup (xfree, addr_string);
737b725ae77Skettenis
738b725ae77Skettenis /* NOTE: we call parse_and_eval and then both
739b725ae77Skettenis value_as_long and value_as_address rather than calling
740b725ae77Skettenis parse_and_eval_long and parse_and_eval_address because
741b725ae77Skettenis of the issue of potential side effects from evaluating
742b725ae77Skettenis the expression. */
743b725ae77Skettenis vp = parse_and_eval (addr_string);
744b725ae77Skettenis if (numargs == 0)
745b725ae77Skettenis level = value_as_long (vp);
746b725ae77Skettenis
747b725ae77Skettenis args[numargs++] = value_as_address (vp);
748e93f7393Sniklas do_cleanups (tmp_cleanup);
749e93f7393Sniklas }
750e93f7393Sniklas
751e93f7393Sniklas /* Skip spaces, move to possible next arg. */
752b725ae77Skettenis while (*p == ' ')
753b725ae77Skettenis p++;
754e93f7393Sniklas frame_exp = p;
755e93f7393Sniklas }
756e93f7393Sniklas }
757e93f7393Sniklas
758e93f7393Sniklas switch (numargs)
759e93f7393Sniklas {
760e93f7393Sniklas case 0:
761b725ae77Skettenis if (deprecated_selected_frame == NULL)
762e93f7393Sniklas error ("No selected frame.");
763b725ae77Skettenis return deprecated_selected_frame;
764e93f7393Sniklas /* NOTREACHED */
765e93f7393Sniklas case 1:
766e93f7393Sniklas {
767e93f7393Sniklas struct frame_info *fid =
768e93f7393Sniklas find_relative_frame (get_current_frame (), &level);
769e93f7393Sniklas struct frame_info *tfid;
770e93f7393Sniklas
771e93f7393Sniklas if (level == 0)
772e93f7393Sniklas /* find_relative_frame was successful */
773e93f7393Sniklas return fid;
774e93f7393Sniklas
775e93f7393Sniklas /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
776e93f7393Sniklas take at least 2 addresses. It is important to detect this case
777e93f7393Sniklas here so that "frame 100" does not give a confusing error message
778e93f7393Sniklas like "frame specification requires two addresses". This of course
779e93f7393Sniklas does not solve the "frame 100" problem for machines on which
780e93f7393Sniklas a frame specification can be made with one address. To solve
781e93f7393Sniklas that, we need a new syntax for a specifying a frame by address.
782e93f7393Sniklas I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
783e93f7393Sniklas two args, etc.), but people might think that is too much typing,
784e93f7393Sniklas so I guess *0x23,0x45 would be a possible alternative (commas
785e93f7393Sniklas really should be used instead of spaces to delimit; using spaces
786e93f7393Sniklas normally works in an expression). */
787e93f7393Sniklas #ifdef SETUP_ARBITRARY_FRAME
788b725ae77Skettenis error ("No frame %s", paddr_d (args[0]));
789e93f7393Sniklas #endif
790e93f7393Sniklas
791e93f7393Sniklas /* If (s)he specifies the frame with an address, he deserves what
792e93f7393Sniklas (s)he gets. Still, give the highest one that matches. */
793e93f7393Sniklas
794e93f7393Sniklas for (fid = get_current_frame ();
795b725ae77Skettenis fid && get_frame_base (fid) != args[0];
796e93f7393Sniklas fid = get_prev_frame (fid))
797e93f7393Sniklas ;
798e93f7393Sniklas
799e93f7393Sniklas if (fid)
800e93f7393Sniklas while ((tfid = get_prev_frame (fid)) &&
801b725ae77Skettenis (get_frame_base (tfid) == args[0]))
802e93f7393Sniklas fid = tfid;
803e93f7393Sniklas
804e93f7393Sniklas /* We couldn't identify the frame as an existing frame, but
805e93f7393Sniklas perhaps we can create one with a single argument. */
806e93f7393Sniklas }
807e93f7393Sniklas
808e93f7393Sniklas default:
809e93f7393Sniklas #ifdef SETUP_ARBITRARY_FRAME
810e93f7393Sniklas return SETUP_ARBITRARY_FRAME (numargs, args);
811e93f7393Sniklas #else
812e93f7393Sniklas /* Usual case. Do it here rather than have everyone supply
813e93f7393Sniklas a SETUP_ARBITRARY_FRAME that does this. */
814e93f7393Sniklas if (numargs == 1)
815e93f7393Sniklas return create_new_frame (args[0], 0);
816e93f7393Sniklas error ("Too many args in frame specification");
817e93f7393Sniklas #endif
818e93f7393Sniklas /* NOTREACHED */
819e93f7393Sniklas }
820e93f7393Sniklas /* NOTREACHED */
821e93f7393Sniklas }
822e93f7393Sniklas
823e93f7393Sniklas /* Print verbosely the selected frame or the frame at address ADDR.
824e93f7393Sniklas This means absolutely all information in the frame is printed. */
825e93f7393Sniklas
826e93f7393Sniklas static void
frame_info(char * addr_exp,int from_tty)827b725ae77Skettenis frame_info (char *addr_exp, int from_tty)
828e93f7393Sniklas {
829e93f7393Sniklas struct frame_info *fi;
830e93f7393Sniklas struct symtab_and_line sal;
831e93f7393Sniklas struct symbol *func;
832e93f7393Sniklas struct symtab *s;
833e93f7393Sniklas struct frame_info *calling_frame_info;
834e93f7393Sniklas int i, count, numregs;
835e93f7393Sniklas char *funname = 0;
836e93f7393Sniklas enum language funlang = language_unknown;
837b725ae77Skettenis const char *pc_regname;
838e93f7393Sniklas
839e93f7393Sniklas if (!target_has_stack)
840e93f7393Sniklas error ("No stack.");
841e93f7393Sniklas
842b725ae77Skettenis /* Name of the value returned by get_frame_pc(). Per comments, "pc"
843b725ae77Skettenis is not a good name. */
844b725ae77Skettenis if (PC_REGNUM >= 0)
845b725ae77Skettenis /* OK, this is weird. The PC_REGNUM hardware register's value can
846b725ae77Skettenis easily not match that of the internal value returned by
847b725ae77Skettenis get_frame_pc(). */
848b725ae77Skettenis pc_regname = REGISTER_NAME (PC_REGNUM);
849b725ae77Skettenis else
850b725ae77Skettenis /* But then, this is weird to. Even without PC_REGNUM, an
851b725ae77Skettenis architectures will often have a hardware register called "pc",
852b725ae77Skettenis and that register's value, again, can easily not match
853b725ae77Skettenis get_frame_pc(). */
854b725ae77Skettenis pc_regname = "pc";
855b725ae77Skettenis
856e93f7393Sniklas fi = parse_frame_specification (addr_exp);
857e93f7393Sniklas if (fi == NULL)
858e93f7393Sniklas error ("Invalid frame specified.");
859e93f7393Sniklas
860b725ae77Skettenis find_frame_sal (fi, &sal);
861e93f7393Sniklas func = get_frame_function (fi);
862b725ae77Skettenis /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
863b725ae77Skettenis the same value. */
864b725ae77Skettenis s = find_pc_symtab (get_frame_pc (fi));
865e93f7393Sniklas if (func)
866e93f7393Sniklas {
867b725ae77Skettenis /* I'd like to use SYMBOL_PRINT_NAME() here, to display
868b725ae77Skettenis * the demangled name that we already have stored in
869b725ae77Skettenis * the symbol table, but we stored a version with
870b725ae77Skettenis * DMGL_PARAMS turned on, and here we don't want
871b725ae77Skettenis * to display parameters. So call the demangler again,
872b725ae77Skettenis * with DMGL_ANSI only. RT
873b725ae77Skettenis * (Yes, I know that printf_symbol_filtered() will
874b725ae77Skettenis * again try to demangle the name on the fly, but
875b725ae77Skettenis * the issue is that if cplus_demangle() fails here,
876b725ae77Skettenis * it'll fail there too. So we want to catch the failure
877b725ae77Skettenis * ("demangled==NULL" case below) here, while we still
878b725ae77Skettenis * have our hands on the function symbol.)
879b725ae77Skettenis */
880b725ae77Skettenis char *demangled;
881b725ae77Skettenis funname = DEPRECATED_SYMBOL_NAME (func);
882e93f7393Sniklas funlang = SYMBOL_LANGUAGE (func);
883b725ae77Skettenis if (funlang == language_cplus)
884b725ae77Skettenis {
885b725ae77Skettenis demangled = cplus_demangle (funname, DMGL_ANSI);
886b725ae77Skettenis /* If the demangler fails, try the demangled name
887b725ae77Skettenis * from the symbol table. This'll have parameters,
888b725ae77Skettenis * but that's preferable to diplaying a mangled name.
889b725ae77Skettenis */
890b725ae77Skettenis if (demangled == NULL)
891b725ae77Skettenis funname = SYMBOL_PRINT_NAME (func);
892b725ae77Skettenis }
893e93f7393Sniklas }
894e93f7393Sniklas else
895e93f7393Sniklas {
896b725ae77Skettenis struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (get_frame_pc (fi));
897e93f7393Sniklas if (msymbol != NULL)
898e93f7393Sniklas {
899b725ae77Skettenis funname = DEPRECATED_SYMBOL_NAME (msymbol);
900e93f7393Sniklas funlang = SYMBOL_LANGUAGE (msymbol);
901e93f7393Sniklas }
902e93f7393Sniklas }
903e93f7393Sniklas calling_frame_info = get_prev_frame (fi);
904e93f7393Sniklas
905b725ae77Skettenis if (!addr_exp && frame_relative_level (deprecated_selected_frame) >= 0)
906e93f7393Sniklas {
907b725ae77Skettenis printf_filtered ("Stack level %d, frame at ",
908b725ae77Skettenis frame_relative_level (deprecated_selected_frame));
909b725ae77Skettenis print_address_numeric (get_frame_base (fi), 1, gdb_stdout);
910e93f7393Sniklas printf_filtered (":\n");
911e93f7393Sniklas }
912e93f7393Sniklas else
913e93f7393Sniklas {
914e93f7393Sniklas printf_filtered ("Stack frame at ");
915b725ae77Skettenis print_address_numeric (get_frame_base (fi), 1, gdb_stdout);
916e93f7393Sniklas printf_filtered (":\n");
917e93f7393Sniklas }
918b725ae77Skettenis printf_filtered (" %s = ", pc_regname);
919b725ae77Skettenis print_address_numeric (get_frame_pc (fi), 1, gdb_stdout);
920e93f7393Sniklas
921e93f7393Sniklas wrap_here (" ");
922e93f7393Sniklas if (funname)
923e93f7393Sniklas {
924e93f7393Sniklas printf_filtered (" in ");
925e93f7393Sniklas fprintf_symbol_filtered (gdb_stdout, funname, funlang,
926e93f7393Sniklas DMGL_ANSI | DMGL_PARAMS);
927e93f7393Sniklas }
928e93f7393Sniklas wrap_here (" ");
929e93f7393Sniklas if (sal.symtab)
930e93f7393Sniklas printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
931e93f7393Sniklas puts_filtered ("; ");
932e93f7393Sniklas wrap_here (" ");
933b725ae77Skettenis printf_filtered ("saved %s ", pc_regname);
934b725ae77Skettenis print_address_numeric (frame_pc_unwind (fi), 1, gdb_stdout);
935e93f7393Sniklas printf_filtered ("\n");
936e93f7393Sniklas
937e93f7393Sniklas if (calling_frame_info)
938e93f7393Sniklas {
939e93f7393Sniklas printf_filtered (" called by frame at ");
940b725ae77Skettenis print_address_numeric (get_frame_base (calling_frame_info),
941b725ae77Skettenis 1, gdb_stdout);
942e93f7393Sniklas }
943b725ae77Skettenis if (get_next_frame (fi) && calling_frame_info)
944e93f7393Sniklas puts_filtered (",");
945e93f7393Sniklas wrap_here (" ");
946b725ae77Skettenis if (get_next_frame (fi))
947e93f7393Sniklas {
948e93f7393Sniklas printf_filtered (" caller of frame at ");
949b725ae77Skettenis print_address_numeric (get_frame_base (get_next_frame (fi)), 1,
950b725ae77Skettenis gdb_stdout);
951e93f7393Sniklas }
952b725ae77Skettenis if (get_next_frame (fi) || calling_frame_info)
953e93f7393Sniklas puts_filtered ("\n");
954e93f7393Sniklas if (s)
955b725ae77Skettenis printf_filtered (" source language %s.\n",
956b725ae77Skettenis language_str (s->language));
957e93f7393Sniklas
958e93f7393Sniklas {
959e93f7393Sniklas /* Address of the argument list for this frame, or 0. */
960b725ae77Skettenis CORE_ADDR arg_list = get_frame_args_address (fi);
961e93f7393Sniklas /* Number of args for this frame, or -1 if unknown. */
962e93f7393Sniklas int numargs;
963e93f7393Sniklas
964e93f7393Sniklas if (arg_list == 0)
965e93f7393Sniklas printf_filtered (" Arglist at unknown address.\n");
966e93f7393Sniklas else
967e93f7393Sniklas {
968e93f7393Sniklas printf_filtered (" Arglist at ");
969e93f7393Sniklas print_address_numeric (arg_list, 1, gdb_stdout);
970e93f7393Sniklas printf_filtered (",");
971e93f7393Sniklas
972b725ae77Skettenis if (!FRAME_NUM_ARGS_P ())
973b725ae77Skettenis {
974b725ae77Skettenis numargs = -1;
975e93f7393Sniklas puts_filtered (" args: ");
976b725ae77Skettenis }
977b725ae77Skettenis else
978b725ae77Skettenis {
979b725ae77Skettenis numargs = FRAME_NUM_ARGS (fi);
980b725ae77Skettenis gdb_assert (numargs >= 0);
981b725ae77Skettenis if (numargs == 0)
982e93f7393Sniklas puts_filtered (" no args.");
983e93f7393Sniklas else if (numargs == 1)
984e93f7393Sniklas puts_filtered (" 1 arg: ");
985e93f7393Sniklas else
986e93f7393Sniklas printf_filtered (" %d args: ", numargs);
987b725ae77Skettenis }
988e93f7393Sniklas print_frame_args (func, fi, numargs, gdb_stdout);
989e93f7393Sniklas puts_filtered ("\n");
990e93f7393Sniklas }
991e93f7393Sniklas }
992e93f7393Sniklas {
993e93f7393Sniklas /* Address of the local variables for this frame, or 0. */
994b725ae77Skettenis CORE_ADDR arg_list = get_frame_locals_address (fi);
995e93f7393Sniklas
996e93f7393Sniklas if (arg_list == 0)
997e93f7393Sniklas printf_filtered (" Locals at unknown address,");
998e93f7393Sniklas else
999e93f7393Sniklas {
1000e93f7393Sniklas printf_filtered (" Locals at ");
1001e93f7393Sniklas print_address_numeric (arg_list, 1, gdb_stdout);
1002e93f7393Sniklas printf_filtered (",");
1003e93f7393Sniklas }
1004e93f7393Sniklas }
1005e93f7393Sniklas
1006b725ae77Skettenis /* Print as much information as possible on the location of all the
1007b725ae77Skettenis registers. */
1008b725ae77Skettenis {
1009b725ae77Skettenis enum lval_type lval;
1010b725ae77Skettenis int optimized;
1011b725ae77Skettenis CORE_ADDR addr;
1012b725ae77Skettenis int realnum;
1013b725ae77Skettenis int count;
1014b725ae77Skettenis int i;
1015b725ae77Skettenis int need_nl = 1;
1016b725ae77Skettenis
1017b725ae77Skettenis /* The sp is special; what's displayed isn't the save address, but
1018b725ae77Skettenis the value of the previous frame's sp. This is a legacy thing,
1019b725ae77Skettenis at one stage the frame cached the previous frame's SP instead
1020b725ae77Skettenis of its address, hence it was easiest to just display the cached
1021b725ae77Skettenis value. */
1022b725ae77Skettenis if (SP_REGNUM >= 0)
1023b725ae77Skettenis {
1024b725ae77Skettenis /* Find out the location of the saved stack pointer with out
1025b725ae77Skettenis actually evaluating it. */
1026b725ae77Skettenis frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr,
1027b725ae77Skettenis &realnum, NULL);
1028b725ae77Skettenis if (!optimized && lval == not_lval)
1029b725ae77Skettenis {
1030b725ae77Skettenis char value[MAX_REGISTER_SIZE];
1031b725ae77Skettenis CORE_ADDR sp;
1032b725ae77Skettenis frame_register_unwind (fi, SP_REGNUM, &optimized, &lval, &addr,
1033b725ae77Skettenis &realnum, value);
1034b725ae77Skettenis /* NOTE: cagney/2003-05-22: This is assuming that the
1035b725ae77Skettenis stack pointer was packed as an unsigned integer. That
1036b725ae77Skettenis may or may not be valid. */
1037*63addd46Skettenis sp = extract_unsigned_integer (value, register_size (current_gdbarch, SP_REGNUM));
1038e93f7393Sniklas printf_filtered (" Previous frame's sp is ");
1039b725ae77Skettenis print_address_numeric (sp, 1, gdb_stdout);
1040e93f7393Sniklas printf_filtered ("\n");
1041b725ae77Skettenis need_nl = 0;
1042b725ae77Skettenis }
1043b725ae77Skettenis else if (!optimized && lval == lval_memory)
1044b725ae77Skettenis {
1045b725ae77Skettenis printf_filtered (" Previous frame's sp at ");
1046b725ae77Skettenis print_address_numeric (addr, 1, gdb_stdout);
1047b725ae77Skettenis printf_filtered ("\n");
1048b725ae77Skettenis need_nl = 0;
1049b725ae77Skettenis }
1050b725ae77Skettenis else if (!optimized && lval == lval_register)
1051b725ae77Skettenis {
1052b725ae77Skettenis printf_filtered (" Previous frame's sp in %s\n",
1053b725ae77Skettenis REGISTER_NAME (realnum));
1054b725ae77Skettenis need_nl = 0;
1055b725ae77Skettenis }
1056b725ae77Skettenis /* else keep quiet. */
1057b725ae77Skettenis }
1058b725ae77Skettenis
1059e93f7393Sniklas count = 0;
1060b725ae77Skettenis numregs = NUM_REGS + NUM_PSEUDO_REGS;
1061e93f7393Sniklas for (i = 0; i < numregs; i++)
1062b725ae77Skettenis if (i != SP_REGNUM
1063b725ae77Skettenis && gdbarch_register_reggroup_p (current_gdbarch, i, all_reggroup))
1064b725ae77Skettenis {
1065b725ae77Skettenis /* Find out the location of the saved register without
1066b725ae77Skettenis fetching the corresponding value. */
1067b725ae77Skettenis frame_register_unwind (fi, i, &optimized, &lval, &addr, &realnum,
1068b725ae77Skettenis NULL);
1069b725ae77Skettenis /* For moment, only display registers that were saved on the
1070b725ae77Skettenis stack. */
1071b725ae77Skettenis if (!optimized && lval == lval_memory)
1072e93f7393Sniklas {
1073e93f7393Sniklas if (count == 0)
1074e93f7393Sniklas puts_filtered (" Saved registers:\n ");
1075e93f7393Sniklas else
1076e93f7393Sniklas puts_filtered (",");
1077e93f7393Sniklas wrap_here (" ");
1078b725ae77Skettenis printf_filtered (" %s at ", REGISTER_NAME (i));
1079b725ae77Skettenis print_address_numeric (addr, 1, gdb_stdout);
1080e93f7393Sniklas count++;
1081e93f7393Sniklas }
1082b725ae77Skettenis }
1083b725ae77Skettenis if (count || need_nl)
1084e93f7393Sniklas puts_filtered ("\n");
1085b725ae77Skettenis }
1086e93f7393Sniklas }
1087e93f7393Sniklas
1088e93f7393Sniklas /* Print briefly all stack frames or just the innermost COUNT frames. */
1089e93f7393Sniklas
1090b725ae77Skettenis static void backtrace_command_1 (char *count_exp, int show_locals,
1091b725ae77Skettenis int from_tty);
1092e93f7393Sniklas static void
backtrace_command_1(char * count_exp,int show_locals,int from_tty)1093b725ae77Skettenis backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
1094e93f7393Sniklas {
1095e93f7393Sniklas struct frame_info *fi;
1096b725ae77Skettenis int count;
1097b725ae77Skettenis int i;
1098b725ae77Skettenis struct frame_info *trailing;
1099b725ae77Skettenis int trailing_level;
1100e93f7393Sniklas
1101e93f7393Sniklas if (!target_has_stack)
1102e93f7393Sniklas error ("No stack.");
1103e93f7393Sniklas
1104e93f7393Sniklas /* The following code must do two things. First, it must
1105e93f7393Sniklas set the variable TRAILING to the frame from which we should start
1106e93f7393Sniklas printing. Second, it must set the variable count to the number
1107e93f7393Sniklas of frames which we should print, or -1 if all of them. */
1108e93f7393Sniklas trailing = get_current_frame ();
1109b725ae77Skettenis
1110b725ae77Skettenis /* The target can be in a state where there is no valid frames
1111b725ae77Skettenis (e.g., just connected). */
1112b725ae77Skettenis if (trailing == NULL)
1113b725ae77Skettenis error ("No stack.");
1114b725ae77Skettenis
1115e93f7393Sniklas trailing_level = 0;
1116e93f7393Sniklas if (count_exp)
1117e93f7393Sniklas {
1118b725ae77Skettenis count = parse_and_eval_long (count_exp);
1119e93f7393Sniklas if (count < 0)
1120e93f7393Sniklas {
1121e93f7393Sniklas struct frame_info *current;
1122e93f7393Sniklas
1123e93f7393Sniklas count = -count;
1124e93f7393Sniklas
1125e93f7393Sniklas current = trailing;
1126e93f7393Sniklas while (current && count--)
1127e93f7393Sniklas {
1128e93f7393Sniklas QUIT;
1129e93f7393Sniklas current = get_prev_frame (current);
1130e93f7393Sniklas }
1131e93f7393Sniklas
1132e93f7393Sniklas /* Will stop when CURRENT reaches the top of the stack. TRAILING
1133e93f7393Sniklas will be COUNT below it. */
1134e93f7393Sniklas while (current)
1135e93f7393Sniklas {
1136e93f7393Sniklas QUIT;
1137e93f7393Sniklas trailing = get_prev_frame (trailing);
1138e93f7393Sniklas current = get_prev_frame (current);
1139e93f7393Sniklas trailing_level++;
1140e93f7393Sniklas }
1141e93f7393Sniklas
1142e93f7393Sniklas count = -1;
1143e93f7393Sniklas }
1144e93f7393Sniklas }
1145e93f7393Sniklas else
1146e93f7393Sniklas count = -1;
1147e93f7393Sniklas
1148e93f7393Sniklas if (info_verbose)
1149e93f7393Sniklas {
1150e93f7393Sniklas struct partial_symtab *ps;
1151e93f7393Sniklas
1152e93f7393Sniklas /* Read in symbols for all of the frames. Need to do this in
1153e93f7393Sniklas a separate pass so that "Reading in symbols for xxx" messages
1154e93f7393Sniklas don't screw up the appearance of the backtrace. Also
1155e93f7393Sniklas if people have strong opinions against reading symbols for
1156e93f7393Sniklas backtrace this may have to be an option. */
1157e93f7393Sniklas i = count;
1158e93f7393Sniklas for (fi = trailing;
1159e93f7393Sniklas fi != NULL && i--;
1160e93f7393Sniklas fi = get_prev_frame (fi))
1161e93f7393Sniklas {
1162e93f7393Sniklas QUIT;
1163b725ae77Skettenis ps = find_pc_psymtab (get_frame_address_in_block (fi));
1164e93f7393Sniklas if (ps)
1165e93f7393Sniklas PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
1166e93f7393Sniklas }
1167e93f7393Sniklas }
1168e93f7393Sniklas
1169e93f7393Sniklas for (i = 0, fi = trailing;
1170e93f7393Sniklas fi && count--;
1171e93f7393Sniklas i++, fi = get_prev_frame (fi))
1172e93f7393Sniklas {
1173e93f7393Sniklas QUIT;
1174e93f7393Sniklas
1175e93f7393Sniklas /* Don't use print_stack_frame; if an error() occurs it probably
1176e93f7393Sniklas means further attempts to backtrace would fail (on the other
1177e93f7393Sniklas hand, perhaps the code does or could be fixed to make sure
1178e93f7393Sniklas the frame->prev field gets set to NULL in that case). */
1179*63addd46Skettenis print_frame_info (fi, 1, LOCATION, 1);
1180b725ae77Skettenis if (show_locals)
1181b725ae77Skettenis print_frame_local_vars (fi, 1, gdb_stdout);
1182e93f7393Sniklas }
1183e93f7393Sniklas
1184e93f7393Sniklas /* If we've stopped before the end, mention that. */
1185e93f7393Sniklas if (fi && from_tty)
1186e93f7393Sniklas printf_filtered ("(More stack frames follow...)\n");
1187e93f7393Sniklas }
1188b725ae77Skettenis
1189b725ae77Skettenis static void
backtrace_command(char * arg,int from_tty)1190b725ae77Skettenis backtrace_command (char *arg, int from_tty)
1191b725ae77Skettenis {
1192b725ae77Skettenis struct cleanup *old_chain = (struct cleanup *) NULL;
1193b725ae77Skettenis char **argv = (char **) NULL;
1194b725ae77Skettenis int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0;
1195b725ae77Skettenis char *argPtr = arg;
1196b725ae77Skettenis
1197b725ae77Skettenis if (arg != (char *) NULL)
1198b725ae77Skettenis {
1199b725ae77Skettenis int i;
1200b725ae77Skettenis
1201b725ae77Skettenis argv = buildargv (arg);
1202b725ae77Skettenis old_chain = make_cleanup_freeargv (argv);
1203b725ae77Skettenis argc = 0;
1204b725ae77Skettenis for (i = 0; (argv[i] != (char *) NULL); i++)
1205b725ae77Skettenis {
1206b725ae77Skettenis unsigned int j;
1207b725ae77Skettenis
1208b725ae77Skettenis for (j = 0; (j < strlen (argv[i])); j++)
1209b725ae77Skettenis argv[i][j] = tolower (argv[i][j]);
1210b725ae77Skettenis
1211b725ae77Skettenis if (argIndicatingFullTrace < 0 && subset_compare (argv[i], "full"))
1212b725ae77Skettenis argIndicatingFullTrace = argc;
1213b725ae77Skettenis else
1214b725ae77Skettenis {
1215b725ae77Skettenis argc++;
1216b725ae77Skettenis totArgLen += strlen (argv[i]);
1217b725ae77Skettenis }
1218b725ae77Skettenis }
1219b725ae77Skettenis totArgLen += argc;
1220b725ae77Skettenis if (argIndicatingFullTrace >= 0)
1221b725ae77Skettenis {
1222b725ae77Skettenis if (totArgLen > 0)
1223b725ae77Skettenis {
1224b725ae77Skettenis argPtr = (char *) xmalloc (totArgLen + 1);
1225b725ae77Skettenis if (!argPtr)
1226b725ae77Skettenis nomem (0);
1227b725ae77Skettenis else
1228b725ae77Skettenis {
1229b725ae77Skettenis memset (argPtr, 0, totArgLen + 1);
1230b725ae77Skettenis for (i = 0; (i < (argc + 1)); i++)
1231b725ae77Skettenis {
1232b725ae77Skettenis if (i != argIndicatingFullTrace)
1233b725ae77Skettenis {
1234b725ae77Skettenis strcat (argPtr, argv[i]);
1235b725ae77Skettenis strcat (argPtr, " ");
1236b725ae77Skettenis }
1237b725ae77Skettenis }
1238b725ae77Skettenis }
1239b725ae77Skettenis }
1240b725ae77Skettenis else
1241b725ae77Skettenis argPtr = (char *) NULL;
1242b725ae77Skettenis }
1243b725ae77Skettenis }
1244b725ae77Skettenis
1245b725ae77Skettenis backtrace_command_1 (argPtr, (argIndicatingFullTrace >= 0), from_tty);
1246b725ae77Skettenis
1247b725ae77Skettenis if (argIndicatingFullTrace >= 0 && totArgLen > 0)
1248b725ae77Skettenis xfree (argPtr);
1249b725ae77Skettenis
1250b725ae77Skettenis if (old_chain)
1251b725ae77Skettenis do_cleanups (old_chain);
1252b725ae77Skettenis }
1253b725ae77Skettenis
1254b725ae77Skettenis static void backtrace_full_command (char *arg, int from_tty);
1255b725ae77Skettenis static void
backtrace_full_command(char * arg,int from_tty)1256b725ae77Skettenis backtrace_full_command (char *arg, int from_tty)
1257b725ae77Skettenis {
1258b725ae77Skettenis backtrace_command_1 (arg, 1, from_tty);
1259b725ae77Skettenis }
1260e93f7393Sniklas
1261b725ae77Skettenis
1262e93f7393Sniklas /* Print the local variables of a block B active in FRAME.
1263e93f7393Sniklas Return 1 if any variables were printed; 0 otherwise. */
1264e93f7393Sniklas
1265e93f7393Sniklas static int
print_block_frame_locals(struct block * b,struct frame_info * fi,int num_tabs,struct ui_file * stream)1266b725ae77Skettenis print_block_frame_locals (struct block *b, struct frame_info *fi,
1267b725ae77Skettenis int num_tabs, struct ui_file *stream)
1268e93f7393Sniklas {
1269b725ae77Skettenis struct dict_iterator iter;
1270b725ae77Skettenis int j;
1271b725ae77Skettenis struct symbol *sym;
1272b725ae77Skettenis int values_printed = 0;
1273e93f7393Sniklas
1274b725ae77Skettenis ALL_BLOCK_SYMBOLS (b, iter, sym)
1275e93f7393Sniklas {
1276e93f7393Sniklas switch (SYMBOL_CLASS (sym))
1277e93f7393Sniklas {
1278e93f7393Sniklas case LOC_LOCAL:
1279e93f7393Sniklas case LOC_REGISTER:
1280e93f7393Sniklas case LOC_STATIC:
1281e93f7393Sniklas case LOC_BASEREG:
1282b725ae77Skettenis case LOC_COMPUTED:
1283e93f7393Sniklas values_printed = 1;
1284b725ae77Skettenis for (j = 0; j < num_tabs; j++)
1285b725ae77Skettenis fputs_filtered ("\t", stream);
1286b725ae77Skettenis fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
1287e93f7393Sniklas fputs_filtered (" = ", stream);
1288e93f7393Sniklas print_variable_value (sym, fi, stream);
1289e93f7393Sniklas fprintf_filtered (stream, "\n");
1290e93f7393Sniklas break;
1291e93f7393Sniklas
1292e93f7393Sniklas default:
1293e93f7393Sniklas /* Ignore symbols which are not locals. */
1294e93f7393Sniklas break;
1295e93f7393Sniklas }
1296e93f7393Sniklas }
1297e93f7393Sniklas return values_printed;
1298e93f7393Sniklas }
1299e93f7393Sniklas
1300e93f7393Sniklas /* Same, but print labels. */
1301e93f7393Sniklas
1302e93f7393Sniklas static int
print_block_frame_labels(struct block * b,int * have_default,struct ui_file * stream)1303b725ae77Skettenis print_block_frame_labels (struct block *b, int *have_default,
1304b725ae77Skettenis struct ui_file *stream)
1305e93f7393Sniklas {
1306b725ae77Skettenis struct dict_iterator iter;
1307b725ae77Skettenis struct symbol *sym;
1308b725ae77Skettenis int values_printed = 0;
1309e93f7393Sniklas
1310b725ae77Skettenis ALL_BLOCK_SYMBOLS (b, iter, sym)
1311e93f7393Sniklas {
1312*63addd46Skettenis if (strcmp (DEPRECATED_SYMBOL_NAME (sym), "default") == 0)
1313e93f7393Sniklas {
1314e93f7393Sniklas if (*have_default)
1315e93f7393Sniklas continue;
1316e93f7393Sniklas *have_default = 1;
1317e93f7393Sniklas }
1318e93f7393Sniklas if (SYMBOL_CLASS (sym) == LOC_LABEL)
1319e93f7393Sniklas {
1320e93f7393Sniklas struct symtab_and_line sal;
1321e93f7393Sniklas sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1322e93f7393Sniklas values_printed = 1;
1323b725ae77Skettenis fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
1324e93f7393Sniklas if (addressprint)
1325e93f7393Sniklas {
1326e93f7393Sniklas fprintf_filtered (stream, " ");
1327e93f7393Sniklas print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
1328e93f7393Sniklas }
1329e93f7393Sniklas fprintf_filtered (stream, " in file %s, line %d\n",
1330e93f7393Sniklas sal.symtab->filename, sal.line);
1331e93f7393Sniklas }
1332e93f7393Sniklas }
1333e93f7393Sniklas return values_printed;
1334e93f7393Sniklas }
1335e93f7393Sniklas
1336e93f7393Sniklas /* Print on STREAM all the local variables in frame FRAME,
1337e93f7393Sniklas including all the blocks active in that frame
1338e93f7393Sniklas at its current pc.
1339e93f7393Sniklas
1340e93f7393Sniklas Returns 1 if the job was done,
1341e93f7393Sniklas or 0 if nothing was printed because we have no info
1342e93f7393Sniklas on the function running in FRAME. */
1343e93f7393Sniklas
1344e93f7393Sniklas static void
print_frame_local_vars(struct frame_info * fi,int num_tabs,struct ui_file * stream)1345b725ae77Skettenis print_frame_local_vars (struct frame_info *fi, int num_tabs,
1346b725ae77Skettenis struct ui_file *stream)
1347e93f7393Sniklas {
1348b725ae77Skettenis struct block *block = get_frame_block (fi, 0);
1349b725ae77Skettenis int values_printed = 0;
1350e93f7393Sniklas
1351e93f7393Sniklas if (block == 0)
1352e93f7393Sniklas {
1353e93f7393Sniklas fprintf_filtered (stream, "No symbol table info available.\n");
1354e93f7393Sniklas return;
1355e93f7393Sniklas }
1356e93f7393Sniklas
1357e93f7393Sniklas while (block != 0)
1358e93f7393Sniklas {
1359b725ae77Skettenis if (print_block_frame_locals (block, fi, num_tabs, stream))
1360e93f7393Sniklas values_printed = 1;
1361e93f7393Sniklas /* After handling the function's top-level block, stop.
1362e93f7393Sniklas Don't continue to its superblock, the block of
1363e93f7393Sniklas per-file symbols. */
1364e93f7393Sniklas if (BLOCK_FUNCTION (block))
1365e93f7393Sniklas break;
1366e93f7393Sniklas block = BLOCK_SUPERBLOCK (block);
1367e93f7393Sniklas }
1368e93f7393Sniklas
1369e93f7393Sniklas if (!values_printed)
1370e93f7393Sniklas {
1371e93f7393Sniklas fprintf_filtered (stream, "No locals.\n");
1372e93f7393Sniklas }
1373e93f7393Sniklas }
1374e93f7393Sniklas
1375e93f7393Sniklas /* Same, but print labels. */
1376e93f7393Sniklas
1377e93f7393Sniklas static void
print_frame_label_vars(struct frame_info * fi,int this_level_only,struct ui_file * stream)1378b725ae77Skettenis print_frame_label_vars (struct frame_info *fi, int this_level_only,
1379b725ae77Skettenis struct ui_file *stream)
1380e93f7393Sniklas {
1381b725ae77Skettenis struct blockvector *bl;
1382b725ae77Skettenis struct block *block = get_frame_block (fi, 0);
1383b725ae77Skettenis int values_printed = 0;
1384e93f7393Sniklas int index, have_default = 0;
1385e93f7393Sniklas char *blocks_printed;
1386b725ae77Skettenis CORE_ADDR pc = get_frame_pc (fi);
1387e93f7393Sniklas
1388e93f7393Sniklas if (block == 0)
1389e93f7393Sniklas {
1390e93f7393Sniklas fprintf_filtered (stream, "No symbol table info available.\n");
1391e93f7393Sniklas return;
1392e93f7393Sniklas }
1393e93f7393Sniklas
1394e93f7393Sniklas bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1395e93f7393Sniklas blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1396e93f7393Sniklas memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1397e93f7393Sniklas
1398e93f7393Sniklas while (block != 0)
1399e93f7393Sniklas {
1400e93f7393Sniklas CORE_ADDR end = BLOCK_END (block) - 4;
1401e93f7393Sniklas int last_index;
1402e93f7393Sniklas
1403e93f7393Sniklas if (bl != blockvector_for_pc (end, &index))
1404e93f7393Sniklas error ("blockvector blotch");
1405e93f7393Sniklas if (BLOCKVECTOR_BLOCK (bl, index) != block)
1406e93f7393Sniklas error ("blockvector botch");
1407e93f7393Sniklas last_index = BLOCKVECTOR_NBLOCKS (bl);
1408e93f7393Sniklas index += 1;
1409e93f7393Sniklas
1410e93f7393Sniklas /* Don't print out blocks that have gone by. */
1411e93f7393Sniklas while (index < last_index
1412e93f7393Sniklas && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1413e93f7393Sniklas index++;
1414e93f7393Sniklas
1415e93f7393Sniklas while (index < last_index
1416e93f7393Sniklas && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1417e93f7393Sniklas {
1418e93f7393Sniklas if (blocks_printed[index] == 0)
1419e93f7393Sniklas {
1420e93f7393Sniklas if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
1421e93f7393Sniklas values_printed = 1;
1422e93f7393Sniklas blocks_printed[index] = 1;
1423e93f7393Sniklas }
1424e93f7393Sniklas index++;
1425e93f7393Sniklas }
1426e93f7393Sniklas if (have_default)
1427e93f7393Sniklas return;
1428e93f7393Sniklas if (values_printed && this_level_only)
1429e93f7393Sniklas return;
1430e93f7393Sniklas
1431e93f7393Sniklas /* After handling the function's top-level block, stop.
1432e93f7393Sniklas Don't continue to its superblock, the block of
1433e93f7393Sniklas per-file symbols. */
1434e93f7393Sniklas if (BLOCK_FUNCTION (block))
1435e93f7393Sniklas break;
1436e93f7393Sniklas block = BLOCK_SUPERBLOCK (block);
1437e93f7393Sniklas }
1438e93f7393Sniklas
1439e93f7393Sniklas if (!values_printed && !this_level_only)
1440e93f7393Sniklas {
1441e93f7393Sniklas fprintf_filtered (stream, "No catches.\n");
1442e93f7393Sniklas }
1443e93f7393Sniklas }
1444e93f7393Sniklas
1445b725ae77Skettenis void
locals_info(char * args,int from_tty)1446b725ae77Skettenis locals_info (char *args, int from_tty)
1447e93f7393Sniklas {
1448b725ae77Skettenis if (!deprecated_selected_frame)
1449e93f7393Sniklas error ("No frame selected.");
1450b725ae77Skettenis print_frame_local_vars (deprecated_selected_frame, 0, gdb_stdout);
1451e93f7393Sniklas }
1452e93f7393Sniklas
1453e93f7393Sniklas static void
catch_info(char * ignore,int from_tty)1454b725ae77Skettenis catch_info (char *ignore, int from_tty)
1455e93f7393Sniklas {
1456b725ae77Skettenis struct symtab_and_line *sal;
1457b725ae77Skettenis
1458b725ae77Skettenis /* Check for target support for exception handling */
1459b725ae77Skettenis sal = target_enable_exception_callback (EX_EVENT_CATCH, 1);
1460b725ae77Skettenis if (sal)
1461b725ae77Skettenis {
1462b725ae77Skettenis /* Currently not handling this */
1463b725ae77Skettenis /* Ideally, here we should interact with the C++ runtime
1464b725ae77Skettenis system to find the list of active handlers, etc. */
1465b725ae77Skettenis fprintf_filtered (gdb_stdout, "Info catch not supported with this target/compiler combination.\n");
1466b725ae77Skettenis }
1467b725ae77Skettenis else
1468b725ae77Skettenis {
1469b725ae77Skettenis /* Assume g++ compiled code -- old v 4.16 behaviour */
1470b725ae77Skettenis if (!deprecated_selected_frame)
1471b725ae77Skettenis error ("No frame selected.");
1472b725ae77Skettenis
1473b725ae77Skettenis print_frame_label_vars (deprecated_selected_frame, 0, gdb_stdout);
1474b725ae77Skettenis }
1475e93f7393Sniklas }
1476e93f7393Sniklas
1477e93f7393Sniklas static void
print_frame_arg_vars(struct frame_info * fi,struct ui_file * stream)1478b725ae77Skettenis print_frame_arg_vars (struct frame_info *fi,
1479b725ae77Skettenis struct ui_file *stream)
1480e93f7393Sniklas {
1481e93f7393Sniklas struct symbol *func = get_frame_function (fi);
1482b725ae77Skettenis struct block *b;
1483b725ae77Skettenis struct dict_iterator iter;
1484b725ae77Skettenis struct symbol *sym, *sym2;
1485b725ae77Skettenis int values_printed = 0;
1486e93f7393Sniklas
1487e93f7393Sniklas if (func == 0)
1488e93f7393Sniklas {
1489e93f7393Sniklas fprintf_filtered (stream, "No symbol table info available.\n");
1490e93f7393Sniklas return;
1491e93f7393Sniklas }
1492e93f7393Sniklas
1493e93f7393Sniklas b = SYMBOL_BLOCK_VALUE (func);
1494b725ae77Skettenis ALL_BLOCK_SYMBOLS (b, iter, sym)
1495e93f7393Sniklas {
1496e93f7393Sniklas switch (SYMBOL_CLASS (sym))
1497e93f7393Sniklas {
1498e93f7393Sniklas case LOC_ARG:
1499e93f7393Sniklas case LOC_LOCAL_ARG:
1500e93f7393Sniklas case LOC_REF_ARG:
1501e93f7393Sniklas case LOC_REGPARM:
1502e93f7393Sniklas case LOC_REGPARM_ADDR:
1503e93f7393Sniklas case LOC_BASEREG_ARG:
1504b725ae77Skettenis case LOC_COMPUTED_ARG:
1505e93f7393Sniklas values_printed = 1;
1506b725ae77Skettenis fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
1507e93f7393Sniklas fputs_filtered (" = ", stream);
1508e93f7393Sniklas
1509e93f7393Sniklas /* We have to look up the symbol because arguments can have
1510e93f7393Sniklas two entries (one a parameter, one a local) and the one we
1511e93f7393Sniklas want is the local, which lookup_symbol will find for us.
1512e93f7393Sniklas This includes gcc1 (not gcc2) on the sparc when passing a
1513e93f7393Sniklas small structure and gcc2 when the argument type is float
1514e93f7393Sniklas and it is passed as a double and converted to float by
1515e93f7393Sniklas the prologue (in the latter case the type of the LOC_ARG
1516e93f7393Sniklas symbol is double and the type of the LOC_LOCAL symbol is
1517e93f7393Sniklas float). There are also LOC_ARG/LOC_REGISTER pairs which
1518e93f7393Sniklas are not combined in symbol-reading. */
1519e93f7393Sniklas
1520b725ae77Skettenis sym2 = lookup_symbol (DEPRECATED_SYMBOL_NAME (sym),
1521b725ae77Skettenis b, VAR_DOMAIN, (int *) NULL, (struct symtab **) NULL);
1522e93f7393Sniklas print_variable_value (sym2, fi, stream);
1523e93f7393Sniklas fprintf_filtered (stream, "\n");
1524e93f7393Sniklas break;
1525e93f7393Sniklas
1526e93f7393Sniklas default:
1527e93f7393Sniklas /* Don't worry about things which aren't arguments. */
1528e93f7393Sniklas break;
1529e93f7393Sniklas }
1530e93f7393Sniklas }
1531e93f7393Sniklas if (!values_printed)
1532e93f7393Sniklas {
1533e93f7393Sniklas fprintf_filtered (stream, "No arguments.\n");
1534e93f7393Sniklas }
1535e93f7393Sniklas }
1536e93f7393Sniklas
1537b725ae77Skettenis void
args_info(char * ignore,int from_tty)1538b725ae77Skettenis args_info (char *ignore, int from_tty)
1539e93f7393Sniklas {
1540b725ae77Skettenis if (!deprecated_selected_frame)
1541e93f7393Sniklas error ("No frame selected.");
1542b725ae77Skettenis print_frame_arg_vars (deprecated_selected_frame, gdb_stdout);
1543b725ae77Skettenis }
1544b725ae77Skettenis
1545b725ae77Skettenis
1546b725ae77Skettenis static void
args_plus_locals_info(char * ignore,int from_tty)1547b725ae77Skettenis args_plus_locals_info (char *ignore, int from_tty)
1548b725ae77Skettenis {
1549b725ae77Skettenis args_info (ignore, from_tty);
1550b725ae77Skettenis locals_info (ignore, from_tty);
1551e93f7393Sniklas }
1552e93f7393Sniklas
1553e93f7393Sniklas
1554b725ae77Skettenis /* Select frame FI. Also print the stack frame and show the source if
1555b725ae77Skettenis this is the tui version. */
1556b725ae77Skettenis static void
select_and_print_frame(struct frame_info * fi)1557b725ae77Skettenis select_and_print_frame (struct frame_info *fi)
1558e93f7393Sniklas {
1559b725ae77Skettenis select_frame (fi);
1560e93f7393Sniklas if (fi)
1561*63addd46Skettenis print_stack_frame (fi, 1, SRC_AND_LOC);
1562e93f7393Sniklas }
1563b725ae77Skettenis
1564e93f7393Sniklas /* Return the symbol-block in which the selected frame is executing.
1565b725ae77Skettenis Can return zero under various legitimate circumstances.
1566b725ae77Skettenis
1567b725ae77Skettenis If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1568b725ae77Skettenis code address within the block returned. We use this to decide
1569b725ae77Skettenis which macros are in scope. */
1570e93f7393Sniklas
1571e93f7393Sniklas struct block *
get_selected_block(CORE_ADDR * addr_in_block)1572b725ae77Skettenis get_selected_block (CORE_ADDR *addr_in_block)
1573e93f7393Sniklas {
1574e93f7393Sniklas if (!target_has_stack)
1575e93f7393Sniklas return 0;
1576e93f7393Sniklas
1577b725ae77Skettenis /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1578*63addd46Skettenis a selected/current frame? Perhaps this function is called,
1579b725ae77Skettenis indirectly, by WFI in "infrun.c" where avoiding the creation of
1580b725ae77Skettenis an inner most frame is very important (it slows down single
1581b725ae77Skettenis step). I suspect, though that this was true in the deep dark
1582b725ae77Skettenis past but is no longer the case. A mindless look at all the
1583b725ae77Skettenis callers tends to support this theory. I think we should be able
1584b725ae77Skettenis to assume that there is always a selcted frame. */
1585b725ae77Skettenis /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1586b725ae77Skettenis lucky? */
1587b725ae77Skettenis if (!deprecated_selected_frame)
1588b725ae77Skettenis {
1589b725ae77Skettenis CORE_ADDR pc = read_pc ();
1590b725ae77Skettenis if (addr_in_block != NULL)
1591b725ae77Skettenis *addr_in_block = pc;
1592b725ae77Skettenis return block_for_pc (pc);
1593b725ae77Skettenis }
1594b725ae77Skettenis return get_frame_block (deprecated_selected_frame, addr_in_block);
1595e93f7393Sniklas }
1596e93f7393Sniklas
1597e93f7393Sniklas /* Find a frame a certain number of levels away from FRAME.
1598e93f7393Sniklas LEVEL_OFFSET_PTR points to an int containing the number of levels.
1599e93f7393Sniklas Positive means go to earlier frames (up); negative, the reverse.
1600e93f7393Sniklas The int that contains the number of levels is counted toward
1601e93f7393Sniklas zero as the frames for those levels are found.
1602e93f7393Sniklas If the top or bottom frame is reached, that frame is returned,
1603e93f7393Sniklas but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1604e93f7393Sniklas how much farther the original request asked to go. */
1605e93f7393Sniklas
1606e93f7393Sniklas struct frame_info *
find_relative_frame(struct frame_info * frame,int * level_offset_ptr)1607b725ae77Skettenis find_relative_frame (struct frame_info *frame,
1608b725ae77Skettenis int *level_offset_ptr)
1609e93f7393Sniklas {
1610b725ae77Skettenis struct frame_info *prev;
1611b725ae77Skettenis struct frame_info *frame1;
1612e93f7393Sniklas
1613e93f7393Sniklas /* Going up is simple: just do get_prev_frame enough times
1614e93f7393Sniklas or until initial frame is reached. */
1615e93f7393Sniklas while (*level_offset_ptr > 0)
1616e93f7393Sniklas {
1617e93f7393Sniklas prev = get_prev_frame (frame);
1618e93f7393Sniklas if (prev == 0)
1619e93f7393Sniklas break;
1620e93f7393Sniklas (*level_offset_ptr)--;
1621e93f7393Sniklas frame = prev;
1622e93f7393Sniklas }
1623e93f7393Sniklas /* Going down is just as simple. */
1624e93f7393Sniklas if (*level_offset_ptr < 0)
1625e93f7393Sniklas {
1626b725ae77Skettenis while (*level_offset_ptr < 0)
1627b725ae77Skettenis {
1628e93f7393Sniklas frame1 = get_next_frame (frame);
1629e93f7393Sniklas if (!frame1)
1630e93f7393Sniklas break;
1631e93f7393Sniklas frame = frame1;
1632e93f7393Sniklas (*level_offset_ptr)++;
1633e93f7393Sniklas }
1634e93f7393Sniklas }
1635e93f7393Sniklas return frame;
1636e93f7393Sniklas }
1637e93f7393Sniklas
1638e93f7393Sniklas /* The "select_frame" command. With no arg, NOP.
1639e93f7393Sniklas With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1640e93f7393Sniklas valid level. Otherwise, treat level_exp as an address expression
1641e93f7393Sniklas and select it. See parse_frame_specification for more info on proper
1642e93f7393Sniklas frame expressions. */
1643e93f7393Sniklas
1644b725ae77Skettenis void
select_frame_command(char * level_exp,int from_tty)1645b725ae77Skettenis select_frame_command (char *level_exp, int from_tty)
1646e93f7393Sniklas {
1647b725ae77Skettenis struct frame_info *frame;
1648e93f7393Sniklas
1649e93f7393Sniklas if (!target_has_stack)
1650e93f7393Sniklas error ("No stack.");
1651e93f7393Sniklas
1652e93f7393Sniklas frame = parse_frame_specification (level_exp);
1653e93f7393Sniklas
1654b725ae77Skettenis select_frame (frame);
1655e93f7393Sniklas }
1656e93f7393Sniklas
1657e93f7393Sniklas /* The "frame" command. With no arg, print selected frame briefly.
1658e93f7393Sniklas With arg, behaves like select_frame and then prints the selected
1659e93f7393Sniklas frame. */
1660e93f7393Sniklas
1661b725ae77Skettenis void
frame_command(char * level_exp,int from_tty)1662b725ae77Skettenis frame_command (char *level_exp, int from_tty)
1663e93f7393Sniklas {
1664e93f7393Sniklas select_frame_command (level_exp, from_tty);
1665*63addd46Skettenis print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
1666b725ae77Skettenis }
1667b725ae77Skettenis
1668b725ae77Skettenis /* The XDB Compatibility command to print the current frame. */
1669b725ae77Skettenis
1670b725ae77Skettenis static void
current_frame_command(char * level_exp,int from_tty)1671b725ae77Skettenis current_frame_command (char *level_exp, int from_tty)
1672b725ae77Skettenis {
1673b725ae77Skettenis if (target_has_stack == 0 || deprecated_selected_frame == 0)
1674b725ae77Skettenis error ("No stack.");
1675*63addd46Skettenis print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
1676e93f7393Sniklas }
1677e93f7393Sniklas
1678e93f7393Sniklas /* Select the frame up one or COUNT stack levels
1679e93f7393Sniklas from the previously selected frame, and print it briefly. */
1680e93f7393Sniklas
1681e93f7393Sniklas static void
up_silently_base(char * count_exp)1682b725ae77Skettenis up_silently_base (char *count_exp)
1683e93f7393Sniklas {
1684b725ae77Skettenis struct frame_info *fi;
1685e93f7393Sniklas int count = 1, count1;
1686e93f7393Sniklas if (count_exp)
1687b725ae77Skettenis count = parse_and_eval_long (count_exp);
1688e93f7393Sniklas count1 = count;
1689e93f7393Sniklas
1690b725ae77Skettenis if (target_has_stack == 0 || deprecated_selected_frame == 0)
1691e93f7393Sniklas error ("No stack.");
1692e93f7393Sniklas
1693b725ae77Skettenis fi = find_relative_frame (deprecated_selected_frame, &count1);
1694e93f7393Sniklas if (count1 != 0 && count_exp == 0)
1695e93f7393Sniklas error ("Initial frame selected; you cannot go up.");
1696b725ae77Skettenis select_frame (fi);
1697e93f7393Sniklas }
1698e93f7393Sniklas
1699e93f7393Sniklas static void
up_silently_command(char * count_exp,int from_tty)1700b725ae77Skettenis up_silently_command (char *count_exp, int from_tty)
1701e93f7393Sniklas {
1702b725ae77Skettenis up_silently_base (count_exp);
1703b725ae77Skettenis }
1704b725ae77Skettenis
1705b725ae77Skettenis static void
up_command(char * count_exp,int from_tty)1706b725ae77Skettenis up_command (char *count_exp, int from_tty)
1707b725ae77Skettenis {
1708b725ae77Skettenis up_silently_base (count_exp);
1709*63addd46Skettenis print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
1710e93f7393Sniklas }
1711e93f7393Sniklas
1712e93f7393Sniklas /* Select the frame down one or COUNT stack levels
1713e93f7393Sniklas from the previously selected frame, and print it briefly. */
1714e93f7393Sniklas
1715e93f7393Sniklas static void
down_silently_base(char * count_exp)1716b725ae77Skettenis down_silently_base (char *count_exp)
1717e93f7393Sniklas {
1718b725ae77Skettenis struct frame_info *frame;
1719e93f7393Sniklas int count = -1, count1;
1720e93f7393Sniklas if (count_exp)
1721b725ae77Skettenis count = -parse_and_eval_long (count_exp);
1722e93f7393Sniklas count1 = count;
1723e93f7393Sniklas
1724b725ae77Skettenis if (target_has_stack == 0 || deprecated_selected_frame == 0)
1725e93f7393Sniklas error ("No stack.");
1726e93f7393Sniklas
1727b725ae77Skettenis frame = find_relative_frame (deprecated_selected_frame, &count1);
1728e93f7393Sniklas if (count1 != 0 && count_exp == 0)
1729e93f7393Sniklas {
1730e93f7393Sniklas
1731e93f7393Sniklas /* We only do this if count_exp is not specified. That way "down"
1732e93f7393Sniklas means to really go down (and let me know if that is
1733e93f7393Sniklas impossible), but "down 9999" can be used to mean go all the way
1734e93f7393Sniklas down without getting an error. */
1735e93f7393Sniklas
1736e93f7393Sniklas error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1737e93f7393Sniklas }
1738e93f7393Sniklas
1739b725ae77Skettenis select_frame (frame);
1740e93f7393Sniklas }
1741e93f7393Sniklas
1742b725ae77Skettenis static void
down_silently_command(char * count_exp,int from_tty)1743b725ae77Skettenis down_silently_command (char *count_exp, int from_tty)
1744b725ae77Skettenis {
1745b725ae77Skettenis down_silently_base (count_exp);
1746b725ae77Skettenis }
1747e93f7393Sniklas
1748e93f7393Sniklas static void
down_command(char * count_exp,int from_tty)1749b725ae77Skettenis down_command (char *count_exp, int from_tty)
1750e93f7393Sniklas {
1751b725ae77Skettenis down_silently_base (count_exp);
1752*63addd46Skettenis print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
1753e93f7393Sniklas }
1754e93f7393Sniklas
1755b725ae77Skettenis void
return_command(char * retval_exp,int from_tty)1756b725ae77Skettenis return_command (char *retval_exp, int from_tty)
1757e93f7393Sniklas {
1758e93f7393Sniklas struct symbol *thisfun;
1759b725ae77Skettenis struct value *return_value = NULL;
1760b725ae77Skettenis const char *query_prefix = "";
1761e93f7393Sniklas
1762b725ae77Skettenis /* FIXME: cagney/2003-10-20: Perform a minimal existance test on the
1763b725ae77Skettenis target. If that fails, error out. For the moment don't rely on
1764b725ae77Skettenis get_selected_frame as it's error message is the the singularly
1765b725ae77Skettenis obscure "No registers". */
1766b725ae77Skettenis if (!target_has_registers)
1767e93f7393Sniklas error ("No selected frame.");
1768b725ae77Skettenis thisfun = get_frame_function (get_selected_frame ());
1769e93f7393Sniklas
1770b725ae77Skettenis /* Compute the return value. If the computation triggers an error,
1771b725ae77Skettenis let it bail. If the return type can't be handled, set
1772b725ae77Skettenis RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1773b725ae77Skettenis message. */
1774e93f7393Sniklas if (retval_exp)
1775e93f7393Sniklas {
1776e93f7393Sniklas struct type *return_type = NULL;
1777e93f7393Sniklas
1778b725ae77Skettenis /* Compute the return value. Should the computation fail, this
1779b725ae77Skettenis call throws an error. */
1780e93f7393Sniklas return_value = parse_and_eval (retval_exp);
1781e93f7393Sniklas
1782b725ae77Skettenis /* Cast return value to the return type of the function. Should
1783b725ae77Skettenis the cast fail, this call throws an error. */
1784e93f7393Sniklas if (thisfun != NULL)
1785e93f7393Sniklas return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
1786e93f7393Sniklas if (return_type == NULL)
1787e93f7393Sniklas return_type = builtin_type_int;
1788*63addd46Skettenis CHECK_TYPEDEF (return_type);
1789e93f7393Sniklas return_value = value_cast (return_type, return_value);
1790e93f7393Sniklas
1791b725ae77Skettenis /* Make sure the value is fully evaluated. It may live in the
1792b725ae77Skettenis stack frame we're about to pop. */
1793e93f7393Sniklas if (VALUE_LAZY (return_value))
1794e93f7393Sniklas value_fetch_lazy (return_value);
1795b725ae77Skettenis
1796b725ae77Skettenis if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
1797b725ae77Skettenis /* If the return-type is "void", don't try to find the
1798b725ae77Skettenis return-value's location. However, do still evaluate the
1799b725ae77Skettenis return expression so that, even when the expression result
1800b725ae77Skettenis is discarded, side effects such as "return i++" still
1801b725ae77Skettenis occure. */
1802b725ae77Skettenis return_value = NULL;
1803b725ae77Skettenis /* FIXME: cagney/2004-01-17: If the architecture implements both
1804b725ae77Skettenis return_value and extract_returned_value_address, should allow
1805b725ae77Skettenis "return" to work - don't set return_value to NULL. */
1806b725ae77Skettenis else if (!gdbarch_return_value_p (current_gdbarch)
1807b725ae77Skettenis && (TYPE_CODE (return_type) == TYPE_CODE_STRUCT
1808b725ae77Skettenis || TYPE_CODE (return_type) == TYPE_CODE_UNION))
1809b725ae77Skettenis {
1810b725ae77Skettenis /* NOTE: cagney/2003-10-20: Compatibility hack for legacy
1811b725ae77Skettenis code. Old architectures don't expect STORE_RETURN_VALUE
1812b725ae77Skettenis to be called with with a small struct that needs to be
1813b725ae77Skettenis stored in registers. Don't start doing it now. */
1814b725ae77Skettenis query_prefix = "\
1815b725ae77Skettenis A structure or union return type is not supported by this architecture.\n\
1816b725ae77Skettenis If you continue, the return value that you specified will be ignored.\n";
1817b725ae77Skettenis return_value = NULL;
1818b725ae77Skettenis }
1819b725ae77Skettenis else if (using_struct_return (return_type, 0))
1820b725ae77Skettenis {
1821b725ae77Skettenis query_prefix = "\
1822b725ae77Skettenis The location at which to store the function's return value is unknown.\n\
1823b725ae77Skettenis If you continue, the return value that you specified will be ignored.\n";
1824b725ae77Skettenis return_value = NULL;
1825b725ae77Skettenis }
1826e93f7393Sniklas }
1827e93f7393Sniklas
1828b725ae77Skettenis /* Does an interactive user really want to do this? Include
1829b725ae77Skettenis information, such as how well GDB can handle the return value, in
1830b725ae77Skettenis the query message. */
1831e93f7393Sniklas if (from_tty)
1832e93f7393Sniklas {
1833b725ae77Skettenis int confirmed;
1834b725ae77Skettenis if (thisfun == NULL)
1835b725ae77Skettenis confirmed = query ("%sMake selected stack frame return now? ",
1836b725ae77Skettenis query_prefix);
1837e93f7393Sniklas else
1838b725ae77Skettenis confirmed = query ("%sMake %s return now? ", query_prefix,
1839b725ae77Skettenis SYMBOL_PRINT_NAME (thisfun));
1840b725ae77Skettenis if (!confirmed)
1841b725ae77Skettenis error ("Not confirmed");
1842e93f7393Sniklas }
1843e93f7393Sniklas
1844b725ae77Skettenis /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each
1845b725ae77Skettenis frame in turn, should this code just go straight to the relevant
1846b725ae77Skettenis frame and pop that? */
1847e93f7393Sniklas
1848b725ae77Skettenis /* First discard all frames inner-to the selected frame (making the
1849b725ae77Skettenis selected frame current). */
1850b725ae77Skettenis {
1851b725ae77Skettenis struct frame_id selected_id = get_frame_id (get_selected_frame ());
1852b725ae77Skettenis while (!frame_id_eq (selected_id, get_frame_id (get_current_frame ())))
1853b725ae77Skettenis {
1854b725ae77Skettenis if (frame_id_inner (selected_id, get_frame_id (get_current_frame ())))
1855b725ae77Skettenis /* Caught in the safety net, oops! We've gone way past the
1856b725ae77Skettenis selected frame. */
1857b725ae77Skettenis error ("Problem while popping stack frames (corrupt stack?)");
1858b725ae77Skettenis frame_pop (get_current_frame ());
1859b725ae77Skettenis }
1860b725ae77Skettenis }
1861e93f7393Sniklas
1862b725ae77Skettenis /* Second discard the selected frame (which is now also the current
1863b725ae77Skettenis frame). */
1864b725ae77Skettenis frame_pop (get_current_frame ());
1865e93f7393Sniklas
1866b725ae77Skettenis /* Store RETURN_VAUE in the just-returned register set. */
1867b725ae77Skettenis if (return_value != NULL)
1868b725ae77Skettenis {
1869b725ae77Skettenis struct type *return_type = VALUE_TYPE (return_value);
1870b725ae77Skettenis gdb_assert (gdbarch_return_value (current_gdbarch, return_type,
1871b725ae77Skettenis NULL, NULL, NULL)
1872b725ae77Skettenis == RETURN_VALUE_REGISTER_CONVENTION);
1873b725ae77Skettenis gdbarch_return_value (current_gdbarch, return_type,
1874b725ae77Skettenis current_regcache, NULL /*read*/,
1875b725ae77Skettenis VALUE_CONTENTS (return_value) /*write*/);
1876b725ae77Skettenis }
1877e93f7393Sniklas
1878b725ae77Skettenis /* If we are at the end of a call dummy now, pop the dummy frame
1879b725ae77Skettenis too. */
1880b725ae77Skettenis if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
1881b725ae77Skettenis frame_pop (get_current_frame ());
1882e93f7393Sniklas
1883e93f7393Sniklas /* If interactive, print the frame that is now current. */
1884e93f7393Sniklas if (from_tty)
1885e93f7393Sniklas frame_command ("0", 1);
1886e93f7393Sniklas else
1887e93f7393Sniklas select_frame_command ("0", 0);
1888e93f7393Sniklas }
1889e93f7393Sniklas
1890b725ae77Skettenis /* Sets the scope to input function name, provided that the
1891b725ae77Skettenis function is within the current stack frame */
1892b725ae77Skettenis
1893b725ae77Skettenis struct function_bounds
1894b725ae77Skettenis {
1895b725ae77Skettenis CORE_ADDR low, high;
1896b725ae77Skettenis };
1897b725ae77Skettenis
1898b725ae77Skettenis static void func_command (char *arg, int from_tty);
1899b725ae77Skettenis static void
func_command(char * arg,int from_tty)1900b725ae77Skettenis func_command (char *arg, int from_tty)
1901b725ae77Skettenis {
1902b725ae77Skettenis struct frame_info *fp;
1903b725ae77Skettenis int found = 0;
1904b725ae77Skettenis struct symtabs_and_lines sals;
1905b725ae77Skettenis int i;
1906b725ae77Skettenis int level = 1;
1907b725ae77Skettenis struct function_bounds *func_bounds = (struct function_bounds *) NULL;
1908b725ae77Skettenis
1909b725ae77Skettenis if (arg != (char *) NULL)
1910b725ae77Skettenis return;
1911b725ae77Skettenis
1912b725ae77Skettenis fp = parse_frame_specification ("0");
1913b725ae77Skettenis sals = decode_line_spec (arg, 1);
1914b725ae77Skettenis func_bounds = (struct function_bounds *) xmalloc (
1915b725ae77Skettenis sizeof (struct function_bounds) * sals.nelts);
1916b725ae77Skettenis for (i = 0; (i < sals.nelts && !found); i++)
1917b725ae77Skettenis {
1918b725ae77Skettenis if (sals.sals[i].pc == (CORE_ADDR) 0 ||
1919b725ae77Skettenis find_pc_partial_function (sals.sals[i].pc,
1920b725ae77Skettenis (char **) NULL,
1921b725ae77Skettenis &func_bounds[i].low,
1922b725ae77Skettenis &func_bounds[i].high) == 0)
1923b725ae77Skettenis {
1924b725ae77Skettenis func_bounds[i].low =
1925b725ae77Skettenis func_bounds[i].high = (CORE_ADDR) NULL;
1926b725ae77Skettenis }
1927b725ae77Skettenis }
1928b725ae77Skettenis
1929b725ae77Skettenis do
1930b725ae77Skettenis {
1931b725ae77Skettenis for (i = 0; (i < sals.nelts && !found); i++)
1932b725ae77Skettenis found = (get_frame_pc (fp) >= func_bounds[i].low &&
1933b725ae77Skettenis get_frame_pc (fp) < func_bounds[i].high);
1934b725ae77Skettenis if (!found)
1935b725ae77Skettenis {
1936b725ae77Skettenis level = 1;
1937b725ae77Skettenis fp = find_relative_frame (fp, &level);
1938b725ae77Skettenis }
1939b725ae77Skettenis }
1940b725ae77Skettenis while (!found && level == 0);
1941b725ae77Skettenis
1942b725ae77Skettenis if (func_bounds)
1943b725ae77Skettenis xfree (func_bounds);
1944b725ae77Skettenis
1945b725ae77Skettenis if (!found)
1946b725ae77Skettenis printf_filtered ("'%s' not within current stack frame.\n", arg);
1947b725ae77Skettenis else if (fp != deprecated_selected_frame)
1948b725ae77Skettenis select_and_print_frame (fp);
1949b725ae77Skettenis }
1950b725ae77Skettenis
1951e93f7393Sniklas /* Gets the language of the current frame. */
1952e93f7393Sniklas
1953e93f7393Sniklas enum language
get_frame_language(void)1954b725ae77Skettenis get_frame_language (void)
1955e93f7393Sniklas {
1956b725ae77Skettenis struct symtab *s;
1957e93f7393Sniklas enum language flang; /* The language of the current frame */
1958e93f7393Sniklas
1959b725ae77Skettenis if (deprecated_selected_frame)
1960e93f7393Sniklas {
1961b725ae77Skettenis /* We determine the current frame language by looking up its
1962b725ae77Skettenis associated symtab. To retrieve this symtab, we use the frame PC.
1963b725ae77Skettenis However we cannot use the frame pc as is, because it usually points
1964b725ae77Skettenis to the instruction following the "call", which is sometimes the first
1965b725ae77Skettenis instruction of another function. So we rely on
1966b725ae77Skettenis get_frame_address_in_block(), it provides us with a PC which is
1967b725ae77Skettenis guaranteed to be inside the frame's code block. */
1968b725ae77Skettenis s = find_pc_symtab (get_frame_address_in_block (deprecated_selected_frame));
1969e93f7393Sniklas if (s)
1970e93f7393Sniklas flang = s->language;
1971e93f7393Sniklas else
1972e93f7393Sniklas flang = language_unknown;
1973e93f7393Sniklas }
1974e93f7393Sniklas else
1975e93f7393Sniklas flang = language_unknown;
1976e93f7393Sniklas
1977e93f7393Sniklas return flang;
1978e93f7393Sniklas }
1979e93f7393Sniklas
1980e93f7393Sniklas void
_initialize_stack(void)1981b725ae77Skettenis _initialize_stack (void)
1982e93f7393Sniklas {
1983e93f7393Sniklas #if 0
1984e93f7393Sniklas backtrace_limit = 30;
1985e93f7393Sniklas #endif
1986e93f7393Sniklas
1987e93f7393Sniklas add_com ("return", class_stack, return_command,
1988e93f7393Sniklas "Make selected stack frame return to its caller.\n\
1989e93f7393Sniklas Control remains in the debugger, but when you continue\n\
1990e93f7393Sniklas execution will resume in the frame above the one now selected.\n\
1991e93f7393Sniklas If an argument is given, it is an expression for the value to return.");
1992e93f7393Sniklas
1993e93f7393Sniklas add_com ("up", class_stack, up_command,
1994e93f7393Sniklas "Select and print stack frame that called this one.\n\
1995e93f7393Sniklas An argument says how many frames up to go.");
1996e93f7393Sniklas add_com ("up-silently", class_support, up_silently_command,
1997e93f7393Sniklas "Same as the `up' command, but does not print anything.\n\
1998e93f7393Sniklas This is useful in command scripts.");
1999e93f7393Sniklas
2000e93f7393Sniklas add_com ("down", class_stack, down_command,
2001e93f7393Sniklas "Select and print stack frame called by this one.\n\
2002e93f7393Sniklas An argument says how many frames down to go.");
2003e93f7393Sniklas add_com_alias ("do", "down", class_stack, 1);
2004e93f7393Sniklas add_com_alias ("dow", "down", class_stack, 1);
2005e93f7393Sniklas add_com ("down-silently", class_support, down_silently_command,
2006e93f7393Sniklas "Same as the `down' command, but does not print anything.\n\
2007e93f7393Sniklas This is useful in command scripts.");
2008e93f7393Sniklas
2009e93f7393Sniklas add_com ("frame", class_stack, frame_command,
2010e93f7393Sniklas "Select and print a stack frame.\n\
2011e93f7393Sniklas With no argument, print the selected stack frame. (See also \"info frame\").\n\
2012e93f7393Sniklas An argument specifies the frame to select.\n\
2013e93f7393Sniklas It can be a stack frame number or the address of the frame.\n\
2014e93f7393Sniklas With argument, nothing is printed if input is coming from\n\
2015e93f7393Sniklas a command file or a user-defined command.");
2016e93f7393Sniklas
2017e93f7393Sniklas add_com_alias ("f", "frame", class_stack, 1);
2018e93f7393Sniklas
2019b725ae77Skettenis if (xdb_commands)
2020b725ae77Skettenis {
2021b725ae77Skettenis add_com ("L", class_stack, current_frame_command,
2022b725ae77Skettenis "Print the current stack frame.\n");
2023b725ae77Skettenis add_com_alias ("V", "frame", class_stack, 1);
2024b725ae77Skettenis }
2025e93f7393Sniklas add_com ("select-frame", class_stack, select_frame_command,
2026e93f7393Sniklas "Select a stack frame without printing anything.\n\
2027e93f7393Sniklas An argument specifies the frame to select.\n\
2028e93f7393Sniklas It can be a stack frame number or the address of the frame.\n");
2029e93f7393Sniklas
2030e93f7393Sniklas add_com ("backtrace", class_stack, backtrace_command,
2031e93f7393Sniklas "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2032b725ae77Skettenis With a negative argument, print outermost -COUNT frames.\n\
2033b725ae77Skettenis Use of the 'full' qualifier also prints the values of the local variables.\n");
2034e93f7393Sniklas add_com_alias ("bt", "backtrace", class_stack, 0);
2035b725ae77Skettenis if (xdb_commands)
2036b725ae77Skettenis {
2037b725ae77Skettenis add_com_alias ("t", "backtrace", class_stack, 0);
2038b725ae77Skettenis add_com ("T", class_stack, backtrace_full_command,
2039b725ae77Skettenis "Print backtrace of all stack frames, or innermost COUNT frames \n\
2040b725ae77Skettenis and the values of the local variables.\n\
2041b725ae77Skettenis With a negative argument, print outermost -COUNT frames.\n\
2042b725ae77Skettenis Usage: T <count>\n");
2043b725ae77Skettenis }
2044b725ae77Skettenis
2045e93f7393Sniklas add_com_alias ("where", "backtrace", class_alias, 0);
2046e93f7393Sniklas add_info ("stack", backtrace_command,
2047e93f7393Sniklas "Backtrace of the stack, or innermost COUNT frames.");
2048e93f7393Sniklas add_info_alias ("s", "stack", 1);
2049e93f7393Sniklas add_info ("frame", frame_info,
2050e93f7393Sniklas "All about selected stack frame, or frame at ADDR.");
2051e93f7393Sniklas add_info_alias ("f", "frame", 1);
2052e93f7393Sniklas add_info ("locals", locals_info,
2053e93f7393Sniklas "Local variables of current stack frame.");
2054e93f7393Sniklas add_info ("args", args_info,
2055e93f7393Sniklas "Argument variables of current stack frame.");
2056b725ae77Skettenis if (xdb_commands)
2057b725ae77Skettenis add_com ("l", class_info, args_plus_locals_info,
2058b725ae77Skettenis "Argument and local variables of current stack frame.");
2059b725ae77Skettenis
2060b725ae77Skettenis if (dbx_commands)
2061b725ae77Skettenis add_com ("func", class_stack, func_command,
2062b725ae77Skettenis "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2063b725ae77Skettenis
2064e93f7393Sniklas add_info ("catch", catch_info,
2065e93f7393Sniklas "Exceptions that can be caught in the current stack frame.");
2066e93f7393Sniklas
2067e93f7393Sniklas #if 0
2068e93f7393Sniklas add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
2069e93f7393Sniklas "Specify maximum number of frames for \"backtrace\" to print by default.",
2070e93f7393Sniklas &setlist);
2071e93f7393Sniklas add_info ("backtrace-limit", backtrace_limit_info,
2072e93f7393Sniklas "The maximum number of frames for \"backtrace\" to print by default.");
2073e93f7393Sniklas #endif
2074e93f7393Sniklas }
2075