Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@redhat.com>
Subject: [RFC v2 7/9] replace unhexify with hex2bin
Date: Thu, 06 Feb 2014 20:23:00 -0000	[thread overview]
Message-ID: <1391714966-12125-8-git-send-email-tromey@redhat.com> (raw)
In-Reply-To: <1391714966-12125-1-git-send-email-tromey@redhat.com>

unhexify and hex2bin are identical, so this removes unhexify.  The
particular choice of which to keep was made on the basis of
parallelism with the earlier patch that removed hexify.

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* common/rsp-low.h (unhexify): Don't declare.
	* common/rsp-low.c (unhexify): Remove.

2014-02-06  Tom Tromey  <tromey@redhat.com>

	* server.c (handle_query, handle_v_run): Use hex2bin, not
	unhexify.
	* tracepoint.c (cmd_qtdpsrc, cmd_qtdv, cmd_qtnotes): Likewise.
---
 gdb/ChangeLog              |  5 +++++
 gdb/common/rsp-low.c       | 19 -------------------
 gdb/common/rsp-low.h       |  2 --
 gdb/gdbserver/ChangeLog    |  6 ++++++
 gdb/gdbserver/server.c     |  5 +++--
 gdb/gdbserver/tracepoint.c | 10 +++++-----
 6 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/gdb/common/rsp-low.c b/gdb/common/rsp-low.c
index c7a00c1..decd23c 100644
--- a/gdb/common/rsp-low.c
+++ b/gdb/common/rsp-low.c
@@ -127,25 +127,6 @@ hex2bin (const char *hex, gdb_byte *bin, int count)
   return i;
 }
 
-int
-unhexify (char *bin, const char *hex, int count)
-{
-  int i;
-
-  for (i = 0; i < count; i++)
-    {
-      if (hex[0] == 0 || hex[1] == 0)
-	{
-	  /* Hex string is short, or of uneven length.
-	     Return the count that has been converted so far. */
-	  return i;
-	}
-      *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]);
-      hex += 2;
-    }
-  return i;
-}
-
 void
 convert_ascii_to_int (const char *from, unsigned char *to, int n)
 {
diff --git a/gdb/common/rsp-low.h b/gdb/common/rsp-low.h
index e1944cf..b793f15 100644
--- a/gdb/common/rsp-low.h
+++ b/gdb/common/rsp-low.h
@@ -36,8 +36,6 @@ extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
 
 extern int hex2bin (const char *hex, gdb_byte *bin, int count);
 
-extern int unhexify (char *bin, const char *hex, int count);
-
 extern void convert_ascii_to_int (const char *from, unsigned char *to, int n);
 
 extern int bin2hex (const gdb_byte *bin, char *hex, int count);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index e582598..1ea1bde 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -2025,7 +2025,8 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
 	  return;
 	}
 
