mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-11-16 04:24:43 +00:00
Use gnulib c-ctype module in gdb
PR ada/33217 points out that gdb incorrectly calls the <ctype.h>
functions. In particular, gdb feels free to pass a 'char' like:
char *str = ...;
... isdigit (*str)
This is incorrect as isdigit only accepts EOF and values that can be
represented as 'unsigned char' -- that is, a cast is needed here to
avoid undefined behavior when 'char' is signed and a character in the
string might be sign-extended. (As an aside, I think this API seems
obviously bad, but unfortunately this is what the standard says, and
some systems check this.)
Rather than adding casts everywhere, this changes all the code in gdb
that uses any <ctype.h> API to instead call the corresponding c-ctype
function.
Now, c-ctype has some limitations compared to <ctype.h>. It works as
if the C locale is in effect, so in theory some non-ASCII characters
may be misclassified. This would only affect a subset of character
sets, though, and in most places I think ASCII is sufficient -- for
example the many places in gdb that check for whitespace.
Furthermore, in practice most users are using UTF-8-based locales,
where these functions aren't really informative for non-ASCII
characters anyway; see the existing workarounds in gdb/c-support.h.
Note that safe-ctype.h cannot be used because it causes conflicts with
readline.h. And, we canot poison the <ctype.h> identifiers as this
provokes errors from some libstdc++ headers.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33217
Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#if HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "gdbsupport/netstuff.h"
|
||||
#include "gdbsupport/filestuff.h"
|
||||
#include "gdbsupport/gdb-sigmask.h"
|
||||
#include <ctype.h>
|
||||
#if HAVE_SYS_IOCTL_H
|
||||
#include <sys/ioctl.h>
|
||||
#endif
|
||||
@@ -759,7 +758,7 @@ input_interrupt (int unused)
|
||||
else if (cc != 1 || c != '\003')
|
||||
{
|
||||
fprintf (stderr, "input_interrupt, count = %d c = %d ", cc, c);
|
||||
if (isprint (c))
|
||||
if (c_isprint (c))
|
||||
fprintf (stderr, "('%c')\n", c);
|
||||
else
|
||||
fprintf (stderr, "('\\x%02x')\n", c & 0xff);
|
||||
@@ -1165,8 +1164,8 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
|
||||
here is convert the buffer from a T packet to an S packet
|
||||
and the avoid adding any extra content by breaking out. */
|
||||
gdb_assert (buf_start[0] == 'T');
|
||||
gdb_assert (isxdigit (buf_start[1]));
|
||||
gdb_assert (isxdigit (buf_start[2]));
|
||||
gdb_assert (c_isxdigit (buf_start[1]));
|
||||
gdb_assert (c_isxdigit (buf_start[2]));
|
||||
buf_start[0] = 'S';
|
||||
buf_start[3] = '\0';
|
||||
break;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "tdesc.h"
|
||||
#include "gdbsupport/rsp-low.h"
|
||||
#include "gdbsupport/signals-state-save-restore.h"
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
@@ -1427,7 +1426,7 @@ parse_debug_format_options (const char *arg, int is_monitor)
|
||||
debug_timestamp = 0;
|
||||
|
||||
/* First remove leading spaces, for "monitor set debug-format". */
|
||||
while (isspace (*arg))
|
||||
while (c_isspace (*arg))
|
||||
++arg;
|
||||
|
||||
std::vector<gdb::unique_xmalloc_ptr<char>> options
|
||||
@@ -1473,8 +1472,8 @@ parse_debug_format_options (const char *arg, int is_monitor)
|
||||
struct debug_opt
|
||||
{
|
||||
/* NAME is the name of this debug option, this should be a simple string
|
||||
containing no whitespace, starting with a letter from isalpha(), and
|
||||
contain only isalnum() characters and '_' underscore and '-' hyphen.
|
||||
containing no whitespace, starting with a letter from c_isalpha(), and
|
||||
contain only c_isalnum() characters and '_' underscore and '-' hyphen.
|
||||
|
||||
SETTER is a callback function used to set the debug variable. This
|
||||
callback will be passed true to enable the debug setting, or false to
|
||||
@@ -1483,7 +1482,7 @@ struct debug_opt
|
||||
: m_name (name),
|
||||
m_setter (setter)
|
||||
{
|
||||
gdb_assert (isalpha (*name));
|
||||
gdb_assert (c_isalpha (*name));
|
||||
}
|
||||
|
||||
/* Called to enable or disable the debug setting. */
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
|
||||
struct thread_db
|
||||
{
|
||||
@@ -849,7 +848,7 @@ thread_db_handle_monitor_command (char *mon)
|
||||
free (libthread_db_search_path);
|
||||
|
||||
/* Skip leading space (if any). */
|
||||
while (isspace (*cp))
|
||||
while (c_isspace (*cp))
|
||||
++cp;
|
||||
|
||||
if (*cp == '\0')
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "gdbthread.h"
|
||||
#include "gdbsupport/rsp-low.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <chrono>
|
||||
@@ -1867,7 +1866,7 @@ add_tracepoint_action (struct tracepoint *tpoint, const char *packet)
|
||||
trace_debug ("Want to collect registers");
|
||||
++act;
|
||||
/* skip past hex digits of mask for now */
|
||||
while (isxdigit(*act))
|
||||
while (c_isxdigit(*act))
|
||||
++act;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user