1 /* Print and select stack frames for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991-1996, 1998-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
27 #include "expression.h"
33 #include "breakpoint.h"
43 /* Prototypes for exported functions. */
45 void args_info PARAMS ((char *, int));
47 void locals_info PARAMS ((char *, int));
49 void (*selected_frame_level_changed_hook) PARAMS ((int));
51 void _initialize_stack PARAMS ((void));
53 /* Prototypes for local functions. */
55 static void return_command PARAMS ((char *, int));
57 static void down_command PARAMS ((char *, int));
59 static void down_silently_base PARAMS ((char *));
61 static void down_silently_command PARAMS ((char *, int));
63 static void up_command PARAMS ((char *, int));
65 static void up_silently_base PARAMS ((char *));
67 static void up_silently_command PARAMS ((char *, int));
69 void frame_command PARAMS ((char *, int));
71 static void current_frame_command PARAMS ((char *, int));
73 static void select_frame_command PARAMS ((char *, int));
75 static void print_frame_arg_vars (struct frame_info *, struct ui_file *);
77 static void catch_info PARAMS ((char *, int));
79 static void args_plus_locals_info PARAMS ((char *, int));
81 static void print_frame_label_vars (struct frame_info *, int,
84 static void print_frame_local_vars (struct frame_info *, int,
87 static int print_block_frame_labels (struct block *, int *,
90 static int print_block_frame_locals (struct block *,
95 static void print_frame (struct frame_info *fi,
99 struct symtab_and_line sal);
101 static void print_frame_info_base PARAMS ((struct frame_info *, int, int, int));
103 static void print_stack_frame_base PARAMS ((struct frame_info *, int, int));
105 static void backtrace_command PARAMS ((char *, int));
107 struct frame_info *parse_frame_specification PARAMS ((char *));
109 static void frame_info PARAMS ((char *, int));
111 extern int addressprint; /* Print addresses, or stay symbolic only? */
112 extern int info_verbose; /* Verbosity of symbol reading msgs */
113 extern int lines_to_list; /* # of lines "list" command shows by default */
115 /* The "selected" stack frame is used by default for local and arg access.
116 May be zero, for no selected frame. */
118 struct frame_info *selected_frame;
120 /* Level of the selected frame:
121 0 for innermost, 1 for its caller, ...
122 or -1 for frame specified by address with no defined level. */
124 int selected_frame_level;
126 /* Zero means do things normally; we are interacting directly with the
127 user. One means print the full filename and linenumber when a
128 frame is printed, and do so in a format emacs18/emacs19.22 can
129 parse. Two means print similar annotations, but in many more
130 cases and in a slightly different syntax. */
132 int annotation_level = 0;
135 struct print_stack_frame_args
137 struct frame_info *fi;
143 static int print_stack_frame_base_stub PARAMS ((char *));
145 /* Show and print the frame arguments.
146 Pass the args the way catch_errors wants them. */
147 static int show_and_print_stack_frame_stub PARAMS ((void *args));
149 show_and_print_stack_frame_stub (args)
152 struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
154 /* Reversed order of these so tuiDo() doesn't occur
155 * in the middle of "Breakpoint 1 ... [location]" printing = RT
158 print_frame_info_base (p->fi, p->level, p->source, p->args);
159 print_frame_info (p->fi, p->level, p->source, p->args);
164 /* Show or print the frame arguments.
165 Pass the args the way catch_errors wants them. */
166 static int print_stack_frame_stub PARAMS ((void *args));
168 print_stack_frame_stub (args)
171 struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
174 print_frame_info (p->fi, p->level, p->source, p->args);
176 print_frame_info_base (p->fi, p->level, p->source, p->args);
180 /* Print a stack frame briefly. FRAME_INFI should be the frame info
181 and LEVEL should be its level in the stack (or -1 for level not
184 /* Pass the args the way catch_errors wants them. */
186 print_stack_frame_base_stub (args)
189 struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
191 print_frame_info_base (p->fi, p->level, p->source, p->args);
195 /* print the frame arguments to the terminal.
196 Pass the args the way catch_errors wants them. */
197 static int print_only_stack_frame_stub PARAMS ((void *));
199 print_only_stack_frame_stub (args)
202 struct print_stack_frame_args *p = (struct print_stack_frame_args *) args;
204 print_frame_info_base (p->fi, p->level, p->source, p->args);
208 /* Print a stack frame briefly. FRAME_INFI should be the frame info
209 and LEVEL should be its level in the stack (or -1 for level not defined).
210 This prints the level, the function executing, the arguments,
211 and the file name and line number.
212 If the pc is not at the beginning of the source line,
213 the actual pc is printed at the beginning.
215 If SOURCE is 1, print the source line as well.
216 If SOURCE is -1, print ONLY the source line. */
219 print_stack_frame_base (fi, level, source)
220 struct frame_info *fi;
224 struct print_stack_frame_args args;
228 args.source = source;
231 catch_errors (print_stack_frame_stub, &args, "", RETURN_MASK_ALL);
234 /* Show and print a stack frame briefly. FRAME_INFI should be the frame info
235 and LEVEL should be its level in the stack (or -1 for level not defined).
236 This prints the level, the function executing, the arguments,
237 and the file name and line number.
238 If the pc is not at the beginning of the source line,
239 the actual pc is printed at the beginning.
241 If SOURCE is 1, print the source line as well.
242 If SOURCE is -1, print ONLY the source line. */
245 show_and_print_stack_frame (fi, level, source)
246 struct frame_info *fi;
250 struct print_stack_frame_args args;
254 args.source = source;
257 catch_errors (show_and_print_stack_frame_stub, &args, "", RETURN_MASK_ALL);
261 /* Show or print a stack frame briefly. FRAME_INFI should be the frame info
262 and LEVEL should be its level in the stack (or -1 for level not defined).
263 This prints the level, the function executing, the arguments,
264 and the file name and line number.
265 If the pc is not at the beginning of the source line,
266 the actual pc is printed at the beginning.
268 If SOURCE is 1, print the source line as well.
269 If SOURCE is -1, print ONLY the source line. */
272 print_stack_frame (fi, level, source)
273 struct frame_info *fi;
277 struct print_stack_frame_args args;
281 args.source = source;
284 catch_errors (print_stack_frame_stub, (char *) &args, "", RETURN_MASK_ALL);
287 /* Print a stack frame briefly. FRAME_INFI should be the frame info
288 and LEVEL should be its level in the stack (or -1 for level not defined).
289 This prints the level, the function executing, the arguments,
290 and the file name and line number.
291 If the pc is not at the beginning of the source line,
292 the actual pc is printed at the beginning.
294 If SOURCE is 1, print the source line as well.
295 If SOURCE is -1, print ONLY the source line. */
298 print_only_stack_frame (fi, level, source)
299 struct frame_info *fi;
303 struct print_stack_frame_args args;
307 args.source = source;
310 catch_errors (print_only_stack_frame_stub, &args, "", RETURN_MASK_ALL);
313 struct print_args_args
316 struct frame_info *fi;
317 struct ui_file *stream;
320 static int print_args_stub PARAMS ((PTR));
322 /* Pass the args the way catch_errors wants them. */
325 print_args_stub (args)
329 struct print_args_args *p = (struct print_args_args *) args;
331 numargs = FRAME_NUM_ARGS (p->fi);
332 print_frame_args (p->func, p->fi, numargs, p->stream);
336 /* Print information about a frame for frame "fi" at level "level".
337 Used in "where" output, also used to emit breakpoint or step
339 LEVEL is the level of the frame, or -1 if it is the
340 innermost frame but we don't want to print the level.
341 The meaning of the SOURCE argument is:
342 SRC_LINE: Print only source line
343 LOCATION: Print only location
344 LOC_AND_SRC: Print location and source line. */
347 print_frame_info_base (fi, level, source, args)
348 struct frame_info *fi;
353 struct symtab_and_line sal;
358 char buf[MAX_REGISTER_RAW_SIZE];
361 /* On the 68k, this spends too much time in m68k_find_saved_regs. */
363 /* Get the value of SP_REGNUM relative to the frame. */
364 get_saved_register (buf, (int *) NULL, (CORE_ADDR *) NULL,
365 FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *) NULL);
366 sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
368 /* This is not a perfect test, because if a function alloca's some
369 memory, puts some code there, and then jumps into it, then the test
370 will succeed even though there is no call dummy. Probably best is
371 to check for a bp_call_dummy breakpoint. */
372 if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
374 if (frame_in_dummy (fi))
377 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
379 /* Do this regardless of SOURCE because we don't have any source
380 to list for this frame. */
382 printf_filtered ("#%-2d ", level);
383 annotate_function_call ();
384 printf_filtered ("<function called from gdb>\n");
385 annotate_frame_end ();
388 if (fi->signal_handler_caller)
390 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
392 /* Do this regardless of SOURCE because we don't have any source
393 to list for this frame. */
395 printf_filtered ("#%-2d ", level);
396 annotate_signal_handler_caller ();
397 printf_filtered ("<signal handler called>\n");
398 annotate_frame_end ();
402 /* If fi is not the innermost frame, that normally means that fi->pc
403 points to *after* the call instruction, and we want to get the line
404 containing the call, never the next line. But if the next frame is
405 a signal_handler_caller or a dummy frame, then the next frame was
406 not entered as the result of a call, and we want to get the line
407 containing fi->pc. */
409 find_pc_line (fi->pc,
411 && !fi->next->signal_handler_caller
412 && !frame_in_dummy (fi->next));
414 location_print = (source == LOCATION
415 || source == LOC_AND_ADDRESS
416 || source == SRC_AND_LOC);
418 if (location_print || !sal.symtab)
419 print_frame (fi, level, source, args, sal);
421 source_print = (source == SRC_LINE || source == SRC_AND_LOC);
423 if (source_print && sal.symtab)
426 int mid_statement = (source == SRC_LINE) && (fi->pc != sal.pc);
428 if (annotation_level)
429 done = identify_source_line (sal.symtab, sal.line, mid_statement,
433 if (addressprint && mid_statement && !tui_version)
436 ui_out_field_core_addr (uiout, "addr", fi->pc);
437 ui_out_text (uiout, "\t");
439 print_address_numeric (fi->pc, 1, gdb_stdout);
440 printf_filtered ("\t");
443 if (print_frame_info_listing_hook)
444 print_frame_info_listing_hook (sal.symtab, sal.line, sal.line + 1, 0);
445 else if (!tui_version)
446 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
448 current_source_line = max (sal.line - lines_to_list / 2, 1);
452 set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
454 annotate_frame_end ();
456 gdb_flush (gdb_stdout);
460 print_frame (struct frame_info *fi,
464 struct symtab_and_line sal)
467 register char *funname = 0;
468 enum language funlang = language_unknown;
470 struct ui_stream *stb;
471 struct cleanup *old_chain;
473 stb = ui_out_stream_new (uiout);
474 old_chain = make_cleanup ((make_cleanup_func) ui_out_stream_delete, stb);
477 func = find_pc_function (fi->pc);
480 /* In certain pathological cases, the symtabs give the wrong
481 function (when we are in the first function in a file which
482 is compiled without debugging symbols, the previous function
483 is compiled with debugging symbols, and the "foo.o" symbol
484 that is supposed to tell us where the file with debugging symbols
485 ends has been truncated by ar because it is longer than 15
486 characters). This also occurs if the user uses asm() to create
487 a function but not stabs for it (in a file compiled -g).
489 So look in the minimal symbol tables as well, and if it comes
490 up with a larger address for the function use that instead.
491 I don't think this can ever cause any problems; there shouldn't
492 be any minimal symbols in the middle of a function; if this is
493 ever changed many parts of GDB will need to be changed (and we'll
494 create a find_pc_minimal_function or some such). */
496 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
498 && (SYMBOL_VALUE_ADDRESS (msymbol)
499 > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
502 /* There is no particular reason to think the line number
503 information is wrong. Someone might have just put in
504 a label with asm() but left the line numbers alone. */
505 /* In this case we have no way of knowing the source file
506 and line number, so don't print them. */
509 /* We also don't know anything about the function besides
510 its address and name. */
512 funname = SYMBOL_NAME (msymbol);
513 funlang = SYMBOL_LANGUAGE (msymbol);
517 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display the
518 demangled name that we already have stored in the symbol
519 table, but we stored a version with DMGL_PARAMS turned
520 on, and here we don't want to display parameters. So call
521 the demangler again, with DMGL_ANSI only. (Yes, I know
522 that printf_symbol_filtered() will again try to demangle
523 the name on the fly, but the issue is that if
524 cplus_demangle() fails here, it'll fail there too. So we
525 want to catch the failure ("demangled==NULL" case below)
526 here, while we still have our hands on the function
529 funname = SYMBOL_NAME (func);
530 funlang = SYMBOL_LANGUAGE (func);
531 if (funlang == language_cplus)
533 demangled = cplus_demangle (funname, DMGL_ANSI);
534 if (demangled == NULL)
535 /* If the demangler fails, try the demangled name from
536 the symbol table. This'll have parameters, but
537 that's preferable to diplaying a mangled name. */
538 funname = SYMBOL_SOURCE_NAME (func);
544 struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
547 funname = SYMBOL_NAME (msymbol);
548 funlang = SYMBOL_LANGUAGE (msymbol);
552 annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
555 ui_out_list_begin (uiout, "frame");
561 ui_out_text (uiout, "#");
562 ui_out_field_fmt (uiout, "level", "%-2d", level);
563 ui_out_spaces (uiout, 1);
565 printf_filtered ("#%-2d ", level);
569 if (fi->pc != sal.pc || !sal.symtab || source == LOC_AND_ADDRESS)
571 annotate_frame_address ();
573 ui_out_field_core_addr (uiout, "addr", fi->pc);
574 annotate_frame_address_end ();
575 ui_out_text (uiout, " in ");
577 print_address_numeric (fi->pc, 1, gdb_stdout);
578 annotate_frame_address_end ();
579 printf_filtered (" in ");
582 annotate_frame_function_name ();
584 fprintf_symbol_filtered (stb->stream, funname ? funname : "??", funlang,
586 ui_out_field_stream (uiout, "func", stb);
587 ui_out_wrap_hint (uiout, " ");
589 fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang,
593 annotate_frame_args ();
596 ui_out_text (uiout, " (");
598 fputs_filtered (" (", gdb_stdout);
602 struct print_args_args args;
605 args.stream = gdb_stdout;
607 ui_out_list_begin (uiout, "args");
608 catch_errors (print_args_stub, &args, "", RETURN_MASK_ALL);
609 /* FIXME: args must be a list. If one argument is a string it will
610 have " that will not be properly escaped. */
611 ui_out_list_end (uiout);
613 catch_errors (print_args_stub, &args, "", RETURN_MASK_ALL);
618 ui_out_text (uiout, ")");
620 printf_filtered (")");
622 if (sal.symtab && sal.symtab->filename)
624 annotate_frame_source_begin ();
626 ui_out_wrap_hint (uiout, " ");
627 ui_out_text (uiout, " at ");
628 annotate_frame_source_file ();
629 ui_out_field_string (uiout, "file", sal.symtab->filename);
630 annotate_frame_source_file_end ();
631 ui_out_text (uiout, ":");
632 annotate_frame_source_line ();
633 ui_out_field_int (uiout, "line", sal.line);
636 printf_filtered (" at ");
637 annotate_frame_source_file ();
638 printf_filtered ("%s", sal.symtab->filename);
639 annotate_frame_source_file_end ();
640 printf_filtered (":");
641 annotate_frame_source_line ();
642 printf_filtered ("%d", sal.line);
644 annotate_frame_source_end ();
647 #ifdef PC_LOAD_SEGMENT
648 /* If we couldn't print out function name but if can figure out what
649 load segment this pc value is from, at least print out some info
650 about its load segment. */
653 annotate_frame_where ();
655 ui_out_wrap_hint (uiout, " ");
656 ui_out_text (uiout, " from ");
657 ui_out_field_string (uiout, "from", PC_LOAD_SEGMENT (fi->pc));
660 printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
663 #endif /* PC_LOAD_SEGMENT */
666 if (!funname || (!sal.symtab || !sal.symtab->filename))
668 char *lib = PC_SOLIB (fi->pc);
671 annotate_frame_where ();
673 ui_out_wrap_hint (uiout, " ");
674 ui_out_text (uiout, " from ");
675 ui_out_field_string (uiout, "from", lib);
678 printf_filtered (" from %s", lib);
682 #endif /* PC_SOLIB */
685 ui_out_list_end (uiout);
686 ui_out_text (uiout, "\n");
687 do_cleanups (old_chain);
689 printf_filtered ("\n");
696 stack_publish_stopped_with_no_frame ()
698 TUIDO (((TuiOpaqueFuncPtr) tuiUpdateOnEnd));
704 /* Show or print the frame info. If this is the tui, it will be shown in
705 the source display */
707 print_frame_info (fi, level, source, args)
708 struct frame_info *fi;
714 print_frame_info_base (fi, level, source, args);
717 if (fi && (frame_in_dummy (fi) || fi->signal_handler_caller))
718 print_frame_info_base (fi, level, source, args);
721 TUIDO (((TuiOpaqueFuncPtr) tui_vShowFrameInfo, fi));
726 /* Show the frame info. If this is the tui, it will be shown in
727 the source display otherwise, nothing is done */
729 show_stack_frame (fi)
730 struct frame_info *fi;
732 TUIDO (((TuiOpaqueFuncPtr) tui_vShowFrameInfo, fi));
736 /* Read a frame specification in whatever the appropriate format is.
737 Call error() if the specification is in any way invalid (i.e.
738 this function never returns NULL). */
741 parse_frame_specification (frame_exp)
746 CORE_ADDR args[MAXARGS];
750 char *addr_string, *p;
751 struct cleanup *tmp_cleanup;
753 while (*frame_exp == ' ')
758 if (numargs > MAXARGS)
759 error ("Too many args in frame specification");
760 /* Parse an argument. */
761 for (p = frame_exp; *p && *p != ' '; p++)
763 addr_string = savestring (frame_exp, p - frame_exp);
766 tmp_cleanup = make_cleanup (free, addr_string);
767 args[numargs++] = parse_and_eval_address (addr_string);
768 do_cleanups (tmp_cleanup);
771 /* Skip spaces, move to possible next arg. */
781 if (selected_frame == NULL)
782 error ("No selected frame.");
783 return selected_frame;
788 struct frame_info *fid =
789 find_relative_frame (get_current_frame (), &level);
790 struct frame_info *tfid;
793 /* find_relative_frame was successful */
796 /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
797 take at least 2 addresses. It is important to detect this case
798 here so that "frame 100" does not give a confusing error message
799 like "frame specification requires two addresses". This of course
800 does not solve the "frame 100" problem for machines on which
801 a frame specification can be made with one address. To solve
802 that, we need a new syntax for a specifying a frame by address.
803 I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
804 two args, etc.), but people might think that is too much typing,
805 so I guess *0x23,0x45 would be a possible alternative (commas
806 really should be used instead of spaces to delimit; using spaces
807 normally works in an expression). */
808 #ifdef SETUP_ARBITRARY_FRAME
809 error ("No frame %d", args[0]);
812 /* If (s)he specifies the frame with an address, he deserves what
813 (s)he gets. Still, give the highest one that matches. */
815 for (fid = get_current_frame ();
816 fid && fid->frame != args[0];
817 fid = get_prev_frame (fid))
821 while ((tfid = get_prev_frame (fid)) &&
822 (tfid->frame == args[0]))
825 /* We couldn't identify the frame as an existing frame, but
826 perhaps we can create one with a single argument. */
830 #ifdef SETUP_ARBITRARY_FRAME
831 return SETUP_ARBITRARY_FRAME (numargs, args);
833 /* Usual case. Do it here rather than have everyone supply
834 a SETUP_ARBITRARY_FRAME that does this. */
836 return create_new_frame (args[0], 0);
837 error ("Too many args in frame specification");
844 /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
845 that if it is unsure about the answer, it returns 0
846 instead of guessing (this happens on the VAX and i960, for example).
848 On most machines, we never have to guess about the args address,
849 so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */
850 #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
851 #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
854 /* Print verbosely the selected frame or the frame at address ADDR.
855 This means absolutely all information in the frame is printed. */
858 frame_info (addr_exp, from_tty)
862 struct frame_info *fi;
863 struct symtab_and_line sal;
866 struct frame_info *calling_frame_info;
867 int i, count, numregs;
869 enum language funlang = language_unknown;
871 if (!target_has_stack)
874 fi = parse_frame_specification (addr_exp);
876 error ("Invalid frame specified.");
878 sal = find_pc_line (fi->pc,
880 && !fi->next->signal_handler_caller
881 && !frame_in_dummy (fi->next));
882 func = get_frame_function (fi);
883 s = find_pc_symtab (fi->pc);
886 /* I'd like to use SYMBOL_SOURCE_NAME() here, to display
887 * the demangled name that we already have stored in
888 * the symbol table, but we stored a version with
889 * DMGL_PARAMS turned on, and here we don't want
890 * to display parameters. So call the demangler again,
891 * with DMGL_ANSI only. RT
892 * (Yes, I know that printf_symbol_filtered() will
893 * again try to demangle the name on the fly, but
894 * the issue is that if cplus_demangle() fails here,
895 * it'll fail there too. So we want to catch the failure
896 * ("demangled==NULL" case below) here, while we still
897 * have our hands on the function symbol.)
900 funname = SYMBOL_NAME (func);
901 funlang = SYMBOL_LANGUAGE (func);
902 if (funlang == language_cplus)
904 demangled = cplus_demangle (funname, DMGL_ANSI);
905 /* If the demangler fails, try the demangled name
906 * from the symbol table. This'll have parameters,
907 * but that's preferable to diplaying a mangled name.
909 if (demangled == NULL)
910 funname = SYMBOL_SOURCE_NAME (func);
915 register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
918 funname = SYMBOL_NAME (msymbol);
919 funlang = SYMBOL_LANGUAGE (msymbol);
922 calling_frame_info = get_prev_frame (fi);
924 if (!addr_exp && selected_frame_level >= 0)
926 printf_filtered ("Stack level %d, frame at ", selected_frame_level);
927 print_address_numeric (fi->frame, 1, gdb_stdout);
928 printf_filtered (":\n");
932 printf_filtered ("Stack frame at ");
933 print_address_numeric (fi->frame, 1, gdb_stdout);
934 printf_filtered (":\n");
936 printf_filtered (" %s = ", REGISTER_NAME (PC_REGNUM));
937 print_address_numeric (fi->pc, 1, gdb_stdout);
942 printf_filtered (" in ");
943 fprintf_symbol_filtered (gdb_stdout, funname, funlang,
944 DMGL_ANSI | DMGL_PARAMS);
948 printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
949 puts_filtered ("; ");
951 printf_filtered ("saved %s ", REGISTER_NAME (PC_REGNUM));
952 print_address_numeric (FRAME_SAVED_PC (fi), 1, gdb_stdout);
953 printf_filtered ("\n");
957 frameless = FRAMELESS_FUNCTION_INVOCATION (fi);
959 printf_filtered (" (FRAMELESS),");
962 if (calling_frame_info)
964 printf_filtered (" called by frame at ");
965 print_address_numeric (calling_frame_info->frame, 1, gdb_stdout);
967 if (fi->next && calling_frame_info)
972 printf_filtered (" caller of frame at ");
973 print_address_numeric (fi->next->frame, 1, gdb_stdout);
975 if (fi->next || calling_frame_info)
976 puts_filtered ("\n");
978 printf_filtered (" source language %s.\n", language_str (s->language));
980 #ifdef PRINT_EXTRA_FRAME_INFO
981 PRINT_EXTRA_FRAME_INFO (fi);
985 /* Address of the argument list for this frame, or 0. */
986 CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
987 /* Number of args for this frame, or -1 if unknown. */
991 printf_filtered (" Arglist at unknown address.\n");
994 printf_filtered (" Arglist at ");
995 print_address_numeric (arg_list, 1, gdb_stdout);
996 printf_filtered (",");
998 numargs = FRAME_NUM_ARGS (fi);
1000 puts_filtered (" args: ");
1001 else if (numargs == 0)
1002 puts_filtered (" no args.");
1003 else if (numargs == 1)
1004 puts_filtered (" 1 arg: ");
1006 printf_filtered (" %d args: ", numargs);
1007 print_frame_args (func, fi, numargs, gdb_stdout);
1008 puts_filtered ("\n");
1012 /* Address of the local variables for this frame, or 0. */
1013 CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
1016 printf_filtered (" Locals at unknown address,");
1019 printf_filtered (" Locals at ");
1020 print_address_numeric (arg_list, 1, gdb_stdout);
1021 printf_filtered (",");
1025 FRAME_INIT_SAVED_REGS (fi);
1026 if (fi->saved_regs != NULL)
1028 /* The sp is special; what's returned isn't the save address, but
1029 actually the value of the previous frame's sp. */
1030 printf_filtered (" Previous frame's sp is ");
1031 print_address_numeric (fi->saved_regs[SP_REGNUM], 1, gdb_stdout);
1032 printf_filtered ("\n");
1034 numregs = ARCH_NUM_REGS;
1035 for (i = 0; i < numregs; i++)
1036 if (fi->saved_regs[i] && i != SP_REGNUM)
1039 puts_filtered (" Saved registers:\n ");
1041 puts_filtered (",");
1043 printf_filtered (" %s at ", REGISTER_NAME (i));
1044 print_address_numeric (fi->saved_regs[i], 1, gdb_stdout);
1048 puts_filtered ("\n");
1052 /* We could get some information about saved registers by
1053 calling get_saved_register on each register. Which info goes
1054 with which frame is necessarily lost, however, and I suspect
1055 that the users don't care whether they get the info. */
1056 puts_filtered ("\n");
1061 /* Set a limit on the number of frames printed by default in a
1064 static int backtrace_limit;
1067 set_backtrace_limit_command (count_exp, from_tty)
1071 int count = parse_and_eval_address (count_exp);
1074 error ("Negative argument not meaningful as backtrace limit.");
1076 backtrace_limit = count;
1080 backtrace_limit_info (arg, from_tty)
1085 error ("\"Info backtrace-limit\" takes no arguments.");
1087 printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
1091 /* Print briefly all stack frames or just the innermost COUNT frames. */
1093 static void backtrace_command_1 PARAMS ((char *count_exp, int show_locals, int from_tty));
1095 backtrace_command_1 (count_exp, show_locals, from_tty)
1100 struct frame_info *fi;
1103 register struct frame_info *trailing;
1104 register int trailing_level;
1106 if (!target_has_stack)
1107 error ("No stack.");
1109 /* The following code must do two things. First, it must
1110 set the variable TRAILING to the frame from which we should start
1111 printing. Second, it must set the variable count to the number
1112 of frames which we should print, or -1 if all of them. */
1113 trailing = get_current_frame ();
1115 /* The target can be in a state where there is no valid frames
1116 (e.g., just connected). */
1117 if (trailing == NULL)
1118 error ("No stack.");
1123 count = parse_and_eval_address (count_exp);
1126 struct frame_info *current;
1131 while (current && count--)
1134 current = get_prev_frame (current);
1137 /* Will stop when CURRENT reaches the top of the stack. TRAILING
1138 will be COUNT below it. */
1142 trailing = get_prev_frame (trailing);
1143 current = get_prev_frame (current);
1155 struct partial_symtab *ps;
1157 /* Read in symbols for all of the frames. Need to do this in
1158 a separate pass so that "Reading in symbols for xxx" messages
1159 don't screw up the appearance of the backtrace. Also
1160 if people have strong opinions against reading symbols for
1161 backtrace this may have to be an option. */
1165 fi = get_prev_frame (fi))
1168 ps = find_pc_psymtab (fi->pc);
1170 PSYMTAB_TO_SYMTAB (ps); /* Force syms to come in */
1174 for (i = 0, fi = trailing;
1176 i++, fi = get_prev_frame (fi))
1180 /* Don't use print_stack_frame; if an error() occurs it probably
1181 means further attempts to backtrace would fail (on the other
1182 hand, perhaps the code does or could be fixed to make sure
1183 the frame->prev field gets set to NULL in that case). */
1184 print_frame_info_base (fi, trailing_level + i, 0, 1);
1186 print_frame_local_vars (fi, 1, gdb_stdout);
1189 /* If we've stopped before the end, mention that. */
1191 printf_filtered ("(More stack frames follow...)\n");
1195 backtrace_command (arg, from_tty)
1199 struct cleanup *old_chain = (struct cleanup *) NULL;
1200 char **argv = (char **) NULL;
1201 int argIndicatingFullTrace = (-1), totArgLen = 0, argc = 0;
1204 if (arg != (char *) NULL)
1208 argv = buildargv (arg);
1209 old_chain = make_cleanup_freeargv (argv);
1211 for (i = 0; (argv[i] != (char *) NULL); i++)
1215 for (j = 0; (j < strlen (argv[i])); j++)
1216 argv[i][j] = tolower (argv[i][j]);
1218 if (argIndicatingFullTrace < 0 && subset_compare (argv[i], "full"))
1219 argIndicatingFullTrace = argc;
1223 totArgLen += strlen (argv[i]);
1227 if (argIndicatingFullTrace >= 0)
1231 argPtr = (char *) xmalloc (totArgLen + 1);
1236 memset (argPtr, 0, totArgLen + 1);
1237 for (i = 0; (i < (argc + 1)); i++)
1239 if (i != argIndicatingFullTrace)
1241 strcat (argPtr, argv[i]);
1242 strcat (argPtr, " ");
1248 argPtr = (char *) NULL;
1252 backtrace_command_1 (argPtr, (argIndicatingFullTrace >= 0), from_tty);
1254 if (argIndicatingFullTrace >= 0 && totArgLen > 0)
1258 do_cleanups (old_chain);
1261 static void backtrace_full_command PARAMS ((char *arg, int from_tty));
1263 backtrace_full_command (arg, from_tty)
1267 backtrace_command_1 (arg, 1, from_tty);
1271 /* Print the local variables of a block B active in FRAME.
1272 Return 1 if any variables were printed; 0 otherwise. */
1275 print_block_frame_locals (b, fi, num_tabs, stream)
1277 register struct frame_info *fi;
1279 register struct ui_file *stream;
1283 register struct symbol *sym;
1284 register int values_printed = 0;
1286 nsyms = BLOCK_NSYMS (b);
1288 for (i = 0; i < nsyms; i++)
1290 sym = BLOCK_SYM (b, i);
1291 switch (SYMBOL_CLASS (sym))
1298 for (j = 0; j < num_tabs; j++)
1299 fputs_filtered ("\t", stream);
1300 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
1301 fputs_filtered (" = ", stream);
1302 print_variable_value (sym, fi, stream);
1303 fprintf_filtered (stream, "\n");
1307 /* Ignore symbols which are not locals. */
1311 return values_printed;
1314 /* Same, but print labels. */
1317 print_block_frame_labels (b, have_default, stream)
1320 register struct ui_file *stream;
1324 register struct symbol *sym;
1325 register int values_printed = 0;
1327 nsyms = BLOCK_NSYMS (b);
1329 for (i = 0; i < nsyms; i++)
1331 sym = BLOCK_SYM (b, i);
1332 if (STREQ (SYMBOL_NAME (sym), "default"))
1338 if (SYMBOL_CLASS (sym) == LOC_LABEL)
1340 struct symtab_and_line sal;
1341 sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
1343 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
1346 fprintf_filtered (stream, " ");
1347 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
1349 fprintf_filtered (stream, " in file %s, line %d\n",
1350 sal.symtab->filename, sal.line);
1353 return values_printed;
1356 /* Print on STREAM all the local variables in frame FRAME,
1357 including all the blocks active in that frame
1360 Returns 1 if the job was done,
1361 or 0 if nothing was printed because we have no info
1362 on the function running in FRAME. */
1365 print_frame_local_vars (fi, num_tabs, stream)
1366 register struct frame_info *fi;
1367 register int num_tabs;
1368 register struct ui_file *stream;
1370 register struct block *block = get_frame_block (fi);
1371 register int values_printed = 0;
1375 fprintf_filtered (stream, "No symbol table info available.\n");
1381 if (print_block_frame_locals (block, fi, num_tabs, stream))
1383 /* After handling the function's top-level block, stop.
1384 Don't continue to its superblock, the block of
1385 per-file symbols. */
1386 if (BLOCK_FUNCTION (block))
1388 block = BLOCK_SUPERBLOCK (block);
1391 if (!values_printed)
1393 fprintf_filtered (stream, "No locals.\n");
1397 /* Same, but print labels. */
1400 print_frame_label_vars (fi, this_level_only, stream)
1401 register struct frame_info *fi;
1402 int this_level_only;
1403 register struct ui_file *stream;
1405 register struct blockvector *bl;
1406 register struct block *block = get_frame_block (fi);
1407 register int values_printed = 0;
1408 int index, have_default = 0;
1409 char *blocks_printed;
1410 CORE_ADDR pc = fi->pc;
1414 fprintf_filtered (stream, "No symbol table info available.\n");
1418 bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
1419 blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1420 memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
1424 CORE_ADDR end = BLOCK_END (block) - 4;
1427 if (bl != blockvector_for_pc (end, &index))
1428 error ("blockvector blotch");
1429 if (BLOCKVECTOR_BLOCK (bl, index) != block)
1430 error ("blockvector botch");
1431 last_index = BLOCKVECTOR_NBLOCKS (bl);
1434 /* Don't print out blocks that have gone by. */
1435 while (index < last_index
1436 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
1439 while (index < last_index
1440 && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
1442 if (blocks_printed[index] == 0)
1444 if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
1446 blocks_printed[index] = 1;
1452 if (values_printed && this_level_only)
1455 /* After handling the function's top-level block, stop.
1456 Don't continue to its superblock, the block of
1457 per-file symbols. */
1458 if (BLOCK_FUNCTION (block))
1460 block = BLOCK_SUPERBLOCK (block);
1463 if (!values_printed && !this_level_only)
1465 fprintf_filtered (stream, "No catches.\n");
1471 locals_info (args, from_tty)
1475 if (!selected_frame)
1476 error ("No frame selected.");
1477 print_frame_local_vars (selected_frame, 0, gdb_stdout);
1481 catch_info (ignore, from_tty)
1485 struct symtab_and_line *sal;
1487 /* Check for target support for exception handling */
1488 sal = target_enable_exception_callback (EX_EVENT_CATCH, 1);
1491 /* Currently not handling this */
1492 /* Ideally, here we should interact with the C++ runtime
1493 system to find the list of active handlers, etc. */
1494 fprintf_filtered (gdb_stdout, "Info catch not supported with this target/compiler combination.\n");
1496 if (!selected_frame)
1497 error ("No frame selected.");
1502 /* Assume g++ compiled code -- old v 4.16 behaviour */
1503 if (!selected_frame)
1504 error ("No frame selected.");
1506 print_frame_label_vars (selected_frame, 0, gdb_stdout);
1511 print_frame_arg_vars (fi, stream)
1512 register struct frame_info *fi;
1513 register struct ui_file *stream;
1515 struct symbol *func = get_frame_function (fi);
1516 register struct block *b;
1519 register struct symbol *sym, *sym2;
1520 register int values_printed = 0;
1524 fprintf_filtered (stream, "No symbol table info available.\n");
1528 b = SYMBOL_BLOCK_VALUE (func);
1529 nsyms = BLOCK_NSYMS (b);
1531 for (i = 0; i < nsyms; i++)
1533 sym = BLOCK_SYM (b, i);
1534 switch (SYMBOL_CLASS (sym))
1540 case LOC_REGPARM_ADDR:
1541 case LOC_BASEREG_ARG:
1543 fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
1544 fputs_filtered (" = ", stream);
1546 /* We have to look up the symbol because arguments can have
1547 two entries (one a parameter, one a local) and the one we
1548 want is the local, which lookup_symbol will find for us.
1549 This includes gcc1 (not gcc2) on the sparc when passing a
1550 small structure and gcc2 when the argument type is float
1551 and it is passed as a double and converted to float by
1552 the prologue (in the latter case the type of the LOC_ARG
1553 symbol is double and the type of the LOC_LOCAL symbol is
1554 float). There are also LOC_ARG/LOC_REGISTER pairs which
1555 are not combined in symbol-reading. */
1557 sym2 = lookup_symbol (SYMBOL_NAME (sym),
1558 b, VAR_NAMESPACE, (int *) NULL, (struct symtab **) NULL);
1559 print_variable_value (sym2, fi, stream);
1560 fprintf_filtered (stream, "\n");
1564 /* Don't worry about things which aren't arguments. */
1569 if (!values_printed)
1571 fprintf_filtered (stream, "No arguments.\n");
1576 args_info (ignore, from_tty)
1580 if (!selected_frame)
1581 error ("No frame selected.");
1582 print_frame_arg_vars (selected_frame, gdb_stdout);
1587 args_plus_locals_info (ignore, from_tty)
1591 args_info (ignore, from_tty);
1592 locals_info (ignore, from_tty);
1596 /* Select frame FI, and note that its stack level is LEVEL.
1597 LEVEL may be -1 if an actual level number is not known. */
1600 select_frame (fi, level)
1601 struct frame_info *fi;
1604 register struct symtab *s;
1606 selected_frame = fi;
1607 selected_frame_level = level;
1608 if (selected_frame_level_changed_hook)
1609 selected_frame_level_changed_hook (level);
1611 /* Ensure that symbols for this frame are read in. Also, determine the
1612 source language of this frame, and switch to it if desired. */
1615 s = find_pc_symtab (fi->pc);
1617 && s->language != current_language->la_language
1618 && s->language != language_unknown
1619 && language_mode == language_mode_auto)
1621 set_language (s->language);
1623 /* elz: this if here fixes the problem with the pc not being displayed
1624 in the tui asm layout, with no debug symbols. The value of s
1625 would be 0 here, and select_source_symtab would abort the
1626 command by calling the 'error' function */
1629 TUIDO (((TuiOpaqueFuncPtr) tui_vSelectSourceSymtab, s));
1635 /* Select frame FI, noting that its stack level is LEVEL. Also print
1636 the stack frame and show the source if this is the tui version. */
1638 select_and_print_frame (fi, level)
1639 struct frame_info *fi;
1642 select_frame (fi, level);
1645 print_stack_frame (fi, level, 1);
1646 TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, fi));
1651 /* Select frame FI, noting that its stack level is LEVEL. Be silent if
1655 select_and_maybe_print_frame (fi, level)
1656 struct frame_info *fi;
1660 select_frame (fi, level);
1662 select_and_print_frame (fi, level);
1667 /* Store the selected frame and its level into *FRAMEP and *LEVELP.
1668 If there is no selected frame, *FRAMEP is set to NULL. */
1671 record_selected_frame (frameaddrp, levelp)
1672 CORE_ADDR *frameaddrp;
1675 *frameaddrp = selected_frame ? selected_frame->frame : 0;
1676 *levelp = selected_frame_level;
1679 /* Return the symbol-block in which the selected frame is executing.
1680 Can return zero under various legitimate circumstances. */
1683 get_selected_block ()
1685 if (!target_has_stack)
1688 if (!selected_frame)
1689 return get_current_block ();
1690 return get_frame_block (selected_frame);
1693 /* Find a frame a certain number of levels away from FRAME.
1694 LEVEL_OFFSET_PTR points to an int containing the number of levels.
1695 Positive means go to earlier frames (up); negative, the reverse.
1696 The int that contains the number of levels is counted toward
1697 zero as the frames for those levels are found.
1698 If the top or bottom frame is reached, that frame is returned,
1699 but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
1700 how much farther the original request asked to go. */
1703 find_relative_frame (frame, level_offset_ptr)
1704 register struct frame_info *frame;
1705 register int *level_offset_ptr;
1707 register struct frame_info *prev;
1708 register struct frame_info *frame1;
1710 /* Going up is simple: just do get_prev_frame enough times
1711 or until initial frame is reached. */
1712 while (*level_offset_ptr > 0)
1714 prev = get_prev_frame (frame);
1717 (*level_offset_ptr)--;
1720 /* Going down is just as simple. */
1721 if (*level_offset_ptr < 0)
1723 while (*level_offset_ptr < 0)
1725 frame1 = get_next_frame (frame);
1729 (*level_offset_ptr)++;
1735 /* The "select_frame" command. With no arg, NOP.
1736 With arg LEVEL_EXP, select the frame at level LEVEL if it is a
1737 valid level. Otherwise, treat level_exp as an address expression
1738 and select it. See parse_frame_specification for more info on proper
1739 frame expressions. */
1744 select_frame_command_wrapper (level_exp, from_tty)
1748 select_frame_command (level_exp, from_tty);
1752 select_frame_command (level_exp, from_tty)
1756 register struct frame_info *frame, *frame1;
1757 unsigned int level = 0;
1759 if (!target_has_stack)
1760 error ("No stack.");
1762 frame = parse_frame_specification (level_exp);
1764 /* Try to figure out what level this frame is. But if there is
1765 no current stack, don't error out -- let the user set one. */
1767 if (get_current_frame ())
1769 for (frame1 = get_prev_frame (0);
1770 frame1 && frame1 != frame;
1771 frame1 = get_prev_frame (frame1))
1778 select_frame (frame, level);
1781 /* The "frame" command. With no arg, print selected frame briefly.
1782 With arg, behaves like select_frame and then prints the selected
1786 frame_command (level_exp, from_tty)
1790 select_frame_command (level_exp, from_tty);
1791 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
1794 /* The XDB Compatibility command to print the current frame. */
1797 current_frame_command (level_exp, from_tty)
1801 if (target_has_stack == 0 || selected_frame == 0)
1802 error ("No stack.");
1803 print_only_stack_frame (selected_frame, selected_frame_level, 1);
1806 /* Select the frame up one or COUNT stack levels
1807 from the previously selected frame, and print it briefly. */
1811 up_silently_base (count_exp)
1814 register struct frame_info *fi;
1815 int count = 1, count1;
1817 count = parse_and_eval_address (count_exp);
1820 if (target_has_stack == 0 || selected_frame == 0)
1821 error ("No stack.");
1823 fi = find_relative_frame (selected_frame, &count1);
1824 if (count1 != 0 && count_exp == 0)
1825 error ("Initial frame selected; you cannot go up.");
1826 select_frame (fi, selected_frame_level + count - count1);
1830 up_silently_command (count_exp, from_tty)
1834 up_silently_base (count_exp);
1836 print_stack_frame (selected_frame, selected_frame_level, 1);
1840 up_command (count_exp, from_tty)
1844 up_silently_base (count_exp);
1845 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
1848 /* Select the frame down one or COUNT stack levels
1849 from the previously selected frame, and print it briefly. */
1853 down_silently_base (count_exp)
1856 register struct frame_info *frame;
1857 int count = -1, count1;
1859 count = -parse_and_eval_address (count_exp);
1862 if (target_has_stack == 0 || selected_frame == 0)
1863 error ("No stack.");
1865 frame = find_relative_frame (selected_frame, &count1);
1866 if (count1 != 0 && count_exp == 0)
1869 /* We only do this if count_exp is not specified. That way "down"
1870 means to really go down (and let me know if that is
1871 impossible), but "down 9999" can be used to mean go all the way
1872 down without getting an error. */
1874 error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
1877 select_frame (frame, selected_frame_level + count - count1);
1882 down_silently_command (count_exp, from_tty)
1886 down_silently_base (count_exp);
1888 print_stack_frame (selected_frame, selected_frame_level, 1);
1892 down_command (count_exp, from_tty)
1896 down_silently_base (count_exp);
1897 show_and_print_stack_frame (selected_frame, selected_frame_level, 1);
1902 return_command_wrapper (retval_exp, from_tty)
1906 return_command (retval_exp, from_tty);
1910 return_command (retval_exp, from_tty)
1914 struct symbol *thisfun;
1915 CORE_ADDR selected_frame_addr;
1916 CORE_ADDR selected_frame_pc;
1917 struct frame_info *frame;
1918 value_ptr return_value = NULL;
1920 if (selected_frame == NULL)
1921 error ("No selected frame.");
1922 thisfun = get_frame_function (selected_frame);
1923 selected_frame_addr = FRAME_FP (selected_frame);
1924 selected_frame_pc = selected_frame->pc;
1926 /* Compute the return value (if any -- possibly getting errors here). */
1930 struct type *return_type = NULL;
1932 return_value = parse_and_eval (retval_exp);
1934 /* Cast return value to the return type of the function. */
1935 if (thisfun != NULL)
1936 return_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (thisfun));
1937 if (return_type == NULL)
1938 return_type = builtin_type_int;
1939 return_value = value_cast (return_type, return_value);
1941 /* Make sure we have fully evaluated it, since
1942 it might live in the stack frame we're about to pop. */
1943 if (VALUE_LAZY (return_value))
1944 value_fetch_lazy (return_value);
1947 /* If interactive, require confirmation. */
1953 if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
1955 error ("Not confirmed.");
1959 else if (!query ("Make selected stack frame return now? "))
1960 error ("Not confirmed.");
1963 /* Do the real work. Pop until the specified frame is current. We
1964 use this method because the selected_frame is not valid after
1965 a POP_FRAME. The pc comparison makes this work even if the
1966 selected frame shares its fp with another frame. */
1968 while (selected_frame_addr != (frame = get_current_frame ())->frame
1969 || selected_frame_pc != frame->pc)
1972 /* Then pop that frame. */
1976 /* Compute the return value (if any) and store in the place
1977 for return values. */
1980 set_return_value (return_value);
1982 /* If interactive, print the frame that is now current. */
1985 frame_command ("0", 1);
1987 select_frame_command ("0", 0);
1990 /* Sets the scope to input function name, provided that the
1991 function is within the current stack frame */
1993 struct function_bounds
1995 CORE_ADDR low, high;
1998 static void func_command PARAMS ((char *arg, int from_tty));
2000 func_command (arg, from_tty)
2004 struct frame_info *fp;
2006 struct symtabs_and_lines sals;
2009 struct function_bounds *func_bounds = (struct function_bounds *) NULL;
2011 if (arg != (char *) NULL)
2014 fp = parse_frame_specification ("0");
2015 sals = decode_line_spec (arg, 1);
2016 func_bounds = (struct function_bounds *) xmalloc (
2017 sizeof (struct function_bounds) * sals.nelts);
2018 for (i = 0; (i < sals.nelts && !found); i++)
2020 if (sals.sals[i].pc == (CORE_ADDR) 0 ||
2021 find_pc_partial_function (sals.sals[i].pc,
2023 &func_bounds[i].low,
2024 &func_bounds[i].high) == 0)
2026 func_bounds[i].low =
2027 func_bounds[i].high = (CORE_ADDR) NULL;
2033 for (i = 0; (i < sals.nelts && !found); i++)
2034 found = (fp->pc >= func_bounds[i].low &&
2035 fp->pc < func_bounds[i].high);
2039 fp = find_relative_frame (fp, &level);
2042 while (!found && level == 0);
2048 printf_filtered ("'%s' not within current stack frame.\n", arg);
2049 else if (fp != selected_frame)
2050 select_and_print_frame (fp, level);
2053 /* Gets the language of the current frame. */
2056 get_frame_language ()
2058 register struct symtab *s;
2059 enum language flang; /* The language of the current frame */
2063 s = find_pc_symtab (selected_frame->pc);
2065 flang = s->language;
2067 flang = language_unknown;
2070 flang = language_unknown;
2076 _initialize_stack ()
2079 backtrace_limit = 30;
2082 add_com ("return", class_stack, return_command,
2083 "Make selected stack frame return to its caller.\n\
2084 Control remains in the debugger, but when you continue\n\
2085 execution will resume in the frame above the one now selected.\n\
2086 If an argument is given, it is an expression for the value to return.");
2088 add_com ("up", class_stack, up_command,
2089 "Select and print stack frame that called this one.\n\
2090 An argument says how many frames up to go.");
2091 add_com ("up-silently", class_support, up_silently_command,
2092 "Same as the `up' command, but does not print anything.\n\
2093 This is useful in command scripts.");
2095 add_com ("down", class_stack, down_command,
2096 "Select and print stack frame called by this one.\n\
2097 An argument says how many frames down to go.");
2098 add_com_alias ("do", "down", class_stack, 1);
2099 add_com_alias ("dow", "down", class_stack, 1);
2100 add_com ("down-silently", class_support, down_silently_command,
2101 "Same as the `down' command, but does not print anything.\n\
2102 This is useful in command scripts.");
2104 add_com ("frame", class_stack, frame_command,
2105 "Select and print a stack frame.\n\
2106 With no argument, print the selected stack frame. (See also \"info frame\").\n\
2107 An argument specifies the frame to select.\n\
2108 It can be a stack frame number or the address of the frame.\n\
2109 With argument, nothing is printed if input is coming from\n\
2110 a command file or a user-defined command.");
2112 add_com_alias ("f", "frame", class_stack, 1);
2116 add_com ("L", class_stack, current_frame_command,
2117 "Print the current stack frame.\n");
2118 add_com_alias ("V", "frame", class_stack, 1);
2120 add_com ("select-frame", class_stack, select_frame_command,
2121 "Select a stack frame without printing anything.\n\
2122 An argument specifies the frame to select.\n\
2123 It can be a stack frame number or the address of the frame.\n");
2125 add_com ("backtrace", class_stack, backtrace_command,
2126 "Print backtrace of all stack frames, or innermost COUNT frames.\n\
2127 With a negative argument, print outermost -COUNT frames.\n\
2128 Use of the 'full' qualifier also prints the values of the local variables.\n");
2129 add_com_alias ("bt", "backtrace", class_stack, 0);
2132 add_com_alias ("t", "backtrace", class_stack, 0);
2133 add_com ("T", class_stack, backtrace_full_command,
2134 "Print backtrace of all stack frames, or innermost COUNT frames \n\
2135 and the values of the local variables.\n\
2136 With a negative argument, print outermost -COUNT frames.\n\
2137 Usage: T <count>\n");
2140 add_com_alias ("where", "backtrace", class_alias, 0);
2141 add_info ("stack", backtrace_command,
2142 "Backtrace of the stack, or innermost COUNT frames.");
2143 add_info_alias ("s", "stack", 1);
2144 add_info ("frame", frame_info,
2145 "All about selected stack frame, or frame at ADDR.");
2146 add_info_alias ("f", "frame", 1);
2147 add_info ("locals", locals_info,
2148 "Local variables of current stack frame.");
2149 add_info ("args", args_info,
2150 "Argument variables of current stack frame.");
2152 add_com ("l", class_info, args_plus_locals_info,
2153 "Argument and local variables of current stack frame.");
2156 add_com ("func", class_stack, func_command,
2157 "Select the stack frame that contains <func>.\nUsage: func <name>\n");
2159 add_info ("catch", catch_info,
2160 "Exceptions that can be caught in the current stack frame.");
2163 add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command,
2164 "Specify maximum number of frames for \"backtrace\" to print by default.",
2166 add_info ("backtrace-limit", backtrace_limit_info,
2167 "The maximum number of frames for \"backtrace\" to print by default.");