================
@@ -5313,6 +5314,160 @@ void ParseFlags(
       });
 }
 
+static const RegisterTypeBuiltin *
+ResolveGDBBuiltinType(llvm::StringRef type_name) {
+  static const RegisterTypeBuiltin bool_type("bool", eEncodingUint,
+                                             eFormatBoolean, 1);
+  static const RegisterTypeBuiltin int8_type("int8", eEncodingSint,
+                                             eFormatDecimal, 1);
+  static const RegisterTypeBuiltin int16_type("int16", eEncodingSint,
+                                              eFormatDecimal, 2);
+  static const RegisterTypeBuiltin int32_type("int32", eEncodingSint,
+                                              eFormatDecimal, 4);
+  static const RegisterTypeBuiltin int64_type("int64", eEncodingSint,
+                                              eFormatDecimal, 8);
+  static const RegisterTypeBuiltin int128_type("int128", eEncodingSint,
+                                               eFormatDecimal, 16);
+  static const RegisterTypeBuiltin uint8_type("uint8", eEncodingUint,
+                                              eFormatHex, 1);
+  static const RegisterTypeBuiltin uint16_type("uint16", eEncodingUint,
+                                               eFormatHex, 2);
+  static const RegisterTypeBuiltin uint32_type("uint32", eEncodingUint,
+                                               eFormatHex, 4);
+  static const RegisterTypeBuiltin uint64_type("uint64", eEncodingUint,
+                                               eFormatHex, 8);
+  static const RegisterTypeBuiltin uint128_type("uint128", eEncodingUint,
+                                                eFormatHex, 16);
+  static const RegisterTypeBuiltin code_ptr_type("code_ptr", eEncodingUint,
+                                                 eFormatAddressInfo, 0);
+  static const RegisterTypeBuiltin data_ptr_type("data_ptr", eEncodingUint,
+                                                 eFormatAddressInfo, 0);
+  static const RegisterTypeBuiltin ieee_half_type("ieee_half", 
eEncodingIEEE754,
+                                                  eFormatFloat, 2);
+  static const RegisterTypeBuiltin ieee_single_type(
+      "ieee_single", eEncodingIEEE754, eFormatFloat, 4);
+  static const RegisterTypeBuiltin ieee_double_type(
+      "ieee_double", eEncodingIEEE754, eFormatFloat, 8);
+  static const RegisterTypeBuiltin i387_ext_type("i387_ext", eEncodingIEEE754,
+                                                 eFormatFloat, 10);
+  static const RegisterTypeBuiltin bfloat16_type("bfloat16", eEncodingIEEE754,
+                                                 eFormatFloat, 2);
+
+  return llvm::StringSwitch<const RegisterTypeBuiltin *>(type_name)
+      .Case("bool", &bool_type)
+      .Case("int8", &int8_type)
+      .Case("int16", &int16_type)
+      .Case("int32", &int32_type)
+      .Case("int64", &int64_type)
+      .Case("int128", &int128_type)
+      .Case("uint8", &uint8_type)
+      .Case("uint16", &uint16_type)
+      .Case("uint32", &uint32_type)
+      .Case("uint64", &uint64_type)
+      .Case("uint128", &uint128_type)
+      .Case("code_ptr", &code_ptr_type)
+      .Case("data_ptr", &data_ptr_type)
+      .Case("ieee_half", &ieee_half_type)
+      .Case("ieee_single", &ieee_single_type)
+      .Case("ieee_double", &ieee_double_type)
+      .Case("i387_ext", &i387_ext_type)
+      .Case("bfloat16", &bfloat16_type)
+      .Default(nullptr);
+}
+
+static const RegisterType *
+ResolveGDBType(llvm::StringRef type_name,
+               const RegisterTypeMap &feature_register_types) {
+  auto type_it = feature_register_types.find(type_name);
+  if (type_it != feature_register_types.end())
+    return type_it->second;
+  return ResolveGDBBuiltinType(type_name);
+}
+
+static void
+ParseVector(const XMLNode &vector_node, RegisterTypeMap 
&feature_register_types,
+            std::vector<std::unique_ptr<RegisterType>> &owned_register_types) {
+  Log *log(GetLog(GDBRLog::Process));
+  std::optional<llvm::StringRef> id;
+  std::optional<llvm::StringRef> element_type_name;
+  std::optional<uint32_t> count;
+
+  vector_node.ForEachAttribute(
+      [&id, &element_type_name, &count, log](llvm::StringRef name,
+                                             llvm::StringRef value) {
+        if (name == "id") {
+          id = value;
+        } else if (name == "type") {
+          element_type_name = value;
+        } else if (name == "count") {
+          uint32_t parsed_count = 0;
+          if (llvm::to_integer(value, parsed_count))
+            count = parsed_count;
+          else
+            LLDB_LOG(log, "ProcessGDBRemote::ParseVector Invalid count 
\"{0}\"",
+                     value);
+        } else {
+          LLDB_LOG(log,
+                   "ProcessGDBRemote::ParseVector Ignoring unknown attribute "
+                   "\"{0}\"",
+                   name);
+        }
+        return true;
+      });
+
+  constexpr uint32_t max_vector_count = 65536;
+  if (!id || id->empty() || !element_type_name || element_type_name->empty() ||
+      !count || *count == 0 || *count > max_vector_count) {
+    LLDB_LOG(log, "ProcessGDBRemote::ParseVector Ignoring vector with invalid "
+                  "id, type, or count");
+    return;
+  }
+
+  if (feature_register_types.contains(*id)) {
+    LLDB_LOG(log,
+             "ProcessGDBRemote::ParseVector Ignoring duplicate type \"{0}\"",
+             *id);
+    return;
+  }
+
+  const RegisterType *element_type =
+      ResolveGDBType(*element_type_name, feature_register_types);
+  if (!element_type || (!llvm::isa<RegisterTypeBuiltin>(element_type) &&
+                        !llvm::isa<RegisterTypeVector>(element_type))) {
----------------
DavidSpickett wrote:

I don't see why an element could not be an enum, but also I don't know of 
anyone actually doing that and I'm fine with keeping to what we know we need.

Though if you haven't already, that would be a good test case. That a vector of 
enum elements is rejected.

https://github.com/llvm/llvm-project/pull/217128
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to