public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Aleksandar Ristovski <ARistovski@qnx.com>
Subject: [PATCH v7 01/10] Move utility functions to common/
Date: Sun, 14 Jun 2015 19:25:00 -0000	[thread overview]
Message-ID: <20150614192551.18346.67512.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150614192542.18346.87859.stgit@host1.jankratochvil.net>

Hi,

some parts of the former patch have been reimplemented in the meantime by
other patches so this is only a part of the former cleanup.

Approved by:
	https://sourceware.org/ml/gdb-patches/2014-05/msg00363.html


Jan


gdb/ChangeLog
2014-02-26  Aleksandar Ristovski  <aristovski@qnx.com
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	Move utility functions to common/.
	* cli/cli-utils.c (skip_spaces, skip_spaces_const, skip_to_space_const):
	Move defs to common/common-utils.c.
	* cli/cli-utils.h (skip_spaces, skip_spaces_const, skip_to_space)
	(skip_to_space_const): Move decls to common/common-utils.h.
	* common/common-defs.h: Move include of common-types.h before
	common-utils.h.
	* common/common-utils.c: Include host-defs.h and ctype.h.
	(HIGH_BYTE_POSN, is_digit_in_base, digit_to_int, strtoulst): Move
	from utils.c.
	(skip_spaces, skip_spaces_const, skip_to_space_const): Move from
	cli/cli-utils.c.
	* common/common-utils.h (strtoulst): Move decl from utils.h.
	(skip_spaces, skip_spaces_const, skip_to_space, skip_to_space_const):
	Move from cli/cli-utils.h.
	* common/host-defs.h: Include limits.h.
	(TARGET_CHAR_BIT, HOST_CHAR_BIT): Moved from defs.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.
	* 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       |   36 ------------
 gdb/cli/cli-utils.h       |   18 ------
 gdb/common/common-defs.h  |    2 -
 gdb/common/common-utils.c |  137 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/common/common-utils.h |   20 +++++++
 gdb/common/host-defs.h    |   21 +++++++
 gdb/defs.h                |   19 ------
 gdb/utils.c               |   99 ---------------------------------
 gdb/utils.h               |    2 -
 9 files changed, 179 insertions(+), 175 deletions(-)

diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index f3586b6..5c6338b 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -225,42 +225,6 @@ number_is_in_list (const 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)
-{
-  if (chp == NULL)
-    return NULL;
-  while (*chp && !isspace (*chp))
-    chp++;
-  return chp;
-}
-
-/* See documentation in cli-utils.h.  */
-
-char *
 remove_trailing_whitespace (const char *start, char *s)
 {
   while (s > start && isspace (*(s - 1)))
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 5e191ec..ad46581 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -93,24 +93,6 @@ extern int get_number_or_range (struct get_number_or_range_state *state);
 
 extern int number_is_in_list (const 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.  */
-
-#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
-
-/* A const-correct version of the above.  */
-
-extern const char *skip_to_space_const (const char *inp);
-
 /* Reverse S to the last non-whitespace character without skipping past
    START.  */
 
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 62d9de5..2be0d7d 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -41,10 +41,10 @@
 #include "gdb/signals.h"
 #include "gdb_locale.h"
 #include "ptid.h"
+#include "common-types.h"
 #include "common-utils.h"
 #include "gdb_assert.h"
 #include "errors.h"
-#include "common-types.h"
 #include "print-utils.h"
 #include "common-debug.h"
 #include "cleanups.h"
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 2925dd5..e86ed5b 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -18,6 +18,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "common-defs.h"
+#include "host-defs.h"
+#include <ctype.h>
 
 /* The xmalloc() (libiberty.h) family of memory management routines.
 
@@ -151,3 +153,138 @@ 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;
+}
+
+/* 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)
+{
+  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 cd2665a..eef5e6b 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -77,4 +77,24 @@ startswith (const char *string, const char *pattern)
   return strncmp (string, pattern, strlen (pattern)) == 0;
 }
 
+ULONGEST strtoulst (const char *num, const char **trailer, int base);
+
+/* 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.  */
+
+#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
+
+/* A const-correct version of the above.  */
+
+extern const char *skip_to_space_const (const char *inp);
+
 #endif
diff --git a/gdb/common/host-defs.h b/gdb/common/host-defs.h
index 6c67034..7bc41a2 100644
--- a/gdb/common/host-defs.h
+++ b/gdb/common/host-defs.h
@@ -19,6 +19,27 @@
 #ifndef HOST_DEFS_H
 #define HOST_DEFS_H
 
+#include <limits.h>
+
+/* Static host-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
+
 #ifdef __MSDOS__
 # define CANT_FORK
 # define GLOBAL_CURDIR
diff --git a/gdb/defs.h b/gdb/defs.h
index 44702ea..32b08bb 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -591,25 +591,6 @@ extern double atof (const char *);	/* X3.159-1989  4.10.1.1 */
 
 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/utils.c b/gdb/utils.c
index 1c1ced4..acb4c7d 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2987,105 +2987,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 0e93ead..995a1cf 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -37,8 +37,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);
 

  reply	other threads:[~2015-06-14 19:25 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-14 19:25 [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-06-14 19:25 ` Jan Kratochvil [this message]
2015-06-15 13:22   ` [PATCH v7 01/10] Move utility functions to common/ Joel Brobecker
2015-06-15 15:07     ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 05/10] Move gdb_regex* " Jan Kratochvil
2015-07-08 14:39   ` Pedro Alves
2015-07-14 20:13     ` Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 07/10] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 03/10] Code cleanup: Rename enum -> enum filterflags Jan Kratochvil
2015-06-15 13:34   ` Joel Brobecker
2015-06-15 15:12     ` [commit] " Jan Kratochvil
2015-07-08 14:38   ` Pedro Alves
2015-06-14 19:26 ` [PATCH v7 02/10] Merge multiple hex conversions Jan Kratochvil
2015-06-15 13:33   ` Joel Brobecker
2015-06-15 15:09     ` [commit] " Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 06/10] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-06-14 19:26 ` [PATCH v7 04/10] Create empty nat/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-06-14 19:27 ` [PATCH v7 09/10] Validate symbol file using build-id Jan Kratochvil
2015-06-21 10:16   ` [PATCH v8 " Jan Kratochvil
2015-06-22 12:55     ` Aleksandar Ristovski
2015-06-22 20:37       ` Jan Kratochvil
2015-06-22 20:41         ` Aleksandar Ristovski
2015-06-22 22:25     ` Doug Evans
2015-06-23 20:47       ` Jan Kratochvil
2015-07-08 14:44         ` Pedro Alves
2015-07-12 19:09           ` Jan Kratochvil
2015-07-12 19:29             ` [PATCH v9 " Jan Kratochvil
2015-07-12 19:54               ` Eli Zaretskii
2015-07-12 20:01                 ` Jan Kratochvil
2015-07-13  2:30                   ` Eli Zaretskii
2015-07-13 10:34                 ` Pedro Alves
2015-07-13 12:38                   ` Jan Kratochvil
2015-07-14 16:14                     ` Doug Evans
2015-07-15  8:21                       ` Jan Kratochvil
2015-07-15 14:59                         ` Doug Evans
2015-06-27 21:05       ` [PATCH v8 " Jan Kratochvil
2015-07-08 15:40         ` Doug Evans
2015-07-12 19:27           ` Jan Kratochvil
2015-06-14 19:27 ` [PATCH v7 10/10] Tests for validate " Jan Kratochvil
2015-07-08 14:44   ` Pedro Alves
2015-06-14 19:27 ` [PATCH v7 08/10] gdbserver build-id attribute generator Jan Kratochvil
2015-07-08 14:41   ` Pedro Alves
2015-07-15 16:36 ` [commit] [PATCH v7 00/10] Validate binary before use Jan Kratochvil
2015-07-15 18:33   ` [revert] " 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=20150614192551.18346.67512.stgit@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).