*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 2bf1f88b91382d733f92ec28bce2ae5b4cbb224f..58d53690c872ea750baaf9aeac50ea6a4d5e5e27 100644 (file)
@@ -18,13 +18,23 @@ along with GDB; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <stdio.h>
+#include <string.h>
 #include "defs.h"
 #include "param.h"
 #include "symtab.h"
 #include "value.h"
+#include "gdbcore.h"
+#include "gdbcmd.h"
+#include "target.h"
+#include "obstack.h"
 
-/* GNU software is only expected to run on systems with 32-bit integers.  */
-#define UINT_MAX 0xffffffff
+#include <errno.h>
+extern int sys_nerr;
+extern char *sys_errlist[];
+
+extern void print_scalar_formatted();  /* printcmd.c */
+extern void print_address_demangle();  /* printcmd.c */
+extern int demangle;   /* whether to print C++ syms raw or source-form */
 
 /* Maximum number of chars to print for a string pointer value
    or vector contents, or UINT_MAX for no limit.  */
@@ -36,6 +46,12 @@ static void type_print_varspec_prefix ();
 static void type_print_base ();
 static void type_print_method_args ();
 
+/* Default input and output radixes, and output format letter.  */
+
+unsigned input_radix = 10;
+unsigned output_radix = 10;
+int output_format = 0;
+
 
 char **unsigned_type_table;
 char **signed_type_table;
@@ -62,6 +78,7 @@ print_string (stream, string, length, force_ellipses)
   unsigned int things_printed = 0;
   int in_quotes = 0;
   int need_comma = 0;
+  extern int inspect_it;
 
   if (length == 0)
     {
@@ -74,7 +91,7 @@ print_string (stream, string, length, force_ellipses)
       /* Position of the character we are examining
         to see whether it is repeated.  */
       unsigned int rep1;
-      /* Number of repititions we have detected so far.  */
+      /* Number of repetitions we have detected so far.  */
       unsigned int reps;
 
       QUIT;
@@ -97,7 +114,10 @@ print_string (stream, string, length, force_ellipses)
        {
          if (in_quotes)
            {
-             fputs_filtered ("\", ", stream);
+             if (inspect_it)
+               fputs_filtered ("\\\", ", stream);
+             else
+               fputs_filtered ("\", ", stream);
              in_quotes = 0;
            }
          fputs_filtered ("'", stream);
@@ -111,7 +131,10 @@ print_string (stream, string, length, force_ellipses)
        {
          if (!in_quotes)
            {
-             fputs_filtered ("\"", stream);
+             if (inspect_it)
+               fputs_filtered ("\\\"", stream);
+             else
+               fputs_filtered ("\"", stream);
              in_quotes = 1;
            }
          printchar (string[i], stream, '"');
@@ -121,11 +144,124 @@ print_string (stream, string, length, force_ellipses)
 
   /* Terminate the quotes if necessary.  */
   if (in_quotes)
-    fputs_filtered ("\"", stream);
+    {
+      if (inspect_it)
+       fputs_filtered ("\\\"", stream);
+      else
+       fputs_filtered ("\"", stream);
+    }
 
   if (force_ellipses || i < length)
     fputs_filtered ("...", stream);
 }
+
+/* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
+   on STREAM.  */
+
+void
+print_floating (valaddr, type, stream)
+     char *valaddr;
+     struct type *type;
+     FILE *stream;
+{
+  double doub;
+  int inv;
+  unsigned len = TYPE_LENGTH (type);
+  
+#if defined (IEEE_FLOAT)
+
+  /* Check for NaN's.  Note that this code does not depend on us being
+     on an IEEE conforming system.  It only depends on the target
+     machine using IEEE representation.  This means (a)
+     cross-debugging works right, and (2) IEEE_FLOAT can (and should)
+     be defined for systems like the 68881, which uses IEEE
+     representation, but is not IEEE conforming.  */
+
+  {
+    long low, high;
+    /* Is the sign bit 0?  */
+    int nonnegative;
+    /* Is it is a NaN (i.e. the exponent is all ones and
+       the fraction is nonzero)?  */
+    int is_nan;
+
+    if (len == sizeof (float))
+      {
+       /* It's single precision. */
+       bcopy (valaddr, &low, sizeof (low));
+       /* target -> host.  */
+       SWAP_TARGET_AND_HOST (&low, sizeof (float));
+       nonnegative = low >= 0;
+       is_nan = ((((low >> 23) & 0xFF) == 0xFF) 
+                 && 0 != (low & 0x7FFFFF));
+       low &= 0x7fffff;
+       high = 0;
+      }
+    else
+      {
+       /* It's double precision.  Get the high and low words.  */
+
+#if TARGET_BYTE_ORDER == BIG_ENDIAN
+         bcopy (valaddr+4, &low,  sizeof (low));
+         bcopy (valaddr+0, &high, sizeof (high));
+#else
+         bcopy (valaddr+0, &low,  sizeof (low));
+         bcopy (valaddr+4, &high, sizeof (high));
+#endif
+         SWAP_TARGET_AND_HOST (&low, sizeof (low));
+         SWAP_TARGET_AND_HOST (&high, sizeof (high));
+         nonnegative = high >= 0;
+         is_nan = (((high >> 20) & 0x7ff) == 0x7ff
+                   && ! ((((high & 0xfffff) == 0)) && (low == 0)));
+         high &= 0xfffff;
+       }
+
+    if (is_nan)
+      {
+       /* The meaning of the sign and fraction is not defined by IEEE.
+          But the user might know what they mean.  For example, they
+          (in an implementation-defined manner) distinguish between
+          signaling and quiet NaN's.  */
+       if (high)
+         fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
+                           high, low);
+       else
+         fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
+       return;
+      }
+  }
+#endif /* IEEE_FLOAT.  */
+
+  doub = unpack_double (type, valaddr, &inv);
+  if (inv)
+    fprintf_filtered (stream, "<invalid float value>");
+  else
+    fprintf_filtered (stream, len <= sizeof(float) ? "%.6g" : "%.17g", doub);
+}
+
+/* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
+static void
+print_hex_chars (stream, valaddr, len)
+     FILE *stream;
+     unsigned char *valaddr;
+     unsigned len;
+{
+  unsigned char *p;
+  
+  fprintf_filtered (stream, "0x");
+#if TARGET_BYTE_ORDER == BIG_ENDIAN
+  for (p = valaddr;
+       p < valaddr + len;
+       p++)
+#else /* Little endian.  */
+  for (p = valaddr + len - 1;
+       p >= valaddr;
+       p--)
+#endif
+    {
+      fprintf_filtered (stream, "%02x", *p);
+    }
+}
 \f
 /* Print the value VAL in C-ish syntax on stream STREAM.
    FORMAT is a format-letter, or 0 for print in natural format of data type.
@@ -141,11 +277,22 @@ value_print (val, stream, format, pretty)
 {
   register unsigned int i, n, typelen;
 
+  if (val == 0)
+    {
+      printf_filtered ("<address of value unknown>");
+      return 0;
+    }
+  if (VALUE_OPTIMIZED_OUT (val))
+    {
+      printf_filtered ("<value optimized out>");
+      return 0;
+    }
+  
   /* A "repeated" value really contains several values in a row.
      They are made by the @ operator.
      Print such values as if they were arrays.  */
 
