Re: GDB 7.99.91 MinGW compilation error in cli-script.c

Eli Zaretskii
2017-05-21T15:33:41Z

> Cc: brobecker@adacore.com, simon.marchi@polymtl.ca, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Fri, 19 May 2017 12:23:06 +0100
>
> On 05/19/2017 12:17 PM, Eli Zaretskii wrote:
>
> > Fine with me, but Someone(TM) should figure out what to use instead of
> > "#if 0".
> >
>
> Something around
> __MINGW32__ / _GLIBCXX_USE_C99 / _GLIBCXX_HAVE_BROKEN_VSWPRINTF ?

Here's what I came up with. OK to commit?

--- gdb/common/common-utils.h~0 2017-04-17 17:09:57.000000000 +0300
+++ gdb/common/common-utils.h 2017-05-21 10:01:22.219168100 +0300
@@ -22,6 +22,7 @@

#include <string>
#include <vector>
+#include <sstream>

/* 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,42 @@
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__
+# include <_mingw.h>
+# ifndef _GLIBCXX_USE_C99
+# undef REPLACE_TO_STRING
+# define REPLACE_TO_STRING 1
+# endif
+#endif
+
+#if REPLACE_TO_STRING
+
+template <class T>
+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. */
--- gdb/cli/cli-script.c~0 2017-04-17 17:09:57.000000000 +0300
+++ gdb/cli/cli-script.c 2017-05-21 09:36:17.610252500 +0300
@@ -806,7 +818,7 @@ user_args::insert_args (const char *line

if (p[4] == 'c')
{
- new_line += std::to_string (m_args.size ());
+ new_line += gdb::to_string (m_args.size ());
line = p + 5;
}
else