From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18440 invoked by alias); 22 Mar 2013 13:04:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 18218 invoked by uid 89); 22 Mar 2013 13:04:11 -0000 X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,TW_CP,TW_QT,TW_TD autolearn=no version=3.3.1 Received: from na3sys009aog132.obsmtp.com (HELO na3sys009aog132.obsmtp.com) (74.125.149.250) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 22 Mar 2013 13:04:05 +0000 Received: from mx10.qnx.com ([209.226.137.110]) (using TLSv1) by na3sys009aob132.postini.com ([74.125.148.12]) with SMTP ID DSNKUUxWw5L8M39HS3R2TDkED5LOjOd1Abg0@postini.com; Fri, 22 Mar 2013 06:04:05 PDT Received: by mx10.qnx.com (Postfix, from userid 500) id D772720E48; Fri, 22 Mar 2013 09:04:02 -0400 (EDT) Received: from exhts.ott.qnx.com (exch1 [10.222.2.137]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mx10.qnx.com (Postfix) with ESMTPS id 400E920A7D; Fri, 22 Mar 2013 09:04:02 -0400 (EDT) Received: from [10.222.96.215] (10.222.2.5) by EXCH1.ott.qnx.com (10.222.2.137) with Microsoft SMTP Server id 14.2.318.4; Fri, 22 Mar 2013 09:04:01 -0400 Message-ID: <514C56C1.30907@qnx.com> Date: Fri, 22 Mar 2013 13:05:00 -0000 From: Aleksandar Ristovski User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 Newsgroups: gmane.comp.gdb.patches To: Jan Kratochvil CC: "gdb-patches@sourceware.org" Subject: Re: [patch 2/6] Merge multiple hex conversions References: <51278984.3070208@qnx.com> <20130310210758.GC21130@host2.jankratochvil.net> In-Reply-To: <20130310210758.GC21130@host2.jankratochvil.net> Content-Type: multipart/mixed; boundary="------------070606050203030204050108" X-Virus-Found: No X-SW-Source: 2013-03/txt/msg00837.txt.bz2 --------------070606050203030204050108 Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Content-length: 827 As per the subject... (tohex): Make externally linkable. * common/common-utils.h (fromhex, tohex): New declaration. * gdbserver/gdbreplay.c (tohex): Rename to 'fromhex'. (logchar): Use fromhex. * gdbserver/remote-utils.c (fromhex, unhexify): Remove. (tohex, hexify): Remove. (look_up_one_symbol, monitor_output): Use bin2hex instead of hexify. * gdbserver/server.c (handle_query): Use bin2hex instead of hexify. (handle_v_run): Ditto. * gdbserver/server.h (unhexify, hexify): Remove declarations. * gdbserver/tracepoint.c (cmd_qtdpsrc, cmd_qtdv): Use hex2bin instead of unhexify. (cmd_qtstatus): Use bin2hex instead of hexify. (cmd_qtnotes): Use hex2bin instead of unhexify. * monitor.c (fromhex): Remove definition. * remote.c (tohex, fromhex): Remove fwd declarations, remove definitions. --- Aleksandar --------------070606050203030204050108 Content-Type: text/x-patch; name="0002-Merge-multiple-hex-conversions.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-Merge-multiple-hex-conversions.patch" Content-length: 11953 >From 3e9d3b829ffc14fae8225977fa6e19dfcf38bce0 Mon Sep 17 00:00:00 2001 From: Aleksandar Ristovski Date: Tue, 12 Mar 2013 14:00:59 -0400 Subject: [PATCH 2/6] Merge multiple hex conversions * common/common-utils.c (fromhex): Make externally linkable. (tohex): Make externally linkable. * common/common-utils.h (fromhex, tohex): New declaration. * gdbserver/gdbreplay.c (tohex): Rename to 'fromhex'. (logchar): Use fromhex. * gdbserver/remote-utils.c (fromhex, unhexify): Remove. (tohex, hexify): Remove. (look_up_one_symbol, monitor_output): Use bin2hex instead of hexify. * gdbserver/server.c (handle_query): Use bin2hex instead of hexify. (handle_v_run): Ditto. * gdbserver/server.h (unhexify, hexify): Remove declarations. * gdbserver/tracepoint.c (cmd_qtdpsrc, cmd_qtdv): Use hex2bin instead of unhexify. (cmd_qtstatus): Use bin2hex instead of hexify. (cmd_qtnotes): Use hex2bin instead of unhexify. * monitor.c (fromhex): Remove definition. * remote.c (tohex, fromhex): Remove fwd declarations, remove definitions. --- gdb/common/common-utils.c | 6 ++-- gdb/common/common-utils.h | 4 +++ gdb/gdbserver/gdbreplay.c | 6 ++-- gdb/gdbserver/remote-utils.c | 67 ++---------------------------------------- gdb/gdbserver/server.c | 5 ++-- gdb/gdbserver/server.h | 2 -- gdb/gdbserver/tracepoint.c | 16 +++++----- gdb/monitor.c | 15 ---------- gdb/remote.c | 30 ------------------- 9 files changed, 24 insertions(+), 127 deletions(-) diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index 5e96692..c123ed7 100644 --- a/gdb/common/common-utils.c +++ b/gdb/common/common-utils.c @@ -264,7 +264,7 @@ strtoulst (const char *num, const char **trailer, int base) /* Convert hex digit A to a number. */ -static int +int fromhex (int a) { if (a >= '0' && a <= '9') @@ -274,7 +274,7 @@ fromhex (int a) else if (a >= 'A' && a <= 'F') return a - 'A' + 10; else - error (_("Reply contains invalid hex digit %d"), a); + error (_("Invalid hex digit %d"), a); } int @@ -298,7 +298,7 @@ hex2bin (const char *hex, gdb_byte *bin, int count) /* Convert number NIB to a hex digit. */ -static int +int tohex (int nib) { if (nib < 10) diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index ee7870e..2c95d34 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -74,6 +74,10 @@ char *savestring (const char *ptr, size_t len); ULONGEST strtoulst (const char *num, const char **trailer, int base); +extern int fromhex (int a); + +extern int tohex (int nib); + extern int hex2bin (const char *hex, gdb_byte *bin, int count); extern int bin2hex (const gdb_byte *bin, char *hex, int count); diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c index 0aa52d8..d0ff8c4 100644 --- a/gdb/gdbserver/gdbreplay.c +++ b/gdb/gdbserver/gdbreplay.c @@ -273,7 +273,7 @@ remote_open (char *name) } static int -tohex (int ch) +fromhex (int ch) { if (ch >= '0' && ch <= '9') { @@ -336,11 +336,11 @@ logchar (FILE *fp) ch2 = fgetc (fp); fputc (ch2, stdout); fflush (stdout); - ch = tohex (ch2) << 4; + ch = fromhex (ch2) << 4; ch2 = fgetc (fp); fputc (ch2, stdout); fflush (stdout); - ch |= tohex (ch2); + ch |= fromhex (ch2); break; default: /* Treat any other char as just itself */ diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 42c6a54..6ff491e 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -416,20 +416,6 @@ remote_close (void) reset_readchar (); } -/* Convert hex digit A to a number. */ - -static int -fromhex (int a) -{ - if (a >= '0' && a <= '9') - return a - '0'; - else if (a >= 'a' && a <= 'f') - return a - 'a' + 10; - else - error ("Reply contains invalid hex digit"); - return 0; -} - #endif static const char hexchars[] = "0123456789abcdef"; @@ -457,25 +443,6 @@ ishex (int ch, int *val) #ifndef IN_PROCESS_AGENT -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 decode_address (CORE_ADDR *addrp, const char *start, int len) { @@ -511,37 +478,8 @@ decode_address_to_semicolon (CORE_ADDR *addrp, const char *start) #endif -/* Convert number NIB to a hex digit. */ - -static int -tohex (int nib) -{ - if (nib < 10) - return '0' + nib; - else - return 'a' + nib - 10; -} - #ifndef IN_PROCESS_AGENT -int -hexify (char *hex, const char *bin, int count) -{ - int i; - - /* May use a length, or a nul-terminated string as input. */ - if (count == 0) - count = strlen (bin); - - for (i = 0; i < count; i++) - { - *hex++ = tohex ((*bin >> 4) & 0xf); - *hex++ = tohex (*bin++ & 0xf); - } - *hex = 0; - return i; -} - /* Convert BUFFER, binary data at least LEN bytes long, into escaped binary data in OUT_BUF. Set *OUT_LEN to the length of the data encoded in OUT_BUF, and return the number of bytes in OUT_BUF @@ -1608,7 +1546,8 @@ look_up_one_symbol (const char *name, CORE_ADDR *addrp, int may_ask_gdb) /* Send the request. */ strcpy (own_buf, "qSymbol:"); - hexify (own_buf + strlen ("qSymbol:"), name, strlen (name)); + bin2hex ((const gdb_byte *) name, own_buf + strlen ("qSymbol:"), + strlen (name)); if (putpkt (own_buf) < 0) return -1; @@ -1770,7 +1709,7 @@ monitor_output (const char *msg) char *buf = xmalloc (strlen (msg) * 2 + 2); buf[0] = 'O'; - hexify (buf + 1, msg, 0); + bin2hex ((const gdb_byte *) msg, buf + 1, 0); putpkt (buf); free (buf); diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 6bb36d8..8b586dd 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -1920,7 +1920,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); @@ -2214,7 +2215,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/server.h b/gdb/gdbserver/server.h index 139cd49..5e16088 100644 --- a/gdb/gdbserver/server.h +++ b/gdb/gdbserver/server.h @@ -322,8 +322,6 @@ int decode_search_memory_packet (const char *buf, int packet_len, gdb_byte *pattern, unsigned int *pattern_lenp); -int unhexify (char *bin, const char *hex, int count); -int hexify (char *hex, const char *bin, int count); int remote_escape_output (const gdb_byte *buffer, int len, gdb_byte *out_buf, int *out_len, int out_maxlen); diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 419765b..f48e3b6 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -2679,7 +2679,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)); @@ -2721,7 +2721,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); @@ -3594,17 +3594,17 @@ cmd_qtstatus (char *packet) str = (tracing_user_name ? tracing_user_name : ""); slen = strlen (str); buf1 = (char *) alloca (slen * 2 + 1); - hexify (buf1, str, slen); + bin2hex ((const gdb_byte *) str, buf1, slen); str = (tracing_notes ? tracing_notes : ""); slen = strlen (str); buf2 = (char *) alloca (slen * 2 + 1); - hexify (buf2, str, slen); + bin2hex ((const gdb_byte *) str, buf2, slen); str = (tracing_stop_note ? tracing_stop_note : ""); slen = strlen (str); buf3 = (char *) alloca (slen * 2 + 1); - hexify (buf3, str, slen); + bin2hex ((const gdb_byte *) str, buf3, slen); trace_debug ("Returning trace status as %d, stop reason %s", tracing, tracing_stop_reason); @@ -4078,7 +4078,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); @@ -4092,7 +4092,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); @@ -4106,7 +4106,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); diff --git a/gdb/monitor.c b/gdb/monitor.c index e6a9766..8ffa594 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -226,21 +226,6 @@ monitor_error (char *function, char *message, message, safe_string); } -/* Convert hex digit A to a number. */ - -static int -fromhex (int a) -{ - if (a >= '0' && a <= '9') - return a - '0'; - else if (a >= 'a' && a <= 'f') - return a - 'a' + 10; - else if (a >= 'A' && a <= 'F') - return a - 'A' + 10; - else - error (_("Invalid hex digit %d"), a); -} - /* monitor_vsprintf - similar to vsprintf but handles 64-bit addresses This function exists to get around the problem that many host platforms diff --git a/gdb/remote.c b/gdb/remote.c index 99c9182..08991fc 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -124,8 +124,6 @@ static int readchar (int timeout); static void remote_kill (struct target_ops *ops); -static int tohex (int nib); - static int remote_can_async_p (void); static int remote_is_async_p (void); @@ -182,8 +180,6 @@ static void remote_find_new_threads (void); static void record_currthread (ptid_t currthread); -static int fromhex (int a); - static int putpkt_binary (char *buf, int cnt); static void check_binary_download (CORE_ADDR addr); @@ -4557,32 +4553,6 @@ extended_remote_attach (struct target_ops *ops, char *args, int from_tty) extended_remote_attach_1 (ops, args, from_tty); } -/* Convert hex digit A to a number. */ - -static int -fromhex (int a) -{ - if (a >= '0' && a <= '9') - return a - '0'; - else if (a >= 'a' && a <= 'f') - return a - 'a' + 10; - else if (a >= 'A' && a <= 'F') - return a - 'A' + 10; - else - error (_("Reply contains invalid hex digit %d"), a); -} - -/* Convert number NIB to a hex digit. */ - -static int -tohex (int nib) -{ - if (nib < 10) - return '0' + nib; - else - return 'a' + nib - 10; -} - /* Check for the availability of vCont. This function should also check the response. */ -- 1.7.10.4 --------------070606050203030204050108--