From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31439 invoked by alias); 10 Mar 2013 21:08:18 -0000 Received: (qmail 31411 invoked by uid 22791); 10 Mar 2013 21:08:17 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP,TW_QT,TW_TD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 10 Mar 2013 21:08:07 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2AL85he032150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 10 Mar 2013 17:08:05 -0400 Received: from host2.jankratochvil.net (ovpn-116-31.ams2.redhat.com [10.36.116.31]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2AL7xTp030911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Sun, 10 Mar 2013 17:08:01 -0400 Date: Sun, 10 Mar 2013 21:08:00 -0000 From: Jan Kratochvil To: Aleksandar Ristovski Cc: "gdb-patches@sourceware.org" Subject: [draft patch 2/6] Merge multiple hex conversions Message-ID: <20130310210758.GC21130@host2.jankratochvil.net> References: <51278984.3070208@qnx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51278984.3070208@qnx.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 X-SW-Source: 2013-03/txt/msg00434.txt.bz2 --- 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) --- 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); --- 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 */ --- 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); --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -1751,7 +1751,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); @@ -2045,7 +2046,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'; } --- 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); --- 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); --- 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 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -123,8 +123,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); @@ -181,8 +179,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); @@ -4548,32 +4544,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. */