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 backtrace_command (char *, int);
105 static void frame_info (char *, int);
107 extern int addressprint
; /* Print addresses, or stay symbolic only? */
109 /* Zero means do things normally; we are interacting directly with the
110 user. One means print the full filename and linenumber when a
111 frame is printed, and do so in a format emacs18/emacs19.22 can
112 parse. Two means print similar annotations, but in many more
113 cases and in a slightly different syntax. */
115 int annotation_level
= 0;
118 struct print_stack_frame_args
120 struct frame_info
*fi
;
122 enum print_what print_what
;
126 /* Show or print the frame arguments.
127 Pass the args the way catch_errors wants them. */
129 print_stack_frame_stub (void *args
)
131 struct print_stack_frame_args
*p
= (struct print_stack_frame_args
*) args
;
133 print_frame_info (p
->fi
, p
->print_level
, p
->print_what
, p
->print_args
);
137 /* Show or print a stack frame FI briefly. The output is format
138 according to PRINT_LEVEL and PRINT_WHAT printing the frame's
139 relative level, function name, argument list, and file name and
140 line number. If the frame's PC is not at the beginning of the
141 source line, the actual PC is printed at the beginning. */
144 print_stack_frame (struct frame_info
*fi
, int print_level
,
145 enum print_what print_what
)
147 struct print_stack_frame_args args
;
150 args
.print_level
= print_level
;
151 args
.print_what
= print_what
;
154 catch_errors (print_stack_frame_stub
, (char *) &args
, "", RETURN_MASK_ALL
);
157 struct print_args_args
160 struct frame_info
*fi
;
161 struct ui_file
*stream
;
164 static int print_args_stub (void *);
166 /* Print nameless args on STREAM.
167 FI is the frameinfo for this frame, START is the offset
168 of the first nameless arg, and NUM is the number of nameless args to
169 print. FIRST is nonzero if this is the first argument (not just
170 the first nameless arg). */
173 print_frame_nameless_args (struct frame_info
*fi
, long start
, int num
,
174 int first
, struct ui_file
*stream
)
180 for (i
= 0; i
< num
; i
++)
183 argsaddr
= get_frame_args_address (fi
);
186 arg_value
= read_memory_integer (argsaddr
+ start
, sizeof (int));
188 fprintf_filtered (stream
, ", ");
189 fprintf_filtered (stream
, "%ld", arg_value
);
191 start
+= sizeof (int);
195 /* Print the arguments of a stack frame, given the function FUNC
196 running in that frame (as a symbol), the info on the frame,
197 and the number of args according to the stack frame (or -1 if unknown). */
199 /* References here and elsewhere to "number of args according to the
200 stack frame" appear in all cases to refer to "number of ints of args
201 according to the stack frame". At least for VAX, i386, isi. */
204 print_frame_args (struct symbol
*func
, struct frame_info
*fi
, int num
,
205 struct ui_file
*stream
)
207 struct block
*b
= NULL
;
209 struct dict_iterator iter
;
212 /* Offset of next stack argument beyond the one we have seen that is
213 at the highest offset.
214 -1 if we haven't come to a stack argument yet. */
215 long highest_offset
= -1;
217 /* Number of ints of arguments that we have printed so far. */
218 int args_printed
= 0;
219 struct cleanup
*old_chain
, *list_chain
;
220 struct ui_stream
*stb
;
222 stb
= ui_out_stream_new (uiout
);
223 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
227 b
= SYMBOL_BLOCK_VALUE (func
);
229 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
233 /* Keep track of the highest stack argument offset seen, and
234 skip over any kinds of symbols we don't care about. */
236 switch (SYMBOL_CLASS (sym
))
241 long current_offset
= SYMBOL_VALUE (sym
);
242 arg_size
= TYPE_LENGTH (SYMBOL_TYPE (sym
));
244 /* Compute address of next argument by adding the size of
245 this argument and rounding to an int boundary. */
247 ((current_offset
+ arg_size
+ sizeof (int) - 1)
248 & ~(sizeof (int) - 1));
250 /* If this is the highest offset seen yet, set highest_offset. */
251 if (highest_offset
== -1
252 || (current_offset
> highest_offset
))
253 highest_offset
= current_offset
;
255 /* Add the number of ints we're about to print to args_printed. */
256 args_printed
+= (arg_size
+ sizeof (int) - 1) / sizeof (int);
259 /* We care about types of symbols, but don't need to keep track of
260 stack offsets in them. */
262 case LOC_REGPARM_ADDR
:
264 case LOC_BASEREG_ARG
:
265 case LOC_COMPUTED_ARG
:
268 /* Other types of symbols we just skip over. */
273 /* We have to look up the symbol because arguments can have
274 two entries (one a parameter, one a local) and the one we
275 want is the local, which lookup_symbol will find for us.
276 This includes gcc1 (not gcc2) on the sparc when passing a
277 small structure and gcc2 when the argument type is float
278 and it is passed as a double and converted to float by
279 the prologue (in the latter case the type of the LOC_ARG
280 symbol is double and the type of the LOC_LOCAL symbol is
282 /* But if the parameter name is null, don't try it.
283 Null parameter names occur on the RS/6000, for traceback tables.
284 FIXME, should we even print them? */
286 if (*DEPRECATED_SYMBOL_NAME (sym
))
290 (DEPRECATED_SYMBOL_NAME (sym
),
291 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
292 if (SYMBOL_CLASS (nsym
) == LOC_REGISTER
)
294 /* There is a LOC_ARG/LOC_REGISTER pair. This means that
295 it was passed on the stack and loaded into a register,
296 or passed in a register and stored in a stack slot.
297 GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
299 Reasons for using the LOC_ARG:
300 (1) because find_saved_registers may be slow for remote
302 (2) because registers are often re-used and stack slots
303 rarely (never?) are. Therefore using the stack slot is
304 much less likely to print garbage.
306 Reasons why we might want to use the LOC_REGISTER:
307 (1) So that the backtrace prints the same value as
308 "print foo". I see no compelling reason why this needs
309 to be the case; having the backtrace print the value which
310 was passed in, and "print foo" print the value as modified
311 within the called function, makes perfect sense to me.
313 Additional note: It might be nice if "info args" displayed
315 One more note: There is a case with sparc structure passing
316 where we need to use the LOC_REGISTER, but this is dealt with
317 by creating a single LOC_REGPARM in symbol reading. */
319 /* Leave sym (the LOC_ARG) alone. */
326 /* Print the current arg. */
328 ui_out_text (uiout
, ", ");
329 ui_out_wrap_hint (uiout
, " ");
331 annotate_arg_begin ();
333 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
334 fprintf_symbol_filtered (stb
->stream
, SYMBOL_PRINT_NAME (sym
),
335 SYMBOL_LANGUAGE (sym
), DMGL_PARAMS
| DMGL_ANSI
);
336 ui_out_field_stream (uiout
, "name", stb
);
337 annotate_arg_name_end ();
338 ui_out_text (uiout
, "=");
340 /* Avoid value_print because it will deref ref parameters. We just
341 want to print their addresses. Print ??? for args whose address
342 we do not know. We pass 2 as "recurse" to val_print because our
343 standard indentation here is 4 spaces, and val_print indents
344 2 for each recurse. */
345 val
= read_var_value (sym
, fi
);
347 annotate_arg_value (val
== NULL
? NULL
: VALUE_TYPE (val
));
351 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), 0,
353 stb
->stream
, 0, 0, 2, Val_no_prettyprint
);
354 ui_out_field_stream (uiout
, "value", stb
);
357 ui_out_text (uiout
, "???");
359 /* Invoke ui_out_tuple_end. */
360 do_cleanups (list_chain
);
368 /* Don't print nameless args in situations where we don't know
369 enough about the stack to find them. */
374 if (highest_offset
== -1)
375 start
= FRAME_ARGS_SKIP
;
377 start
= highest_offset
;
379 print_frame_nameless_args (fi
, start
, num
- args_printed
,
382 do_cleanups (old_chain
);
385 /* Pass the args the way catch_errors wants them. */
388 print_args_stub (void *args
)
391 struct print_args_args
*p
= (struct print_args_args
*) args
;
393 if (FRAME_NUM_ARGS_P ())
395 numargs
= FRAME_NUM_ARGS (p
->fi
);
396 gdb_assert (numargs
>= 0);
400 print_frame_args (p
->func
, p
->fi
, numargs
, p
->stream
);
404 /* Print information about a frame for frame "fi" at level "level".
405 Used in "where" output, also used to emit breakpoint or step
407 LEVEL is the level of the frame, or -1 if it is the
408 innermost frame but we don't want to print the level.
409 The meaning of the SOURCE argument is:
410 SRC_LINE: Print only source line
411 LOCATION: Print only location
412 LOC_AND_SRC: Print location and source line. */
415 print_frame_info (struct frame_info
*fi
, int print_level
,
416 enum print_what print_what
, int print_args
)
418 struct symtab_and_line sal
;
422 if (get_frame_type (fi
) == DUMMY_FRAME
423 || get_frame_type (fi
) == SIGTRAMP_FRAME
)
425 struct cleanup
*uiout_cleanup
426 = make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
428 annotate_frame_begin (print_level
? frame_relative_level (fi
) : 0,
431 /* Do this regardless of SOURCE because we don't have any source
432 to list for this frame. */
435 ui_out_text (uiout
, "#");
436 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
437 frame_relative_level (fi
));
439 if (ui_out_is_mi_like_p (uiout
))
441 annotate_frame_address ();
442 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
443 annotate_frame_address_end ();
446 if (get_frame_type (fi
) == DUMMY_FRAME
)
448 annotate_function_call ();
449 ui_out_field_string (uiout
, "func", "<function called from gdb>");
451 else if (get_frame_type (fi
) == SIGTRAMP_FRAME
)
453 annotate_signal_handler_caller ();
454 ui_out_field_string (uiout
, "func", "<signal handler called>");
456 ui_out_text (uiout
, "\n");
457 annotate_frame_end ();
459 do_cleanups (uiout_cleanup
);
463 /* If fi is not the innermost frame, that normally means that fi->pc
464 points to *after* the call instruction, and we want to get the
465 line containing the call, never the next line. But if the next
466 frame is a SIGTRAMP_FRAME or a DUMMY_FRAME, then the next frame
467 was not entered as the result of a call, and we want to get the
468 line containing fi->pc. */
469 find_frame_sal (fi
, &sal
);
471 location_print
= (print_what
== LOCATION
472 || print_what
== LOC_AND_ADDRESS
473 || print_what
== SRC_AND_LOC
);
475 if (location_print
|| !sal
.symtab
)
476 print_frame (fi
, print_level
, print_what
, print_args
, sal
);
478 source_print
= (print_what
== SRC_LINE
|| print_what
== SRC_AND_LOC
);
481 set_current_source_symtab_and_line (&sal
);
483 if (source_print
&& sal
.symtab
)
485 struct symtab_and_line cursal
;
487 int mid_statement
= ((print_what
== SRC_LINE
)
488 && (get_frame_pc (fi
) != sal
.pc
));
490 if (annotation_level
)
491 done
= identify_source_line (sal
.symtab
, sal
.line
, mid_statement
,
495 if (deprecated_print_frame_info_listing_hook
)
496 deprecated_print_frame_info_listing_hook (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
499 /* We used to do this earlier, but that is clearly
500 wrong. This function is used by many different
501 parts of gdb, including normal_stop in infrun.c,
502 which uses this to print out the current PC
503 when we stepi/nexti into the middle of a source
504 line. Only the command line really wants this
505 behavior. Other UIs probably would like the
506 ability to decide for themselves if it is desired. */
507 if (addressprint
&& mid_statement
)
509 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
510 ui_out_text (uiout
, "\t");
513 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
516 /* Make sure we have at least a default source file */
517 set_default_source_symtab_and_line ();
518 cursal
= get_current_source_symtab_and_line ();
519 cursal
.line
= max (sal
.line
- get_lines_to_list () / 2, 1);
520 set_current_source_symtab_and_line (&cursal
);
523 if (print_what
!= LOCATION
)
524 set_default_breakpoint (1, get_frame_pc (fi
), sal
.symtab
, sal
.line
);
526 annotate_frame_end ();
528 gdb_flush (gdb_stdout
);
532 print_frame (struct frame_info
*fi
,
534 enum print_what print_what
,
536 struct symtab_and_line sal
)
540 enum language funlang
= language_unknown
;
541 struct ui_stream
*stb
;
542 struct cleanup
*old_chain
;
543 struct cleanup
*list_chain
;
545 stb
= ui_out_stream_new (uiout
);
546 old_chain
= make_cleanup_ui_out_stream_delete (stb
);
548 func
= find_pc_function (get_frame_address_in_block (fi
));
551 /* In certain pathological cases, the symtabs give the wrong
552 function (when we are in the first function in a file which
553 is compiled without debugging symbols, the previous function
554 is compiled with debugging symbols, and the "foo.o" symbol
555 that is supposed to tell us where the file with debugging symbols
556 ends has been truncated by ar because it is longer than 15
557 characters). This also occurs if the user uses asm() to create
558 a function but not stabs for it (in a file compiled -g).
560 So look in the minimal symbol tables as well, and if it comes
561 up with a larger address for the function use that instead.
562 I don't think this can ever cause any problems; there shouldn't
563 be any minimal symbols in the middle of a function; if this is
564 ever changed many parts of GDB will need to be changed (and we'll
565 create a find_pc_minimal_function or some such). */
567 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
569 && (SYMBOL_VALUE_ADDRESS (msymbol
)
570 > BLOCK_START (SYMBOL_BLOCK_VALUE (func
))))
572 /* We also don't know anything about the function besides
573 its address and name. */
575 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
576 funlang
= SYMBOL_LANGUAGE (msymbol
);
580 /* I'd like to use SYMBOL_PRINT_NAME() here, to display the
581 demangled name that we already have stored in the symbol
582 table, but we stored a version with DMGL_PARAMS turned
583 on, and here we don't want to display parameters. So call
584 the demangler again, with DMGL_ANSI only. (Yes, I know
585 that printf_symbol_filtered() will again try to demangle
586 the name on the fly, but the issue is that if
587 cplus_demangle() fails here, it'll fail there too. So we
588 want to catch the failure ("demangled==NULL" case below)
589 here, while we still have our hands on the function
592 funname
= DEPRECATED_SYMBOL_NAME (func
);
593 funlang
= SYMBOL_LANGUAGE (func
);
594 if (funlang
== language_cplus
)
596 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
597 if (demangled
== NULL
)
598 /* If the demangler fails, try the demangled name from
599 the symbol table. This'll have parameters, but
600 that's preferable to diplaying a mangled name. */
601 funname
= SYMBOL_PRINT_NAME (func
);
607 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_address_in_block (fi
));
610 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
611 funlang
= SYMBOL_LANGUAGE (msymbol
);
615 annotate_frame_begin (print_level
? frame_relative_level (fi
) : 0,
618 list_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "frame");
622 ui_out_text (uiout
, "#");
623 ui_out_field_fmt_int (uiout
, 2, ui_left
, "level",
624 frame_relative_level (fi
));
627 if (get_frame_pc (fi
) != sal
.pc
629 || print_what
== LOC_AND_ADDRESS
)
631 annotate_frame_address ();
632 ui_out_field_core_addr (uiout
, "addr", get_frame_pc (fi
));
633 annotate_frame_address_end ();
634 ui_out_text (uiout
, " in ");
636 annotate_frame_function_name ();
637 fprintf_symbol_filtered (stb
->stream
, funname
? funname
: "??", funlang
,
639 ui_out_field_stream (uiout
, "func", stb
);
640 ui_out_wrap_hint (uiout
, " ");
641 annotate_frame_args ();
643 ui_out_text (uiout
, " (");
646 struct print_args_args args
;
647 struct cleanup
*args_list_chain
;
650 args
.stream
= gdb_stdout
;
651 args_list_chain
= make_cleanup_ui_out_list_begin_end (uiout
, "args");
652 catch_errors (print_args_stub
, &args
, "", RETURN_MASK_ALL
);
653 /* FIXME: args must be a list. If one argument is a string it will
654 have " that will not be properly escaped. */
655 /* Invoke ui_out_tuple_end. */
656 do_cleanups (args_list_chain
);
659 ui_out_text (uiout
, ")");
660 if (sal
.symtab
&& sal
.symtab
->filename
)
662 annotate_frame_source_begin ();
663 ui_out_wrap_hint (uiout
, " ");
664 ui_out_text (uiout
, " at ");
665 annotate_frame_source_file ();
666 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
667 annotate_frame_source_file_end ();
668 ui_out_text (uiout
, ":");
669 annotate_frame_source_line ();
670 ui_out_field_int (uiout
, "line", sal
.line
);
671 annotate_frame_source_end ();
675 if (!funname
|| (!sal
.symtab
|| !sal
.symtab
->filename
))
677 char *lib
= PC_SOLIB (get_frame_pc (fi
));
680 annotate_frame_where ();
681 ui_out_wrap_hint (uiout
, " ");
682 ui_out_text (uiout
, " from ");
683 ui_out_field_string (uiout
, "from", lib
);
686 #endif /* PC_SOLIB */
688 /* do_cleanups will call ui_out_tuple_end() for us. */
689 do_cleanups (list_chain
);
690 ui_out_text (uiout
, "\n");
691 do_cleanups (old_chain
);
694 /* Show the frame info. If this is the tui, it will be shown in
695 the source display otherwise, nothing is done */
697 show_stack_frame (struct frame_info
*fi
)
702 /* Read a frame specification in whatever the appropriate format is.
703 Call error() if the specification is in any way invalid (i.e. this
704 function never returns NULL). When SEPECTED_P is non-NULL set it's
705 target to indicate that the default selected frame was used. */
707 static struct frame_info
*
708 parse_frame_specification_1 (const char *frame_exp
, const char *message
,
709 int *selected_frame_p
)
712 struct value
*args
[4];
713 CORE_ADDR addrs
[ARRAY_SIZE (args
)];
715 if (frame_exp
== NULL
)
720 struct cleanup
*tmp_cleanup
;
726 struct cleanup
*cleanup
;
729 /* Skip leading white space, bail of EOL. */
730 while (isspace (*frame_exp
))
735 /* Parse the argument, extract it, save it. */
739 addr_string
= savestring (frame_exp
, p
- frame_exp
);
741 cleanup
= make_cleanup (xfree
, addr_string
);
743 /* NOTE: Parse and evaluate expression, but do not use
744 functions such as parse_and_eval_long or
745 parse_and_eval_address to also extract the value.
746 Instead value_as_long and value_as_address are used.
747 This avoids problems with expressions that contain
749 if (numargs
>= ARRAY_SIZE (args
))
750 error ("Too many args in frame specification");
751 args
[numargs
++] = parse_and_eval (addr_string
);
753 do_cleanups (cleanup
);
757 /* If no args, default to the selected frame. */
760 if (selected_frame_p
!= NULL
)
761 (*selected_frame_p
) = 1;
762 return get_selected_frame (message
);
765 /* None of the remaining use the selected frame. */
766 if (selected_frame_p
!= NULL
)
767 (*selected_frame_p
) = 1;
769 /* Assume the single arg[0] is an integer, and try using that to
770 select a frame relative to current. */
773 struct frame_info
*fid
;
774 int level
= value_as_long (args
[0]);
775 fid
= find_relative_frame (get_current_frame (), &level
);
777 /* find_relative_frame was successful */
781 /* Convert each value into a corresponding address. */
784 for (i
= 0; i
< numargs
; i
++)
785 addrs
[i
] = value_as_address (args
[0]);
788 /* Assume that the single arg[0] is an address, use that to identify
789 a frame with a matching ID. Should this also accept stack/pc or
793 struct frame_id id
= frame_id_build_wild (addrs
[0]);
794 struct frame_info
*fid
;
796 /* If SETUP_ARBITRARY_FRAME is defined, then frame
797 specifications take at least 2 addresses. It is important to
798 detect this case here so that "frame 100" does not give a
799 confusing error message like "frame specification requires
800 two addresses". This of course does not solve the "frame
801 100" problem for machines on which a frame specification can
802 be made with one address. To solve that, we need a new
803 syntax for a specifying a frame by address. I think the
804 cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for two
805 args, etc.), but people might think that is too much typing,
806 so I guess *0x23,0x45 would be a possible alternative (commas
807 really should be used instead of spaces to delimit; using
808 spaces normally works in an expression). */
809 #ifdef SETUP_ARBITRARY_FRAME
810 error ("No frame %s", paddr_d (addrs
[0]));
812 /* If (s)he specifies the frame with an address, he deserves
813 what (s)he gets. Still, give the highest one that matches.
814 (NOTE: cagney/2004-10-29: Why highest, or outer-most, I don't
816 for (fid
= get_current_frame ();
818 fid
= get_prev_frame (fid
))
820 if (frame_id_eq (id
, get_frame_id (fid
)))
822 while (frame_id_eq (id
, frame_unwind_id (fid
)))
823 fid
= get_prev_frame (fid
);
829 /* We couldn't identify the frame as an existing frame, but
830 perhaps we can create one with a single argument. */
831 #ifdef SETUP_ARBITRARY_FRAME
832 return SETUP_ARBITRARY_FRAME (numargs
, addrs
);
834 /* Usual case. Do it here rather than have everyone supply a
835 SETUP_ARBITRARY_FRAME that does this. */
837 return create_new_frame (addrs
[0], 0);
838 error ("Too many args in frame specification");
843 parse_frame_specification (char *frame_exp
)
845 return parse_frame_specification_1 (frame_exp
, NULL
, NULL
);
848 /* Print verbosely the selected frame or the frame at address ADDR.
849 This means absolutely all information in the frame is printed. */
852 frame_info (char *addr_exp
, int from_tty
)
854 struct frame_info
*fi
;
855 struct symtab_and_line sal
;
858 struct frame_info
*calling_frame_info
;
859 int i
, count
, numregs
;
861 enum language funlang
= language_unknown
;
862 const char *pc_regname
;
863 int selected_frame_p
;
865 fi
= parse_frame_specification_1 (addr_exp
, "No stack.", &selected_frame_p
);
867 /* Name of the value returned by get_frame_pc(). Per comments, "pc"
868 is not a good name. */
870 /* OK, this is weird. The PC_REGNUM hardware register's value can
871 easily not match that of the internal value returned by
873 pc_regname
= REGISTER_NAME (PC_REGNUM
);
875 /* But then, this is weird to. Even without PC_REGNUM, an
876 architectures will often have a hardware register called "pc",
877 and that register's value, again, can easily not match
881 find_frame_sal (fi
, &sal
);
882 func
= get_frame_function (fi
);
883 /* FIXME: cagney/2002-11-28: Why bother? Won't sal.symtab contain
885 s
= find_pc_symtab (get_frame_pc (fi
));
888 /* I'd like to use SYMBOL_PRINT_NAME() here, to display
889 * the demangled name that we already have stored in
890 * the symbol table, but we stored a version with
891 * DMGL_PARAMS turned on, and here we don't want
892 * to display parameters. So call the demangler again,
893 * with DMGL_ANSI only. RT
894 * (Yes, I know that printf_symbol_filtered() will
895 * again try to demangle the name on the fly, but
896 * the issue is that if cplus_demangle() fails here,
897 * it'll fail there too. So we want to catch the failure
898 * ("demangled==NULL" case below) here, while we still
899 * have our hands on the function symbol.)
902 funname
= DEPRECATED_SYMBOL_NAME (func
);
903 funlang
= SYMBOL_LANGUAGE (func
);
904 if (funlang
== language_cplus
)
906 demangled
= cplus_demangle (funname
, DMGL_ANSI
);
907 /* If the demangler fails, try the demangled name
908 * from the symbol table. This'll have parameters,
909 * but that's preferable to diplaying a mangled name.
911 if (demangled
== NULL
)
912 funname
= SYMBOL_PRINT_NAME (func
);
917 struct minimal_symbol
*msymbol
= lookup_minimal_symbol_by_pc (get_frame_pc (fi
));
920 funname
= DEPRECATED_SYMBOL_NAME (msymbol
);
921 funlang
= SYMBOL_LANGUAGE (msymbol
);
924 calling_frame_info
= get_prev_frame (fi
);
926 if (selected_frame_p
&& frame_relative_level (fi
) >= 0)
928 printf_filtered ("Stack level %d, frame at ",
929 frame_relative_level (fi
));
930 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
931 printf_filtered (":\n");
935 printf_filtered ("Stack frame at ");
936 print_address_numeric (get_frame_base (fi
), 1, gdb_stdout
);
937 printf_filtered (":\n");
939 printf_filtered (" %s = ", pc_regname
);
940 print_address_numeric (get_frame_pc (fi
), 1, gdb_stdout
);
945 printf_filtered (" in ");
946 fprintf_symbol_filtered (gdb_stdout
, funname
, funlang
,
947 DMGL_ANSI
| DMGL_PARAMS
);
951 printf_filtered (" (%s:%d)", sal
.symtab
->filename
, sal
.line
);
952 puts_filtered ("; ");
954 printf_filtered ("saved %s ", pc_regname
);
955 print_address_numeric (frame_pc_unwind (fi
), 1, gdb_stdout
);
956 printf_filtered ("\n");
958 if (calling_frame_info
)
960 printf_filtered (" called by frame at ");
961 print_address_numeric (get_frame_base (calling_frame_info
),
964 if (get_next_frame (fi
) && calling_frame_info
)
967 if (get_next_frame (fi
))
969 printf_filtered (" caller of frame at ");
970 print_address_numeric (get_frame_base (get_next_frame (fi
)), 1,
973 if (get_next_frame (fi
) || calling_frame_info
)
974 puts_filtered ("\n");
976 printf_filtered (" source language %s.\n",
977 language_str (s
->language
));
980 /* Address of the argument list for this frame, or 0. */
981 CORE_ADDR arg_list
= get_frame_args_address (fi
);
982 /* Number of args for this frame, or -1 if unknown. */
986 printf_filtered (" Arglist at unknown address.\n");
989 printf_filtered (" Arglist at ");
990 print_address_numeric (arg_list
, 1, gdb_stdout
);
991 printf_filtered (",");
993 if (!FRAME_NUM_ARGS_P ())
996 puts_filtered (" args: ");
1000 numargs
= FRAME_NUM_ARGS (fi
);
1001 gdb_assert (numargs
>= 0);
1003 puts_filtered (" no args.");
1004 else if (numargs
== 1)
1005 puts_filtered (" 1 arg: ");
1007 printf_filtered (" %d args: ", numargs
);
1009 print_frame_args (func
, fi
, numargs
, gdb_stdout
);
1010 puts_filtered ("\n");
1014 /* Address of the local variables for this frame, or 0. */
1015 CORE_ADDR arg_list
= get_frame_locals_address (fi
);
1018 printf_filtered (" Locals at unknown address,");
1021 printf_filtered (" Locals at ");
1022 print_address_numeric (arg_list
, 1, gdb_stdout
);
1023 printf_filtered (",");
1027 /* Print as much information as possible on the location of all the
1030 enum lval_type lval
;
1038 /* The sp is special; what's displayed isn't the save address, but
1039 the value of the previous frame's sp. This is a legacy thing,
1040 at one stage the frame cached the previous frame's SP instead
1041 of its address, hence it was easiest to just display the cached
1045 /* Find out the location of the saved stack pointer with out
1046 actually evaluating it. */
1047 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1049 if (!optimized
&& lval
== not_lval
)
1051 char value
[MAX_REGISTER_SIZE
];
1053 frame_register_unwind (fi
, SP_REGNUM
, &optimized
, &lval
, &addr
,
1055 /* NOTE: cagney/2003-05-22: This is assuming that the
1056 stack pointer was packed as an unsigned integer. That
1057 may or may not be valid. */
1058 sp
= extract_unsigned_integer (value
, register_size (current_gdbarch
, SP_REGNUM
));
1059 printf_filtered (" Previous frame's sp is ");
1060 print_address_numeric (sp
, 1, gdb_stdout
);
1061 printf_filtered ("\n");
1064 else if (!optimized
&& lval
== lval_memory
)
1066 printf_filtered (" Previous frame's sp at ");
1067 print_address_numeric (addr
, 1, gdb_stdout
);
1068 printf_filtered ("\n");
1071 else if (!optimized
&& lval
== lval_register
)
1073 printf_filtered (" Previous frame's sp in %s\n",
1074 REGISTER_NAME (realnum
));
1077 /* else keep quiet. */
1081 numregs
= NUM_REGS
+ NUM_PSEUDO_REGS
;
1082 for (i
= 0; i
< numregs
; i
++)
1084 && gdbarch_register_reggroup_p (current_gdbarch
, i
, all_reggroup
))
1086 /* Find out the location of the saved register without
1087 fetching the corresponding value. */
1088 frame_register_unwind (fi
, i
, &optimized
, &lval
, &addr
, &realnum
,
1090 /* For moment, only display registers that were saved on the
1092 if (!optimized
&& lval
== lval_memory
)
1095 puts_filtered (" Saved registers:\n ");
1097 puts_filtered (",");
1099 printf_filtered (" %s at ", REGISTER_NAME (i
));
1100 print_address_numeric (addr
, 1, gdb_stdout
);
1104 if (count
|| need_nl
)
1105 puts_filtered ("\n");
1109 /* Print briefly all stack frames or just the innermost COUNT frames. */
1111 static void backtrace_command_1 (char *count_exp
, int show_locals
,
1114 backtrace_command_1 (char *count_exp
, int show_locals
, int from_tty
)
1116 struct frame_info
*fi
;
1119 struct frame_info
*trailing
;
1122 if (!target_has_stack
)
1123 error ("No stack.");
1125 /* The following code must do two things. First, it must
1126 set the variable TRAILING to the frame from which we should start
1127 printing. Second, it must set the variable count to the number
1128 of frames which we should print, or -1 if all of them. */
1129 trailing
= get_current_frame ();
1131 /* The target can be in a state where there is no valid frames
1132 (e.g., just connected). */
1133 if (trailing
== NULL
)
1134 error ("No stack.");
1139 count
= parse_and_eval_long (count_exp
);
1142 struct frame_info
*current
;
1147 while (current
&& count
--)
1150 current
= get_prev_frame (current
);
1153 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1154 will be COUNT below it. */
1158 trailing
= get_prev_frame (trailing
);
1159 current
= get_prev_frame (current
);
1171 struct partial_symtab
*ps
;
1173 /* Read in symbols for all of the frames. Need to do this in
1174 a separate pass so that "Reading in symbols for xxx" messages
1175 don't screw up the appearance of the backtrace. Also
1176 if people have strong opinions against reading symbols for
1177 backtrace this may have to be an option. */
1181 fi
= get_prev_frame (fi
))
1184 ps
= find_pc_psymtab (get_frame_address_in_block (fi
));
1186 PSYMTAB_TO_SYMTAB (ps
); /* Force syms to come in */
1190 for (i
= 0, fi
= trailing
;
1192 i
++, fi
= get_prev_frame (fi
))
1196 /* Don't use print_stack_frame; if an error() occurs it probably
1197 means further attempts to backtrace would fail (on the other
1198 hand, perhaps the code does or could be fixed to make sure
1199 the frame->prev field gets set to NULL in that case). */
1200 print_frame_info (fi
, 1, LOCATION
, 1);
1202 print_frame_local_vars (fi
, 1, gdb_stdout
);
1205 /* If we've stopped before the end, mention that. */
1207 printf_filtered ("(More stack frames follow...)\n");
1211 backtrace_command (char *arg
, int from_tty
)
1213 struct cleanup
*old_chain
= (struct cleanup
*) NULL
;
1214 char **argv
= (char **) NULL
;
1215 int argIndicatingFullTrace
= (-1), totArgLen
= 0, argc
= 0;
1218 if (arg
!= (char *) NULL
)
1222 argv
= buildargv (arg
);
1223 old_chain
= make_cleanup_freeargv (argv
);
1225 for (i
= 0; (argv
[i
] != (char *) NULL
); i
++)
1229 for (j
= 0; (j
< strlen (argv
[i
])); j
++)
1230 argv
[i
][j
] = tolower (argv
[i
][j
]);
1232 if (argIndicatingFullTrace
< 0 && subset_compare (argv
[i
], "full"))
1233 argIndicatingFullTrace
= argc
;
1237 totArgLen
+= strlen (argv
[i
]);
1241 if (argIndicatingFullTrace
>= 0)
1245 argPtr
= (char *) xmalloc (totArgLen
+ 1);
1250 memset (argPtr
, 0, totArgLen
+ 1);
1251 for (i
= 0; (i
< (argc
+ 1)); i
++)
1253 if (i
!= argIndicatingFullTrace
)
1255 strcat (argPtr
, argv
[i
]);
1256 strcat (argPtr
, " ");
1262 argPtr
= (char *) NULL
;
1266 backtrace_command_1 (argPtr
, (argIndicatingFullTrace
>= 0), from_tty
);
1268 if (argIndicatingFullTrace
>= 0 && totArgLen
> 0)
1272 do_cleanups (old_chain
);
1275 static void backtrace_full_command (char *arg
, int from_tty
);
1277 backtrace_full_command (char *arg
, int from_tty
)
1279 backtrace_command_1 (arg
, 1, from_tty
);
1283 /* Print the local variables of a block B active in FRAME.
1284 Return 1 if any variables were printed; 0 otherwise. */
1287 print_block_frame_locals (struct block
*b
, struct frame_info
*fi
,
1288 int num_tabs
, struct ui_file
*stream
)
1290 struct dict_iterator iter
;
1293 int values_printed
= 0;
1295 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1297 switch (SYMBOL_CLASS (sym
))
1305 for (j
= 0; j
< num_tabs
; j
++)
1306 fputs_filtered ("\t", stream
);
1307 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1308 fputs_filtered (" = ", stream
);
1309 print_variable_value (sym
, fi
, stream
);
1310 fprintf_filtered (stream
, "\n");
1314 /* Ignore symbols which are not locals. */
1318 return values_printed
;
1321 /* Same, but print labels. */
1324 print_block_frame_labels (struct block
*b
, int *have_default
,
1325 struct ui_file
*stream
)
1327 struct dict_iterator iter
;
1329 int values_printed
= 0;
1331 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1333 if (strcmp (DEPRECATED_SYMBOL_NAME (sym
), "default") == 0)
1339 if (SYMBOL_CLASS (sym
) == LOC_LABEL
)
1341 struct symtab_and_line sal
;
1342 sal
= find_pc_line (SYMBOL_VALUE_ADDRESS (sym
), 0);
1344 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1347 fprintf_filtered (stream
, " ");
1348 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, stream
);
1350 fprintf_filtered (stream
, " in file %s, line %d\n",
1351 sal
.symtab
->filename
, sal
.line
);
1354 return values_printed
;
1357 /* Print on STREAM all the local variables in frame FRAME,
1358 including all the blocks active in that frame
1361 Returns 1 if the job was done,
1362 or 0 if nothing was printed because we have no info
1363 on the function running in FRAME. */
1366 print_frame_local_vars (struct frame_info
*fi
, int num_tabs
,
1367 struct ui_file
*stream
)
1369 struct block
*block
= get_frame_block (fi
, 0);
1370 int values_printed
= 0;
1374 fprintf_filtered (stream
, "No symbol table info available.\n");
1380 if (print_block_frame_locals (block
, fi
, num_tabs
, stream
))
1382 /* After handling the function's top-level block, stop.
1383 Don't continue to its superblock, the block of
1384 per-file symbols. */
1385 if (BLOCK_FUNCTION (block
))
1387 block
= BLOCK_SUPERBLOCK (block
);
1390 if (!values_printed
)
1392 fprintf_filtered (stream
, "No locals.\n");
1396 /* Same, but print labels. */
1399 print_frame_label_vars (struct frame_info
*fi
, int this_level_only
,
1400 struct ui_file
*stream
)
1402 struct blockvector
*bl
;
1403 struct block
*block
= get_frame_block (fi
, 0);
1404 int values_printed
= 0;
1405 int index
, have_default
= 0;
1406 char *blocks_printed
;
1407 CORE_ADDR pc
= get_frame_pc (fi
);
1411 fprintf_filtered (stream
, "No symbol table info available.\n");
1415 bl
= blockvector_for_pc (BLOCK_END (block
) - 4, &index
);
1416 blocks_printed
= (char *) alloca (BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1417 memset (blocks_printed
, 0, BLOCKVECTOR_NBLOCKS (bl
) * sizeof (char));
1421 CORE_ADDR end
= BLOCK_END (block
) - 4;
1424 if (bl
!= blockvector_for_pc (end
, &index
))
1425 error ("blockvector blotch");
1426 if (BLOCKVECTOR_BLOCK (bl
, index
) != block
)
1427 error ("blockvector botch");
1428 last_index
= BLOCKVECTOR_NBLOCKS (bl
);
1431 /* Don't print out blocks that have gone by. */
1432 while (index
< last_index
1433 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < pc
)
1436 while (index
< last_index
1437 && BLOCK_END (BLOCKVECTOR_BLOCK (bl
, index
)) < end
)
1439 if (blocks_printed
[index
] == 0)
1441 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl
, index
), &have_default
, stream
))
1443 blocks_printed
[index
] = 1;
1449 if (values_printed
&& this_level_only
)
1452 /* After handling the function's top-level block, stop.
1453 Don't continue to its superblock, the block of
1454 per-file symbols. */
1455 if (BLOCK_FUNCTION (block
))
1457 block
= BLOCK_SUPERBLOCK (block
);
1460 if (!values_printed
&& !this_level_only
)
1462 fprintf_filtered (stream
, "No catches.\n");
1467 locals_info (char *args
, int from_tty
)
1469 print_frame_local_vars (get_selected_frame ("No frame selected."),
1474 catch_info (char *ignore
, int from_tty
)
1476 struct symtab_and_line
*sal
;
1478 /* Check for target support for exception handling */
1479 sal
= target_enable_exception_callback (EX_EVENT_CATCH
, 1);
1482 /* Currently not handling this */
1483 /* Ideally, here we should interact with the C++ runtime
1484 system to find the list of active handlers, etc. */
1485 fprintf_filtered (gdb_stdout
, "Info catch not supported with this target/compiler combination.\n");
1489 /* Assume g++ compiled code -- old v 4.16 behaviour */
1490 print_frame_label_vars (get_selected_frame ("No frame selected."),
1496 print_frame_arg_vars (struct frame_info
*fi
,
1497 struct ui_file
*stream
)
1499 struct symbol
*func
= get_frame_function (fi
);
1501 struct dict_iterator iter
;
1502 struct symbol
*sym
, *sym2
;
1503 int values_printed
= 0;
1507 fprintf_filtered (stream
, "No symbol table info available.\n");
1511 b
= SYMBOL_BLOCK_VALUE (func
);
1512 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1514 switch (SYMBOL_CLASS (sym
))
1520 case LOC_REGPARM_ADDR
:
1521 case LOC_BASEREG_ARG
:
1522 case LOC_COMPUTED_ARG
:
1524 fputs_filtered (SYMBOL_PRINT_NAME (sym
), stream
);
1525 fputs_filtered (" = ", stream
);
1527 /* We have to look up the symbol because arguments can have
1528 two entries (one a parameter, one a local) and the one we
1529 want is the local, which lookup_symbol will find for us.
1530 This includes gcc1 (not gcc2) on the sparc when passing a
1531 small structure and gcc2 when the argument type is float
1532 and it is passed as a double and converted to float by
1533 the prologue (in the latter case the type of the LOC_ARG
1534 symbol is double and the type of the LOC_LOCAL symbol is
1535 float). There are also LOC_ARG/LOC_REGISTER pairs which
1536 are not combined in symbol-reading. */
1538 sym2
= lookup_symbol (DEPRECATED_SYMBOL_NAME (sym
),
1539 b
, VAR_DOMAIN
, (int *) NULL
, (struct symtab
**) NULL
);
1540 print_variable_value (sym2
, fi
, stream
);
1541 fprintf_filtered (stream
, "\n");
1545 /* Don't worry about things which aren't arguments. */
1549 if (!values_printed
)
1551 fprintf_filtered (stream
, "No arguments.\n");
1556 args_info (char *ignore
, int from_tty
)
1558 print_frame_arg_vars (get_selected_frame ("No frame selected."),
1564 args_plus_locals_info (char *ignore
, int from_tty
)
1566 args_info (ignore
, from_tty
);
1567 locals_info (ignore
, from_tty
);
1571 /* Select frame FI. Also print the stack frame and show the source if
1572 this is the tui version. */
1574 select_and_print_frame (struct frame_info
*fi
)
1578 print_stack_frame (fi
, 1, SRC_AND_LOC
);
1581 /* Return the symbol-block in which the selected frame is executing.
1582 Can return zero under various legitimate circumstances.
1584 If ADDR_IN_BLOCK is non-zero, set *ADDR_IN_BLOCK to the relevant
1585 code address within the block returned. We use this to decide
1586 which macros are in scope. */
1589 get_selected_block (CORE_ADDR
*addr_in_block
)
1591 if (!target_has_stack
)
1594 /* NOTE: cagney/2002-11-28: Why go to all this effort to not create
1595 a selected/current frame? Perhaps this function is called,
1596 indirectly, by WFI in "infrun.c" where avoiding the creation of
1597 an inner most frame is very important (it slows down single
1598 step). I suspect, though that this was true in the deep dark
1599 past but is no longer the case. A mindless look at all the
1600 callers tends to support this theory. I think we should be able
1601 to assume that there is always a selcted frame. */
1602 /* gdb_assert (deprecated_selected_frame != NULL); So, do you feel
1604 if (!deprecated_selected_frame
)
1606 CORE_ADDR pc
= read_pc ();
1607 if (addr_in_block
!= NULL
)
1608 *addr_in_block
= pc
;
1609 return block_for_pc (pc
);
1611 return get_frame_block (deprecated_selected_frame
, addr_in_block
);
1614 /* Find a frame a certain number of levels away from FRAME.
1615 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1616 Positive means go to earlier frames (up); negative, the reverse.
1617 The int that contains the number of levels is counted toward
1618 zero as the frames for those levels are found.
1619 If the top or bottom frame is reached, that frame is returned,
1620 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1621 how much farther the original request asked to go. */
1624 find_relative_frame (struct frame_info
*frame
,
1625 int *level_offset_ptr
)
1627 struct frame_info
*prev
;
1628 struct frame_info
*frame1
;
1630 /* Going up is simple: just do get_prev_frame enough times
1631 or until initial frame is reached. */
1632 while (*level_offset_ptr
> 0)
1634 prev
= get_prev_frame (frame
);
1637 (*level_offset_ptr
)--;
1640 /* Going down is just as simple. */
1641 if (*level_offset_ptr
< 0)
1643 while (*level_offset_ptr
< 0)
1645 frame1
= get_next_frame (frame
);
1649 (*level_offset_ptr
)++;
1655 /* The "select_frame" command. With no arg, NOP.
1656 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1657 valid level. Otherwise, treat level_exp as an address expression
1658 and select it. See parse_frame_specification for more info on proper
1659 frame expressions. */
1662 select_frame_command (char *level_exp
, int from_tty
)
1664 select_frame (parse_frame_specification_1 (level_exp
, "No stack.", NULL
));
1667 /* The "frame" command. With no arg, print selected frame briefly.
1668 With arg, behaves like select_frame and then prints the selected
1672 frame_command (char *level_exp
, int from_tty
)
1674 select_frame_command (level_exp
, from_tty
);
1675 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1678 /* The XDB Compatibility command to print the current frame. */
1681 current_frame_command (char *level_exp
, int from_tty
)
1683 print_stack_frame (get_selected_frame ("No stack."), 1, SRC_AND_LOC
);
1686 /* Select the frame up one or COUNT stack levels
1687 from the previously selected frame, and print it briefly. */
1690 up_silently_base (char *count_exp
)
1692 struct frame_info
*fi
;
1693 int count
= 1, count1
;
1695 count
= parse_and_eval_long (count_exp
);
1698 fi
= find_relative_frame (get_selected_frame ("No stack."), &count1
);
1699 if (count1
!= 0 && count_exp
== 0)
1700 error ("Initial frame selected; you cannot go up.");
1705 up_silently_command (char *count_exp
, int from_tty
)
1707 up_silently_base (count_exp
);
1711 up_command (char *count_exp
, int from_tty
)
1713 up_silently_base (count_exp
);
1714 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1717 /* Select the frame down one or COUNT stack levels
1718 from the previously selected frame, and print it briefly. */
1721 down_silently_base (char *count_exp
)
1723 struct frame_info
*frame
;
1724 int count
= -1, count1
;
1726 count
= -parse_and_eval_long (count_exp
);
1729 frame
= find_relative_frame (get_selected_frame ("No stack."), &count1
);
1730 if (count1
!= 0 && count_exp
== 0)
1733 /* We only do this if count_exp is not specified. That way "down"
1734 means to really go down (and let me know if that is
1735 impossible), but "down 9999" can be used to mean go all the way
1736 down without getting an error. */
1738 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1741 select_frame (frame
);
1745 down_silently_command (char *count_exp
, int from_tty
)
1747 down_silently_base (count_exp
);
1751 down_command (char *count_exp
, int from_tty
)
1753 down_silently_base (count_exp
);
1754 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
1758 return_command (char *retval_exp
, int from_tty
)
1760 struct symbol
*thisfun
;
1761 struct value
*return_value
= NULL
;
1762 const char *query_prefix
= "";
1764 thisfun
= get_frame_function (get_selected_frame ("No selected frame."));
1766 /* Compute the return value. If the computation triggers an error,
1767 let it bail. If the return type can't be handled, set
1768 RETURN_VALUE to NULL, and QUERY_PREFIX to an informational
1772 struct type
*return_type
= NULL
;
1774 /* Compute the return value. Should the computation fail, this
1775 call throws an error. */
1776 return_value
= parse_and_eval (retval_exp
);
1778 /* Cast return value to the return type of the function. Should
1779 the cast fail, this call throws an error. */
1780 if (thisfun
!= NULL
)
1781 return_type
= TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun
));
1782 if (return_type
== NULL
)
1783 return_type
= builtin_type_int
;
1784 CHECK_TYPEDEF (return_type
);
1785 return_value
= value_cast (return_type
, return_value
);
1787 /* Make sure the value is fully evaluated. It may live in the
1788 stack frame we're about to pop. */
1789 if (VALUE_LAZY (return_value
))
1790 value_fetch_lazy (return_value
);
1792 if (TYPE_CODE (return_type
) == TYPE_CODE_VOID
)
1793 /* If the return-type is "void", don't try to find the
1794 return-value's location. However, do still evaluate the
1795 return expression so that, even when the expression result
1796 is discarded, side effects such as "return i++" still
1798 return_value
= NULL
;
1799 /* FIXME: cagney/2004-01-17: If the architecture implements both
1800 return_value and extract_returned_value_address, should allow
1801 "return" to work - don't set return_value to NULL. */
1802 else if (!gdbarch_return_value_p (current_gdbarch
)
1803 && (TYPE_CODE (return_type
) == TYPE_CODE_STRUCT
1804 || TYPE_CODE (return_type
) == TYPE_CODE_UNION
))
1806 /* NOTE: cagney/2003-10-20: Compatibility hack for legacy
1807 code. Old architectures don't expect STORE_RETURN_VALUE
1808 to be called with with a small struct that needs to be
1809 stored in registers. Don't start doing it now. */
1811 A structure or union return type is not supported by this architecture.\n\
1812 If you continue, the return value that you specified will be ignored.\n";
1813 return_value
= NULL
;
1815 else if (using_struct_return (return_type
, 0))
1818 The location at which to store the function's return value is unknown.\n\
1819 If you continue, the return value that you specified will be ignored.\n";
1820 return_value
= NULL
;
1824 /* Does an interactive user really want to do this? Include
1825 information, such as how well GDB can handle the return value, in
1826 the query message. */
1830 if (thisfun
== NULL
)
1831 confirmed
= query ("%sMake selected stack frame return now? ",
1834 confirmed
= query ("%sMake %s return now? ", query_prefix
,
1835 SYMBOL_PRINT_NAME (thisfun
));
1837 error ("Not confirmed");
1840 /* NOTE: cagney/2003-01-18: Is this silly? Rather than pop each
1841 frame in turn, should this code just go straight to the relevant
1842 frame and pop that? */
1844 /* First discard all frames inner-to the selected frame (making the
1845 selected frame current). */
1847 struct frame_id selected_id
= get_frame_id (get_selected_frame (NULL
));
1848 while (!frame_id_eq (selected_id
, get_frame_id (get_current_frame ())))
1850 if (frame_id_inner (selected_id
, get_frame_id (get_current_frame ())))
1851 /* Caught in the safety net, oops! We've gone way past the
1853 error ("Problem while popping stack frames (corrupt stack?)");
1854 frame_pop (get_current_frame ());
1858 /* Second discard the selected frame (which is now also the current
1860 frame_pop (get_current_frame ());
1862 /* Store RETURN_VAUE in the just-returned register set. */
1863 if (return_value
!= NULL
)
1865 struct type
*return_type
= VALUE_TYPE (return_value
);
1866 gdb_assert (gdbarch_return_value (current_gdbarch
, return_type
,
1868 == RETURN_VALUE_REGISTER_CONVENTION
);
1869 gdbarch_return_value (current_gdbarch
, return_type
,
1870 current_regcache
, NULL
/*read*/,
1871 VALUE_CONTENTS (return_value
) /*write*/);
1874 /* If we are at the end of a call dummy now, pop the dummy frame
1876 if (get_frame_type (get_current_frame ()) == DUMMY_FRAME
)
1877 frame_pop (get_current_frame ());
1879 /* If interactive, print the frame that is now current. */
1881 frame_command ("0", 1);
1883 select_frame_command ("0", 0);
1886 /* Sets the scope to input function name, provided that the
1887 function is within the current stack frame */
1889 struct function_bounds
1891 CORE_ADDR low
, high
;
1894 static void func_command (char *arg
, int from_tty
);
1896 func_command (char *arg
, int from_tty
)
1898 struct frame_info
*fp
;
1900 struct symtabs_and_lines sals
;
1903 struct function_bounds
*func_bounds
= (struct function_bounds
*) NULL
;
1905 if (arg
!= (char *) NULL
)
1908 fp
= parse_frame_specification ("0");
1909 sals
= decode_line_spec (arg
, 1);
1910 func_bounds
= (struct function_bounds
*) xmalloc (
1911 sizeof (struct function_bounds
) * sals
.nelts
);
1912 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1914 if (sals
.sals
[i
].pc
== (CORE_ADDR
) 0 ||
1915 find_pc_partial_function (sals
.sals
[i
].pc
,
1917 &func_bounds
[i
].low
,
1918 &func_bounds
[i
].high
) == 0)
1920 func_bounds
[i
].low
=
1921 func_bounds
[i
].high
= (CORE_ADDR
) NULL
;
1927 for (i
= 0; (i
< sals
.nelts
&& !found
); i
++)
1928 found
= (get_frame_pc (fp
) >= func_bounds
[i
].low
&&
1929 get_frame_pc (fp
) < func_bounds
[i
].high
);
1933 fp
= find_relative_frame (fp
, &level
);
1936 while (!found
&& level
== 0);
1939 xfree (func_bounds
);
1942 printf_filtered ("'%s' not within current stack frame.\n", arg
);
1943 else if (fp
!= deprecated_selected_frame
)
1944 select_and_print_frame (fp
);
1947 /* Gets the language of the current frame. */
1950 get_frame_language (void)
1953 enum language flang
; /* The language of the current frame */
1955 if (deprecated_selected_frame
)
1957 /* We determine the current frame language by looking up its
1958 associated symtab. To retrieve this symtab, we use the frame PC.
1959 However we cannot use the frame pc as is, because it usually points
1960 to the instruction following the "call", which is sometimes the first
1961 instruction of another function. So we rely on
1962 get_frame_address_in_block(), it provides us with a PC which is
1963 guaranteed to be inside the frame's code block. */
1964 s
= find_pc_symtab (get_frame_address_in_block (deprecated_selected_frame
));
1966 flang
= s
->language
;
1968 flang
= language_unknown
;
1971 flang
= language_unknown
;
1977 _initialize_stack (void)
1980 backtrace_limit
= 30;
1983 add_com ("return", class_stack
, return_command
,
1984 "Make selected stack frame return to its caller.\n\
1985 Control remains in the debugger, but when you continue\n\
1986 execution will resume in the frame above the one now selected.\n\
1987 If an argument is given, it is an expression for the value to return.");
1989 add_com ("up", class_stack
, up_command
,
1990 "Select and print stack frame that called this one.\n\
1991 An argument says how many frames up to go.");
1992 add_com ("up-silently", class_support
, up_silently_command
,
1993 "Same as the `up' command, but does not print anything.\n\
1994 This is useful in command scripts.");
1996 add_com ("down", class_stack
, down_command
,
1997 "Select and print stack frame called by this one.\n\
1998 An argument says how many frames down to go.");
1999 add_com_alias ("do", "down", class_stack
, 1);
2000 add_com_alias ("dow", "down", class_stack
, 1);
2001 add_com ("down-silently", class_support
, down_silently_command
,
2002 "Same as the `down' command, but does not print anything.\n\
2003 This is useful in command scripts.");
2005 add_com ("frame", class_stack
, frame_command
,
2006 "Select and print a stack frame.\n\
2007 With no argument, print the selected stack frame. (See also \"info frame\").\n\
2008 An argument specifies the frame to select.\n\
2009 It can be a stack frame number or the address of the frame.\n\
2010 With argument, nothing is printed if input is coming from\n\
2011 a command file or a user-defined command.");
2013 add_com_alias ("f", "frame", class_stack
, 1);
2017 add_com ("L", class_stack
, current_frame_command
,
2018 "Print the current stack frame.\n");
2019 add_com_alias ("V", "frame", class_stack
, 1);
2021 add_com ("select-frame", class_stack
, select_frame_command
,
2022 "Select a stack frame without printing anything.\n\
2023 An argument specifies the frame to select.\n\
2024 It can be a stack frame number or the address of the frame.\n");
2026 add_com ("backtrace", class_stack
, backtrace_command
,
2027 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2028 With a negative argument, print outermost -COUNT frames.\n\
2029 Use of the 'full' qualifier also prints the values of the local variables.\n");
2030 add_com_alias ("bt", "backtrace", class_stack
, 0);
2033 add_com_alias ("t", "backtrace", class_stack
, 0);
2034 add_com ("T", class_stack
, backtrace_full_command
,
2035 "Print backtrace of all stack frames, or innermost COUNT frames \n\
2036 and the values of the local variables.\n\
2037 With a negative argument, print outermost -COUNT frames.\n\
2038 Usage: T <count>\n");
2041 add_com_alias ("where", "backtrace", class_alias
, 0);
2042 add_info ("stack", backtrace_command
,
2043 "Backtrace of the stack, or innermost COUNT frames.");
2044 add_info_alias ("s", "stack", 1);
2045 add_info ("frame", frame_info
,
2046 "All about selected stack frame, or frame at ADDR.");
2047 add_info_alias ("f", "frame", 1);
2048 add_info ("locals", locals_info
,
2049 "Local variables of current stack frame.");
2050 add_info ("args", args_info
,
2051 "Argument variables of current stack frame.");
2053 add_com ("l", class_info
, args_plus_locals_info
,
2054 "Argument and local variables of current stack frame.");
2057 add_com ("func", class_stack
, func_command
,
2058 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2060 add_info ("catch", catch_info
,
2061 "Exceptions that can be caught in the current stack frame.");
2064 add_cmd ("backtrace-limit", class_stack
, set_backtrace_limit_command
,
2065 "Specify maximum number of frames for \"backtrace\" to print by default.",
2067 add_info ("backtrace-limit", backtrace_limit_info
,
2068 "The maximum number of frames for \"backtrace\" to print by default.");