-  if (VALUE_REPEATED (val))
+  else if (VALUE_REPEATED (val))
     {
       n = VALUE_REPETITIONS (val);
       typelen = TYPE_LENGTH (VALUE_TYPE (val));
@@ -163,11 +310,12 @@ value_print (val, stream, format, pretty)
              /* Position of the array element we are examining to see
                 whether it is repeated.  */
              unsigned int rep1;
-             /* Number of repititions we have detected so far.  */
+             /* Number of repetitions we have detected so far.  */
              unsigned int reps;
 
              if (i != 0)
                fprintf_filtered (stream, ", ");
+             wrap_here ("");
 
              rep1 = i + 1;
              reps = 1;
@@ -215,32 +363,255 @@ value_print (val, stream, format, pretty)
       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
          || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
        {
-         fprintf_filtered (stream, "(");
-         type_print (VALUE_TYPE (val), "", stream, -1);
-         fprintf_filtered (stream, ") ");
-
-         /* If this is a function pointer, try to print what
-            function it is pointing to by name.  */
-         if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
-             == TYPE_CODE_FUNC)
+         /* Hack:  remove (char *) for char strings.  Their
+            type is indicated by the quoted string anyway. */
+          if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
+           && TYPE_LENGTH   (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
+                        == sizeof(char)
+           && TYPE_CODE     (TYPE_TARGET_TYPE (VALUE_TYPE (val)))
+                        == TYPE_CODE_INT
+           && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (VALUE_TYPE (val))))
            {
-             print_address (((int *) VALUE_CONTENTS (val))[0], stream);
-             /* Return value is irrelevant except for string pointers.  */
-             return 0;
+               /* Print nothing */
+           }
+         else
+           {
+             fprintf_filtered (stream, "(");
+             type_print (VALUE_TYPE (val), "", stream, -1);
+             fprintf_filtered (stream, ") ");
            }
        }
       return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
                        VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
     }
 }
+
+/* Return truth value for assertion that TYPE is of the type
+   "pointer to virtual function".  */
+static int
+is_vtbl_ptr_type(type)
+     struct type *type;
+{
+  char *typename = TYPE_NAME(type);
+  static const char vtbl_ptr_name[] =
+    { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e' };
+
+  return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
+}
+
+/* Return truth value for the assertion that TYPE is of the type
+   "pointer to virtual function table".  */
+static int
+is_vtbl_member(type)
+     struct type *type;
+{
+  if (TYPE_CODE (type) == TYPE_CODE_PTR
+      && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
+      && TYPE_CODE (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type))) == TYPE_CODE_STRUCT)
+    /* Virtual functions tables are full of pointers to virtual functions.  */
+    return is_vtbl_ptr_type (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)));
+  return 0;
+}
 \f
-static int prettyprint;        /* Controls prettyprinting of structures.  */
+/* Define a mess of print controls.  */
+
+int prettyprint;       /* Controls pretty printing of structures */
+int vtblprint;         /* Controls printing of vtbl's */
 int unionprint;                /* Controls printing of nested unions.  */
+int arrayprint;                /* Controls pretty printing of arrays.  */
+int addressprint;      /* Controls pretty printing of addresses.  */
+
+struct obstack dont_print_obstack;
+
+static void cplus_val_print ();
+
+/* Mutually recursive subroutines of cplus_val_print and val_print to print out
+   a structure's fields: val_print_fields and cplus_val_print.
+
+   TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
+   same meanings as in cplus_val_print and val_print.
+
+   DONT_PRINT is an array of baseclass types that we
+   should not print, or zero if called from top level.  */
+static void
+val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
+     struct type *type;
+     char *valaddr;
+     FILE *stream;
+     char format;
+     int recurse;
+     enum val_prettyprint pretty;
+     struct type **dont_print;
+{
+  int i, len, n_baseclasses;
+
+  fprintf_filtered (stream, "{");
+  len = TYPE_NFIELDS (type);
+  n_baseclasses = TYPE_N_BASECLASSES (type);
+
+  /* Print out baseclasses such that we don't print
+     duplicates of virtual baseclasses.  */
+  if (n_baseclasses > 0)
+    cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print);
+
+  if (!len && n_baseclasses == 1)
+    fprintf_filtered (stream, "<No data fields>");
+  else
+    {
+      extern int inspect_it;
+      int fields_seen = 0;
+
+      for (i = n_baseclasses; i < len; i++)
+       {
+         /* Check if static field */
+         if (TYPE_FIELD_STATIC (type, i))
+           continue;
+         if (fields_seen)
+           fprintf_filtered (stream, ", ");
+         else if (n_baseclasses > 0)
+           {
+             fprintf_filtered (stream, "\n");
+             print_spaces_filtered (2 + 2 * recurse, stream);
+             fputs_filtered ("members of ", stream);
+             fputs_filtered (type_name_no_tag (type), stream);
+             fputs_filtered (": ", stream);
+           }
+         fields_seen = 1;
+
+         if (pretty)
+           {
+             fprintf_filtered (stream, "\n");
+             print_spaces_filtered (2 + 2 * recurse, stream);
+           }
+         else 
+           {
+             wrap_here (n_spaces (2 + 2 * recurse));
+           }
+         if (inspect_it)
+           {
+             if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
+               fputs_filtered ("\"( ptr \"", stream);
+             else
+               fputs_filtered ("\"( nodef \"", stream);
+             fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+             fputs_filtered ("\" \"", stream);
+             fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+             fputs_filtered ("\") \"", stream);
+           }
+         else
+           {
+             fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
+             fputs_filtered (" = ", stream);
+           }
+         if (TYPE_FIELD_PACKED (type, i))
+           {
+             value v;
+
+             /* Bitfields require special handling, especially due to byte
+                order problems.  */
+             v = value_from_long (TYPE_FIELD_TYPE (type, i),
+                                  unpack_field_as_long (type, valaddr, i));
+
+             val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
+                        stream, format, 0, recurse + 1, pretty);
+           }
+         else
+           {
+             val_print (TYPE_FIELD_TYPE (type, i), 
+                        valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
+                        0, stream, format, 0, recurse + 1, pretty);
+           }
+       }
+      if (pretty)
+       {
+         fprintf_filtered (stream, "\n");
+         print_spaces_filtered (2 * recurse, stream);
+       }
+    }
+  fprintf_filtered (stream, "}");
+}
+
+/* Special val_print routine to avoid printing multiple copies of virtual
+   baseclasses.  */
+
+static void
+cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
+     struct type *type;
+     char *valaddr;
+     FILE *stream;
+     char format;
+     int recurse;
+     enum val_prettyprint pretty;
+     struct type **dont_print;
+{
+  struct obstack tmp_obstack;
+  struct type **last_dont_print
+    = (struct type **)obstack_next_free (&dont_print_obstack);
+  int i, n_baseclasses = TYPE_N_BASECLASSES (type);
+
+  if (dont_print == 0)
+    {
+      /* If we're at top level, carve out a completely fresh
+        chunk of the obstack and use that until this particular
+        invocation returns.  */
+      tmp_obstack = dont_print_obstack;
+      /* Bump up the high-water mark.  Now alpha is omega.  */
+      obstack_finish (&dont_print_obstack);
+    }
+
+  for (i = 0; i < n_baseclasses; i++)
+    {
+      char *baddr;
+
+      if (BASETYPE_VIA_VIRTUAL (type, i))
+       {
+         struct type **first_dont_print
+           = (struct type **)obstack_base (&dont_print_obstack);
+
+         int j = (struct type **)obstack_next_free (&dont_print_obstack)
+           - first_dont_print;
+
+         while (--j >= 0)
+           if (TYPE_BASECLASS (type, i) == first_dont_print[j])
+             goto flush_it;
+
+         obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
+       }
+
+      baddr = baseclass_addr (type, i, valaddr, 0);
+      if (baddr == 0)
+       error ("could not find virtual baseclass `%s'\n",
+              type_name_no_tag (TYPE_BASECLASS (type, i)));
+
+      fprintf_filtered (stream, "\n");
+      if (pretty)
+       print_spaces_filtered (2 + 2 * recurse, stream);
+      fputs_filtered ("<", stream);
+      fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
+      fputs_filtered ("> = ", stream);
+      val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
+                       recurse, pretty,
+                       (struct type **)obstack_base (&dont_print_obstack));
+    flush_it:
+      ;
+    }
+
+  if (dont_print == 0)
+    {
+      /* Free the space used to deal with the printing
+        of this type from top level.  */
+      obstack_free (&dont_print_obstack, last_dont_print);
+      /* Reset watermark so that we can continue protecting
+        ourselves from whatever we were protecting ourselves.  */
+      dont_print_obstack = tmp_obstack;
+    }
+}
 
 /* Print data of type TYPE located at VALADDR (within GDB),
    which came from the inferior at address ADDRESS,
    onto stdio stream STREAM according to FORMAT
-   (a letter or 0 for natural format).
+   (a letter or 0 for natural format).  The data at VALADDR
+   is in target byte order.
 
    If the data are a string pointer, returns the number of
    sting characters printed.
@@ -263,9 +634,9 @@ val_print (type, valaddr, address, stream, format,
      enum val_prettyprint pretty;
 {
   register unsigned int i;
-  int len, n_baseclasses;
+  unsigned len;
   struct type *elttype;
-  int eltlen;
+  unsigned eltlen;
   LONGEST val;
   unsigned char c;
 
@@ -276,9 +647,11 @@ val_print (type, valaddr, address, stream, format,
   
   QUIT;
 
+  check_stub_type (type);
+  
   if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
     {
-      fprintf_filtered (stream, "<Type not defined in this context>");
+      fprintf_filtered (stream, "<unknown struct>");
       fflush (stream);
       return 0;
     }
@@ -292,10 +665,12 @@ val_print (type, valaddr, address, stream, format,
          elttype = TYPE_TARGET_TYPE (type);
          eltlen = TYPE_LENGTH (elttype);
          len = TYPE_LENGTH (type) / eltlen;
+         if (arrayprint)
+           print_spaces_filtered (2 + 2 * recurse, stream);
          fprintf_filtered (stream, "{");
          /* For an array of chars, print with string syntax.  */
          if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
