gdb/
[deliverable/binutils-gdb.git] / gdb / stack.c
CommitLineData
c906108c 1/* Print and select stack frames for GDB, the GNU debugger.
8926118c 2
6aba47ca 3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
0fb0cc75 4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
7b6bb8da 5 2009, 2010, 2011 Free Software Foundation, Inc.
c906108c 6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c 21
c906108c 22#include "defs.h"
c906108c
SS
23#include "value.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "expression.h"
27#include "language.h"
28#include "frame.h"
29#include "gdbcmd.h"
30#include "gdbcore.h"
31#include "target.h"
0378c332 32#include "source.h"
c906108c
SS
33#include "breakpoint.h"
34#include "demangle.h"
35#include "inferior.h"
36#include "annotate.h"
8b93c638 37#include "ui-out.h"
fe898f56 38#include "block.h"
b9362cc7 39#include "stack.h"
de4f826b 40#include "dictionary.h"
60250e8b 41#include "exceptions.h"
898c62f5 42#include "reggroups.h"
fc70c2a0 43#include "regcache.h"
a77053c2 44#include "solib.h"
033a42c2 45#include "valprint.h"
8ea051c5 46#include "gdbthread.h"
3567439c 47#include "cp-support.h"
30c33a9f 48#include "disasm.h"
edb3359d 49#include "inline-frame.h"
c906108c 50
033a42c2
MK
51#include "gdb_assert.h"
52#include <ctype.h>
53#include "gdb_string.h"
c906108c 54
ccefe4c4
TT
55#include "psymtab.h"
56#include "symfile.h"
57
9a4105ab 58void (*deprecated_selected_frame_level_changed_hook) (int);
c906108c 59
2421fe6f 60/* The possible choices of "set print frame-arguments", and the value
88408340
JB
61 of this setting. */
62
63static const char *print_frame_arguments_choices[] =
64 {"all", "scalars", "none", NULL};
476f7b68 65static const char *print_frame_arguments = "scalars";
88408340 66
e18b2753
JK
67/* The possible choices of "set print entry-values", and the value
68 of this setting. */
69
70const char print_entry_values_no[] = "no";
71const char print_entry_values_only[] = "only";
72const char print_entry_values_preferred[] = "preferred";
73const char print_entry_values_if_needed[] = "if-needed";
74const char print_entry_values_both[] = "both";
75const char print_entry_values_compact[] = "compact";
76const char print_entry_values_default[] = "default";
77static const char *print_entry_values_choices[] =
78{
79 print_entry_values_no,
80 print_entry_values_only,
81 print_entry_values_preferred,
82 print_entry_values_if_needed,
83 print_entry_values_both,
84 print_entry_values_compact,
85 print_entry_values_default,
86 NULL
87};
88const char *print_entry_values = print_entry_values_default;
89
c378eb4e 90/* Prototypes for local functions. */
c906108c 91
d9fcf2fb
JM
92static void print_frame_local_vars (struct frame_info *, int,
93 struct ui_file *);
c906108c 94
033a42c2
MK
95static void print_frame (struct frame_info *frame, int print_level,
96 enum print_what print_what, int print_args,
c5394b80
JM
97 struct symtab_and_line sal);
98
c906108c
SS
99/* Zero means do things normally; we are interacting directly with the
100 user. One means print the full filename and linenumber when a
101 frame is printed, and do so in a format emacs18/emacs19.22 can
102 parse. Two means print similar annotations, but in many more
103 cases and in a slightly different syntax. */
104
105int annotation_level = 0;
c906108c 106\f
c5aa993b 107
edb3359d
DJ
108/* Return 1 if we should display the address in addition to the location,
109 because we are in the middle of a statement. */
110
111static int
112frame_show_address (struct frame_info *frame,
113 struct symtab_and_line sal)
114{
115 /* If there is a line number, but no PC, then there is no location
116 information associated with this sal. The only way that should
117 happen is for the call sites of inlined functions (SAL comes from
118 find_frame_sal). Otherwise, we would have some PC range if the
119 SAL came from a line table. */
120 if (sal.line != 0 && sal.pc == 0 && sal.end == 0)
121 {
122 if (get_next_frame (frame) == NULL)
123 gdb_assert (inline_skipped_frames (inferior_ptid) > 0);
124 else
125 gdb_assert (get_frame_type (get_next_frame (frame)) == INLINE_FRAME);
126 return 0;
127 }
128
129 return get_frame_pc (frame) != sal.pc;
130}
131
033a42c2 132/* Show or print a stack frame FRAME briefly. The output is format
d762c46a
AC
133 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
134 relative level, function name, argument list, and file name and
135 line number. If the frame's PC is not at the beginning of the
136 source line, the actual PC is printed at the beginning. */
c906108c
SS
137
138void
033a42c2 139print_stack_frame (struct frame_info *frame, int print_level,
0faf0076 140 enum print_what print_what)
c906108c 141{
311b5970 142 volatile struct gdb_exception e;
c906108c 143
aaf9e9fd 144 /* For mi, alway print location and address. */
79a45e25 145 if (ui_out_is_mi_like_p (current_uiout))
311b5970 146 print_what = LOC_AND_ADDRESS;
c906108c 147
311b5970
JK
148 TRY_CATCH (e, RETURN_MASK_ERROR)
149 {
150 int center = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
c906108c 151
311b5970
JK
152 print_frame_info (frame, print_level, print_what, 1 /* print_args */);
153 set_current_sal_from_frame (frame, center);
154 }
155}
c906108c 156
033a42c2
MK
157/* Print nameless arguments of frame FRAME on STREAM, where START is
158 the offset of the first nameless argument, and NUM is the number of
159 nameless arguments to print. FIRST is nonzero if this is the first
160 argument (not just the first nameless argument). */
8d3b0994
AC
161
162static void
033a42c2 163print_frame_nameless_args (struct frame_info *frame, long start, int num,
8d3b0994
AC
164 int first, struct ui_file *stream)
165{
e17a4113
UW
166 struct gdbarch *gdbarch = get_frame_arch (frame);
167 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8d3b0994
AC
168 int i;
169 CORE_ADDR argsaddr;
170 long arg_value;
171
172 for (i = 0; i < num; i++)
173 {
174 QUIT;
033a42c2 175 argsaddr = get_frame_args_address (frame);
8d3b0994
AC
176 if (!argsaddr)
177 return;
e17a4113
UW
178 arg_value = read_memory_integer (argsaddr + start,
179 sizeof (int), byte_order);
8d3b0994
AC
180 if (!first)
181 fprintf_filtered (stream, ", ");
182 fprintf_filtered (stream, "%ld", arg_value);
183 first = 0;
184 start += sizeof (int);
185 }
186}
187
93d86cef
JK
188/* Print single argument of inferior function. ARG must be already
189 read in.
190
191 Errors are printed as if they would be the parameter value. Use zeroed ARG
192 iff it should not be printed accoring to user settings. */
193
194static void
195print_frame_arg (const struct frame_arg *arg)
196{
197 struct ui_out *uiout = current_uiout;
198 volatile struct gdb_exception except;
199 struct cleanup *old_chain;
200 struct ui_stream *stb;
201
202 stb = ui_out_stream_new (uiout);
203 old_chain = make_cleanup_ui_out_stream_delete (stb);
204
205 gdb_assert (!arg->val || !arg->error);
e18b2753
JK
206 gdb_assert (arg->entry_kind == print_entry_values_no
207 || arg->entry_kind == print_entry_values_only
208 || (!ui_out_is_mi_like_p (uiout)
209 && arg->entry_kind == print_entry_values_compact));
93d86cef
JK
210
211 annotate_arg_begin ();
212
213 make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
214 fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
215 SYMBOL_LANGUAGE (arg->sym), DMGL_PARAMS | DMGL_ANSI);
e18b2753
JK
216 if (arg->entry_kind == print_entry_values_compact)
217 {
218 /* It is OK to provide invalid MI-like stream as with
219 PRINT_ENTRY_VALUE_COMPACT we never use MI. */
220 fputs_filtered ("=", stb->stream);
221
222 fprintf_symbol_filtered (stb->stream, SYMBOL_PRINT_NAME (arg->sym),
223 SYMBOL_LANGUAGE (arg->sym),
224 DMGL_PARAMS | DMGL_ANSI);
225 }
226 if (arg->entry_kind == print_entry_values_only
227 || arg->entry_kind == print_entry_values_compact)
228 fputs_filtered ("@entry", stb->stream);
93d86cef
JK
229 ui_out_field_stream (uiout, "name", stb);
230 annotate_arg_name_end ();
231 ui_out_text (uiout, "=");
232
233 if (!arg->val && !arg->error)
234 ui_out_text (uiout, "...");
235 else
236 {
237 if (arg->error)
238 except.message = arg->error;
239 else
240 {
241 /* TRY_CATCH has two statements, wrap it in a block. */
242
243 TRY_CATCH (except, RETURN_MASK_ERROR)
244 {
245 const struct language_defn *language;
246 struct value_print_options opts;
247
248 /* Avoid value_print because it will deref ref parameters. We
249 just want to print their addresses. Print ??? for args whose
250 address we do not know. We pass 2 as "recurse" to val_print
251 because our standard indentation here is 4 spaces, and
252 val_print indents 2 for each recurse. */
253
254 annotate_arg_value (value_type (arg->val));
255
256 /* Use the appropriate language to display our symbol, unless the
257 user forced the language to a specific language. */
258 if (language_mode == language_mode_auto)
259 language = language_def (SYMBOL_LANGUAGE (arg->sym));
260 else
261 language = current_language;
262
263 get_raw_print_options (&opts);
3343315b 264 opts.deref_ref = 1;
93d86cef
JK
265
266 /* True in "summary" mode, false otherwise. */
267 opts.summary = !strcmp (print_frame_arguments, "scalars");
268
269 common_val_print (arg->val, stb->stream, 2, &opts, language);
270 }
271 }
272 if (except.message)
273 fprintf_filtered (stb->stream, _("<error reading variable: %s>"),
274 except.message);
275 }
276
277 ui_out_field_stream (uiout, "value", stb);
278
279 /* Aleo invoke ui_out_tuple_end. */
280 do_cleanups (old_chain);
281
282 annotate_arg_end ();
283}
284
285/* Read in inferior function parameter SYM at FRAME into ARGP. Caller is
286 responsible for xfree of ARGP->ERROR. This function never throws an
287 exception. */
288
289void
290read_frame_arg (struct symbol *sym, struct frame_info *frame,
e18b2753 291 struct frame_arg *argp, struct frame_arg *entryargp)
93d86cef 292{
e18b2753
JK
293 struct value *val = NULL, *entryval = NULL;
294 char *val_error = NULL, *entryval_error = NULL;
295 int val_equal = 0;
93d86cef
JK
296 volatile struct gdb_exception except;
297
e18b2753
JK
298 if (print_entry_values != print_entry_values_only
299 && print_entry_values != print_entry_values_preferred)
300 {
301 TRY_CATCH (except, RETURN_MASK_ERROR)
302 {
303 val = read_var_value (sym, frame);
304 }
305 if (!val)
306 {
307 val_error = alloca (strlen (except.message) + 1);
308 strcpy (val_error, except.message);
309 }
310 }
311
312 if (SYMBOL_CLASS (sym) == LOC_COMPUTED
313 && print_entry_values != print_entry_values_no
314 && (print_entry_values != print_entry_values_if_needed
315 || !val || value_optimized_out (val)))
316 {
317 TRY_CATCH (except, RETURN_MASK_ERROR)
318 {
319 const struct symbol_computed_ops *ops;
320
321 ops = SYMBOL_COMPUTED_OPS (sym);
322 entryval = ops->read_variable_at_entry (sym, frame);
323 }
324 if (!entryval)
325 {
326 entryval_error = alloca (strlen (except.message) + 1);
327 strcpy (entryval_error, except.message);
328 }
329
330 if (except.error == NO_ENTRY_VALUE_ERROR
331 || (entryval && value_optimized_out (entryval)))
332 {
333 entryval = NULL;
334 entryval_error = NULL;
335 }
336
337 if (print_entry_values == print_entry_values_compact
338 || print_entry_values == print_entry_values_default)
339 {
340 /* For MI do not try to use print_entry_values_compact for ARGP. */
341
342 if (val && entryval && !ui_out_is_mi_like_p (current_uiout))
343 {
344 unsigned len = TYPE_LENGTH (value_type (val));
345
346 if (!value_optimized_out (val) && value_lazy (val))
347 value_fetch_lazy (val);
348 if (!value_optimized_out (val) && value_lazy (entryval))
349 value_fetch_lazy (entryval);
350 if (!value_optimized_out (val)
351 && value_available_contents_eq (val, 0, entryval, 0, len))
352 {
a471c594
JK
353 struct value *val_deref, *entryval_deref;
354
355 /* DW_AT_GNU_call_site_value does match with the current
356 value. If it is a reference still try to verify if
357 dereferenced DW_AT_GNU_call_site_data_value does not
358 differ. */
359
360 TRY_CATCH (except, RETURN_MASK_ERROR)
361 {
362 unsigned len_deref;
363
364 val_deref = coerce_ref (val);
365 if (value_lazy (val_deref))
366 value_fetch_lazy (val_deref);
367 len_deref = TYPE_LENGTH (value_type (val_deref));
368
369 entryval_deref = coerce_ref (entryval);
370 if (value_lazy (entryval_deref))
371 value_fetch_lazy (entryval_deref);
372
373 /* If the reference addresses match but dereferenced
374 content does not match print them. */
375 if (val != val_deref
376 && value_available_contents_eq (val_deref, 0,
377 entryval_deref, 0,
378 len_deref))
379 val_equal = 1;
380 }
381
382 /* Value was not a reference; and its content matches. */
383 if (val == val_deref)
384 val_equal = 1;
385 /* If the dereferenced content could not be fetched do not
386 display anything. */
387 else if (except.error == NO_ENTRY_VALUE_ERROR)
388 val_equal = 1;
389 else if (except.message)
390 {
391 entryval_error = alloca (strlen (except.message) + 1);
392 strcpy (entryval_error, except.message);
393 }
394
395 if (val_equal)
396 entryval = NULL;
e18b2753
JK
397 }
398 }
399
400 /* Try to remove possibly duplicate error message for ENTRYARGP even
401 in MI mode. */
402
403 if (val_error && entryval_error
404 && strcmp (val_error, entryval_error) == 0)
405 {
406 entryval_error = NULL;
407
408 /* Do not se VAL_EQUAL as the same error message may be shown for
409 the entry value even if no entry values are present in the
410 inferior. */
411 }
412 }
413 }
414
415 if (entryval == NULL)
93d86cef 416 {
e18b2753
JK
417 if (print_entry_values == print_entry_values_preferred)
418 {
419 TRY_CATCH (except, RETURN_MASK_ERROR)
420 {
421 val = read_var_value (sym, frame);
422 }
423 if (!val)
424 {
425 val_error = alloca (strlen (except.message) + 1);
426 strcpy (val_error, except.message);
427 }
428 }
429 if (print_entry_values == print_entry_values_only
430 || print_entry_values == print_entry_values_both
431 || (print_entry_values == print_entry_values_preferred
432 && (!val || value_optimized_out (val))))
433 entryval = allocate_optimized_out_value (SYMBOL_TYPE (sym));
93d86cef 434 }
e18b2753
JK
435 if ((print_entry_values == print_entry_values_compact
436 || print_entry_values == print_entry_values_if_needed
437 || print_entry_values == print_entry_values_preferred)
438 && (!val || value_optimized_out (val)) && entryval != NULL)
93d86cef 439 {
e18b2753
JK
440 val = NULL;
441 val_error = NULL;
93d86cef
JK
442 }
443
444 argp->sym = sym;
445 argp->val = val;
446 argp->error = val_error ? xstrdup (val_error) : NULL;
e18b2753
JK
447 if (!val && !val_error)
448 argp->entry_kind = print_entry_values_only;
449 else if ((print_entry_values == print_entry_values_compact
450 || print_entry_values == print_entry_values_default) && val_equal)
451 {
452 argp->entry_kind = print_entry_values_compact;
453 gdb_assert (!ui_out_is_mi_like_p (current_uiout));
454 }
455 else
456 argp->entry_kind = print_entry_values_no;
457
458 entryargp->sym = sym;
459 entryargp->val = entryval;
460 entryargp->error = entryval_error ? xstrdup (entryval_error) : NULL;
461 if (!entryval && !entryval_error)
462 entryargp->entry_kind = print_entry_values_no;
463 else
464 entryargp->entry_kind = print_entry_values_only;
93d86cef
JK
465}
466
033a42c2
MK
467/* Print the arguments of frame FRAME on STREAM, given the function
468 FUNC running in that frame (as a symbol), where NUM is the number
469 of arguments according to the stack frame (or -1 if the number of
470 arguments is unknown). */
8d3b0994 471
e3168615 472/* Note that currently the "number of arguments according to the
033a42c2 473 stack frame" is only known on VAX where i refers to the "number of
e3168615 474 ints of arguments according to the stack frame". */
8d3b0994
AC
475
476static void
033a42c2
MK
477print_frame_args (struct symbol *func, struct frame_info *frame,
478 int num, struct ui_file *stream)
8d3b0994 479{
79a45e25 480 struct ui_out *uiout = current_uiout;
8d3b0994 481 int first = 1;
8d3b0994 482 /* Offset of next stack argument beyond the one we have seen that is
033a42c2
MK
483 at the highest offset, or -1 if we haven't come to a stack
484 argument yet. */
8d3b0994 485 long highest_offset = -1;
8d3b0994
AC
486 /* Number of ints of arguments that we have printed so far. */
487 int args_printed = 0;
488 struct cleanup *old_chain, *list_chain;
489 struct ui_stream *stb;
a6bac58e
TT
490 /* True if we should print arguments, false otherwise. */
491 int print_args = strcmp (print_frame_arguments, "none");
492 /* True in "summary" mode, false otherwise. */
493 int summary = !strcmp (print_frame_arguments, "scalars");
8d3b0994
AC
494
495 stb = ui_out_stream_new (uiout);
496 old_chain = make_cleanup_ui_out_stream_delete (stb);
497
498 if (func)
499 {
033a42c2
MK
500 struct block *b = SYMBOL_BLOCK_VALUE (func);
501 struct dict_iterator iter;
502 struct symbol *sym;
8d3b0994 503
de4f826b 504 ALL_BLOCK_SYMBOLS (b, iter, sym)
8d3b0994 505 {
e18b2753 506 struct frame_arg arg, entryarg;
93d86cef 507
8d3b0994
AC
508 QUIT;
509
510 /* Keep track of the highest stack argument offset seen, and
511 skip over any kinds of symbols we don't care about. */
512
2a2d4dc3
AS
513 if (!SYMBOL_IS_ARGUMENT (sym))
514 continue;
515
8d3b0994
AC
516 switch (SYMBOL_CLASS (sym))
517 {
518 case LOC_ARG:
519 case LOC_REF_ARG:
520 {
521 long current_offset = SYMBOL_VALUE (sym);
033a42c2 522 int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
8d3b0994
AC
523
524 /* Compute address of next argument by adding the size of
525 this argument and rounding to an int boundary. */
526 current_offset =
527 ((current_offset + arg_size + sizeof (int) - 1)
528 & ~(sizeof (int) - 1));
529
033a42c2
MK
530 /* If this is the highest offset seen yet, set
531 highest_offset. */
8d3b0994
AC
532 if (highest_offset == -1
533 || (current_offset > highest_offset))
534 highest_offset = current_offset;
535
033a42c2
MK
536 /* Add the number of ints we're about to print to
537 args_printed. */
8d3b0994
AC
538 args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
539 }
540
033a42c2
MK
541 /* We care about types of symbols, but don't need to
542 keep track of stack offsets in them. */
2a2d4dc3 543 case LOC_REGISTER:
8d3b0994 544 case LOC_REGPARM_ADDR:
2a2d4dc3
AS
545 case LOC_COMPUTED:
546 case LOC_OPTIMIZED_OUT:
8d3b0994 547 default:
2a2d4dc3 548 break;
8d3b0994
AC
549 }
550
551 /* We have to look up the symbol because arguments can have
552 two entries (one a parameter, one a local) and the one we
553 want is the local, which lookup_symbol will find for us.
033a42c2 554 This includes gcc1 (not gcc2) on SPARC when passing a
8d3b0994
AC
555 small structure and gcc2 when the argument type is float
556 and it is passed as a double and converted to float by
557 the prologue (in the latter case the type of the LOC_ARG
558 symbol is double and the type of the LOC_LOCAL symbol is
559 float). */
033a42c2
MK
560 /* But if the parameter name is null, don't try it. Null
561 parameter names occur on the RS/6000, for traceback
562 tables. FIXME, should we even print them? */
8d3b0994 563
3567439c 564 if (*SYMBOL_LINKAGE_NAME (sym))
8d3b0994
AC
565 {
566 struct symbol *nsym;
433759f7 567
3567439c 568 nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
2570f2b7 569 b, VAR_DOMAIN, NULL);
55765a25 570 gdb_assert (nsym != NULL);
2a2d4dc3
AS
571 if (SYMBOL_CLASS (nsym) == LOC_REGISTER
572 && !SYMBOL_IS_ARGUMENT (nsym))
8d3b0994 573 {
033a42c2
MK
574 /* There is a LOC_ARG/LOC_REGISTER pair. This means
575 that it was passed on the stack and loaded into a
576 register, or passed in a register and stored in a
577 stack slot. GDB 3.x used the LOC_ARG; GDB
578 4.0-4.11 used the LOC_REGISTER.
8d3b0994
AC
579
580 Reasons for using the LOC_ARG:
033a42c2
MK
581
582 (1) Because find_saved_registers may be slow for
583 remote debugging.
584
585 (2) Because registers are often re-used and stack
586 slots rarely (never?) are. Therefore using
587 the stack slot is much less likely to print
588 garbage.
8d3b0994
AC
589
590 Reasons why we might want to use the LOC_REGISTER:
033a42c2
MK
591
592 (1) So that the backtrace prints the same value
593 as "print foo". I see no compelling reason
594 why this needs to be the case; having the
595 backtrace print the value which was passed
596 in, and "print foo" print the value as
597 modified within the called function, makes
598 perfect sense to me.
599
600 Additional note: It might be nice if "info args"
601 displayed both values.
602
603 One more note: There is a case with SPARC
604 structure passing where we need to use the
605 LOC_REGISTER, but this is dealt with by creating
606 a single LOC_REGPARM in symbol reading. */
8d3b0994
AC
607
608 /* Leave sym (the LOC_ARG) alone. */
609 ;
610 }
611 else
612 sym = nsym;
613 }
614
615 /* Print the current arg. */
616 if (!first)
617 ui_out_text (uiout, ", ");
618 ui_out_wrap_hint (uiout, " ");
619
93d86cef
JK
620 if (!print_args)
621 {
622 memset (&arg, 0, sizeof (arg));
623 arg.sym = sym;
e18b2753
JK
624 arg.entry_kind = print_entry_values_no;
625 memset (&entryarg, 0, sizeof (entryarg));
626 entryarg.sym = sym;
627 entryarg.entry_kind = print_entry_values_no;
93d86cef
JK
628 }
629 else
e18b2753 630 read_frame_arg (sym, frame, &arg, &entryarg);
8d3b0994 631
e18b2753
JK
632 if (arg.entry_kind != print_entry_values_only)
633 print_frame_arg (&arg);
634
635 if (entryarg.entry_kind != print_entry_values_no)
636 {
637 if (arg.entry_kind != print_entry_values_only)
638 {
639 ui_out_text (uiout, ", ");
640 ui_out_wrap_hint (uiout, " ");
641 }
642
643 print_frame_arg (&entryarg);
644 }
8d3b0994 645
93d86cef 646 xfree (arg.error);
e18b2753 647 xfree (entryarg.error);
8d3b0994
AC
648
649 first = 0;
650 }
651 }
652
653 /* Don't print nameless args in situations where we don't know
654 enough about the stack to find them. */
655 if (num != -1)
656 {
657 long start;
658
659 if (highest_offset == -1)
7500260a 660 start = gdbarch_frame_args_skip (get_frame_arch (frame));
8d3b0994
AC
661 else
662 start = highest_offset;
663
033a42c2 664 print_frame_nameless_args (frame, start, num - args_printed,
8d3b0994
AC
665 first, stream);
666 }
033a42c2 667
8d3b0994
AC
668 do_cleanups (old_chain);
669}
670
033a42c2
MK
671/* Set the current source and line to the location given by frame
672 FRAME, if possible. When CENTER is true, adjust so the relevant
673 line is in the center of the next 'list'. */
c789492a 674
7abfe014 675void
033a42c2 676set_current_sal_from_frame (struct frame_info *frame, int center)
c789492a
FL
677{
678 struct symtab_and_line sal;
679
033a42c2 680 find_frame_sal (frame, &sal);
c789492a
FL
681 if (sal.symtab)
682 {
683 if (center)
684 sal.line = max (sal.line - get_lines_to_list () / 2, 1);
685 set_current_source_symtab_and_line (&sal);
686 }
687}
688
30c33a9f
HZ
689/* If ON, GDB will display disassembly of the next source line when
690 execution of the program being debugged stops.
481df73e
HZ
691 If AUTO (which is the default), or there's no line info to determine
692 the source line of the next instruction, display disassembly of next
693 instruction instead. */
30c33a9f
HZ
694
695static enum auto_boolean disassemble_next_line;
696
697static void
698show_disassemble_next_line (struct ui_file *file, int from_tty,
699 struct cmd_list_element *c,
700 const char *value)
701{
3e43a32a
MS
702 fprintf_filtered (file,
703 _("Debugger's willingness to use "
704 "disassemble-next-line is %s.\n"),
30c33a9f
HZ
705 value);
706}
707
30c33a9f
HZ
708/* Use TRY_CATCH to catch the exception from the gdb_disassembly
709 because it will be broken by filter sometime. */
710
711static void
13274fc3
UW
712do_gdb_disassembly (struct gdbarch *gdbarch,
713 int how_many, CORE_ADDR low, CORE_ADDR high)
30c33a9f
HZ
714{
715 volatile struct gdb_exception exception;
30c33a9f 716
b1d288d3 717 TRY_CATCH (exception, RETURN_MASK_ERROR)
30c33a9f 718 {
79a45e25
PA
719 gdb_disassembly (gdbarch, current_uiout, 0,
720 DISASSEMBLY_RAW_INSN, how_many,
721 low, high);
30c33a9f 722 }
b1d288d3
JK
723 if (exception.reason < 0)
724 {
725 /* If an exception was thrown while doing the disassembly, print
726 the error message, to give the user a clue of what happened. */
727 exception_print (gdb_stderr, exception);
728 }
30c33a9f
HZ
729}
730
033a42c2 731/* Print information about frame FRAME. The output is format according
65aa373f 732 to PRINT_LEVEL and PRINT_WHAT and PRINT_ARGS. The meaning of
033a42c2
MK
733 PRINT_WHAT is:
734
735 SRC_LINE: Print only source line.
736 LOCATION: Print only location.
737 LOC_AND_SRC: Print location and source line.
738
739 Used in "where" output, and to emit breakpoint or step
740 messages. */
c906108c 741
7789c6f5 742void
033a42c2 743print_frame_info (struct frame_info *frame, int print_level,
0faf0076 744 enum print_what print_what, int print_args)
c906108c 745{
5af949e3 746 struct gdbarch *gdbarch = get_frame_arch (frame);
c906108c 747 struct symtab_and_line sal;
c5394b80
JM
748 int source_print;
749 int location_print;
79a45e25 750 struct ui_out *uiout = current_uiout;
c906108c 751
033a42c2 752 if (get_frame_type (frame) == DUMMY_FRAME
36f15f55
UW
753 || get_frame_type (frame) == SIGTRAMP_FRAME
754 || get_frame_type (frame) == ARCH_FRAME)
c906108c 755 {
075559bc
AC
756 struct cleanup *uiout_cleanup
757 = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
c906108c 758
033a42c2 759 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
5af949e3 760 gdbarch, get_frame_pc (frame));
6a3fe0a4 761
c906108c 762 /* Do this regardless of SOURCE because we don't have any source
c5aa993b 763 to list for this frame. */
0faf0076 764 if (print_level)
52c6a6ac
JJ
765 {
766 ui_out_text (uiout, "#");
0faf0076 767 ui_out_field_fmt_int (uiout, 2, ui_left, "level",
033a42c2 768 frame_relative_level (frame));
52c6a6ac 769 }
075559bc 770 if (ui_out_is_mi_like_p (uiout))
52c6a6ac 771 {
075559bc 772 annotate_frame_address ();
5af949e3
UW
773 ui_out_field_core_addr (uiout, "addr",
774 gdbarch, get_frame_pc (frame));
075559bc 775 annotate_frame_address_end ();
52c6a6ac 776 }
6a3fe0a4 777
033a42c2 778 if (get_frame_type (frame) == DUMMY_FRAME)
075559bc
AC
779 {
780 annotate_function_call ();
781 ui_out_field_string (uiout, "func", "<function called from gdb>");
782 }
033a42c2 783 else if (get_frame_type (frame) == SIGTRAMP_FRAME)
075559bc
AC
784 {
785 annotate_signal_handler_caller ();
786 ui_out_field_string (uiout, "func", "<signal handler called>");
787 }
36f15f55
UW
788 else if (get_frame_type (frame) == ARCH_FRAME)
789 {
790 ui_out_field_string (uiout, "func", "<cross-architecture call>");
791 }
075559bc 792 ui_out_text (uiout, "\n");
c906108c 793 annotate_frame_end ();
075559bc
AC
794
795 do_cleanups (uiout_cleanup);
c906108c
SS
796 return;
797 }
798
033a42c2
MK
799 /* If FRAME is not the innermost frame, that normally means that
800 FRAME->pc points to *after* the call instruction, and we want to
801 get the line containing the call, never the next line. But if
802 the next frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the
803 next frame was not entered as the result of a call, and we want
804 to get the line containing FRAME->pc. */
805 find_frame_sal (frame, &sal);
c906108c 806
0faf0076
AC
807 location_print = (print_what == LOCATION
808 || print_what == LOC_AND_ADDRESS
809 || print_what == SRC_AND_LOC);
c5394b80
JM
810
811 if (location_print || !sal.symtab)
033a42c2 812 print_frame (frame, print_level, print_what, print_args, sal);
c5394b80 813
0faf0076 814 source_print = (print_what == SRC_LINE || print_what == SRC_AND_LOC);
0378c332 815
30c33a9f
HZ
816 /* If disassemble-next-line is set to auto or on and doesn't have
817 the line debug messages for $pc, output the next instruction. */
818 if ((disassemble_next_line == AUTO_BOOLEAN_AUTO
819 || disassemble_next_line == AUTO_BOOLEAN_TRUE)
820 && source_print && !sal.symtab)
13274fc3
UW
821 do_gdb_disassembly (get_frame_arch (frame), 1,
822 get_frame_pc (frame), get_frame_pc (frame) + 1);
30c33a9f 823
c5394b80
JM
824 if (source_print && sal.symtab)
825 {
826 int done = 0;
0faf0076 827 int mid_statement = ((print_what == SRC_LINE)
edb3359d 828 && frame_show_address (frame, sal));
c5394b80
JM
829
830 if (annotation_level)
831 done = identify_source_line (sal.symtab, sal.line, mid_statement,
033a42c2 832 get_frame_pc (frame));
c5394b80
JM
833 if (!done)
834 {
9a4105ab 835 if (deprecated_print_frame_info_listing_hook)
cbd3c883
MS
836 deprecated_print_frame_info_listing_hook (sal.symtab,
837 sal.line,
838 sal.line + 1, 0);
ba4bbdcb 839 else
c5394b80 840 {
79a45b7d 841 struct value_print_options opts;
433759f7 842
79a45b7d 843 get_user_print_options (&opts);
ba4bbdcb 844 /* We used to do this earlier, but that is clearly
c378eb4e 845 wrong. This function is used by many different
ba4bbdcb
KS
846 parts of gdb, including normal_stop in infrun.c,
847 which uses this to print out the current PC
848 when we stepi/nexti into the middle of a source
c378eb4e
MS
849 line. Only the command line really wants this
850 behavior. Other UIs probably would like the
cbd3c883 851 ability to decide for themselves if it is desired. */
79a45b7d 852 if (opts.addressprint && mid_statement)
ba4bbdcb 853 {
5af949e3
UW
854 ui_out_field_core_addr (uiout, "addr",
855 gdbarch, get_frame_pc (frame));
ba4bbdcb 856 ui_out_text (uiout, "\t");
ba4bbdcb
KS
857 }
858
859 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
c5394b80 860 }
c5394b80 861 }
30c33a9f
HZ
862
863 /* If disassemble-next-line is set to on and there is line debug
864 messages, output assembly codes for next line. */
865 if (disassemble_next_line == AUTO_BOOLEAN_TRUE)
2b28d209 866 do_gdb_disassembly (get_frame_arch (frame), -1, sal.pc, sal.end);
c5394b80
JM
867 }
868
0faf0076 869 if (print_what != LOCATION)
e3eebbd7
PA
870 {
871 CORE_ADDR pc;
872
873 if (get_frame_pc_if_available (frame, &pc))
874 set_default_breakpoint (1, sal.pspace, pc, sal.symtab, sal.line);
875 else
876 set_default_breakpoint (0, 0, 0, 0, 0);
877 }
c5394b80
JM
878
879 annotate_frame_end ();
880
881 gdb_flush (gdb_stdout);
882}
883
e9e07ba6
JK
884/* Attempt to obtain the FUNNAME, FUNLANG and optionally FUNCP of the function
885 corresponding to FRAME. */
886
f8f6f20b
TJB
887void
888find_frame_funname (struct frame_info *frame, char **funname,
e9e07ba6 889 enum language *funlang, struct symbol **funcp)
c5394b80
JM
890{
891 struct symbol *func;
8b93c638 892
f8f6f20b
TJB
893 *funname = NULL;
894 *funlang = language_unknown;
e9e07ba6
JK
895 if (funcp)
896 *funcp = NULL;
c5394b80 897
edb3359d 898 func = get_frame_function (frame);
c906108c
SS
899 if (func)
900 {
901 /* In certain pathological cases, the symtabs give the wrong
c5aa993b
JM
902 function (when we are in the first function in a file which
903 is compiled without debugging symbols, the previous function
904 is compiled with debugging symbols, and the "foo.o" symbol
033a42c2
MK
905 that is supposed to tell us where the file with debugging
906 symbols ends has been truncated by ar because it is longer
907 than 15 characters). This also occurs if the user uses asm()
908 to create a function but not stabs for it (in a file compiled
909 with -g).
c5aa993b
JM
910
911 So look in the minimal symbol tables as well, and if it comes
912 up with a larger address for the function use that instead.
033a42c2
MK
913 I don't think this can ever cause any problems; there
914 shouldn't be any minimal symbols in the middle of a function;
915 if this is ever changed many parts of GDB will need to be
916 changed (and we'll create a find_pc_minimal_function or some
917 such). */
918
edb3359d
DJ
919 struct minimal_symbol *msymbol = NULL;
920
921 /* Don't attempt to do this for inlined functions, which do not
922 have a corresponding minimal symbol. */
923 if (!block_inlined_p (SYMBOL_BLOCK_VALUE (func)))
924 msymbol
925 = lookup_minimal_symbol_by_pc (get_frame_address_in_block (frame));
c906108c 926
c906108c 927 if (msymbol != NULL
c5aa993b 928 && (SYMBOL_VALUE_ADDRESS (msymbol)
c906108c
SS
929 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
930 {
c906108c
SS
931 /* We also don't know anything about the function besides
932 its address and name. */
933 func = 0;
f8f6f20b
TJB
934 *funname = SYMBOL_PRINT_NAME (msymbol);
935 *funlang = SYMBOL_LANGUAGE (msymbol);
c906108c
SS
936 }
937 else
938 {
f8f6f20b
TJB
939 *funname = SYMBOL_PRINT_NAME (func);
940 *funlang = SYMBOL_LANGUAGE (func);
e9e07ba6
JK
941 if (funcp)
942 *funcp = func;
f8f6f20b 943 if (*funlang == language_cplus)
c5aa993b 944 {
033a42c2
MK
945 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
946 to display the demangled name that we already have
947 stored in the symbol table, but we stored a version
948 with DMGL_PARAMS turned on, and here we don't want to
3567439c 949 display parameters. So remove the parameters. */
f8f6f20b 950 char *func_only = cp_remove_params (*funname);
433759f7 951
3567439c
DJ
952 if (func_only)
953 {
f8f6f20b 954 *funname = func_only;
3567439c
DJ
955 make_cleanup (xfree, func_only);
956 }
c5aa993b 957 }
c906108c
SS
958 }
959 }
960 else
961 {
e3eebbd7
PA
962 struct minimal_symbol *msymbol;
963 CORE_ADDR pc;
033a42c2 964
e3eebbd7
PA
965 if (!get_frame_address_in_block_if_available (frame, &pc))
966 return;
967
968 msymbol = lookup_minimal_symbol_by_pc (pc);
c906108c
SS
969 if (msymbol != NULL)
970 {
f8f6f20b
TJB
971 *funname = SYMBOL_PRINT_NAME (msymbol);
972 *funlang = SYMBOL_LANGUAGE (msymbol);
c906108c
SS
973 }
974 }
f8f6f20b
TJB
975}
976
977static void
978print_frame (struct frame_info *frame, int print_level,
979 enum print_what print_what, int print_args,
980 struct symtab_and_line sal)
981{
5af949e3 982 struct gdbarch *gdbarch = get_frame_arch (frame);
79a45e25 983 struct ui_out *uiout = current_uiout;
f8f6f20b
TJB
984 char *funname = NULL;
985 enum language funlang = language_unknown;
986 struct ui_stream *stb;
987 struct cleanup *old_chain, *list_chain;
988 struct value_print_options opts;
e9e07ba6 989 struct symbol *func;
e3eebbd7
PA
990 CORE_ADDR pc = 0;
991 int pc_p;
992
993 pc_p = get_frame_pc_if_available (frame, &pc);
f8f6f20b
TJB
994
995 stb = ui_out_stream_new (uiout);
996 old_chain = make_cleanup_ui_out_stream_delete (stb);
997
e9e07ba6 998 find_frame_funname (frame, &funname, &funlang, &func);
c906108c 999
033a42c2 1000 annotate_frame_begin (print_level ? frame_relative_level (frame) : 0,
e3eebbd7 1001 gdbarch, pc);
c5394b80 1002
666547aa 1003 list_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");
c5394b80 1004
0faf0076 1005 if (print_level)
8b93c638 1006 {
8b93c638 1007 ui_out_text (uiout, "#");
0faf0076 1008 ui_out_field_fmt_int (uiout, 2, ui_left, "level",
033a42c2 1009 frame_relative_level (frame));
8b93c638 1010 }
79a45b7d
TT
1011 get_user_print_options (&opts);
1012 if (opts.addressprint)
e3eebbd7
PA
1013 if (!sal.symtab
1014 || frame_show_address (frame, sal)
0faf0076 1015 || print_what == LOC_AND_ADDRESS)
c5394b80
JM
1016 {
1017 annotate_frame_address ();
e3eebbd7
PA
1018 if (pc_p)
1019 ui_out_field_core_addr (uiout, "addr", gdbarch, pc);
1020 else
1021 ui_out_field_string (uiout, "addr", "<unavailable>");
8b93c638
JM
1022 annotate_frame_address_end ();
1023 ui_out_text (uiout, " in ");
c5394b80
JM
1024 }
1025 annotate_frame_function_name ();
033a42c2
MK
1026 fprintf_symbol_filtered (stb->stream, funname ? funname : "??",
1027 funlang, DMGL_ANSI);
8b93c638
JM
1028 ui_out_field_stream (uiout, "func", stb);
1029 ui_out_wrap_hint (uiout, " ");
c5394b80
JM
1030 annotate_frame_args ();
1031
8b93c638 1032 ui_out_text (uiout, " (");
0faf0076 1033 if (print_args)
c906108c 1034 {
311b5970
JK
1035 struct gdbarch *gdbarch = get_frame_arch (frame);
1036 int numargs;
d493eb33 1037 struct cleanup *args_list_chain;
311b5970 1038 volatile struct gdb_exception e;
433759f7 1039
311b5970
JK
1040 if (gdbarch_frame_num_args_p (gdbarch))
1041 {
1042 numargs = gdbarch_frame_num_args (gdbarch, frame);
1043 gdb_assert (numargs >= 0);
1044 }
1045 else
1046 numargs = -1;
1047
68c81b54 1048 args_list_chain = make_cleanup_ui_out_list_begin_end (uiout, "args");
311b5970
JK
1049 TRY_CATCH (e, RETURN_MASK_ERROR)
1050 {
1051 print_frame_args (func, frame, numargs, gdb_stdout);
1052 }
c378eb4e 1053 /* FIXME: ARGS must be a list. If one argument is a string it
033a42c2 1054 will have " that will not be properly escaped. */
666547aa 1055 /* Invoke ui_out_tuple_end. */
d493eb33 1056 do_cleanups (args_list_chain);
c5394b80
JM
1057 QUIT;
1058 }
8b93c638 1059 ui_out_text (uiout, ")");
c5394b80
JM
1060 if (sal.symtab && sal.symtab->filename)
1061 {
1062 annotate_frame_source_begin ();
8b93c638
JM
1063 ui_out_wrap_hint (uiout, " ");
1064 ui_out_text (uiout, " at ");
1065 annotate_frame_source_file ();
1066 ui_out_field_string (uiout, "file", sal.symtab->filename);
76ff342d
DJ
1067 if (ui_out_is_mi_like_p (uiout))
1068 {
1069 const char *fullname = symtab_to_fullname (sal.symtab);
433759f7 1070
76ff342d
DJ
1071 if (fullname != NULL)
1072 ui_out_field_string (uiout, "fullname", fullname);
1073 }
8b93c638
JM
1074 annotate_frame_source_file_end ();
1075 ui_out_text (uiout, ":");
1076 annotate_frame_source_line ();
1077 ui_out_field_int (uiout, "line", sal.line);
c5394b80
JM
1078 annotate_frame_source_end ();
1079 }
c906108c 1080
e3eebbd7 1081 if (pc_p && (!funname || (!sal.symtab || !sal.symtab->filename)))
c906108c 1082 {
a77053c2 1083#ifdef PC_SOLIB
033a42c2 1084 char *lib = PC_SOLIB (get_frame_pc (frame));
a77053c2 1085#else
6c95b8df
PA
1086 char *lib = solib_name_from_address (get_frame_program_space (frame),
1087 get_frame_pc (frame));
a77053c2 1088#endif
c5394b80 1089 if (lib)
c906108c 1090 {
c5394b80 1091 annotate_frame_where ();
8b93c638
JM
1092 ui_out_wrap_hint (uiout, " ");
1093 ui_out_text (uiout, " from ");
1094 ui_out_field_string (uiout, "from", lib);
c906108c 1095 }
c906108c 1096 }
e514a9d6 1097
666547aa 1098 /* do_cleanups will call ui_out_tuple_end() for us. */
e6e0bfab 1099 do_cleanups (list_chain);
8b93c638
JM
1100 ui_out_text (uiout, "\n");
1101 do_cleanups (old_chain);
c906108c
SS
1102}
1103\f
c5aa993b 1104
033a42c2
MK
1105/* Read a frame specification in whatever the appropriate format is
1106 from FRAME_EXP. Call error(), printing MESSAGE, if the
1107 specification is in any way invalid (so this function never returns
1108 NULL). When SEPECTED_P is non-NULL set its target to indicate that
1109 the default selected frame was used. */
c906108c 1110
1c8831c5
AC
1111static struct frame_info *
1112parse_frame_specification_1 (const char *frame_exp, const char *message,
1113 int *selected_frame_p)
c906108c 1114{
1c8831c5
AC
1115 int numargs;
1116 struct value *args[4];
1117 CORE_ADDR addrs[ARRAY_SIZE (args)];
c5aa993b 1118
1c8831c5
AC
1119 if (frame_exp == NULL)
1120 numargs = 0;
1121 else
c906108c 1122 {
1c8831c5
AC
1123 numargs = 0;
1124 while (1)
c906108c 1125 {
1c8831c5
AC
1126 char *addr_string;
1127 struct cleanup *cleanup;
1128 const char *p;
1129
1130 /* Skip leading white space, bail of EOL. */
1131 while (isspace (*frame_exp))
1132 frame_exp++;
1133 if (!*frame_exp)
1134 break;
c906108c 1135
1c8831c5
AC
1136 /* Parse the argument, extract it, save it. */
1137 for (p = frame_exp;
1138 *p && !isspace (*p);
1139 p++);
1140 addr_string = savestring (frame_exp, p - frame_exp);
c906108c 1141 frame_exp = p;
1c8831c5
AC
1142 cleanup = make_cleanup (xfree, addr_string);
1143
1144 /* NOTE: Parse and evaluate expression, but do not use
1145 functions such as parse_and_eval_long or
1146 parse_and_eval_address to also extract the value.
1147 Instead value_as_long and value_as_address are used.
1148 This avoids problems with expressions that contain
1149 side-effects. */
1150 if (numargs >= ARRAY_SIZE (args))
8a3fe4f8 1151 error (_("Too many args in frame specification"));
1c8831c5
AC
1152 args[numargs++] = parse_and_eval (addr_string);
1153
1154 do_cleanups (cleanup);
c906108c
SS
1155 }
1156 }
1157
1c8831c5
AC
1158 /* If no args, default to the selected frame. */
1159 if (numargs == 0)
c906108c 1160 {
1c8831c5
AC
1161 if (selected_frame_p != NULL)
1162 (*selected_frame_p) = 1;
1163 return get_selected_frame (message);
1164 }
c906108c 1165
1c8831c5
AC
1166 /* None of the remaining use the selected frame. */
1167 if (selected_frame_p != NULL)
98f276a0 1168 (*selected_frame_p) = 0;
c906108c 1169
1c8831c5
AC
1170 /* Assume the single arg[0] is an integer, and try using that to
1171 select a frame relative to current. */
1172 if (numargs == 1)
1173 {
1174 struct frame_info *fid;
1175 int level = value_as_long (args[0]);
433759f7 1176
1c8831c5
AC
1177 fid = find_relative_frame (get_current_frame (), &level);
1178 if (level == 0)
c378eb4e 1179 /* find_relative_frame was successful. */
1c8831c5
AC
1180 return fid;
1181 }
c906108c 1182
1c8831c5
AC
1183 /* Convert each value into a corresponding address. */
1184 {
1185 int i;
433759f7 1186
1c8831c5 1187 for (i = 0; i < numargs; i++)
1e275f79 1188 addrs[i] = value_as_address (args[i]);
1c8831c5 1189 }
c5aa993b 1190
1c8831c5
AC
1191 /* Assume that the single arg[0] is an address, use that to identify
1192 a frame with a matching ID. Should this also accept stack/pc or
1193 stack/pc/special. */
1194 if (numargs == 1)
1195 {
1196 struct frame_id id = frame_id_build_wild (addrs[0]);
1197 struct frame_info *fid;
1198
1c8831c5
AC
1199 /* If (s)he specifies the frame with an address, he deserves
1200 what (s)he gets. Still, give the highest one that matches.
1201 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
1202 know). */
1203 for (fid = get_current_frame ();
1204 fid != NULL;
1205 fid = get_prev_frame (fid))
1206 {
1207 if (frame_id_eq (id, get_frame_id (fid)))
1208 {
c7ce8faa
DJ
1209 struct frame_info *prev_frame;
1210
1211 while (1)
1212 {
1213 prev_frame = get_prev_frame (fid);
1214 if (!prev_frame
1215 || !frame_id_eq (id, get_frame_id (prev_frame)))
1216 break;
1217 fid = prev_frame;
1218 }
1c8831c5
AC
1219 return fid;
1220 }
1221 }
c906108c
SS
1222 }
1223
1c8831c5
AC
1224 /* We couldn't identify the frame as an existing frame, but
1225 perhaps we can create one with a single argument. */
1c8831c5
AC
1226 if (numargs == 1)
1227 return create_new_frame (addrs[0], 0);
cd65c8f6
AC
1228 else if (numargs == 2)
1229 return create_new_frame (addrs[0], addrs[1]);
1230 else
8a3fe4f8 1231 error (_("Too many args in frame specification"));
1c8831c5
AC
1232}
1233
9c833c82 1234static struct frame_info *
1c8831c5
AC
1235parse_frame_specification (char *frame_exp)
1236{
1237 return parse_frame_specification_1 (frame_exp, NULL, NULL);
c906108c
SS
1238}
1239
033a42c2
MK
1240/* Print verbosely the selected frame or the frame at address
1241 ADDR_EXP. Absolutely all information in the frame is printed. */
c906108c
SS
1242
1243static void
fba45db2 1244frame_info (char *addr_exp, int from_tty)
c906108c
SS
1245{
1246 struct frame_info *fi;
1247 struct symtab_and_line sal;
1248 struct symbol *func;
1249 struct symtab *s;
1250 struct frame_info *calling_frame_info;
167e4384 1251 int numregs;
c906108c
SS
1252 char *funname = 0;
1253 enum language funlang = language_unknown;
82de1e5b 1254 const char *pc_regname;
1c8831c5 1255 int selected_frame_p;
7500260a 1256 struct gdbarch *gdbarch;
3567439c 1257 struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
008f8f2e
PA
1258 CORE_ADDR frame_pc;
1259 int frame_pc_p;
1260 CORE_ADDR caller_pc;
c906108c 1261
1c8831c5 1262 fi = parse_frame_specification_1 (addr_exp, "No stack.", &selected_frame_p);
12368003 1263 gdbarch = get_frame_arch (fi);
c906108c 1264
82de1e5b
AC
1265 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
1266 is not a good name. */
12368003 1267 if (gdbarch_pc_regnum (gdbarch) >= 0)
3e8c568d 1268 /* OK, this is weird. The gdbarch_pc_regnum hardware register's value can
82de1e5b
AC
1269 easily not match that of the internal value returned by
1270 get_frame_pc(). */
12368003 1271 pc_regname = gdbarch_register_name (gdbarch, gdbarch_pc_regnum (gdbarch));
82de1e5b 1272 else
3e8c568d 1273 /* But then, this is weird to. Even without gdbarch_pc_regnum, an
82de1e5b
AC
1274 architectures will often have a hardware register called "pc",
1275 and that register's value, again, can easily not match
1276 get_frame_pc(). */
1277 pc_regname = "pc";
1278
008f8f2e 1279 frame_pc_p = get_frame_pc_if_available (fi, &frame_pc);
1058bca7 1280 find_frame_sal (fi, &sal);
c906108c 1281 func = get_frame_function (fi);
008f8f2e 1282 s = sal.symtab;
c906108c
SS
1283 if (func)
1284 {
3567439c 1285 funname = SYMBOL_PRINT_NAME (func);
c5aa993b
JM
1286 funlang = SYMBOL_LANGUAGE (func);
1287 if (funlang == language_cplus)
1288 {
3567439c
DJ
1289 /* It seems appropriate to use SYMBOL_PRINT_NAME() here,
1290 to display the demangled name that we already have
1291 stored in the symbol table, but we stored a version
1292 with DMGL_PARAMS turned on, and here we don't want to
1293 display parameters. So remove the parameters. */
1294 char *func_only = cp_remove_params (funname);
433759f7 1295
3567439c
DJ
1296 if (func_only)
1297 {
1298 funname = func_only;
1299 make_cleanup (xfree, func_only);
1300 }
c5aa993b 1301 }
c906108c 1302 }
008f8f2e 1303 else if (frame_pc_p)
c906108c 1304 {
033a42c2
MK
1305 struct minimal_symbol *msymbol;
1306
008f8f2e 1307 msymbol = lookup_minimal_symbol_by_pc (frame_pc);
c906108c
SS
1308 if (msymbol != NULL)
1309 {
3567439c 1310 funname = SYMBOL_PRINT_NAME (msymbol);
c906108c
SS
1311 funlang = SYMBOL_LANGUAGE (msymbol);
1312 }
1313 }
1314 calling_frame_info = get_prev_frame (fi);
1315
1c8831c5 1316 if (selected_frame_p && frame_relative_level (fi) >= 0)
c906108c 1317 {
a3f17187 1318 printf_filtered (_("Stack level %d, frame at "),
1c8831c5 1319 frame_relative_level (fi));
c906108c
SS
1320 }
1321 else
1322 {
a3f17187 1323 printf_filtered (_("Stack frame at "));
c906108c 1324 }
5af949e3 1325 fputs_filtered (paddress (gdbarch, get_frame_base (fi)), gdb_stdout);
9c833c82 1326 printf_filtered (":\n");
82de1e5b 1327 printf_filtered (" %s = ", pc_regname);
008f8f2e
PA
1328 if (frame_pc_p)
1329 fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
1330 else
1331 fputs_filtered ("<unavailable>", gdb_stdout);
c906108c
SS
1332
1333 wrap_here (" ");
1334 if (funname)
1335 {
1336 printf_filtered (" in ");
1337 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
1338 DMGL_ANSI | DMGL_PARAMS);
1339 }
1340 wrap_here (" ");
1341 if (sal.symtab)
1342 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
1343 puts_filtered ("; ");
1344 wrap_here (" ");
82de1e5b 1345 printf_filtered ("saved %s ", pc_regname);
008f8f2e
PA
1346 if (frame_unwind_caller_pc_if_available (fi, &caller_pc))
1347 fputs_filtered (paddress (gdbarch, caller_pc), gdb_stdout);
1348 else
1349 fputs_filtered ("<unavailable>", gdb_stdout);
c906108c
SS
1350 printf_filtered ("\n");
1351
55feb689
DJ
1352 if (calling_frame_info == NULL)
1353 {
1354 enum unwind_stop_reason reason;
1355
1356 reason = get_frame_unwind_stop_reason (fi);
1357 if (reason != UNWIND_NO_REASON)
1358 printf_filtered (_(" Outermost frame: %s\n"),
1359 frame_stop_reason_string (reason));
1360 }
111c6489
JK
1361 else if (get_frame_type (fi) == TAILCALL_FRAME)
1362 puts_filtered (" tail call frame");
edb3359d
DJ
1363 else if (get_frame_type (fi) == INLINE_FRAME)
1364 printf_filtered (" inlined into frame %d",
1365 frame_relative_level (get_prev_frame (fi)));
1366 else
c906108c
SS
1367 {
1368 printf_filtered (" called by frame at ");
5af949e3 1369 fputs_filtered (paddress (gdbarch, get_frame_base (calling_frame_info)),
ed49a04f 1370 gdb_stdout);
c906108c 1371 }
75e3c1f9 1372 if (get_next_frame (fi) && calling_frame_info)
c906108c
SS
1373 puts_filtered (",");
1374 wrap_here (" ");
75e3c1f9 1375 if (get_next_frame (fi))
c906108c
SS
1376 {
1377 printf_filtered (" caller of frame at ");
5af949e3 1378 fputs_filtered (paddress (gdbarch, get_frame_base (get_next_frame (fi))),
ed49a04f 1379 gdb_stdout);
c906108c 1380 }
75e3c1f9 1381 if (get_next_frame (fi) || calling_frame_info)
c906108c 1382 puts_filtered ("\n");
55feb689 1383
c906108c 1384 if (s)
1058bca7
AC
1385 printf_filtered (" source language %s.\n",
1386 language_str (s->language));
c906108c 1387
c906108c
SS
1388 {
1389 /* Address of the argument list for this frame, or 0. */
da62e633 1390 CORE_ADDR arg_list = get_frame_args_address (fi);
c906108c
SS
1391 /* Number of args for this frame, or -1 if unknown. */
1392 int numargs;
1393
1394 if (arg_list == 0)
1395 printf_filtered (" Arglist at unknown address.\n");
1396 else
1397 {
1398 printf_filtered (" Arglist at ");
5af949e3 1399 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
c906108c
SS
1400 printf_filtered (",");
1401
7500260a 1402 if (!gdbarch_frame_num_args_p (gdbarch))
983a287a
AC
1403 {
1404 numargs = -1;
1405 puts_filtered (" args: ");
1406 }
c906108c 1407 else
983a287a 1408 {
7500260a 1409 numargs = gdbarch_frame_num_args (gdbarch, fi);
983a287a
AC
1410 gdb_assert (numargs >= 0);
1411 if (numargs == 0)
1412 puts_filtered (" no args.");
1413 else if (numargs == 1)
1414 puts_filtered (" 1 arg: ");
1415 else
1416 printf_filtered (" %d args: ", numargs);
1417 }
c906108c
SS
1418 print_frame_args (func, fi, numargs, gdb_stdout);
1419 puts_filtered ("\n");
1420 }
1421 }
1422 {
1423 /* Address of the local variables for this frame, or 0. */
da62e633 1424 CORE_ADDR arg_list = get_frame_locals_address (fi);
c906108c
SS
1425
1426 if (arg_list == 0)
1427 printf_filtered (" Locals at unknown address,");
1428 else
1429 {
1430 printf_filtered (" Locals at ");
5af949e3 1431 fputs_filtered (paddress (gdbarch, arg_list), gdb_stdout);
c906108c
SS
1432 printf_filtered (",");
1433 }
1434 }
1435
4f460812
AC
1436 /* Print as much information as possible on the location of all the
1437 registers. */
1438 {
1439 enum lval_type lval;
1440 int optimized;
0fdb4f18 1441 int unavailable;
4f460812
AC
1442 CORE_ADDR addr;
1443 int realnum;
1444 int count;
1445 int i;
1446 int need_nl = 1;
1447
1448 /* The sp is special; what's displayed isn't the save address, but
1449 the value of the previous frame's sp. This is a legacy thing,
1450 at one stage the frame cached the previous frame's SP instead
1451 of its address, hence it was easiest to just display the cached
1452 value. */
7500260a 1453 if (gdbarch_sp_regnum (gdbarch) >= 0)
4f460812
AC
1454 {
1455 /* Find out the location of the saved stack pointer with out
1456 actually evaluating it. */
7500260a 1457 frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
0fdb4f18 1458 &optimized, &unavailable, &lval, &addr,
4f460812 1459 &realnum, NULL);
0fdb4f18 1460 if (!optimized && !unavailable && lval == not_lval)
c906108c 1461 {
e17a4113
UW
1462 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1463 int sp_size = register_size (gdbarch, gdbarch_sp_regnum (gdbarch));
10c42a71 1464 gdb_byte value[MAX_REGISTER_SIZE];
4f460812 1465 CORE_ADDR sp;
433759f7 1466
7500260a 1467 frame_register_unwind (fi, gdbarch_sp_regnum (gdbarch),
0fdb4f18 1468 &optimized, &unavailable, &lval, &addr,
4f460812 1469 &realnum, value);
af1342ab
AC
1470 /* NOTE: cagney/2003-05-22: This is assuming that the
1471 stack pointer was packed as an unsigned integer. That
1472 may or may not be valid. */
e17a4113 1473 sp = extract_unsigned_integer (value, sp_size, byte_order);
4f460812 1474 printf_filtered (" Previous frame's sp is ");
5af949e3 1475 fputs_filtered (paddress (gdbarch, sp), gdb_stdout);
4f460812
AC
1476 printf_filtered ("\n");
1477 need_nl = 0;
c906108c 1478 }
0fdb4f18 1479 else if (!optimized && !unavailable && lval == lval_memory)
4f460812
AC
1480 {
1481 printf_filtered (" Previous frame's sp at ");
5af949e3 1482 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
4f460812
AC
1483 printf_filtered ("\n");
1484 need_nl = 0;
1485 }
0fdb4f18 1486 else if (!optimized && !unavailable && lval == lval_register)
4f460812
AC
1487 {
1488 printf_filtered (" Previous frame's sp in %s\n",
7500260a 1489 gdbarch_register_name (gdbarch, realnum));
4f460812
AC
1490 need_nl = 0;
1491 }
1492 /* else keep quiet. */
1493 }
1494
1495 count = 0;
7500260a
UW
1496 numregs = gdbarch_num_regs (gdbarch)
1497 + gdbarch_num_pseudo_regs (gdbarch);
4f460812 1498 for (i = 0; i < numregs; i++)
7500260a
UW
1499 if (i != gdbarch_sp_regnum (gdbarch)
1500 && gdbarch_register_reggroup_p (gdbarch, i, all_reggroup))
4f460812
AC
1501 {
1502 /* Find out the location of the saved register without
1503 fetching the corresponding value. */
0fdb4f18
PA
1504 frame_register_unwind (fi, i, &optimized, &unavailable,
1505 &lval, &addr, &realnum, NULL);
4f460812
AC
1506 /* For moment, only display registers that were saved on the
1507 stack. */
0fdb4f18 1508 if (!optimized && !unavailable && lval == lval_memory)
4f460812
AC
1509 {
1510 if (count == 0)
1511 puts_filtered (" Saved registers:\n ");
1512 else
1513 puts_filtered (",");
1514 wrap_here (" ");
c9f4d572 1515 printf_filtered (" %s at ",
7500260a 1516 gdbarch_register_name (gdbarch, i));
5af949e3 1517 fputs_filtered (paddress (gdbarch, addr), gdb_stdout);
4f460812
AC
1518 count++;
1519 }
1520 }
1521 if (count || need_nl)
c906108c 1522 puts_filtered ("\n");
4f460812 1523 }
3567439c
DJ
1524
1525 do_cleanups (back_to);
c906108c
SS
1526}
1527
033a42c2
MK
1528/* Print briefly all stack frames or just the innermost COUNT_EXP
1529 frames. */
c906108c
SS
1530
1531static void
fba45db2 1532backtrace_command_1 (char *count_exp, int show_locals, int from_tty)
c906108c
SS
1533{
1534 struct frame_info *fi;
52f0bd74
AC
1535 int count;
1536 int i;
1537 struct frame_info *trailing;
1538 int trailing_level;
c906108c
SS
1539
1540 if (!target_has_stack)
8a3fe4f8 1541 error (_("No stack."));
c906108c 1542
033a42c2
MK
1543 /* The following code must do two things. First, it must set the
1544 variable TRAILING to the frame from which we should start
c906108c
SS
1545 printing. Second, it must set the variable count to the number
1546 of frames which we should print, or -1 if all of them. */
1547 trailing = get_current_frame ();
d082b2bb 1548
c906108c
SS
1549 trailing_level = 0;
1550 if (count_exp)
1551 {
bb518678 1552 count = parse_and_eval_long (count_exp);
c906108c
SS
1553 if (count < 0)
1554 {
1555 struct frame_info *current;
1556
1557 count = -count;
1558
1559 current = trailing;
1560 while (current && count--)
1561 {
1562 QUIT;
1563 current = get_prev_frame (current);
1564 }
c5aa993b 1565
033a42c2
MK
1566 /* Will stop when CURRENT reaches the top of the stack.
1567 TRAILING will be COUNT below it. */
c906108c
SS
1568 while (current)
1569 {
1570 QUIT;
1571 trailing = get_prev_frame (trailing);
1572 current = get_prev_frame (current);
1573 trailing_level++;
1574 }
c5aa993b 1575
c906108c
SS
1576 count = -1;
1577 }
1578 }
1579 else
1580 count = -1;
1581
1582 if (info_verbose)
1583 {
033a42c2
MK
1584 /* Read in symbols for all of the frames. Need to do this in a
1585 separate pass so that "Reading in symbols for xxx" messages
1586 don't screw up the appearance of the backtrace. Also if
1587 people have strong opinions against reading symbols for
c5aa993b 1588 backtrace this may have to be an option. */
c906108c 1589 i = count;
033a42c2 1590 for (fi = trailing; fi != NULL && i--; fi = get_prev_frame (fi))
c906108c 1591 {
ccefe4c4 1592 CORE_ADDR pc;
433759f7 1593
c906108c 1594 QUIT;
ccefe4c4
TT
1595 pc = get_frame_address_in_block (fi);
1596 find_pc_sect_symtab_via_partial (pc, find_pc_mapped_section (pc));
c906108c
SS
1597 }
1598 }
1599
033a42c2 1600 for (i = 0, fi = trailing; fi && count--; i++, fi = get_prev_frame (fi))
c906108c
SS
1601 {
1602 QUIT;
1603
1604 /* Don't use print_stack_frame; if an error() occurs it probably
c5aa993b
JM
1605 means further attempts to backtrace would fail (on the other
1606 hand, perhaps the code does or could be fixed to make sure
1607 the frame->prev field gets set to NULL in that case). */
0faf0076 1608 print_frame_info (fi, 1, LOCATION, 1);
c906108c 1609 if (show_locals)
c5aa993b 1610 print_frame_local_vars (fi, 1, gdb_stdout);
55feb689
DJ
1611
1612 /* Save the last frame to check for error conditions. */
1613 trailing = fi;
c906108c
SS
1614 }
1615
1616 /* If we've stopped before the end, mention that. */
1617 if (fi && from_tty)
a3f17187 1618 printf_filtered (_("(More stack frames follow...)\n"));
55feb689
DJ
1619
1620 /* If we've run out of frames, and the reason appears to be an error
1621 condition, print it. */
1622 if (fi == NULL && trailing != NULL)
1623 {
1624 enum unwind_stop_reason reason;
1625
1626 reason = get_frame_unwind_stop_reason (trailing);
1627 if (reason > UNWIND_FIRST_ERROR)
1628 printf_filtered (_("Backtrace stopped: %s\n"),
1629 frame_stop_reason_string (reason));
1630 }
c906108c
SS
1631}
1632
1633static void
fba45db2 1634backtrace_command (char *arg, int from_tty)
c906108c 1635{
5fe41fbf 1636 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
033a42c2 1637 int fulltrace_arg = -1, arglen = 0, argc = 0;
c906108c 1638
033a42c2 1639 if (arg)
c906108c 1640 {
033a42c2 1641 char **argv;
c906108c
SS
1642 int i;
1643
d1a41061 1644 argv = gdb_buildargv (arg);
5fe41fbf 1645 make_cleanup_freeargv (argv);
c906108c 1646 argc = 0;
033a42c2 1647 for (i = 0; argv[i]; i++)
c5aa993b 1648 {
745b8ca0 1649 unsigned int j;
c5aa993b 1650
033a42c2 1651 for (j = 0; j < strlen (argv[i]); j++)
c5aa993b
JM
1652 argv[i][j] = tolower (argv[i][j]);
1653
033a42c2
MK
1654 if (fulltrace_arg < 0 && subset_compare (argv[i], "full"))
1655 fulltrace_arg = argc;
c5aa993b
JM
1656 else
1657 {
033a42c2 1658 arglen += strlen (argv[i]);
c5aa993b 1659 argc++;
c5aa993b
JM
1660 }
1661 }
033a42c2
MK
1662 arglen += argc;
1663 if (fulltrace_arg >= 0)
c5aa993b 1664 {
033a42c2 1665 if (arglen > 0)
c5aa993b 1666 {
033a42c2 1667 arg = xmalloc (arglen + 1);
b1d288d3
JK
1668 make_cleanup (xfree, arg);
1669 arg[0] = 0;
033a42c2 1670 for (i = 0; i < (argc + 1); i++)
c5aa993b 1671 {
033a42c2 1672 if (i != fulltrace_arg)
c5aa993b 1673 {
033a42c2
MK
1674 strcat (arg, argv[i]);
1675 strcat (arg, " ");
c5aa993b
JM
1676 }
1677 }
1678 }
1679 else
033a42c2 1680 arg = NULL;
c5aa993b 1681 }
c906108c
SS
1682 }
1683
b1d288d3 1684 backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */, from_tty);
c906108c 1685
5fe41fbf 1686 do_cleanups (old_chain);
c906108c
SS
1687}
1688
1689static void
fba45db2 1690backtrace_full_command (char *arg, int from_tty)
c906108c 1691{
b1d288d3 1692 backtrace_command_1 (arg, 1 /* show_locals */, from_tty);
c906108c 1693}
c906108c 1694\f
c5aa993b 1695
2c58c0a9
PA
1696/* Iterate over the local variables of a block B, calling CB with
1697 CB_DATA. */
c906108c 1698
2c58c0a9
PA
1699static void
1700iterate_over_block_locals (struct block *b,
1701 iterate_over_block_arg_local_vars_cb cb,
1702 void *cb_data)
c906108c 1703{
de4f826b 1704 struct dict_iterator iter;
de4f826b 1705 struct symbol *sym;
c906108c 1706
de4f826b 1707 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 1708 {
c906108c
SS
1709 switch (SYMBOL_CLASS (sym))
1710 {
1711 case LOC_LOCAL:
1712 case LOC_REGISTER:
1713 case LOC_STATIC:
4c2df51b 1714 case LOC_COMPUTED:
2a2d4dc3
AS
1715 if (SYMBOL_IS_ARGUMENT (sym))
1716 break;
2c58c0a9 1717 (*cb) (SYMBOL_PRINT_NAME (sym), sym, cb_data);
c906108c
SS
1718 break;
1719
1720 default:
1721 /* Ignore symbols which are not locals. */
1722 break;
1723 }
1724 }
c906108c
SS
1725}
1726
65c06092 1727
c906108c
SS
1728/* Same, but print labels. */
1729
65c06092
JB
1730#if 0
1731/* Commented out, as the code using this function has also been
1732 commented out. FIXME:brobecker/2009-01-13: Find out why the code
1733 was commented out in the first place. The discussion introducing
1734 this change (2007-12-04: Support lexical blocks and function bodies
1735 that occupy non-contiguous address ranges) did not explain why
1736 this change was made. */
c906108c 1737static int
5af949e3
UW
1738print_block_frame_labels (struct gdbarch *gdbarch, struct block *b,
1739 int *have_default, struct ui_file *stream)
c906108c 1740{
de4f826b 1741 struct dict_iterator iter;
52f0bd74
AC
1742 struct symbol *sym;
1743 int values_printed = 0;
c906108c 1744
de4f826b 1745 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 1746 {
3567439c 1747 if (strcmp (SYMBOL_LINKAGE_NAME (sym), "default") == 0)
c906108c
SS
1748 {
1749 if (*have_default)
1750 continue;
1751 *have_default = 1;
1752 }
1753 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1754 {
1755 struct symtab_and_line sal;
79a45b7d 1756 struct value_print_options opts;
433759f7 1757
c906108c
SS
1758 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1759 values_printed = 1;
de5ad195 1760 fputs_filtered (SYMBOL_PRINT_NAME (sym), stream);
79a45b7d
TT
1761 get_user_print_options (&opts);
1762 if (opts.addressprint)
c906108c
SS
1763 {
1764 fprintf_filtered (stream, " ");
5af949e3
UW
1765 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (sym)),
1766 stream);
c906108c
SS
1767 }
1768 fprintf_filtered (stream, " in file %s, line %d\n",
1769 sal.symtab->filename, sal.line);
1770 }
1771 }
033a42c2 1772
c906108c
SS
1773 return values_printed;
1774}
65c06092 1775#endif
c906108c 1776
2c58c0a9
PA
1777/* Iterate over all the local variables in block B, including all its
1778 superblocks, stopping when the top-level block is reached. */
1779
1780void
1781iterate_over_block_local_vars (struct block *block,
1782 iterate_over_block_arg_local_vars_cb cb,
1783 void *cb_data)
1784{
1785 while (block)
1786 {
1787 iterate_over_block_locals (block, cb, cb_data);
1788 /* After handling the function's top-level block, stop. Don't
1789 continue to its superblock, the block of per-file
1790 symbols. */
1791 if (BLOCK_FUNCTION (block))
1792 break;
1793 block = BLOCK_SUPERBLOCK (block);
1794 }
1795}
1796
1797/* Data to be passed around in the calls to the locals and args
1798 iterators. */
c906108c 1799
2c58c0a9
PA
1800struct print_variable_and_value_data
1801{
1802 struct frame_info *frame;
1803 int num_tabs;
1804 struct ui_file *stream;
1805 int values_printed;
1806};
1807
c378eb4e 1808/* The callback for the locals and args iterators. */
2c58c0a9
PA
1809
1810static void
1811do_print_variable_and_value (const char *print_name,
1812 struct symbol *sym,
1813 void *cb_data)
1814{
1815 struct print_variable_and_value_data *p = cb_data;
1816
1817 print_variable_and_value (print_name, sym,
1818 p->frame, p->stream, p->num_tabs);
1819 p->values_printed = 1;
1820}
c906108c
SS
1821
1822static void
033a42c2 1823print_frame_local_vars (struct frame_info *frame, int num_tabs,
aa1ee363 1824 struct ui_file *stream)
c906108c 1825{
2c58c0a9
PA
1826 struct print_variable_and_value_data cb_data;
1827 struct block *block;
1d4f5741
PA
1828 CORE_ADDR pc;
1829
1830 if (!get_frame_pc_if_available (frame, &pc))
1831 {
1832 fprintf_filtered (stream,
1833 _("PC unavailable, cannot determine locals.\n"));
1834 return;
1835 }
c906108c 1836
2c58c0a9 1837 block = get_frame_block (frame, 0);
c906108c
SS
1838 if (block == 0)
1839 {
1840 fprintf_filtered (stream, "No symbol table info available.\n");
1841 return;
1842 }
c5aa993b 1843
2c58c0a9
PA
1844 cb_data.frame = frame;
1845 cb_data.num_tabs = 4 * num_tabs;
1846 cb_data.stream = stream;
1847 cb_data.values_printed = 0;
1848
1849 iterate_over_block_local_vars (block,
1850 do_print_variable_and_value,
1851 &cb_data);
c906108c 1852
2c58c0a9 1853 if (!cb_data.values_printed)
033a42c2 1854 fprintf_filtered (stream, _("No locals.\n"));
c906108c
SS
1855}
1856
1857/* Same, but print labels. */
1858
1859static void
033a42c2 1860print_frame_label_vars (struct frame_info *frame, int this_level_only,
aa1ee363 1861 struct ui_file *stream)
c906108c 1862{
801e3a5b
JB
1863#if 1
1864 fprintf_filtered (stream, "print_frame_label_vars disabled.\n");
1865#else
52f0bd74 1866 struct blockvector *bl;
033a42c2 1867 struct block *block = get_frame_block (frame, 0);
5af949e3 1868 struct gdbarch *gdbarch = get_frame_arch (frame);
52f0bd74 1869 int values_printed = 0;
c906108c
SS
1870 int index, have_default = 0;
1871 char *blocks_printed;
033a42c2 1872 CORE_ADDR pc = get_frame_pc (frame);
c906108c
SS
1873
1874 if (block == 0)
1875 {
1876 fprintf_filtered (stream, "No symbol table info available.\n");
1877 return;
1878 }
1879
1880 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
033a42c2 1881 blocks_printed = alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
c906108c
SS
1882 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1883
1884 while (block != 0)
1885 {
1886 CORE_ADDR end = BLOCK_END (block) - 4;
1887 int last_index;
1888
1889 if (bl != blockvector_for_pc (end, &index))
8a3fe4f8 1890 error (_("blockvector blotch"));
c906108c 1891 if (BLOCKVECTOR_BLOCK (bl, index) != block)
8a3fe4f8 1892 error (_("blockvector botch"));
c906108c
SS
1893 last_index = BLOCKVECTOR_NBLOCKS (bl);
1894 index += 1;
1895
1896 /* Don't print out blocks that have gone by. */
1897 while (index < last_index
1898 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1899 index++;
1900
1901 while (index < last_index
1902 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1903 {
1904 if (blocks_printed[index] == 0)
1905 {
5af949e3
UW
1906 if (print_block_frame_labels (gdbarch,
1907 BLOCKVECTOR_BLOCK (bl, index),
033a42c2 1908 &have_default, stream))
c906108c
SS
1909 values_printed = 1;
1910 blocks_printed[index] = 1;
1911 }
1912 index++;
1913 }
1914 if (have_default)
1915 return;
1916 if (values_printed && this_level_only)
1917 return;
1918
033a42c2 1919 /* After handling the function's top-level block, stop. Don't
edb3359d
DJ
1920 continue to its superblock, the block of per-file symbols.
1921 Also do not continue to the containing function of an inlined
1922 function. */
c906108c
SS
1923 if (BLOCK_FUNCTION (block))
1924 break;
1925 block = BLOCK_SUPERBLOCK (block);
1926 }
1927
1928 if (!values_printed && !this_level_only)
033a42c2 1929 fprintf_filtered (stream, _("No catches.\n"));
801e3a5b 1930#endif
c906108c
SS
1931}
1932
c906108c 1933void
fba45db2 1934locals_info (char *args, int from_tty)
c906108c 1935{
033a42c2 1936 print_frame_local_vars (get_selected_frame (_("No frame selected.")),
b04f3ab4 1937 0, gdb_stdout);
c906108c
SS
1938}
1939
1940static void
fba45db2 1941catch_info (char *ignore, int from_tty)
c906108c 1942{
dfdfb3ca
JB
1943 /* Assume g++ compiled code; old GDB 4.16 behaviour. */
1944 print_frame_label_vars (get_selected_frame (_("No frame selected.")),
1945 0, gdb_stdout);
c906108c
SS
1946}
1947
2c58c0a9
PA
1948/* Iterate over all the argument variables in block B.
1949
1950 Returns 1 if any argument was walked; 0 otherwise. */
1951
1952void
1953iterate_over_block_arg_vars (struct block *b,
1954 iterate_over_block_arg_local_vars_cb cb,
1955 void *cb_data)
c906108c 1956{
de4f826b 1957 struct dict_iterator iter;
52f0bd74 1958 struct symbol *sym, *sym2;
c906108c 1959
de4f826b 1960 ALL_BLOCK_SYMBOLS (b, iter, sym)
c906108c 1961 {
2a2d4dc3
AS
1962 /* Don't worry about things which aren't arguments. */
1963 if (SYMBOL_IS_ARGUMENT (sym))
c906108c 1964 {
c906108c
SS
1965 /* We have to look up the symbol because arguments can have
1966 two entries (one a parameter, one a local) and the one we
1967 want is the local, which lookup_symbol will find for us.
1968 This includes gcc1 (not gcc2) on the sparc when passing a
1969 small structure and gcc2 when the argument type is float
1970 and it is passed as a double and converted to float by
1971 the prologue (in the latter case the type of the LOC_ARG
1972 symbol is double and the type of the LOC_LOCAL symbol is
1973 float). There are also LOC_ARG/LOC_REGISTER pairs which
1974 are not combined in symbol-reading. */
1975
3567439c 1976 sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
2570f2b7 1977 b, VAR_DOMAIN, NULL);
2c58c0a9 1978 (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
c906108c
SS
1979 }
1980 }
2c58c0a9
PA
1981}
1982
1983static void
1984print_frame_arg_vars (struct frame_info *frame, struct ui_file *stream)
1985{
1986 struct print_variable_and_value_data cb_data;
1987 struct symbol *func;
1d4f5741
PA
1988 CORE_ADDR pc;
1989
1990 if (!get_frame_pc_if_available (frame, &pc))
1991 {
1992 fprintf_filtered (stream, _("PC unavailable, cannot determine args.\n"));
1993 return;
1994 }
2c58c0a9
PA
1995
1996 func = get_frame_function (frame);
1997 if (func == NULL)
1998 {
1999 fprintf_filtered (stream, _("No symbol table info available.\n"));
2000 return;
2001 }
2002
2003 cb_data.frame = frame;
2004 cb_data.num_tabs = 0;
2005 cb_data.stream = gdb_stdout;
2006 cb_data.values_printed = 0;
2007
2008 iterate_over_block_arg_vars (SYMBOL_BLOCK_VALUE (func),
2009 do_print_variable_and_value, &cb_data);
033a42c2 2010
2c58c0a9 2011 if (!cb_data.values_printed)
033a42c2 2012 fprintf_filtered (stream, _("No arguments.\n"));
c906108c
SS
2013}
2014
2015void
fba45db2 2016args_info (char *ignore, int from_tty)
c906108c 2017{
033a42c2 2018 print_frame_arg_vars (get_selected_frame (_("No frame selected.")),
b04f3ab4 2019 gdb_stdout);
c906108c
SS
2020}
2021
2022
2023static void
fba45db2 2024args_plus_locals_info (char *ignore, int from_tty)
c906108c 2025{
c5aa993b
JM
2026 args_info (ignore, from_tty);
2027 locals_info (ignore, from_tty);
c906108c 2028}
c906108c 2029\f
c5aa993b 2030
033a42c2
MK
2031/* Select frame FRAME. Also print the stack frame and show the source
2032 if this is the tui version. */
bedfa57b 2033static void
033a42c2 2034select_and_print_frame (struct frame_info *frame)
c906108c 2035{
033a42c2
MK
2036 select_frame (frame);
2037 if (frame)
2038 print_stack_frame (frame, 1, SRC_AND_LOC);
c906108c 2039}
c906108c 2040\f
c906108c 2041/* Return the symbol-block in which the selected frame is executing.
ae767bfb
JB
2042 Can return zero under various legitimate circumstances.
2043
2044 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
2045 code address within the block returned. We use this to decide
2046 which macros are in scope. */
c906108c
SS
2047
2048struct block *
ae767bfb 2049get_selected_block (CORE_ADDR *addr_in_block)
c906108c 2050{
d729566a 2051 if (!has_stack_frames ())
8ea051c5
PA
2052 return 0;
2053
206415a3 2054 return get_frame_block (get_selected_frame (NULL), addr_in_block);
c906108c
SS
2055}
2056
2057/* Find a frame a certain number of levels away from FRAME.
2058 LEVEL_OFFSET_PTR points to an int containing the number of levels.
2059 Positive means go to earlier frames (up); negative, the reverse.
2060 The int that contains the number of levels is counted toward
2061 zero as the frames for those levels are found.
2062 If the top or bottom frame is reached, that frame is returned,
2063 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
2064 how much farther the original request asked to go. */
2065
2066struct frame_info *
033a42c2 2067find_relative_frame (struct frame_info *frame, int *level_offset_ptr)
c906108c 2068{
033a42c2
MK
2069 /* Going up is simple: just call get_prev_frame enough times or
2070 until the initial frame is reached. */
c906108c
SS
2071 while (*level_offset_ptr > 0)
2072 {
033a42c2 2073 struct frame_info *prev = get_prev_frame (frame);
433759f7 2074
033a42c2 2075 if (!prev)
c906108c
SS
2076 break;
2077 (*level_offset_ptr)--;
2078 frame = prev;
2079 }
033a42c2 2080
c906108c 2081 /* Going down is just as simple. */
033a42c2 2082 while (*level_offset_ptr < 0)
c906108c 2083 {
033a42c2 2084 struct frame_info *next = get_next_frame (frame);
433759f7 2085
033a42c2
MK
2086 if (!next)
2087 break;
2088 (*level_offset_ptr)++;
2089 frame = next;
c906108c 2090 }
033a42c2 2091
c906108c
SS
2092 return frame;
2093}
2094
033a42c2
MK
2095/* The "select_frame" command. With no argument this is a NOP.
2096 Select the frame at level LEVEL_EXP if it is a valid level.
2097 Otherwise, treat LEVEL_EXP as an address expression and select it.
2098
2099 See parse_frame_specification for more info on proper frame
2100 expressions. */
c906108c 2101
8b93c638 2102void
fba45db2 2103select_frame_command (char *level_exp, int from_tty)
c906108c 2104{
1c8831c5 2105 select_frame (parse_frame_specification_1 (level_exp, "No stack.", NULL));
c906108c
SS
2106}
2107
033a42c2
MK
2108/* The "frame" command. With no argument, print the selected frame
2109 briefly. With an argument, behave like select_frame and then print
2110 the selected frame. */
c906108c 2111
033a42c2 2112static void
fba45db2 2113frame_command (char *level_exp, int from_tty)
c906108c
SS
2114{
2115 select_frame_command (level_exp, from_tty);
b04f3ab4 2116 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
c906108c
SS
2117}
2118
033a42c2 2119/* The XDB Compatibility command to print the current frame. */
c906108c 2120
7a292a7a 2121static void
fba45db2 2122current_frame_command (char *level_exp, int from_tty)
c906108c 2123{
033a42c2 2124 print_stack_frame (get_selected_frame (_("No stack.")), 1, SRC_AND_LOC);
7a292a7a 2125}
c906108c 2126
033a42c2
MK
2127/* Select the frame up one or COUNT_EXP stack levels from the
2128 previously selected frame, and print it briefly. */
c906108c 2129
c906108c 2130static void
fba45db2 2131up_silently_base (char *count_exp)
c906108c 2132{
033a42c2
MK
2133 struct frame_info *frame;
2134 int count = 1;
2135
c906108c 2136 if (count_exp)
bb518678 2137 count = parse_and_eval_long (count_exp);
c5aa993b 2138
033a42c2
MK
2139 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2140 if (count != 0 && count_exp == NULL)
8a3fe4f8 2141 error (_("Initial frame selected; you cannot go up."));
033a42c2 2142 select_frame (frame);
c906108c
SS
2143}
2144
2145static void
fba45db2 2146up_silently_command (char *count_exp, int from_tty)
c906108c 2147{
c5aa993b 2148 up_silently_base (count_exp);
c906108c
SS
2149}
2150
2151static void
fba45db2 2152up_command (char *count_exp, int from_tty)
c906108c
SS
2153{
2154 up_silently_base (count_exp);
b04f3ab4 2155 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
c906108c
SS
2156}
2157
033a42c2
MK
2158/* Select the frame down one or COUNT_EXP stack levels from the previously
2159 selected frame, and print it briefly. */
c906108c 2160
c906108c 2161static void
fba45db2 2162down_silently_base (char *count_exp)
c906108c 2163{
52f0bd74 2164 struct frame_info *frame;
033a42c2 2165 int count = -1;
f89b749f 2166
c906108c 2167 if (count_exp)
bb518678 2168 count = -parse_and_eval_long (count_exp);
c5aa993b 2169
033a42c2
MK
2170 frame = find_relative_frame (get_selected_frame ("No stack."), &count);
2171 if (count != 0 && count_exp == NULL)
c906108c 2172 {
033a42c2
MK
2173 /* We only do this if COUNT_EXP is not specified. That way
2174 "down" means to really go down (and let me know if that is
2175 impossible), but "down 9999" can be used to mean go all the
2176 way down without getting an error. */
c906108c 2177
033a42c2 2178 error (_("Bottom (innermost) frame selected; you cannot go down."));
c906108c
SS
2179 }
2180
0f7d239c 2181 select_frame (frame);
c906108c
SS
2182}
2183
c906108c 2184static void
fba45db2 2185down_silently_command (char *count_exp, int from_tty)
c906108c
SS
2186{
2187 down_silently_base (count_exp);
c906108c
SS
2188}
2189
2190static void
fba45db2 2191down_command (char *count_exp, int from_tty)
c906108c
SS
2192{
2193 down_silently_base (count_exp);
b04f3ab4 2194 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
c906108c
SS
2195}
2196\f
033a42c2 2197
8b93c638 2198void
fba45db2 2199return_command (char *retval_exp, int from_tty)
c906108c 2200{
5ed92fa8 2201 struct frame_info *thisframe;
d80b854b 2202 struct gdbarch *gdbarch;
c906108c 2203 struct symbol *thisfun;
3d6d86c6 2204 struct value *return_value = NULL;
fc70c2a0 2205 const char *query_prefix = "";
c906108c 2206
5ed92fa8
UW
2207 thisframe = get_selected_frame ("No selected frame.");
2208 thisfun = get_frame_function (thisframe);
d80b854b 2209 gdbarch = get_frame_arch (thisframe);
c906108c 2210
edb3359d
DJ
2211 if (get_frame_type (get_current_frame ()) == INLINE_FRAME)
2212 error (_("Can not force return from an inlined function."));
2213
fc70c2a0
AC
2214 /* Compute the return value. If the computation triggers an error,
2215 let it bail. If the return type can't be handled, set
2216 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
2217 message. */
c906108c
SS
2218 if (retval_exp)
2219 {
61ff14c6
JK
2220 struct expression *retval_expr = parse_expression (retval_exp);
2221 struct cleanup *old_chain = make_cleanup (xfree, retval_expr);
c906108c
SS
2222 struct type *return_type = NULL;
2223
fc70c2a0
AC
2224 /* Compute the return value. Should the computation fail, this
2225 call throws an error. */
61ff14c6 2226 return_value = evaluate_expression (retval_expr);
c906108c 2227
fc70c2a0
AC
2228 /* Cast return value to the return type of the function. Should
2229 the cast fail, this call throws an error. */
c906108c
SS
2230 if (thisfun != NULL)
2231 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
2232 if (return_type == NULL)
61ff14c6
JK
2233 {
2234 if (retval_expr->elts[0].opcode != UNOP_CAST)
2235 error (_("Return value type not available for selected "
2236 "stack frame.\n"
2237 "Please use an explicit cast of the value to return."));
2238 return_type = value_type (return_value);
2239 }
2240 do_cleanups (old_chain);
3e9a183c 2241 CHECK_TYPEDEF (return_type);
c906108c
SS
2242 return_value = value_cast (return_type, return_value);
2243
fc70c2a0
AC
2244 /* Make sure the value is fully evaluated. It may live in the
2245 stack frame we're about to pop. */
d69fe07e 2246 if (value_lazy (return_value))
c906108c 2247 value_fetch_lazy (return_value);
c906108c 2248
667e784f
AC
2249 if (TYPE_CODE (return_type) == TYPE_CODE_VOID)
2250 /* If the return-type is "void", don't try to find the
2251 return-value's location. However, do still evaluate the
2252 return expression so that, even when the expression result
2253 is discarded, side effects such as "return i++" still
033a42c2 2254 occur. */
667e784f 2255 return_value = NULL;
42e2132c 2256 else if (thisfun != NULL
d80b854b
UW
2257 && using_struct_return (gdbarch,
2258 SYMBOL_TYPE (thisfun), return_type))
fc70c2a0 2259 {
3e43a32a
MS
2260 query_prefix = "The location at which to store the "
2261 "function's return value is unknown.\n"
2262 "If you continue, the return value "
2263 "that you specified will be ignored.\n";
667e784f 2264 return_value = NULL;
fc70c2a0 2265 }
c906108c
SS
2266 }
2267
fc70c2a0
AC
2268 /* Does an interactive user really want to do this? Include
2269 information, such as how well GDB can handle the return value, in
2270 the query message. */
2271 if (from_tty)
2272 {
2273 int confirmed;
433759f7 2274
fc70c2a0 2275 if (thisfun == NULL)
e2e0b3e5 2276 confirmed = query (_("%sMake selected stack frame return now? "),
fc70c2a0
AC
2277 query_prefix);
2278 else
e2e0b3e5 2279 confirmed = query (_("%sMake %s return now? "), query_prefix,
fc70c2a0
AC
2280 SYMBOL_PRINT_NAME (thisfun));
2281 if (!confirmed)
8a3fe4f8 2282 error (_("Not confirmed"));
fc70c2a0 2283 }
c906108c 2284
a45ae3ed
UW
2285 /* Discard the selected frame and all frames inner-to it. */
2286 frame_pop (get_selected_frame (NULL));
c906108c 2287
a1f5b845 2288 /* Store RETURN_VALUE in the just-returned register set. */
fc70c2a0
AC
2289 if (return_value != NULL)
2290 {
df407dfe 2291 struct type *return_type = value_type (return_value);
7500260a 2292 struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());
42e2132c
JK
2293 struct type *func_type = thisfun == NULL ? NULL : SYMBOL_TYPE (thisfun);
2294
2295 gdb_assert (gdbarch_return_value (gdbarch, func_type, return_type, NULL,
2296 NULL, NULL)
750eb019 2297 == RETURN_VALUE_REGISTER_CONVENTION);
42e2132c 2298 gdbarch_return_value (gdbarch, func_type, return_type,
594f7785 2299 get_current_regcache (), NULL /*read*/,
0fd88904 2300 value_contents (return_value) /*write*/);
fc70c2a0 2301 }
1a2aab69 2302
fc70c2a0
AC
2303 /* If we are at the end of a call dummy now, pop the dummy frame
2304 too. */
e8bcf01f
AC
2305 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME)
2306 frame_pop (get_current_frame ());
1a2aab69 2307
c906108c 2308 /* If interactive, print the frame that is now current. */
c906108c
SS
2309 if (from_tty)
2310 frame_command ("0", 1);
2311 else
2312 select_frame_command ("0", 0);
2313}
2314
033a42c2 2315/* Sets the scope to input function name, provided that the function
c378eb4e 2316 is within the current stack frame. */
c906108c
SS
2317
2318struct function_bounds
2319{
2320 CORE_ADDR low, high;
2321};
2322
2323static void
fba45db2 2324func_command (char *arg, int from_tty)
c906108c 2325{
033a42c2 2326 struct frame_info *frame;
c906108c
SS
2327 int found = 0;
2328 struct symtabs_and_lines sals;
2329 int i;
2330 int level = 1;
033a42c2 2331 struct function_bounds *func_bounds = NULL;
c906108c 2332
033a42c2 2333 if (arg != NULL)
c906108c
SS
2334 return;
2335
033a42c2 2336 frame = parse_frame_specification ("0");
c906108c
SS
2337 sals = decode_line_spec (arg, 1);
2338 func_bounds = (struct function_bounds *) xmalloc (
2339 sizeof (struct function_bounds) * sals.nelts);
2340 for (i = 0; (i < sals.nelts && !found); i++)
2341 {
033a42c2
MK
2342 if (sals.sals[i].pc == 0
2343 || find_pc_partial_function (sals.sals[i].pc, NULL,
2344 &func_bounds[i].low,
2345 &func_bounds[i].high) == 0)
c906108c 2346 {
033a42c2 2347 func_bounds[i].low = func_bounds[i].high = 0;
c906108c
SS
2348 }
2349 }
2350
2351 do
2352 {
2353 for (i = 0; (i < sals.nelts && !found); i++)
033a42c2
MK
2354 found = (get_frame_pc (frame) >= func_bounds[i].low
2355 && get_frame_pc (frame) < func_bounds[i].high);
c906108c
SS
2356 if (!found)
2357 {
2358 level = 1;
033a42c2 2359 frame = find_relative_frame (frame, &level);
c906108c
SS
2360 }
2361 }
2362 while (!found && level == 0);
2363
2364 if (func_bounds)
b8c9b27d 2365 xfree (func_bounds);
c906108c
SS
2366
2367 if (!found)
a3f17187 2368 printf_filtered (_("'%s' not within current stack frame.\n"), arg);
206415a3 2369 else if (frame != get_selected_frame (NULL))
033a42c2 2370 select_and_print_frame (frame);
c906108c
SS
2371}
2372
2373/* Gets the language of the current frame. */
2374
2375enum language
fba45db2 2376get_frame_language (void)
c906108c 2377{
206415a3 2378 struct frame_info *frame = deprecated_safe_get_selected_frame ();
c5aa993b 2379
033a42c2 2380 if (frame)
c906108c 2381 {
e3eebbd7
PA
2382 volatile struct gdb_exception ex;
2383 CORE_ADDR pc = 0;
2384 struct symtab *s;
2385
7ae4c3a5 2386 /* We determine the current frame language by looking up its
033a42c2
MK
2387 associated symtab. To retrieve this symtab, we use the frame
2388 PC. However we cannot use the frame PC as is, because it
2389 usually points to the instruction following the "call", which
2390 is sometimes the first instruction of another function. So
2391 we rely on get_frame_address_in_block(), it provides us with
2392 a PC that is guaranteed to be inside the frame's code
2393 block. */
033a42c2 2394
e3eebbd7
PA
2395 TRY_CATCH (ex, RETURN_MASK_ERROR)
2396 {
2397 pc = get_frame_address_in_block (frame);
2398 }
2399 if (ex.reason < 0)
2400 {
2401 if (ex.error != NOT_AVAILABLE_ERROR)
2402 throw_exception (ex);
2403 }
2404 else
2405 {
2406 s = find_pc_symtab (pc);
2407 if (s != NULL)
2408 return s->language;
2409 }
c906108c 2410 }
c906108c 2411
033a42c2 2412 return language_unknown;
c906108c
SS
2413}
2414\f
033a42c2
MK
2415
2416/* Provide a prototype to silence -Wmissing-prototypes. */
2417void _initialize_stack (void);
2418
c906108c 2419void
fba45db2 2420_initialize_stack (void)
c906108c 2421{
1bedd215
AC
2422 add_com ("return", class_stack, return_command, _("\
2423Make selected stack frame return to its caller.\n\
c906108c
SS
2424Control remains in the debugger, but when you continue\n\
2425execution will resume in the frame above the one now selected.\n\
1bedd215
AC
2426If an argument is given, it is an expression for the value to return."));
2427
2428 add_com ("up", class_stack, up_command, _("\
2429Select and print stack frame that called this one.\n\
2430An argument says how many frames up to go."));
2431 add_com ("up-silently", class_support, up_silently_command, _("\
2432Same as the `up' command, but does not print anything.\n\
2433This is useful in command scripts."));
2434
2435 add_com ("down", class_stack, down_command, _("\
2436Select and print stack frame called by this one.\n\
2437An argument says how many frames down to go."));
c906108c
SS
2438 add_com_alias ("do", "down", class_stack, 1);
2439 add_com_alias ("dow", "down", class_stack, 1);
1bedd215
AC
2440 add_com ("down-silently", class_support, down_silently_command, _("\
2441Same as the `down' command, but does not print anything.\n\
2442This is useful in command scripts."));
c906108c 2443
1bedd215 2444 add_com ("frame", class_stack, frame_command, _("\
3e43a32a
MS
2445Select and print a stack frame.\nWith no argument, \
2446print the selected stack frame. (See also \"info frame\").\n\
c906108c
SS
2447An argument specifies the frame to select.\n\
2448It can be a stack frame number or the address of the frame.\n\
2449With argument, nothing is printed if input is coming from\n\
1bedd215 2450a command file or a user-defined command."));
c906108c
SS
2451
2452 add_com_alias ("f", "frame", class_stack, 1);
2453
2454 if (xdb_commands)
2455 {
c5aa993b 2456 add_com ("L", class_stack, current_frame_command,
1bedd215 2457 _("Print the current stack frame.\n"));
c906108c
SS
2458 add_com_alias ("V", "frame", class_stack, 1);
2459 }
1bedd215
AC
2460 add_com ("select-frame", class_stack, select_frame_command, _("\
2461Select a stack frame without printing anything.\n\
c906108c 2462An argument specifies the frame to select.\n\
1bedd215 2463It can be a stack frame number or the address of the frame.\n"));
c906108c 2464
1bedd215
AC
2465 add_com ("backtrace", class_stack, backtrace_command, _("\
2466Print backtrace of all stack frames, or innermost COUNT frames.\n\
3e43a32a
MS
2467With a negative argument, print outermost -COUNT frames.\nUse of the \
2468'full' qualifier also prints the values of the local variables.\n"));
c906108c
SS
2469 add_com_alias ("bt", "backtrace", class_stack, 0);
2470 if (xdb_commands)
2471 {
2472 add_com_alias ("t", "backtrace", class_stack, 0);
1bedd215 2473 add_com ("T", class_stack, backtrace_full_command, _("\
cce7e648 2474Print backtrace of all stack frames, or innermost COUNT frames\n\
c906108c
SS
2475and the values of the local variables.\n\
2476With a negative argument, print outermost -COUNT frames.\n\
1bedd215 2477Usage: T <count>\n"));
c906108c
SS
2478 }
2479
2480 add_com_alias ("where", "backtrace", class_alias, 0);
2481 add_info ("stack", backtrace_command,
1bedd215 2482 _("Backtrace of the stack, or innermost COUNT frames."));
c906108c
SS
2483 add_info_alias ("s", "stack", 1);
2484 add_info ("frame", frame_info,
1bedd215 2485 _("All about selected stack frame, or frame at ADDR."));
c906108c
SS
2486 add_info_alias ("f", "frame", 1);
2487 add_info ("locals", locals_info,
1bedd215 2488 _("Local variables of current stack frame."));
c906108c 2489 add_info ("args", args_info,
1bedd215 2490 _("Argument variables of current stack frame."));
c906108c 2491 if (xdb_commands)
c5aa993b 2492 add_com ("l", class_info, args_plus_locals_info,
1bedd215 2493 _("Argument and local variables of current stack frame."));
c906108c
SS
2494
2495 if (dbx_commands)
1bedd215
AC
2496 add_com ("func", class_stack, func_command, _("\
2497Select the stack frame that contains <func>.\n\
2498Usage: func <name>\n"));
c906108c
SS
2499
2500 add_info ("catch", catch_info,
1bedd215 2501 _("Exceptions that can be caught in the current stack frame."));
c906108c 2502
88408340
JB
2503 add_setshow_enum_cmd ("frame-arguments", class_stack,
2504 print_frame_arguments_choices, &print_frame_arguments,
2505 _("Set printing of non-scalar frame arguments"),
2506 _("Show printing of non-scalar frame arguments"),
2507 NULL, NULL, NULL, &setprintlist, &showprintlist);
2508
30c33a9f
HZ
2509 add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
2510 &disassemble_next_line, _("\
3e43a32a
MS
2511Set whether to disassemble next source line or insn when execution stops."),
2512 _("\
2513Show whether to disassemble next source line or insn when execution stops."),
2514 _("\
80a0ea0f
EZ
2515If ON, GDB will display disassembly of the next source line, in addition\n\
2516to displaying the source line itself. If the next source line cannot\n\
2517be displayed (e.g., source is unavailable or there's no line info), GDB\n\
2518will display disassembly of next instruction instead of showing the\n\
2519source line.\n\
2520If AUTO, display disassembly of next instruction only if the source line\n\
2521cannot be displayed.\n\
2522If OFF (which is the default), never display the disassembly of the next\n\
2523source line."),
30c33a9f
HZ
2524 NULL,
2525 show_disassemble_next_line,
2526 &setlist, &showlist);
a362e3d3 2527 disassemble_next_line = AUTO_BOOLEAN_FALSE;
e18b2753
JK
2528
2529 add_setshow_enum_cmd ("entry-values", class_stack,
2530 print_entry_values_choices, &print_entry_values,
2531 _("Set printing of function arguments at function "
2532 "entry"),
2533 _("Show printing of function arguments at function "
2534 "entry"),
2535 _("\
2536GDB can sometimes determine the values of function arguments at entry,\n\
2537in addition to their current values. This option tells GDB whether\n\
2538to print the current value, the value at entry (marked as val@entry),\n\
2539or both. Note that one or both of these values may be <optimized out>."),
2540 NULL, NULL, &setprintlist, &showprintlist);
c906108c 2541}
This page took 1.303024 seconds and 4 git commands to generate.