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 ada_value_print_array
Date: Sat, 14 Mar 2020 00:08:50 +0000 (GMT)	[thread overview]
Message-ID: <20200314000850.9BC97394B02F@sourceware.org> (raw)

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

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

    Introduce ada_value_print_array
    
    This adds ada_value_print_array, a value-based analogue of
    ada_val_print_array.  It also removes some unused parameters from a
    couple of helper functions.
    
    gdb/ChangeLog
    2020-03-13  Tom Tromey  <tom@tromey.com>
    
            * ada-valprint.c (val_print_packed_array_elements): Remove
            bitoffset and val parameters.  Call common_val_print.
            (ada_val_print_string): Remove offset, address, and original_value
            parameters.
            (ada_val_print_array): Update.
            (ada_value_print_array): New function.
            (ada_value_print_1): Call it.

Diff:
---
 gdb/ChangeLog      | 10 ++++++++
 gdb/ada-valprint.c | 71 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5cf5c9a80b0..3f8d8b1ef9b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2020-03-13  Tom Tromey  <tom@tromey.com>
+
+	* ada-valprint.c (val_print_packed_array_elements): Remove
+	bitoffset and val parameters.  Call common_val_print.
+	(ada_val_print_string): Remove offset, address, and original_value
+	parameters.
+	(ada_val_print_array): Update.
+	(ada_value_print_array): New function.
+	(ada_value_print_1): Call it.
+
 2020-03-13  Tom Tromey  <tom@tromey.com>
 
 	* ada-valprint.c (ada_value_print): Use common_val_print.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index dd8468ac5c0..fc34ca5e6e2 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -112,17 +112,15 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
 }
 
 /*  Version of val_print_array_elements for GNAT-style packed arrays.
-    Prints elements of packed array of type TYPE at bit offset
-    BITOFFSET from VALADDR on STREAM.  Formats according to OPTIONS and
-    separates with commas.  RECURSE is the recursion (nesting) level.
-    TYPE must have been decoded (as by ada_coerce_to_simple_array).  */
+    Prints elements of packed array of type TYPE from VALADDR on
+    STREAM.  Formats according to OPTIONS and separates with commas.
+    RECURSE is the recursion (nesting) level.  TYPE must have been
+    decoded (as by ada_coerce_to_simple_array).  */
 
 static void
 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
-				 int offset,
-				 int bitoffset, struct ui_file *stream,
+				 int offset, struct ui_file *stream,
 				 int recurse,
-				 struct value *val,
 				 const struct value_print_options *options)
 {
   unsigned int i;
@@ -230,9 +228,7 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 	  struct value_print_options opts = *options;
 
 	  opts.deref_ref = 0;
-	  val_print (elttype,
-		     value_embedded_offset (v0), 0, stream,
-		     recurse + 1, v0, &opts, current_language);
+	  common_val_print (v0, stream, recurse + 1, &opts, current_language);
 	  annotate_elt_rep (i - i0);
 	  fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
 			    metadata_style.style ().ptr (), i - i0, nullptr);
@@ -262,9 +258,8 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
 		  maybe_print_array_index (index_type, j + low,
 					   stream, options);
 		}
-	      val_print (elttype,
-			 value_embedded_offset (v0), 0, stream,
-			 recurse + 1, v0, &opts, current_language);
+	      common_val_print (v0, stream, recurse + 1, &opts,
+				current_language);
 	      annotate_elt ();
 	    }
 	}
@@ -715,9 +710,8 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
 
 static void
 ada_val_print_string (struct type *type, const gdb_byte *valaddr,
-		      int offset, int offset_aligned, CORE_ADDR address,
+		      int offset_aligned,
 		      struct ui_file *stream, int recurse,
-		      struct value *original_value,
 		      const struct value_print_options *options)
 {
   enum bfd_endian byte_order = type_byte_order (type);
@@ -1129,9 +1123,8 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
   if (ada_is_string_type (type)
       && (options->format == 0 || options->format == 's'))
     {
-      ada_val_print_string (type, valaddr, offset, offset_aligned,
-			    address, stream, recurse, original_value,
-			    options);
+      ada_val_print_string (type, valaddr, offset_aligned,
+			    stream, recurse, options);
       return;
     }
 
@@ -1139,8 +1132,7 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
   print_optional_low_bound (stream, type, options);
   if (TYPE_FIELD_BITSIZE (type, 0) > 0)
     val_print_packed_array_elements (type, valaddr, offset_aligned,
-				     0, stream, recurse,
-				     original_value, options);
+				     stream, recurse, options);
   else
     val_print_array_elements (type, offset_aligned, address,
 			      stream, recurse, original_value,
@@ -1148,6 +1140,41 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
   fprintf_filtered (stream, ")");
 }
 
+/* Implement Ada value_print'ing for the case where TYPE is a
+   TYPE_CODE_ARRAY.  */
+
+static void
+ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
+		       const struct value_print_options *options)
+{
+  struct type *type = ada_check_typedef (value_type (val));
+
+  /* For an array of characters, print with string syntax.  */
+  if (ada_is_string_type (type)
+      && (options->format == 0 || options->format == 's'))
+    {
+      const gdb_byte *valaddr = value_contents_for_printing (val);
+      int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
+
+      ada_val_print_string (type, valaddr, offset_aligned, stream, recurse,
+			    options);
+      return;
+    }
+
+  fprintf_filtered (stream, "(");
+  print_optional_low_bound (stream, type, options);
+  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
+    {
+      const gdb_byte *valaddr = value_contents_for_printing (val);
+      int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
+      val_print_packed_array_elements (type, valaddr, offset_aligned,
+				       stream, recurse, options);
+    }
+  else
+    value_print_array_elements (val, stream, recurse, options, 0);
+  fprintf_filtered (stream, ")");
+}
+
 /* Implement Ada val_print'ing for the case where TYPE is
    a TYPE_CODE_REF.  */
 
@@ -1390,9 +1417,7 @@ ada_value_print_1 (struct value *val, struct ui_file *stream, int recurse,
       break;
 
     case TYPE_CODE_ARRAY:
-      ada_val_print_array (type, valaddr, 0, 0,
-			   address, stream, recurse, val,
-			   options);
+      ada_value_print_array (val, stream, recurse, options);
       return;
 
     case TYPE_CODE_REF:


                 reply	other threads:[~2020-03-14  0:08 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=20200314000850.9BC97394B02F@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).