-             && format == 0)
+             && (format == 0 || format == 's') )
            print_string (stream, valaddr, len, 0);
          else
            {
@@ -306,11 +681,18 @@ val_print (type, valaddr, address, stream, format,
                  /* Position of the array element we are examining to see
                     whether it is repeated.  */
                  unsigned int rep1;
-                 /* Number of repititions we have detected so far.  */
+                 /* Number of repetitions we have detected so far.  */
                  unsigned int reps;
                  
-                 if (i > 0)
-                   fprintf_filtered (stream, ", ");
+                 if (i != 0)
+                   if (arrayprint)
+                     {
+                       fprintf_filtered (stream, ",\n");
+                       print_spaces_filtered (2 + 2 * recurse, stream);
+                     }
+                   else
+                     fprintf_filtered (stream, ", ");
+                   wrap_here (n_spaces (2 + 2 * recurse));
                  
                  rep1 = i + 1;
                  reps = 1;
@@ -349,7 +731,7 @@ val_print (type, valaddr, address, stream, format,
       valaddr = (char *) &address;
 
     case TYPE_CODE_PTR:
-      if (format)
+      if (format && format != 's')
        {
          print_scalar_formatted (valaddr, type, format, 0, stream);
          break;
@@ -357,7 +739,6 @@ val_print (type, valaddr, address, stream, format,
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
        {
          struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
-         struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
          struct fn_field *f;
          int j, len2;
          char *kind = "";
@@ -408,7 +789,7 @@ val_print (type, valaddr, address, stream, format,
              type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
              fprintf (stream, kind);
              if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
-                 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
+                 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
                type_print_method_args
                  (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
                   TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
@@ -425,8 +806,6 @@ val_print (type, valaddr, address, stream, format,
       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
        {
          struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
-         struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
-         char *kind = "";
 
          /* VAL is a byte offset into the structure type DOMAIN.
             Find the name of the field for that offset and
@@ -436,15 +815,14 @@ val_print (type, valaddr, address, stream, format,
          len = TYPE_NFIELDS (domain);
          /* @@ Make VAL into bit offset */
          val = unpack_long (builtin_type_int, valaddr) << 3;
-         for (i = 0; i < len; i++)
+         for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
            {
              int bitpos = TYPE_FIELD_BITPOS (domain, i);
              QUIT;
              if (val == bitpos)
                break;
-             if (val < bitpos && i > 0)
+             if (val < bitpos && i != 0)
                {
-                 int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target));
                  /* Somehow pointing into a field.  */
                  i -= 1;
                  extra = (val - TYPE_FIELD_BITPOS (domain, i));
@@ -471,77 +849,132 @@ val_print (type, valaddr, address, stream, format,
        }
       else
        {
-         fprintf_filtered (stream, "0x%x", * (int *) valaddr);
+         CORE_ADDR addr = (CORE_ADDR) unpack_long (type, valaddr);
+         elttype = TYPE_TARGET_TYPE (type);
+
+         if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
+           {
+             /* Try to print what function it points to.  */
+             print_address_demangle (addr, stream, demangle);
+             /* Return value is irrelevant except for string pointers.  */
+             return 0;
+           }
+
+         if (addressprint && format != 's')
+           fprintf_filtered (stream, "0x%x", addr);
+
          /* For a pointer to char or unsigned char,
             also print the string pointed to, unless pointer is null.  */
-         
-         /* For an array of chars, print with string syntax.  */
-         elttype = TYPE_TARGET_TYPE (type);
          i = 0;                /* Number of characters printed.  */
          if (TYPE_LENGTH (elttype) == 1 
              && TYPE_CODE (elttype) == TYPE_CODE_INT
-             && format == 0
-             && unpack_long (type, valaddr) != 0
+             && (format == 0 || format == 's')
+             && addr != 0
              /* If print_max is UINT_MAX, the alloca below will fail.
                 In that case don't try to print the string.  */
              && print_max < UINT_MAX)
            {
-             fprintf_filtered (stream, " ");
-
+             int first_addr_err = 0;
+             int errcode = 0;
+             
              /* Get first character.  */
-             if (read_memory ( (CORE_ADDR) unpack_long (type, valaddr),
-                              &c, 1))
+             errcode = target_read_memory (addr, (char *)&c, 1);
+             if (errcode != 0)
                {
                  /* First address out of bounds.  */
-                 fprintf_filtered (stream, "<Address 0x%x out of bounds>",
-                          (* (int *) valaddr));
-                 break;
+                 first_addr_err = 1;
                }
              else
                {
                  /* A real string.  */
-                 int out_of_bounds = 0;
                  char *string = (char *) alloca (print_max);
 
                  /* If the loop ends by us hitting print_max characters,
                     we need to have elipses at the end.  */
                  int force_ellipses = 1;
 
-                 /* This loop only fetches print_max characters, even
-                    though print_string might want to print more
+                 /* This loop always fetches print_max characters, even
+                    though print_string might want to print more or fewer
                     (with repeated characters).  This is so that
                     we don't spend forever fetching if we print
                     a long string consisting of the same character
-                    repeated.  */
-                 while (i < print_max)
-                   {
-                     QUIT;
-                     if (read_memory ((CORE_ADDR) unpack_long (type, valaddr)
-                                      + i, &c, 1))
-                       {
-                         out_of_bounds = 1;
-                         force_ellipses = 0;
-                         break;
-                       }
-                     else if (c == '\0')
+                    repeated.  Also so we can do it all in one memory
+                    operation, which is faster.  However, this will be
+                    slower if print_max is set high, e.g. if you set
+                    print_max to 1000, not only will it take a long
+                    time to fetch short strings, but if you are near
+                    the end of the address space, it might not work.
+                    FIXME.  */
+                 QUIT;
+                 errcode = target_read_memory (addr, string, print_max);
+                 if (errcode != 0)
+                     force_ellipses = 0;
+                 else 
+                   for (i = 0; i < print_max; i++)
+                     if (string[i] == '\0')
                        {
                          force_ellipses = 0;
                          break;
-                       }
+                       }
+                 QUIT;
+
+                 if (addressprint)
+                   fputs_filtered (" ", stream);
+                 print_string (stream, string, i, force_ellipses);
+               }
+
+             if (errcode != 0)
+               {
+                 if (errcode == EIO)
+                   {
+                     fprintf_filtered (stream,
+                                       (" <Address 0x%x out of bounds>"
+                                        + first_addr_err),
+                                       addr + i);
+                   }
+                 else
+                   {
+                     if (errcode >= sys_nerr || errcode < 0)
+                       error ("Error reading memory address 0x%x: unknown error (%d).",
+                              addr + i, errcode);
                      else
-                       string[i++] = c;
+                       error ("Error reading memory address 0x%x: %s.",
+                              addr + i, sys_errlist[errcode]);
                    }
-
-                 if (i != 0)
-                   print_string (stream, string, i, force_ellipses);
-                 if (out_of_bounds)
-                   fprintf_filtered (stream,
-                                     " <Address 0x%x out of bounds>",
-                                     (*(int *) valaddr) + i);
                }
 
              fflush (stream);
            }
+         else /* print vtbl's nicely */
+         if (is_vtbl_member(type))
+           {
+             CORE_ADDR vt_address = (CORE_ADDR) unpack_long (type, valaddr);
+
+             int vt_index = find_pc_misc_function (vt_address);
+             if (vt_index >= 0
+                 && vt_address == misc_function_vector[vt_index].address)
+               {
+                 fputs_filtered (" <", stream);
+                 fputs_demangled (misc_function_vector[vt_index].name,
+                                  stream, 1);
+                 fputs_filtered (">", stream);
+               }
+             if (vtblprint)
+               {
+                 value val;
+
+                 val = value_at (TYPE_TARGET_TYPE (type), vt_address);
+                 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
+                            VALUE_ADDRESS (val), stream, format,
+                            deref_ref, recurse + 1, pretty);
+                 if (pretty)
+                   {
+                     fprintf_filtered (stream, "\n");
+                     print_spaces_filtered (2 + 2 * recurse, stream);
+                   }
+               }
+             }
+
          /* Return number of characters printed, plus one for the
             terminating null if we have "reached the end".  */
          return i + (print_max && i != print_max);
@@ -553,19 +986,27 @@ val_print (type, valaddr, address, stream, format,
       break;
 
     case TYPE_CODE_REF:
-      fprintf_filtered (stream, "(0x%x &) = ", * (int *) valaddr);
+      if (addressprint)
+        {
+         fprintf_filtered (stream, "@0x%lx",
+                           unpack_long (builtin_type_int, valaddr));
+         if (deref_ref)
+           fputs_filtered (": ", stream);
+        }
       /* De-reference the reference.  */
       if (deref_ref)
        {
          if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
            {
-             value val = value_at (TYPE_TARGET_TYPE (type), * (int *) valaddr);
+             value val = value_at (TYPE_TARGET_TYPE (type),
+                                   (CORE_ADDR) unpack_long (builtin_type_int,
+                                                            valaddr));
              val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
                         VALUE_ADDRESS (val), stream, format,
                         deref_ref, recurse + 1, pretty);
            }
          else
-           fprintf_filtered (stream, "???");
+           fputs_filtered ("???", stream);
        }
       break;
 
@@ -577,78 +1018,15 @@ val_print (type, valaddr, address, stream, format,
        }
       /* Fall through.  */
     case TYPE_CODE_STRUCT:
-      fprintf_filtered (stream, "{");
-      len = TYPE_NFIELDS (type);
-      n_baseclasses = TYPE_N_BASECLASSES (type);
-      for (i = 1; i <= n_baseclasses; i++)
+      if (vtblprint && is_vtbl_ptr_type(type))
        {
-         fprintf_filtered (stream, "\n");
-         if (pretty)
-           print_spaces_filtered (2 + 2 * recurse, stream);
-         fputs_filtered ("<", stream);
-         fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type, i)), stream);
-         fputs_filtered ("> = ", stream);
-         val_print (TYPE_FIELD_TYPE (type, 0),
-                    valaddr + TYPE_FIELD_BITPOS (type, i-1) / 8,
-                    0, stream, 0, 0, recurse + 1, pretty);
-       }
-      if (i > 1) {
-       fprintf_filtered (stream, "\n");
-       print_spaces_filtered (2 + 2 * recurse, stream);
-       fputs_filtered ("members of ", stream);
-        fputs_filtered (TYPE_NAME (type), stream);
-        fputs_filtered (": ", stream);
-      }
-      if (!len && i == 1)
-       fprintf_filtered (stream, "<No data fields>");
-      else
-       {
-         for (i -= 1; i < len; i++)
-           {
-             if (i > n_baseclasses) fprintf_filtered (stream, ", ");
-             if (pretty)
-               {
-                 fprintf_filtered (stream, "\n");
-                 print_spaces_filtered (2 + 2 * recurse, stream);
-               }
-             fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
-             fputs_filtered (" = ", stream);
-             /* check if static field */
-             if (TYPE_FIELD_STATIC (type, i))
-               {
-                 value v;
-                 
-                 v = value_static_field (type, TYPE_FIELD_NAME (type, i), i);
-                 val_print (TYPE_FIELD_TYPE (type, i),
-                            VALUE_CONTENTS (v), 0, stream, format,
-                            deref_ref, recurse + 1, pretty);
-               }
-             else if (TYPE_FIELD_PACKED (type, i))
-               {
-                 char *valp = (char *) & val;
-                 union {int i; char c;} test;
-                 test.i = 1;
-                 if (test.c != 1)
-                   valp += sizeof val - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i));
-                 val = unpack_field_as_long (type, valaddr, i);
-                 val_print (TYPE_FIELD_TYPE (type, i), valp, 0,
-                            stream, format, deref_ref, recurse + 1, pretty);
-               }
-             else
-               {
-                 val_print (TYPE_FIELD_TYPE (type, i), 
-                            valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
-                            0, stream, format, deref_ref,
-                            recurse + 1, pretty);
-               }
-           }
-         if (pretty)
-           {
-             fprintf_filtered (stream, "\n");
-             print_spaces_filtered (2 * recurse, stream);
-           }
+          /* Print the unmangled name if desired.  */
+         print_address_demangle(*((int *) (valaddr +   /* FIXME bytesex */
+             TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
+             stream, demangle);
+         break;
        }
-      fprintf_filtered (stream, "}");
+      val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
       break;
 
     case TYPE_CODE_ENUM:
@@ -680,13 +1058,76 @@ val_print (type, valaddr, address, stream, format,
       fprintf_filtered (stream, "{");
       type_print (type, "", stream, -1);
       fprintf_filtered (stream, "} ");
-      fprintf_filtered (stream, "0x%x", address);
+      if (addressprint)
+       fprintf_filtered (stream, "0x%x", address);
       break;
 
     case TYPE_CODE_INT:
-      if (format)
+      if (format || output_format)
        {
-         print_scalar_formatted (valaddr, type, format, 0, stream);
+         print_scalar_formatted (valaddr, type,
+                                 format? format: output_format,
+                                 0, stream);
+         break;
+       }
+      if (TYPE_LENGTH (type) > sizeof (LONGEST))
+       {
+         if (TYPE_UNSIGNED (type))
+           {
+             /* First figure out whether the number in fact has zeros
+                in all its bytes more significant than least significant
+                sizeof (LONGEST) ones.  */
+             char *p;
+             /* Pointer to first (i.e. lowest address) nonzero character.  */
+             char *first_addr;
+             unsigned len = TYPE_LENGTH (type);
+
+#if TARGET_BYTE_ORDER == BIG_ENDIAN
+             for (p = valaddr;
+                  len > sizeof (LONGEST)
+                  && p < valaddr + TYPE_LENGTH (type);
+                  p++)
+#else /* Little endian.  */
+             first_addr = valaddr;
+             for (p = valaddr + TYPE_LENGTH (type);
+                  len > sizeof (LONGEST) && p >= valaddr;
+                  p--)
+#endif /* Little endian.  */
+               {
+                 if (*p == 0)
+                   len--;
+                 else
+                   break;
+               }
+#if TARGET_BYTE_ORDER == BIG_ENDIAN
+             first_addr = p;
+#endif
+             
+             if (len <= sizeof (LONGEST))
+               {
+                 /* We can print it in decimal.  */
+                 fprintf_filtered
+                   (stream, 
+#if defined (LONG_LONG)
+                    "%llu",
+#else
+                    "%lu",
+#endif
+                    unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
+               }
+             else
+               {
+                 /* It is big, so print it in hex.  */
+                 print_hex_chars (stream, (unsigned char *)first_addr, len);
+               }
+           }
+         else
+           {
+             /* Signed.  One could assume two's complement (a reasonable
+                assumption, I think) and do better than this.  */
+             print_hex_chars (stream, (unsigned char *)valaddr,
+                              TYPE_LENGTH (type));
+           }
          break;
        }
 #ifdef PRINT_TYPELESS_INTEGER
@@ -714,34 +1155,26 @@ val_print (type, valaddr, address, stream, format,
 
     case TYPE_CODE_FLT:
       if (format)
-       {
-         print_scalar_formatted (valaddr, type, format, 0, stream);
-         break;
-       }
-#ifdef IEEE_FLOAT
-      if (is_nan ((char *) valaddr, TYPE_LENGTH (type)))
-       {
-         fprintf_filtered (stream, "NaN");
-         break;
-       }
-#endif
-      {
-       double doub;
-       int inv;
-
-       doub = unpack_double (type, valaddr, &inv);
-       if (inv)
-         fprintf_filtered (stream, "Invalid float value");
-       else
-         fprintf_filtered (stream,
-                           TYPE_LENGTH (type) <= 4? "%.6g": "%.16g", doub);
-      }
+       print_scalar_formatted (valaddr, type, format, 0, stream);
+      else
+       print_floating (valaddr, type, stream);
       break;
 
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
 
+    case TYPE_CODE_UNDEF:
+      /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
+        dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
+        and no complete type for struct foo in that file.  */
+      fprintf_filtered (stream, "<unknown struct>");
+      break;
+
+    case TYPE_CODE_ERROR:
+      fprintf_filtered (stream, "?");
+      break;
+
     default:
       error ("Invalid type code in symbol table.");
     }
@@ -749,51 +1182,9 @@ val_print (type, valaddr, address, stream, format,
   return 0;
 }
 \f
-#ifdef IEEE_FLOAT
-
-/* Nonzero if ARG (a double) is a NAN.  */
-
-int
-is_nan (fp, len)
-     char *fp;
-     int len;
-{
-  int lowhalf, highhalf;
-  union ieee
-    {
-      long i[2];               /* ASSUMED 32 BITS */
-      float f;         /* ASSUMED 32 BITS */
-      double d;                /* ASSUMED 64 BITS */
-    } *arg;
-
-  arg = (union ieee *)fp;
-
-  /*
-   * Single precision float.
-   */
-  if (len == sizeof(long))
-    {
-      highhalf = arg->i[0];
-      return ((((highhalf >> 23) & 0xFF) == 0xFF) 
-             && 0 != (highhalf & 0x7FFFFF));
-    }
-  
-  /* Separate the high and low words of the double.
-     Distinguish big and little-endian machines.  */
-#ifdef WORDS_BIG_ENDIAN
-    lowhalf = arg->i[1], highhalf = arg->i[0];
-#else
-    lowhalf = arg->i[0], highhalf = arg->i[1];
-#endif
-  
-  /* Nan: exponent is the maximum possible, and fraction is nonzero.  */
-  return (((highhalf>>20) & 0x7ff) == 0x7ff
-         && ! ((highhalf & 0xfffff == 0) && (lowhalf == 0)));
-}
-#endif
-\f
 /* Print a description of a type TYPE
    in the form of a declaration of a variable named VARSTRING.
+   (VARSTRING is demangled if necessary.)
    Output goes to STREAM (via stdio).
    If SHOW is positive, we show the contents of the outermost level
    of structure even if there is a type name that could be used instead.
@@ -835,7 +1226,8 @@ type_print_1 (type, varstring, stream, show, level)
        || code == TYPE_CODE_REF)))
     fprintf_filtered (stream, " ");
   type_print_varspec_prefix (type, stream, show, 0);
-  fputs_filtered (varstring, stream);
+  fputs_demangled (varstring, stream, -1);     /* Print demangled name
+                                                  without arguments */
   type_print_varspec_suffix (type, stream, show, 0);
 }
 
@@ -850,8 +1242,8 @@ type_print_method_args (args, prefix, varstring, staticp, stream)
   int i;
 
   fputs_filtered (" ", stream);
-  fputs_filtered (prefix, stream);
-  fputs_filtered (varstring, stream);
+  fputs_demangled (prefix, stream, 1);
+  fputs_demangled (varstring, stream, 1);
   fputs_filtered (" (", stream);
   if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
     {
@@ -887,41 +1279,33 @@ type_print_derivation_info (stream, type)
   int i, n_baseclasses = TYPE_N_BASECLASSES (type);
   struct type *basetype = 0;
 
-  while (type && n_baseclasses == 1)
-    {
-      basetype = TYPE_BASECLASS (type, 1);
-      if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
-       {
-         while (*name != ' ') name++;
-         fprintf_filtered (stream, ": %s%s ",
-                  TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
-                  TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
-         fputs_filtered (name + 1, stream);
-         fputs_filtered (" ", stream);
-       }
-      n_baseclasses = TYPE_N_BASECLASSES (basetype);
-      type = basetype;
-    }
-
-  if (type)
+  while (type && n_baseclasses > 0)
     {
-      if (n_baseclasses != 0)
-       fprintf_filtered (stream, ": ");
-      for (i = 1; i <= n_baseclasses; i++)
+      /* Not actually sure about this one -- Bryan. */
+      check_stub_type (type);
+      
+      fprintf_filtered (stream, ": ");
+      for (i = 0; ;)
        {
          basetype = TYPE_BASECLASS (type, i);
-         if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
+         if (name = type_name_no_tag (basetype))
            {
-             while (*name != ' ') name++;
              fprintf_filtered (stream, "%s%s ",
-                      TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
-                      TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "");
-             fputs_filtered (name + 1, stream);
+                      BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private",
+                      BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
+             fputs_filtered (name, stream);
            }
-         if (i < n_baseclasses)
-           fprintf_filtered (stream, ", ");
+         i++;
+         if (i >= n_baseclasses)
+             break;
+         fprintf_filtered (stream, ", ");
        }
+
       fprintf_filtered (stream, " ");
+      if (n_baseclasses != 1)
+       break;
+      n_baseclasses = TYPE_N_BASECLASSES (basetype);
+      type = basetype;
     }
 }
 
@@ -994,6 +1378,18 @@ type_print_varspec_prefix (type, stream, show, passed_a_ptr)
                                 0);
       if (passed_a_ptr)
        fprintf_filtered (stream, "(");
+
+    case TYPE_CODE_UNDEF:
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_INT:
+    case TYPE_CODE_FLT:
+    case TYPE_CODE_VOID:
+    case TYPE_CODE_ERROR:
+      /* These types need no prefix.  They are listed here so that
+        gcc -Wall will reveal any types that haven't been handled.  */
+      break;
     }
 }
 
@@ -1076,6 +1472,18 @@ type_print_varspec_suffix (type, stream, show, passed_a_ptr)
        fprintf_filtered (stream, ")");
       fprintf_filtered (stream, "()");
       break;
+
+    case TYPE_CODE_UNDEF:
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_INT:
+    case TYPE_CODE_FLT:
+    case TYPE_CODE_VOID:
+    case TYPE_CODE_ERROR:
+      /* These types do not need a suffix.  They are listed so that
+        gcc -Wall will report types that may not have been considered.  */
+      break;
     }
 }
 
@@ -1136,18 +1544,17 @@ type_print_base (type, stream, show, level)
     case TYPE_CODE_UNION:
       fprintf_filtered (stream, "union ");
     struct_union:
-      if (TYPE_NAME (type) && (name = TYPE_NAME (type)))
+      if (name = type_name_no_tag (type))
        {
-         while (*name != ' ') name++;
-         fputs_filtered (name + 1, stream);
+         fputs_filtered (name, stream);
          fputs_filtered (" ", stream);
        }
       if (show < 0)
        fprintf_filtered (stream, "{...}");
       else
        {
-         int i;
-
+         check_stub_type (type);
+         
          type_print_derivation_info (stream, type);
          
          fprintf_filtered (stream, "{");
@@ -1168,8 +1575,8 @@ type_print_base (type, stream, show, level)
            {
              QUIT;
              /* Don't print out virtual function table.  */
-             if (! strncmp (TYPE_FIELD_NAME (type, i),
-                          "_vptr$", 6))
+             if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
+                 !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
                continue;
 
              print_spaces_filtered (level + 4, stream);
@@ -1211,8 +1618,34 @@ type_print_base (type, stream, show, level)
                  else if (TYPE_FN_FIELD_STATIC_P (f, j))
                    fprintf_filtered (stream, "static ");
                  type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0);
-                 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
-                     && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
+                 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB)
+                   {
+                     /* Build something we can demangle.  */
+                     char *strchr (), *gdb_mangle_typename ();
+                     char *inner_name = gdb_mangle_typename (type);
+                     char *mangled_name
+                       = (char *)xmalloc (strlen (TYPE_FN_FIELDLIST_NAME (type, i))
+                                         + strlen (inner_name)
+                                         + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
+                                         + 1);
+                     char *demangled_name, *cplus_demangle ();
+                     strcpy (mangled_name, TYPE_FN_FIELDLIST_NAME (type, i));
+                     strcat (mangled_name, inner_name);
+                     strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
+                     demangled_name = cplus_demangle (mangled_name, 1);
+                     if (demangled_name == 0)
+                       fprintf_filtered (stream, " <badly mangled name %s>",
+                           mangled_name);
+                     else 
+                       {
+                         fprintf_filtered (stream, " %s",
+                             strchr (demangled_name, ':') + 2);
+                         free (demangled_name);
+                       }
+                     free (mangled_name);
+                   }
+                 else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
+                       && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
                    type_print_method_args
                      (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
                       TYPE_FN_FIELDLIST_NAME (type, i), 0, stream);
@@ -1224,7 +1657,6 @@ type_print_base (type, stream, show, level)
 
                  fprintf_filtered (stream, ";\n");
                }
-             if (len2) fprintf_filtered (stream, "\n");
            }
 
          print_spaces_filtered (level, stream);
@@ -1234,11 +1666,9 @@ type_print_base (type, stream, show, level)
 
     case TYPE_CODE_ENUM:
       fprintf_filtered (stream, "enum ");
-      if (TYPE_NAME (type))
+      if (name = type_name_no_tag (type))
        {
-         name = TYPE_NAME (type);
-         while (*name != ' ') name++;
-         fputs_filtered (name + 1, stream);
+         fputs_filtered (name, stream);
          fputs_filtered (" ", stream);
        }
       if (show < 0)
@@ -1255,7 +1685,7 @@ type_print_base (type, stream, show, level)
              fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
              if (lastval != TYPE_FIELD_BITPOS (type, i))
                {
-                 fprintf_filtered (stream, " : %d", TYPE_FIELD_BITPOS (type, i));
+                 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
                  lastval = TYPE_FIELD_BITPOS (type, i);
                }
              lastval++;
@@ -1265,10 +1695,18 @@ type_print_base (type, stream, show, level)
       break;
 
     case TYPE_CODE_INT:
-      if (TYPE_UNSIGNED (type))
-       name = unsigned_type_table[TYPE_LENGTH (type)];
+      if (TYPE_LENGTH (type) > sizeof (LONGEST))
+       {
+         fprintf_filtered (stream, "<%d bit integer>",
+                           TYPE_LENGTH (type) * TARGET_CHAR_BIT);
+       }
       else
-       name = signed_type_table[TYPE_LENGTH (type)];
+       {
+         if (TYPE_UNSIGNED (type))
+           name = unsigned_type_table[TYPE_LENGTH (type)];
+         else
+           name = signed_type_table[TYPE_LENGTH (type)];
+       }
       fputs_filtered (name, stream);
       break;
 
@@ -1285,80 +1723,187 @@ type_print_base (type, stream, show, level)
       fprintf_filtered (stream, "struct unknown");
       break;
 
+    case TYPE_CODE_ERROR:
+      fprintf_filtered (stream, "<unknown type>");
+      break;
+
     default:
       error ("Invalid type code in symbol table.");
     }
 }
 \f
