public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 5/7] Allow printing of complex integers
Date: Sat,  7 Mar 2020 08:22:44 -0700	[thread overview]
Message-ID: <20200307152246.32630-6-tom@tromey.com> (raw)
In-Reply-To: <20200307152246.32630-1-tom@tromey.com>

GCC allows complex integers, but gdb could not print them.  The
problem was that generic_val_print_complex assumed that complex
numbers have floating point components.  This patch corrects this
error.

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

	* valprint.c (generic_val_print_complex): Use
	val_print_scalar_formatted.
---
 gdb/ChangeLog  |  5 +++++
 gdb/valprint.c | 27 +++++++--------------------
 2 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/gdb/valprint.c b/gdb/valprint.c
index 8adbb3df457..93e118e12d5 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -886,28 +886,15 @@ generic_val_print_complex (struct type *type,
 			   const struct generic_val_print_decorations
 			     *decorations)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
-  int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
-  const gdb_byte *valaddr = value_contents_for_printing (original_value);
-
   fprintf_filtered (stream, "%s", decorations->complex_prefix);
-  if (options->format)
-    val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
-				embedded_offset, original_value, options, 0,
-				stream);
-  else
-    print_floating (valaddr + embedded_offset * unit_size,
-		    TYPE_TARGET_TYPE (type), stream);
+  val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+			      embedded_offset, original_value, options, 0,
+			      stream);
   fprintf_filtered (stream, "%s", decorations->complex_infix);
-  if (options->format)
-    val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
-				embedded_offset
-				+ type_length_units (TYPE_TARGET_TYPE (type)),
-				original_value, options, 0, stream);
-  else
-    print_floating (valaddr + embedded_offset * unit_size
-		    + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
-		    TYPE_TARGET_TYPE (type), stream);
+  val_print_scalar_formatted (TYPE_TARGET_TYPE (type),
+			      embedded_offset
+			      + type_length_units (TYPE_TARGET_TYPE (type)),
+			      original_value, options, 0, stream);
   fprintf_filtered (stream, "%s", decorations->complex_suffix);
 }
 
-- 
2.17.2


  parent reply	other threads:[~2020-03-07 15:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-07 15:22 [PATCH 0/7] Update complex number support Tom Tromey
2020-03-07 15:22 ` [PATCH 1/7] Change how complex types are created Tom Tromey
2020-03-07 15:22 ` [PATCH 2/7] Add accessors for members of complex numbers Tom Tromey
2020-03-07 15:22 ` [PATCH 3/7] Change how complex types are printed in C Tom Tromey
2020-03-07 15:22 ` [PATCH 4/7] Change the C parser to allow complex constants Tom Tromey
2020-03-07 15:22 ` Tom Tromey [this message]
2020-03-20 21:52   ` [PATCH 5/7] Allow printing of complex integers Tom Tromey
2020-03-07 15:22 ` [PATCH 6/7] Implement complex arithmetic Tom Tromey
2020-03-07 15:22 ` [PATCH 7/7] Add _Complex type support to C parser Tom Tromey

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=20200307152246.32630-6-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@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).