From patchwork Wed May 24 18:28:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Zaretskii X-Patchwork-Id: 20565 Received: (qmail 23443 invoked by alias); 24 May 2017 18:28:49 -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 23431 invoked by uid 89); 24 May 2017 18:28:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 May 2017 18:28:46 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dDb1Z-0003Ow-Mi for gdb-patches@sourceware.org; Wed, 24 May 2017 14:28:48 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:55192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dDb1Z-0003Of-JQ; Wed, 24 May 2017 14:28:45 -0400 Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2096 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dDb1X-0007CG-Oz; Wed, 24 May 2017 14:28:45 -0400 Date: Wed, 24 May 2017 21:28:31 +0300 Message-Id: <834lwam7n4.fsf@gnu.org> From: Eli Zaretskii To: Pedro Alves CC: brobecker@adacore.com, simon.marchi@polymtl.ca, gdb-patches@sourceware.org In-reply-to: <54594002-5d70-9ff8-c481-0cbfc8c68c7b@redhat.com> (message from Pedro Alves on Tue, 23 May 2017 10:53:47 +0100) Subject: Re: GDB 7.99.91 MinGW compilation error in cli-script.c Reply-to: Eli Zaretskii References: <20170504194442.63AAF60B72@joel.gnat.com> <83o9v3cs25.fsf@gnu.org> <91d9fc6cc7c07674a0b5cd02e7b1502b@polymtl.ca> <8360h38r1r.fsf@gnu.org> <20170517143136.mdnstf2u2jiydvnd@adacore.com> <83fug35v70.fsf@gnu.org> <83y3tt2ow0.fsf@gnu.org> <83vaox2j0w.fsf@gnu.org> <7017128a-7b51-5436-657b-58807d04eb02@redhat.com> <83vaouns1q.fsf@gnu.org> <837f18ohr2.fsf@gnu.org> <54594002-5d70-9ff8-c481-0cbfc8c68c7b@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-IsSubscribed: yes > Cc: brobecker@adacore.com, simon.marchi@polymtl.ca, gdb-patches@sourceware.org > From: Pedro Alves > Date: Tue, 23 May 2017 10:53:47 +0100 > > >> It'd be useful for the archives if you expanded on which mingw versions > >> and compilers you tested this on. Also likewise a short comment to > >> the effect in the code would be likewise handy for future readers > > > > OK, will do. Here's the final version; okay to commit? diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a96e71f..d3a251b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2017-05-24 Eli Zaretskii + + * common/common-utils.h (REPLACE_TO_STRING) [__MINGW32__]: Define + to 1 if std::to_string is not available. + (std::to_string) [REPLACE_TO_STRING]: Provide a replacement + implementation. + 2017-05-24 Yao Qi * rs6000-tdep.c (gdb_print_insn_powerpc): Remove. diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index e0e27ef..2e5e397 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -806,7 +818,7 @@ user_args::insert_args (const char *line) const if (p[4] == 'c') { - new_line += std::to_string (m_args.size ()); + new_line += gdb::to_string (m_args.size ()); line = p + 5; } else diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index c331f0d..e3cd66e 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -22,6 +22,7 @@ #include #include +#include /* If possible, define FUNCTION_NAME, a macro containing the name of the function being defined. Since this macro may not always be @@ -63,6 +64,47 @@ int xsnprintf (char *str, size_t size, const char *format, ...) std::string string_printf (const char* fmt, ...) ATTRIBUTE_PRINTF (1, 2); +/* Returns a string representation of VAL. Replacement for C++11 + std::to_string for hosts that lack it. */ + +namespace gdb { + +#define REPLACE_TO_STRING 0 + +#ifdef __MINGW32__ +/* mingw.org's MinGW runtime before version 5.0 needs the replacement + below. Tested with mingwrt-3.22.2 and mingwrt-5.0, and with + libstdc++ included with MinGW GCC 5.3.0. */ +# include <_mingw.h> +/* We test __MINGW64_VERSION_MAJOR to exclude MinGW64, which doesn't + need this replacement. */ +# if !defined __MINGW64_VERSION_MAJOR && !defined _GLIBCXX_USE_C99 +# undef REPLACE_TO_STRING +# define REPLACE_TO_STRING 1 +# endif +#endif + +#if REPLACE_TO_STRING + +template +inline std::string +to_string (const T &val) +{ + std::stringstream ss; + + ss << val; + return ss.str (); +} + +#else /* !REPLACE_TO_STRING */ + +using std::to_string; + +#endif + +#undef REPLACE_TO_STRING +} + /* Make a copy of the string at PTR with LEN characters (and add a null character at the end in the copy). Uses malloc to get the space. Returns the address of the copy. */