static const char *
charset_for_string_type (enum c_string_type str_type,
- enum bfd_endian byte_order)
+ struct gdbarch *gdbarch)
{
switch (str_type & ~C_CHAR)
{
case C_STRING:
- return target_charset ();
+ return target_charset (gdbarch);
case C_WIDE_STRING:
- return target_wide_charset (byte_order);
+ return target_wide_charset (gdbarch);
case C_STRING_16:
/* FIXME: UTF-16 is not always correct. */
- if (byte_order == BFD_ENDIAN_BIG)
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
return "UTF-16BE";
else
return "UTF-16LE";
case C_STRING_32:
/* FIXME: UTF-32 is not always correct. */
- if (byte_order == BFD_ENDIAN_BIG)
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
return "UTF-32BE";
else
return "UTF-32LE";
characters of this type in target BYTE_ORDER to the host character set. */
static enum c_string_type
-classify_type (struct type *elttype, enum bfd_endian byte_order,
+classify_type (struct type *elttype, struct gdbarch *gdbarch,
const char **encoding)
{
- struct type *saved_type;
enum c_string_type result;
/* We loop because ELTTYPE may be a typedef, and we want to
done:
if (encoding)
- *encoding = charset_for_string_type (result, byte_order);
+ *encoding = charset_for_string_type (result, gdbarch);
return result;
}
int quoter, int *need_escapep)
{
int need_escape = *need_escapep;
+
*need_escapep = 0;
if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
&& w != LCST ('8')
{
char octal[30];
ULONGEST value;
+
value = extract_unsigned_integer (&orig[i], width, byte_order);
/* If the value fits in 3 octal digits, print it that
way. Otherwise, print it as a hex escape. */
while (i < orig_len)
{
char octal[5];
+
sprintf (octal, "\\%.3o", orig[i] & 0xff);
append_string_as_wide (octal, output);
++i;
string whose delimiter is QUOTER. Note that that format for printing
characters and strings is language specific. */
-static void
-c_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
+void
+c_emit_char (int c, struct type *type,
+ struct ui_file *stream, int quoter)
{
enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
struct obstack wchar_buf, output;
struct wchar_iterator *iter;
int need_escape = 0;
- classify_type (type, byte_order, &encoding);
+ classify_type (type, get_type_arch (type), &encoding);
buf = alloca (TYPE_LENGTH (type));
pack_long (buf, type, c);
{
enum c_string_type str_type;
- str_type = classify_type (type, BFD_ENDIAN_UNKNOWN, NULL);
+ str_type = classify_type (type, get_type_arch (type), NULL);
switch (str_type)
{
case C_CHAR:
int finished = 0;
int need_escape = 0;
+ if (length == -1)
+ {
+ unsigned long current_char = 1;
+
+ for (i = 0; current_char; ++i)
+ {
+ QUIT;
+ current_char = extract_unsigned_integer (string + i * width,
+ width, byte_order);
+ }
+ length = i;
+ }
+
/* If the string was not truncated due to `set print elements', and
the last byte of it is a null, we don't print that, in traditional C
style. */
width, byte_order) == 0))
length--;
- str_type = classify_type (type, byte_order, &type_encoding) & ~C_CHAR;
+ str_type = (classify_type (type, get_type_arch (type), &type_encoding)
+ & ~C_CHAR);
switch (str_type)
{
case C_STRING:
return;
}
- if (length == -1)
- {
- unsigned long current_char = 1;
- for (i = 0; current_char; ++i)
- {
- QUIT;
- current_char = extract_unsigned_integer (string + i * width,
- width, byte_order);
- }
- length = i;
- }
-
/* Arrange to iterate over the characters, in wchar_t form. */
iter = make_wchar_iterator (string, length * width, encoding, width);
cleanup = make_cleanup_wchar_iterator (iter);
/* Painful gyrations. */
int j;
char *s = xstrprintf (_(" <repeats %u times>"), reps);
+
for (j = 0; s[j]; ++j)
{
gdb_wchar_t w = gdb_btowc (s[j]);
if (! c_textual_element_type (element_type, 0))
goto error;
kind = classify_type (element_type,
- gdbarch_byte_order (get_type_arch (element_type)),
+ get_type_arch (element_type),
charset);
width = TYPE_LENGTH (element_type);
case 'U':
{
int length = *p == 'u' ? 4 : 8;
+
ADVANCE;
if (!isxdigit (*p))
error (_("\\u used with no following hex digits"));
while (data < limit)
{
char *p = data;
+
/* Look for next escape, or the end of the input. */
while (p < limit && *p != '\\')
++p;
struct value *result;
enum c_string_type dest_type;
const char *dest_charset;
- enum bfd_endian byte_order;
obstack_init (&output);
cleanup = make_cleanup_obstack_free (&output);
/* Ensure TYPE_LENGTH is valid for TYPE. */
check_typedef (type);
- byte_order = gdbarch_byte_order (exp->gdbarch);
- dest_charset = charset_for_string_type (dest_type, byte_order);
+ dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
++*pos;
while (*pos < limit)
else
{
int i;
+
/* Write the terminating character. */
for (i = 0; i < TYPE_LENGTH (type); ++i)
obstack_1grow (&output, 0);
struct language_arch_info *lai)
{
const struct builtin_type *builtin = builtin_type (gdbarch);
+
lai->string_char_type = builtin->builtin_char;
lai->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1,
lai->bool_type_default = builtin->builtin_int;
}
-static const struct exp_descriptor exp_descriptor_c =
+const struct exp_descriptor exp_descriptor_c =
{
print_subexp_standard,
operator_length_standard,
+ operator_check_standard,
op_name_standard,
dump_subexp_body_standard,
evaluate_subexp_c
struct language_arch_info *lai)
{
const struct builtin_type *builtin = builtin_type (gdbarch);
+
lai->string_char_type = builtin->builtin_char;
lai->primitive_type_vector
= GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1,