* gdb.base/help.exp (help source): Update expected output.
[deliverable/binutils-gdb.git] / gdb / c-lang.c
index 405c489fa4f9a857ccedc2847b4324306c9dc3bb..fefd67556459156040fe5f3ed9dedaa9edbba0a5 100644 (file)
@@ -1,7 +1,7 @@
 /* C language support routines for GDB, the GNU debugger.
 
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003,
-   2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   2004, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -43,23 +43,23 @@ extern void _initialize_c_language (void);
 
 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";
@@ -73,7 +73,7 @@ charset_for_string_type (enum c_string_type str_type,
    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;
@@ -134,7 +134,7 @@ classify_type (struct type *elttype, enum bfd_endian byte_order,
 
  done:
   if (encoding)
-    *encoding = charset_for_string_type (result, byte_order);
+    *encoding = charset_for_string_type (result, gdbarch);
 
   return result;
 }
@@ -264,7 +264,7 @@ c_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
   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);
@@ -340,7 +340,7 @@ c_printchar (int c, struct type *type, struct ui_file *stream)
 {
   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:
@@ -369,7 +369,7 @@ c_printchar (int c, struct type *type, struct ui_file *stream)
 
 void
 c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
-           unsigned int length, int force_ellipses,
+           unsigned int length, const char *user_encoding, int force_ellipses,
            const struct value_print_options *options)
 {
   enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
@@ -381,6 +381,7 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
   struct obstack wchar_buf, output;
   struct cleanup *cleanup;
   enum c_string_type str_type;
+  const char *type_encoding;
   const char *encoding;
   struct wchar_iterator *iter;
   int finished = 0;
@@ -395,7 +396,8 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
                                    width, byte_order) == 0))
     length--;
 
-  str_type = classify_type (type, byte_order, &encoding) & ~C_CHAR;
+  str_type = (classify_type (type, get_type_arch (type), &type_encoding)
+             & ~C_CHAR);
   switch (str_type)
     {
     case C_STRING:
@@ -411,6 +413,8 @@ c_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
       break;
     }
 
+  encoding = (user_encoding && *user_encoding) ? user_encoding : type_encoding;
+
   if (length == 0)
     {
       fputs_filtered ("\"\"", stream);
@@ -656,7 +660,7 @@ c_get_string (struct value *value, gdb_byte **buffer, int *length,
   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);
 
@@ -939,7 +943,6 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
        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);
@@ -976,8 +979,7 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
        /* 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)
This page took 0.027896 seconds and 4 git commands to generate.