+/* Validate an input or output radix setting, and make sure the user
+   knows what they really did here.  Radix setting is confusing, e.g.
+   setting the input radix to "10" never changes it!  */
+
 static void
-set_maximum_command (arg)
-     char *arg;
+set_input_radix (args, from_tty, c)
+     char *args;
+     int from_tty;
+     struct cmd_list_element *c;
 {
-  if (!arg) error_no_arg ("value for maximum elements to print");
-  print_max = parse_and_eval_address (arg);
-  if (print_max == 0)
-    print_max = UINT_MAX;
+  unsigned radix = *(unsigned *)c->var;
+
+  if (from_tty)
+    printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
+       radix, radix, radix);
 }
 
 static void
-set_prettyprint_command (arg, from_tty)
-     char *arg;
+set_output_radix (args, from_tty, c)
+     char *args;
      int from_tty;
+     struct cmd_list_element *c;
 {
-  prettyprint = parse_binary_operation ("set prettyprint", arg);
+  unsigned radix = *(unsigned *)c->var;
+
+  if (from_tty)
+    printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
+       radix, radix, radix);
+
+  /* FIXME, we really should be able to validate the setting BEFORE
+     it takes effect.  */
+  switch (radix)
+    {
+    case 16:
+      output_format = 'x';
+      break;
+    case 10:
+      output_format = 0;
+      break;
+    case 8:
+      output_format = 'o';             /* octal */
+      break;
+    default:
+      output_format = 0;
+      error ("Unsupported radix ``decimal %d''; using decimal output",
+             radix);
+    }
 }
 
