home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-16  |  39.9 KB  |  1,483 lines

  1. /* Print and select stack frames for GDB, the GNU debugger.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  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.
  10.  
  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.
  15.  
  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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "value.h"
  22. #include "symtab.h"
  23. #include "gdbtypes.h"
  24. #include "expression.h"
  25. #include "language.h"
  26. #include "frame.h"
  27. #include "gdbcmd.h"
  28. #include "gdbcore.h"
  29. #include "target.h"
  30. #include "breakpoint.h"
  31. #include "demangle.h"
  32. #include "inferior.h"
  33. #include "annotate.h"
  34.  
  35. static void
  36. return_command PARAMS ((char *, int));
  37.  
  38. static void
  39. down_command PARAMS ((char *, int));
  40.  
  41. static void
  42. down_silently_command PARAMS ((char *, int));
  43.  
  44. static void
  45. up_command PARAMS ((char *, int));
  46.  
  47. static void
  48. up_silently_command PARAMS ((char *, int));
  49.  
  50. static void
  51. frame_command PARAMS ((char *, int));
  52.  
  53. static void
  54. select_frame_command PARAMS ((char *, int));
  55.  
  56. static void
  57. args_info PARAMS ((char *, int));
  58.  
  59. static void
  60. print_frame_arg_vars PARAMS ((FRAME, GDB_FILE *));
  61.  
  62. static void
  63. catch_info PARAMS ((char *, int));
  64.  
  65. static void
  66. locals_info PARAMS ((char *, int));
  67.  
  68. static void
  69. print_frame_label_vars PARAMS ((FRAME, int, GDB_FILE *));
  70.  
  71. static void
  72. print_frame_local_vars PARAMS ((FRAME, GDB_FILE *));
  73.  
  74. static int
  75. print_block_frame_labels PARAMS ((struct block *, int *, GDB_FILE *));
  76.  
  77. static int
  78. print_block_frame_locals PARAMS ((struct block *, FRAME, GDB_FILE *));
  79.  
  80. static void
  81. backtrace_command PARAMS ((char *, int));
  82.  
  83. static FRAME
  84. parse_frame_specification PARAMS ((char *));
  85.  
  86. static void
  87. frame_info PARAMS ((char *, int));
  88.  
  89.  
  90. extern int addressprint;    /* Print addresses, or stay symbolic only? */
  91. extern int info_verbose;    /* Verbosity of symbol reading msgs */
  92. extern int lines_to_list;    /* # of lines "list" command shows by default */
  93.  
  94. /* The "selected" stack frame is used by default for local and arg access.
  95.    May be zero, for no selected frame.  */
  96.  
  97. FRAME selected_frame;
  98.  
  99. /* Level of the selected frame:
  100.    0 for innermost, 1 for its caller, ...
  101.    or -1 for frame specified by address with no defined level.  */
  102.  
  103. int selected_frame_level;
  104.  
  105. /* Zero means do things normally; we are interacting directly with the
  106.    user.  One means print the full filename and linenumber when a
  107.    frame is printed, and do so in a format emacs18/emacs19.22 can
  108.    parse.  Two means print similar annotations, but in many more
  109.    cases and in a slightly different syntax.  */
  110.  
  111. int annotation_level = 0;
  112.  
  113.  
  114. struct print_stack_frame_args {
  115.   struct frame_info *fi;
  116.   int level;
  117.   int source;
  118.   int args;
  119. };
  120.  
  121. static int print_stack_frame_stub PARAMS ((char *));
  122.  
  123. /* Pass the args the way catch_errors wants them.  */
  124. static int
  125. print_stack_frame_stub (args)
  126.      char *args;
  127. {
  128.   struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
  129.   print_frame_info (p->fi, p->level, p->source, p->args);
  130.   return 0;
  131. }
  132.  
  133. /* Print a stack frame briefly.  FRAME should be the frame id
  134.    and LEVEL should be its level in the stack (or -1 for level not defined).
  135.    This prints the level, the function executing, the arguments,
  136.    and the file name and line number.
  137.    If the pc is not at the beginning of the source line,
  138.    the actual pc is printed at the beginning.
  139.  
  140.    If SOURCE is 1, print the source line as well.
  141.    If SOURCE is -1, print ONLY the source line.  */
  142.  
  143. void
  144. print_stack_frame (frame, level, source)
  145.      FRAME frame;
  146.      int level;
  147.      int source;
  148. {
  149.   struct print_stack_frame_args args;
  150.  
  151.   args.fi = get_frame_info (frame);
  152.   args.level = level;
  153.   args.source = source;
  154.   args.args = 1;
  155.  
  156.   catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ERROR);
  157. }
  158.  
  159. struct print_args_args {
  160.   struct symbol *func;
  161.   struct frame_info *fi;
  162. };
  163.  
  164. static int print_args_stub PARAMS ((char *));
  165.  
  166. /* Pass the args the way catch_errors wants them.  */
  167. static int
  168. print_args_stub (args)
  169.      char *args;
  170. {
  171.   int numargs;
  172.   struct print_args_args *p = (struct print_args_args *)args;
  173.   FRAME_NUM_ARGS (numargs, (p->fi));
  174.   print_frame_args (p->func, p->fi, numargs, gdb_stdout);
  175.   return 0;
  176. }
  177.  
  178. /* LEVEL is the level of the frame, or -1 if it is the innermost frame
  179.    but we don't want to print the level.  */
  180. void
  181. print_frame_info (fi, level, source, args)
  182.      struct frame_info *fi;
  183.      register int level;
  184.      int source;
  185.      int args;
  186. {
  187.   struct symtab_and_line sal;
  188.   struct symbol *func;
  189.   register char *funname = 0;
  190.   enum language funlang = language_unknown;
  191.  
  192. #if 0
  193.   char buf[MAX_REGISTER_RAW_SIZE];
  194.   CORE_ADDR sp;
  195.  
  196.   /* On the 68k, this spends too much time in m68k_find_saved_regs.  */
  197.  
  198.   /* Get the value of SP_REGNUM relative to the frame.  */
  199.   get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
  200.               FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
  201.   sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
  202.  
  203.   /* This is not a perfect test, because if a function alloca's some
  204.      memory, puts some code there, and then jumps into it, then the test
  205.      will succeed even though there is no call dummy.  Probably best is
  206.      to check for a bp_call_dummy breakpoint.  */
  207.   if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
  208. #else
  209.   if (frame_in_dummy (fi))
  210. #endif
  211.     {
  212.       annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
  213.  
  214.       /* Do this regardless of SOURCE because we don't have any source
  215.      to list for this frame.  */
  216.       if (level >= 0)
  217.     printf_filtered ("#%-2d ", level);
  218.       annotate_function_call ();
  219.       printf_filtered ("<function called from gdb>\n");
  220.       annotate_frame_end ();
  221.       return;
  222.     }
  223.   if (fi->signal_handler_caller)
  224.     {
  225.       annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
  226.  
  227.       /* Do this regardless of SOURCE because we don't have any source
  228.      to list for this frame.  */
  229.       if (level >= 0)
  230.     printf_filtered ("#%-2d ", level);
  231.       annotate_signal_handler_caller ();
  232.       printf_filtered ("<signal handler called>\n");
  233.       annotate_frame_end ();
  234.       return;
  235.     }
  236.  
  237.   /* If fi is not the innermost frame, that normally means that fi->pc
  238.      points to *after* the call instruction, and we want to get the line
  239.      containing the call, never the next line.  But if the next frame is
  240.      a signal_handler_caller or a dummy frame, then the next frame was
  241.      not entered as the result of a call, and we want to get the line
  242.      containing fi->pc.  */
  243.   sal =
  244.     find_pc_line (fi->pc,
  245.           fi->next != NULL
  246.           && !fi->next->signal_handler_caller
  247.           && !frame_in_dummy (fi->next));
  248.  
  249.   func = find_pc_function (fi->pc);
  250.   if (func)
  251.     {
  252.       /* In certain pathological cases, the symtabs give the wrong
  253.      function (when we are in the first function in a file which
  254.      is compiled without debugging symbols, the previous function
  255.      is compiled with debugging symbols, and the "foo.o" symbol
  256.      that is supposed to tell us where the file with debugging symbols
  257.      ends has been truncated by ar because it is longer than 15
  258.      characters).  This also occurs if the user uses asm() to create
  259.      a function but not stabs for it (in a file compiled -g).
  260.  
  261.      So look in the minimal symbol tables as well, and if it comes
  262.      up with a larger address for the function use that instead.
  263.      I don't think this can ever cause any problems; there shouldn't
  264.      be any minimal symbols in the middle of a function; if this is
  265.      ever changed many parts of GDB will need to be changed (and we'll
  266.      create a find_pc_minimal_function or some such).  */
  267.  
  268.       struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  269.       if (msymbol != NULL
  270.       && (SYMBOL_VALUE_ADDRESS (msymbol) 
  271.           > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
  272.     {
  273. #if 0
  274.       /* There is no particular reason to think the line number
  275.          information is wrong.  Someone might have just put in
  276.          a label with asm() but left the line numbers alone.  */
  277.       /* In this case we have no way of knowing the source file
  278.          and line number, so don't print them.  */
  279.       sal.symtab = 0;
  280. #endif
  281.       /* We also don't know anything about the function besides
  282.          its address and name.  */
  283.       func = 0;
  284.       funname = SYMBOL_NAME (msymbol);
  285.       funlang = SYMBOL_LANGUAGE (msymbol);
  286.     }
  287.       else
  288.     {
  289.       funname = SYMBOL_NAME (func);
  290.       funlang = SYMBOL_LANGUAGE (func);
  291.     }
  292.     }
  293.   else
  294.     {
  295.       register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  296.       if (msymbol != NULL)
  297.     {
  298.       funname = SYMBOL_NAME (msymbol);
  299.       funlang = SYMBOL_LANGUAGE (msymbol);
  300.     }
  301.     }
  302.  
  303.   if (source >= 0 || !sal.symtab)
  304.     {
  305.       annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
  306.  
  307.       if (level >= 0)
  308.     printf_filtered ("#%-2d ", level);
  309.       if (addressprint)
  310.     if (fi->pc != sal.pc || !sal.symtab)
  311.       {
  312.         annotate_frame_address ();
  313.         print_address_numeric (fi->pc, 1, gdb_stdout);
  314.         annotate_frame_address_end ();
  315.         printf_filtered (" in ");
  316.       }
  317.       annotate_frame_function_name ();
  318.       fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang,
  319.                    DMGL_ANSI);
  320.       wrap_here ("   ");
  321.       annotate_frame_args ();
  322.       fputs_filtered (" (", gdb_stdout);
  323.       if (args)
  324.     {
  325.       struct print_args_args args;
  326.       args.fi = fi;
  327.       args.func = func;
  328.       catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
  329.     }
  330.       printf_filtered (")");
  331.       if (sal.symtab && sal.symtab->filename)
  332.     {
  333.       annotate_frame_source_begin ();
  334.           wrap_here ("   ");
  335.       printf_filtered (" at ");
  336.       annotate_frame_source_file ();
  337.       printf_filtered ("%s", sal.symtab->filename);
  338.       annotate_frame_source_file_end ();
  339.       printf_filtered (":");
  340.       annotate_frame_source_line ();
  341.       printf_filtered ("%d", sal.line);
  342.       annotate_frame_source_end ();
  343.     }
  344.  
  345. #ifdef PC_LOAD_SEGMENT
  346.      /* If we couldn't print out function name but if can figure out what
  347.         load segment this pc value is from, at least print out some info
  348.     about its load segment. */
  349.       if (!funname)
  350.     {
  351.       annotate_frame_where ();
  352.       wrap_here ("  ");
  353.       printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
  354.     }
  355. #endif
  356.       printf_filtered ("\n");
  357.     }
  358.  
  359.   if ((source != 0) && sal.symtab)
  360.     {
  361.       int done = 0;
  362.       int mid_statement = source < 0 && fi->pc != sal.pc;
  363.       if (annotation_level)
  364.     done = identify_source_line (sal.symtab, sal.line, mid_statement,
  365.                      fi->pc);
  366.       if (!done)
  367.     {
  368.       if (addressprint && mid_statement)
  369.         {
  370.           print_address_numeric (fi->pc, 1, gdb_stdout);
  371.           printf_filtered ("\t");
  372.         }
  373.       print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
  374.     }
  375.       current_source_line = max (sal.line - lines_to_list/2, 1);
  376.     }
  377.   if (source != 0)
  378.     set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
  379.  
  380.   annotate_frame_end ();
  381.  
  382.   gdb_flush (gdb_stdout);
  383. }
  384.  
  385. /*
  386.  * Read a frame specification in whatever the appropriate format is.
  387.  * Call error() if the specification is in any way invalid (i.e.
  388.  * this function never returns NULL).
  389.  */
  390. static FRAME
  391. parse_frame_specification (frame_exp)
  392.      char *frame_exp;
  393. {
  394.   int numargs = 0;
  395. #define    MAXARGS    4
  396.   CORE_ADDR args[MAXARGS];
  397.   
  398.   if (frame_exp)
  399.     {
  400.       char *addr_string, *p;
  401.       struct cleanup *tmp_cleanup;
  402.  
  403.       while (*frame_exp == ' ') frame_exp++;
  404.  
  405.       while (*frame_exp)
  406.     {
  407.       if (numargs > MAXARGS)
  408.         error ("Too many args in frame specification");
  409.       /* Parse an argument.  */
  410.           for (p = frame_exp; *p && *p != ' '; p++)
  411.         ;
  412.       addr_string = savestring(frame_exp, p - frame_exp);
  413.  
  414.       {
  415.         tmp_cleanup = make_cleanup (free, addr_string);
  416.         args[numargs++] = parse_and_eval_address (addr_string);
  417.         do_cleanups (tmp_cleanup);
  418.       }
  419.  
  420.       /* Skip spaces, move to possible next arg.  */
  421.       while (*p == ' ') p++;
  422.       frame_exp = p;
  423.     }
  424.     }
  425.  
  426.   switch (numargs)
  427.     {
  428.     case 0:
  429.       if (selected_frame == NULL)
  430.     error ("No selected frame.");
  431.       return selected_frame;
  432.       /* NOTREACHED */
  433.     case 1:
  434.       {
  435.     int level = args[0];
  436.     FRAME fid = find_relative_frame (get_current_frame (), &level);
  437.     FRAME tfid;
  438.  
  439.     if (level == 0)
  440.       /* find_relative_frame was successful */
  441.       return fid;
  442.  
  443.     /* If SETUP_ARBITRARY_FRAME is defined, then frame specifications
  444.        take at least 2 addresses.  It is important to detect this case
  445.        here so that "frame 100" does not give a confusing error message
  446.        like "frame specification requires two addresses".  This of course
  447.        does not solve the "frame 100" problem for machines on which
  448.        a frame specification can be made with one address.  To solve
  449.        that, we need a new syntax for a specifying a frame by address.
  450.        I think the cleanest syntax is $frame(0x45) ($frame(0x23,0x45) for
  451.        two args, etc.), but people might think that is too much typing,
  452.        so I guess *0x23,0x45 would be a possible alternative (commas
  453.        really should be used instead of spaces to delimit; using spaces
  454.        normally works in an expression).  */
  455. #ifdef SETUP_ARBITRARY_FRAME
  456.     error ("No frame %d", args[0]);
  457. #endif
  458.  
  459.     /* If (s)he specifies the frame with an address, he deserves what
  460.        (s)he gets.  Still, give the highest one that matches.  */
  461.  
  462.     for (fid = get_current_frame ();
  463.          fid && FRAME_FP (fid) != args[0];
  464.          fid = get_prev_frame (fid))
  465.       ;
  466.  
  467.     if (fid)
  468.       while ((tfid = get_prev_frame (fid)) &&
  469.          (FRAME_FP (tfid) == args[0]))
  470.         fid = tfid;
  471.       
  472.     /* We couldn't identify the frame as an existing frame, but
  473.        perhaps we can create one with a single argument.  */
  474.       }
  475.  
  476.      default:
  477. #ifdef SETUP_ARBITRARY_FRAME
  478.       return SETUP_ARBITRARY_FRAME (numargs, args);
  479. #else
  480.       /* Usual case.  Do it here rather than have everyone supply
  481.      a SETUP_ARBITRARY_FRAME that does this.  */
  482.       if (numargs == 1)
  483.     return create_new_frame (args[0], 0);
  484.       error ("Too many args in frame specification");
  485. #endif
  486.       /* NOTREACHED */
  487.     }
  488.   /* NOTREACHED */
  489. }
  490.  
  491. /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
  492.    that if it is unsure about the answer, it returns 0
  493.    instead of guessing (this happens on the VAX and i960, for example).
  494.  
  495.    On most machines, we never have to guess about the args address,
  496.    so FRAME_ARGS_ADDRESS{,_CORRECT} are the same.  */
  497. #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
  498. #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
  499. #endif
  500.  
  501. /* Print verbosely the selected frame or the frame at address ADDR.
  502.    This means absolutely all information in the frame is printed.  */
  503.  
  504. static void
  505. frame_info (addr_exp, from_tty)
  506.      char *addr_exp;
  507.      int from_tty;
  508. {
  509.   FRAME frame;
  510.   struct frame_info *fi;
  511.   struct frame_saved_regs fsr;
  512.   struct symtab_and_line sal;
  513.   struct symbol *func;
  514.   struct symtab *s;
  515.   FRAME calling_frame;
  516.   int i, count, numregs;
  517.   char *funname = 0;
  518.   enum language funlang = language_unknown;
  519.  
  520.   if (!target_has_stack)
  521.     error ("No stack.");
  522.  
  523.   frame = parse_frame_specification (addr_exp);
  524.   if (!frame)
  525.     error ("Invalid frame specified.");
  526.  
  527.   fi = get_frame_info (frame);
  528.   sal = find_pc_line (fi->pc,
  529.               fi->next != NULL
  530.               && !fi->next->signal_handler_caller
  531.               && !frame_in_dummy (fi->next));
  532.   func = get_frame_function (frame);
  533.   s = find_pc_symtab(fi->pc);
  534.   if (func)
  535.     {
  536.       funname = SYMBOL_NAME (func);
  537.       funlang = SYMBOL_LANGUAGE (func);
  538.     }
  539.   else
  540.     {
  541.       register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  542.       if (msymbol != NULL)
  543.     {
  544.       funname = SYMBOL_NAME (msymbol);
  545.       funlang = SYMBOL_LANGUAGE (msymbol);
  546.     }
  547.     }
  548.   calling_frame = get_prev_frame (frame);
  549.  
  550.   if (!addr_exp && selected_frame_level >= 0)
  551.     {
  552.       printf_filtered ("Stack level %d, frame at ", selected_frame_level);
  553.       print_address_numeric (FRAME_FP(frame), 1, gdb_stdout);
  554.       printf_filtered (":\n");
  555.     }
  556.   else
  557.     {
  558.       printf_filtered ("Stack frame at ");
  559.       print_address_numeric (FRAME_FP(frame), 1, gdb_stdout);
  560.       printf_filtered (":\n");
  561.     }
  562.   printf_filtered (" %s = ",
  563.            reg_names[PC_REGNUM]);
  564.   print_address_numeric (fi->pc, 1, gdb_stdout);
  565.  
  566.   wrap_here ("   ");
  567.   if (funname)
  568.     {
  569.       printf_filtered (" in ");
  570.       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
  571.                    DMGL_ANSI | DMGL_PARAMS);
  572.     }
  573.   wrap_here ("   ");
  574.   if (sal.symtab)
  575.     printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
  576.   puts_filtered ("; ");
  577.   wrap_here ("    ");
  578.   printf_filtered ("saved %s ", reg_names[PC_REGNUM]);
  579.   print_address_numeric (FRAME_SAVED_PC (frame), 1, gdb_stdout);
  580.   printf_filtered ("\n");
  581.  
  582.   {
  583.     int frameless = 0;
  584. #ifdef FRAMELESS_FUNCTION_INVOCATION
  585.     FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
  586. #endif
  587.     if (frameless)
  588.       printf_filtered (" (FRAMELESS),");
  589.   }
  590.  
  591.   if (calling_frame)
  592.     {
  593.       printf_filtered (" called by frame at ");
  594.       print_address_numeric (FRAME_FP (calling_frame), 1, gdb_stdout);
  595.     }
  596.   if (fi->next && calling_frame)
  597.     puts_filtered (",");
  598.   wrap_here ("   ");
  599.   if (fi->next)
  600.     {
  601.       printf_filtered (" caller of frame at ");
  602.       print_address_numeric (fi->next->frame, 1, gdb_stdout);
  603.     }
  604.   if (fi->next || calling_frame)
  605.     puts_filtered ("\n");
  606.   if (s)
  607.     printf_filtered (" source language %s.\n", language_str (s->language));
  608.  
  609. #ifdef PRINT_EXTRA_FRAME_INFO
  610.   PRINT_EXTRA_FRAME_INFO (fi);
  611. #endif
  612.  
  613.   {
  614.     /* Address of the argument list for this frame, or 0.  */
  615.     CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
  616.     /* Number of args for this frame, or -1 if unknown.  */
  617.     int numargs;
  618.  
  619.     if (arg_list == 0)
  620.       printf_filtered (" Arglist at unknown address.\n");
  621.     else
  622.       {
  623.     printf_filtered (" Arglist at ");
  624.     print_address_numeric (arg_list, 1, gdb_stdout);
  625.     printf_filtered (",");
  626.  
  627.     FRAME_NUM_ARGS (numargs, fi);
  628.     if (numargs < 0)
  629.       puts_filtered (" args: ");
  630.     else if (numargs == 0)
  631.       puts_filtered (" no args.");
  632.     else if (numargs == 1)
  633.       puts_filtered (" 1 arg: ");
  634.     else
  635.       printf_filtered (" %d args: ", numargs);
  636.     print_frame_args (func, fi, numargs, gdb_stdout);
  637.     puts_filtered ("\n");
  638.       }
  639.   }
  640.   {
  641.     /* Address of the local variables for this frame, or 0.  */
  642.     CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
  643.  
  644.     if (arg_list == 0)
  645.       printf_filtered (" Locals at unknown address,");
  646.     else
  647.       {
  648.     printf_filtered (" Locals at ");
  649.     print_address_numeric (arg_list, 1, gdb_stdout);
  650.     printf_filtered (",");
  651.       }
  652.   }
  653.  
  654. #if defined (FRAME_FIND_SAVED_REGS)  
  655.   get_frame_saved_regs (fi, &fsr);
  656.   /* The sp is special; what's returned isn't the save address, but
  657.      actually the value of the previous frame's sp.  */
  658.   printf_filtered (" Previous frame's sp is ");
  659.   print_address_numeric (fsr.regs[SP_REGNUM], 1, gdb_stdout);
  660.   printf_filtered ("\n");
  661.   count = 0;
  662.   numregs = ARCH_NUM_REGS;
  663.   for (i = 0; i < numregs; i++)
  664.     if (fsr.regs[i] && i != SP_REGNUM)
  665.       {
  666.     if (count == 0)
  667.       puts_filtered (" Saved registers:\n ");
  668.     else
  669.       puts_filtered (",");
  670.     wrap_here (" ");
  671.     printf_filtered (" %s at ", reg_names[i]);
  672.     print_address_numeric (fsr.regs[i], 1, gdb_stdout);
  673.     count++;
  674.       }
  675.   if (count)
  676.     puts_filtered ("\n");
  677. #else  /* Have FRAME_FIND_SAVED_REGS.  */
  678.   puts_filtered ("\n");
  679. #endif /* Have FRAME_FIND_SAVED_REGS.  */
  680. }
  681.  
  682. #if 0
  683. /* Set a limit on the number of frames printed by default in a
  684.    backtrace.  */
  685.  
  686. static int backtrace_limit;
  687.  
  688. static void
  689. set_backtrace_limit_command (count_exp, from_tty)
  690.      char *count_exp;
  691.      int from_tty;
  692. {
  693.   int count = parse_and_eval_address (count_exp);
  694.  
  695.   if (count < 0)
  696.     error ("Negative argument not meaningful as backtrace limit.");
  697.  
  698.   backtrace_limit = count;
  699. }
  700.  
  701. static void
  702. backtrace_limit_info (arg, from_tty)
  703.      char *arg;
  704.      int from_tty;
  705. {
  706.   if (arg)
  707.     error ("\"Info backtrace-limit\" takes no arguments.");
  708.  
  709.   printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
  710. }
  711. #endif
  712.  
  713. /* Print briefly all stack frames or just the innermost COUNT frames.  */
  714.  
  715. static void
  716. backtrace_command (count_exp, from_tty)
  717.      char *count_exp;
  718.      int from_tty;
  719. {
  720.   struct frame_info *fi;
  721.   register int count;
  722.   register FRAME frame;
  723.   register int i;
  724.   register FRAME trailing;
  725.   register int trailing_level;
  726.  
  727.   if (!target_has_stack)
  728.     error ("No stack.");
  729.  
  730.   /* The following code must do two things.  First, it must
  731.      set the variable TRAILING to the frame from which we should start
  732.      printing.  Second, it must set the variable count to the number
  733.      of frames which we should print, or -1 if all of them.  */
  734.   trailing = get_current_frame ();
  735.   trailing_level = 0;
  736.   if (count_exp)
  737.     {
  738.       count = parse_and_eval_address (count_exp);
  739.       if (count < 0)
  740.     {
  741.       FRAME current;
  742.  
  743.       count = -count;
  744.  
  745.       current = trailing;
  746.       while (current && count--)
  747.         {
  748.           QUIT;
  749.           current = get_prev_frame (current);
  750.         }
  751.       
  752.       /* Will stop when CURRENT reaches the top of the stack.  TRAILING
  753.          will be COUNT below it.  */
  754.       while (current)
  755.         {
  756.           QUIT;
  757.           trailing = get_prev_frame (trailing);
  758.           current = get_prev_frame (current);
  759.           trailing_level++;
  760.         }
  761.       
  762.       count = -1;
  763.     }
  764.     }
  765.   else
  766.     count = -1;
  767.  
  768.   if (info_verbose)
  769.     {
  770.       struct partial_symtab *ps;
  771.       
  772.       /* Read in symbols for all of the frames.  Need to do this in
  773.      a separate pass so that "Reading in symbols for xxx" messages
  774.      don't screw up the appearance of the backtrace.  Also
  775.      if people have strong opinions against reading symbols for
  776.      backtrace this may have to be an option.  */
  777.       i = count;
  778.       for (frame = trailing;
  779.        frame != NULL && i--;
  780.        frame = get_prev_frame (frame))
  781.     {
  782.       QUIT;
  783.       fi = get_frame_info (frame);
  784.       ps = find_pc_psymtab (fi->pc);
  785.       if (ps)
  786.         PSYMTAB_TO_SYMTAB (ps);    /* Force syms to come in */
  787.     }
  788.     }
  789.  
  790.   for (i = 0, frame = trailing;
  791.        frame && count--;
  792.        i++, frame = get_prev_frame (frame))
  793.     {
  794.       QUIT;
  795.       fi = get_frame_info (frame);
  796.  
  797.       /* Don't use print_stack_frame; if an error() occurs it probably
  798.      means further attempts to backtrace would fail (on the other
  799.      hand, perhaps the code does or could be fixed to make sure
  800.      the frame->prev field gets set to NULL in that case).  */
  801.       print_frame_info (fi, trailing_level + i, 0, 1);
  802.     }
  803.  
  804.   /* If we've stopped before the end, mention that.  */
  805.   if (frame && from_tty)
  806.     printf_filtered ("(More stack frames follow...)\n");
  807. }
  808.  
  809. /* Print the local variables of a block B active in FRAME.
  810.    Return 1 if any variables were printed; 0 otherwise.  */
  811.  
  812. static int
  813. print_block_frame_locals (b, frame, stream)
  814.      struct block *b;
  815.      register FRAME frame;
  816.      register GDB_FILE *stream;
  817. {
  818.   int nsyms;
  819.   register int i;
  820.   register struct symbol *sym;
  821.   register int values_printed = 0;
  822.  
  823.   nsyms = BLOCK_NSYMS (b);
  824.  
  825.   for (i = 0; i < nsyms; i++)
  826.     {
  827.       sym = BLOCK_SYM (b, i);
  828.       switch (SYMBOL_CLASS (sym))
  829.     {
  830.     case LOC_LOCAL:
  831.     case LOC_REGISTER:
  832.     case LOC_STATIC:
  833.     case LOC_BASEREG:
  834.       values_printed = 1;
  835.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  836.       fputs_filtered (" = ", stream);
  837.       print_variable_value (sym, frame, stream);
  838.       fprintf_filtered (stream, "\n");
  839.       break;
  840.  
  841.     default:
  842.       /* Ignore symbols which are not locals.  */
  843.       break;
  844.     }
  845.     }
  846.   return values_printed;
  847. }
  848.  
  849. /* Same, but print labels.  */
  850.  
  851. static int
  852. print_block_frame_labels (b, have_default, stream)
  853.      struct block *b;
  854.      int *have_default;
  855.      register GDB_FILE *stream;
  856. {
  857.   int nsyms;
  858.   register int i;
  859.   register struct symbol *sym;
  860.   register int values_printed = 0;
  861.  
  862.   nsyms = BLOCK_NSYMS (b);
  863.  
  864.   for (i = 0; i < nsyms; i++)
  865.     {
  866.       sym = BLOCK_SYM (b, i);
  867.       if (STREQ (SYMBOL_NAME (sym), "default"))
  868.     {
  869.       if (*have_default)
  870.         continue;
  871.       *have_default = 1;
  872.     }
  873.       if (SYMBOL_CLASS (sym) == LOC_LABEL)
  874.     {
  875.       struct symtab_and_line sal;
  876.       sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  877.       values_printed = 1;
  878.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  879.       if (addressprint)
  880.         {
  881.           fprintf_filtered (stream, " ");
  882.           print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, stream);
  883.         }
  884.       fprintf_filtered (stream, " in file %s, line %d\n",
  885.                 sal.symtab->filename, sal.line);
  886.     }
  887.     }
  888.   return values_printed;
  889. }
  890.  
  891. /* Print on STREAM all the local variables in frame FRAME,
  892.    including all the blocks active in that frame
  893.    at its current pc.
  894.  
  895.    Returns 1 if the job was done,
  896.    or 0 if nothing was printed because we have no info
  897.    on the function running in FRAME.  */
  898.  
  899. static void
  900. print_frame_local_vars (frame, stream)
  901.      register FRAME frame;
  902.      register GDB_FILE *stream;
  903. {
  904.   register struct block *block = get_frame_block (frame);
  905.   register int values_printed = 0;
  906.  
  907.   if (block == 0)
  908.     {
  909.       fprintf_filtered (stream, "No symbol table info available.\n");
  910.       return;
  911.     }
  912.   
  913.   while (block != 0)
  914.     {
  915.       if (print_block_frame_locals (block, frame, stream))
  916.     values_printed = 1;
  917.       /* After handling the function's top-level block, stop.
  918.      Don't continue to its superblock, the block of
  919.      per-file symbols.  */
  920.       if (BLOCK_FUNCTION (block))
  921.     break;
  922.       block = BLOCK_SUPERBLOCK (block);
  923.     }
  924.  
  925.   if (!values_printed)
  926.     {
  927.       fprintf_filtered (stream, "No locals.\n");
  928.     }
  929. }
  930.  
  931. /* Same, but print labels.  */
  932.  
  933. static void
  934. print_frame_label_vars (frame, this_level_only, stream)
  935.      register FRAME frame;
  936.      int this_level_only;
  937.      register GDB_FILE *stream;
  938. {
  939.   register struct blockvector *bl;
  940.   register struct block *block = get_frame_block (frame);
  941.   register int values_printed = 0;
  942.   int index, have_default = 0;
  943.   char *blocks_printed;
  944.   struct frame_info *fi = get_frame_info (frame);
  945.   CORE_ADDR pc = fi->pc;
  946.  
  947.   if (block == 0)
  948.     {
  949.       fprintf_filtered (stream, "No symbol table info available.\n");
  950.       return;
  951.     }
  952.  
  953.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  954.   blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  955.   memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  956.  
  957.   while (block != 0)
  958.     {
  959.       CORE_ADDR end = BLOCK_END (block) - 4;
  960.       int last_index;
  961.  
  962.       if (bl != blockvector_for_pc (end, &index))
  963.     error ("blockvector blotch");
  964.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  965.     error ("blockvector botch");
  966.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  967.       index += 1;
  968.  
  969.       /* Don't print out blocks that have gone by.  */
  970.       while (index < last_index
  971.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  972.     index++;
  973.  
  974.       while (index < last_index
  975.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  976.     {
  977.       if (blocks_printed[index] == 0)
  978.         {
  979.           if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
  980.         values_printed = 1;
  981.           blocks_printed[index] = 1;
  982.         }
  983.       index++;
  984.     }
  985.       if (have_default)
  986.     return;
  987.       if (values_printed && this_level_only)
  988.     return;
  989.  
  990.       /* After handling the function's top-level block, stop.
  991.      Don't continue to its superblock, the block of
  992.      per-file symbols.  */
  993.       if (BLOCK_FUNCTION (block))
  994.     break;
  995.       block = BLOCK_SUPERBLOCK (block);
  996.     }
  997.  
  998.   if (!values_printed && !this_level_only)
  999.     {
  1000.       fprintf_filtered (stream, "No catches.\n");
  1001.     }
  1002. }
  1003.  
  1004. /* ARGSUSED */
  1005. static void
  1006. locals_info (args, from_tty)
  1007.      char *args;
  1008.      int from_tty;
  1009. {
  1010.   if (!selected_frame)
  1011.     error ("No frame selected.");
  1012.   print_frame_local_vars (selected_frame, gdb_stdout);
  1013. }
  1014.  
  1015. static void
  1016. catch_info (ignore, from_tty)
  1017.      char *ignore;
  1018.      int from_tty;
  1019. {
  1020.   if (!selected_frame)
  1021.     error ("No frame selected.");
  1022.   print_frame_label_vars (selected_frame, 0, gdb_stdout);
  1023. }
  1024.  
  1025. static void
  1026. print_frame_arg_vars (frame, stream)
  1027.      register FRAME frame;
  1028.      register GDB_FILE *stream;
  1029. {
  1030.   struct symbol *func = get_frame_function (frame);
  1031.   register struct block *b;
  1032.   int nsyms;
  1033.   register int i;
  1034.   register struct symbol *sym, *sym2;
  1035.   register int values_printed = 0;
  1036.  
  1037.   if (func == 0)
  1038.     {
  1039.       fprintf_filtered (stream, "No symbol table info available.\n");
  1040.       return;
  1041.     }
  1042.  
  1043.   b = SYMBOL_BLOCK_VALUE (func);
  1044.   nsyms = BLOCK_NSYMS (b);
  1045.  
  1046.   for (i = 0; i < nsyms; i++)
  1047.     {
  1048.       sym = BLOCK_SYM (b, i);
  1049.       switch (SYMBOL_CLASS (sym))
  1050.     {
  1051.     case LOC_ARG:
  1052.     case LOC_LOCAL_ARG:
  1053.     case LOC_REF_ARG:
  1054.     case LOC_REGPARM:
  1055.     case LOC_REGPARM_ADDR:
  1056.     case LOC_BASEREG_ARG:
  1057.       values_printed = 1;
  1058.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  1059.       fputs_filtered (" = ", stream);
  1060.  
  1061.       /* We have to look up the symbol because arguments can have
  1062.          two entries (one a parameter, one a local) and the one we
  1063.          want is the local, which lookup_symbol will find for us.
  1064.          This includes gcc1 (not gcc2) on the sparc when passing a
  1065.          small structure and gcc2 when the argument type is float
  1066.          and it is passed as a double and converted to float by
  1067.          the prologue (in the latter case the type of the LOC_ARG
  1068.          symbol is double and the type of the LOC_LOCAL symbol is
  1069.          float).  There are also LOC_ARG/LOC_REGISTER pairs which
  1070.          are not combined in symbol-reading.  */
  1071.  
  1072.       sym2 = lookup_symbol (SYMBOL_NAME (sym),
  1073.             b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
  1074.       print_variable_value (sym2, frame, stream);
  1075.       fprintf_filtered (stream, "\n");
  1076.       break;
  1077.  
  1078.     default:
  1079.       /* Don't worry about things which aren't arguments.  */
  1080.       break;
  1081.     }
  1082.     }
  1083.  
  1084.   if (!values_printed)
  1085.     {
  1086.       fprintf_filtered (stream, "No arguments.\n");
  1087.     }
  1088. }
  1089.  
  1090. static void
  1091. args_info (ignore, from_tty)
  1092.      char *ignore;
  1093.      int from_tty;
  1094. {
  1095.   if (!selected_frame)
  1096.     error ("No frame selected.");
  1097.   print_frame_arg_vars (selected_frame, gdb_stdout);
  1098. }
  1099.  
  1100. /* Select frame FRAME, and note that its stack level is LEVEL.
  1101.    LEVEL may be -1 if an actual level number is not known.  */
  1102.  
  1103. void
  1104. select_frame (frame, level)
  1105.      FRAME frame;
  1106.      int level;
  1107. {
  1108.   register struct symtab *s;
  1109.  
  1110.   selected_frame = frame;
  1111.   selected_frame_level = level;
  1112.  
  1113.   /* Ensure that symbols for this frame are read in.  Also, determine the
  1114.      source language of this frame, and switch to it if desired.  */
  1115.   if (frame)
  1116.   {
  1117.     s = find_pc_symtab (get_frame_info (frame)->pc);
  1118.     if (s 
  1119.     && s->language != current_language->la_language
  1120.     && s->language != language_unknown
  1121.     && language_mode == language_mode_auto) {
  1122.       set_language(s->language);
  1123.     }
  1124.   }
  1125. }
  1126.  
  1127. /* Store the selected frame and its level into *FRAMEP and *LEVELP.
  1128.    If there is no selected frame, *FRAMEP is set to NULL.  */
  1129.  
  1130. void
  1131. record_selected_frame (frameaddrp, levelp)
  1132.      FRAME_ADDR *frameaddrp;
  1133.      int *levelp;
  1134. {
  1135.   *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
  1136.   *levelp = selected_frame_level;
  1137. }
  1138.  
  1139. /* Return the symbol-block in which the selected frame is executing.
  1140.    Can return zero under various legitimate circumstances.  */
  1141.  
  1142. struct block *
  1143. get_selected_block ()
  1144. {
  1145.   if (!target_has_stack)
  1146.     return 0;
  1147.  
  1148.   if (!selected_frame)
  1149.     return get_current_block ();
  1150.   return get_frame_block (selected_frame);
  1151. }
  1152.  
  1153. /* Find a frame a certain number of levels away from FRAME.
  1154.    LEVEL_OFFSET_PTR points to an int containing the number of levels.
  1155.    Positive means go to earlier frames (up); negative, the reverse.
  1156.    The int that contains the number of levels is counted toward
  1157.    zero as the frames for those levels are found.
  1158.    If the top or bottom frame is reached, that frame is returned,
  1159.    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
  1160.    how much farther the original request asked to go.  */
  1161.  
  1162. FRAME
  1163. find_relative_frame (frame, level_offset_ptr)
  1164.      register FRAME frame;
  1165.      register int* level_offset_ptr;
  1166. {
  1167.   register FRAME prev;
  1168.   register FRAME frame1;
  1169.  
  1170.   /* Going up is simple: just do get_prev_frame enough times
  1171.      or until initial frame is reached.  */
  1172.   while (*level_offset_ptr > 0)
  1173.     {
  1174.       prev = get_prev_frame (frame);
  1175.       if (prev == 0)
  1176.     break;
  1177.       (*level_offset_ptr)--;
  1178.       frame = prev;
  1179.     }
  1180.   /* Going down is just as simple.  */
  1181.   if (*level_offset_ptr < 0)
  1182.     {
  1183.       while (*level_offset_ptr < 0) {
  1184.     frame1 = get_next_frame (frame);
  1185.     if (!frame1)
  1186.       break;
  1187.     frame = frame1;
  1188.     (*level_offset_ptr)++;
  1189.       }
  1190.     }
  1191.   return frame;
  1192. }
  1193.  
  1194. /* The "select_frame" command.  With no arg, NOP.
  1195.    With arg LEVEL_EXP, select the frame at level LEVEL if it is a
  1196.    valid level.  Otherwise, treat level_exp as an address expression
  1197.    and select it.  See parse_frame_specification for more info on proper
  1198.    frame expressions. */
  1199.  
  1200. /* ARGSUSED */
  1201. static void
  1202. select_frame_command (level_exp, from_tty)
  1203.      char *level_exp;
  1204.      int from_tty;
  1205. {
  1206.   register FRAME frame, frame1;
  1207.   unsigned int level = 0;
  1208.  
  1209.   if (!target_has_stack)
  1210.     error ("No stack.");
  1211.  
  1212.   frame = parse_frame_specification (level_exp);
  1213.  
  1214.   /* Try to figure out what level this frame is.  But if there is
  1215.      no current stack, don't error out -- let the user set one.  */
  1216.   frame1 = 0;
  1217.   if (get_current_frame()) {
  1218.     for (frame1 = get_prev_frame (0);
  1219.      frame1 && frame1 != frame;
  1220.      frame1 = get_prev_frame (frame1))
  1221.       level++;
  1222.   }
  1223.  
  1224.   if (!frame1)
  1225.     level = 0;
  1226.  
  1227.   select_frame (frame, level);
  1228. }
  1229.  
  1230. /* The "frame" command.  With no arg, print selected frame briefly.
  1231.    With arg, behaves like select_frame and then prints the selected
  1232.    frame.  */
  1233.  
  1234. static void
  1235. frame_command (level_exp, from_tty)
  1236.      char *level_exp;
  1237.      int from_tty;
  1238. {
  1239.   select_frame_command (level_exp, from_tty);
  1240.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1241. }
  1242.  
  1243. /* Select the frame up one or COUNT stack levels
  1244.    from the previously selected frame, and print it briefly.  */
  1245.  
  1246. /* ARGSUSED */
  1247. static void
  1248. up_silently_command (count_exp, from_tty)
  1249.      char *count_exp;
  1250.      int from_tty;
  1251. {
  1252.   register FRAME frame;
  1253.   int count = 1, count1;
  1254.   if (count_exp)
  1255.     count = parse_and_eval_address (count_exp);
  1256.   count1 = count;
  1257.   
  1258.   if (target_has_stack == 0 || selected_frame == 0)
  1259.     error ("No stack.");
  1260.  
  1261.   frame = find_relative_frame (selected_frame, &count1);
  1262.   if (count1 != 0 && count_exp == 0)
  1263.     error ("Initial frame selected; you cannot go up.");
  1264.   select_frame (frame, selected_frame_level + count - count1);
  1265. }
  1266.  
  1267. static void
  1268. up_command (count_exp, from_tty)
  1269.      char *count_exp;
  1270.      int from_tty;
  1271. {
  1272.   up_silently_command (count_exp, from_tty);
  1273.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1274. }
  1275.  
  1276. /* Select the frame down one or COUNT stack levels
  1277.    from the previously selected frame, and print it briefly.  */
  1278.  
  1279. /* ARGSUSED */
  1280. static void
  1281. down_silently_command (count_exp, from_tty)
  1282.      char *count_exp;
  1283.      int from_tty;
  1284. {
  1285.   register FRAME frame;
  1286.   int count = -1, count1;
  1287.   if (count_exp)
  1288.     count = - parse_and_eval_address (count_exp);
  1289.   count1 = count;
  1290.   
  1291.   if (target_has_stack == 0 || selected_frame == 0)
  1292.     error ("No stack.");
  1293.  
  1294.   frame = find_relative_frame (selected_frame, &count1);
  1295.   if (count1 != 0 && count_exp == 0)
  1296.     {
  1297.  
  1298.       /* We only do this if count_exp is not specified.  That way "down"
  1299.      means to really go down (and let me know if that is
  1300.      impossible), but "down 9999" can be used to mean go all the way
  1301.      down without getting an error.  */
  1302.  
  1303.       error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
  1304.     }
  1305.  
  1306.   select_frame (frame, selected_frame_level + count - count1);
  1307. }
  1308.  
  1309.  
  1310. static void
  1311. down_command (count_exp, from_tty)
  1312.      char *count_exp;
  1313.      int from_tty;
  1314. {
  1315.   down_silently_command (count_exp, from_tty);
  1316.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1317. }
  1318.  
  1319. static void
  1320. return_command (retval_exp, from_tty)
  1321.      char *retval_exp;
  1322.      int from_tty;
  1323. {
  1324.   struct symbol *thisfun;
  1325.   FRAME_ADDR selected_frame_addr;
  1326.   CORE_ADDR selected_frame_pc;
  1327.   FRAME frame;
  1328.   value_ptr return_value = NULL;
  1329.  
  1330.   if (selected_frame == NULL)
  1331.     error ("No selected frame.");
  1332.   thisfun = get_frame_function (selected_frame);
  1333.   selected_frame_addr = FRAME_FP (selected_frame);
  1334.   selected_frame_pc = (get_frame_info (selected_frame))->pc;
  1335.  
  1336.   /* Compute the return value (if any -- possibly getting errors here).  */
  1337.  
  1338.   if (retval_exp)
  1339.     {
  1340.       return_value = parse_and_eval (retval_exp);
  1341.  
  1342.       /* Make sure we have fully evaluated it, since
  1343.      it might live in the stack frame we're about to pop.  */
  1344.       if (VALUE_LAZY (return_value))
  1345.     value_fetch_lazy (return_value);
  1346.     }
  1347.  
  1348.   /* If interactive, require confirmation.  */
  1349.  
  1350.   if (from_tty)
  1351.     {
  1352.       if (thisfun != 0)
  1353.     {
  1354.       if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
  1355.         {
  1356.           error ("Not confirmed.");
  1357.           /* NOTREACHED */
  1358.         }
  1359.     }
  1360.       else
  1361.     if (!query ("Make selected stack frame return now? "))
  1362.       error ("Not confirmed.");
  1363.     }
  1364.  
  1365.   /* Do the real work.  Pop until the specified frame is current.  We
  1366.      use this method because the selected_frame is not valid after
  1367.      a POP_FRAME.  The pc comparison makes this work even if the
  1368.      selected frame shares its fp with another frame.  */
  1369.  
  1370.   while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
  1371.        || selected_frame_pc   != (get_frame_info (frame))->pc  )
  1372.     POP_FRAME;
  1373.  
  1374.   /* Then pop that frame.  */
  1375.  
  1376.   POP_FRAME;
  1377.  
  1378.   /* Compute the return value (if any) and store in the place
  1379.      for return values.  */
  1380.  
  1381.   if (retval_exp)
  1382.     set_return_value (return_value);
  1383.  
  1384.   /* If interactive, print the frame that is now current.  */
  1385.  
  1386.   if (from_tty)
  1387.     frame_command ("0", 1);
  1388. }
  1389.  
  1390. /* Gets the language of the current frame. */
  1391. enum language
  1392. get_frame_language()
  1393. {
  1394.    register struct symtab *s;
  1395.    FRAME fr;
  1396.    enum language flang;        /* The language of the current frame */
  1397.    
  1398.    fr = get_frame_info(selected_frame);
  1399.    if(fr)
  1400.    {
  1401.       s = find_pc_symtab(fr->pc);
  1402.       if(s)
  1403.      flang = s->language;
  1404.       else
  1405.      flang = language_unknown;
  1406.    }
  1407.    else
  1408.       flang = language_unknown;
  1409.  
  1410.    return flang;
  1411. }
  1412.  
  1413. void
  1414. _initialize_stack ()
  1415. {
  1416. #if 0  
  1417.   backtrace_limit = 30;
  1418. #endif
  1419.  
  1420.   add_com ("return", class_stack, return_command,
  1421.        "Make selected stack frame return to its caller.\n\
  1422. Control remains in the debugger, but when you continue\n\
  1423. execution will resume in the frame above the one now selected.\n\
  1424. If an argument is given, it is an expression for the value to return.");
  1425.  
  1426.   add_com ("up", class_stack, up_command,
  1427.        "Select and print stack frame that called this one.\n\
  1428. An argument says how many frames up to go.");
  1429.   add_com ("up-silently", class_support, up_silently_command,
  1430.        "Same as the `up' command, but does not print anything.\n\
  1431. This is useful in command scripts.");
  1432.  
  1433.   add_com ("down", class_stack, down_command,
  1434.        "Select and print stack frame called by this one.\n\
  1435. An argument says how many frames down to go.");
  1436.   add_com_alias ("do", "down", class_stack, 1);
  1437.   add_com_alias ("dow", "down", class_stack, 1);
  1438.   add_com ("down-silently", class_support, down_silently_command,
  1439.        "Same as the `down' command, but does not print anything.\n\
  1440. This is useful in command scripts.");
  1441.  
  1442.   add_com ("frame", class_stack, frame_command,
  1443.        "Select and print a stack frame.\n\
  1444. With no argument, print the selected stack frame.  (See also \"info frame\").\n\
  1445. An argument specifies the frame to select.\n\
  1446. It can be a stack frame number or the address of the frame.\n\
  1447. With argument, nothing is printed if input is coming from\n\
  1448. a command file or a user-defined command.");
  1449.  
  1450.   add_com_alias ("f", "frame", class_stack, 1);
  1451.  
  1452.   add_com ("select-frame", class_stack, select_frame_command,
  1453.        "Select a stack frame without printing anything.\n\
  1454. An argument specifies the frame to select.\n\
  1455. It can be a stack frame number or the address of the frame.\n");
  1456.  
  1457.   add_com ("backtrace", class_stack, backtrace_command,
  1458.        "Print backtrace of all stack frames, or innermost COUNT frames.\n\
  1459. With a negative argument, print outermost -COUNT frames.");
  1460.   add_com_alias ("bt", "backtrace", class_stack, 0);
  1461.   add_com_alias ("where", "backtrace", class_alias, 0);
  1462.   add_info ("stack", backtrace_command,
  1463.         "Backtrace of the stack, or innermost COUNT frames.");
  1464.   add_info_alias ("s", "stack", 1);
  1465.   add_info ("frame", frame_info,
  1466.         "All about selected stack frame, or frame at ADDR.");
  1467.   add_info_alias ("f", "frame", 1);
  1468.   add_info ("locals", locals_info,
  1469.         "Local variables of current stack frame.");
  1470.   add_info ("args", args_info,
  1471.         "Argument variables of current stack frame.");
  1472.   add_info ("catch", catch_info,
  1473.         "Exceptions that can be caught in the current stack frame.");
  1474.  
  1475. #if 0
  1476.   add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, 
  1477.        "Specify maximum number of frames for \"backtrace\" to print by default.",
  1478.        &setlist);
  1479.   add_info ("backtrace-limit", backtrace_limit_info,
  1480.         "The maximum number of frames for \"backtrace\" to print by default.");
  1481. #endif
  1482. }
  1483.