#include "charset.h"
#include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
#include "gdbsupport/gdb_obstack.h"
#include "gdbsupport/gdb_wait.h"
#include "charset-list.h"
{
/* "CP" + x<=5 digits + paranoia. */
static char w32_host_default_charset[16];
-
- snprintf (w32_host_default_charset, sizeof w32_host_default_charset,
- "CP%d", GetACP());
+ unsigned codepage = mingw_get_codeset ();
+
+ /* The rest of the code expects a literal "UTF-8" and doesn't know
+ anything about codepage 65001. */
+ if (codepage == 65001)
+ {
+ strcpy (w32_host_default_charset, "UTF-8");
+ /* This is needed to force Windows CRT output functions treat
+ output as simple stream of bytes, instead of trying to
+ interpret it as encoded non-ASCII text, which will fail if
+ the system locale's codeset is NOT UTF-8. */
+ setlocale (LC_CTYPE, "C");
+ }
+ else
+ snprintf (w32_host_default_charset, sizeof w32_host_default_charset,
+ "CP%u", codepage);
auto_host_charset_name = w32_host_default_charset;
auto_target_charset_name = auto_host_charset_name;
+
+ /* Windows Terminal supports Emoji when using UTF-8 output. */
+ if (strcmp (w32_host_default_charset, "UTF-8") != 0)
+ no_emojis ();
}
#endif
#endif
#include "gdbsupport/event-loop.h"
#include "gdbsupport/gdb_select.h"
#include "inferior.h"
-#include "cli/cli-style.h"
#include "command.h"
#include "cli/cli-cmds.h"
#include "terminal.h"
+#include "charset.h"
#include <windows.h>
#include <signal.h>
}
else if (hstdout != INVALID_HANDLE_VALUE)
mingw_use_console_color_apis = -1; /* valid, but not a console device */
-
- if (mingw_use_console_color_apis > 0)
- no_emojis ();
}
void
return 1;
}
+unsigned int
+mingw_get_codeset ()
+{
+ unsigned int default_codepage = GetACP ();
+ unsigned int output_codepage = GetConsoleOutputCP ();
+
+ /* Multibyte writes will not work correctly if written one byte at a
+ time, which is what gdb_console_fputs above does. So if they set
+ the console's output to use UTF-8, only use that if we have
+ successfully set up the terminal for Virtual Terminal Sequences,
+ and are using 'fputs' directly. */
+ if (output_codepage == 0 /* GetConsoleOutputCP failed */
+ || (output_codepage == 65001
+ && output_codepage != default_codepage
+ && !(mingw_use_console_color_apis < 0
+ && hstdout != INVALID_HANDLE_VALUE
+ && orig_console_mode != 0)))
+ return default_codepage;
+ return output_codepage;
+}
+
/* See inferior.h. */
tribool