+/* Both at once */
 static void
-set_unionprint_command (arg, from_tty)
+set_radix (arg, from_tty, c)
      char *arg;
      int from_tty;
+     struct cmd_list_element *c;
 {
-  unionprint = parse_binary_operation ("set unionprint", arg);
+  unsigned radix = *(unsigned *)c->var;
+
+  if (from_tty)
+    printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
+       radix, radix, radix);
+
+  input_radix = radix;
+  output_radix = radix;
+
+  set_output_radix (arg, 0, c);
 }
+\f
+struct cmd_list_element *setprintlist = NULL;
+struct cmd_list_element *showprintlist = NULL;
 
-format_info (arg, from_tty)
+/*ARGSUSED*/
+static void
+set_print (arg, from_tty)
      char *arg;
      int from_tty;
 {
-  if (arg)
-    error ("\"info format\" does not take any arguments.");
-  printf ("Prettyprinting of structures is %s.\n",
-         prettyprint ? "on" : "off");
-  printf ("Printing of unions interior to structures is %s.\n",
-         unionprint ? "on" : "off");
-  if (print_max == UINT_MAX)
-    printf_filtered
-      ("There is no maximum number of array elements printed.\n");
-  else
-    printf_filtered
-      ("The maximum number of array elements printed is %d.\n", print_max);
+  printf (
+"\"set print\" must be followed by the name of a print subcommand.\n");
+  help_list (setprintlist, "set print ", -1, stdout);
 }
 
