* ada-lang.c (ada_index_type): Update comment.
[deliverable/binutils-gdb.git] / gdb / valprint.c
index d13dc4cd20cc03397e8aa49e2b49fccdaa8cc882..756dc50a57ff585c5855a6696221ac102a148ad4 100644 (file)
@@ -34,6 +34,7 @@
 #include "doublest.h"
 #include "exceptions.h"
 #include "dfp.h"
+#include "python/python.h"
 
 #include <errno.h>
 
@@ -80,7 +81,9 @@ struct value_print_options user_print_options =
   0,                           /* print_array_indexes */
   0,                           /* deref_ref */
   1,                           /* static_field_print */
-  1                            /* pascal_static_field_print */
+  1,                           /* pascal_static_field_print */
+  0,                           /* raw */
+  0                            /* summary */
 };
 
 /* Initialize *OPTS to be a copy of the user print options.  */
@@ -214,6 +217,33 @@ show_addressprint (struct ui_file *file, int from_tty,
 }
 \f
 
+/* A helper function for val_print.  When printing in "summary" mode,
+   we want to print scalar arguments, but not aggregate arguments.
+   This function distinguishes between the two.  */
+
+static int
+scalar_type_p (struct type *type)
+{
+  CHECK_TYPEDEF (type);
+  while (TYPE_CODE (type) == TYPE_CODE_REF)
+    {
+      type = TYPE_TARGET_TYPE (type);
+      CHECK_TYPEDEF (type);
+    }
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_ARRAY:
+    case TYPE_CODE_STRUCT:
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_SET:
+    case TYPE_CODE_STRING:
+    case TYPE_CODE_BITSTRING:
+      return 0;
+    default:
+      return 1;
+    }
+}
+
 /* Print using the given LANGUAGE the data of type TYPE located at VALADDR
    (within GDB), which came from the inferior at address ADDRESS, onto
    stdio stream STREAM according to OPTIONS.
@@ -257,6 +287,23 @@ val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
       return (0);
     }
 
+  if (!options->raw)
+    {
+      ret = apply_val_pretty_printer (type, valaddr, embedded_offset,
+                                     address, stream, recurse, options,
+                                     language);
+      if (ret)
+       return ret;
+    }
+
+  /* Handle summary mode.  If the value is a scalar, print it;
+     otherwise, print an ellipsis.  */
+  if (options->summary && !scalar_type_p (type))
+    {
+      fprintf_filtered (stream, "...");
+      return 0;
+    }
+
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
       ret = language->la_val_print (type, valaddr, embedded_offset, address,
@@ -287,6 +334,13 @@ value_check_printable (struct value *val, struct ui_file *stream)
       return 0;
     }
 
+  if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
+    {
+      fprintf_filtered (stream, _("<internal function %s>"),
+                       value_internal_function_name (val));
+      return 0;
+    }
+
   return 1;
 }
 
@@ -308,7 +362,7 @@ common_val_print (struct value *val, struct ui_file *stream, int recurse,
     return 0;
 
   return val_print (value_type (val), value_contents_all (val),
-                   value_embedded_offset (val), VALUE_ADDRESS (val),
+                   value_embedded_offset (val), value_address (val),
                    stream, recurse, options, language);
 }
 
@@ -324,6 +378,18 @@ value_print (struct value *val, struct ui_file *stream,
   if (!value_check_printable (val, stream))
     return 0;
 
+  if (!options->raw)
+    {
+      int r = apply_val_pretty_printer (value_type (val),
+                                       value_contents_all (val),
+                                       value_embedded_offset (val),
+                                       value_address (val),
+                                       stream, 0, options,
+                                       current_language);
+      if (r)
+       return r;
+    }
+
   return LA_VALUE_PRINT (val, stream, options);
 }
 
@@ -919,7 +985,8 @@ print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
    Omit any leading zero chars.  */
 
 void
-print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
+print_char_chars (struct ui_file *stream, struct type *type,
+                 const gdb_byte *valaddr,
                  unsigned len, enum bfd_endian byte_order)
 {
   const gdb_byte *p;
@@ -932,7 +999,7 @@ print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
 
       while (p < valaddr + len)
        {
-         LA_EMIT_CHAR (*p, stream, '\'');
+         LA_EMIT_CHAR (*p, type, stream, '\'');
          ++p;
        }
     }
@@ -944,7 +1011,7 @@ print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
 
       while (p >= valaddr)
        {
-         LA_EMIT_CHAR (*p, stream, '\'');
+         LA_EMIT_CHAR (*p, type, stream, '\'');
          --p;
        }
     }
@@ -1226,13 +1293,14 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
      some error, such as bumping into the end of the address space.  */
 
   found_nul = 0;
-  old_chain = make_cleanup (null_cleanup, 0);
+  *buffer = NULL;
+
+  old_chain = make_cleanup (free_current_contents, buffer);
 
   if (len > 0)
     {
       *buffer = (gdb_byte *) xmalloc (len * width);
       bufptr = *buffer;
-      old_chain = make_cleanup (xfree, *buffer);
 
       nfetch = partial_memory_read (addr, bufptr, len * width, &errcode)
        / width;
@@ -1243,8 +1311,6 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
     {
       unsigned long bufsize = 0;
 
-      *buffer = NULL;
-
       do
        {
          QUIT;
@@ -1253,13 +1319,9 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
          if (*buffer == NULL)
            *buffer = (gdb_byte *) xmalloc (nfetch * width);
          else
-           {
-             discard_cleanups (old_chain);
-             *buffer = (gdb_byte *) xrealloc (*buffer,
-                                              (nfetch + bufsize) * width);
-           }
+           *buffer = (gdb_byte *) xrealloc (*buffer,
+                                            (nfetch + bufsize) * width);
 
-         old_chain = make_cleanup (xfree, *buffer);
          bufptr = *buffer + bufsize * width;
          bufsize += nfetch;
 
@@ -1320,7 +1382,8 @@ read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit,
    whichever is smaller.  */
 
 int
-val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream,
+val_print_string (struct type *elttype, CORE_ADDR addr, int len,
+                 struct ui_file *stream,
                  const struct value_print_options *options)
 {
   int force_ellipsis = 0;      /* Force ellipsis to be printed if nonzero.  */
@@ -1330,6 +1393,7 @@ val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream,
   int bytes_read;
   gdb_byte *buffer = NULL;     /* Dynamically growable fetch buffer.  */
   struct cleanup *old_chain = NULL;    /* Top of the old cleanup chain.  */
+  int width = TYPE_LENGTH (elttype);
 
   /* First we need to figure out the limit on the number of characters we are
      going to attempt to fetch and print.  This is actually pretty simple.  If
@@ -1383,7 +1447,7 @@ val_print_string (CORE_ADDR addr, int len, int width, struct ui_file *stream,
        {
          fputs_filtered (" ", stream);
        }
-      LA_PRINT_STRING (stream, buffer, bytes_read / width, width, force_ellipsis, options);
+      LA_PRINT_STRING (stream, elttype, buffer, bytes_read / width, force_ellipsis, options);
     }
 
   if (errcode != 0)
This page took 0.030195 seconds and 4 git commands to generate.