-      if ((len % 2) != 0 || unhexify (mon, own_buf + 6, len / 2) != len / 2)
+      if ((len % 2) != 0
+	  || hex2bin (own_buf + 6, (gdb_byte *) mon, len / 2) != len / 2)
 	{
 	  write_enn (own_buf);
 	  free (mon);
@@ -2408,7 +2409,7 @@ handle_v_run (char *own_buf)
 	{
 	  /* FIXME: Fail request if out of memory instead of dying.  */
 	  new_argv[i] = xmalloc (1 + (next_p - p) / 2);
-	  unhexify (new_argv[i], p, (next_p - p) / 2);
+	  hex2bin (p, (gdb_byte *) new_argv[i], (next_p - p) / 2);
 	  new_argv[i][(next_p - p) / 2] = '\0';
 	}
 
diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index df32005..8e294f6 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -2708,7 +2708,7 @@ cmd_qtdpsrc (char *own_buf)
   packet = unpack_varlen_hex (packet, &slen);
   ++packet; /* skip a colon */
   src = xmalloc (slen + 1);
-  nbytes = unhexify (src, packet, strlen (packet) / 2);
+  nbytes = hex2bin (packet, (gdb_byte *) src, strlen (packet) / 2);
   src[nbytes] = '\0';
 
   newlast = xmalloc (sizeof (struct source_string));
@@ -2750,7 +2750,7 @@ cmd_qtdv (char *own_buf)
 
   nbytes = strlen (packet) / 2;
   varname = xmalloc (nbytes + 1);
-  nbytes = unhexify (varname, packet, nbytes);
+  nbytes = hex2bin (packet, (gdb_byte *) varname, nbytes);
   varname[nbytes] = '\0';
 
   tsv = create_trace_state_variable (num, 1);
@@ -4108,7 +4108,7 @@ cmd_qtnotes (char *own_buf)
 	  packet = strchr (packet, ';');
 	  nbytes = (packet - saved) / 2;
 	  user = xmalloc (nbytes + 1);
-	  nbytes = unhexify (user, saved, nbytes);
+	  nbytes = hex2bin (saved, (gdb_byte *) user, nbytes);
 	  user[nbytes] = '\0';
 	  ++packet; /* skip the semicolon */
 	  trace_debug ("User is '%s'", user);
@@ -4122,7 +4122,7 @@ cmd_qtnotes (char *own_buf)
 	  packet = strchr (packet, ';');
 	  nbytes = (packet - saved) / 2;
 	  notes = xmalloc (nbytes + 1);
-	  nbytes = unhexify (notes, saved, nbytes);
+	  nbytes = hex2bin (saved, (gdb_byte *) notes, nbytes);
 	  notes[nbytes] = '\0';
 	  ++packet; /* skip the semicolon */
 	  trace_debug ("Notes is '%s'", notes);
@@ -4136,7 +4136,7 @@ cmd_qtnotes (char *own_buf)
 	  packet = strchr (packet, ';');
 	  nbytes = (packet - saved) / 2;
 	  stopnote = xmalloc (nbytes + 1);
-	  nbytes = unhexify (stopnote, saved, nbytes);
+	  nbytes = hex2bin (saved, (gdb_byte *) stopnote, nbytes);
 	  stopnote[nbytes] = '\0';
 	  ++packet; /* skip the semicolon */
 	  trace_debug ("tstop note is '%s'", stopnote);
-- 
1.8.1.4


  parent reply	other threads:[~2014-02-06 20:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-06 19:29 [RFC v2 0/9] move more code into common/ Tom Tromey
2014-02-06 19:29 ` [RFC v2 4/9] don't let hexify call strlen Tom Tromey
2014-02-06 19:29 ` [RFC v2 2/9] move some rsp bits into rsp-low.h Tom Tromey
2014-02-13  9:02   ` Yao Qi
2014-02-13 10:38     ` Pedro Alves
2014-02-14  2:00       ` Yao Qi
2014-02-13 15:08     ` Tom Tromey
2014-02-14  1:36       ` Yao Qi
2014-02-06 19:29 ` [RFC v2 1/9] share "cell" code Tom Tromey
2014-02-06 19:29 ` [RFC v2 3/9] don't let bin2hex call strlen Tom Tromey
2014-02-06 19:38 ` [RFC v2 5/9] replace hexify with bin2hex Tom Tromey
2014-02-06 19:41 ` [RFC v2 6/9] replace convert_int_to_ascii " Tom Tromey
2014-02-06 20:23 ` [RFC v2 8/9] replace convert_ascii_to_int with hex2bin Tom Tromey
2014-02-06 20:23 ` Tom Tromey [this message]
2014-02-06 20:24 ` [RFC v2 9/9] update rsp-low comments Tom Tromey
2014-02-07 12:53 ` [RFC v2 0/9] move more code into common/ Pedro Alves
2014-02-12 16:57 ` 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=1391714966-12125-8-git-send-email-tromey@redhat.com \
    --to=tromey@redhat.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