-extern struct cmd_list_element *setlist;
-
+/*ARGSUSED*/
+static void
+show_print (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  cmd_show_list (showprintlist, from_tty, "");
+}
+\f
 void
 _initialize_valprint ()
 {
-  add_cmd ("array-max", class_vars, set_maximum_command,
-          "Set NUMBER as limit on string chars or array elements to print.\n\
-\"set array-max 0\" causes there to be no limit.",
-          &setlist);
-
-  add_cmd ("prettyprint", class_support, set_prettyprint_command,
-          "Turn prettyprinting of structures on and off.",
-          &setlist);
-  add_alias_cmd ("pp", "prettyprint", class_support, 1, &setlist);
-
-  add_cmd ("unionprint", class_support, set_unionprint_command,
-          "Turn printing of unions interior to structures on and off.",
-          &setlist);
-
-  add_info ("format", format_info,
-           "Show current settings of data formatting options.");
+  struct cmd_list_element *c;
+
+  add_prefix_cmd ("print", no_class, set_print,
+                 "Generic command for setting how things print.",
+                 &setprintlist, "set print ", 0, &setlist);
+  add_prefix_cmd ("print", no_class, show_print,
+                 "Generic command for showing print settings.",
+                 &showprintlist, "show print ", 0, &showlist);
+
+  add_show_from_set
+    (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
+                 "Set limit on string chars or array elements to print.\n\
+\"set print elements 0\" causes there to be no limit.",
+                 &setprintlist),
+     &showprintlist);
+
+  add_show_from_set
+    (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
+                 "Set prettyprinting of structures.",
+                 &setprintlist),
+     &showprintlist);
+
+  add_show_from_set
+    (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
+                 "Set printing of unions interior to structures.",
+                 &setprintlist),
+     &showprintlist);
+  
+  add_show_from_set
+    (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
+                 "Set printing of C++ virtual function tables.",
+                 &setprintlist),
+     &showprintlist);
+
+  add_show_from_set
+    (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
+                 "Set prettyprinting of arrays.",
+                 &setprintlist),
+     &showprintlist);
+
+  add_show_from_set
+    (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
+                 "Set printing of addresses.",
+                 &setprintlist),
+     &showprintlist);
+
+#if 0
+  /* The "show radix" cmd isn't good enough to show two separate values.
+     The rest of the code works, but the show part is confusing, so don't
+     let them be set separately 'til we work out "show".  */
+  c = add_set_cmd ("input-radix", class_support, var_uinteger,
+                  (char *)&input_radix,
+                 "Set default input radix for entering numbers.",
+                 &setlist);
+  add_show_from_set (c, &showlist);
+  c->function = set_input_radix;
+
+  c = add_set_cmd ("output-radix", class_support, var_uinteger,
+                  (char *)&output_radix,
+                 "Set default output radix for printing of values.",
+                 &setlist);
+  add_show_from_set (c, &showlist);
+  c->function = set_output_radix;
+#endif 
+
+  c = add_set_cmd ("radix", class_support, var_uinteger,
+                  (char *)&output_radix,
+                 "Set default input and output number radix.",
+                 &setlist);
+  add_show_from_set (c, &showlist);
+  c->function = set_radix;
 
   /* Give people the defaults which they are used to.  */
   prettyprint = 0;
   unionprint = 1;
+  vtblprint = 0;
+  arrayprint = 0;
+  addressprint = 1;
 
   print_max = 200;
 
@@ -1389,5 +1934,5 @@ _initialize_valprint ()
   bzero (float_type_table, (1 + sizeof (double)));
   float_type_table[sizeof (float)] = "float";
   float_type_table[sizeof (double)] = "double";
+  obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));
 }
-
This page took 0.039579 seconds and 4 git commands to generate.