* amd64-tdep.c (amd64_return_value): Change type of readbuf and
[deliverable/binutils-gdb.git] / gdb / valprint.c
index 044ed21054650af40fe27b25184ca2a1a93db026..ac2d401aae939544854497d3c378e3e9f66ac3c2 100644 (file)
@@ -190,7 +190,7 @@ show_addressprint (struct ui_file *file, int from_tty,
 
 
 int
-val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
+val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
           CORE_ADDR address, struct ui_file *stream, int format,
           int deref_ref, int recurse, enum val_prettyprint pretty)
 {
@@ -217,25 +217,66 @@ val_print (struct type *type, const bfd_byte *valaddr, int embedded_offset,
                        stream, format, deref_ref, recurse, pretty));
 }
 
-/* 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.
-   If the object printed is a string pointer, returns
-   the number of string bytes printed.  */
+/* Check whether the value VAL is printable.  Return 1 if it is;
+   return 0 and print an appropriate error message to STREAM if it
+   is not.  */
 
-int
-value_print (struct value *val, struct ui_file *stream, int format,
-            enum val_prettyprint pretty)
+static int
+value_check_printable (struct value *val, struct ui_file *stream)
 {
   if (val == 0)
     {
-      printf_filtered (_("<address of value unknown>"));
+      fprintf_filtered (stream, _("<address of value unknown>"));
       return 0;
     }
+
   if (value_optimized_out (val))
     {
-      printf_filtered (_("<value optimized out>"));
+      fprintf_filtered (stream, _("<value optimized out>"));
       return 0;
     }
+
+  return 1;
+}
+
+/* Print the value VAL onto stream STREAM according to FORMAT (a
+   letter, or 0 for natural format using TYPE).
+
+   If DEREF_REF is nonzero, then dereference references, otherwise just print
+   them like pointers.
+
+   The PRETTY parameter controls prettyprinting.
+
+   If the data are a string pointer, returns the number of string characters
+   printed.
+
+   This is a preferable interface to val_print, above, because it uses
+   GDB's value mechanism.  */
+
+int
+common_val_print (struct value *val, struct ui_file *stream, int format,
+                 int deref_ref, int recurse, enum val_prettyprint pretty)
+{
+  if (!value_check_printable (val, stream))
+    return 0;
+
+  return val_print (value_type (val), value_contents_all (val),
+                   value_embedded_offset (val), VALUE_ADDRESS (val),
+                   stream, format, deref_ref, recurse, pretty);
+}
+
+/* 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.
+   If the object printed is a string pointer, returns
+   the number of string bytes printed.  */
+
+int
+value_print (struct value *val, struct ui_file *stream, int format,
+            enum val_prettyprint pretty)
+{
+  if (!value_check_printable (val, stream))
+    return 0;
+
   return LA_VALUE_PRINT (val, stream, format, pretty);
 }
 
@@ -244,7 +285,7 @@ value_print (struct value *val, struct ui_file *stream, int format,
    value.  STREAM is where to print the value.  */
 
 void
-val_print_type_code_int (struct type *type, const bfd_byte *valaddr,
+val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
                         struct ui_file *stream)
 {
   if (TYPE_LENGTH (type) > sizeof (LONGEST))
@@ -351,7 +392,7 @@ longest_to_int (LONGEST arg)
    TYPE_CODE_FLT), pointed to in GDB by VALADDR, on STREAM.  */
 
 void
-print_floating (const bfd_byte *valaddr, struct type *type,
+print_floating (const gdb_byte *valaddr, struct type *type,
                struct ui_file *stream)
 {
   DOUBLEST doub;
@@ -412,13 +453,13 @@ print_floating (const bfd_byte *valaddr, struct type *type,
 }
 
 void
-print_binary_chars (struct ui_file *stream, const bfd_byte *valaddr,
+print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
                    unsigned len)
 {
 
 #define BITS_IN_BYTES 8
 
-  const bfd_byte *p;
+  const gdb_byte *p;
   unsigned int i;
   int b;
 
@@ -472,10 +513,10 @@ print_binary_chars (struct ui_file *stream, const bfd_byte *valaddr,
  * Print it in octal on stream or format it in buf.
  */
 void
-print_octal_chars (struct ui_file *stream, const bfd_byte *valaddr,
+print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
                   unsigned len)
 {
-  const bfd_byte *p;
+  const gdb_byte *p;
   unsigned char octa1, octa2, octa3, carry;
   int cycle;
 
@@ -620,7 +661,7 @@ print_octal_chars (struct ui_file *stream, const bfd_byte *valaddr,
  * Print it in decimal on stream or format it in buf.
  */
 void
-print_decimal_chars (struct ui_file *stream, const bfd_byte *valaddr,
+print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
                     unsigned len)
 {
 #define TEN             10
@@ -637,7 +678,7 @@ print_decimal_chars (struct ui_file *stream, const bfd_byte *valaddr,
 #define LOW_NIBBLE(  x ) ( (x) & 0x00F)
 #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
 
-  const bfd_byte *p;
+  const gdb_byte *p;
   unsigned char *digits;
   int carry;
   int decimal_len;
@@ -755,10 +796,10 @@ print_decimal_chars (struct ui_file *stream, const bfd_byte *valaddr,
 /* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
 
 void
-print_hex_chars (struct ui_file *stream, const bfd_byte *valaddr,
+print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
                 unsigned len)
 {
-  const bfd_byte *p;
+  const gdb_byte *p;
 
   /* FIXME: We should be not printing leading zeroes in most cases.  */
 
@@ -787,10 +828,10 @@ print_hex_chars (struct ui_file *stream, const bfd_byte *valaddr,
    Omit any leading zero chars.  */
 
 void
-print_char_chars (struct ui_file *stream, const bfd_byte *valaddr,
+print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
                  unsigned len)
 {
-  const bfd_byte *p;
+  const gdb_byte *p;
 
   if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
@@ -828,7 +869,7 @@ print_char_chars (struct ui_file *stream, const bfd_byte *valaddr,
  */
 
 void
-val_print_array_elements (struct type *type, const bfd_byte *valaddr,
+val_print_array_elements (struct type *type, const gdb_byte *valaddr,
                          CORE_ADDR address, struct ui_file *stream,
                          int format, int deref_ref,
                          int recurse, enum val_prettyprint pretty,
This page took 0.025786 seconds and 4 git commands to generate.