From: "Christian Biesinger (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: gdb-patches@sourceware.org
Cc: Christian Biesinger <cbiesinger@google.com>
Subject: [review] Use strerror_r in safe_strerror if available
Date: Thu, 31 Oct 2019 19:44:00 -0000 [thread overview]
Message-ID: <gerrit.1572551088000.I81048fbaf148035c221c528727f7efe58ba528eb@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1572551088000.I81048fbaf148035c221c528727f7efe58ba528eb@gnutoolchain-gerrit.osci.io>
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/474
......................................................................
Use strerror_r in safe_strerror if available
Also stores the result in a thread-local static variable.
This is already important because Guile creates threads and
Python can create threads, but with the patch series here:
https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/176
GDB itself will create threads, too.
gdb/ChangeLog:
2019-10-31 Christian Biesinger <cbiesinger@google.com>
* configure: Regenerate.
* configure.ac: Check for strerror_r.
* gdbsupport/posix-strerror.c (safe_strerror): Make buf
thread_local and call strerror_r, if available.
Change-Id: I81048fbaf148035c221c528727f7efe58ba528eb
---
M gdb/configure
M gdb/configure.ac
M gdb/gdbsupport/posix-strerror.c
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/gdb/configure b/gdb/configure
index e805903..018cc4b 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -13073,7 +13073,7 @@
sigaction sigsetmask socketpair \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid \
- ptrace64 sigaltstack setns use_default_colors
+ ptrace64 sigaltstack setns use_default_colors strerror_r
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 354bb7b..987507a 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1318,7 +1318,7 @@
sigaction sigsetmask socketpair \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid \
- ptrace64 sigaltstack setns use_default_colors])
+ ptrace64 sigaltstack setns use_default_colors strerror_r])
AM_LANGINFO_CODESET
GDB_AC_COMMON
diff --git a/gdb/gdbsupport/posix-strerror.c b/gdb/gdbsupport/posix-strerror.c
index a8651b7..727eb7b 100644
--- a/gdb/gdbsupport/posix-strerror.c
+++ b/gdb/gdbsupport/posix-strerror.c
@@ -24,12 +24,22 @@
char *
safe_strerror (int errnum)
{
- char *msg;
+ static thread_local char buf[1024];
+ char *msg = nullptr;
+#ifdef HAVE_STRERROR_R
+#if !__GLIBC__ || ((_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE)
+ /* Glibc has two different, incompatible versions of strerror_r. */
+ if (strerror_r (errnum, buf, sizeof (buf)) == 0)
+ msg = buf;
+#else
+ msg = strerror_r (errnum, buf, sizeof (buf));
+#endif
+#else
msg = strerror (errnum);
- if (msg == NULL)
+#endif
+ if (msg == nullptr)
{
- static char buf[32];
xsnprintf (buf, sizeof buf, "(undocumented errno %d)", errnum);
msg = buf;
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I81048fbaf148035c221c528727f7efe58ba528eb
Gerrit-Change-Number: 474
Gerrit-PatchSet: 1
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-MessageType: newchange
next parent reply other threads:[~2019-10-31 19:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-31 19:44 Christian Biesinger (Code Review) [this message]
2019-10-31 19:53 ` Simon Marchi (Code Review)
2019-10-31 20:05 ` [review v2] " Christian Biesinger (Code Review)
2019-10-31 20:05 ` Christian Biesinger (Code Review)
2019-10-31 20:10 ` Simon Marchi (Code Review)
2019-10-31 20:10 ` Simon Marchi (Code Review)
2019-10-31 20:15 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-10-31 20:15 ` Sourceware to Gerrit sync (Code Review)
2019-11-01 15:21 ` [review v3] " Hannes Domani (Code Review)
2019-11-01 15:22 ` Christian Biesinger (Code Review)
2019-11-01 17:10 ` Tom Tromey
2019-11-06 1:08 ` Pedro Alves (Code Review)
2019-11-06 19:37 ` Christian Biesinger (Code Review)
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=gerrit.1572551088000.I81048fbaf148035c221c528727f7efe58ba528eb@gnutoolchain-gerrit.osci.io \
--to=gerrit@gnutoolchain-gerrit.osci.io \
--cc=cbiesinger@google.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