public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Introduce generic_value_print_bool
Date: Sat, 14 Mar 2020 00:07:17 +0000 (GMT)	[thread overview]
Message-ID: <20200314000717.3193D394B02F@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6dde752183769c712eb22f49a5b74bfadad4a6be

commit 6dde752183769c712eb22f49a5b74bfadad4a6be
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Mar 13 17:39:52 2020 -0600

    Introduce generic_value_print_bool
    
    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.

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

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c969b12bcad..1d15ca6c24a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0517bf089f3..56a2e99c860 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -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:


                 reply	other threads:[~2020-03-14  0:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200314000717.3193D394B02F@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).