================
@@ -5043,8 +5046,20 @@ static void ParseEnums(
             LLDB_LOG(log,
                      "ProcessGDBRemote::ParseEnums Found enum type \"{0}\"",
                      id);
-            registers_enum_types.insert_or_assign(
-                id, std::make_unique<RegisterTypeEnum>(id, enumerators));
+            auto enum_type =
+                std::make_unique<RegisterTypeEnum>(id, enumerators);
+            const RegisterTypeEnum *enum_type_ptr = enum_type.get();
+            auto [it, inserted] = register_types.try_emplace(id, 
enum_type_ptr);
+            if (inserted || llvm::isa<RegisterTypeEnum>(it->second)) {
----------------
DavidSpickett wrote:

> if (inserted

This I understand. If inserted is true then it is new and we want to own the 
type.

> || llvm::isa<RegisterTypeEnum>(it->second)) {

This I'm not sure about. If we inserted, then it will be an enum because that's 
what we inserted. If we didn't insert then it could be an enum but it might not 
be the same as the one enum_type points to.

So it seems that you could make enum_type for an enum with ID A and contents X, 
then look it up and find there was another enum with ID A and contents Y.

> it->second = enum_type_ptr;

Whose pointer then gets replaced by this one in one of the maps.

This logic needs comments to explain what it's doing, it's too hard to audit 
like this.

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

Reply via email to