Introduce generic_value_print_bool
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 generic_value_print_bool, a value-based analogue of
generic_val_print_bool.

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

* valprint.c (generic_value_print_bool): New function.
(generic_value_print): Use it.

gdb/ChangeLog
gdb/valprint.c

index c969b12bcad076e435507ad403a3ed1d4f8fbc72..1d15ca6c24a4d4895e46ad3241a6c5825664be60 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-13  Tom Tromey  <tom@tromey.com>
+
+       * valprint.c (generic_value_print_bool): New function.
+       (generic_value_print): Use it.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
        * valprint.c (generic_val_print_func): Simplify.
index 0517bf089f3c7e20b9b234a7dbf914e379e7fa11..56a2e99c860dedb3b85ed1eaf7882bd0b7201b83 100644 (file)
@@ -789,6 +789,35 @@ generic_val_print_bool (struct type *type,
     }
 }
 
+/* generic_value_print helper for TYPE_CODE_BOOL.  */
+
+static void
+generic_value_print_bool
+  (struct value *value, struct ui_file *stream,
+   const struct value_print_options *options,
+   const struct generic_val_print_decorations *decorations)
+{
+  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 (value, &opts, 0, stream);
+    }
+  else
+    {
+      const gdb_byte *valaddr = value_contents_for_printing (value);
+      struct type *type = check_typedef (value_type (value));
+      LONGEST val = unpack_long (type, valaddr);
+      if (val == 0)
+       fputs_filtered (decorations->false_name, stream);
+      else if (val == 1)
+       fputs_filtered (decorations->true_name, stream);
+      else
+       print_longest (stream, 'd', 0, val);
+    }
+}
+
 /* generic_val_print helper for TYPE_CODE_INT.  */
 
 static void
@@ -1090,8 +1119,7 @@ generic_value_print (struct value *val, struct ui_file *stream, int recurse,
       break;
 
     case TYPE_CODE_BOOL:
-      generic_val_print_bool (type, 0, stream,
-                             val, options, decorations);
+      generic_value_print_bool (val, stream, options, decorations);
       break;
 
     case TYPE_CODE_RANGE:
This page took 0.027692 seconds and 4 git commands to generate.