From patchwork Thu Oct 31 21:06:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35540 Received: (qmail 37386 invoked by alias); 31 Oct 2019 21:06:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 37377 invoked by uid 89); 31 Oct 2019 21:06:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=200809L, 200809l X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 31 Oct 2019 21:06:25 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 489EB2031F; Thu, 31 Oct 2019 17:06:24 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 99F9220300; Thu, 31 Oct 2019 17:06:22 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 7B3CE20AF6; Thu, 31 Oct 2019 17:06:22 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Thu, 31 Oct 2019 17:06:22 -0400 From: "Christian Biesinger (Code Review)" To: gdb-patches@sourceware.org Cc: Christian Biesinger Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Use ctime_r and localtime_r if available X-Gerrit-Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd X-Gerrit-Change-Number: 475 X-Gerrit-ChangeURL: X-Gerrit-Commit: 5061e71a18c53c52b1a46341967c5437acafa21f References: Reply-To: cbiesinger@google.com, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-75-g9005159e5d Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/475 ...................................................................... Use ctime_r and localtime_r if available This requires definining _POSIX_C_SOURCE for glibc. I don't know if there are any undesired side-effects from that. I am also adding the strerror_r check to gdbserver's configure.ac that I previously forgot (but gdbserver doesn't use threads as much, so that's less critical) gdb/ChangeLog: 2019-10-31 Christian Biesinger * config.in: Regenerate. * configure: Regenerate. * configure.ac: Check for localtime_r and ctime_r, and define _POSIX_C_SOURCE so that we actually find them. * maint.c (scoped_command_stats::print_time): Use localtime_r when available instead of localtime. * nat/linux-osdata.c (time_from_time_t): Use ctime_r if available instead of ctime. gdb/gdbserver/ChangeLog: 2019-10-31 Christian Biesinger * config.in: Regenerate. * configure: Regenerate. * configure.ac: Define _POSIX_C_SOURCE and search for strerror_r and ctime_r. Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd --- M gdb/config.in M gdb/configure M gdb/configure.ac M gdb/gdbserver/config.in M gdb/gdbserver/configure M gdb/gdbserver/configure.ac M gdb/maint.c M gdb/nat/linux-osdata.c 8 files changed, 42 insertions(+), 5 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index 5a21fca..a676b47 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -78,6 +78,9 @@ /* Define to 1 if you have the `btowc' function. */ #undef HAVE_BTOWC +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + /* Define to 1 if you have the header file. */ #undef HAVE_CURSESX_H @@ -261,6 +264,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LOCALE_H +/* Define to 1 if you have the `localtime_r' function. */ +#undef HAVE_LOCALTIME_R + /* Define to 1 if the compiler supports long double. */ #undef HAVE_LONG_DOUBLE @@ -780,6 +786,9 @@ this defined. */ #undef _POSIX_1_SOURCE +/* We want the latest POSIX standard */ +#undef _POSIX_C_SOURCE + /* Define to 1 if you need to in order for `stat' and other things to work. */ #undef _POSIX_SOURCE diff --git a/gdb/configure b/gdb/configure index 018cc4b..42cfb5b 100755 --- a/gdb/configure +++ b/gdb/configure @@ -4408,6 +4408,9 @@ $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h + +$as_echo "#define _POSIX_C_SOURCE 200809L" >>confdefs.h + ac_aux_dir= for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do if test -f "$ac_dir/install-sh"; then @@ -13072,7 +13075,7 @@ sbrk getpgid setpgid setpgrp setsid \ sigaction sigsetmask socketpair \ ttrace wborder wresize setlocale iconvlist libiconvlist btowc \ - setrlimit getrlimit posix_madvise waitpid \ + setrlimit getrlimit posix_madvise waitpid ctime_r localtime_r \ ptrace64 sigaltstack setns use_default_colors strerror_r do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/gdb/configure.ac b/gdb/configure.ac index 987507a..6a6ec5b 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -29,6 +29,7 @@ AC_PROG_CXX AC_USE_SYSTEM_EXTENSIONS +AC_DEFINE([_POSIX_C_SOURCE], [200809L], [We want the latest POSIX standard]) ACX_LARGEFILE AM_PROG_CC_STDC AM_PROG_INSTALL_STRIP @@ -1317,7 +1318,7 @@ sbrk getpgid setpgid setpgrp setsid \ sigaction sigsetmask socketpair \ ttrace wborder wresize setlocale iconvlist libiconvlist btowc \ - setrlimit getrlimit posix_madvise waitpid \ + setrlimit getrlimit posix_madvise waitpid ctime_r localtime_r \ ptrace64 sigaltstack setns use_default_colors strerror_r]) AM_LANGINFO_CODESET GDB_AC_COMMON diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index 0bce18d..78fbf26 100644 --- a/gdb/gdbserver/config.in +++ b/gdb/gdbserver/config.in @@ -21,6 +21,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + /* define if the compiler supports basic C++11 syntax */ #undef HAVE_CXX11 @@ -229,6 +232,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H +/* Define to 1 if you have the `strerror_r' function. */ +#undef HAVE_STRERROR_R + /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H @@ -420,6 +426,9 @@ this defined. */ #undef _POSIX_1_SOURCE +/* We want the latest POSIX standard */ +#undef _POSIX_C_SOURCE + /* Define to 1 if you need to in order for `stat' and other things to work. */ #undef _POSIX_SOURCE diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index e513fc5..8dd13b0 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -4094,6 +4094,9 @@ + +$as_echo "#define _POSIX_C_SOURCE 200809L" >>confdefs.h + # Check whether --enable-largefile was given. if test "${enable_largefile+set}" = set; then : enableval=$enable_largefile; @@ -6448,7 +6451,7 @@ fi -for ac_func in getauxval pread pwrite pread64 setns +for ac_func in getauxval pread pwrite pread64 setns strerror_r ctime_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/gdbserver/configure.ac b/gdb/gdbserver/configure.ac index 7ebc9c3..972a17d 100644 --- a/gdb/gdbserver/configure.ac +++ b/gdb/gdbserver/configure.ac @@ -26,6 +26,7 @@ AC_PROG_CC AC_PROG_CXX AC_GNU_SOURCE +AC_DEFINE([_POSIX_C_SOURCE], [200809L], [We want the latest POSIX standard]) AC_SYS_LARGEFILE AC_CANONICAL_SYSTEM @@ -90,7 +91,7 @@ sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl netinet/tcp.h arpa/inet.h) AC_FUNC_FORK -AC_CHECK_FUNCS(getauxval pread pwrite pread64 setns) +AC_CHECK_FUNCS(getauxval pread pwrite pread64 setns strerror_r ctime_r) GDB_AC_COMMON diff --git a/gdb/maint.c b/gdb/maint.c index ec9f4ab..36ab716 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -1039,7 +1039,12 @@ auto millis = ticks % 1000; std::time_t as_time = system_clock::to_time_t (now); +#ifdef HAVE_LOCALTIME_R + struct tm buf; + struct tm *tm = localtime_r (&as_time, &buf); +#else struct tm *tm = localtime (&as_time); +#endif char out[100]; strftime (out, sizeof (out), "%F %H:%M:%S", tm); diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 67f9f3a..e0bad81 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -912,7 +912,13 @@ { time_t t = (time_t) seconds; - strncpy (time, ctime (&t), maxlen); + char buf[30]; +#ifdef HAVE_CTIME_R + const char *time_str = ctime_r (&t, buf); +#else + const char *time_str = ctime (&t); +#endif + strncpy (time, time_str, maxlen); time[maxlen - 1] = '\0'; } }