/* Character set conversion support for GDB.
- Copyright (C) 2001-2020 Free Software Foundation, Inc.
+ Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "charset.h"
#include "gdbcmd.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "gdbsupport/gdb_wait.h"
#include "charset-list.h"
#include "gdbsupport/environ.h"
const char *value)
{
if (!strcmp (value, "auto"))
- fprintf_filtered (file,
- _("The host character set is \"auto; currently %s\".\n"),
- auto_host_charset_name);
+ gdb_printf (file,
+ _("The host character set is \"auto; currently %s\".\n"),
+ auto_host_charset_name);
else
- fprintf_filtered (file, _("The host character set is \"%s\".\n"), value);
+ gdb_printf (file, _("The host character set is \"%s\".\n"), value);
}
static const char *target_charset_name = "auto";
struct cmd_list_element *c, const char *value)
{
if (!strcmp (value, "auto"))
- fprintf_filtered (file,
- _("The target character set is \"auto; "
- "currently %s\".\n"),
- gdbarch_auto_charset (get_current_arch ()));
+ gdb_printf (file,
+ _("The target character set is \"auto; "
+ "currently %s\".\n"),
+ gdbarch_auto_charset (get_current_arch ()));
else
- fprintf_filtered (file, _("The target character set is \"%s\".\n"),
- value);
+ gdb_printf (file, _("The target character set is \"%s\".\n"),
+ value);
}
static const char *target_wide_charset_name = "auto";
const char *value)
{
if (!strcmp (value, "auto"))
- fprintf_filtered (file,
- _("The target wide character set is \"auto; "
- "currently %s\".\n"),
- gdbarch_auto_wide_charset (get_current_arch ()));
+ gdb_printf (file,
+ _("The target wide character set is \"auto; "
+ "currently %s\".\n"),
+ gdbarch_auto_wide_charset (get_current_arch ()));
else
- fprintf_filtered (file, _("The target wide character set is \"%s\".\n"),
- value);
+ gdb_printf (file, _("The target wide character set is \"%s\".\n"),
+ value);
}
static const char * const default_charset_names[] =
return c & 0237;
}
-/* Convert a host character, C, to its hex value. C must already have
- been validated using isxdigit. */
-
-int
-host_hex_value (char c)
-{
- if (isdigit (c))
- return c - '0';
- if (c >= 'a' && c <= 'f')
- return 10 + c - 'a';
- gdb_assert (c >= 'A' && c <= 'F');
- return 10 + c - 'A';
-}
-
\f
/* Public character management functions. */
{
iconv_t desc;
static const char *stored_result = NULL;
- char *result;
+ gdb::unique_xmalloc_ptr<char> result;
if (stored_result)
return stored_result;
result = xstrprintf ("UTF-%d%s", (int) (sizeof (gdb_wchar_t) * 8),
ENDIAN_SUFFIX);
/* Check that the name is supported by iconv_open. */
- desc = iconv_open (result, host_charset ());
+ desc = iconv_open (result.get (), host_charset ());
if (desc != (iconv_t) -1)
{
iconv_close (desc);
- stored_result = result;
- return result;
+ stored_result = result.release ();
+ return stored_result;
}
- /* Not valid, free the allocated memory. */
- xfree (result);
/* Second try, with UCS-2 type. */
result = xstrprintf ("UCS-%d%s", (int) sizeof (gdb_wchar_t),
ENDIAN_SUFFIX);
/* Check that the name is supported by iconv_open. */
- desc = iconv_open (result, host_charset ());
+ desc = iconv_open (result.get (), host_charset ());
if (desc != (iconv_t) -1)
{
iconv_close (desc);
- stored_result = result;
- return result;
+ stored_result = result.release ();
+ return stored_result;
}
- /* Not valid, free the allocated memory. */
- xfree (result);
/* No valid charset found, generate error here. */
error (_("Unable to find a valid charset for string conversions"));
}
#endif
#endif
+ /* Recall that the first element is always "auto". */
+ host_charset_name = charset_enum[0];
+ gdb_assert (strcmp (host_charset_name, "auto") == 0);
add_setshow_enum_cmd ("charset", class_support,
charset_enum, &host_charset_name, _("\
Set the host and target character sets."), _("\
show_host_charset_name,
&setlist, &showlist);
+ /* Recall that the first element is always "auto". */
+ target_charset_name = charset_enum[0];
+ gdb_assert (strcmp (target_charset_name, "auto") == 0);
add_setshow_enum_cmd ("target-charset", class_support,
charset_enum, &target_charset_name, _("\
Set the target character set."), _("\
show_target_charset_name,
&setlist, &showlist);
+ /* Recall that the first element is always "auto". */
+ target_wide_charset_name = charset_enum[0];
+ gdb_assert (strcmp (target_wide_charset_name, "auto") == 0);
add_setshow_enum_cmd ("target-wide-charset", class_support,
charset_enum, &target_wide_charset_name,
_("\