2009-07-01 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gdb / c-lang.c
index f95c98f336915b4c506837c04212cabe11cfa0b2..57181433a5aef1177d06f57687159bd6cc05d99b 100644 (file)
@@ -77,9 +77,12 @@ classify_type (struct type *elttype, const char **encoding)
   struct type *saved_type;
   enum c_string_type result;
 
-  /* We do one or two passes -- one on ELTTYPE, and then maybe a
-     second one on a typedef target.  */
-  do
+  /* We loop because ELTTYPE may be a typedef, and we want to
+     successively peel each typedef until we reach a type we
+     understand.  We don't use CHECK_TYPEDEF because that will strip
+     all typedefs at once -- but in C, wchar_t is itself a typedef, so
+     that would do the wrong thing.  */
+  while (elttype)
     {
       char *name = TYPE_NAME (elttype);
 
@@ -107,10 +110,22 @@ classify_type (struct type *elttype, const char **encoding)
          goto done;
        }
 
-      saved_type = elttype;
-      CHECK_TYPEDEF (elttype);
+      if (TYPE_CODE (elttype) != TYPE_CODE_TYPEDEF)
+       break;
+
+      /* Call for side effects.  */
+      check_typedef (elttype);
+
+      if (TYPE_TARGET_TYPE (elttype))
+       elttype = TYPE_TARGET_TYPE (elttype);
+      else
+       {
+         /* Perhaps check_typedef did not update the target type.  In
+            this case, force the lookup again and hope it works out.
+            It never will for C, but it might for C++.  */
+         CHECK_TYPEDEF (elttype);
+       }
     }
-  while (elttype != saved_type);
 
   /* Punt.  */
   result = C_CHAR;
@@ -166,7 +181,7 @@ print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
                                            && w != LCST ('8')
                                            && w != LCST ('9'))))
     {
-      gdb_wchar_t wchar = (gdb_wchar_t) w;
+      gdb_wchar_t wchar = w;
 
       if (w == gdb_btowc (quoter) || w == LCST ('\\'))
        obstack_grow_wstr (output, LCST ("\\"));
@@ -904,17 +919,20 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
        switch (dest_type & ~C_CHAR)
          {
          case C_STRING:
-           type = language_string_char_type (current_language,
-                                             current_gdbarch);
+           type = language_string_char_type (exp->language_defn,
+                                             exp->gdbarch);
            break;
          case C_WIDE_STRING:
-           type = lookup_typename ("wchar_t", NULL, 0);
+           type = lookup_typename (exp->language_defn, exp->gdbarch,
+                                   "wchar_t", NULL, 0);
            break;
          case C_STRING_16:
-           type = lookup_typename ("char16_t", NULL, 0);
+           type = lookup_typename (exp->language_defn, exp->gdbarch,
+                                   "char16_t", NULL, 0);
            break;
          case C_STRING_32:
-           type = lookup_typename ("char32_t", NULL, 0);
+           type = lookup_typename (exp->language_defn, exp->gdbarch,
+                                   "char32_t", NULL, 0);
            break;
          default:
            internal_error (__FILE__, __LINE__, "unhandled c_string_type");
@@ -948,7 +966,7 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
            if ((dest_type & C_CHAR) != 0)
              result = allocate_value (type);
            else
-             result = value_typed_string ("", 0, type);
+             result = value_cstring ("", 0, type);
            do_cleanups (cleanup);
            return result;
          }
@@ -968,9 +986,9 @@ evaluate_subexp_c (struct type *expect_type, struct expression *exp,
            /* Write the terminating character.  */
            for (i = 0; i < TYPE_LENGTH (type); ++i)
              obstack_1grow (&output, 0);
-           result = value_typed_string (obstack_base (&output),
-                                        obstack_object_size (&output),
-                                        type);
+           result = value_cstring (obstack_base (&output),
+                                   obstack_object_size (&output),
+                                   type);
          }
        do_cleanups (cleanup);
        return result;
This page took 0.025054 seconds and 4 git commands to generate.