diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2561,7 +2561,7 @@ /// The plugin if one is available for the specified feature; /// otherwise, returns an empty shared pointer. lldb::StructuredDataPluginSP - GetStructuredDataPlugin(ConstString type_name) const; + GetStructuredDataPlugin(llvm::StringRef type_name) const; virtual void *GetImplementation() { return nullptr; } @@ -2908,9 +2908,6 @@ } }; - using StructuredDataPluginMap = - std::map; - // Member variables std::weak_ptr m_target_wp; ///< The target that owns this process. lldb::pid_t m_pid = LLDB_INVALID_PROCESS_ID; @@ -3033,7 +3030,7 @@ // don't support the ability to modify // the stack. std::mutex m_run_thread_plan_lock; - StructuredDataPluginMap m_structured_data_plugin_map; + llvm::StringMap m_structured_data_plugin_map; enum { eCanJITDontKnow = 0, eCanJITYes, eCanJITNo } m_can_jit; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -4301,7 +4301,7 @@ } StructuredDataPluginSP -Process::GetStructuredDataPlugin(ConstString type_name) const { +Process::GetStructuredDataPlugin(llvm::StringRef type_name) const { auto find_it = m_structured_data_plugin_map.find(type_name); if (find_it != m_structured_data_plugin_map.end()) return find_it->second; @@ -5782,7 +5782,7 @@ LoadOperatingSystemPlugin(false); // Inform the structured-data plugins of the modified modules. - for (auto pair : m_structured_data_plugin_map) { + for (auto &pair : m_structured_data_plugin_map) { if (pair.second) pair.second->ModulesDidLoad(*this, module_list); } @@ -5977,34 +5977,29 @@ // Bail out early if there are no type names to map. if (supported_type_names.GetSize() == 0) { - LLDB_LOGF(log, "Process::%s(): no structured data types supported", - __FUNCTION__); + LLDB_LOG(log, "no structured data types supported"); return; } - // Convert StructuredData type names to ConstString instances. - std::set const_type_names; + // These StringRefs are backed by the input parameter. + std::set type_names; - LLDB_LOGF(log, - "Process::%s(): the process supports the following async " - "structured data types:", - __FUNCTION__); + LLDB_LOG(log, + "the process supports the following async structured data types:"); supported_type_names.ForEach( - [&const_type_names, &log](StructuredData::Object *object) { - if (!object) { - // Invalid - shouldn't be null objects in the array. + [&type_names, &log](StructuredData::Object *object) { + // There shouldn't be null objects in the array. + if (!object) return false; - } - auto type_name = object->GetAsString(); - if (!type_name) { - // Invalid format - all type names should be strings. + // All type names should be strings. + const llvm::StringRef type_name = object->GetStringValue(); + if (type_name.empty()) return false; - } - const_type_names.insert(ConstString(type_name->GetValue())); - LLDB_LOG(log, "- {0}", type_name->GetValue()); + type_names.insert(type_name); + LLDB_LOG(log, "- {0}", type_name); return true; }); @@ -6013,10 +6008,10 @@ // we've consumed all the type names. // FIXME: should we return an error if there are type names nobody // supports? - for (uint32_t plugin_index = 0; !const_type_names.empty(); plugin_index++) { + for (uint32_t plugin_index = 0; !type_names.empty(); plugin_index++) { auto create_instance = - PluginManager::GetStructuredDataPluginCreateCallbackAtIndex( - plugin_index); + PluginManager::GetStructuredDataPluginCreateCallbackAtIndex( + plugin_index); if (!create_instance) break; @@ -6029,9 +6024,9 @@ } // For any of the remaining type names, map any that this plugin supports. - std::vector names_to_remove; - for (auto &type_name : const_type_names) { - if (plugin_sp->SupportsStructuredDataType(type_name)) { + std::vector names_to_remove; + for (llvm::StringRef type_name : type_names) { + if (plugin_sp->SupportsStructuredDataType(ConstString(type_name))) { m_structured_data_plugin_map.insert( std::make_pair(type_name, plugin_sp)); names_to_remove.push_back(type_name); @@ -6041,8 +6036,8 @@ } // Remove the type names that were consumed by this plugin. - for (auto &type_name : names_to_remove) - const_type_names.erase(type_name); + for (llvm::StringRef type_name : names_to_remove) + type_names.erase(type_name); } } @@ -6059,7 +6054,7 @@ return false; // Grab the async structured type name (i.e. the feature/plugin name). - ConstString type_name; + llvm::StringRef type_name; if (!dictionary->GetValueForKeyAsString("type", type_name)) return false; @@ -6071,7 +6066,8 @@ } // Route the structured data to the plugin. - find_it->second->HandleArrivalOfStructuredData(*this, type_name, object_sp); + find_it->second->HandleArrivalOfStructuredData(*this, ConstString(type_name), + object_sp); return true; }