gdb: Introduce new language field la_is_string_type_p
[deliverable/binutils-gdb.git] / gdb / rust-lang.c
index 0c6c13d738e64588798ade84cfa81769142b4a5c..2fada465d651527d1c54fc99aa80f15df2063528 100644 (file)
@@ -226,6 +226,26 @@ rust_chartype_p (struct type *type)
          && TYPE_UNSIGNED (type));
 }
 
+/* Return true if TYPE is a string type.  */
+
+static bool
+rust_is_string_type_p (struct type *type)
+{
+  LONGEST low_bound, high_bound;
+
+  type = check_typedef (type);
+  return ((TYPE_CODE (type) == TYPE_CODE_STRING)
+         || (TYPE_CODE (type) == TYPE_CODE_PTR
+             && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY
+                 && rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
+                 && get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
+                                      &high_bound)))
+         || (TYPE_CODE (type) == TYPE_CODE_STRUCT
+             && !rust_enum_p (type)
+             && rust_slice_type_p (type)
+             && strcmp (TYPE_NAME (type), "&str") == 0));
+}
+
 /* If VALUE represents a trait object pointer, return the underlying
    pointer with the correct (i.e., runtime) type.  Otherwise, return
    NULL.  */
@@ -1743,18 +1763,17 @@ tuple structs, and tuple-like enum variants"));
                       field_name, TYPE_NAME (outer_type),
                       rust_last_path_segment (TYPE_NAME (type)));
 
-           TRY
+           try
              {
                result = value_struct_elt (&lhs, NULL, field_name,
                                           NULL, "structure");
              }
-           CATCH (except, RETURN_MASK_ERROR)
+           catch (const gdb_exception_error &except)
              {
                error (_("Could not find field %s of struct variant %s::%s"),
                       field_name, TYPE_NAME (outer_type),
                       rust_last_path_segment (TYPE_NAME (type)));
              }
-           END_CATCH
          }
        else
          result = value_struct_elt (&lhs, NULL, field_name, NULL, "structure");
@@ -2143,5 +2162,6 @@ extern const struct language_defn rust_language_defn =
   &default_varobj_ops,
   NULL,
   NULL,
-  LANG_MAGIC
+  rust_is_string_type_p,
+  "{...}"                      /* la_struct_too_deep_ellipsis */
 };
This page took 0.02788 seconds and 4 git commands to generate.