public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 4/9] Remove the byte order parameter to target_read_string
Date: Wed, 13 Apr 2022 13:17:51 -0600	[thread overview]
Message-ID: <20220413191756.1146768-5-tromey@adacore.com> (raw)
In-Reply-To: <20220413191756.1146768-1-tromey@adacore.com>

target_read_string takes a byte order parameter, but only uses this to
check whether a given character is zero.  This is readily done without
requiring the parameter, so remove it.
---
 gdb/c-lang.c   |  2 +-
 gdb/target.c   |  3 +--
 gdb/valprint.c | 12 +++++++-----
 gdb/valprint.h |  1 -
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index a7ecf8f91da..be9ee073f58 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -353,7 +353,7 @@ c_get_string (struct value *value, gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 	fetchlimit = UINT_MAX;
 
       err = target_read_string (addr, *length, width, fetchlimit,
-				byte_order, buffer, length);
+				buffer, length);
       if (err != 0)
 	memory_error (TARGET_XFER_E_IO, addr);
     }
diff --git a/gdb/target.c b/gdb/target.c
index 6542305f0d0..5a416d5ee3a 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1406,8 +1406,7 @@ target_read_string (CORE_ADDR memaddr, int len, int *bytes_read)
     bytes_read = &ignore;
 
   /* Note that the endian-ness does not matter here.  */
-  int errcode = target_read_string (memaddr, -1, 1, len, BFD_ENDIAN_LITTLE,
-				    &buffer, bytes_read);
+  int errcode = target_read_string (memaddr, -1, 1, len, &buffer, bytes_read);
   if (errcode != 0)
     return {};
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index a4c0f7b343d..8f9954778c5 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -2052,7 +2052,6 @@ partial_memory_read (CORE_ADDR memaddr, gdb_byte *myaddr,
 int
 target_read_string (CORE_ADDR addr, int len, int width,
 		    unsigned int fetchlimit,
-		    enum bfd_endian byte_order,
 		    gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 		    int *bytes_read)
 {
@@ -2122,12 +2121,15 @@ target_read_string (CORE_ADDR addr, int len, int width,
 	  limit = bufptr + nfetch * width;
 	  while (bufptr < limit)
 	    {
-	      unsigned long c;
+	      bool found_nonzero = false;
+
+	      for (int i = 0; !found_nonzero && i < width; ++i)
+		if (bufptr[i] != 0)
+		  found_nonzero = true;
 
-	      c = extract_unsigned_integer (bufptr, width, byte_order);
 	      addr += width;
 	      bufptr += width;
-	      if (c == 0)
+	      if (!found_nonzero)
 		{
 		  /* We don't care about any error which happened after
 		     the NUL terminator.  */
@@ -2733,7 +2735,7 @@ val_print_string (struct type *elttype, const char *encoding,
   fetchlimit = (len == -1 ? options->print_max : std::min ((unsigned) len,
 							   options->print_max));
 
-  err = target_read_string (addr, len, width, fetchlimit, byte_order,
+  err = target_read_string (addr, len, width, fetchlimit,
 			    &buffer, &bytes_read);
 
   addr += bytes_read;
diff --git a/gdb/valprint.h b/gdb/valprint.h
index 2f4a5022b3e..b12495b10c1 100644
--- a/gdb/valprint.h
+++ b/gdb/valprint.h
@@ -167,7 +167,6 @@ extern void print_function_pointer_address (const struct value_print_options *op
 
 extern int target_read_string (CORE_ADDR addr, int len, int width,
 			       unsigned int fetchlimit,
-			       enum bfd_endian byte_order,
 			       gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 			       int *bytes_read);
 
-- 
2.34.1


  parent reply	other threads:[~2022-04-13 19:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13 19:17 [PATCH 0/9] Windows thread names Tom Tromey
2022-04-13 19:17 ` [PATCH 1/9] Fix possible Cygwin build problem Tom Tromey
2022-05-21 11:18   ` Jon Turney
2022-05-21 12:31     ` Eli Zaretskii
2022-05-26 17:00       ` Tom Tromey
2022-05-26 19:04         ` Eli Zaretskii
2022-06-02 14:12           ` Jon Turney
2022-06-02 16:04             ` Eli Zaretskii
2022-04-13 19:17 ` [PATCH 2/9] Don't call QUIT in read_string Tom Tromey
2022-04-13 19:17 ` [PATCH 3/9] Rename read_string Tom Tromey
2022-04-13 19:17 ` Tom Tromey [this message]
2022-04-13 19:17 ` [PATCH 5/9] Move target_read_string to target/target.c Tom Tromey
2022-04-13 19:17 ` [PATCH 6/9] Share handle_ms_vc_exception with gdbserver Tom Tromey
2022-04-13 19:17 ` [PATCH 7/9] Implement thread_name for gdbserver Tom Tromey
2022-04-13 19:17 ` [PATCH 8/9] Set the worker thread name on Windows Tom Tromey
2022-04-13 19:17 ` [PATCH 9/9] Use GetThreadDescription " Tom Tromey
2022-04-13 19:33   ` Eli Zaretskii
2022-04-14  5:26     ` Eli Zaretskii
2022-04-14 13:17       ` Tom Tromey
2022-04-14 13:51         ` Eli Zaretskii
2022-04-14 18:20           ` Tom Tromey
2022-04-14 18:18         ` Tom Tromey
2022-04-14 13:58 ` [PATCH 0/9] Windows thread names Pedro Alves

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=20220413191756.1146768-5-tromey@adacore.com \
    --to=tromey@adacore.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).