home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gdb-4.12-src.lha / GNU / src / amiga / gdb-4.12 / gdb / printcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  57.7 KB  |  2,159 lines

  1. /* Print values for GNU debugger GDB.
  2.    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993, 1994
  3.              Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include <string.h>
  23. #include <varargs.h>
  24. #include "frame.h"
  25. #include "symtab.h"
  26. #include "gdbtypes.h"
  27. #include "value.h"
  28. #include "language.h"
  29. #include "expression.h"
  30. #include "gdbcore.h"
  31. #include "gdbcmd.h"
  32. #include "target.h"
  33. #include "breakpoint.h"
  34. #include "demangle.h"
  35. #include "valprint.h"
  36.  
  37. extern int asm_demangle;    /* Whether to demangle syms in asm printouts */
  38. extern int addressprint;    /* Whether to print hex addresses in HLL " */
  39.  
  40. struct format_data
  41. {
  42.   int count;
  43.   char format;
  44.   char size;
  45. };
  46.  
  47. /* Last specified output format.  */
  48.  
  49. static char last_format = 'x';
  50.  
  51. /* Last specified examination size.  'b', 'h', 'w' or `q'.  */
  52.  
  53. static char last_size = 'w';
  54.  
  55. /* Default address to examine next.  */
  56.  
  57. static CORE_ADDR next_address;
  58.  
  59. /* Last address examined.  */
  60.  
  61. static CORE_ADDR last_examine_address;
  62.  
  63. /* Contents of last address examined.
  64.    This is not valid past the end of the `x' command!  */
  65.  
  66. static value last_examine_value;
  67.  
  68. /* Largest offset between a symbolic value and an address, that will be
  69.    printed as `0x1234 <symbol+offset>'.  */
  70.  
  71. static unsigned int max_symbolic_offset = UINT_MAX;
  72.  
  73. /* Append the source filename and linenumber of the symbol when
  74.    printing a symbolic value as `<symbol at filename:linenum>' if set.  */
  75. static int print_symbol_filename = 0;
  76.  
  77. /* Switch for quick display of symbolic addresses -- only uses minsyms,
  78.    not full search of symtabs.  */
  79.  
  80. int fast_symbolic_addr = 1;
  81.  
  82. /* Number of auto-display expression currently being displayed.
  83.    So that we can disable it if we get an error or a signal within it.
  84.    -1 when not doing one.  */
  85.  
  86. int current_display_number;
  87.  
  88. /* Flag to low-level print routines that this value is being printed
  89.    in an epoch window.  We'd like to pass this as a parameter, but
  90.    every routine would need to take it.  Perhaps we can encapsulate
  91.    this in the I/O stream once we have GNU stdio. */
  92.  
  93. int inspect_it = 0;
  94.  
  95. struct display
  96. {
  97.   /* Chain link to next auto-display item.  */
  98.   struct display *next;
  99.   /* Expression to be evaluated and displayed.  */
  100.   struct expression *exp;
  101.   /* Item number of this auto-display item.  */
  102.   int number;
  103.   /* Display format specified.  */
  104.   struct format_data format;
  105.   /* Innermost block required by this expression when evaluated */
  106.   struct block *block;
  107.   /* Status of this display (enabled or disabled) */
  108.   enum enable status;
  109. };
  110.  
  111. /* Chain of expressions whose values should be displayed
  112.    automatically each time the program stops.  */
  113.  
  114. static struct display *display_chain;
  115.  
  116. static int display_number;
  117.  
  118. /* Prototypes for local functions */
  119.  
  120. static void
  121. delete_display PARAMS ((int));
  122.  
  123. static void
  124. enable_display PARAMS ((char *, int));
  125.  
  126. static void
  127. disable_display_command PARAMS ((char *, int));
  128.  
  129. static void
  130. disassemble_command PARAMS ((char *, int));
  131.  
  132. static void
  133. printf_command PARAMS ((char *, int));
  134.  
  135. static void
  136. print_frame_nameless_args PARAMS ((struct frame_info *, long, int, int,
  137.                    GDB_FILE *));
  138.  
  139. static void
  140. display_info PARAMS ((char *, int));
  141.  
  142. static void
  143. do_one_display PARAMS ((struct display *));
  144.  
  145. static void
  146. undisplay_command PARAMS ((char *, int));
  147.  
  148. static void
  149. free_display PARAMS ((struct display *));
  150.  
  151. static void
  152. display_command PARAMS ((char *, int));
  153.  
  154. static void
  155. x_command PARAMS ((char *, int));
  156.  
  157. static void
  158. address_info PARAMS ((char *, int));
  159.  
  160. static void
  161. set_command PARAMS ((char *, int));
  162.  
  163. static void
  164. output_command PARAMS ((char *, int));
  165.  
  166. static void
  167. call_command PARAMS ((char *, int));
  168.  
  169. static void
  170. inspect_command PARAMS ((char *, int));
  171.  
  172. static void
  173. print_command PARAMS ((char *, int));
  174.  
  175. static void
  176. print_command_1 PARAMS ((char *, int, int));
  177.  
  178. static void
  179. validate_format PARAMS ((struct format_data, char *));
  180.  
  181. static void
  182. do_examine PARAMS ((struct format_data, CORE_ADDR));
  183.  
  184. static void
  185. print_formatted PARAMS ((value, int, int));
  186.  
  187. static struct format_data
  188. decode_format PARAMS ((char **, int, int));
  189.  
  190.  
  191. /* Decode a format specification.  *STRING_PTR should point to it.
  192.    OFORMAT and OSIZE are used as defaults for the format and size
  193.    if none are given in the format specification.
  194.    If OSIZE is zero, then the size field of the returned value
  195.    should be set only if a size is explicitly specified by the
  196.    user.
  197.    The structure returned describes all the data
  198.    found in the specification.  In addition, *STRING_PTR is advanced
  199.    past the specification and past all whitespace following it.  */
  200.  
  201. static struct format_data
  202. decode_format (string_ptr, oformat, osize)
  203.      char **string_ptr;
  204.      int oformat;
  205.      int osize;
  206. {
  207.   struct format_data val;
  208.   register char *p = *string_ptr;
  209.  
  210.   val.format = '?';
  211.   val.size = '?';
  212.   val.count = 1;
  213.  
  214.   if (*p >= '0' && *p <= '9')
  215.     val.count = atoi (p);
  216.   while (*p >= '0' && *p <= '9') p++;
  217.  
  218.   /* Now process size or format letters that follow.  */
  219.  
  220.   while (1)
  221.     {
  222.       if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
  223.     val.size = *p++;
  224.       else if (*p >= 'a' && *p <= 'z')
  225.     val.format = *p++;
  226.       else
  227.     break;
  228.     }
  229.  
  230. #ifndef CC_HAS_LONG_LONG
  231.   /* Make sure 'g' size is not used on integer types.
  232.      Well, actually, we can handle hex.  */
  233.   if (val.size == 'g' && val.format != 'f' && val.format != 'x')
  234.     val.size = 'w';
  235. #endif
  236.  
  237.   while (*p == ' ' || *p == '\t') p++;
  238.   *string_ptr = p;
  239.  
  240.   /* Set defaults for format and size if not specified.  */
  241.   if (val.format == '?')
  242.     {
  243.       if (val.size == '?')
  244.     {
  245.       /* Neither has been specified.  */
  246.       val.format = oformat;
  247.       val.size = osize;
  248.     }
  249.       else
  250.     /* If a size is specified, any format makes a reasonable
  251.        default except 'i'.  */
  252.     val.format = oformat == 'i' ? 'x' : oformat;
  253.     }
  254.   else if (val.size == '?')
  255.     switch (val.format)
  256.       {
  257.       case 'a':
  258.       case 's':
  259.     /* Addresses must be words.  */
  260.     val.size = osize ? 'w' : osize;
  261.     break;
  262.       case 'f':
  263.     /* Floating point has to be word or giantword.  */
  264.     if (osize == 'w' || osize == 'g')
  265.       val.size = osize;
  266.     else
  267.       /* Default it to giantword if the last used size is not
  268.          appropriate.  */
  269.       val.size = osize ? 'g' : osize;
  270.     break;
  271.       case 'c':
  272.     /* Characters default to one byte.  */
  273.     val.size = osize ? 'b' : osize;
  274.     break;
  275.       default:
  276.     /* The default is the size most recently specified.  */
  277.     val.size = osize;
  278.       }
  279.  
  280.   return val;
  281. }
  282.  
  283. /* Print value VAL on gdb_stdout according to FORMAT, a letter or 0.
  284.    Do not end with a newline.
  285.    0 means print VAL according to its own type.
  286.    SIZE is the letter for the size of datum being printed.
  287.    This is used to pad hex numbers so they line up.  */
  288.  
  289. static void
  290. print_formatted (val, format, size)
  291.      register value val;
  292.      register int format;
  293.      int size;
  294. {
  295.   int len = TYPE_LENGTH (VALUE_TYPE (val));
  296.  
  297.   if (VALUE_LVAL (val) == lval_memory)
  298.     next_address = VALUE_ADDRESS (val) + len;
  299.  
  300.   switch (format)
  301.     {
  302.     case 's':
  303.       next_address = VALUE_ADDRESS (val)
  304.     + value_print (value_addr (val), gdb_stdout, format, Val_pretty_default);
  305.       break;
  306.  
  307.     case 'i':
  308.       /* The old comment says
  309.      "Force output out, print_insn not using _filtered".
  310.      I'm not completely sure what that means, I suspect most print_insn
  311.      now do use _filtered, so I guess it's obsolete.  */
  312.       /* We often wrap here if there are long symbolic names.  */
  313.       wrap_here ("    ");
  314.       next_address = VALUE_ADDRESS (val)
  315.     + print_insn (VALUE_ADDRESS (val), gdb_stdout);
  316.       break;
  317.  
  318.     default:
  319.       if (format == 0
  320.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
  321.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRING
  322.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
  323.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
  324.       || VALUE_REPEATED (val))
  325.     value_print (val, gdb_stdout, format, Val_pretty_default);
  326.       else
  327.     print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
  328.                 format, size, gdb_stdout);
  329.     }
  330. }
  331.  
  332. /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
  333.    according to letters FORMAT and SIZE on STREAM.
  334.    FORMAT may not be zero.  Formats s and i are not supported at this level.
  335.  
  336.    This is how the elements of an array or structure are printed
  337.    with a format.  */
  338.  
  339. void
  340. print_scalar_formatted (valaddr, type, format, size, stream)
  341.      char *valaddr;
  342.      struct type *type;
  343.      int format;
  344.      int size;
  345.      GDB_FILE *stream;
  346. {
  347.   LONGEST val_long;
  348.   int len = TYPE_LENGTH (type);
  349.  
  350.   if (len > sizeof (LONGEST)
  351.       && (format == 't'
  352.       || format == 'c'
  353.       || format == 'o'
  354.       || format == 'u'
  355.       || format == 'd'
  356.       || format == 'x'))
  357.     {
  358.       /* We can't print it normally, but we can print it in hex.
  359.          Printing it in the wrong radix is more useful than saying
  360.      "use /x, you dummy".  */
  361.       /* FIXME:  we could also do octal or binary if that was the
  362.      desired format.  */
  363.       /* FIXME:  we should be using the size field to give us a minimum
  364.      field width to print.  */
  365.       val_print_type_code_int (type, valaddr, stream);
  366.       return;
  367.     }
  368.  
  369.   val_long = unpack_long (type, valaddr);
  370.  
  371.   /* If we are printing it as unsigned, truncate it in case it is actually
  372.      a negative signed value (e.g. "print/u (short)-1" should print 65535
  373.      (if shorts are 16 bits) instead of 4294967295).  */
  374.   if (format != 'd')
  375.     {
  376.       if (len < sizeof (LONGEST))
  377.     val_long &= ((LONGEST) 1 << HOST_CHAR_BIT * len) - 1;
  378.     }
  379.  
  380.   switch (format)
  381.     {
  382.     case 'x':
  383.       if (!size)
  384.     {
  385.       /* no size specified, like in print.  Print varying # of digits. */
  386.       print_longest (stream, 'x', 1, val_long);
  387.     }
  388.       else
  389.     switch (size)
  390.       {
  391.       case 'b':
  392.       case 'h':
  393.       case 'w':
  394.       case 'g':
  395.         print_longest (stream, size, 1, val_long);
  396.         break;
  397.       default:
  398.         error ("Undefined output size \"%c\".", size);
  399.       }
  400.       break;
  401.  
  402.     case 'd':
  403.       print_longest (stream, 'd', 1, val_long);
  404.       break;
  405.  
  406.     case 'u':
  407.       print_longest (stream, 'u', 0, val_long);
  408.       break;
  409.  
  410.     case 'o':
  411.       if (val_long)
  412.     print_longest (stream, 'o', 1, val_long);
  413.       else
  414.     fprintf_filtered (stream, "0");
  415.       break;
  416.  
  417.     case 'a':
  418.       print_address (unpack_pointer (type, valaddr), stream);
  419.       break;
  420.  
  421.     case 'c':
  422.       value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
  423.            Val_pretty_default);
  424.       break;
  425.  
  426.     case 'f':
  427.       if (len == sizeof (float))
  428.     type = builtin_type_float;
  429.       else if (len == sizeof (double))
  430.     type = builtin_type_double;
  431.       print_floating (valaddr, type, stream);
  432.       break;
  433.  
  434.     case 0:
  435.       abort ();
  436.  
  437.     case 't':
  438.       /* Binary; 't' stands for "two".  */
  439.       {
  440.         char bits[8*(sizeof val_long) + 1];
  441.     char *cp = bits;
  442.     int width;
  443.  
  444.         if (!size)
  445.       width = 8*(sizeof val_long);
  446.         else
  447.           switch (size)
  448.         {
  449.         case 'b':
  450.           width = 8;
  451.           break;
  452.         case 'h':
  453.           width = 16;
  454.           break;
  455.         case 'w':
  456.           width = 32;
  457.           break;
  458.         case 'g':
  459.           width = 64;
  460.           break;
  461.         default:
  462.           error ("Undefined output size \"%c\".", size);
  463.         }
  464.  
  465.         bits[width] = '\0';
  466.         while (width-- > 0)
  467.           {
  468.             bits[width] = (val_long & 1) ? '1' : '0';
  469.             val_long >>= 1;
  470.           }
  471.     if (!size)
  472.       {
  473.         while (*cp && *cp == '0')
  474.           cp++;
  475.         if (*cp == '\0')
  476.           cp--;
  477.       }
  478.     fprintf_filtered (stream, local_binary_format_prefix());
  479.         fprintf_filtered (stream, cp);
  480.     fprintf_filtered (stream, local_binary_format_suffix());
  481.       }
  482.       break;
  483.  
  484.     default:
  485.       error ("Undefined output format \"%c\".", format);
  486.     }
  487. }
  488.  
  489. /* Specify default address for `x' command.
  490.    `info lines' uses this.  */
  491.  
  492. void
  493. set_next_address (addr)
  494.      CORE_ADDR addr;
  495. {
  496.   next_address = addr;
  497.  
  498.   /* Make address available to the user as $_.  */
  499.   set_internalvar (lookup_internalvar ("_"),
  500.            value_from_longest (lookup_pointer_type (builtin_type_void),
  501.                     (LONGEST) addr));
  502. }
  503.  
  504. /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
  505.    after LEADIN.  Print nothing if no symbolic name is found nearby.
  506.    Optionally also print source file and line number, if available.
  507.    DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
  508.    or to interpret it as a possible C++ name and convert it back to source
  509.    form.  However note that DO_DEMANGLE can be overridden by the specific
  510.    settings of the demangle and asm_demangle variables.  */
  511.  
  512. void
  513. print_address_symbolic (addr, stream, do_demangle, leadin)
  514.      CORE_ADDR addr;
  515.      GDB_FILE *stream;
  516.      int do_demangle;
  517.      char *leadin;
  518. {
  519.   struct minimal_symbol *msymbol;
  520.   struct symbol *symbol;
  521.   struct symtab *symtab = 0;
  522.   CORE_ADDR name_location = 0;
  523.   char *name;
  524.  
  525.   /* First try to find the address in the symbol table, then
  526.      in the minsyms.  Take the closest one.  */
  527.  
  528.   if (fast_symbolic_addr)
  529.     {
  530.       /* This is defective in the sense that it only finds text symbols.  */
  531.       symbol = find_pc_function (addr);
  532.       if (symbol)
  533.     name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (symbol));
  534.     }
  535.   else
  536.     find_addr_symbol (addr, &symtab, &name_location);
  537.  
  538.   if (symbol)
  539.     {
  540.       if (do_demangle)
  541.     name = SYMBOL_SOURCE_NAME (symbol);
  542.       else
  543.     name = SYMBOL_LINKAGE_NAME (symbol);
  544.     }
  545.  
  546.   msymbol = lookup_minimal_symbol_by_pc (addr);
  547.   if (msymbol != NULL)
  548.     {
  549.       if (SYMBOL_VALUE_ADDRESS (msymbol) > name_location || symbol == NULL)
  550.     {
  551.       /* The msymbol is closer to the address than the symbol;
  552.          use the msymbol instead.  */
  553.       symbol = 0;
  554.       symtab = 0;
  555.       name_location = SYMBOL_VALUE_ADDRESS (msymbol);
  556.       if (do_demangle)
  557.         name = SYMBOL_SOURCE_NAME (msymbol);
  558.       else
  559.         name = SYMBOL_LINKAGE_NAME (msymbol);
  560.     }
  561.     }
  562.   if (symbol == NULL && msymbol == NULL)
  563.     return;
  564.  
  565.   /* If the nearest symbol is too far away, don't print anything symbolic.  */
  566.  
  567.   /* For when CORE_ADDR is larger than unsigned int, we do math in
  568.      CORE_ADDR.  But when we detect unsigned wraparound in the
  569.      CORE_ADDR math, we ignore this test and print the offset,
  570.      because addr+max_symbolic_offset has wrapped through the end
  571.      of the address space back to the beginning, giving bogus comparison.  */
  572.   if (addr > name_location + max_symbolic_offset
  573.       && name_location + max_symbolic_offset > name_location)
  574.     return;
  575.  
  576.   fputs_filtered (leadin, stream);
  577.   fputs_filtered ("<", stream);
  578.   fputs_filtered (name, stream);
  579.   if (addr != name_location)
  580.     fprintf_filtered (stream, "+%u", (unsigned int)(addr - name_location));
  581.  
  582.   /* Append source filename and line number if desired.  Give specific
  583.      line # of this addr, if we have it; else line # of the nearest symbol.  */
  584.   if (print_symbol_filename)
  585.     {
  586.       struct symtab_and_line sal;
  587.  
  588.       sal = find_pc_line (addr, 0);
  589.       if (sal.symtab)
  590.     fprintf_filtered (stream, " at %s:%d", sal.symtab->filename, sal.line);
  591.       else if (symtab && symbol && symbol->line)
  592.     fprintf_filtered (stream, " at %s:%d", symtab->filename, symbol->line);
  593.       else if (symtab)
  594.     fprintf_filtered (stream, " in %s", symtab->filename);
  595.     }
  596.   fputs_filtered (">", stream);
  597. }
  598.  
  599.  
  600. /* Print address ADDR symbolically on STREAM.
  601.    First print it as a number.  Then perhaps print
  602.    <SYMBOL + OFFSET> after the number.  */
  603.  
  604. void
  605. print_address (addr, stream)
  606.      CORE_ADDR addr;
  607.      GDB_FILE *stream;
  608. {
  609. #if 0 && defined (ADDR_BITS_REMOVE)
  610.   /* This is wrong for pointer to char, in which we do want to print
  611.      the low bits.  */
  612.   fprintf_filtered (stream, local_hex_format(),
  613.             (unsigned long) ADDR_BITS_REMOVE(addr));
  614. #else
  615.   fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
  616. #endif
  617.   print_address_symbolic (addr, stream, asm_demangle, " ");
  618. }
  619.  
  620. /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
  621.    controls whether to print the symbolic name "raw" or demangled.
  622.    Global setting "addressprint" controls whether to print hex address
  623.    or not.  */
  624.  
  625. void
  626. print_address_demangle (addr, stream, do_demangle)
  627.      CORE_ADDR addr;
  628.      GDB_FILE *stream;
  629.      int do_demangle;
  630. {
  631.   if (addr == 0) {
  632.     fprintf_filtered (stream, "0");
  633.   } else if (addressprint) {
  634.     fprintf_filtered (stream, local_hex_format(), (unsigned long) addr);
  635.     print_address_symbolic (addr, stream, do_demangle, " ");
  636.   } else {
  637.     print_address_symbolic (addr, stream, do_demangle, "");
  638.   }
  639. }
  640.  
  641.  
  642. /* These are the types that $__ will get after an examine command of one
  643.    of these sizes.  */
  644.  
  645. static struct type *examine_b_type;
  646. static struct type *examine_h_type;
  647. static struct type *examine_w_type;
  648. static struct type *examine_g_type;
  649.  
  650. /* Examine data at address ADDR in format FMT.
  651.    Fetch it from memory and print on gdb_stdout.  */
  652.  
  653. static void
  654. do_examine (fmt, addr)
  655.      struct format_data fmt;
  656.      CORE_ADDR addr;
  657. {
  658.   register char format = 0;
  659.   register char size;
  660.   register int count = 1;
  661.   struct type *val_type = NULL;
  662.   register int i;
  663.   register int maxelts;
  664.  
  665.   format = fmt.format;
  666.   size = fmt.size;
  667.   count = fmt.count;
  668.   next_address = addr;
  669.  
  670.   /* String or instruction format implies fetch single bytes
  671.      regardless of the specified size.  */
  672.   if (format == 's' || format == 'i')
  673.     size = 'b';
  674.  
  675.   if (size == 'b')
  676.     val_type = examine_b_type;
  677.   else if (size == 'h')
  678.     val_type = examine_h_type;
  679.   else if (size == 'w')
  680.     val_type = examine_w_type;
  681.   else if (size == 'g')
  682.     val_type = examine_g_type;
  683.  
  684.   maxelts = 8;
  685.   if (size == 'w')
  686.     maxelts = 4;
  687.   if (size == 'g')
  688.     maxelts = 2;
  689.   if (format == 's' || format == 'i')
  690.     maxelts = 1;
  691.  
  692.   /* Print as many objects as specified in COUNT, at most maxelts per line,
  693.      with the address of the next one at the start of each line.  */
  694.  
  695.   while (count > 0)
  696.     {
  697.       print_address (next_address, gdb_stdout);
  698.       printf_filtered (":");
  699.       for (i = maxelts;
  700.        i > 0 && count > 0;
  701.        i--, count--)
  702.     {
  703.       printf_filtered ("\t");
  704.       /* Note that print_formatted sets next_address for the next
  705.          object.  */
  706.       last_examine_address = next_address;
  707.       last_examine_value = value_at (val_type, next_address);
  708.       print_formatted (last_examine_value, format, size);
  709.     }
  710.       printf_filtered ("\n");
  711.       gdb_flush (gdb_stdout);
  712.     }
  713. }
  714.  
  715. static void
  716. validate_format (fmt, cmdname)
  717.      struct format_data fmt;
  718.      char *cmdname;
  719. {
  720.   if (fmt.size != 0)
  721.     error ("Size letters are meaningless in \"%s\" command.", cmdname);
  722.   if (fmt.count != 1)
  723.     error ("Item count other than 1 is meaningless in \"%s\" command.",
  724.        cmdname);
  725.   if (fmt.format == 'i' || fmt.format == 's')
  726.     error ("Format letter \"%c\" is meaningless in \"%s\" command.",
  727.        fmt.format, cmdname);
  728. }
  729.  
  730. /*  Evaluate string EXP as an expression in the current language and
  731.     print the resulting value.  EXP may contain a format specifier as the
  732.     first argument ("/x myvar" for example, to print myvar in hex).
  733.     */
  734.  
  735. static void
  736. print_command_1 (exp, inspect, voidprint)
  737.      char *exp;
  738.      int inspect;
  739.      int voidprint;
  740. {
  741.   struct expression *expr;
  742.   register struct cleanup *old_chain = 0;
  743.   register char format = 0;
  744.   register value val;
  745.   struct format_data fmt;
  746.   int cleanup = 0;
  747.  
  748.   /* Pass inspect flag to the rest of the print routines in a global (sigh). */
  749.   inspect_it = inspect;
  750.  
  751.   if (exp && *exp == '/')
  752.     {
  753.       exp++;
  754.       fmt = decode_format (&exp, last_format, 0);
  755.       validate_format (fmt, "print");
  756.       last_format = format = fmt.format;
  757.     }
  758.   else
  759.     {
  760.       fmt.count = 1;
  761.       fmt.format = 0;
  762.       fmt.size = 0;
  763.     }
  764.  
  765.   if (exp && *exp)
  766.     {
  767.       extern int objectprint;
  768.       struct type *type;
  769.       expr = parse_expression (exp);
  770.       old_chain = make_cleanup (free_current_contents, &expr);
  771.       cleanup = 1;
  772.       val = evaluate_expression (expr);
  773.  
  774.       /* C++: figure out what type we actually want to print it as.  */
  775.       type = VALUE_TYPE (val);
  776.  
  777.       if (objectprint
  778.       && (   TYPE_CODE (type) == TYPE_CODE_PTR
  779.           || TYPE_CODE (type) == TYPE_CODE_REF)
  780.       && (   TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT
  781.           || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_UNION))
  782.     {
  783.       value v;
  784.  
  785.       v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
  786.       if (v != 0)
  787.         {
  788.           val = v;
  789.           type = VALUE_TYPE (val);
  790.         }
  791.     }
  792.     }
  793.   else
  794.     val = access_value_history (0);
  795.  
  796.   if (voidprint || (val && VALUE_TYPE (val) &&
  797.                     TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
  798.     {
  799.       int histindex = record_latest_value (val);
  800.  
  801.       if (inspect)
  802.     printf_unfiltered ("\031(gdb-makebuffer \"%s\"  %d '(\"", exp, histindex);
  803.       else
  804.     if (histindex >= 0) printf_filtered ("$%d = ", histindex);
  805.  
  806.       print_formatted (val, format, fmt.size);
  807.       printf_filtered ("\n");
  808.       if (inspect)
  809.     printf_unfiltered("\") )\030");
  810.     }
  811.  
  812.   if (cleanup)
  813.     do_cleanups (old_chain);
  814.   inspect_it = 0;    /* Reset print routines to normal */
  815. }
  816.  
  817. /* ARGSUSED */
  818. static void
  819. print_command (exp, from_tty)
  820.      char *exp;
  821.      int from_tty;
  822. {
  823.   print_command_1 (exp, 0, 1);
  824. }
  825.  
  826. /* Same as print, except in epoch, it gets its own window */
  827. /* ARGSUSED */
  828. static void
  829. inspect_command (exp, from_tty)
  830.      char *exp;
  831.      int from_tty;
  832. {
  833.   extern int epoch_interface;
  834.  
  835.   print_command_1 (exp, epoch_interface, 1);
  836. }
  837.  
  838. /* Same as print, except it doesn't print void results. */
  839. /* ARGSUSED */
  840. static void
  841. call_command (exp, from_tty)
  842.      char *exp;
  843.      int from_tty;
  844. {
  845.   print_command_1 (exp, 0, 0);
  846. }
  847.  
  848. /* ARGSUSED */
  849. static void
  850. output_command (exp, from_tty)
  851.      char *exp;
  852.      int from_tty;
  853. {
  854.   struct expression *expr;
  855.   register struct cleanup *old_chain;
  856.   register char format = 0;
  857.   register value val;
  858.   struct format_data fmt;
  859.  
  860.   if (exp && *exp == '/')
  861.     {
  862.       exp++;
  863.       fmt = decode_format (&exp, 0, 0);
  864.       validate_format (fmt, "output");
  865.       format = fmt.format;
  866.     }
  867.  
  868.   expr = parse_expression (exp);
  869.   old_chain = make_cleanup (free_current_contents, &expr);
  870.  
  871.   val = evaluate_expression (expr);
  872.  
  873.   print_formatted (val, format, fmt.size);
  874.  
  875.   do_cleanups (old_chain);
  876. }
  877.  
  878. /* ARGSUSED */
  879. static void
  880. set_command (exp, from_tty)
  881.      char *exp;
  882.      int from_tty;
  883. {
  884.   struct expression *expr = parse_expression (exp);
  885.   register struct cleanup *old_chain
  886.     = make_cleanup (free_current_contents, &expr);
  887.   evaluate_expression (expr);
  888.   do_cleanups (old_chain);
  889. }
  890.  
  891. /* ARGSUSED */
  892. static void
  893. address_info (exp, from_tty)
  894.      char *exp;
  895.      int from_tty;
  896. {
  897.   register struct symbol *sym;
  898.   register struct minimal_symbol *msymbol;
  899.   register long val;
  900.   register long basereg;
  901.   int is_a_field_of_this;    /* C++: lookup_symbol sets this to nonzero
  902.                    if exp is a field of `this'. */
  903.  
  904.   if (exp == 0)
  905.     error ("Argument required.");
  906.  
  907.   sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE, 
  908.                &is_a_field_of_this, (struct symtab **)NULL);
  909.   if (sym == NULL)
  910.     {
  911.       if (is_a_field_of_this)
  912.     {
  913.       printf_filtered ("Symbol \"");
  914.       fprintf_symbol_filtered (gdb_stdout, exp,
  915.                    current_language->la_language, DMGL_ANSI);
  916.       printf_filtered ("\" is a field of the local class variable `this'\n");
  917.       return;
  918.     }
  919.  
  920.       msymbol = lookup_minimal_symbol (exp, (struct objfile *) NULL);
  921.  
  922.       if (msymbol != NULL)
  923.     {
  924.       printf_filtered ("Symbol \"");
  925.       fprintf_symbol_filtered (gdb_stdout, exp,
  926.                    current_language->la_language, DMGL_ANSI);
  927.       printf_filtered ("\" is at %s in a file compiled without debugging.\n",
  928.           local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (msymbol)));
  929.     }
  930.       else
  931.     error ("No symbol \"%s\" in current context.", exp);
  932.       return;
  933.     }
  934.  
  935.   printf_filtered ("Symbol \"");
  936.   fprintf_symbol_filtered (gdb_stdout, SYMBOL_NAME (sym),
  937.                current_language->la_language, DMGL_ANSI);
  938.   printf_filtered ("\" is ", SYMBOL_NAME (sym));
  939.   val = SYMBOL_VALUE (sym);
  940.   basereg = SYMBOL_BASEREG (sym);
  941.  
  942.   switch (SYMBOL_CLASS (sym))
  943.     {
  944.     case LOC_CONST:
  945.     case LOC_CONST_BYTES:
  946.       printf_filtered ("constant");
  947.       break;
  948.  
  949.     case LOC_LABEL:
  950.       printf_filtered ("a label at address %s",
  951.           local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
  952.       break;
  953.  
  954.     case LOC_REGISTER:
  955.       printf_filtered ("a variable in register %s", reg_names[val]);
  956.       break;
  957.  
  958.     case LOC_STATIC:
  959.       printf_filtered ("static storage at address %s",
  960.           local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
  961.       break;
  962.  
  963.     case LOC_REGPARM:
  964.       printf_filtered ("an argument in register %s", reg_names[val]);
  965.       break;
  966.  
  967.     case LOC_REGPARM_ADDR:
  968.       printf_filtered ("address of an argument in register %s", reg_names[val]);
  969.       break;
  970.  
  971.     case LOC_ARG:
  972.       printf_filtered ("an argument at offset %ld", val);
  973.       break;
  974.  
  975.     case LOC_LOCAL_ARG:
  976.       printf_filtered ("an argument at frame offset %ld", val);
  977.       break;
  978.  
  979.     case LOC_LOCAL:
  980.       printf_filtered ("a local variable at frame offset %ld", val);
  981.       break;
  982.  
  983.     case LOC_REF_ARG:
  984.       printf_filtered ("a reference argument at offset %ld", val);
  985.       break;
  986.  
  987.     case LOC_BASEREG:
  988.       printf_filtered ("a variable at offset %ld from register %s",
  989.           val, reg_names[basereg]);
  990.       break;
  991.  
  992.     case LOC_BASEREG_ARG:
  993.       printf_filtered ("an argument at offset %ld from register %s",
  994.           val, reg_names[basereg]);
  995.       break;
  996.  
  997.     case LOC_TYPEDEF:
  998.       printf_filtered ("a typedef");
  999.       break;
  1000.  
  1001.     case LOC_BLOCK:
  1002.       printf_filtered ("a function at address %s",
  1003.           local_hex_string((unsigned long) BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
  1004.       break;
  1005.  
  1006.     case LOC_OPTIMIZED_OUT:
  1007.       printf_filtered ("optimized out");
  1008.       break;
  1009.       
  1010.     default:
  1011.       printf_filtered ("of unknown (botched) type");
  1012.       break;
  1013.     }
  1014.   printf_filtered (".\n");
  1015. }
  1016.  
  1017. static void
  1018. x_command (exp, from_tty)
  1019.      char *exp;
  1020.      int from_tty;
  1021. {
  1022.   struct expression *expr;
  1023.   struct format_data fmt;
  1024.   struct cleanup *old_chain;
  1025.   struct value *val;
  1026.  
  1027.   fmt.format = last_format;
  1028.   fmt.size = last_size;
  1029.   fmt.count = 1;
  1030.  
  1031.   if (exp && *exp == '/')
  1032.     {
  1033.       exp++;
  1034.       fmt = decode_format (&exp, last_format, last_size);
  1035.     }
  1036.  
  1037.   /* If we have an expression, evaluate it and use it as the address.  */
  1038.  
  1039.   if (exp != 0 && *exp != 0)
  1040.     {
  1041.       expr = parse_expression (exp);
  1042.       /* Cause expression not to be there any more
  1043.      if this command is repeated with Newline.
  1044.      But don't clobber a user-defined command's definition.  */
  1045.       if (from_tty)
  1046.     *exp = 0;
  1047.       old_chain = make_cleanup (free_current_contents, &expr);
  1048.       val = evaluate_expression (expr);
  1049.       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
  1050.     val = value_ind (val);
  1051.       /* In rvalue contexts, such as this, functions are coerced into
  1052.      pointers to functions.  This makes "x/i main" work.  */
  1053.       if (/* last_format == 'i'
  1054.       && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
  1055.       && VALUE_LVAL (val) == lval_memory)
  1056.     next_address = VALUE_ADDRESS (val);
  1057.       else
  1058.     next_address = value_as_pointer (val);
  1059.       do_cleanups (old_chain);
  1060.     }
  1061.  
  1062.   do_examine (fmt, next_address);
  1063.  
  1064.   /* If the examine succeeds, we remember its size and format for next time.  */
  1065.   last_size = fmt.size;
  1066.   last_format = fmt.format;
  1067.  
  1068.   /* Set a couple of internal variables if appropriate. */
  1069.   if (last_examine_value)
  1070.     {
  1071.       /* Make last address examined available to the user as $_.  Use
  1072.      the correct pointer type.  */
  1073.       set_internalvar (lookup_internalvar ("_"),
  1074.            value_from_longest (
  1075.          lookup_pointer_type (VALUE_TYPE (last_examine_value)),
  1076.                    (LONGEST) last_examine_address));
  1077.       
  1078.       /* Make contents of last address examined available to the user as $__.*/
  1079.       set_internalvar (lookup_internalvar ("__"), last_examine_value);
  1080.     }
  1081. }
  1082.  
  1083.  
  1084. /* Add an expression to the auto-display chain.
  1085.    Specify the expression.  */
  1086.  
  1087. static void
  1088. display_command (exp, from_tty)
  1089.      char *exp;
  1090.      int from_tty;
  1091. {
  1092.   struct format_data fmt;
  1093.   register struct expression *expr;
  1094.   register struct display *new;
  1095.  
  1096.   if (exp == 0)
  1097.     {
  1098.       do_displays ();
  1099.       return;
  1100.     }
  1101.  
  1102.   if (*exp == '/')
  1103.     {
  1104.       exp++;
  1105.       fmt = decode_format (&exp, 0, 0);
  1106.       if (fmt.size && fmt.format == 0)
  1107.     fmt.format = 'x';
  1108.       if (fmt.format == 'i' || fmt.format == 's')
  1109.     fmt.size = 'b';
  1110.     }
  1111.   else
  1112.     {
  1113.       fmt.format = 0;
  1114.       fmt.size = 0;
  1115.       fmt.count = 0;
  1116.     }
  1117.  
  1118.   innermost_block = 0;
  1119.   expr = parse_expression (exp);
  1120.  
  1121.   new = (struct display *) xmalloc (sizeof (struct display));
  1122.  
  1123.   new->exp = expr;
  1124.   new->block = innermost_block;
  1125.   new->next = display_chain;
  1126.   new->number = ++display_number;
  1127.   new->format = fmt;
  1128.   new->status = enabled;
  1129.   display_chain = new;
  1130.  
  1131.   if (from_tty && target_has_execution)
  1132.     do_one_display (new);
  1133.  
  1134.   dont_repeat ();
  1135. }
  1136.  
  1137. static void
  1138. free_display (d)
  1139.      struct display *d;
  1140. {
  1141.   free ((PTR)d->exp);
  1142.   free ((PTR)d);
  1143. }
  1144.  
  1145. /* Clear out the display_chain.
  1146.    Done when new symtabs are loaded, since this invalidates
  1147.    the types stored in many expressions.  */
  1148.  
  1149. void
  1150. clear_displays ()
  1151. {
  1152.   register struct display *d;
  1153.  
  1154.   while ((d = display_chain) != NULL)
  1155.     {
  1156.       free ((PTR)d->exp);
  1157.       display_chain = d->next;
  1158.       free ((PTR)d);
  1159.     }
  1160. }
  1161.  
  1162. /* Delete the auto-display number NUM.  */
  1163.  
  1164. static void
  1165. delete_display (num)
  1166.      int num;
  1167. {
  1168.   register struct display *d1, *d;
  1169.  
  1170.   if (!display_chain)
  1171.     error ("No display number %d.", num);
  1172.  
  1173.   if (display_chain->number == num)
  1174.     {
  1175.       d1 = display_chain;
  1176.       display_chain = d1->next;
  1177.       free_display (d1);
  1178.     }
  1179.   else
  1180.     for (d = display_chain; ; d = d->next)
  1181.       {
  1182.     if (d->next == 0)
  1183.       error ("No display number %d.", num);
  1184.     if (d->next->number == num)
  1185.       {
  1186.         d1 = d->next;
  1187.         d->next = d1->next;
  1188.         free_display (d1);
  1189.         break;
  1190.       }
  1191.       }
  1192. }
  1193.  
  1194. /* Delete some values from the auto-display chain.
  1195.    Specify the element numbers.  */
  1196.  
  1197. static void
  1198. undisplay_command (args, from_tty)
  1199.      char *args;
  1200.      int from_tty;
  1201. {
  1202.   register char *p = args;
  1203.   register char *p1;
  1204.   register int num;
  1205.  
  1206.   if (args == 0)
  1207.     {
  1208.       if (query ("Delete all auto-display expressions? "))
  1209.     clear_displays ();
  1210.       dont_repeat ();
  1211.       return;
  1212.     }
  1213.  
  1214.   while (*p)
  1215.     {
  1216.       p1 = p;
  1217.       while (*p1 >= '0' && *p1 <= '9') p1++;
  1218.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  1219.     error ("Arguments must be display numbers.");
  1220.  
  1221.       num = atoi (p);
  1222.  
  1223.       delete_display (num);
  1224.  
  1225.       p = p1;
  1226.       while (*p == ' ' || *p == '\t') p++;
  1227.     }
  1228.   dont_repeat ();
  1229. }
  1230.  
  1231. /* Display a single auto-display.  
  1232.    Do nothing if the display cannot be printed in the current context,
  1233.    or if the display is disabled. */
  1234.  
  1235. static void
  1236. do_one_display (d)
  1237.      struct display *d;
  1238. {
  1239.   int within_current_scope;
  1240.  
  1241.   if (d->status == disabled)
  1242.     return;
  1243.  
  1244.   if (d->block)
  1245.     within_current_scope = contained_in (get_selected_block (), d->block);
  1246.   else
  1247.     within_current_scope = 1;
  1248.   if (!within_current_scope)
  1249.     return;
  1250.  
  1251.   current_display_number = d->number;
  1252.  
  1253.   printf_filtered ("%d: ", d->number);
  1254.   if (d->format.size)
  1255.     {
  1256.       CORE_ADDR addr;
  1257.       
  1258.       printf_filtered ("x/");
  1259.       if (d->format.count != 1)
  1260.     printf_filtered ("%d", d->format.count);
  1261.       printf_filtered ("%c", d->format.format);
  1262.       if (d->format.format != 'i' && d->format.format != 's')
  1263.     printf_filtered ("%c", d->format.size);
  1264.       printf_filtered (" ");
  1265.       print_expression (d->exp, gdb_stdout);
  1266.       if (d->format.count != 1)
  1267.     printf_filtered ("\n");
  1268.       else
  1269.     printf_filtered ("  ");
  1270.       
  1271.       addr = value_as_pointer (evaluate_expression (d->exp));
  1272.       if (d->format.format == 'i')
  1273.     addr = ADDR_BITS_REMOVE (addr);
  1274.       
  1275.       do_examine (d->format, addr);
  1276.     }
  1277.   else
  1278.     {
  1279.       if (d->format.format)
  1280.     printf_filtered ("/%c ", d->format.format);
  1281.       print_expression (d->exp, gdb_stdout);
  1282.       printf_filtered (" = ");
  1283.       print_formatted (evaluate_expression (d->exp),
  1284.                d->format.format, d->format.size);
  1285.       printf_filtered ("\n");
  1286.     }
  1287.  
  1288.   gdb_flush (gdb_stdout);
  1289.   current_display_number = -1;
  1290. }
  1291.  
  1292. /* Display all of the values on the auto-display chain which can be
  1293.    evaluated in the current scope.  */
  1294.  
  1295. void
  1296. do_displays ()
  1297. {
  1298.   register struct display *d;
  1299.  
  1300.   for (d = display_chain; d; d = d->next)
  1301.     do_one_display (d);
  1302. }
  1303.  
  1304. /* Delete the auto-display which we were in the process of displaying.
  1305.    This is done when there is an error or a signal.  */
  1306.  
  1307. void
  1308. disable_display (num)
  1309.      int num;
  1310. {
  1311.   register struct display *d;
  1312.  
  1313.   for (d = display_chain; d; d = d->next)
  1314.     if (d->number == num)
  1315.       {
  1316.     d->status = disabled;
  1317.     return;
  1318.       }
  1319.   printf_unfiltered ("No display number %d.\n", num);
  1320. }
  1321.   
  1322. void
  1323. disable_current_display ()
  1324. {
  1325.   if (current_display_number >= 0)
  1326.     {
  1327.       disable_display (current_display_number);
  1328.       fprintf_unfiltered (gdb_stderr, "Disabling display %d to avoid infinite recursion.\n",
  1329.            current_display_number);
  1330.     }
  1331.   current_display_number = -1;
  1332. }
  1333.  
  1334. static void
  1335. display_info (ignore, from_tty)
  1336.      char *ignore;
  1337.      int from_tty;
  1338. {
  1339.   register struct display *d;
  1340.  
  1341.   if (!display_chain)
  1342.     printf_unfiltered ("There are no auto-display expressions now.\n");
  1343.   else
  1344.       printf_filtered ("Auto-display expressions now in effect:\n\
  1345. Num Enb Expression\n");
  1346.  
  1347.   for (d = display_chain; d; d = d->next)
  1348.     {
  1349.       printf_filtered ("%d:   %c  ", d->number, "ny"[(int)d->status]);
  1350.       if (d->format.size)
  1351.     printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
  1352.         d->format.format);
  1353.       else if (d->format.format)
  1354.     printf_filtered ("/%c ", d->format.format);
  1355.       print_expression (d->exp, gdb_stdout);
  1356.       if (d->block && !contained_in (get_selected_block (), d->block))
  1357.     printf_filtered (" (cannot be evaluated in the current context)");
  1358.       printf_filtered ("\n");
  1359.       gdb_flush (gdb_stdout);
  1360.     }
  1361. }
  1362.  
  1363. static void
  1364. enable_display (args, from_tty)
  1365.      char *args;
  1366.      int from_tty;
  1367. {
  1368.   register char *p = args;
  1369.   register char *p1;
  1370.   register int num;
  1371.   register struct display *d;
  1372.  
  1373.   if (p == 0)
  1374.     {
  1375.       for (d = display_chain; d; d = d->next)
  1376.     d->status = enabled;
  1377.     }
  1378.   else
  1379.     while (*p)
  1380.       {
  1381.     p1 = p;
  1382.     while (*p1 >= '0' && *p1 <= '9')
  1383.       p1++;
  1384.     if (*p1 && *p1 != ' ' && *p1 != '\t')
  1385.       error ("Arguments must be display numbers.");
  1386.     
  1387.     num = atoi (p);
  1388.     
  1389.     for (d = display_chain; d; d = d->next)
  1390.       if (d->number == num)
  1391.         {
  1392.           d->status = enabled;
  1393.           goto win;
  1394.         }
  1395.     printf_unfiltered ("No display number %d.\n", num);
  1396.       win:
  1397.     p = p1;
  1398.     while (*p == ' ' || *p == '\t')
  1399.       p++;
  1400.       }
  1401. }
  1402.  
  1403. /* ARGSUSED */
  1404. static void
  1405. disable_display_command (args, from_tty)
  1406.      char *args;
  1407.      int from_tty;
  1408. {
  1409.   register char *p = args;
  1410.   register char *p1;
  1411.   register struct display *d;
  1412.  
  1413.   if (p == 0)
  1414.     {
  1415.       for (d = display_chain; d; d = d->next)
  1416.     d->status = disabled;
  1417.     }
  1418.   else
  1419.     while (*p)
  1420.       {
  1421.     p1 = p;
  1422.     while (*p1 >= '0' && *p1 <= '9')
  1423.       p1++;
  1424.     if (*p1 && *p1 != ' ' && *p1 != '\t')
  1425.       error ("Arguments must be display numbers.");
  1426.     
  1427.     disable_display (atoi (p));
  1428.  
  1429.     p = p1;
  1430.     while (*p == ' ' || *p == '\t')
  1431.       p++;
  1432.       }
  1433. }
  1434.  
  1435.  
  1436. /* Print the value in stack frame FRAME of a variable
  1437.    specified by a struct symbol.  */
  1438.  
  1439. void
  1440. print_variable_value (var, frame, stream)
  1441.      struct symbol *var;
  1442.      FRAME frame;
  1443.      GDB_FILE *stream;
  1444. {
  1445.   value val = read_var_value (var, frame);
  1446.   value_print (val, stream, 0, Val_pretty_default);
  1447. }
  1448.  
  1449. /* Print the arguments of a stack frame, given the function FUNC
  1450.    running in that frame (as a symbol), the info on the frame,
  1451.    and the number of args according to the stack frame (or -1 if unknown).  */
  1452.  
  1453. /* References here and elsewhere to "number of args according to the
  1454.    stack frame" appear in all cases to refer to "number of ints of args
  1455.    according to the stack frame".  At least for VAX, i386, isi.  */
  1456.  
  1457. void
  1458. print_frame_args (func, fi, num, stream)
  1459.      struct symbol *func;
  1460.      struct frame_info *fi;
  1461.      int num;
  1462.      GDB_FILE *stream;
  1463. {
  1464.   struct block *b = NULL;
  1465.   int nsyms = 0;
  1466.   int first = 1;
  1467.   register int i;
  1468.   register struct symbol *sym;
  1469.   register value val;
  1470.   /* Offset of next stack argument beyond the one we have seen that is
  1471.      at the highest offset.
  1472.      -1 if we haven't come to a stack argument yet.  */
  1473.   long highest_offset = -1;
  1474.   int arg_size;
  1475.   /* Number of ints of arguments that we have printed so far.  */
  1476.   int args_printed = 0;
  1477.  
  1478.   if (func)
  1479.     {
  1480.       b = SYMBOL_BLOCK_VALUE (func);
  1481.       nsyms = BLOCK_NSYMS (b);
  1482.     }
  1483.  
  1484.   for (i = 0; i < nsyms; i++)
  1485.     {
  1486.       QUIT;
  1487.       sym = BLOCK_SYM (b, i);
  1488.  
  1489.       /* Keep track of the highest stack argument offset seen, and
  1490.      skip over any kinds of symbols we don't care about.  */
  1491.  
  1492.       switch (SYMBOL_CLASS (sym)) {
  1493.       case LOC_ARG:
  1494.       case LOC_REF_ARG:
  1495.     {
  1496.       long current_offset = SYMBOL_VALUE (sym);
  1497.  
  1498.       arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
  1499.       
  1500.       /* Compute address of next argument by adding the size of
  1501.          this argument and rounding to an int boundary.  */
  1502.       current_offset
  1503.         = ((current_offset + arg_size + sizeof (int) - 1)
  1504.            & ~(sizeof (int) - 1));
  1505.  
  1506.       /* If this is the highest offset seen yet, set highest_offset.  */
  1507.       if (highest_offset == -1
  1508.           || (current_offset > highest_offset))
  1509.         highest_offset = current_offset;
  1510.  
  1511.       /* Add the number of ints we're about to print to args_printed.  */
  1512.       args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
  1513.     }
  1514.  
  1515.       /* We care about types of symbols, but don't need to keep track of
  1516.      stack offsets in them.  */
  1517.       case LOC_REGPARM:
  1518.       case LOC_REGPARM_ADDR:
  1519.       case LOC_LOCAL_ARG:
  1520.       case LOC_BASEREG_ARG:
  1521.     break;
  1522.  
  1523.       /* Other types of symbols we just skip over.  */
  1524.       default:
  1525.     continue;
  1526.       }
  1527.  
  1528.       /* We have to look up the symbol because arguments can have
  1529.      two entries (one a parameter, one a local) and the one we
  1530.      want is the local, which lookup_symbol will find for us.
  1531.      This includes gcc1 (not gcc2) on the sparc when passing a
  1532.      small structure and gcc2 when the argument type is float
  1533.      and it is passed as a double and converted to float by
  1534.      the prologue (in the latter case the type of the LOC_ARG
  1535.      symbol is double and the type of the LOC_LOCAL symbol is
  1536.      float).  */
  1537.       /* But if the parameter name is null, don't try it.
  1538.      Null parameter names occur on the RS/6000, for traceback tables.
  1539.      FIXME, should we even print them?  */
  1540.  
  1541.       if (*SYMBOL_NAME (sym))
  1542.     {
  1543.       struct symbol *nsym;
  1544.       nsym = lookup_symbol
  1545.         (SYMBOL_NAME (sym),
  1546.          b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
  1547.       if (SYMBOL_CLASS (nsym) == LOC_REGISTER)
  1548.         {
  1549.           /* There is a LOC_ARG/LOC_REGISTER pair.  This means that
  1550.          it was passed on the stack and loaded into a register,
  1551.          or passed in a register and stored in a stack slot.
  1552.          GDB 3.x used the LOC_ARG; GDB 4.0-4.11 used the LOC_REGISTER.
  1553.  
  1554.          Reasons for using the LOC_ARG:
  1555.          (1) because find_saved_registers may be slow for remote
  1556.          debugging,
  1557.          (2) because registers are often re-used and stack slots
  1558.          rarely (never?) are.  Therefore using the stack slot is
  1559.          much less likely to print garbage.
  1560.  
  1561.          Reasons why we might want to use the LOC_REGISTER:
  1562.          (1) So that the backtrace prints the same value as
  1563.          "print foo".  I see no compelling reason why this needs
  1564.          to be the case; having the backtrace print the value which
  1565.          was passed in, and "print foo" print the value as modified
  1566.          within the called function, makes perfect sense to me.
  1567.  
  1568.          Additional note:  It might be nice if "info args" displayed
  1569.          both values.
  1570.          One more note:  There is a case with sparc sturcture passing
  1571.          where we need to use the LOC_REGISTER, but this is dealt with
  1572.          by creating a single LOC_REGPARM in symbol reading.  */
  1573.  
  1574.           /* Leave sym (the LOC_ARG) alone.  */
  1575.           ;
  1576.         }
  1577.       else
  1578.         sym = nsym;
  1579.     }
  1580.  
  1581.       /* Print the current arg.  */
  1582.       if (! first)
  1583.     fprintf_filtered (stream, ", ");
  1584.       wrap_here ("    ");
  1585.       fprintf_symbol_filtered (stream, SYMBOL_SOURCE_NAME (sym),
  1586.                    SYMBOL_LANGUAGE (sym), DMGL_PARAMS | DMGL_ANSI);
  1587.       fputs_filtered ("=", stream);
  1588.  
  1589.       /* Avoid value_print because it will deref ref parameters.  We just
  1590.      want to print their addresses.  Print ??? for args whose address
  1591.      we do not know.  We pass 2 as "recurse" to val_print because our
  1592.      standard indentation here is 4 spaces, and val_print indents
  1593.      2 for each recurse.  */
  1594.       val = read_var_value (sym, FRAME_INFO_ID (fi));
  1595.       if (val)
  1596.         val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
  1597.            stream, 0, 0, 2, Val_no_prettyprint);
  1598.       else
  1599.     fputs_filtered ("???", stream);
  1600.       first = 0;
  1601.     }
  1602.  
  1603.   /* Don't print nameless args in situations where we don't know
  1604.      enough about the stack to find them.  */
  1605.   if (num != -1)
  1606.     {
  1607.       long start;
  1608.  
  1609.       if (highest_offset == -1)
  1610.     start = FRAME_ARGS_SKIP;
  1611.       else
  1612.     start = highest_offset;
  1613.  
  1614.       print_frame_nameless_args (fi, start, num - args_printed,
  1615.                  first, stream);
  1616.     }
  1617. }
  1618.  
  1619. /* Print nameless args on STREAM.
  1620.    FI is the frameinfo for this frame, START is the offset
  1621.    of the first nameless arg, and NUM is the number of nameless args to
  1622.    print.  FIRST is nonzero if this is the first argument (not just
  1623.    the first nameless arg).  */
  1624. static void
  1625. print_frame_nameless_args (fi, start, num, first, stream)
  1626.      struct frame_info *fi;
  1627.      long start;
  1628.      int num;
  1629.      int first;
  1630.      GDB_FILE *stream;
  1631. {
  1632.   int i;
  1633.   CORE_ADDR argsaddr;
  1634.   long arg_value;
  1635.  
  1636.   for (i = 0; i < num; i++)
  1637.     {
  1638.       QUIT;
  1639. #ifdef NAMELESS_ARG_VALUE
  1640.       NAMELESS_ARG_VALUE (fi, start, &arg_value);
  1641. #else
  1642.       argsaddr = FRAME_ARGS_ADDRESS (fi);
  1643.       if (!argsaddr)
  1644.     return;
  1645.  
  1646.       arg_value = read_memory_integer (argsaddr + start, sizeof (int));
  1647. #endif
  1648.  
  1649.       if (!first)
  1650.     fprintf_filtered (stream, ", ");
  1651.  
  1652. #ifdef    PRINT_NAMELESS_INTEGER
  1653.       PRINT_NAMELESS_INTEGER (stream, arg_value);
  1654. #else
  1655. #ifdef PRINT_TYPELESS_INTEGER
  1656.       PRINT_TYPELESS_INTEGER (stream, builtin_type_int, (LONGEST) arg_value);
  1657. #else
  1658.       fprintf_filtered (stream, "%d", arg_value);
  1659. #endif /* PRINT_TYPELESS_INTEGER */
  1660. #endif /* PRINT_NAMELESS_INTEGER */
  1661.       first = 0;
  1662.       start += sizeof (int);
  1663.     }
  1664. }
  1665.  
  1666. /* ARGSUSED */
  1667. static void
  1668. printf_command (arg, from_tty)
  1669.      char *arg;
  1670.      int from_tty;
  1671. {
  1672.   register char *f;
  1673.   register char *s = arg;
  1674.   char *string;
  1675.   value *val_args;
  1676.   char *substrings;
  1677.   char *current_substring;
  1678.   int nargs = 0;
  1679.   int allocated_args = 20;
  1680.   struct cleanup *old_cleanups;
  1681.  
  1682.   val_args = (value *) xmalloc (allocated_args * sizeof (value));
  1683.   old_cleanups = make_cleanup (free_current_contents, &val_args);
  1684.  
  1685.   if (s == 0)
  1686.     error_no_arg ("format-control string and values to print");
  1687.  
  1688.   /* Skip white space before format string */
  1689.   while (*s == ' ' || *s == '\t') s++;
  1690.  
  1691.   /* A format string should follow, enveloped in double quotes */
  1692.   if (*s++ != '"')
  1693.     error ("Bad format string, missing '\"'.");
  1694.  
  1695.   /* Parse the format-control string and copy it into the string STRING,
  1696.      processing some kinds of escape sequence.  */
  1697.  
  1698.   f = string = (char *) alloca (strlen (s) + 1);
  1699.  
  1700.   while (*s != '"')
  1701.     {
  1702.       int c = *s++;
  1703.       switch (c)
  1704.     {
  1705.     case '\0':
  1706.       error ("Bad format string, non-terminated '\"'.");
  1707.  
  1708.     case '\\':
  1709.       switch (c = *s++)
  1710.         {
  1711.         case '\\':
  1712.           *f++ = '\\';
  1713.           break;
  1714.         case 'n':
  1715.           *f++ = '\n';
  1716.           break;
  1717.         case 't':
  1718.           *f++ = '\t';
  1719.           break;
  1720.         case 'r':
  1721.           *f++ = '\r';
  1722.           break;
  1723.         case '"':
  1724.           *f++ = '"';
  1725.           break;
  1726.         default:
  1727.           /* ??? TODO: handle other escape sequences */
  1728.           error ("Unrecognized \\ escape character in format string.");
  1729.         }
  1730.       break;
  1731.  
  1732.     default:
  1733.       *f++ = c;
  1734.     }
  1735.     }
  1736.  
  1737.   /* Skip over " and following space and comma.  */
  1738.   s++;
  1739.   *f++ = '\0';
  1740.   while (*s == ' ' || *s == '\t') s++;
  1741.  
  1742.   if (*s != ',' && *s != 0)
  1743.     error ("Invalid argument syntax");
  1744.  
  1745.   if (*s == ',') s++;
  1746.   while (*s == ' ' || *s == '\t') s++;
  1747.  
  1748.   /* Need extra space for the '\0's.  Doubling the size is sufficient.  */
  1749.   substrings = alloca (strlen (string) * 2);
  1750.   current_substring = substrings;
  1751.  
  1752.   {
  1753.     /* Now scan the string for %-specs and see what kinds of args they want.
  1754.        argclass[I] classifies the %-specs so we can give vprintf_unfiltered something
  1755.        of the right size.  */
  1756.  
  1757.     enum argclass {no_arg, int_arg, string_arg, double_arg, long_long_arg};
  1758.     enum argclass *argclass;
  1759.     enum argclass this_argclass;
  1760.     char *last_arg;
  1761.     int nargs_wanted;
  1762.     int lcount;
  1763.     int i;
  1764.  
  1765.     argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
  1766.     nargs_wanted = 0;
  1767.     f = string;
  1768.     last_arg = string;
  1769.     while (*f)
  1770.       if (*f++ == '%')
  1771.     {
  1772.       lcount = 0;
  1773.       while (strchr ("0123456789.hlL-+ #", *f)) 
  1774.         {
  1775.           if (*f == 'l' || *f == 'L')
  1776.         lcount++;
  1777.           f++;
  1778.         }
  1779.       switch (*f)
  1780.         {
  1781.         case 's':
  1782.           this_argclass = string_arg;
  1783.           break;
  1784.  
  1785.         case 'e':
  1786.         case 'f':
  1787.         case 'g':
  1788.           this_argclass = double_arg;
  1789.           break;
  1790.  
  1791.         case '*':
  1792.           error ("`*' not supported for precision or width in printf");
  1793.  
  1794.         case 'n':
  1795.           error ("Format specifier `n' not supported in printf");
  1796.  
  1797.         case '%':
  1798.           this_argclass = no_arg;
  1799.           break;
  1800.  
  1801.         default:
  1802.           if (lcount > 1)
  1803.         this_argclass = long_long_arg;
  1804.           else
  1805.         this_argclass = int_arg;
  1806.           break;
  1807.         }
  1808.       f++;
  1809.       if (this_argclass != no_arg)
  1810.         {
  1811.           strncpy (current_substring, last_arg, f - last_arg);
  1812.           current_substring += f - last_arg;
  1813.           *current_substring++ = '\0';
  1814.           last_arg = f;
  1815.           argclass[nargs_wanted++] = this_argclass;
  1816.         }
  1817.     }
  1818.  
  1819.     /* Now, parse all arguments and evaluate them.
  1820.        Store the VALUEs in VAL_ARGS.  */
  1821.  
  1822.     while (*s != '\0')
  1823.       {
  1824.     char *s1;
  1825.     if (nargs == allocated_args)
  1826.       val_args = (value *) xrealloc ((char *) val_args,
  1827.                      (allocated_args *= 2)
  1828.                      * sizeof (value));
  1829.     s1 = s;
  1830.     val_args[nargs] = parse_to_comma_and_eval (&s1);
  1831.  
  1832.     /* If format string wants a float, unchecked-convert the value to
  1833.        floating point of the same size */
  1834.  
  1835.     if (argclass[nargs] == double_arg)
  1836.       {
  1837.         if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
  1838.           VALUE_TYPE (val_args[nargs]) = builtin_type_float;
  1839.         if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
  1840.           VALUE_TYPE (val_args[nargs]) = builtin_type_double;
  1841.       }
  1842.     nargs++;
  1843.     s = s1;
  1844.     if (*s == ',')
  1845.       s++;
  1846.       }
  1847.  
  1848.     if (nargs != nargs_wanted)
  1849.       error ("Wrong number of arguments for specified format-string");
  1850.  
  1851.     /* FIXME: We should be using vprintf_filtered, but as long as it
  1852.        has an arbitrary limit that is unacceptable.  Correct fix is
  1853.        for vprintf_filtered to scan down the format string so it knows
  1854.        how big a buffer it needs (perhaps by putting a vasprintf (see
  1855.        GNU C library) in libiberty).
  1856.  
  1857.        But for now, just force out any pending output, so at least the output
  1858.        appears in the correct order.  */
  1859.     wrap_here ((char *)NULL);
  1860.  
  1861.     /* Now actually print them.  */
  1862.     current_substring = substrings;
  1863.     for (i = 0; i < nargs; i++)
  1864.       {
  1865.     switch (argclass[i])
  1866.       {
  1867.       case string_arg:
  1868.         {
  1869.           char *str;
  1870.           CORE_ADDR tem;
  1871.           int j;
  1872.           tem = value_as_pointer (val_args[i]);
  1873.  
  1874.           /* This is a %s argument.  Find the length of the string.  */
  1875.           for (j = 0; ; j++)
  1876.         {
  1877.           char c;
  1878.           QUIT;
  1879.           read_memory (tem + j, &c, 1);
  1880.           if (c == 0)
  1881.             break;
  1882.         }
  1883.  
  1884.           /* Copy the string contents into a string inside GDB.  */
  1885.           str = (char *) alloca (j + 1);
  1886.           read_memory (tem, str, j);
  1887.           str[j] = 0;
  1888.  
  1889.           /* Don't use printf_filtered because of arbitrary limit.  */
  1890.           printf_unfiltered (current_substring, str);
  1891.         }
  1892.         break;
  1893.       case double_arg:
  1894.         {
  1895.           double val = value_as_double (val_args[i]);
  1896.           /* Don't use printf_filtered because of arbitrary limit.  */
  1897.           printf_unfiltered (current_substring, val);
  1898.           break;
  1899.         }
  1900.       case long_long_arg:
  1901. #if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
  1902.         {
  1903.           long long val = value_as_long (val_args[i]);
  1904.           /* Don't use printf_filtered because of arbitrary limit.  */
  1905.           printf_unfiltered (current_substring, val);
  1906.           break;
  1907.         }
  1908. #else
  1909.         error ("long long not supported in printf");
  1910. #endif
  1911.       case int_arg:
  1912.         {
  1913.           /* FIXME: there should be separate int_arg and long_arg.  */
  1914.           long val = value_as_long (val_args[i]);
  1915.           /* Don't use printf_filtered because of arbitrary limit.  */
  1916.           printf_unfiltered (current_substring, val);
  1917.           break;
  1918.         }
  1919.       default:
  1920.         error ("internal error in printf_command");
  1921.       }
  1922.     /* Skip to the next substring.  */
  1923.     current_substring += strlen (current_substring) + 1;
  1924.       }
  1925.     /* Print the portion of the format string after the last argument.  */
  1926.     /* It would be OK to use printf_filtered here.  */
  1927.     printf (last_arg);
  1928.   }
  1929.   do_cleanups (old_cleanups);
  1930. }
  1931.  
  1932. /* Dump a specified section of assembly code.  With no command line
  1933.    arguments, this command will dump the assembly code for the
  1934.    function surrounding the pc value in the selected frame.  With one
  1935.    argument, it will dump the assembly code surrounding that pc value.
  1936.    Two arguments are interpeted as bounds within which to dump
  1937.    assembly.  */
  1938.  
  1939. /* ARGSUSED */
  1940. static void
  1941. disassemble_command (arg, from_tty)
  1942.      char *arg;
  1943.      int from_tty;
  1944. {
  1945.   CORE_ADDR low, high;
  1946.   char *name;
  1947.   CORE_ADDR pc;
  1948.   char *space_index;
  1949.  
  1950.   name = NULL;
  1951.   if (!arg)
  1952.     {
  1953.       if (!selected_frame)
  1954.     error ("No frame selected.\n");
  1955.  
  1956.       pc = get_frame_pc (selected_frame);
  1957.       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
  1958.     error ("No function contains program counter for selected frame.\n");
  1959.     }
  1960.   else if (!(space_index = (char *) strchr (arg, ' ')))
  1961.     {
  1962.       /* One argument.  */
  1963.       pc = parse_and_eval_address (arg);
  1964.       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
  1965.     error ("No function contains specified address.\n");
  1966.     }
  1967.   else
  1968.     {
  1969.       /* Two arguments.  */
  1970.       *space_index = '\0';
  1971.       low = parse_and_eval_address (arg);
  1972.       high = parse_and_eval_address (space_index + 1);
  1973.     }
  1974.  
  1975.   printf_filtered ("Dump of assembler code ");
  1976.   if (name != NULL)
  1977.     {
  1978.       printf_filtered ("for function %s:\n", name);
  1979.     }
  1980.   else
  1981.     {
  1982.       printf_filtered ("from %s ", local_hex_string((unsigned long) low));
  1983.       printf_filtered ("to %s:\n", local_hex_string((unsigned long) high));
  1984.     }
  1985.  
  1986.   /* Dump the specified range.  */
  1987.   for (pc = low; pc < high; )
  1988.     {
  1989.       QUIT;
  1990.       print_address (pc, gdb_stdout);
  1991.       printf_filtered (":\t");
  1992.       /* We often wrap here if there are long symbolic names.  */
  1993.       wrap_here ("    ");
  1994.       pc += print_insn (pc, gdb_stdout);
  1995.       printf_filtered ("\n");
  1996.     }
  1997.   printf_filtered ("End of assembler dump.\n");
  1998.   gdb_flush (gdb_stdout);
  1999. }
  2000.  
  2001.  
  2002. void
  2003. _initialize_printcmd ()
  2004. {
  2005.   current_display_number = -1;
  2006.  
  2007.   add_info ("address", address_info,
  2008.        "Describe where variable VAR is stored.");
  2009.  
  2010.   add_com ("x", class_vars, x_command,
  2011.        "Examine memory: x/FMT ADDRESS.\n\
  2012. ADDRESS is an expression for the memory address to examine.\n\
  2013. FMT is a repeat count followed by a format letter and a size letter.\n\
  2014. Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
  2015.   t(binary), f(float), a(address), i(instruction), c(char) and s(string).\n\
  2016. Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
  2017. The specified number of objects of the specified size are printed\n\
  2018. according to the format.\n\n\
  2019. Defaults for format and size letters are those previously used.\n\
  2020. Default count is 1.  Default address is following last thing printed\n\
  2021. with this command or \"print\".");
  2022.  
  2023.   add_com ("disassemble", class_vars, disassemble_command,
  2024.        "Disassemble a specified section of memory.\n\
  2025. Default is the function surrounding the pc of the selected frame.\n\
  2026. With a single argument, the function surrounding that address is dumped.\n\
  2027. Two arguments are taken as a range of memory to dump.");
  2028.  
  2029. #if 0
  2030.   add_com ("whereis", class_vars, whereis_command,
  2031.        "Print line number and file of definition of variable.");
  2032. #endif
  2033.   
  2034.   add_info ("display", display_info,
  2035.         "Expressions to display when program stops, with code numbers.");
  2036.  
  2037.   add_cmd ("undisplay", class_vars, undisplay_command,
  2038.        "Cancel some expressions to be displayed when program stops.\n\
  2039. Arguments are the code numbers of the expressions to stop displaying.\n\
  2040. No argument means cancel all automatic-display expressions.\n\
  2041. \"delete display\" has the same effect as this command.\n\
  2042. Do \"info display\" to see current list of code numbers.",
  2043.           &cmdlist);
  2044.  
  2045.   add_com ("display", class_vars, display_command,
  2046.        "Print value of expression EXP each time the program stops.\n\
  2047. /FMT may be used before EXP as in the \"print\" command.\n\
  2048. /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
  2049. as in the \"x\" command, and then EXP is used to get the address to examine\n\
  2050. and examining is done as in the \"x\" command.\n\n\
  2051. With no argument, display all currently requested auto-display expressions.\n\
  2052. Use \"undisplay\" to cancel display requests previously made.");
  2053.  
  2054.   add_cmd ("display", class_vars, enable_display, 
  2055.        "Enable some expressions to be displayed when program stops.\n\
  2056. Arguments are the code numbers of the expressions to resume displaying.\n\
  2057. No argument means enable all automatic-display expressions.\n\
  2058. Do \"info display\" to see current list of code numbers.", &enablelist);
  2059.  
  2060.   add_cmd ("display", class_vars, disable_display_command, 
  2061.        "Disable some expressions to be displayed when program stops.\n\
  2062. Arguments are the code numbers of the expressions to stop displaying.\n\
  2063. No argument means disable all automatic-display expressions.\n\
  2064. Do \"info display\" to see current list of code numbers.", &disablelist);
  2065.  
  2066.   add_cmd ("display", class_vars, undisplay_command, 
  2067.        "Cancel some expressions to be displayed when program stops.\n\
  2068. Arguments are the code numbers of the expressions to stop displaying.\n\
  2069. No argument means cancel all automatic-display expressions.\n\
  2070. Do \"info display\" to see current list of code numbers.", &deletelist);
  2071.  
  2072.   add_com ("printf", class_vars, printf_command,
  2073.     "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
  2074. This is useful for formatted output in user-defined commands.");
  2075.   add_com ("output", class_vars, output_command,
  2076.        "Like \"print\" but don't put in value history and don't print newline.\n\
  2077. This is useful in user-defined commands.");
  2078.  
  2079.   add_prefix_cmd ("set", class_vars, set_command,
  2080. "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
  2081. syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
  2082. example).  VAR may be a debugger \"convenience\" variable (names starting\n\
  2083. with $), a register (a few standard names starting with $), or an actual\n\
  2084. variable in the program being debugged.  EXP is any valid expression.\n\
  2085. Use \"set variable\" for variables with names identical to set subcommands.\n\
  2086. \nWith a subcommand, this command modifies parts of the gdb environment.\n\
  2087. You can see these environment settings with the \"show\" command.",
  2088.                   &setlist, "set ", 1, &cmdlist);
  2089.  
  2090.   /* "call" is the same as "set", but handy for dbx users to call fns. */
  2091.   add_com ("call", class_vars, call_command,
  2092.        "Call a function in the program.\n\
  2093. The argument is the function name and arguments, in the notation of the\n\
  2094. current working language.  The result is printed and saved in the value\n\
  2095. history, if it is not void.");
  2096.  
  2097.   add_cmd ("variable", class_vars, set_command,
  2098. "Evaluate expression EXP and assign result to variable VAR, using assignment\n\
  2099. syntax appropriate for the current language (VAR = EXP or VAR := EXP for\n\
  2100. example).  VAR may be a debugger \"convenience\" variable (names starting\n\
  2101. with $), a register (a few standard names starting with $), or an actual\n\
  2102. variable in the program being debugged.  EXP is any valid expression.\n\
  2103. This may usually be abbreviated to simply \"set\".",
  2104.            &setlist);
  2105.  
  2106.   add_com ("print", class_vars, print_command,
  2107.        concat ("Print value of expression EXP.\n\
  2108. Variables accessible are those of the lexical environment of the selected\n\
  2109. stack frame, plus all those whose scope is global or an entire file.\n\
  2110. \n\
  2111. $NUM gets previous value number NUM.  $ and $$ are the last two values.\n\
  2112. $$NUM refers to NUM'th value back from the last one.\n\
  2113. Names starting with $ refer to registers (with the values they would have\n\
  2114. if the program were to return to the stack frame now selected, restoring\n\
  2115. all registers saved by frames farther in) or else to debugger\n\
  2116. \"convenience\" variables (any such name not a known register).\n\
  2117. Use assignment expressions to give values to convenience variables.\n",
  2118.            "\n\
  2119. {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
  2120. @ is a binary operator for treating consecutive data objects\n\
  2121. anywhere in memory as an array.  FOO@NUM gives an array whose first\n\
  2122. element is FOO, whose second element is stored in the space following\n\
  2123. where FOO is stored, etc.  FOO must be an expression whose value\n\
  2124. resides in memory.\n",
  2125.            "\n\
  2126. EXP may be preceded with /FMT, where FMT is a format letter\n\
  2127. but no count or size letter (see \"x\" command).", NULL));
  2128.   add_com_alias ("p", "print", class_vars, 1);
  2129.  
  2130.   add_com ("inspect", class_vars, inspect_command,
  2131. "Same as \"print\" command, except that if you are running in the epoch\n\
  2132. environment, the value is printed in its own window.");
  2133.  
  2134.   add_show_from_set (
  2135.       add_set_cmd ("max-symbolic-offset", no_class, var_uinteger,
  2136.            (char *)&max_symbolic_offset,
  2137.     "Set the largest offset that will be printed in <symbol+1234> form.",
  2138.            &setprintlist),
  2139.       &showprintlist);
  2140.   add_show_from_set (
  2141.       add_set_cmd ("symbol-filename", no_class, var_boolean,
  2142.            (char *)&print_symbol_filename,
  2143.     "Set printing of source filename and line number with <symbol>.",
  2144.            &setprintlist),
  2145.       &showprintlist);
  2146.  
  2147.   add_show_from_set (
  2148.       add_set_cmd ("fast-symbolic-addr", no_class, var_boolean,
  2149.            (char *)&fast_symbolic_addr,
  2150.     "Set fast printing of symbolic addresses (using minimal symbols).",
  2151.            &setprintlist),
  2152.       &showprintlist);
  2153.  
  2154.   examine_b_type = init_type (TYPE_CODE_INT, 1, 0, NULL, NULL);
  2155.   examine_h_type = init_type (TYPE_CODE_INT, 2, 0, NULL, NULL);
  2156.   examine_w_type = init_type (TYPE_CODE_INT, 4, 0, NULL, NULL);
  2157.   examine_g_type = init_type (TYPE_CODE_INT, 8, 0, NULL, NULL);
  2158. }
  2159.