From patchwork Fri May 19 09:48:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 20507 Received: (qmail 8907 invoked by alias); 19 May 2017 09:49:01 -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 8075 invoked by uid 89); 19 May 2017 09:49:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 19 May 2017 09:48:59 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 544473D944; Fri, 19 May 2017 09:49:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 544473D944 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 544473D944 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8353B77EC0; Fri, 19 May 2017 09:48:58 +0000 (UTC) Subject: Re: GDB 7.99.91 MinGW compilation error in cli-script.c To: Eli Zaretskii , brobecker@adacore.com, simon.marchi@polymtl.ca 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> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Fri, 19 May 2017 10:48:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <83y3tt2ow0.fsf@gnu.org> On 05/19/2017 10:10 AM, Eli Zaretskii wrote: >> Date: Wed, 17 May 2017 19:01:23 +0300 >> From: Eli Zaretskii >> CC: simon.marchi@polymtl.ca, gdb-patches@sourceware.org >> >> I will probably post later a workaround patch for older versions, >> but that's for master. I see no reason to delay the release or to >> have the fix on the branch. > > Is the below OK? It's a bit ugly, and a small fix is needed even for > the latest MinGW runtime. Messing with libstdc++ internal macros and changing what libstdc++ defines is recipe for undefined behavior and trouble. I'd prefer avoiding it if possible. How about going back to the original gdb::to_string, implemented in terms of stringstring: https://sourceware.org/ml/gdb-patches/2016-10/msg00535.html ... with a tweak to only use if it the host compiler doesn't support std::to_string, like the patchlet below. (It's functionally equivalent, it's just that std::to_string is potentially cheaper.) We'd use gdb::to_string instead of std::to_string until compilers that miss std::to_string are phased out. From bf3b8c9199965d15ddf8f0435fab6b6af3b08bda Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 19 May 2017 10:34:51 +0100 Subject: [PATCH] to_string --- gdb/cli/cli-script.c | 2 +- gdb/common/common-utils.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index e0e27ef..3a2ae15 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -806,7 +806,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..2c35de8 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,30 @@ 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 on hosts that miss it. */ + +namespace gdb { + +#if 0 // some check here + +template +inline std::string +to_string (const T &val) +{ + std::stringstream ss; + + ss << val; + return ss.str (); +} + +#else + +using std::to_string; + +#endif + +} /* 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. */