Introduce c_value_print_int
authorTom Tromey <tom@tromey.com>
Fri, 13 Mar 2020 23:39:52 +0000 (17:39 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 14 Mar 2020 00:03:41 +0000 (18:03 -0600)
This adds c_value_print_int, a value-based analogue of
c_val_print_int.

gdb/ChangeLog
2020-03-13  Tom Tromey  <tom@tromey.com>

* c-valprint.c (c_value_print_int): New function.
(c_value_print_inner): Use it.

gdb/ChangeLog
gdb/c-valprint.c

index 98223d4dfb6ec38e495667c95ef025ffe9bec9a6..b5d41ae130f1d18c577b1400f35895bce0205dcb 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-13  Tom Tromey  <tom@tromey.com>
+
+       * c-valprint.c (c_value_print_int): New function.
+       (c_value_print_inner): Use it.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
        * c-valprint.c (c_value_print_ptr): New function.
index 6cac9e0b578e61f11970b27f4b1fe598273dff0f..80ba5d7195aee58dc4ad3da446b8b02c4f8cb4eb 100644 (file)
@@ -502,6 +502,37 @@ c_val_print_int (struct type *type, struct type *unresolved_type,
     }
 }
 
+/* c_value_print helper for TYPE_CODE_INT.  */
+
+static void
+c_value_print_int (struct value *val, struct ui_file *stream,
+                  const struct value_print_options *options)
+{
+  if (options->format || options->output_format)
+    {
+      struct value_print_options opts = *options;
+
+      opts.format = (options->format ? options->format
+                    : options->output_format);
+      value_print_scalar_formatted (val, &opts, 0, stream);
+    }
+  else
+    {
+      value_print_scalar_formatted (val, options, 0, stream);
+      /* C and C++ has no single byte int type, char is used
+        instead.  Since we don't know whether the value is really
+        intended to be used as an integer or a character, print
+        the character equivalent as well.  */
+      struct type *type = value_type (val);
+      const gdb_byte *valaddr = value_contents_for_printing (val);
+      if (c_textual_element_type (type, options->format))
+       {
+         fputs_filtered (" ", stream);
+         LA_PRINT_CHAR (unpack_long (type, valaddr), type, stream);
+       }
+    }
+}
+
 /* c_val_print helper for TYPE_CODE_MEMBERPTR.  */
 
 static void
@@ -602,7 +633,6 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
                     const struct value_print_options *options)
 {
   struct type *type = value_type (val);
-  struct type *unresolved_type = type;
   CORE_ADDR address = value_address (val);
   const gdb_byte *valaddr = value_contents_for_printing (val);
 
@@ -633,8 +663,7 @@ c_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
       break;
 
     case TYPE_CODE_INT:
-      c_val_print_int (type, unresolved_type, valaddr, 0, stream,
-                      val, options);
+      c_value_print_int (val, stream, options);
       break;
 
     case TYPE_CODE_MEMBERPTR:
This page took 0.028825 seconds and 4 git commands to generate.