mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-04 22:15:12 +08:00
Replace the remaining uses of strerror with safe_strerror
To do that, this patch makes IPA compile safe-strerror as well. Because it doesn't use Gnulib, it calls the Glibc version of strerror_r directly. Consequently this patch also removes the configure checks for strerror. gdb/ChangeLog: 2019-12-10 Christian Biesinger <cbiesinger@google.com> * config.in: Regenerate. * configure: Regenerate. * gdbsupport/agent.c (gdb_connect_sync_socket): Call safe_strerror instead of strerror. * gdbsupport/common.m4: Don't check for strerror. * gdbsupport/safe-strerror.c: Support both the glibc version of strerror_r and the XSI version. gdb/gdbserver/ChangeLog: 2019-12-10 Christian Biesinger <cbiesinger@google.com> * Makefile.in: Add safe-strerror.c to gdbreplay and IPA, and change UNDO_GNULIB_CFLAGS to undo strerror_r instead of strerror. * config.in: Regenerate. * configure: Regenerate. * configure.ac: Don't check for strerror. * linux-i386-ipa.c (initialize_fast_tracepoint_trampoline_buffer): Call safe_strerror instead of strerror. * server.h (strerror): Remove this now-unnecessary declaration. * tracepoint.c (init_named_socket): Call safe_strerror instead of strerror. (gdb_agent_helper_thread): Likewise. * utils.c (perror_with_name): Likewise. Change-Id: I74848f072dcde75cb55c435ef9398dc8f958cd73
This commit is contained in:
@ -1,3 +1,13 @@
|
|||||||
|
2019-12-10 Christian Biesinger <cbiesinger@google.com>
|
||||||
|
|
||||||
|
* config.in: Regenerate.
|
||||||
|
* configure: Regenerate.
|
||||||
|
* gdbsupport/agent.c (gdb_connect_sync_socket): Call
|
||||||
|
safe_strerror instead of strerror.
|
||||||
|
* gdbsupport/common.m4: Don't check for strerror.
|
||||||
|
* gdbsupport/safe-strerror.c: Support both the glibc version
|
||||||
|
of strerror_r and the XSI version.
|
||||||
|
|
||||||
2019-12-10 Tom Tromey <tromey@adacore.com>
|
2019-12-10 Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
* ada-typeprint.c (print_choices): Use a single "?".
|
* ada-typeprint.c (print_choices): Use a single "?".
|
||||||
|
@ -117,10 +117,6 @@
|
|||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL_SNPRINTF
|
#undef HAVE_DECL_SNPRINTF
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `strerror', and to 0 if you
|
|
||||||
don't. */
|
|
||||||
#undef HAVE_DECL_STRERROR
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `strstr', and to 0 if you don't.
|
/* Define to 1 if you have the declaration of `strstr', and to 0 if you don't.
|
||||||
*/
|
*/
|
||||||
#undef HAVE_DECL_STRSTR
|
#undef HAVE_DECL_STRSTR
|
||||||
|
12
gdb/configure
vendored
12
gdb/configure
vendored
@ -13630,17 +13630,7 @@ fi
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
ac_fn_c_check_decl "$LINENO" "strerror" "ac_cv_have_decl_strerror" "$ac_includes_default"
|
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
|
||||||
if test "x$ac_cv_have_decl_strerror" = xyes; then :
|
|
||||||
ac_have_decl=1
|
|
||||||
else
|
|
||||||
ac_have_decl=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat >>confdefs.h <<_ACEOF
|
|
||||||
#define HAVE_DECL_STRERROR $ac_have_decl
|
|
||||||
_ACEOF
|
|
||||||
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
|
|
||||||
if test "x$ac_cv_have_decl_strstr" = xyes; then :
|
if test "x$ac_cv_have_decl_strstr" = xyes; then :
|
||||||
ac_have_decl=1
|
ac_have_decl=1
|
||||||
else
|
else
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
2019-12-10 Christian Biesinger <cbiesinger@google.com>
|
||||||
|
|
||||||
|
* Makefile.in: Add safe-strerror.c to gdbreplay and IPA, and change
|
||||||
|
UNDO_GNULIB_CFLAGS to undo strerror_r instead of strerror.
|
||||||
|
* config.in: Regenerate.
|
||||||
|
* configure: Regenerate.
|
||||||
|
* configure.ac: Don't check for strerror.
|
||||||
|
* linux-i386-ipa.c (initialize_fast_tracepoint_trampoline_buffer):
|
||||||
|
Call safe_strerror instead of strerror.
|
||||||
|
* server.h (strerror): Remove this now-unnecessary declaration.
|
||||||
|
* tracepoint.c (init_named_socket): Call safe_strerror instead of
|
||||||
|
strerror.
|
||||||
|
(gdb_agent_helper_thread): Likewise.
|
||||||
|
* utils.c (perror_with_name): Likewise.
|
||||||
|
|
||||||
2019-11-26 Tom Tromey <tom@tromey.com>
|
2019-11-26 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* configure, config.in: Rebuild.
|
* configure, config.in: Rebuild.
|
||||||
|
@ -304,6 +304,7 @@ GDBREPLAY_OBS = \
|
|||||||
gdbsupport/errors.o \
|
gdbsupport/errors.o \
|
||||||
gdbsupport/netstuff.o \
|
gdbsupport/netstuff.o \
|
||||||
gdbsupport/print-utils.o \
|
gdbsupport/print-utils.o \
|
||||||
|
gdbsupport/safe-strerror.o \
|
||||||
gdbreplay.o \
|
gdbreplay.o \
|
||||||
utils.o \
|
utils.o \
|
||||||
version.o
|
version.o
|
||||||
@ -430,6 +431,7 @@ IPA_OBJS = \
|
|||||||
gdbsupport/format-ipa.o \
|
gdbsupport/format-ipa.o \
|
||||||
gdbsupport/print-utils-ipa.o \
|
gdbsupport/print-utils-ipa.o \
|
||||||
gdbsupport/rsp-low-ipa.o \
|
gdbsupport/rsp-low-ipa.o \
|
||||||
|
gdbsupport/safe-strerror-ipa.o \
|
||||||
gdbsupport/tdesc-ipa.o \
|
gdbsupport/tdesc-ipa.o \
|
||||||
regcache-ipa.o \
|
regcache-ipa.o \
|
||||||
remote-utils-ipa.o \
|
remote-utils-ipa.o \
|
||||||
@ -557,7 +559,7 @@ UST_CFLAGS = $(ustinc) -DCONFIG_UST_GDB_INTEGRATION
|
|||||||
# Undo gnulib replacements for the IPA shared library build.
|
# Undo gnulib replacements for the IPA shared library build.
|
||||||
# The gnulib headers are still needed, but gnulib is not linked
|
# The gnulib headers are still needed, but gnulib is not linked
|
||||||
# into the IPA lib so replacement apis don't work.
|
# into the IPA lib so replacement apis don't work.
|
||||||
UNDO_GNULIB_CFLAGS = -Drpl_strerror=strerror
|
UNDO_GNULIB_CFLAGS = -Drpl_strerror_r=strerror_r
|
||||||
|
|
||||||
# Note, we only build the IPA if -fvisibility=hidden is supported in
|
# Note, we only build the IPA if -fvisibility=hidden is supported in
|
||||||
# the first place.
|
# the first place.
|
||||||
|
@ -54,10 +54,6 @@
|
|||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL_SNPRINTF
|
#undef HAVE_DECL_SNPRINTF
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `strerror', and to 0 if you
|
|
||||||
don't. */
|
|
||||||
#undef HAVE_DECL_STRERROR
|
|
||||||
|
|
||||||
/* Define to 1 if you have the declaration of `strstr', and to 0 if you don't.
|
/* Define to 1 if you have the declaration of `strstr', and to 0 if you don't.
|
||||||
*/
|
*/
|
||||||
#undef HAVE_DECL_STRSTR
|
#undef HAVE_DECL_STRSTR
|
||||||
|
22
gdb/gdbserver/configure
vendored
22
gdb/gdbserver/configure
vendored
@ -7022,17 +7022,7 @@ fi
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
ac_fn_c_check_decl "$LINENO" "strerror" "ac_cv_have_decl_strerror" "$ac_includes_default"
|
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
|
||||||
if test "x$ac_cv_have_decl_strerror" = xyes; then :
|
|
||||||
ac_have_decl=1
|
|
||||||
else
|
|
||||||
ac_have_decl=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat >>confdefs.h <<_ACEOF
|
|
||||||
#define HAVE_DECL_STRERROR $ac_have_decl
|
|
||||||
_ACEOF
|
|
||||||
ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
|
|
||||||
if test "x$ac_cv_have_decl_strstr" = xyes; then :
|
if test "x$ac_cv_have_decl_strstr" = xyes; then :
|
||||||
ac_have_decl=1
|
ac_have_decl=1
|
||||||
else
|
else
|
||||||
@ -8427,16 +8417,6 @@ _ACEOF
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ac_fn_c_check_decl "$LINENO" "strerror" "ac_cv_have_decl_strerror" "$ac_includes_default"
|
|
||||||
if test "x$ac_cv_have_decl_strerror" = xyes; then :
|
|
||||||
ac_have_decl=1
|
|
||||||
else
|
|
||||||
ac_have_decl=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat >>confdefs.h <<_ACEOF
|
|
||||||
#define HAVE_DECL_STRERROR $ac_have_decl
|
|
||||||
_ACEOF
|
|
||||||
ac_fn_c_check_decl "$LINENO" "perror" "ac_cv_have_decl_perror" "$ac_includes_default"
|
ac_fn_c_check_decl "$LINENO" "perror" "ac_cv_have_decl_perror" "$ac_includes_default"
|
||||||
if test "x$ac_cv_have_decl_perror" = xyes; then :
|
if test "x$ac_cv_have_decl_perror" = xyes; then :
|
||||||
ac_have_decl=1
|
ac_have_decl=1
|
||||||
|
@ -158,7 +158,7 @@ LIBS="$old_LIBS"
|
|||||||
|
|
||||||
libiberty_INIT
|
libiberty_INIT
|
||||||
|
|
||||||
AC_CHECK_DECLS([strerror, perror, vasprintf, vsnprintf])
|
AC_CHECK_DECLS([perror, vasprintf, vsnprintf])
|
||||||
|
|
||||||
AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
|
AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ initialize_fast_tracepoint_trampoline_buffer (void)
|
|||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
snprintf (buf, sizeof (buf), "mmap_min_addr open failed: %s",
|
snprintf (buf, sizeof (buf), "mmap_min_addr open failed: %s",
|
||||||
strerror (errno));
|
safe_strerror (errno));
|
||||||
set_trampoline_buffer_space (0, 0, buf);
|
set_trampoline_buffer_space (0, 0, buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ initialize_fast_tracepoint_trampoline_buffer (void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf (buf, IPA_BUFSIZ, "low-64K-buffer mmap() failed: %s",
|
snprintf (buf, IPA_BUFSIZ, "low-64K-buffer mmap() failed: %s",
|
||||||
strerror (errno));
|
safe_strerror (errno));
|
||||||
set_trampoline_buffer_space (0, 0, buf);
|
set_trampoline_buffer_space (0, 0, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,6 @@ gdb_static_assert (sizeof (CORE_ADDR) >= sizeof (void *));
|
|||||||
|
|
||||||
#include "gdbsupport/version.h"
|
#include "gdbsupport/version.h"
|
||||||
|
|
||||||
#if !HAVE_DECL_STRERROR
|
|
||||||
#ifndef strerror
|
|
||||||
extern char *strerror (int); /* X3.159-1989 4.11.6.2 */
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !HAVE_DECL_PERROR
|
#if !HAVE_DECL_PERROR
|
||||||
#ifndef perror
|
#ifndef perror
|
||||||
extern void perror (const char *);
|
extern void perror (const char *);
|
||||||
|
@ -6879,7 +6879,7 @@ init_named_socket (const char *name)
|
|||||||
result = fd = socket (PF_UNIX, SOCK_STREAM, 0);
|
result = fd = socket (PF_UNIX, SOCK_STREAM, 0);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
warning ("socket creation failed: %s", strerror (errno));
|
warning ("socket creation failed: %s", safe_strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6895,7 +6895,7 @@ init_named_socket (const char *name)
|
|||||||
result = unlink (name);
|
result = unlink (name);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
warning ("unlink failed: %s", strerror (errno));
|
warning ("unlink failed: %s", safe_strerror (errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -6905,7 +6905,7 @@ init_named_socket (const char *name)
|
|||||||
result = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
|
result = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
warning ("bind failed: %s", strerror (errno));
|
warning ("bind failed: %s", safe_strerror (errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -6913,7 +6913,7 @@ init_named_socket (const char *name)
|
|||||||
result = listen (fd, 1);
|
result = listen (fd, 1);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
warning ("listen: %s", strerror (errno));
|
warning ("listen: %s", safe_strerror (errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -7219,7 +7219,7 @@ gdb_agent_helper_thread (void *arg)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
warning ("Accept returned %d, error: %s",
|
warning ("Accept returned %d, error: %s",
|
||||||
fd, strerror (errno));
|
fd, safe_strerror (errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7231,7 +7231,7 @@ gdb_agent_helper_thread (void *arg)
|
|||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
{
|
{
|
||||||
warning ("reading socket (fd=%d) failed with %s",
|
warning ("reading socket (fd=%d) failed with %s",
|
||||||
fd, strerror (errno));
|
fd, safe_strerror (errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ perror_with_name (const char *string)
|
|||||||
const char *err;
|
const char *err;
|
||||||
char *combined;
|
char *combined;
|
||||||
|
|
||||||
err = strerror (errno);
|
err = safe_strerror (errno);
|
||||||
if (err == NULL)
|
if (err == NULL)
|
||||||
err = "unknown error";
|
err = "unknown error";
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ gdb_connect_sync_socket (int pid)
|
|||||||
res = fd = gdb_socket_cloexec (PF_UNIX, SOCK_STREAM, 0);
|
res = fd = gdb_socket_cloexec (PF_UNIX, SOCK_STREAM, 0);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
warning (_("error opening sync socket: %s"), strerror (errno));
|
warning (_("error opening sync socket: %s"), safe_strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ gdb_connect_sync_socket (int pid)
|
|||||||
{
|
{
|
||||||
warning (_("error connecting sync socket (%s): %s. "
|
warning (_("error connecting sync socket (%s): %s. "
|
||||||
"Make sure the directory exists and that it is writable."),
|
"Make sure the directory exists and that it is writable."),
|
||||||
path, strerror (errno));
|
path, safe_strerror (errno));
|
||||||
close (fd);
|
close (fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ AC_DEFUN([GDB_AC_COMMON], [
|
|||||||
AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction \
|
AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction \
|
||||||
sigprocmask])
|
sigprocmask])
|
||||||
|
|
||||||
AC_CHECK_DECLS([strerror, strstr])
|
AC_CHECK_DECLS([strstr])
|
||||||
|
|
||||||
# Check for std::thread. This does not work on some platforms, like
|
# Check for std::thread. This does not work on some platforms, like
|
||||||
# mingw and DJGPP.
|
# mingw and DJGPP.
|
||||||
|
@ -20,6 +20,26 @@
|
|||||||
#include "common-defs.h"
|
#include "common-defs.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* There are two different versions of strerror_r; one is GNU-specific, the
|
||||||
|
other XSI-compliant. They differ in the return type. This overload lets
|
||||||
|
us choose the right behavior for each return type. We cannot rely on Gnulib
|
||||||
|
to solve this for us because IPA does not use Gnulib but uses this
|
||||||
|
function. */
|
||||||
|
|
||||||
|
/* Called if we have a XSI-compliant strerror_r. */
|
||||||
|
static char *
|
||||||
|
select_strerror_r (int res, char *buf)
|
||||||
|
{
|
||||||
|
return res == 0 ? buf : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called if we have a GNU strerror_r. */
|
||||||
|
static char *
|
||||||
|
select_strerror_r (char *res, char *)
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/* Implementation of safe_strerror as defined in common-utils.h. */
|
/* Implementation of safe_strerror as defined in common-utils.h. */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -27,11 +47,9 @@ safe_strerror (int errnum)
|
|||||||
{
|
{
|
||||||
static thread_local char buf[1024];
|
static thread_local char buf[1024];
|
||||||
|
|
||||||
/* Assign the return value to an int, so we get an error if we accidentally
|
char *res = select_strerror_r (strerror_r (errnum, buf, sizeof (buf)), buf);
|
||||||
get the wrong version of this function (glibc has two of them...). */
|
if (res != nullptr)
|
||||||
int ret = strerror_r (errnum, buf, sizeof (buf));
|
return res;
|
||||||
if (ret == 0)
|
|
||||||
return buf;
|
|
||||||
|
|
||||||
xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
|
xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
|
||||||
return buf;
|
return buf;
|
||||||
|
Reference in New Issue
Block a user