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, 2004 Free
5 Software Foundation, Inc.
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 (*deprecated_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
,
99 enum print_what print_what
,
101 struct symtab_and_line sal
);
103 static void set_current_sal_from_frame (struct frame_info
*, int);
105 static void backtrace_command (char *, int);
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
;
124 enum print_what print_what
;
128 /* Show or print the frame arguments.
129 Pass the args the way catch_errors wants them. */
131 print_stack_frame_stub (void *args
)
133 struct print_stack_frame_args
*p
= args
;
134 int center
= (p
->print_what
== SRC_LINE
135 || p
->print_what
== SRC_AND_LOC
);
137 print_frame_info (p
->fi
, p
->print_level
, p
->print_what
, p
->print_args
);
138 set_current_sal_from_frame (p
->fi
, center
);
142 /* Show or print a stack frame FI briefly. The output is format
143 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
144 relative level, function name, argument list, and file name and
145 line number. If the frame's PC is not at the beginning of the
146 source line, the actual PC is printed at the beginning. */
149 print_stack_frame (struct frame_info
*fi
, int print_level
,
150 enum print_what print_what
)
152 struct print_stack_frame_args args
;
155 args
.print_level
= print_level
;
156 args
.print_what
= print_what
;
159 catch_errors (print_stack_frame_stub
, (char *) &args
, "", RETURN_MASK_ALL
);
162 struct print_args_args
165 struct frame_info
*fi
;
166 struct ui_file
*stream
;
169 static int print_args_stub (void *);
171 /* Print nameless args on STREAM.
172 FI is the frameinfo for this frame, START is the offset
173 of the first nameless arg, and NUM is the number of nameless args to
174 print. FIRST is nonzero if this is the first argument (not just
175 the first nameless arg). */
178 print_frame_nameless_args (struct frame_info
*fi
, long start
, int num
,
179 int first
, struct ui_file
*stream
)
185 for (i
= 0; i
< num
; i
++)
188 argsaddr
= get_frame_args_address (fi
);
191 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
193 fprintf_filtered (stream
, ", ");
194 fprintf_filtered (stream
, "%ld", arg_value
);
196 start
+= sizeof (int);
200 /* Print the arguments of a stack frame, given the function FUNC
201 running in that frame (as a symbol), the info on the frame,
202 and the number of args according to the stack frame (or -1 if unknown). */
204 /* References here and elsewhere to "number of args according to the
205 stack frame" appear in all cases to refer to "number of ints of args
206 according to the stack frame". At least for VAX, i386, isi. */
209 print_frame_args (struct symbol
*func
, struct frame_info
*fi
, int num
,
210 struct ui_file
*stream
)
212 struct block
*b
= NULL
;
214 struct dict_iterator iter
;
217 /* Offset of next stack argument beyond the one we have seen that is
218 at the highest offset.
219 -1 if we haven't come to a stack argument yet. */
220 long highest_offset
= -1;
222 /* Number of ints of arguments that we have printed so far. */
223 int args_printed
= 0;
224 struct cleanup
*old_chain
, *list_chain
;
225 struct ui_stream
*stb
;
227 stb
= ui_out_stream_new (uiout
);
228 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
232 b
= SYMBOL_BLOCK_VALUE (func
);
234 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
238 /* Keep track of the highest stack argument offset seen, and
239 skip over any kinds of symbols we don't care about. */
241 switch (SYMBOL_CLASS (sym
))
246 long current_offset
= SYMBOL_VALUE (sym
);
247 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
249 /* Compute address of next argument by adding the size of
250 this argument and rounding to an int boundary. */
252 ((current_offset
+ arg_size
+ sizeof (int) - 1)
253 & ~(sizeof (int) - 1));
255 /* If this is the highest offset seen yet, set highest_offset. */
256 if (highest_offset
== -1
257 || (current_offset
> highest_offset
))
258 highest_offset
= current_offset
;
260 /* Add the number of ints we're about to print to args_printed. */
261 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
264 /* We care about types of symbols, but don't need to keep track of
265 stack offsets in them. */
267 case LOC_REGPARM_ADDR
:
269 case LOC_BASEREG_ARG
:
270 case LOC_COMPUTED_ARG
:
273 /* Other types of symbols we just skip over. */
278 /* We have to look up the symbol because arguments can have
279 two entries (one a parameter, one a local) and the one we
280 want is the local, which lookup_symbol will find for us.
281 This includes gcc1 (not gcc2) on the sparc when passing a
282 small structure and gcc2 when the argument type is float
283 and it is passed as a double and converted to float by
284 the prologue (in the latter case the type of the LOC_ARG
285 symbol is double and the type of the LOC_LOCAL symbol is
287 /* But if the parameter name is null, don't try it.
288 Null parameter names occur on the RS/6000, for traceback tables.
289 FIXME, should we even print them? */
291 if (*DEPRECATED_SYMBOL_NAME (sym
))
295 (DEPRECATED_SYMBOL_NAME (sym
),
296 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
297 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
299 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
300 it was passed on the stack and loaded into a register,
301 or passed in a register and stored in a stack slot.
302 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
304 Reasons for using the LOC_ARG:
305 (1) because find_saved_registers may be slow for remote
307 (2) because registers are often re-used and stack slots
308 rarely (never?) are. Therefore using the stack slot is
309 much less likely to print garbage.
311 Reasons why we might want to use the LOC_REGISTER:
312 (1) So that the backtrace prints the same value as
313 "print foo". I see no compelling reason why this needs
314 to be the case; having the backtrace print the value which
315 was passed in, and "print foo" print the value as modified
316 within the called function, makes perfect sense to me.
318 Additional note: It might be nice if "info args" displayed
320 One more note: There is a case with sparc structure passing
321 where we need to use the LOC_REGISTER, but this is dealt with
322 by creating a single LOC_REGPARM in symbol reading. */
324 /* Leave sym (the LOC_ARG) alone. */
331 /* Print the current arg. */
333 ui_out_text (uiout
, ", ");
334 ui_out_wrap_hint (uiout
, " ");
336 annotate_arg_begin ();
338 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
339 fprintf_symbol_filtered (stb
->stream
, SYMBOL_PRINT_NAME (sym
),
340 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
341 ui_out_field_stream (uiout
, "name", stb
);
342 annotate_arg_name_end ();
343 ui_out_text (uiout
, "=");
345 /* Avoid value_print because it will deref ref parameters. We just
346 want to print their addresses. Print ??? for args whose address
347 we do not know. We pass 2 as "recurse" to val_print because our
348 standard indentation here is 4 spaces, and val_print indents
349 2 for each recurse. */
350 val
= read_var_value (sym
, fi
);
352 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
356 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
358 stb
->stream
, 0, 0, 2, Val_no_prettyprint
);
359 ui_out_field_stream (uiout
, "value", stb
);
362 ui_out_text (uiout
, "???");
364 /* Invoke ui_out_tuple_end. */
365 do_cleanups (list_chain
);
373 /* Don't print nameless args in situations where we don't know
374 enough about the stack to find them. */
379 if (highest_offset
== -1)
380 start
= FRAME_ARGS_SKIP
;
382 start
= highest_offset
;
384 print_frame_nameless_args (fi
, start
, num
- args_printed
,
387 do_cleanups (old_chain
);
390 /* Pass the args the way catch_errors wants them. */
393 print_args_stub (void *args
)
396 struct print_args_args
*p
= (struct print_args_args
*) args
;
398 if (FRAME_NUM_ARGS_P ())
400 numargs
= FRAME_NUM_ARGS (p
->fi
);
401 gdb_assert (numargs
>= 0);
405 print_frame_args (p
->func
, p
->fi
, numargs
, p
->stream
);
409 /* Set the current source and line to the location of the given
410 frame, if possible. When CENTER is true, adjust so the
411 relevant line is in the center of the next 'list'. */
414 set_current_sal_from_frame (struct frame_info
*fi
, int center
)
416 struct symtab_and_line sal
;
418 find_frame_sal (fi
, &sal
);
422 sal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
423 set_current_source_symtab_and_line (&sal
);
427 /* Print information about a frame for frame "fi" at level "level".
428 Used in "where" output, also used to emit breakpoint or step
430 LEVEL is the level of the frame, or -1 if it is the
431 innermost frame but we don't want to print the level.
432 The meaning of the SOURCE argument is:
433 SRC_LINE: Print only source line
434 LOCATION: Print only location
435 LOC_AND_SRC: Print location and source line. */
438 print_frame_info (struct frame_info
*fi
, int print_level
,
439 enum print_what print_what
, int print_args
)
441 struct symtab_and_line sal
;
445 if (get_frame_type (fi
) == DUMMY_FRAME
446 || get_frame_type (fi
) == SIGTRAMP_FRAME
)
448 struct cleanup
*uiout_cleanup
449 = make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
451 annotate_frame_begin (print_level
? frame_relative_level (fi
) : 0,
454 /* Do this regardless of SOURCE because we don't have any source
455 to list for this frame. */
458 ui_out_text (uiout
, "#");
459 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
460 frame_relative_level (fi
));
462 if (ui_out_is_mi_like_p (uiout
))
464 annotate_frame_address ();
465 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
466 annotate_frame_address_end ();
469 if (get_frame_type (fi
) == DUMMY_FRAME
)
471 annotate_function_call ();
472 ui_out_field_string (uiout
, "func", "<function called from gdb>");
474 else if (get_frame_type (fi
) == SIGTRAMP_FRAME
)
476 annotate_signal_handler_caller ();
477 ui_out_field_string (uiout
, "func", "<signal handler called>");
479 ui_out_text (uiout
, "\n");
480 annotate_frame_end ();
482 do_cleanups (uiout_cleanup
);
486 /* If fi is not the innermost frame, that normally means that fi->pc
487 points to *after* the call instruction, and we want to get the
488 line containing the call, never the next line. But if the next
489 frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
490 was not entered as the result of a call, and we want to get the
491 line containing fi->pc. */
492 find_frame_sal (fi
, &sal
);
494 location_print
= (print_what
== LOCATION
495 || print_what
== LOC_AND_ADDRESS
496 || print_what
== SRC_AND_LOC
);
498 if (location_print
|| !sal
.symtab
)
499 print_frame (fi
, print_level
, print_what
, print_args
, sal
);
501 source_print
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
503 if (source_print
&& sal
.symtab
)
506 int mid_statement
= ((print_what
== SRC_LINE
)
507 && (get_frame_pc (fi
) != sal
.pc
));
509 if (annotation_level
)
510 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
514 if (deprecated_print_frame_info_listing_hook
)
515 deprecated_print_frame_info_listing_hook (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
518 /* We used to do this earlier, but that is clearly
519 wrong. This function is used by many different
520 parts of gdb, including normal_stop in infrun.c,
521 which uses this to print out the current PC
522 when we stepi/nexti into the middle of a source
523 line. Only the command line really wants this
524 behavior. Other UIs probably would like the
525 ability to decide for themselves if it is desired. */
526 if (addressprint
&& mid_statement
)
528 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
529 ui_out_text (uiout
, "\t");
532 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
537 if (print_what
!= LOCATION
)
538 set_default_breakpoint (1, get_frame_pc (fi
), sal
.symtab
, sal
.line
);
540 annotate_frame_end ();
542 gdb_flush (gdb_stdout
);
546 print_frame (struct frame_info
*fi
,
548 enum print_what print_what
,
550 struct symtab_and_line sal
)
554 enum language funlang
= language_unknown
;
555 struct ui_stream
*stb
;
556 struct cleanup
*old_chain
;
557 struct cleanup
*list_chain
;
559 stb
= ui_out_stream_new (uiout
);
560 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
562 func
= find_pc_function (get_frame_address_in_block (fi
));
565 /* In certain pathological cases, the symtabs give the wrong
566 function (when we are in the first function in a file which
567 is compiled without debugging symbols, the previous function
568 is compiled with debugging symbols, and the "foo.o" symbol
569 that is supposed to tell us where the file with debugging symbols
570 ends has been truncated by ar because it is longer than 15
571 characters). This also occurs if the user uses asm() to create
572 a function but not stabs for it (in a file compiled -g).
574 So look in the minimal symbol tables as well, and if it comes
575 up with a larger address for the function use that instead.
576 I don't think this can ever cause any problems; there shouldn't
577 be any minimal symbols in the middle of a function; if this is
578 ever changed many parts of GDB will need to be changed (and we'll
579 create a find_pc_minimal_function or some such). */
581 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
583 && (SYMBOL_VALUE_ADDRESS (msymbol
)
584 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
586 /* We also don't know anything about the function besides
587 its address and name. */
589 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
590 funlang
= SYMBOL_LANGUAGE (msymbol
);
594 /* I'd like to use SYMBOL_PRINT_NAME() here, to display the
595 demangled name that we already have stored in the symbol
596 table, but we stored a version with DMGL_PARAMS turned
597 on, and here we don't want to display parameters. So call
598 the demangler again, with DMGL_ANSI only. (Yes, I know
599 that printf_symbol_filtered() will again try to demangle
600 the name on the fly, but the issue is that if
601 cplus_demangle() fails here, it'll fail there too. So we
602 want to catch the failure ("demangled==NULL" case below)
603 here, while we still have our hands on the function
606 funname
= DEPRECATED_SYMBOL_NAME (func
);
607 funlang
= SYMBOL_LANGUAGE (func
);
608 if (funlang
== language_cplus
)
610 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
611 if (demangled
== NULL
)
612 /* If the demangler fails, try the demangled name from
613 the symbol table. This'll have parameters, but
614 that's preferable to diplaying a mangled name. */
615 funname
= SYMBOL_PRINT_NAME (func
);
621 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
624 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
625 funlang
= SYMBOL_LANGUAGE (msymbol
);
629 annotate_frame_begin (print_level
? frame_relative_level (fi
) : 0,
632 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
636 ui_out_text (uiout
, "#");
637 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
638 frame_relative_level (fi
));
641 if (get_frame_pc (fi
) != sal
.pc
643 || print_what
== LOC_AND_ADDRESS
)
645 annotate_frame_address ();
646 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
647 annotate_frame_address_end ();
648 ui_out_text (uiout
, " in ");
650 annotate_frame_function_name ();
651 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??", funlang
,
653 ui_out_field_stream (uiout
, "func", stb
);
654 ui_out_wrap_hint (uiout
, " ");
655 annotate_frame_args ();
657 ui_out_text (uiout
, " (");
660 struct print_args_args args
;
661 struct cleanup
*args_list_chain
;
664 args
.stream
= gdb_stdout
;
665 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
666 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
667 /* FIXME: args must be a list. If one argument is a string it will
668 have " that will not be properly escaped. */
669 /* Invoke ui_out_tuple_end. */
670 do_cleanups (args_list_chain
);
673 ui_out_text (uiout
, ")");
674 if (sal
.symtab
&& sal
.symtab
->filename
)
676 annotate_frame_source_begin ();
677 ui_out_wrap_hint (uiout
, " ");
678 ui_out_text (uiout
, " at ");
679 annotate_frame_source_file ();
680 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
681 annotate_frame_source_file_end ();
682 ui_out_text (uiout
, ":");
683 annotate_frame_source_line ();
684 ui_out_field_int (uiout
, "line", sal
.line
);
685 annotate_frame_source_end ();
689 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
691 char *lib
= PC_SOLIB (get_frame_pc (fi
));
694 annotate_frame_where ();
695 ui_out_wrap_hint (uiout
, " ");
696 ui_out_text (uiout
, " from ");
697 ui_out_field_string (uiout
, "from", lib
);
700 #endif /* PC_SOLIB */
702 /* do_cleanups will call ui_out_tuple_end() for us. */
703 do_cleanups (list_chain
);
704 ui_out_text (uiout
, "\n");
705 do_cleanups (old_chain
);
708 /* Show the frame info. If this is the tui, it will be shown in
709 the source display otherwise, nothing is done */
711 show_stack_frame (struct frame_info
*fi
)
716 /* Read a frame specification in whatever the appropriate format is.
717 Call error() if the specification is in any way invalid (i.e. this
718 function never returns NULL). When SEPECTED_P is non-NULL set it's
719 target to indicate that the default selected frame was used. */
721 static struct frame_info
*
722 parse_frame_specification_1 (const char *frame_exp
, const char *message
,
723 int *selected_frame_p
)
726 struct value
*args
[4];
727 CORE_ADDR addrs
[ARRAY_SIZE (args
)];
729 if (frame_exp
== NULL
)
734 struct cleanup
*tmp_cleanup
;
740 struct cleanup
*cleanup
;
743 /* Skip leading white space, bail of EOL. */
744 while (isspace (*frame_exp
))
749 /* Parse the argument, extract it, save it. */
753 addr_string
= savestring (frame_exp
, p
- frame_exp
);
755 cleanup
= make_cleanup (xfree
, addr_string
);
757 /* NOTE: Parse and evaluate expression, but do not use
758 functions such as parse_and_eval_long or
759 parse_and_eval_address to also extract the value.
760 Instead value_as_long and value_as_address are used.
761 This avoids problems with expressions that contain
763 if (numargs
>= ARRAY_SIZE (args
))
764 error ("Too many args in frame specification");
765 args
[numargs
++] = parse_and_eval (addr_string
);
767 do_cleanups (cleanup
);
771 /* If no args, default to the selected frame. */
774 if (selected_frame_p
!= NULL
)
775 (*selected_frame_p
) = 1;
776 return get_selected_frame (message
);
779 /* None of the remaining use the selected frame. */
780 if (selected_frame_p
!= NULL
)
781 (*selected_frame_p
) = 1;
783 /* Assume the single arg[0] is an integer, and try using that to
784 select a frame relative to current. */
787 struct frame_info
*fid
;
788 int level
= value_as_long (args
[0]);
789 fid
= find_relative_frame (get_current_frame (), &level
);
791 /* find_relative_frame was successful */
795 /* Convert each value into a corresponding address. */
798 for (i
= 0; i
< numargs
; i
++)
799 addrs
[i
] = value_as_address (args
[0]);
802 /* Assume that the single arg[0] is an address, use that to identify
803 a frame with a matching ID. Should this also accept stack/pc or
807 struct frame_id id
= frame_id_build_wild (addrs
[0]);
808 struct frame_info
*fid
;
810 /* If SETUP_ARBITRARY_FRAME is defined, then frame
811 specifications take at least 2 addresses. It is important to
812 detect this case here so that "frame 100" does not give a
813 confusing error message like "frame specification requires
814 two addresses". This of course does not solve the "frame
815 100" problem for machines on which a frame specification can
816 be made with one address. To solve that, we need a new
817 syntax for a specifying a frame by address. I think the
818 cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for two
819 args, etc.), but people might think that is too much typing,
820 so I guess *0x23,0x45 would be a possible alternative (commas
821 really should be used instead of spaces to delimit; using
822 spaces normally works in an expression). */
823 #ifdef SETUP_ARBITRARY_FRAME
824 error ("No frame %s", paddr_d (addrs
[0]));
826 /* If (s)he specifies the frame with an address, he deserves
827 what (s)he gets. Still, give the highest one that matches.
828 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
830 for (fid
= get_current_frame ();
832 fid
= get_prev_frame (fid
))
834 if (frame_id_eq (id
, get_frame_id (fid
)))
836 while (frame_id_eq (id
, frame_unwind_id (fid
)))
837 fid
= get_prev_frame (fid
);
843 /* We couldn't identify the frame as an existing frame, but
844 perhaps we can create one with a single argument. */
846 return create_new_frame (addrs
[0], 0);
847 else if (numargs
== 2)
848 return create_new_frame (addrs
[0], addrs
[1]);
850 error ("Too many args in frame specification");
854 parse_frame_specification (char *frame_exp
)
856 return parse_frame_specification_1 (frame_exp
, NULL
, NULL
);
859 /* Print verbosely the selected frame or the frame at address ADDR.
860 This means absolutely all information in the frame is printed. */
863 frame_info (char *addr_exp
, int from_tty
)
865 struct frame_info
*fi
;
866 struct symtab_and_line sal
;
869 struct frame_info
*calling_frame_info
;
870 int i
, count
, numregs
;
872 enum language funlang
= language_unknown
;
873 const char *pc_regname
;
874 int selected_frame_p
;
876 fi
= parse_frame_specification_1 (addr_exp
, "No stack.", &selected_frame_p
);
878 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
879 is not a good name. */
881 /* OK, this is weird. The PC_REGNUM hardware register's value can
882 easily not match that of the internal value returned by
884 pc_regname
= REGISTER_NAME (PC_REGNUM
);
886 /* But then, this is weird to. Even without PC_REGNUM, an
887 architectures will often have a hardware register called "pc",
888 and that register's value, again, can easily not match
892 find_frame_sal (fi
, &sal
);
893 func
= get_frame_function (fi
);
894 /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
896 s
= find_pc_symtab (get_frame_pc (fi
));
899 /* I'd like to use SYMBOL_PRINT_NAME() here, to display
900 * the demangled name that we already have stored in
901 * the symbol table, but we stored a version with
902 * DMGL_PARAMS turned on, and here we don't want
903 * to display parameters. So call the demangler again,
904 * with DMGL_ANSI only. RT
905 * (Yes, I know that printf_symbol_filtered() will
906 * again try to demangle the name on the fly, but
907 * the issue is that if cplus_demangle() fails here,
908 * it'll fail there too. So we want to catch the failure
909 * ("demangled==NULL" case below) here, while we still
910 * have our hands on the function symbol.)
913 funname
= DEPRECATED_SYMBOL_NAME (func
);
914 funlang
= SYMBOL_LANGUAGE (func
);
915 if (funlang
== language_cplus
)
917 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
918 /* If the demangler fails, try the demangled name
919 * from the symbol table. This'll have parameters,
920 * but that's preferable to diplaying a mangled name.
922 if (demangled
== NULL
)
923 funname
= SYMBOL_PRINT_NAME (func
);
928 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_pc (fi
));
931 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
932 funlang
= SYMBOL_LANGUAGE (msymbol
);
935 calling_frame_info
= get_prev_frame (fi
);
937 if (selected_frame_p
&& frame_relative_level (fi
) >= 0)
939 printf_filtered ("Stack level %d, frame at ",
940 frame_relative_level (fi
));
941 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
942 printf_filtered (":\n");
946 printf_filtered ("Stack frame at ");
947 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
948 printf_filtered (":\n");
950 printf_filtered (" %s = ", pc_regname
);
951 print_address_numeric (get_frame_pc (fi
), 1, gdb_stdout
);
956 printf_filtered (" in ");
957 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
958 DMGL_ANSI
| DMGL_PARAMS
);
962 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
963 puts_filtered ("; ");
965 printf_filtered ("saved %s ", pc_regname
);
966 print_address_numeric (frame_pc_unwind (fi
), 1, gdb_stdout
);
967 printf_filtered ("\n");
969 if (calling_frame_info
)
971 printf_filtered (" called by frame at ");
972 print_address_numeric (get_frame_base (calling_frame_info
),
975 if (get_next_frame (fi
) && calling_frame_info
)
978 if (get_next_frame (fi
))
980 printf_filtered (" caller of frame at ");
981 print_address_numeric (get_frame_base (get_next_frame (fi
)), 1,
984 if (get_next_frame (fi
) || calling_frame_info
)
985 puts_filtered ("\n");
987 printf_filtered (" source language %s.\n",
988 language_str (s
->language
));
991 /* Address of the argument list for this frame, or 0. */
992 CORE_ADDR arg_list
= get_frame_args_address (fi
);
993 /* Number of args for this frame, or -1 if unknown. */
997 printf_filtered (" Arglist at unknown address.\n");
1000 printf_filtered (" Arglist at ");
1001 print_address_numeric (arg_list
, 1, gdb_stdout
);
1002 printf_filtered (",");
1004 if (!FRAME_NUM_ARGS_P ())
1007 puts_filtered (" args: ");
1011 numargs
= FRAME_NUM_ARGS (fi
);
1012 gdb_assert (numargs
>= 0);
1014 puts_filtered (" no args.");
1015 else if (numargs
== 1)
1016 puts_filtered (" 1 arg: ");
1018 printf_filtered (" %d args: ", numargs
);
1020 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
1021 puts_filtered ("\n");
1025 /* Address of the local variables for this frame, or 0. */
1026 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1029 printf_filtered (" Locals at unknown address,");
1032 printf_filtered (" Locals at ");
1033 print_address_numeric (arg_list
, 1, gdb_stdout
);
1034 printf_filtered (",");
1038 /* Print as much information as possible on the location of all the
1041 enum lval_type lval
;
1049 /* The sp is special; what's displayed isn't the save address, but
1050 the value of the previous frame's sp. This is a legacy thing,
1051 at one stage the frame cached the previous frame's SP instead
1052 of its address, hence it was easiest to just display the cached
1056 /* Find out the location of the saved stack pointer with out
1057 actually evaluating it. */
1058 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1060 if (!optimized
&& lval
== not_lval
)
1062 char value
[MAX_REGISTER_SIZE
];
1064 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1066 /* NOTE: cagney/2003-05-22: This is assuming that the
1067 stack pointer was packed as an unsigned integer. That
1068 may or may not be valid. */
1069 sp
= extract_unsigned_integer (value
, register_size (current_gdbarch
, SP_REGNUM
));
1070 printf_filtered (" Previous frame's sp is ");
1071 print_address_numeric (sp
, 1, gdb_stdout
);
1072 printf_filtered ("\n");
1075 else if (!optimized
&& lval
== lval_memory
)
1077 printf_filtered (" Previous frame's sp at ");
1078 print_address_numeric (addr
, 1, gdb_stdout
);
1079 printf_filtered ("\n");
1082 else if (!optimized
&& lval
== lval_register
)
1084 printf_filtered (" Previous frame's sp in %s\n",
1085 REGISTER_NAME (realnum
));
1088 /* else keep quiet. */
1092 numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
1093 for (i
= 0; i
< numregs
; i
++)
1095 && gdbarch_register_reggroup_p (current_gdbarch
, i
, all_reggroup
))
1097 /* Find out the location of the saved register without
1098 fetching the corresponding value. */
1099 frame_register_unwind (fi
, i
, &optimized
, &lval
, &addr
, &realnum
,
1101 /* For moment, only display registers that were saved on the
1103 if (!optimized
&& lval
== lval_memory
)
1106 puts_filtered (" Saved registers:\n ");
1108 puts_filtered (",");
1110 printf_filtered (" %s at ", REGISTER_NAME (i
));
1111 print_address_numeric (addr
, 1, gdb_stdout
);
1115 if (count
|| need_nl
)
1116 puts_filtered ("\n");
1120 /* Print briefly all stack frames or just the innermost COUNT frames. */
1122 static void backtrace_command_1 (char *count_exp
, int show_locals
,
1125 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1127 struct frame_info
*fi
;
1130 struct frame_info
*trailing
;
1133 if (!target_has_stack
)
1134 error ("No stack.");
1136 /* The following code must do two things. First, it must
1137 set the variable TRAILING to the frame from which we should start
1138 printing. Second, it must set the variable count to the number
1139 of frames which we should print, or -1 if all of them. */
1140 trailing
= get_current_frame ();
1142 /* The target can be in a state where there is no valid frames
1143 (e.g., just connected). */
1144 if (trailing
== NULL
)
1145 error ("No stack.");
1150 count
= parse_and_eval_long (count_exp
);
1153 struct frame_info
*current
;
1158 while (current
&& count
--)
1161 current
= get_prev_frame (current
);
1164 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1165 will be COUNT below it. */
1169 trailing
= get_prev_frame (trailing
);
1170 current
= get_prev_frame (current
);
1182 struct partial_symtab
*ps
;
1184 /* Read in symbols for all of the frames. Need to do this in
1185 a separate pass so that "Reading in symbols for xxx" messages
1186 don't screw up the appearance of the backtrace. Also
1187 if people have strong opinions against reading symbols for
1188 backtrace this may have to be an option. */
1192 fi
= get_prev_frame (fi
))
1195 ps
= find_pc_psymtab (get_frame_address_in_block (fi
));
1197 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
1201 for (i
= 0, fi
= trailing
;
1203 i
++, fi
= get_prev_frame (fi
))
1207 /* Don't use print_stack_frame; if an error() occurs it probably
1208 means further attempts to backtrace would fail (on the other
1209 hand, perhaps the code does or could be fixed to make sure
1210 the frame->prev field gets set to NULL in that case). */
1211 print_frame_info (fi
, 1, LOCATION
, 1);
1213 print_frame_local_vars (fi
, 1, gdb_stdout
);
1216 /* If we've stopped before the end, mention that. */
1218 printf_filtered ("(More stack frames follow...)\n");
1222 backtrace_command (char *arg
, int from_tty
)
1224 struct cleanup
*old_chain
= (struct cleanup
*) NULL
;
1225 char **argv
= (char **) NULL
;
1226 int argIndicatingFullTrace
= (-1), totArgLen
= 0, argc
= 0;
1229 if (arg
!= (char *) NULL
)
1233 argv
= buildargv (arg
);
1234 old_chain
= make_cleanup_freeargv (argv
);
1236 for (i
= 0; (argv
[i
] != (char *) NULL
); i
++)
1240 for (j
= 0; (j
< strlen (argv
[i
])); j
++)
1241 argv
[i
][j
] = tolower (argv
[i
][j
]);
1243 if (argIndicatingFullTrace
< 0 && subset_compare (argv
[i
], "full"))
1244 argIndicatingFullTrace
= argc
;
1248 totArgLen
+= strlen (argv
[i
]);
1252 if (argIndicatingFullTrace
>= 0)
1256 argPtr
= (char *) xmalloc (totArgLen
+ 1);
1261 memset (argPtr
, 0, totArgLen
+ 1);
1262 for (i
= 0; (i
< (argc
+ 1)); i
++)
1264 if (i
!= argIndicatingFullTrace
)
1266 strcat (argPtr
, argv
[i
]);
1267 strcat (argPtr
, " ");
1273 argPtr
= (char *) NULL
;
1277 backtrace_command_1 (argPtr
, (argIndicatingFullTrace
>= 0), from_tty
);
1279 if (argIndicatingFullTrace
>= 0 && totArgLen
> 0)
1283 do_cleanups (old_chain
);
1286 static void backtrace_full_command (char *arg
, int from_tty
);
1288 backtrace_full_command (char *arg
, int from_tty
)
1290 backtrace_command_1 (arg
, 1, from_tty
);
1294 /* Print the local variables of a block B active in FRAME.
1295 Return 1 if any variables were printed; 0 otherwise. */
1298 print_block_frame_locals (struct block
*b
, struct frame_info
*fi
,
1299 int num_tabs
, struct ui_file
*stream
)
1301 struct dict_iterator iter
;
1304 int values_printed
= 0;
1306 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1308 switch (SYMBOL_CLASS (sym
))
1316 for (j
= 0; j
< num_tabs
; j
++)
1317 fputs_filtered ("\t", stream
);
1318 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1319 fputs_filtered (" = ", stream
);
1320 print_variable_value (sym
, fi
, stream
);
1321 fprintf_filtered (stream
, "\n");
1325 /* Ignore symbols which are not locals. */
1329 return values_printed
;
1332 /* Same, but print labels. */
1335 print_block_frame_labels (struct block
*b
, int *have_default
,
1336 struct ui_file
*stream
)
1338 struct dict_iterator iter
;
1340 int values_printed
= 0;
1342 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1344 if (strcmp (DEPRECATED_SYMBOL_NAME (sym
), "default") == 0)
1350 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1352 struct symtab_and_line sal
;
1353 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1355 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1358 fprintf_filtered (stream
, " ");
1359 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1361 fprintf_filtered (stream
, " in file %s, line %d\n",
1362 sal
.symtab
->filename
, sal
.line
);
1365 return values_printed
;
1368 /* Print on STREAM all the local variables in frame FRAME,
1369 including all the blocks active in that frame
1372 Returns 1 if the job was done,
1373 or 0 if nothing was printed because we have no info
1374 on the function running in FRAME. */
1377 print_frame_local_vars (struct frame_info
*fi
, int num_tabs
,
1378 struct ui_file
*stream
)
1380 struct block
*block
= get_frame_block (fi
, 0);
1381 int values_printed
= 0;
1385 fprintf_filtered (stream
, "No symbol table info available.\n");
1391 if (print_block_frame_locals (block
, fi
, num_tabs
, stream
))
1393 /* After handling the function's top-level block, stop.
1394 Don't continue to its superblock, the block of
1395 per-file symbols. */
1396 if (BLOCK_FUNCTION (block
))
1398 block
= BLOCK_SUPERBLOCK (block
);
1401 if (!values_printed
)
1403 fprintf_filtered (stream
, "No locals.\n");
1407 /* Same, but print labels. */
1410 print_frame_label_vars (struct frame_info
*fi
, int this_level_only
,
1411 struct ui_file
*stream
)
1413 struct blockvector
*bl
;
1414 struct block
*block
= get_frame_block (fi
, 0);
1415 int values_printed
= 0;
1416 int index
, have_default
= 0;
1417 char *blocks_printed
;
1418 CORE_ADDR pc
= get_frame_pc (fi
);
1422 fprintf_filtered (stream
, "No symbol table info available.\n");
1426 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1427 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1428 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1432 CORE_ADDR end
= BLOCK_END (block
) - 4;
1435 if (bl
!= blockvector_for_pc (end
, &index
))
1436 error ("blockvector blotch");
1437 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1438 error ("blockvector botch");
1439 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1442 /* Don't print out blocks that have gone by. */
1443 while (index
< last_index
1444 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1447 while (index
< last_index
1448 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1450 if (blocks_printed
[index
] == 0)
1452 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
1454 blocks_printed
[index
] = 1;
1460 if (values_printed
&& this_level_only
)
1463 /* After handling the function's top-level block, stop.
1464 Don't continue to its superblock, the block of
1465 per-file symbols. */
1466 if (BLOCK_FUNCTION (block
))
1468 block
= BLOCK_SUPERBLOCK (block
);
1471 if (!values_printed
&& !this_level_only
)
1473 fprintf_filtered (stream
, "No catches.\n");
1478 locals_info (char *args
, int from_tty
)
1480 print_frame_local_vars (get_selected_frame ("No frame selected."),
1485 catch_info (char *ignore
, int from_tty
)
1487 struct symtab_and_line
*sal
;
1489 /* Check for target support for exception handling */
1490 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1493 /* Currently not handling this */
1494 /* Ideally, here we should interact with the C++ runtime
1495 system to find the list of active handlers, etc. */
1496 fprintf_filtered (gdb_stdout
, "Info catch not supported with this target/compiler combination.\n");
1500 /* Assume g++ compiled code -- old v 4.16 behaviour */
1501 print_frame_label_vars (get_selected_frame ("No frame selected."),
1507 print_frame_arg_vars (struct frame_info
*fi
,
1508 struct ui_file
*stream
)
1510 struct symbol
*func
= get_frame_function (fi
);
1512 struct dict_iterator iter
;
1513 struct symbol
*sym
, *sym2
;
1514 int values_printed
= 0;
1518 fprintf_filtered (stream
, "No symbol table info available.\n");
1522 b
= SYMBOL_BLOCK_VALUE (func
);
1523 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1525 switch (SYMBOL_CLASS (sym
))
1531 case LOC_REGPARM_ADDR
:
1532 case LOC_BASEREG_ARG
:
1533 case LOC_COMPUTED_ARG
:
1535 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1536 fputs_filtered (" = ", stream
);
1538 /* We have to look up the symbol because arguments can have
1539 two entries (one a parameter, one a local) and the one we
1540 want is the local, which lookup_symbol will find for us.
1541 This includes gcc1 (not gcc2) on the sparc when passing a
1542 small structure and gcc2 when the argument type is float
1543 and it is passed as a double and converted to float by
1544 the prologue (in the latter case the type of the LOC_ARG
1545 symbol is double and the type of the LOC_LOCAL symbol is
1546 float). There are also LOC_ARG/LOC_REGISTER pairs which
1547 are not combined in symbol-reading. */
1549 sym2
= lookup_symbol (DEPRECATED_SYMBOL_NAME (sym
),
1550 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
1551 print_variable_value (sym2
, fi
, stream
);
1552 fprintf_filtered (stream
, "\n");
1556 /* Don't worry about things which aren't arguments. */
1560 if (!values_printed
)
1562 fprintf_filtered (stream
, "No arguments.\n");
1567 args_info (char *ignore
, int from_tty
)
1569 print_frame_arg_vars (get_selected_frame ("No frame selected."),
1575 args_plus_locals_info (char *ignore
, int from_tty
)
1577 args_info (ignore
, from_tty
);
1578 locals_info (ignore
, from_tty
);
1582 /* Select frame FI. Also print the stack frame and show the source if
1583 this is the tui version. */
1585 select_and_print_frame (struct frame_info
*fi
)
1589 print_stack_frame (fi
, 1, SRC_AND_LOC
);
1592 /* Return the symbol-block in which the selected frame is executing.
1593 Can return zero under various legitimate circumstances.
1595 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1596 code address within the block returned. We use this to decide
1597 which macros are in scope. */
1600 get_selected_block (CORE_ADDR
*addr_in_block
)
1602 if (!target_has_stack
)
1605 /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1606 a selected/current frame? Perhaps this function is called,
1607 indirectly, by WFI in "infrun.c" where avoiding the creation of
1608 an inner most frame is very important (it slows down single
1609 step). I suspect, though that this was true in the deep dark
1610 past but is no longer the case. A mindless look at all the
1611 callers tends to support this theory. I think we should be able
1612 to assume that there is always a selcted frame. */
1613 /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1615 if (!deprecated_selected_frame
)
1617 CORE_ADDR pc
= read_pc ();
1618 if (addr_in_block
!= NULL
)
1619 *addr_in_block
= pc
;
1620 return block_for_pc (pc
);
1622 return get_frame_block (deprecated_selected_frame
, addr_in_block
);
1625 /* Find a frame a certain number of levels away from FRAME.
1626 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1627 Positive means go to earlier frames (up); negative, the reverse.
1628 The int that contains the number of levels is counted toward
1629 zero as the frames for those levels are found.
1630 If the top or bottom frame is reached, that frame is returned,
1631 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1632 how much farther the original request asked to go. */
1635 find_relative_frame (struct frame_info
*frame
,
1636 int *level_offset_ptr
)
1638 struct frame_info
*prev
;
1639 struct frame_info
*frame1
;
1641 /* Going up is simple: just do get_prev_frame enough times
1642 or until initial frame is reached. */
1643 while (*level_offset_ptr
> 0)
1645 prev
= get_prev_frame (frame
);
1648 (*level_offset_ptr
)--;
1651 /* Going down is just as simple. */
1652 if (*level_offset_ptr
< 0)
1654 while (*level_offset_ptr
< 0)
1656 frame1
= get_next_frame (frame
);
1660 (*level_offset_ptr
)++;
1666 /* The "select_frame" command. With no arg, NOP.
1667 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1668 valid level. Otherwise, treat level_exp as an address expression
1669 and select it. See parse_frame_specification for more info on proper
1670 frame expressions. */
1673 select_frame_command (char *level_exp
, int from_tty
)
1675 select_frame (parse_frame_specification_1 (level_exp
, "No stack.", NULL
));
1678 /* The "frame" command. With no arg, print selected frame briefly.
1679 With arg, behaves like select_frame and then prints the selected
1683 frame_command (char *level_exp
, int from_tty
)
1685 select_frame_command (level_exp
, from_tty
);
1686 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1689 /* The XDB Compatibility command to print the current frame. */
1692 current_frame_command (char *level_exp
, int from_tty
)
1694 print_stack_frame (get_selected_frame ("No stack."), 1, SRC_AND_LOC
);
1697 /* Select the frame up one or COUNT stack levels
1698 from the previously selected frame, and print it briefly. */
1701 up_silently_base (char *count_exp
)
1703 struct frame_info
*fi
;
1704 int count
= 1, count1
;
1706 count
= parse_and_eval_long (count_exp
);
1709 fi
= find_relative_frame (get_selected_frame ("No stack."), &count1
);
1710 if (count1
!= 0 && count_exp
== 0)
1711 error ("Initial frame selected; you cannot go up.");
1716 up_silently_command (char *count_exp
, int from_tty
)
1718 up_silently_base (count_exp
);
1722 up_command (char *count_exp
, int from_tty
)
1724 up_silently_base (count_exp
);
1725 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1728 /* Select the frame down one or COUNT stack levels
1729 from the previously selected frame, and print it briefly. */
1732 down_silently_base (char *count_exp
)
1734 struct frame_info
*frame
;
1735 int count
= -1, count1
;
1737 count
= -parse_and_eval_long (count_exp
);
1740 frame
= find_relative_frame (get_selected_frame ("No stack."), &count1
);
1741 if (count1
!= 0 && count_exp
== 0)
1744 /* We only do this if count_exp is not specified. That way "down"
1745 means to really go down (and let me know if that is
1746 impossible), but "down 9999" can be used to mean go all the way
1747 down without getting an error. */
1749 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1752 select_frame (frame
);
1756 down_silently_command (char *count_exp
, int from_tty
)
1758 down_silently_base (count_exp
);
1762 down_command (char *count_exp
, int from_tty
)
1764 down_silently_base (count_exp
);
1765 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1769 return_command (char *retval_exp
, int from_tty
)
1771 struct symbol
*thisfun
;
1772 struct value
*return_value
= NULL
;
1773 const char *query_prefix
= "";
1775 thisfun
= get_frame_function (get_selected_frame ("No selected frame."));
1777 /* Compute the return value. If the computation triggers an error,
1778 let it bail. If the return type can't be handled, set
1779 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1783 struct type
*return_type
= NULL
;
1785 /* Compute the return value. Should the computation fail, this
1786 call throws an error. */
1787 return_value
= parse_and_eval (retval_exp
);
1789 /* Cast return value to the return type of the function. Should
1790 the cast fail, this call throws an error. */
1791 if (thisfun
!= NULL
)
1792 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1793 if (return_type
== NULL
)
1794 return_type
= builtin_type_int
;
1795 CHECK_TYPEDEF (return_type
);
1796 return_value
= value_cast (return_type
, return_value
);
1798 /* Make sure the value is fully evaluated. It may live in the
1799 stack frame we're about to pop. */
1800 if (VALUE_LAZY (return_value
))
1801 value_fetch_lazy (return_value
);
1803 if (TYPE_CODE (return_type
) == TYPE_CODE_VOID
)
1804 /* If the return-type is "void", don't try to find the
1805 return-value's location. However, do still evaluate the
1806 return expression so that, even when the expression result
1807 is discarded, side effects such as "return i++" still
1809 return_value
= NULL
;
1810 /* FIXME: cagney/2004-01-17: If the architecture implements both
1811 return_value and extract_returned_value_address, should allow
1812 "return" to work - don't set return_value to NULL. */
1813 else if (!gdbarch_return_value_p (current_gdbarch
)
1814 && (TYPE_CODE (return_type
) == TYPE_CODE_STRUCT
1815 || TYPE_CODE (return_type
) == TYPE_CODE_UNION
))
1817 /* NOTE: cagney/2003-10-20: Compatibility hack for legacy
1818 code. Old architectures don't expect STORE_RETURN_VALUE
1819 to be called with with a small struct that needs to be
1820 stored in registers. Don't start doing it now. */
1822 A structure or union return type is not supported by this architecture.\n\
1823 If you continue, the return value that you specified will be ignored.\n";
1824 return_value
= NULL
;
1826 else if (using_struct_return (return_type
, 0))
1829 The location at which to store the function's return value is unknown.\n\
1830 If you continue, the return value that you specified will be ignored.\n";
1831 return_value
= NULL
;
1835 /* Does an interactive user really want to do this? Include
1836 information, such as how well GDB can handle the return value, in
1837 the query message. */
1841 if (thisfun
== NULL
)
1842 confirmed
= query ("%sMake selected stack frame return now? ",
1845 confirmed
= query ("%sMake %s return now? ", query_prefix
,
1846 SYMBOL_PRINT_NAME (thisfun
));
1848 error ("Not confirmed");
1851 /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each
1852 frame in turn, should this code just go straight to the relevant
1853 frame and pop that? */
1855 /* First discard all frames inner-to the selected frame (making the
1856 selected frame current). */
1858 struct frame_id selected_id
= get_frame_id (get_selected_frame (NULL
));
1859 while (!frame_id_eq (selected_id
, get_frame_id (get_current_frame ())))
1861 if (frame_id_inner (selected_id
, get_frame_id (get_current_frame ())))
1862 /* Caught in the safety net, oops! We've gone way past the
1864 error ("Problem while popping stack frames (corrupt stack?)");
1865 frame_pop (get_current_frame ());
1869 /* Second discard the selected frame (which is now also the current
1871 frame_pop (get_current_frame ());
1873 /* Store RETURN_VAUE in the just-returned register set. */
1874 if (return_value
!= NULL
)
1876 struct type
*return_type
= VALUE_TYPE (return_value
);
1877 gdb_assert (gdbarch_return_value (current_gdbarch
, return_type
,
1879 == RETURN_VALUE_REGISTER_CONVENTION
);
1880 gdbarch_return_value (current_gdbarch
, return_type
,
1881 current_regcache
, NULL
/*read*/,
1882 VALUE_CONTENTS (return_value
) /*write*/);
1885 /* If we are at the end of a call dummy now, pop the dummy frame
1887 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
1888 frame_pop (get_current_frame ());
1890 /* If interactive, print the frame that is now current. */
1892 frame_command ("0", 1);
1894 select_frame_command ("0", 0);
1897 /* Sets the scope to input function name, provided that the
1898 function is within the current stack frame */
1900 struct function_bounds
1902 CORE_ADDR low
, high
;
1905 static void func_command (char *arg
, int from_tty
);
1907 func_command (char *arg
, int from_tty
)
1909 struct frame_info
*fp
;
1911 struct symtabs_and_lines sals
;
1914 struct function_bounds
*func_bounds
= (struct function_bounds
*) NULL
;
1916 if (arg
!= (char *) NULL
)
1919 fp
= parse_frame_specification ("0");
1920 sals
= decode_line_spec (arg
, 1);
1921 func_bounds
= (struct function_bounds
*) xmalloc (
1922 sizeof (struct function_bounds
) * sals
.nelts
);
1923 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1925 if (sals
.sals
[i
].pc
== (CORE_ADDR
) 0 ||
1926 find_pc_partial_function (sals
.sals
[i
].pc
,
1928 &func_bounds
[i
].low
,
1929 &func_bounds
[i
].high
) == 0)
1931 func_bounds
[i
].low
=
1932 func_bounds
[i
].high
= (CORE_ADDR
) NULL
;
1938 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1939 found
= (get_frame_pc (fp
) >= func_bounds
[i
].low
&&
1940 get_frame_pc (fp
) < func_bounds
[i
].high
);
1944 fp
= find_relative_frame (fp
, &level
);
1947 while (!found
&& level
== 0);
1950 xfree (func_bounds
);
1953 printf_filtered ("'%s' not within current stack frame.\n", arg
);
1954 else if (fp
!= deprecated_selected_frame
)
1955 select_and_print_frame (fp
);
1958 /* Gets the language of the current frame. */
1961 get_frame_language (void)
1964 enum language flang
; /* The language of the current frame */
1966 if (deprecated_selected_frame
)
1968 /* We determine the current frame language by looking up its
1969 associated symtab. To retrieve this symtab, we use the frame PC.
1970 However we cannot use the frame pc as is, because it usually points
1971 to the instruction following the "call", which is sometimes the first
1972 instruction of another function. So we rely on
1973 get_frame_address_in_block(), it provides us with a PC which is
1974 guaranteed to be inside the frame's code block. */
1975 s
= find_pc_symtab (get_frame_address_in_block (deprecated_selected_frame
));
1977 flang
= s
->language
;
1979 flang
= language_unknown
;
1982 flang
= language_unknown
;
1988 _initialize_stack (void)
1991 backtrace_limit
= 30;
1994 add_com ("return", class_stack
, return_command
,
1995 "Make selected stack frame return to its caller.\n\
1996 Control remains in the debugger, but when you continue\n\
1997 execution will resume in the frame above the one now selected.\n\
1998 If an argument is given, it is an expression for the value to return.");
2000 add_com ("up", class_stack
, up_command
,
2001 "Select and print stack frame that called this one.\n\
2002 An argument says how many frames up to go.");
2003 add_com ("up-silently", class_support
, up_silently_command
,
2004 "Same as the `up' command, but does not print anything.\n\
2005 This is useful in command scripts.");
2007 add_com ("down", class_stack
, down_command
,
2008 "Select and print stack frame called by this one.\n\
2009 An argument says how many frames down to go.");
2010 add_com_alias ("do", "down", class_stack
, 1);
2011 add_com_alias ("dow", "down", class_stack
, 1);
2012 add_com ("down-silently", class_support
, down_silently_command
,
2013 "Same as the `down' command, but does not print anything.\n\
2014 This is useful in command scripts.");
2016 add_com ("frame", class_stack
, frame_command
,
2017 "Select and print a stack frame.\n\
2018 With no argument, print the selected stack frame. (See also \"info frame\").\n\
2019 An argument specifies the frame to select.\n\
2020 It can be a stack frame number or the address of the frame.\n\
2021 With argument, nothing is printed if input is coming from\n\
2022 a command file or a user-defined command.");
2024 add_com_alias ("f", "frame", class_stack
, 1);
2028 add_com ("L", class_stack
, current_frame_command
,
2029 "Print the current stack frame.\n");
2030 add_com_alias ("V", "frame", class_stack
, 1);
2032 add_com ("select-frame", class_stack
, select_frame_command
,
2033 "Select a stack frame without printing anything.\n\
2034 An argument specifies the frame to select.\n\
2035 It can be a stack frame number or the address of the frame.\n");
2037 add_com ("backtrace", class_stack
, backtrace_command
,
2038 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2039 With a negative argument, print outermost -COUNT frames.\n\
2040 Use of the 'full' qualifier also prints the values of the local variables.\n");
2041 add_com_alias ("bt", "backtrace", class_stack
, 0);
2044 add_com_alias ("t", "backtrace", class_stack
, 0);
2045 add_com ("T", class_stack
, backtrace_full_command
,
2046 "Print backtrace of all stack frames, or innermost COUNT frames \n\
2047 and the values of the local variables.\n\
2048 With a negative argument, print outermost -COUNT frames.\n\
2049 Usage: T <count>\n");
2052 add_com_alias ("where", "backtrace", class_alias
, 0);
2053 add_info ("stack", backtrace_command
,
2054 "Backtrace of the stack, or innermost COUNT frames.");
2055 add_info_alias ("s", "stack", 1);
2056 add_info ("frame", frame_info
,
2057 "All about selected stack frame, or frame at ADDR.");
2058 add_info_alias ("f", "frame", 1);
2059 add_info ("locals", locals_info
,
2060 "Local variables of current stack frame.");
2061 add_info ("args", args_info
,
2062 "Argument variables of current stack frame.");
2064 add_com ("l", class_info
, args_plus_locals_info
,
2065 "Argument and local variables of current stack frame.");
2068 add_com ("func", class_stack
, func_command
,
2069 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2071 add_info ("catch", catch_info
,
2072 "Exceptions that can be caught in the current stack frame.");
2075 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
2076 "Specify maximum number of frames for \"backtrace\" to print by default.",
2078 add_info ("backtrace-limit", backtrace_limit_info
,
2079 "The maximum number of frames for \"backtrace\" to print by default.");