gdbsupport: make use of safe-ctype functions from libiberty

Make use of the safe-ctype replacements for the standard ctype
character checking functions in gdbsupport/common-utils.cc.  The
gdbsupport library is included into both gdb and gdbserver, and on the
gdbserver side there are two targets, gdbserver itself, and also
libinproctrace.so.

libiberty was already being included in the gdbserver link command,
but was missing from the libinproctrace.so link.  As a result, after
changing gdbsupport/common-utils.cc to depend on libiberty,
libinproctrace.so would no longer link until I modified its link line.

gdbserver/ChangeLog:

	* Makefile.in (IPA_LIB): Include libiberty library.

gdbsupport/ChangeLog:

	* gdbsupport/common-utils.cc: Change 'ctype.h' include to
	'safe-ctype.h'.
	(extract_string_maybe_quoted): Use safe-ctype function versions.
	(is_digit_in_base): Likewise.
	(digit_to_int): Likewise.
	(strtoulst): Likewise.
	(skip_spaces): Likewise.
	(skip_to_space): Likewise.
This commit is contained in:
Andrew Burgess 2020-11-20 17:23:03 +00:00
parent 94ba44a68d
commit 9664849417
4 changed files with 27 additions and 12 deletions

View file

@ -1,3 +1,7 @@
2020-12-11 Andrew Burgess <andrew.burgess@embecosm.com>
* Makefile.in (IPA_LIB): Include libiberty library.
2020-11-11 Andrew Burgess <andrew.burgess@embecosm.com> 2020-11-11 Andrew Burgess <andrew.burgess@embecosm.com>
* server.cc (gdbserver_usage): Add missing option to usage text. * server.cc (gdbserver_usage): Add missing option to usage text.

View file

@ -395,7 +395,7 @@ $(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
$(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \ $(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
-Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \ -Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
$(CXXFLAGS) \ $(CXXFLAGS) \
-o $(IPA_LIB) ${IPA_OBJS} -ldl -pthread -o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY) -ldl -pthread
# Put the proper machine-specific files first, so M-. on a machine # Put the proper machine-specific files first, so M-. on a machine
# specific routine gets the one for the correct machine. # specific routine gets the one for the correct machine.

View file

@ -1,3 +1,14 @@
2020-12-11 Andrew Burgess <andrew.burgess@embecosm.com>
* gdbsupport/common-utils.cc: Change 'ctype.h' include to
'safe-ctype.h'.
(extract_string_maybe_quoted): Use safe-ctype function versions.
(is_digit_in_base): Likewise.
(digit_to_int): Likewise.
(strtoulst): Likewise.
(skip_spaces): Likewise.
(skip_to_space): Likewise.
2020-12-11 Simon Marchi <simon.marchi@polymtl.ca> 2020-12-11 Simon Marchi <simon.marchi@polymtl.ca>
* common-debug.h (debug_prefixed_printf_cond): New. * common-debug.h (debug_prefixed_printf_cond): New.

View file

@ -20,7 +20,7 @@
#include "common-defs.h" #include "common-defs.h"
#include "common-utils.h" #include "common-utils.h"
#include "host-defs.h" #include "host-defs.h"
#include <ctype.h> #include "safe-ctype.h"
void * void *
xzalloc (size_t size) xzalloc (size_t size)
@ -177,7 +177,7 @@ extract_string_maybe_quoted (const char **arg)
/* Parse p similarly to gdb_argv buildargv function. */ /* Parse p similarly to gdb_argv buildargv function. */
while (*p != '\0') while (*p != '\0')
{ {
if (isspace (*p) && !squote && !dquote && !bsquote) if (ISSPACE (*p) && !squote && !dquote && !bsquote)
break; break;
else else
{ {
@ -230,21 +230,21 @@ extract_string_maybe_quoted (const char **arg)
static int static int
is_digit_in_base (unsigned char digit, int base) is_digit_in_base (unsigned char digit, int base)
{ {
if (!isalnum (digit)) if (!ISALNUM (digit))
return 0; return 0;
if (base <= 10) if (base <= 10)
return (isdigit (digit) && digit < base + '0'); return (ISDIGIT (digit) && digit < base + '0');
else else
return (isdigit (digit) || tolower (digit) < base - 10 + 'a'); return (ISDIGIT (digit) || TOLOWER (digit) < base - 10 + 'a');
} }
static int static int
digit_to_int (unsigned char c) digit_to_int (unsigned char c)
{ {
if (isdigit (c)) if (ISDIGIT (c))
return c - '0'; return c - '0';
else else
return tolower (c) - 'a' + 10; return TOLOWER (c) - 'a' + 10;
} }
/* As for strtoul, but for ULONGEST results. */ /* As for strtoul, but for ULONGEST results. */
@ -258,7 +258,7 @@ strtoulst (const char *num, const char **trailer, int base)
int i = 0; int i = 0;
/* Skip leading whitespace. */ /* Skip leading whitespace. */
while (isspace (num[i])) while (ISSPACE (num[i]))
i++; i++;
/* Handle prefixes. */ /* Handle prefixes. */
@ -325,7 +325,7 @@ skip_spaces (char *chp)
{ {
if (chp == NULL) if (chp == NULL)
return NULL; return NULL;
while (*chp && isspace (*chp)) while (*chp && ISSPACE (*chp))
chp++; chp++;
return chp; return chp;
} }
@ -337,7 +337,7 @@ skip_spaces (const char *chp)
{ {
if (chp == NULL) if (chp == NULL)
return NULL; return NULL;
while (*chp && isspace (*chp)) while (*chp && ISSPACE (*chp))
chp++; chp++;
return chp; return chp;
} }
@ -349,7 +349,7 @@ skip_to_space (const char *chp)
{ {
if (chp == NULL) if (chp == NULL)
return NULL; return NULL;
while (*chp && !isspace (*chp)) while (*chp && !ISSPACE (*chp))
chp++; chp++;
return chp; return chp;
} }