Use c-ctype.h (not safe-ctype.h) in gdb

This changes gdb and related programs to use the gnulib c-ctype code
rather than safe-ctype.h.  The gdb-safe-ctype.h header is removed.

This changes common-defs.h to include the c-ctype header, making it
available everywhere in gdb.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33217
Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey
2025-08-04 09:58:43 -06:00
parent 50673a4629
commit 15e11aac9c
23 changed files with 78 additions and 140 deletions

View File

@@ -222,6 +222,12 @@
/* Pull in gdb::unique_xmalloc_ptr. */
#include "gdbsupport/gdb_unique_ptr.h"
/* Note that there's no simple way to enforce the use of the c-ctype
functions. We can't poison the <ctype.h> functions (see
safe-ctype.h) because that will provoke errors from libstdc++
headers. */
#include "c-ctype.h"
/* sbrk on macOS is not useful for our purposes, since sbrk(0) always
returns the same value. brk/sbrk on macOS is just an emulation
that always returns a pointer to a 4MB section reserved for

View File

@@ -19,7 +19,6 @@
#include "common-utils.h"
#include "host-defs.h"
#include "gdbsupport/gdb-safe-ctype.h"
#include "gdbsupport/gdb-xfree.h"
void *
@@ -180,7 +179,7 @@ extract_string_maybe_quoted (const char **arg)
/* Parse p similarly to gdb_argv buildargv function. */
while (*p != '\0')
{
if (ISSPACE (*p) && !squote && !dquote && !bsquote)
if (c_isspace (*p) && !squote && !dquote && !bsquote)
break;
else
{
@@ -254,21 +253,21 @@ make_quoted_string (const char *str)
static int
is_digit_in_base (unsigned char digit, int base)
{
if (!ISALNUM (digit))
if (!c_isalnum (digit))
return 0;
if (base <= 10)
return (ISDIGIT (digit) && digit < base + '0');
return (c_isdigit (digit) && digit < base + '0');
else
return (ISDIGIT (digit) || TOLOWER (digit) < base - 10 + 'a');
return (c_isdigit (digit) || c_tolower (digit) < base - 10 + 'a');
}
static int
digit_to_int (unsigned char c)
{
if (ISDIGIT (c))
if (c_isdigit (c))
return c - '0';
else
return TOLOWER (c) - 'a' + 10;
return c_tolower (c) - 'a' + 10;
}
/* As for strtoul, but for ULONGEST results. */
@@ -282,7 +281,7 @@ strtoulst (const char *num, const char **trailer, int base)
int i = 0;
/* Skip leading whitespace. */
while (ISSPACE (num[i]))
while (c_isspace (num[i]))
i++;
/* Handle prefixes. */
@@ -349,7 +348,7 @@ skip_spaces (char *chp)
{
if (chp == NULL)
return NULL;
while (*chp && ISSPACE (*chp))
while (*chp && c_isspace (*chp))
chp++;
return chp;
}
@@ -361,7 +360,7 @@ skip_spaces (const char *chp)
{
if (chp == NULL)
return NULL;
while (*chp && ISSPACE (*chp))
while (*chp && c_isspace (*chp))
chp++;
return chp;
}
@@ -373,7 +372,7 @@ skip_to_space (const char *chp)
{
if (chp == NULL)
return NULL;
while (*chp && !ISSPACE (*chp))
while (*chp && !c_isspace (*chp))
chp++;
return chp;
}

View File

@@ -1,49 +0,0 @@
/* Wrapper around libiberty's safe-ctype.h for GDB, the GNU debugger.
Copyright (C) 2019-2025 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef GDBSUPPORT_GDB_SAFE_CTYPE_H
#define GDBSUPPORT_GDB_SAFE_CTYPE_H
/* After safe-ctype.h is included, we can no longer use the host's
ctype routines. Trying to do so results in compile errors. Code
that uses safe-ctype.h that wants to refer to the locale-dependent
ctype functions must call these wrapper versions instead.
When compiling in C++ mode, also include <locale> before "safe-ctype.h"
which also defines is* functions. */
static inline int
gdb_isprint (int ch)
{
return isprint (ch);
}
/* readline.h defines these symbols too, but we want libiberty's
versions. */
#undef ISALPHA
#undef ISALNUM
#undef ISDIGIT
#undef ISLOWER
#undef ISPRINT
#undef ISUPPER
#undef ISXDIGIT
#include <locale>
#include "safe-ctype.h"
#endif /* GDBSUPPORT_GDB_SAFE_CTYPE_H */