From: Aleksandar Ristovski <aristovski@qnx.com>
To: gdb-patches@sourceware.org
Cc: gdb-patches@sourceware.org
Subject: Re: [patch 1/6] Move utility functions to common/
Date: Sun, 07 Apr 2013 18:54:00 -0000 [thread overview]
Message-ID: <515ECAAF.8030209@qnx.com> (raw)
In-Reply-To: <514C56BA.5050504@qnx.com>
[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]
Rebased to master e96bd93d436e464a532a7e1161e1d201c9fc50c7
On 13-03-22 09:03 AM, Aleksandar Ristovski wrote:
> As per the subject...
>
>
> ChangeLog:
>
> * cli/cli-utils.c (skip_spaces, skip_spaces_const): Move defs to
> common/common-utils.c.
> * cli/cli-utils.h (skip_spaces, skip_spaces_const): Move decls to
> common/common-utils.h.
> * common/common-utils.c (ctype.h): Include.
> (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
> from utils.c.
> (fromhex): Copy from remote.c.
> (hex2bin): Move from remote.c.
> (tohex): Copy from remote.c.
> (bin2hex): Move from remote.c.
> (skip_spaces, skip_spaces_const): Move from cli/cli-utils.c.
> * common/common-utils.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved
> from defs.h.
> (strtoulst): Move decl from utils.h.
> (hex2bin, bin2hex): Move decls from remote.h.
> (skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
> * defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
> common/common-utils.h
> * remote.c (hex2bin, bin2hex): Moved defs to common/common-utils.c.
> * remote.h (hex2bin, bin2hex): Moved decls to common/common-utils.h.
> * utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int,
> strtoulst): Move to common/common-utils.c.
> * utils.h (strtoulst): Moved decl to common/common-utils.h.
>
>
>
> Thanks,
>
> Aleksandar
>
>
[-- Attachment #2: 0001-Move-utility-functions-to-common.patch --]
[-- Type: text/x-patch, Size: 14057 bytes --]
From d2cb04f1e90e14d72a63fa23ec5bb6421cc9e682 Mon Sep 17 00:00:00 2001
From: Aleksandar Ristovski <ARistovski@qnx.com>
Date: Wed, 27 Mar 2013 09:39:05 -0400
Subject: [PATCH 1/8] Move utility functions to common/
* cli/cli-utils.c (skip_spaces, skip_spaces_const): Move defs to
common/common-utils.c.
* cli/cli-utils.h (skip_spaces, skip_spaces_const): Move decls to
common/common-utils.h.
* common/common-utils.c (ctype.h): Include.
(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
from utils.c.
(fromhex): Copy from remote.c.
(hex2bin): Move from remote.c.
(tohex): Copy from remote.c.
(bin2hex): Move from remote.c.
(skip_spaces, skip_spaces_const): Move from cli/cli-utils.c.
* common/common-utils.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved
from defs.h.
(strtoulst): Move decl from utils.h.
(hex2bin, bin2hex): Move decls from remote.h.
(skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
* defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
common/common-utils.h
* remote.c (hex2bin, bin2hex): Moved defs to common/common-utils.c.
* remote.h (hex2bin, bin2hex): Moved decls to common/common-utils.h.
* utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int,
strtoulst): Move to common/common-utils.c.
* utils.h (strtoulst): Moved decl to common/common-utils.h.
---
gdb/cli/cli-utils.c | 24 ------
gdb/cli/cli-utils.h | 9 ---
gdb/common/common-utils.c | 187 +++++++++++++++++++++++++++++++++++++++++++++
gdb/common/common-utils.h | 34 +++++++++
gdb/defs.h | 19 -----
gdb/remote.c | 36 ---------
gdb/remote.h | 4 -
gdb/utils.c | 99 ------------------------
gdb/utils.h | 2 -
9 files changed, 221 insertions(+), 193 deletions(-)
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f74e6b1..60f7553 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -213,30 +213,6 @@ number_is_in_list (char *list, int number)
/* See documentation in cli-utils.h. */
-char *
-skip_spaces (char *chp)
-{
- if (chp == NULL)
- return NULL;
- while (*chp && isspace (*chp))
- chp++;
- return chp;
-}
-
-/* A const-correct version of the above. */
-
-const char *
-skip_spaces_const (const char *chp)
-{
- if (chp == NULL)
- return NULL;
- while (*chp && isspace (*chp))
- chp++;
- return chp;
-}
-
-/* See documentation in cli-utils.h. */
-
const char *
skip_to_space_const (const char *chp)
{
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 152fb89..2a8850d 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -89,15 +89,6 @@ extern int get_number_or_range (struct get_number_or_range_state *state);
extern int number_is_in_list (char *list, int number);
-/* Skip leading whitespace characters in INP, returning an updated
- pointer. If INP is NULL, return NULL. */
-
-extern char *skip_spaces (char *inp);
-
-/* A const-correct version of the above. */
-
-extern const char *skip_spaces_const (const char *inp);
-
/* Skip leading non-whitespace characters in INP, returning an updated
pointer. If INP is NULL, return NULL. */
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 4204abf..5e96692 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h>
/* The xmalloc() (libiberty.h) family of memory management routines.
@@ -161,3 +162,189 @@ savestring (const char *ptr, size_t len)
p[len] = 0;
return p;
}
+
+/* The bit offset of the highest byte in a ULONGEST, for overflow
+ checking. */
+
+#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
+
+/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
+ where 2 <= BASE <= 36. */
+
+static int
+is_digit_in_base (unsigned char digit, int base)
+{
+ if (!isalnum (digit))
+ return 0;
+ if (base <= 10)
+ return (isdigit (digit) && digit < base + '0');
+ else
+ return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
+}
+
+static int
+digit_to_int (unsigned char c)
+{
+ if (isdigit (c))
+ return c - '0';
+ else
+ return tolower (c) - 'a' + 10;
+}
+
+/* As for strtoul, but for ULONGEST results. */
+
+ULONGEST
+strtoulst (const char *num, const char **trailer, int base)
+{
+ unsigned int high_part;
+ ULONGEST result;
+ int minus = 0;
+ int i = 0;
+
+ /* Skip leading whitespace. */
+ while (isspace (num[i]))
+ i++;
+
+ /* Handle prefixes. */
+ if (num[i] == '+')
+ i++;
+ else if (num[i] == '-')
+ {
+ minus = 1;
+ i++;
+ }
+
+ if (base == 0 || base == 16)
+ {
+ if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
+ {
+ i += 2;
+ if (base == 0)
+ base = 16;
+ }
+ }
+
+ if (base == 0 && num[i] == '0')
+ base = 8;
+
+ if (base == 0)
+ base = 10;
+
+ if (base < 2 || base > 36)
+ {
+ errno = EINVAL;
+ return 0;
+ }
+
+ result = high_part = 0;
+ for (; is_digit_in_base (num[i], base); i += 1)
+ {
+ result = result * base + digit_to_int (num[i]);
+ high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
+ result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
+ if (high_part > 0xff)
+ {
+ errno = ERANGE;
+ result = ~ (ULONGEST) 0;
+ high_part = 0;
+ minus = 0;
+ break;
+ }
+ }
+
+ if (trailer != NULL)
+ *trailer = &num[i];
+
+ result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
+ if (minus)
+ return -result;
+ else
+ return result;
+}
+
+/* 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);
+}
+
+int
+hex2bin (const char *hex, gdb_byte *bin, 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;
+}
+
+/* Convert number NIB to a hex digit. */
+
+static int
+tohex (int nib)
+{
+ if (nib < 10)
+ return '0' + nib;
+ else
+ return 'a' + nib - 10;
+}
+
+int
+bin2hex (const gdb_byte *bin, char *hex, int count)
+{
+ int i;
+
+ /* May use a length, or a nul-terminated string as input. */
+ if (count == 0)
+ count = strlen ((char *) bin);
+
+ for (i = 0; i < count; i++)
+ {
+ *hex++ = tohex ((*bin >> 4) & 0xf);
+ *hex++ = tohex (*bin++ & 0xf);
+ }
+ *hex = 0;
+ return i;
+}
+
+/* See documentation in cli-utils.h. */
+
+char *
+skip_spaces (char *chp)
+{
+ if (chp == NULL)
+ return NULL;
+ while (*chp && isspace (*chp))
+ chp++;
+ return chp;
+}
+
+/* A const-correct version of the above. */
+
+const char *
+skip_spaces_const (const char *chp)
+{
+ if (chp == NULL)
+ return NULL;
+ while (*chp && isspace (*chp))
+ chp++;
+ return chp;
+}
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 9b659d8..ee7870e 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -25,6 +25,25 @@
#include <stddef.h>
#include <stdarg.h>
+/* Static target-system-dependent parameters for GDB. */
+
+/* Number of bits in a char or unsigned char for the target machine.
+ Just like CHAR_BIT in <limits.h> but describes the target machine. */
+#if !defined (TARGET_CHAR_BIT)
+#define TARGET_CHAR_BIT 8
+#endif
+
+/* If we picked up a copy of CHAR_BIT from a configuration file
+ (which may get it by including <limits.h>) then use it to set
+ the number of bits in a host char. If not, use the same size
+ as the target. */
+
+#if defined (CHAR_BIT)
+#define HOST_CHAR_BIT CHAR_BIT
+#else
+#define HOST_CHAR_BIT TARGET_CHAR_BIT
+#endif
+
extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
extern void internal_error (const char *file, int line, const char *, ...)
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4);
@@ -53,4 +72,19 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
char *savestring (const char *ptr, size_t len);
+ULONGEST strtoulst (const char *num, const char **trailer, int base);
+
+extern int hex2bin (const char *hex, gdb_byte *bin, int count);
+
+extern int bin2hex (const gdb_byte *bin, char *hex, int count);
+
+/* Skip leading whitespace characters in INP, returning an updated
+ pointer. If INP is NULL, return NULL. */
+
+extern char *skip_spaces (char *inp);
+
+/* A const-correct version of the above. */
+
+extern const char *skip_spaces_const (const char *inp);
+
#endif
diff --git a/gdb/defs.h b/gdb/defs.h
index d8a1adb..ec7e4f3 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -648,25 +648,6 @@ extern void *alloca ();
enum { MAX_REGISTER_SIZE = 64 };
-/* Static target-system-dependent parameters for GDB. */
-
-/* Number of bits in a char or unsigned char for the target machine.
- Just like CHAR_BIT in <limits.h> but describes the target machine. */
-#if !defined (TARGET_CHAR_BIT)
-#define TARGET_CHAR_BIT 8
-#endif
-
-/* If we picked up a copy of CHAR_BIT from a configuration file
- (which may get it by including <limits.h>) then use it to set
- the number of bits in a host char. If not, use the same size
- as the target. */
-
-#if defined (CHAR_BIT)
-#define HOST_CHAR_BIT CHAR_BIT
-#else
-#define HOST_CHAR_BIT TARGET_CHAR_BIT
-#endif
-
/* In findvar.c. */
extern LONGEST extract_signed_integer (const gdb_byte *, int,
diff --git a/gdb/remote.c b/gdb/remote.c
index aefbcf1..6a11652 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4569,25 +4569,6 @@ fromhex (int a)
error (_("Reply contains invalid hex digit %d"), a);
}
-int
-hex2bin (const char *hex, gdb_byte *bin, 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;
-}
-
/* Convert number NIB to a hex digit. */
static int
@@ -4599,23 +4580,6 @@ tohex (int nib)
return 'a' + nib - 10;
}
-int
-bin2hex (const gdb_byte *bin, char *hex, int count)
-{
- int i;
-
- /* May use a length, or a nul-terminated string as input. */
- if (count == 0)
- count = strlen ((char *) bin);
-
- for (i = 0; i < count; i++)
- {
- *hex++ = tohex ((*bin >> 4) & 0xf);
- *hex++ = tohex (*bin++ & 0xf);
- }
- *hex = 0;
- return i;
-}
\f
/* Check for the availability of vCont. This function should also check
the response. */
diff --git a/gdb/remote.h b/gdb/remote.h
index b95370c..d49b427 100644
--- a/gdb/remote.h
+++ b/gdb/remote.h
@@ -39,10 +39,6 @@ extern void getpkt (char **buf, long *sizeof_buf, int forever);
extern int putpkt (char *buf);
-extern int hex2bin (const char *hex, gdb_byte *bin, int count);
-
-extern int bin2hex (const gdb_byte *bin, char *hex, int count);
-
extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
extern void async_remote_interrupt_twice (void *arg);
diff --git a/gdb/utils.c b/gdb/utils.c
index a222c59..e1ced2c 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3233,105 +3233,6 @@ dummy_obstack_deallocate (void *object, void *data)
return;
}
-/* The bit offset of the highest byte in a ULONGEST, for overflow
- checking. */
-
-#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
-
-/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
- where 2 <= BASE <= 36. */
-
-static int
-is_digit_in_base (unsigned char digit, int base)
-{
- if (!isalnum (digit))
- return 0;
- if (base <= 10)
- return (isdigit (digit) && digit < base + '0');
- else
- return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
-}
-
-static int
-digit_to_int (unsigned char c)
-{
- if (isdigit (c))
- return c - '0';
- else
- return tolower (c) - 'a' + 10;
-}
-
-/* As for strtoul, but for ULONGEST results. */
-
-ULONGEST
-strtoulst (const char *num, const char **trailer, int base)
-{
- unsigned int high_part;
- ULONGEST result;
- int minus = 0;
- int i = 0;
-
- /* Skip leading whitespace. */
- while (isspace (num[i]))
- i++;
-
- /* Handle prefixes. */
- if (num[i] == '+')
- i++;
- else if (num[i] == '-')
- {
- minus = 1;
- i++;
- }
-
- if (base == 0 || base == 16)
- {
- if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
- {
- i += 2;
- if (base == 0)
- base = 16;
- }
- }
-
- if (base == 0 && num[i] == '0')
- base = 8;
-
- if (base == 0)
- base = 10;
-
- if (base < 2 || base > 36)
- {
- errno = EINVAL;
- return 0;
- }
-
- result = high_part = 0;
- for (; is_digit_in_base (num[i], base); i += 1)
- {
- result = result * base + digit_to_int (num[i]);
- high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
- result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
- if (high_part > 0xff)
- {
- errno = ERANGE;
- result = ~ (ULONGEST) 0;
- high_part = 0;
- minus = 0;
- break;
- }
- }
-
- if (trailer != NULL)
- *trailer = &num[i];
-
- result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
- if (minus)
- return -result;
- else
- return result;
-}
-
/* Simple, portable version of dirname that does not modify its
argument. */
diff --git a/gdb/utils.h b/gdb/utils.h
index ad5bea4..e3b6fbf 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -39,8 +39,6 @@ extern int streq (const char *, const char *);
extern int subset_compare (char *, char *);
-ULONGEST strtoulst (const char *num, const char **trailer, int base);
-
int compare_positive_ints (const void *ap, const void *bp);
int compare_strings (const void *ap, const void *bp);
--
1.7.10.4
WARNING: multiple messages have this Message-ID
From: Aleksandar Ristovski <aristovski@qnx.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [patch 1/6] Move utility functions to common/
Date: Fri, 05 Apr 2013 13:06:00 -0000 [thread overview]
Message-ID: <515ECAAF.8030209@qnx.com> (raw)
Message-ID: <20130405130600.cwaeFBg_Fjj4LXaizE6OnJn0uJ4oQ1YX0iFZaUIGzaM@z> (raw)
In-Reply-To: <514C56BA.5050504@qnx.com>
[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]
Rebased to master e96bd93d436e464a532a7e1161e1d201c9fc50c7
On 13-03-22 09:03 AM, Aleksandar Ristovski wrote:
> As per the subject...
>
>
> ChangeLog:
>
> * cli/cli-utils.c (skip_spaces, skip_spaces_const): Move defs to
> common/common-utils.c.
> * cli/cli-utils.h (skip_spaces, skip_spaces_const): Move decls to
> common/common-utils.h.
> * common/common-utils.c (ctype.h): Include.
> (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
> from utils.c.
> (fromhex): Copy from remote.c.
> (hex2bin): Move from remote.c.
> (tohex): Copy from remote.c.
> (bin2hex): Move from remote.c.
> (skip_spaces, skip_spaces_const): Move from cli/cli-utils.c.
> * common/common-utils.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved
> from defs.h.
> (strtoulst): Move decl from utils.h.
> (hex2bin, bin2hex): Move decls from remote.h.
> (skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
> * defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
> common/common-utils.h
> * remote.c (hex2bin, bin2hex): Moved defs to common/common-utils.c.
> * remote.h (hex2bin, bin2hex): Moved decls to common/common-utils.h.
> * utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int,
> strtoulst): Move to common/common-utils.c.
> * utils.h (strtoulst): Moved decl to common/common-utils.h.
>
>
>
> Thanks,
>
> Aleksandar
>
>
[-- Attachment #2: 0001-Move-utility-functions-to-common.patch --]
[-- Type: text/x-patch, Size: 14057 bytes --]
From d2cb04f1e90e14d72a63fa23ec5bb6421cc9e682 Mon Sep 17 00:00:00 2001
From: Aleksandar Ristovski <ARistovski@qnx.com>
Date: Wed, 27 Mar 2013 09:39:05 -0400
Subject: [PATCH 1/8] Move utility functions to common/
* cli/cli-utils.c (skip_spaces, skip_spaces_const): Move defs to
common/common-utils.c.
* cli/cli-utils.h (skip_spaces, skip_spaces_const): Move decls to
common/common-utils.h.
* common/common-utils.c (ctype.h): Include.
(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
from utils.c.
(fromhex): Copy from remote.c.
(hex2bin): Move from remote.c.
(tohex): Copy from remote.c.
(bin2hex): Move from remote.c.
(skip_spaces, skip_spaces_const): Move from cli/cli-utils.c.
* common/common-utils.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved
from defs.h.
(strtoulst): Move decl from utils.h.
(hex2bin, bin2hex): Move decls from remote.h.
(skip_spaces, skip_spaces_const): Move decls from cli/cli-utils.h.
* defs.h (TARGET_CHAR_BIT, HOST_CHAR_BIT): Move to
common/common-utils.h
* remote.c (hex2bin, bin2hex): Moved defs to common/common-utils.c.
* remote.h (hex2bin, bin2hex): Moved decls to common/common-utils.h.
* utils.c (HIGH_BYTE_POSN, is_digit_in_base, digit_to_int,
strtoulst): Move to common/common-utils.c.
* utils.h (strtoulst): Moved decl to common/common-utils.h.
---
gdb/cli/cli-utils.c | 24 ------
gdb/cli/cli-utils.h | 9 ---
gdb/common/common-utils.c | 187 +++++++++++++++++++++++++++++++++++++++++++++
gdb/common/common-utils.h | 34 +++++++++
gdb/defs.h | 19 -----
gdb/remote.c | 36 ---------
gdb/remote.h | 4 -
gdb/utils.c | 99 ------------------------
gdb/utils.h | 2 -
9 files changed, 221 insertions(+), 193 deletions(-)
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f74e6b1..60f7553 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -213,30 +213,6 @@ number_is_in_list (char *list, int number)
/* See documentation in cli-utils.h. */
-char *
-skip_spaces (char *chp)
-{
- if (chp == NULL)
- return NULL;
- while (*chp && isspace (*chp))
- chp++;
- return chp;
-}
-
-/* A const-correct version of the above. */
-
-const char *
-skip_spaces_const (const char *chp)
-{
- if (chp == NULL)
- return NULL;
- while (*chp && isspace (*chp))
- chp++;
- return chp;
-}
-
-/* See documentation in cli-utils.h. */
-
const char *
skip_to_space_const (const char *chp)
{
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 152fb89..2a8850d 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -89,15 +89,6 @@ extern int get_number_or_range (struct get_number_or_range_state *state);
extern int number_is_in_list (char *list, int number);
-/* Skip leading whitespace characters in INP, returning an updated
- pointer. If INP is NULL, return NULL. */
-
-extern char *skip_spaces (char *inp);
-
-/* A const-correct version of the above. */
-
-extern const char *skip_spaces_const (const char *inp);
-
/* Skip leading non-whitespace characters in INP, returning an updated
pointer. If INP is NULL, return NULL. */
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 4204abf..5e96692 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h>
/* The xmalloc() (libiberty.h) family of memory management routines.
@@ -161,3 +162,189 @@ savestring (const char *ptr, size_t len)
p[len] = 0;
return p;
}
+
+/* The bit offset of the highest byte in a ULONGEST, for overflow
+ checking. */
+
+#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
+
+/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
+ where 2 <= BASE <= 36. */
+
+static int
+is_digit_in_base (unsigned char digit, int base)
+{
+ if (!isalnum (digit))
+ return 0;
+ if (base <= 10)
+ return (isdigit (digit) && digit < base + '0');
+ else
+ return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
+}
+
+static int
+digit_to_int (unsigned char c)
+{
+ if (isdigit (c))
+ return c - '0';
+ else
+ return tolower (c) - 'a' + 10;
+}
+
+/* As for strtoul, but for ULONGEST results. */
+
+ULONGEST
+strtoulst (const char *num, const char **trailer, int base)
+{
+ unsigned int high_part;
+ ULONGEST result;
+ int minus = 0;
+ int i = 0;
+
+ /* Skip leading whitespace. */
+ while (isspace (num[i]))
+ i++;
+
+ /* Handle prefixes. */
+ if (num[i] == '+')
+ i++;
+ else if (num[i] == '-')
+ {
+ minus = 1;
+ i++;
+ }
+
+ if (base == 0 || base == 16)
+ {
+ if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
+ {
+ i += 2;
+ if (base == 0)
+ base = 16;
+ }
+ }
+
+ if (base == 0 && num[i] == '0')
+ base = 8;
+
+ if (base == 0)
+ base = 10;
+
+ if (base < 2 || base > 36)
+ {
+ errno = EINVAL;
+ return 0;
+ }
+
+ result = high_part = 0;
+ for (; is_digit_in_base (num[i], base); i += 1)
+ {
+ result = result * base + digit_to_int (num[i]);
+ high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
+ result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
+ if (high_part > 0xff)
+ {
+ errno = ERANGE;
+ result = ~ (ULONGEST) 0;
+ high_part = 0;
+ minus = 0;
+ break;
+ }
+ }
+
+ if (trailer != NULL)
+ *trailer = &num[i];
+
+ result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
+ if (minus)
+ return -result;
+ else
+ return result;
+}
+
+/* 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);
+}
+
+int
+hex2bin (const char *hex, gdb_byte *bin, 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;
+}
+
+/* Convert number NIB to a hex digit. */
+
+static int
+tohex (int nib)
+{
+ if (nib < 10)
+ return '0' + nib;
+ else
+ return 'a' + nib - 10;
+}
+
+int
+bin2hex (const gdb_byte *bin, char *hex, int count)
+{
+ int i;
+
+ /* May use a length, or a nul-terminated string as input. */
+ if (count == 0)
+ count = strlen ((char *) bin);
+
+ for (i = 0; i < count; i++)
+ {
+ *hex++ = tohex ((*bin >> 4) & 0xf);
+ *hex++ = tohex (*bin++ & 0xf);
+ }
+ *hex = 0;
+ return i;
+}
+
+/* See documentation in cli-utils.h. */
+
+char *
+skip_spaces (char *chp)
+{
+ if (chp == NULL)
+ return NULL;
+ while (*chp && isspace (*chp))
+ chp++;
+ return chp;
+}
+
+/* A const-correct version of the above. */
+
+const char *
+skip_spaces_const (const char *chp)
+{
+ if (chp == NULL)
+ return NULL;
+ while (*chp && isspace (*chp))
+ chp++;
+ return chp;
+}
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 9b659d8..ee7870e 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -25,6 +25,25 @@
#include <stddef.h>
#include <stdarg.h>
+/* Static target-system-dependent parameters for GDB. */
+
+/* Number of bits in a char or unsigned char for the target machine.
+ Just like CHAR_BIT in <limits.h> but describes the target machine. */
+#if !defined (TARGET_CHAR_BIT)
+#define TARGET_CHAR_BIT 8
+#endif
+
+/* If we picked up a copy of CHAR_BIT from a configuration file
+ (which may get it by including <limits.h>) then use it to set
+ the number of bits in a host char. If not, use the same size
+ as the target. */
+
+#if defined (CHAR_BIT)
+#define HOST_CHAR_BIT CHAR_BIT
+#else
+#define HOST_CHAR_BIT TARGET_CHAR_BIT
+#endif
+
extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
extern void internal_error (const char *file, int line, const char *, ...)
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4);
@@ -53,4 +72,19 @@ int xsnprintf (char *str, size_t size, const char *format, ...)
char *savestring (const char *ptr, size_t len);
+ULONGEST strtoulst (const char *num, const char **trailer, int base);
+
+extern int hex2bin (const char *hex, gdb_byte *bin, int count);
+
+extern int bin2hex (const gdb_byte *bin, char *hex, int count);
+
+/* Skip leading whitespace characters in INP, returning an updated
+ pointer. If INP is NULL, return NULL. */
+
+extern char *skip_spaces (char *inp);
+
+/* A const-correct version of the above. */
+
+extern const char *skip_spaces_const (const char *inp);
+
#endif
diff --git a/gdb/defs.h b/gdb/defs.h
index d8a1adb..ec7e4f3 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -648,25 +648,6 @@ extern void *alloca ();
enum { MAX_REGISTER_SIZE = 64 };
-/* Static target-system-dependent parameters for GDB. */
-
-/* Number of bits in a char or unsigned char for the target machine.
- Just like CHAR_BIT in <limits.h> but describes the target machine. */
-#if !defined (TARGET_CHAR_BIT)
-#define TARGET_CHAR_BIT 8
-#endif
-
-/* If we picked up a copy of CHAR_BIT from a configuration file
- (which may get it by including <limits.h>) then use it to set
- the number of bits in a host char. If not, use the same size
- as the target. */
-
-#if defined (CHAR_BIT)
-#define HOST_CHAR_BIT CHAR_BIT
-#else
-#define HOST_CHAR_BIT TARGET_CHAR_BIT
-#endif
-
/* In findvar.c. */
extern LONGEST extract_signed_integer (const gdb_byte *, int,
diff --git a/gdb/remote.c b/gdb/remote.c
index aefbcf1..6a11652 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4569,25 +4569,6 @@ fromhex (int a)
error (_("Reply contains invalid hex digit %d"), a);
}
-int
-hex2bin (const char *hex, gdb_byte *bin, 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;
-}
-
/* Convert number NIB to a hex digit. */
static int
@@ -4599,23 +4580,6 @@ tohex (int nib)
return 'a' + nib - 10;
}
-int
-bin2hex (const gdb_byte *bin, char *hex, int count)
-{
- int i;
-
- /* May use a length, or a nul-terminated string as input. */
- if (count == 0)
- count = strlen ((char *) bin);
-
- for (i = 0; i < count; i++)
- {
- *hex++ = tohex ((*bin >> 4) & 0xf);
- *hex++ = tohex (*bin++ & 0xf);
- }
- *hex = 0;
- return i;
-}
\f
/* Check for the availability of vCont. This function should also check
the response. */
diff --git a/gdb/remote.h b/gdb/remote.h
index b95370c..d49b427 100644
--- a/gdb/remote.h
+++ b/gdb/remote.h
@@ -39,10 +39,6 @@ extern void getpkt (char **buf, long *sizeof_buf, int forever);
extern int putpkt (char *buf);
-extern int hex2bin (const char *hex, gdb_byte *bin, int count);
-
-extern int bin2hex (const gdb_byte *bin, char *hex, int count);
-
extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
extern void async_remote_interrupt_twice (void *arg);
diff --git a/gdb/utils.c b/gdb/utils.c
index a222c59..e1ced2c 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3233,105 +3233,6 @@ dummy_obstack_deallocate (void *object, void *data)
return;
}
-/* The bit offset of the highest byte in a ULONGEST, for overflow
- checking. */
-
-#define HIGH_BYTE_POSN ((sizeof (ULONGEST) - 1) * HOST_CHAR_BIT)
-
-/* True (non-zero) iff DIGIT is a valid digit in radix BASE,
- where 2 <= BASE <= 36. */
-
-static int
-is_digit_in_base (unsigned char digit, int base)
-{
- if (!isalnum (digit))
- return 0;
- if (base <= 10)
- return (isdigit (digit) && digit < base + '0');
- else
- return (isdigit (digit) || tolower (digit) < base - 10 + 'a');
-}
-
-static int
-digit_to_int (unsigned char c)
-{
- if (isdigit (c))
- return c - '0';
- else
- return tolower (c) - 'a' + 10;
-}
-
-/* As for strtoul, but for ULONGEST results. */
-
-ULONGEST
-strtoulst (const char *num, const char **trailer, int base)
-{
- unsigned int high_part;
- ULONGEST result;
- int minus = 0;
- int i = 0;
-
- /* Skip leading whitespace. */
- while (isspace (num[i]))
- i++;
-
- /* Handle prefixes. */
- if (num[i] == '+')
- i++;
- else if (num[i] == '-')
- {
- minus = 1;
- i++;
- }
-
- if (base == 0 || base == 16)
- {
- if (num[i] == '0' && (num[i + 1] == 'x' || num[i + 1] == 'X'))
- {
- i += 2;
- if (base == 0)
- base = 16;
- }
- }
-
- if (base == 0 && num[i] == '0')
- base = 8;
-
- if (base == 0)
- base = 10;
-
- if (base < 2 || base > 36)
- {
- errno = EINVAL;
- return 0;
- }
-
- result = high_part = 0;
- for (; is_digit_in_base (num[i], base); i += 1)
- {
- result = result * base + digit_to_int (num[i]);
- high_part = high_part * base + (unsigned int) (result >> HIGH_BYTE_POSN);
- result &= ((ULONGEST) 1 << HIGH_BYTE_POSN) - 1;
- if (high_part > 0xff)
- {
- errno = ERANGE;
- result = ~ (ULONGEST) 0;
- high_part = 0;
- minus = 0;
- break;
- }
- }
-
- if (trailer != NULL)
- *trailer = &num[i];
-
- result = result + ((ULONGEST) high_part << HIGH_BYTE_POSN);
- if (minus)
- return -result;
- else
- return result;
-}
-
/* Simple, portable version of dirname that does not modify its
argument. */
diff --git a/gdb/utils.h b/gdb/utils.h
index ad5bea4..e3b6fbf 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -39,8 +39,6 @@ extern int streq (const char *, const char *);
extern int subset_compare (char *, char *);
-ULONGEST strtoulst (const char *num, const char **trailer, int base);
-
int compare_positive_ints (const void *ap, const void *bp);
int compare_strings (const void *ap, const void *bp);
--
1.7.10.4
next prev parent reply other threads:[~2013-04-06 19:11 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 15:07 [patch] gdbserver build-id in qxfer_libraries reply Aleksandar Ristovski
2013-02-22 18:39 ` Aleksandar Ristovski
2013-02-26 12:01 ` Pedro Alves
2013-02-27 17:25 ` Aleksandar Ristovski
2013-02-27 17:31 ` Aleksandar Ristovski
2013-02-27 18:44 ` Eli Zaretskii
2013-03-10 21:07 ` [draft patch 0/6] Split FYI and some review notes Jan Kratochvil
2013-03-11 14:25 ` Aleksandar Ristovski
2013-03-11 15:07 ` Jan Kratochvil
2013-03-14 18:43 ` Gary Benson
2013-03-14 19:55 ` Tom Tromey
2013-03-15 15:35 ` Aleksandar Ristovski
2013-03-15 15:44 ` Aleksandar Ristovski
2013-03-15 15:38 ` Aleksandar Ristovski
2013-03-15 16:28 ` Jan Kratochvil
2013-03-15 16:43 ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 2/6] Merge multiple hex conversions Jan Kratochvil
2013-03-22 13:05 ` [patch " Aleksandar Ristovski
2013-04-05 16:07 ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 4/6] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2013-03-22 13:34 ` [patch " Aleksandar Ristovski
2013-03-22 13:54 ` Aleksandar Ristovski
2013-03-26 18:11 ` Jan Kratochvil
2013-03-27 20:44 ` Aleksandar Ristovski
2013-03-27 21:54 ` Aleksandar Ristovski
2013-03-28 23:02 ` Jan Kratochvil
2013-03-29 0:26 ` Aleksandar Ristovski
2013-03-29 0:29 ` Pedro Alves
2013-04-01 22:39 ` Aleksandar Ristovski
2013-04-01 21:13 ` Aleksandar Ristovski
2013-04-02 13:41 ` Jan Kratochvil
2013-04-02 13:41 ` Aleksandar Ristovski
2013-04-02 13:41 ` Jan Kratochvil
2013-04-05 15:37 ` Aleksandar Ristovski
2013-04-07 14:28 ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 3/6] Create empty common/linux-maps.[ch] Jan Kratochvil
2013-03-22 14:54 ` [patch " Aleksandar Ristovski
2013-03-22 13:06 ` Aleksandar Ristovski
2013-04-05 13:25 ` Aleksandar Ristovski
2013-03-10 21:08 ` [draft patch 1/6] Move utility functions to common/ Jan Kratochvil
2013-03-22 13:13 ` [patch " Aleksandar Ristovski
2013-03-22 13:05 ` Aleksandar Ristovski
2013-04-07 18:54 ` Aleksandar Ristovski [this message]
2013-04-05 13:06 ` Aleksandar Ristovski
2013-03-10 21:09 ` [draft patch 5/6] Move linux_find_memory_regions_full & co Jan Kratochvil
2013-03-22 13:05 ` [patch " Aleksandar Ristovski
2013-03-22 13:34 ` Aleksandar Ristovski
2013-03-26 18:27 ` Jan Kratochvil
2013-03-27 21:25 ` Aleksandar Ristovski
2013-03-28 22:38 ` Jan Kratochvil
2013-04-01 23:19 ` Aleksandar Ristovski
2013-04-02 2:33 ` Aleksandar Ristovski
2013-04-02 2:33 ` Jan Kratochvil
2013-04-07 18:54 ` Aleksandar Ristovski
2013-04-05 15:37 ` Aleksandar Ristovski
2013-03-10 21:09 ` [draft patch 6/6] gdbserver build-id attribute generator (unfixed) Jan Kratochvil
2013-03-10 22:04 ` Eli Zaretskii
2013-03-22 13:05 ` [patch 6/6] gdbserver build-id attribute generator Aleksandar Ristovski
2013-03-22 15:19 ` Aleksandar Ristovski
2013-03-22 17:24 ` Eli Zaretskii
2013-03-26 23:45 ` Jan Kratochvil
2013-03-27 17:54 ` Aleksandar Ristovski
2013-03-27 18:08 ` Jan Kratochvil
2013-03-27 18:12 ` Eli Zaretskii
2013-03-27 20:46 ` Aleksandar Ristovski
2013-03-29 0:13 ` Aleksandar Ristovski
2013-03-29 0:20 ` Aleksandar Ristovski
2013-03-29 16:19 ` Jan Kratochvil
[not found] ` <20130331174322.GB21374@host2.jankratochvil.net>
2013-04-02 17:18 ` Aleksandar Ristovski
2013-04-04 2:22 ` Jan Kratochvil
2013-04-05 15:05 ` Aleksandar Ristovski
2013-04-09 15:28 ` Gary Benson
2013-04-09 15:28 ` Jan Kratochvil
2013-04-09 15:29 ` Gary Benson
2013-04-09 15:29 ` Aleksandar Ristovski
2013-04-09 15:28 ` Aleksandar Ristovski
2013-04-09 19:26 ` Gary Benson
2013-04-12 15:28 ` Jan Kratochvil
2013-04-04 16:08 ` [patch] gdbserver build-id in qxfer_libraries reply Jan Kratochvil
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=515ECAAF.8030209@qnx.com \
--to=aristovski@qnx.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