1 /* Print and select stack frames for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
30 #include "expression.h"
37 #include "breakpoint.h"
44 #include "gdb_assert.h"
45 #include "dictionary.h"
46 #include "reggroups.h"
49 /* Prototypes for exported functions. */
51 void args_info (char *, int);
53 void locals_info (char *, int);
55 void (*selected_frame_level_changed_hook
) (int);
57 void _initialize_stack (void);
59 /* Prototypes for local functions. */
61 static void down_command (char *, int);
63 static void down_silently_base (char *);
65 static void down_silently_command (char *, int);
67 static void up_command (char *, int);
69 static void up_silently_base (char *);
71 static void up_silently_command (char *, int);
73 void frame_command (char *, int);
75 static void current_frame_command (char *, int);
77 static void print_frame_arg_vars (struct frame_info
*, struct ui_file
*);
79 static void catch_info (char *, int);
81 static void args_plus_locals_info (char *, int);
83 static void print_frame_label_vars (struct frame_info
*, int,
86 static void print_frame_local_vars (struct frame_info
*, int,
89 static int print_block_frame_labels (struct block
*, int *,
92 static int print_block_frame_locals (struct block
*,
97 static void print_frame (struct frame_info
*fi
,
101 struct symtab_and_line sal
);
103 static void backtrace_command (char *, int);
105 struct frame_info
*parse_frame_specification (char *);
107 static void frame_info (char *, int);
109 extern int addressprint
; /* Print addresses, or stay symbolic only? */
111 /* Zero means do things normally; we are interacting directly with the
112 user. One means print the full filename and linenumber when a
113 frame is printed, and do so in a format emacs18/emacs19.22 can
114 parse. Two means print similar annotations, but in many more
115 cases and in a slightly different syntax. */
117 int annotation_level
= 0;
120 struct print_stack_frame_args
122 struct frame_info
*fi
;
128 /* Show or print the frame arguments.
129 Pass the args the way catch_errors wants them. */
130 static int print_stack_frame_stub (void *args
);
132 print_stack_frame_stub (void *args
)
134 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
136 print_frame_info (p
->fi
, p
->level
, p
->source
, p
->args
);
140 /* Show or print a stack frame briefly. FRAME_INFI should be the frame info
141 and LEVEL should be its level in the stack (or -1 for level not defined).
142 This prints the level, the function executing, the arguments,
143 and the file name and line number.
144 If the pc is not at the beginning of the source line,
145 the actual pc is printed at the beginning.
147 If SOURCE is 1, print the source line as well.
148 If SOURCE is -1, print ONLY the source line. */
151 print_stack_frame (struct frame_info
*fi
, int level
, int source
)
153 struct print_stack_frame_args args
;
157 args
.source
= source
;
160 catch_errors (print_stack_frame_stub
, (char *) &args
, "", RETURN_MASK_ALL
);
163 struct print_args_args
166 struct frame_info
*fi
;
167 struct ui_file
*stream
;
170 static int print_args_stub (void *);
172 /* Print nameless args on STREAM.
173 FI is the frameinfo for this frame, START is the offset
174 of the first nameless arg, and NUM is the number of nameless args to
175 print. FIRST is nonzero if this is the first argument (not just
176 the first nameless arg). */
179 print_frame_nameless_args (struct frame_info
*fi
, long start
, int num
,
180 int first
, struct ui_file
*stream
)
186 for (i
= 0; i
< num
; i
++)
189 argsaddr
= get_frame_args_address (fi
);
192 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
194 fprintf_filtered (stream
, ", ");
195 fprintf_filtered (stream
, "%ld", arg_value
);
197 start
+= sizeof (int);
201 /* Print the arguments of a stack frame, given the function FUNC
202 running in that frame (as a symbol), the info on the frame,
203 and the number of args according to the stack frame (or -1 if unknown). */
205 /* References here and elsewhere to "number of args according to the
206 stack frame" appear in all cases to refer to "number of ints of args
207 according to the stack frame". At least for VAX, i386, isi. */
210 print_frame_args (struct symbol
*func
, struct frame_info
*fi
, int num
,
211 struct ui_file
*stream
)
213 struct block
*b
= NULL
;
215 struct dict_iterator iter
;
218 /* Offset of next stack argument beyond the one we have seen that is
219 at the highest offset.
220 -1 if we haven't come to a stack argument yet. */
221 long highest_offset
= -1;
223 /* Number of ints of arguments that we have printed so far. */
224 int args_printed
= 0;
225 struct cleanup
*old_chain
, *list_chain
;
226 struct ui_stream
*stb
;
228 stb
= ui_out_stream_new (uiout
);
229 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
233 b
= SYMBOL_BLOCK_VALUE (func
);
235 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
239 /* Keep track of the highest stack argument offset seen, and
240 skip over any kinds of symbols we don't care about. */
242 switch (SYMBOL_CLASS (sym
))
247 long current_offset
= SYMBOL_VALUE (sym
);
248 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
250 /* Compute address of next argument by adding the size of
251 this argument and rounding to an int boundary. */
253 ((current_offset
+ arg_size
+ sizeof (int) - 1)
254 & ~(sizeof (int) - 1));
256 /* If this is the highest offset seen yet, set highest_offset. */
257 if (highest_offset
== -1
258 || (current_offset
> highest_offset
))
259 highest_offset
= current_offset
;
261 /* Add the number of ints we're about to print to args_printed. */
262 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
265 /* We care about types of symbols, but don't need to keep track of
266 stack offsets in them. */
268 case LOC_REGPARM_ADDR
:
270 case LOC_BASEREG_ARG
:
271 case LOC_COMPUTED_ARG
:
274 /* Other types of symbols we just skip over. */
279 /* We have to look up the symbol because arguments can have
280 two entries (one a parameter, one a local) and the one we
281 want is the local, which lookup_symbol will find for us.
282 This includes gcc1 (not gcc2) on the sparc when passing a
283 small structure and gcc2 when the argument type is float
284 and it is passed as a double and converted to float by
285 the prologue (in the latter case the type of the LOC_ARG
286 symbol is double and the type of the LOC_LOCAL symbol is
288 /* But if the parameter name is null, don't try it.
289 Null parameter names occur on the RS/6000, for traceback tables.
290 FIXME, should we even print them? */
292 if (*DEPRECATED_SYMBOL_NAME (sym
))
296 (DEPRECATED_SYMBOL_NAME (sym
),
297 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
298 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
300 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
301 it was passed on the stack and loaded into a register,
302 or passed in a register and stored in a stack slot.
303 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
305 Reasons for using the LOC_ARG:
306 (1) because find_saved_registers may be slow for remote
308 (2) because registers are often re-used and stack slots
309 rarely (never?) are. Therefore using the stack slot is
310 much less likely to print garbage.
312 Reasons why we might want to use the LOC_REGISTER:
313 (1) So that the backtrace prints the same value as
314 "print foo". I see no compelling reason why this needs
315 to be the case; having the backtrace print the value which
316 was passed in, and "print foo" print the value as modified
317 within the called function, makes perfect sense to me.
319 Additional note: It might be nice if "info args" displayed
321 One more note: There is a case with sparc structure passing
322 where we need to use the LOC_REGISTER, but this is dealt with
323 by creating a single LOC_REGPARM in symbol reading. */
325 /* Leave sym (the LOC_ARG) alone. */
332 /* Print the current arg. */
334 ui_out_text (uiout
, ", ");
335 ui_out_wrap_hint (uiout
, " ");
337 annotate_arg_begin ();
339 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
340 fprintf_symbol_filtered (stb
->stream
, SYMBOL_PRINT_NAME (sym
),
341 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
342 ui_out_field_stream (uiout
, "name", stb
);
343 annotate_arg_name_end ();
344 ui_out_text (uiout
, "=");
346 /* Avoid value_print because it will deref ref parameters. We just
347 want to print their addresses. Print ??? for args whose address
348 we do not know. We pass 2 as "recurse" to val_print because our
349 standard indentation here is 4 spaces, and val_print indents
350 2 for each recurse. */
351 val
= read_var_value (sym
, fi
);
353 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
357 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
359 stb
->stream
, 0, 0, 2, Val_no_prettyprint
);
360 ui_out_field_stream (uiout
, "value", stb
);
363 ui_out_text (uiout
, "???");
365 /* Invoke ui_out_tuple_end. */
366 do_cleanups (list_chain
);
374 /* Don't print nameless args in situations where we don't know
375 enough about the stack to find them. */
380 if (highest_offset
== -1)
381 start
= FRAME_ARGS_SKIP
;
383 start
= highest_offset
;
385 print_frame_nameless_args (fi
, start
, num
- args_printed
,
388 do_cleanups (old_chain
);
391 /* Pass the args the way catch_errors wants them. */
394 print_args_stub (void *args
)
397 struct print_args_args
*p
= (struct print_args_args
*) args
;
399 if (FRAME_NUM_ARGS_P ())
401 numargs
= FRAME_NUM_ARGS (p
->fi
);
402 gdb_assert (numargs
>= 0);
406 print_frame_args (p
->func
, p
->fi
, numargs
, p
->stream
);
410 /* Print information about a frame for frame "fi" at level "level".
411 Used in "where" output, also used to emit breakpoint or step
413 LEVEL is the level of the frame, or -1 if it is the
414 innermost frame but we don't want to print the level.
415 The meaning of the SOURCE argument is:
416 SRC_LINE: Print only source line
417 LOCATION: Print only location
418 LOC_AND_SRC: Print location and source line. */
421 print_frame_info (struct frame_info
*fi
, int level
, int source
, int args
)
423 struct symtab_and_line sal
;
427 if (get_frame_type (fi
) == DUMMY_FRAME
428 || get_frame_type (fi
) == SIGTRAMP_FRAME
)
430 struct cleanup
*uiout_cleanup
431 = make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
433 annotate_frame_begin (level
== -1 ? 0 : level
, get_frame_pc (fi
));
435 /* Do this regardless of SOURCE because we don't have any source
436 to list for this frame. */
439 ui_out_text (uiout
, "#");
440 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level", level
);
442 if (ui_out_is_mi_like_p (uiout
))
444 annotate_frame_address ();
445 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
446 annotate_frame_address_end ();
449 if (get_frame_type (fi
) == DUMMY_FRAME
)
451 annotate_function_call ();
452 ui_out_field_string (uiout
, "func", "<function called from gdb>");
454 else if (get_frame_type (fi
) == SIGTRAMP_FRAME
)
456 annotate_signal_handler_caller ();
457 ui_out_field_string (uiout
, "func", "<signal handler called>");
459 ui_out_text (uiout
, "\n");
460 annotate_frame_end ();
462 do_cleanups (uiout_cleanup
);
466 /* If fi is not the innermost frame, that normally means that fi->pc
467 points to *after* the call instruction, and we want to get the
468 line containing the call, never the next line. But if the next
469 frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
470 was not entered as the result of a call, and we want to get the
471 line containing fi->pc. */
472 find_frame_sal (fi
, &sal
);
474 location_print
= (source
== LOCATION
475 || source
== LOC_AND_ADDRESS
476 || source
== SRC_AND_LOC
);
478 if (location_print
|| !sal
.symtab
)
479 print_frame (fi
, level
, source
, args
, sal
);
481 source_print
= (source
== SRC_LINE
|| source
== SRC_AND_LOC
);
484 set_current_source_symtab_and_line (&sal
);
486 if (source_print
&& sal
.symtab
)
488 struct symtab_and_line cursal
;
490 int mid_statement
= (source
== SRC_LINE
) && (get_frame_pc (fi
) != sal
.pc
);
492 if (annotation_level
)
493 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
497 if (print_frame_info_listing_hook
)
498 print_frame_info_listing_hook (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
501 /* We used to do this earlier, but that is clearly
502 wrong. This function is used by many different
503 parts of gdb, including normal_stop in infrun.c,
504 which uses this to print out the current PC
505 when we stepi/nexti into the middle of a source
506 line. Only the command line really wants this
507 behavior. Other UIs probably would like the
508 ability to decide for themselves if it is desired. */
509 if (addressprint
&& mid_statement
)
511 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
512 ui_out_text (uiout
, "\t");
515 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
518 /* Make sure we have at least a default source file */
519 set_default_source_symtab_and_line ();
520 cursal
= get_current_source_symtab_and_line ();
521 cursal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
522 set_current_source_symtab_and_line (&cursal
);
526 set_default_breakpoint (1, get_frame_pc (fi
), sal
.symtab
, sal
.line
);
528 annotate_frame_end ();
530 gdb_flush (gdb_stdout
);
534 print_frame (struct frame_info
*fi
,
538 struct symtab_and_line sal
)
542 enum language funlang
= language_unknown
;
543 struct ui_stream
*stb
;
544 struct cleanup
*old_chain
;
545 struct cleanup
*list_chain
;
547 stb
= ui_out_stream_new (uiout
);
548 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
550 func
= find_pc_function (get_frame_address_in_block (fi
));
553 /* In certain pathological cases, the symtabs give the wrong
554 function (when we are in the first function in a file which
555 is compiled without debugging symbols, the previous function
556 is compiled with debugging symbols, and the "foo.o" symbol
557 that is supposed to tell us where the file with debugging symbols
558 ends has been truncated by ar because it is longer than 15
559 characters). This also occurs if the user uses asm() to create
560 a function but not stabs for it (in a file compiled -g).
562 So look in the minimal symbol tables as well, and if it comes
563 up with a larger address for the function use that instead.
564 I don't think this can ever cause any problems; there shouldn't
565 be any minimal symbols in the middle of a function; if this is
566 ever changed many parts of GDB will need to be changed (and we'll
567 create a find_pc_minimal_function or some such). */
569 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
571 && (SYMBOL_VALUE_ADDRESS (msymbol
)
572 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
575 /* There is no particular reason to think the line number
576 information is wrong. Someone might have just put in
577 a label with asm() but left the line numbers alone. */
578 /* In this case we have no way of knowing the source file
579 and line number, so don't print them. */
582 /* We also don't know anything about the function besides
583 its address and name. */
585 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
586 funlang
= SYMBOL_LANGUAGE (msymbol
);
590 /* I'd like to use SYMBOL_PRINT_NAME() here, to display the
591 demangled name that we already have stored in the symbol
592 table, but we stored a version with DMGL_PARAMS turned
593 on, and here we don't want to display parameters. So call
594 the demangler again, with DMGL_ANSI only. (Yes, I know
595 that printf_symbol_filtered() will again try to demangle
596 the name on the fly, but the issue is that if
597 cplus_demangle() fails here, it'll fail there too. So we
598 want to catch the failure ("demangled==NULL" case below)
599 here, while we still have our hands on the function
602 funname
= DEPRECATED_SYMBOL_NAME (func
);
603 funlang
= SYMBOL_LANGUAGE (func
);
604 if (funlang
== language_cplus
)
606 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
607 if (demangled
== NULL
)
608 /* If the demangler fails, try the demangled name from
609 the symbol table. This'll have parameters, but
610 that's preferable to diplaying a mangled name. */
611 funname
= SYMBOL_PRINT_NAME (func
);
617 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
620 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
621 funlang
= SYMBOL_LANGUAGE (msymbol
);
625 annotate_frame_begin (level
== -1 ? 0 : level
, get_frame_pc (fi
));
627 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
631 ui_out_text (uiout
, "#");
632 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level", level
);
635 if (get_frame_pc (fi
) != sal
.pc
637 || source
== LOC_AND_ADDRESS
)
639 annotate_frame_address ();
640 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
641 annotate_frame_address_end ();
642 ui_out_text (uiout
, " in ");
644 annotate_frame_function_name ();
645 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??", funlang
,
647 ui_out_field_stream (uiout
, "func", stb
);
648 ui_out_wrap_hint (uiout
, " ");
649 annotate_frame_args ();
651 ui_out_text (uiout
, " (");
654 struct print_args_args args
;
655 struct cleanup
*args_list_chain
;
658 args
.stream
= gdb_stdout
;
659 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
660 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
661 /* FIXME: args must be a list. If one argument is a string it will
662 have " that will not be properly escaped. */
663 /* Invoke ui_out_tuple_end. */
664 do_cleanups (args_list_chain
);
667 ui_out_text (uiout
, ")");
668 if (sal
.symtab
&& sal
.symtab
->filename
)
670 annotate_frame_source_begin ();
671 ui_out_wrap_hint (uiout
, " ");
672 ui_out_text (uiout
, " at ");
673 annotate_frame_source_file ();
674 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
675 annotate_frame_source_file_end ();
676 ui_out_text (uiout
, ":");
677 annotate_frame_source_line ();
678 ui_out_field_int (uiout
, "line", sal
.line
);
679 annotate_frame_source_end ();
683 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
685 char *lib
= PC_SOLIB (get_frame_pc (fi
));
688 annotate_frame_where ();
689 ui_out_wrap_hint (uiout
, " ");
690 ui_out_text (uiout
, " from ");
691 ui_out_field_string (uiout
, "from", lib
);
694 #endif /* PC_SOLIB */
696 /* do_cleanups will call ui_out_tuple_end() for us. */
697 do_cleanups (list_chain
);
698 ui_out_text (uiout
, "\n");
699 do_cleanups (old_chain
);
702 /* Show the frame info. If this is the tui, it will be shown in
703 the source display otherwise, nothing is done */
705 show_stack_frame (struct frame_info
*fi
)
710 /* Read a frame specification in whatever the appropriate format is.
711 Call error() if the specification is in any way invalid (i.e.
712 this function never returns NULL). */
715 parse_frame_specification (char *frame_exp
)
719 CORE_ADDR args
[MAXARGS
];
724 char *addr_string
, *p
;
725 struct cleanup
*tmp_cleanup
;
727 while (*frame_exp
== ' ')
732 if (numargs
> MAXARGS
)
733 error ("Too many args in frame specification");
734 /* Parse an argument. */
735 for (p
= frame_exp
; *p
&& *p
!= ' '; p
++)
737 addr_string
= savestring (frame_exp
, p
- frame_exp
);
742 tmp_cleanup
= make_cleanup (xfree
, addr_string
);
744 /* NOTE: we call parse_and_eval and then both
745 value_as_long and value_as_address rather than calling
746 parse_and_eval_long and parse_and_eval_address because
747 of the issue of potential side effects from evaluating
749 vp
= parse_and_eval (addr_string
);
751 level
= value_as_long (vp
);
753 args
[numargs
++] = value_as_address (vp
);
754 do_cleanups (tmp_cleanup
);
757 /* Skip spaces, move to possible next arg. */
767 if (deprecated_selected_frame
== NULL
)
768 error ("No selected frame.");
769 return deprecated_selected_frame
;
773 struct frame_info
*fid
=
774 find_relative_frame (get_current_frame (), &level
);
775 struct frame_info
*tfid
;
778 /* find_relative_frame was successful */
781 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
782 take at least 2 addresses. It is important to detect this case
783 here so that "frame 100" does not give a confusing error message
784 like "frame specification requires two addresses". This of course
785 does not solve the "frame 100" problem for machines on which
786 a frame specification can be made with one address. To solve
787 that, we need a new syntax for a specifying a frame by address.
788 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
789 two args, etc.), but people might think that is too much typing,
790 so I guess *0x23,0x45 would be a possible alternative (commas
791 really should be used instead of spaces to delimit; using spaces
792 normally works in an expression). */
793 #ifdef SETUP_ARBITRARY_FRAME
794 error ("No frame %s", paddr_d (args
[0]));
797 /* If (s)he specifies the frame with an address, he deserves what
798 (s)he gets. Still, give the highest one that matches. */
800 for (fid
= get_current_frame ();
801 fid
&& get_frame_base (fid
) != args
[0];
802 fid
= get_prev_frame (fid
))
806 while ((tfid
= get_prev_frame (fid
)) &&
807 (get_frame_base (tfid
) == args
[0]))
810 /* We couldn't identify the frame as an existing frame, but
811 perhaps we can create one with a single argument. */
815 #ifdef SETUP_ARBITRARY_FRAME
816 return SETUP_ARBITRARY_FRAME (numargs
, args
);
818 /* Usual case. Do it here rather than have everyone supply
819 a SETUP_ARBITRARY_FRAME that does this. */
821 return create_new_frame (args
[0], 0);
822 error ("Too many args in frame specification");
829 /* Print verbosely the selected frame or the frame at address ADDR.
830 This means absolutely all information in the frame is printed. */
833 frame_info (char *addr_exp
, int from_tty
)
835 struct frame_info
*fi
;
836 struct symtab_and_line sal
;
839 struct frame_info
*calling_frame_info
;
840 int i
, count
, numregs
;
842 enum language funlang
= language_unknown
;
843 const char *pc_regname
;
845 if (!target_has_stack
)
848 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
849 is not a good name. */
851 /* OK, this is weird. The PC_REGNUM hardware register's value can
852 easily not match that of the internal value returned by
854 pc_regname
= REGISTER_NAME (PC_REGNUM
);
856 /* But then, this is weird to. Even without PC_REGNUM, an
857 architectures will often have a hardware register called "pc",
858 and that register's value, again, can easily not match
862 fi
= parse_frame_specification (addr_exp
);
864 error ("Invalid frame specified.");
866 find_frame_sal (fi
, &sal
);
867 func
= get_frame_function (fi
);
868 /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
870 s
= find_pc_symtab (get_frame_pc (fi
));
873 /* I'd like to use SYMBOL_PRINT_NAME() here, to display
874 * the demangled name that we already have stored in
875 * the symbol table, but we stored a version with
876 * DMGL_PARAMS turned on, and here we don't want
877 * to display parameters. So call the demangler again,
878 * with DMGL_ANSI only. RT
879 * (Yes, I know that printf_symbol_filtered() will
880 * again try to demangle the name on the fly, but
881 * the issue is that if cplus_demangle() fails here,
882 * it'll fail there too. So we want to catch the failure
883 * ("demangled==NULL" case below) here, while we still
884 * have our hands on the function symbol.)
887 funname
= DEPRECATED_SYMBOL_NAME (func
);
888 funlang
= SYMBOL_LANGUAGE (func
);
889 if (funlang
== language_cplus
)
891 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
892 /* If the demangler fails, try the demangled name
893 * from the symbol table. This'll have parameters,
894 * but that's preferable to diplaying a mangled name.
896 if (demangled
== NULL
)
897 funname
= SYMBOL_PRINT_NAME (func
);
902 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_pc (fi
));
905 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
906 funlang
= SYMBOL_LANGUAGE (msymbol
);
909 calling_frame_info
= get_prev_frame (fi
);
911 if (!addr_exp
&& frame_relative_level (deprecated_selected_frame
) >= 0)
913 printf_filtered ("Stack level %d, frame at ",
914 frame_relative_level (deprecated_selected_frame
));
915 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
916 printf_filtered (":\n");
920 printf_filtered ("Stack frame at ");
921 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
922 printf_filtered (":\n");
924 printf_filtered (" %s = ", pc_regname
);
925 print_address_numeric (get_frame_pc (fi
), 1, gdb_stdout
);
930 printf_filtered (" in ");
931 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
932 DMGL_ANSI
| DMGL_PARAMS
);
936 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
937 puts_filtered ("; ");
939 printf_filtered ("saved %s ", pc_regname
);
940 print_address_numeric (frame_pc_unwind (fi
), 1, gdb_stdout
);
941 printf_filtered ("\n");
945 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
947 printf_filtered (" (FRAMELESS),");
950 if (calling_frame_info
)
952 printf_filtered (" called by frame at ");
953 print_address_numeric (get_frame_base (calling_frame_info
),
956 if (get_next_frame (fi
) && calling_frame_info
)
959 if (get_next_frame (fi
))
961 printf_filtered (" caller of frame at ");
962 print_address_numeric (get_frame_base (get_next_frame (fi
)), 1,
965 if (get_next_frame (fi
) || calling_frame_info
)
966 puts_filtered ("\n");
968 printf_filtered (" source language %s.\n",
969 language_str (s
->language
));
971 #ifdef DEPRECATED_PRINT_EXTRA_FRAME_INFO
972 DEPRECATED_PRINT_EXTRA_FRAME_INFO (fi
);
976 /* Address of the argument list for this frame, or 0. */
977 CORE_ADDR arg_list
= get_frame_args_address (fi
);
978 /* Number of args for this frame, or -1 if unknown. */
982 printf_filtered (" Arglist at unknown address.\n");
985 printf_filtered (" Arglist at ");
986 print_address_numeric (arg_list
, 1, gdb_stdout
);
987 printf_filtered (",");
989 if (!FRAME_NUM_ARGS_P ())
992 puts_filtered (" args: ");
996 numargs
= FRAME_NUM_ARGS (fi
);
997 gdb_assert (numargs
>= 0);
999 puts_filtered (" no args.");
1000 else if (numargs
== 1)
1001 puts_filtered (" 1 arg: ");
1003 printf_filtered (" %d args: ", numargs
);
1005 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
1006 puts_filtered ("\n");
1010 /* Address of the local variables for this frame, or 0. */
1011 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1014 printf_filtered (" Locals at unknown address,");
1017 printf_filtered (" Locals at ");
1018 print_address_numeric (arg_list
, 1, gdb_stdout
);
1019 printf_filtered (",");
1023 if (DEPRECATED_FRAME_INIT_SAVED_REGS_P ()
1024 && deprecated_get_frame_saved_regs (fi
) == NULL
)
1025 DEPRECATED_FRAME_INIT_SAVED_REGS (fi
);
1026 /* Print as much information as possible on the location of all the
1029 enum lval_type lval
;
1037 /* The sp is special; what's displayed isn't the save address, but
1038 the value of the previous frame's sp. This is a legacy thing,
1039 at one stage the frame cached the previous frame's SP instead
1040 of its address, hence it was easiest to just display the cached
1044 /* Find out the location of the saved stack pointer with out
1045 actually evaluating it. */
1046 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1048 if (!optimized
&& lval
== not_lval
)
1050 char value
[MAX_REGISTER_SIZE
];
1052 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1054 /* NOTE: cagney/2003-05-22: This is assuming that the
1055 stack pointer was packed as an unsigned integer. That
1056 may or may not be valid. */
1057 sp
= extract_unsigned_integer (value
, DEPRECATED_REGISTER_RAW_SIZE (SP_REGNUM
));
1058 printf_filtered (" Previous frame's sp is ");
1059 print_address_numeric (sp
, 1, gdb_stdout
);
1060 printf_filtered ("\n");
1063 else if (!optimized
&& lval
== lval_memory
)
1065 printf_filtered (" Previous frame's sp at ");
1066 print_address_numeric (addr
, 1, gdb_stdout
);
1067 printf_filtered ("\n");
1070 else if (!optimized
&& lval
== lval_register
)
1072 printf_filtered (" Previous frame's sp in %s\n",
1073 REGISTER_NAME (realnum
));
1076 /* else keep quiet. */
1080 numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
1081 for (i
= 0; i
< numregs
; i
++)
1083 && gdbarch_register_reggroup_p (current_gdbarch
, i
, all_reggroup
))
1085 /* Find out the location of the saved register without
1086 fetching the corresponding value. */
1087 frame_register_unwind (fi
, i
, &optimized
, &lval
, &addr
, &realnum
,
1089 /* For moment, only display registers that were saved on the
1091 if (!optimized
&& lval
== lval_memory
)
1094 puts_filtered (" Saved registers:\n ");
1096 puts_filtered (",");
1098 printf_filtered (" %s at ", REGISTER_NAME (i
));
1099 print_address_numeric (addr
, 1, gdb_stdout
);
1103 if (count
|| need_nl
)
1104 puts_filtered ("\n");
1109 /* Set a limit on the number of frames printed by default in a
1112 static int backtrace_limit
;
1115 set_backtrace_limit_command (char *count_exp
, int from_tty
)
1117 int count
= parse_and_eval_long (count_exp
);
1120 error ("Negative argument not meaningful as backtrace limit.");
1122 backtrace_limit
= count
;
1126 backtrace_limit_info (char *arg
, int from_tty
)
1129 error ("\"Info backtrace-limit\" takes no arguments.");
1131 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit
);
1135 /* Print briefly all stack frames or just the innermost COUNT frames. */
1137 static void backtrace_command_1 (char *count_exp
, int show_locals
,
1140 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1142 struct frame_info
*fi
;
1145 struct frame_info
*trailing
;
1148 if (!target_has_stack
)
1149 error ("No stack.");
1151 /* The following code must do two things. First, it must
1152 set the variable TRAILING to the frame from which we should start
1153 printing. Second, it must set the variable count to the number
1154 of frames which we should print, or -1 if all of them. */
1155 trailing
= get_current_frame ();
1157 /* The target can be in a state where there is no valid frames
1158 (e.g., just connected). */
1159 if (trailing
== NULL
)
1160 error ("No stack.");
1165 count
= parse_and_eval_long (count_exp
);
1168 struct frame_info
*current
;
1173 while (current
&& count
--)
1176 current
= get_prev_frame (current
);
1179 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1180 will be COUNT below it. */
1184 trailing
= get_prev_frame (trailing
);
1185 current
= get_prev_frame (current
);
1197 struct partial_symtab
*ps
;
1199 /* Read in symbols for all of the frames. Need to do this in
1200 a separate pass so that "Reading in symbols for xxx" messages
1201 don't screw up the appearance of the backtrace. Also
1202 if people have strong opinions against reading symbols for
1203 backtrace this may have to be an option. */
1207 fi
= get_prev_frame (fi
))
1210 ps
= find_pc_psymtab (get_frame_address_in_block (fi
));
1212 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
1216 for (i
= 0, fi
= trailing
;
1218 i
++, fi
= get_prev_frame (fi
))
1222 /* Don't use print_stack_frame; if an error() occurs it probably
1223 means further attempts to backtrace would fail (on the other
1224 hand, perhaps the code does or could be fixed to make sure
1225 the frame->prev field gets set to NULL in that case). */
1226 print_frame_info (fi
, trailing_level
+ i
, 0, 1);
1228 print_frame_local_vars (fi
, 1, gdb_stdout
);
1231 /* If we've stopped before the end, mention that. */
1233 printf_filtered ("(More stack frames follow...)\n");
1237 backtrace_command (char *arg
, int from_tty
)
1239 struct cleanup
*old_chain
= (struct cleanup
*) NULL
;
1240 char **argv
= (char **) NULL
;
1241 int argIndicatingFullTrace
= (-1), totArgLen
= 0, argc
= 0;
1244 if (arg
!= (char *) NULL
)
1248 argv
= buildargv (arg
);
1249 old_chain
= make_cleanup_freeargv (argv
);
1251 for (i
= 0; (argv
[i
] != (char *) NULL
); i
++)
1255 for (j
= 0; (j
< strlen (argv
[i
])); j
++)
1256 argv
[i
][j
] = tolower (argv
[i
][j
]);
1258 if (argIndicatingFullTrace
< 0 && subset_compare (argv
[i
], "full"))
1259 argIndicatingFullTrace
= argc
;
1263 totArgLen
+= strlen (argv
[i
]);
1267 if (argIndicatingFullTrace
>= 0)
1271 argPtr
= (char *) xmalloc (totArgLen
+ 1);
1276 memset (argPtr
, 0, totArgLen
+ 1);
1277 for (i
= 0; (i
< (argc
+ 1)); i
++)
1279 if (i
!= argIndicatingFullTrace
)
1281 strcat (argPtr
, argv
[i
]);
1282 strcat (argPtr
, " ");
1288 argPtr
= (char *) NULL
;
1292 backtrace_command_1 (argPtr
, (argIndicatingFullTrace
>= 0), from_tty
);
1294 if (argIndicatingFullTrace
>= 0 && totArgLen
> 0)
1298 do_cleanups (old_chain
);
1301 static void backtrace_full_command (char *arg
, int from_tty
);
1303 backtrace_full_command (char *arg
, int from_tty
)
1305 backtrace_command_1 (arg
, 1, from_tty
);
1309 /* Print the local variables of a block B active in FRAME.
1310 Return 1 if any variables were printed; 0 otherwise. */
1313 print_block_frame_locals (struct block
*b
, struct frame_info
*fi
,
1314 int num_tabs
, struct ui_file
*stream
)
1316 struct dict_iterator iter
;
1319 int values_printed
= 0;
1321 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1323 switch (SYMBOL_CLASS (sym
))
1331 for (j
= 0; j
< num_tabs
; j
++)
1332 fputs_filtered ("\t", stream
);
1333 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1334 fputs_filtered (" = ", stream
);
1335 print_variable_value (sym
, fi
, stream
);
1336 fprintf_filtered (stream
, "\n");
1340 /* Ignore symbols which are not locals. */
1344 return values_printed
;
1347 /* Same, but print labels. */
1350 print_block_frame_labels (struct block
*b
, int *have_default
,
1351 struct ui_file
*stream
)
1353 struct dict_iterator iter
;
1355 int values_printed
= 0;
1357 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1359 if (STREQ (DEPRECATED_SYMBOL_NAME (sym
), "default"))
1365 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1367 struct symtab_and_line sal
;
1368 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1370 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1373 fprintf_filtered (stream
, " ");
1374 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1376 fprintf_filtered (stream
, " in file %s, line %d\n",
1377 sal
.symtab
->filename
, sal
.line
);
1380 return values_printed
;
1383 /* Print on STREAM all the local variables in frame FRAME,
1384 including all the blocks active in that frame
1387 Returns 1 if the job was done,
1388 or 0 if nothing was printed because we have no info
1389 on the function running in FRAME. */
1392 print_frame_local_vars (struct frame_info
*fi
, int num_tabs
,
1393 struct ui_file
*stream
)
1395 struct block
*block
= get_frame_block (fi
, 0);
1396 int values_printed
= 0;
1400 fprintf_filtered (stream
, "No symbol table info available.\n");
1406 if (print_block_frame_locals (block
, fi
, num_tabs
, stream
))
1408 /* After handling the function's top-level block, stop.
1409 Don't continue to its superblock, the block of
1410 per-file symbols. */
1411 if (BLOCK_FUNCTION (block
))
1413 block
= BLOCK_SUPERBLOCK (block
);
1416 if (!values_printed
)
1418 fprintf_filtered (stream
, "No locals.\n");
1422 /* Same, but print labels. */
1425 print_frame_label_vars (struct frame_info
*fi
, int this_level_only
,
1426 struct ui_file
*stream
)
1428 struct blockvector
*bl
;
1429 struct block
*block
= get_frame_block (fi
, 0);
1430 int values_printed
= 0;
1431 int index
, have_default
= 0;
1432 char *blocks_printed
;
1433 CORE_ADDR pc
= get_frame_pc (fi
);
1437 fprintf_filtered (stream
, "No symbol table info available.\n");
1441 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1442 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1443 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1447 CORE_ADDR end
= BLOCK_END (block
) - 4;
1450 if (bl
!= blockvector_for_pc (end
, &index
))
1451 error ("blockvector blotch");
1452 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1453 error ("blockvector botch");
1454 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1457 /* Don't print out blocks that have gone by. */
1458 while (index
< last_index
1459 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1462 while (index
< last_index
1463 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1465 if (blocks_printed
[index
] == 0)
1467 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
1469 blocks_printed
[index
] = 1;
1475 if (values_printed
&& this_level_only
)
1478 /* After handling the function's top-level block, stop.
1479 Don't continue to its superblock, the block of
1480 per-file symbols. */
1481 if (BLOCK_FUNCTION (block
))
1483 block
= BLOCK_SUPERBLOCK (block
);
1486 if (!values_printed
&& !this_level_only
)
1488 fprintf_filtered (stream
, "No catches.\n");
1493 locals_info (char *args
, int from_tty
)
1495 if (!deprecated_selected_frame
)
1496 error ("No frame selected.");
1497 print_frame_local_vars (deprecated_selected_frame
, 0, gdb_stdout
);
1501 catch_info (char *ignore
, int from_tty
)
1503 struct symtab_and_line
*sal
;
1505 /* Check for target support for exception handling */
1506 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1509 /* Currently not handling this */
1510 /* Ideally, here we should interact with the C++ runtime
1511 system to find the list of active handlers, etc. */
1512 fprintf_filtered (gdb_stdout
, "Info catch not supported with this target/compiler combination.\n");
1514 if (!deprecated_selected_frame
)
1515 error ("No frame selected.");
1520 /* Assume g++ compiled code -- old v 4.16 behaviour */
1521 if (!deprecated_selected_frame
)
1522 error ("No frame selected.");
1524 print_frame_label_vars (deprecated_selected_frame
, 0, gdb_stdout
);
1529 print_frame_arg_vars (struct frame_info
*fi
,
1530 struct ui_file
*stream
)
1532 struct symbol
*func
= get_frame_function (fi
);
1534 struct dict_iterator iter
;
1535 struct symbol
*sym
, *sym2
;
1536 int values_printed
= 0;
1540 fprintf_filtered (stream
, "No symbol table info available.\n");
1544 b
= SYMBOL_BLOCK_VALUE (func
);
1545 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1547 switch (SYMBOL_CLASS (sym
))
1553 case LOC_REGPARM_ADDR
:
1554 case LOC_BASEREG_ARG
:
1555 case LOC_COMPUTED_ARG
:
1557 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1558 fputs_filtered (" = ", stream
);
1560 /* We have to look up the symbol because arguments can have
1561 two entries (one a parameter, one a local) and the one we
1562 want is the local, which lookup_symbol will find for us.
1563 This includes gcc1 (not gcc2) on the sparc when passing a
1564 small structure and gcc2 when the argument type is float
1565 and it is passed as a double and converted to float by
1566 the prologue (in the latter case the type of the LOC_ARG
1567 symbol is double and the type of the LOC_LOCAL symbol is
1568 float). There are also LOC_ARG/LOC_REGISTER pairs which
1569 are not combined in symbol-reading. */
1571 sym2
= lookup_symbol (DEPRECATED_SYMBOL_NAME (sym
),
1572 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
1573 print_variable_value (sym2
, fi
, stream
);
1574 fprintf_filtered (stream
, "\n");
1578 /* Don't worry about things which aren't arguments. */
1582 if (!values_printed
)
1584 fprintf_filtered (stream
, "No arguments.\n");
1589 args_info (char *ignore
, int from_tty
)
1591 if (!deprecated_selected_frame
)
1592 error ("No frame selected.");
1593 print_frame_arg_vars (deprecated_selected_frame
, gdb_stdout
);
1598 args_plus_locals_info (char *ignore
, int from_tty
)
1600 args_info (ignore
, from_tty
);
1601 locals_info (ignore
, from_tty
);
1605 /* Select frame FI. Also print the stack frame and show the source if
1606 this is the tui version. */
1608 select_and_print_frame (struct frame_info
*fi
)
1613 print_stack_frame (fi
, frame_relative_level (fi
), 1);
1617 /* Return the symbol-block in which the selected frame is executing.
1618 Can return zero under various legitimate circumstances.
1620 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1621 code address within the block returned. We use this to decide
1622 which macros are in scope. */
1625 get_selected_block (CORE_ADDR
*addr_in_block
)
1627 if (!target_has_stack
)
1630 /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1631 a selected/current frame? Perhaphs this function is called,
1632 indirectly, by WFI in "infrun.c" where avoiding the creation of
1633 an inner most frame is very important (it slows down single
1634 step). I suspect, though that this was true in the deep dark
1635 past but is no longer the case. A mindless look at all the
1636 callers tends to support this theory. I think we should be able
1637 to assume that there is always a selcted frame. */
1638 /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1640 if (!deprecated_selected_frame
)
1642 CORE_ADDR pc
= read_pc ();
1643 if (addr_in_block
!= NULL
)
1644 *addr_in_block
= pc
;
1645 return block_for_pc (pc
);
1647 return get_frame_block (deprecated_selected_frame
, addr_in_block
);
1650 /* Find a frame a certain number of levels away from FRAME.
1651 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1652 Positive means go to earlier frames (up); negative, the reverse.
1653 The int that contains the number of levels is counted toward
1654 zero as the frames for those levels are found.
1655 If the top or bottom frame is reached, that frame is returned,
1656 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1657 how much farther the original request asked to go. */
1660 find_relative_frame (struct frame_info
*frame
,
1661 int *level_offset_ptr
)
1663 struct frame_info
*prev
;
1664 struct frame_info
*frame1
;
1666 /* Going up is simple: just do get_prev_frame enough times
1667 or until initial frame is reached. */
1668 while (*level_offset_ptr
> 0)
1670 prev
= get_prev_frame (frame
);
1673 (*level_offset_ptr
)--;
1676 /* Going down is just as simple. */
1677 if (*level_offset_ptr
< 0)
1679 while (*level_offset_ptr
< 0)
1681 frame1
= get_next_frame (frame
);
1685 (*level_offset_ptr
)++;
1691 /* The "select_frame" command. With no arg, NOP.
1692 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1693 valid level. Otherwise, treat level_exp as an address expression
1694 and select it. See parse_frame_specification for more info on proper
1695 frame expressions. */
1698 select_frame_command (char *level_exp
, int from_tty
)
1700 struct frame_info
*frame
;
1701 int level
= frame_relative_level (deprecated_selected_frame
);
1703 if (!target_has_stack
)
1704 error ("No stack.");
1706 frame
= parse_frame_specification (level_exp
);
1708 select_frame (frame
);
1709 if (level
!= frame_relative_level (deprecated_selected_frame
))
1710 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1713 /* The "frame" command. With no arg, print selected frame briefly.
1714 With arg, behaves like select_frame and then prints the selected
1718 frame_command (char *level_exp
, int from_tty
)
1720 select_frame_command (level_exp
, from_tty
);
1721 print_stack_frame (deprecated_selected_frame
,
1722 frame_relative_level (deprecated_selected_frame
), 1);
1725 /* The XDB Compatibility command to print the current frame. */
1728 current_frame_command (char *level_exp
, int from_tty
)
1730 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1731 error ("No stack.");
1732 print_stack_frame (deprecated_selected_frame
,
1733 frame_relative_level (deprecated_selected_frame
), 1);
1736 /* Select the frame up one or COUNT stack levels
1737 from the previously selected frame, and print it briefly. */
1740 up_silently_base (char *count_exp
)
1742 struct frame_info
*fi
;
1743 int count
= 1, count1
;
1745 count
= parse_and_eval_long (count_exp
);
1748 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1749 error ("No stack.");
1751 fi
= find_relative_frame (deprecated_selected_frame
, &count1
);
1752 if (count1
!= 0 && count_exp
== 0)
1753 error ("Initial frame selected; you cannot go up.");
1755 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1759 up_silently_command (char *count_exp
, int from_tty
)
1761 up_silently_base (count_exp
);
1765 up_command (char *count_exp
, int from_tty
)
1767 up_silently_base (count_exp
);
1768 print_stack_frame (deprecated_selected_frame
,
1769 frame_relative_level (deprecated_selected_frame
), 1);
1772 /* Select the frame down one or COUNT stack levels
1773 from the previously selected frame, and print it briefly. */
1776 down_silently_base (char *count_exp
)
1778 struct frame_info
*frame
;
1779 int count
= -1, count1
;
1781 count
= -parse_and_eval_long (count_exp
);
1784 if (target_has_stack
== 0 || deprecated_selected_frame
== 0)
1785 error ("No stack.");
1787 frame
= find_relative_frame (deprecated_selected_frame
, &count1
);
1788 if (count1
!= 0 && count_exp
== 0)
1791 /* We only do this if count_exp is not specified. That way "down"
1792 means to really go down (and let me know if that is
1793 impossible), but "down 9999" can be used to mean go all the way
1794 down without getting an error. */
1796 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1799 select_frame (frame
);
1800 selected_frame_level_changed_event (frame_relative_level (deprecated_selected_frame
));
1804 down_silently_command (char *count_exp
, int from_tty
)
1806 down_silently_base (count_exp
);
1810 down_command (char *count_exp
, int from_tty
)
1812 down_silently_base (count_exp
);
1813 print_stack_frame (deprecated_selected_frame
,
1814 frame_relative_level (deprecated_selected_frame
), 1);
1818 return_command (char *retval_exp
, int from_tty
)
1820 struct symbol
*thisfun
;
1821 struct value
*return_value
= NULL
;
1822 const char *query_prefix
= "";
1824 /* FIXME: cagney/2003-10-20: Perform a minimal existance test on the
1825 target. If that fails, error out. For the moment don't rely on
1826 get_selected_frame as it's error message is the the singularly
1827 obscure "No registers". */
1828 if (!target_has_registers
)
1829 error ("No selected frame.");
1830 thisfun
= get_frame_function (get_selected_frame ());
1832 /* Compute the return value. If the computation triggers an error,
1833 let it bail. If the return type can't be handled, set
1834 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1838 struct type
*return_type
= NULL
;
1840 /* Compute the return value. Should the computation fail, this
1841 call throws an error. */
1842 return_value
= parse_and_eval (retval_exp
);
1844 /* Cast return value to the return type of the function. Should
1845 the cast fail, this call throws an error. */
1846 if (thisfun
!= NULL
)
1847 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1848 if (return_type
== NULL
)
1849 return_type
= builtin_type_int
;
1850 return_value
= value_cast (return_type
, return_value
);
1852 /* Make sure the value is fully evaluated. It may live in the
1853 stack frame we're about to pop. */
1854 if (VALUE_LAZY (return_value
))
1855 value_fetch_lazy (return_value
);
1857 /* Check that this architecture can handle the function's return
1858 type. In the case of "struct convention", still do the
1859 "return", just also warn the user. */
1860 if (gdbarch_return_value_p (current_gdbarch
))
1862 if (gdbarch_return_value (current_gdbarch
, return_type
,
1864 == RETURN_VALUE_REGISTER_CONVENTION
)
1865 return_value
= NULL
;
1869 /* NOTE: cagney/2003-10-20: The double check is to ensure
1870 that the STORE_RETURN_VALUE call, further down, is not
1871 applied to a struct or union return-value. It wasn't
1872 allowed previously, so don't start allowing it now. An
1873 ABI that uses "register convention" to return small
1874 structures and should implement the "return_value"
1875 architecture method. */
1876 if (using_struct_return (return_type
, 0)
1877 || TYPE_CODE (return_type
) == TYPE_CODE_STRUCT
1878 || TYPE_CODE (return_type
) == TYPE_CODE_UNION
)
1879 return_value
= NULL
;
1881 if (return_value
== NULL
)
1883 The location at which to store the function's return value is unknown.\n";
1886 /* Does an interactive user really want to do this? Include
1887 information, such as how well GDB can handle the return value, in
1888 the query message. */
1892 if (thisfun
== NULL
)
1893 confirmed
= query ("%sMake selected stack frame return now? ",
1896 confirmed
= query ("%sMake %s return now? ", query_prefix
,
1897 SYMBOL_PRINT_NAME (thisfun
));
1899 error ("Not confirmed");
1902 /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each
1903 frame in turn, should this code just go straight to the relevant
1904 frame and pop that? */
1906 /* First discard all frames inner-to the selected frame (making the
1907 selected frame current). */
1909 struct frame_id selected_id
= get_frame_id (get_selected_frame ());
1910 while (!frame_id_eq (selected_id
, get_frame_id (get_current_frame ())))
1912 if (frame_id_inner (selected_id
, get_frame_id (get_current_frame ())))
1913 /* Caught in the safety net, oops! We've gone way past the
1915 error ("Problem while popping stack frames (corrupt stack?)");
1916 frame_pop (get_current_frame ());
1920 /* Second discard the selected frame (which is now also the current
1922 frame_pop (get_current_frame ());
1924 /* Store RETURN_VAUE in the just-returned register set. */
1925 if (return_value
!= NULL
)
1927 struct type
*return_type
= VALUE_TYPE (return_value
);
1928 if (!gdbarch_return_value_p (current_gdbarch
))
1930 STORE_RETURN_VALUE (return_type
, current_regcache
,
1931 VALUE_CONTENTS (return_value
));
1935 gdb_assert (gdbarch_return_value (current_gdbarch
, return_type
,
1937 == RETURN_VALUE_REGISTER_CONVENTION
);
1938 gdbarch_return_value (current_gdbarch
, return_type
, current_regcache
,
1939 VALUE_CONTENTS (return_value
), NULL
);
1943 /* If we are at the end of a call dummy now, pop the dummy frame
1945 /* NOTE: cagney/2003-01-18: Is this silly? Instead of popping all
1946 the frames in sequence, should this code just pop the dummy frame
1948 #ifdef DEPRECATED_CALL_DUMMY_HAS_COMPLETED
1949 /* Since all up-to-date architectures return direct to the dummy
1950 breakpoint address, a dummy frame has, by definition, always
1951 completed. Hence this method is no longer needed. */
1952 if (DEPRECATED_CALL_DUMMY_HAS_COMPLETED (read_pc(), read_sp (),
1953 get_frame_base (get_current_frame ())))
1954 frame_pop (get_current_frame ());
1956 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
1957 frame_pop (get_current_frame ());
1960 /* If interactive, print the frame that is now current. */
1962 frame_command ("0", 1);
1964 select_frame_command ("0", 0);
1967 /* Sets the scope to input function name, provided that the
1968 function is within the current stack frame */
1970 struct function_bounds
1972 CORE_ADDR low
, high
;
1975 static void func_command (char *arg
, int from_tty
);
1977 func_command (char *arg
, int from_tty
)
1979 struct frame_info
*fp
;
1981 struct symtabs_and_lines sals
;
1984 struct function_bounds
*func_bounds
= (struct function_bounds
*) NULL
;
1986 if (arg
!= (char *) NULL
)
1989 fp
= parse_frame_specification ("0");
1990 sals
= decode_line_spec (arg
, 1);
1991 func_bounds
= (struct function_bounds
*) xmalloc (
1992 sizeof (struct function_bounds
) * sals
.nelts
);
1993 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1995 if (sals
.sals
[i
].pc
== (CORE_ADDR
) 0 ||
1996 find_pc_partial_function (sals
.sals
[i
].pc
,
1998 &func_bounds
[i
].low
,
1999 &func_bounds
[i
].high
) == 0)
2001 func_bounds
[i
].low
=
2002 func_bounds
[i
].high
= (CORE_ADDR
) NULL
;
2008 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
2009 found
= (get_frame_pc (fp
) >= func_bounds
[i
].low
&&
2010 get_frame_pc (fp
) < func_bounds
[i
].high
);
2014 fp
= find_relative_frame (fp
, &level
);
2017 while (!found
&& level
== 0);
2020 xfree (func_bounds
);
2023 printf_filtered ("'%s' not within current stack frame.\n", arg
);
2024 else if (fp
!= deprecated_selected_frame
)
2025 select_and_print_frame (fp
);
2028 /* Gets the language of the current frame. */
2031 get_frame_language (void)
2034 enum language flang
; /* The language of the current frame */
2036 if (deprecated_selected_frame
)
2038 s
= find_pc_symtab (get_frame_pc (deprecated_selected_frame
));
2040 flang
= s
->language
;
2042 flang
= language_unknown
;
2045 flang
= language_unknown
;
2051 _initialize_stack (void)
2054 backtrace_limit
= 30;
2057 add_com ("return", class_stack
, return_command
,
2058 "Make selected stack frame return to its caller.\n\
2059 Control remains in the debugger, but when you continue\n\
2060 execution will resume in the frame above the one now selected.\n\
2061 If an argument is given, it is an expression for the value to return.");
2063 add_com ("up", class_stack
, up_command
,
2064 "Select and print stack frame that called this one.\n\
2065 An argument says how many frames up to go.");
2066 add_com ("up-silently", class_support
, up_silently_command
,
2067 "Same as the `up' command, but does not print anything.\n\
2068 This is useful in command scripts.");
2070 add_com ("down", class_stack
, down_command
,
2071 "Select and print stack frame called by this one.\n\
2072 An argument says how many frames down to go.");
2073 add_com_alias ("do", "down", class_stack
, 1);
2074 add_com_alias ("dow", "down", class_stack
, 1);
2075 add_com ("down-silently", class_support
, down_silently_command
,
2076 "Same as the `down' command, but does not print anything.\n\
2077 This is useful in command scripts.");
2079 add_com ("frame", class_stack
, frame_command
,
2080 "Select and print a stack frame.\n\
2081 With no argument, print the selected stack frame. (See also \"info frame\").\n\
2082 An argument specifies the frame to select.\n\
2083 It can be a stack frame number or the address of the frame.\n\
2084 With argument, nothing is printed if input is coming from\n\
2085 a command file or a user-defined command.");
2087 add_com_alias ("f", "frame", class_stack
, 1);
2091 add_com ("L", class_stack
, current_frame_command
,
2092 "Print the current stack frame.\n");
2093 add_com_alias ("V", "frame", class_stack
, 1);
2095 add_com ("select-frame", class_stack
, select_frame_command
,
2096 "Select a stack frame without printing anything.\n\
2097 An argument specifies the frame to select.\n\
2098 It can be a stack frame number or the address of the frame.\n");
2100 add_com ("backtrace", class_stack
, backtrace_command
,
2101 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2102 With a negative argument, print outermost -COUNT frames.\n\
2103 Use of the 'full' qualifier also prints the values of the local variables.\n");
2104 add_com_alias ("bt", "backtrace", class_stack
, 0);
2107 add_com_alias ("t", "backtrace", class_stack
, 0);
2108 add_com ("T", class_stack
, backtrace_full_command
,
2109 "Print backtrace of all stack frames, or innermost COUNT frames \n\
2110 and the values of the local variables.\n\
2111 With a negative argument, print outermost -COUNT frames.\n\
2112 Usage: T <count>\n");
2115 add_com_alias ("where", "backtrace", class_alias
, 0);
2116 add_info ("stack", backtrace_command
,
2117 "Backtrace of the stack, or innermost COUNT frames.");
2118 add_info_alias ("s", "stack", 1);
2119 add_info ("frame", frame_info
,
2120 "All about selected stack frame, or frame at ADDR.");
2121 add_info_alias ("f", "frame", 1);
2122 add_info ("locals", locals_info
,
2123 "Local variables of current stack frame.");
2124 add_info ("args", args_info
,
2125 "Argument variables of current stack frame.");
2127 add_com ("l", class_info
, args_plus_locals_info
,
2128 "Argument and local variables of current stack frame.");
2131 add_com ("func", class_stack
, func_command
,
2132 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2134 add_info ("catch", catch_info
,
2135 "Exceptions that can be caught in the current stack frame.");
2138 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
2139 "Specify maximum number of frames for \"backtrace\" to print by default.",
2141 add_info ("backtrace-limit", backtrace_limit_info
,
2142 "The maximum number of frames for \"backtrace\" to print by default.");