[5/7] Allow printing of complex integers

Message ID 20200307152246.32630-6-tom@tromey.com
State New
Headers show
Series
  • Update complex number support
Related show

Commit Message

Tom Tromey March 7, 2020, 3:22 p.m.
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(-)

-- 
2.17.2

Comments

Tom Tromey March 20, 2020, 9:52 p.m. | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:


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

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

Tom> 	* valprint.c (generic_val_print_complex): Use
Tom> 	val_print_scalar_formatted.

It turns out I already fixed this in the val_print removal series, so
this patch is no longer needed.

Tom

Patch

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);
 }