[34/55] Introduce generic_value_print_bool

Message ID 20191208182958.10181-35-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Dec. 8, 2019, 6:29 p.m. UTC
  This adds generic_value_print_bool, a value-based analogue of
generic_val_print_bool.

gdb/ChangeLog
2019-12-08  Tom Tromey  <tom@tromey.com>

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

Change-Id: I4f802a26430d4f430c32b605273d927e460bb20a
---
 gdb/ChangeLog  |  5 +++++
 gdb/valprint.c | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 5c25f98faf8..5b1b9cff804 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -763,6 +763,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
@@ -1064,8 +1093,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: