+ case wide_string_arg:
+ {
+ gdb_byte *str;
+ CORE_ADDR tem;
+ int j;
+ struct gdbarch *gdbarch
+ = get_type_arch (value_type (val_args[i]));
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ struct type *wctype = lookup_typename (current_language, gdbarch,
+ "wchar_t", NULL, 0);
+ int wcwidth = TYPE_LENGTH (wctype);
+ gdb_byte *buf = alloca (wcwidth);
+ struct obstack output;
+ struct cleanup *inner_cleanup;
+
+ tem = value_as_address (val_args[i]);
+
+ /* This is a %s argument. Find the length of the string. */
+ for (j = 0;; j += wcwidth)
+ {
+ QUIT;
+ read_memory (tem + j, buf, wcwidth);
+ if (extract_unsigned_integer (buf, wcwidth, byte_order) == 0)
+ break;
+ }
+
+ /* Copy the string contents into a string inside GDB. */
+ str = (gdb_byte *) alloca (j + wcwidth);
+ if (j != 0)
+ read_memory (tem, str, j);
+ memset (&str[j], 0, wcwidth);
+
+ obstack_init (&output);
+ inner_cleanup = make_cleanup_obstack_free (&output);
+
+ convert_between_encodings (target_wide_charset (byte_order),
+ host_charset (),
+ str, j, wcwidth,
+ &output, translit_char);
+ obstack_grow_str0 (&output, "");
+
+ printf_filtered (current_substring, obstack_base (&output));
+ do_cleanups (inner_cleanup);
+ }
+ break;
+ case wide_char_arg:
+ {
+ struct gdbarch *gdbarch
+ = get_type_arch (value_type (val_args[i]));
+ enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
+ struct type *wctype = lookup_typename (current_language, gdbarch,
+ "wchar_t", NULL, 0);
+ struct type *valtype;
+ struct obstack output;
+ struct cleanup *inner_cleanup;
+ const gdb_byte *bytes;
+
+ valtype = value_type (val_args[i]);
+ if (TYPE_LENGTH (valtype) != TYPE_LENGTH (wctype)
+ || TYPE_CODE (valtype) != TYPE_CODE_INT)
+ error (_("expected wchar_t argument for %%lc"));
+
+ bytes = value_contents (val_args[i]);
+
+ obstack_init (&output);
+ inner_cleanup = make_cleanup_obstack_free (&output);
+
+ convert_between_encodings (target_wide_charset (byte_order),
+ host_charset (),
+ bytes, TYPE_LENGTH (valtype),
+ TYPE_LENGTH (valtype),
+ &output, translit_char);
+ obstack_grow_str0 (&output, "");
+
+ printf_filtered (current_substring, obstack_base (&output));
+ do_cleanups (inner_cleanup);
+ }
+ break;