diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -116,7 +116,7 @@ static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id); static lldb::DebuggerSP - FindDebuggerWithInstanceName(ConstString instance_name); + FindDebuggerWithInstanceName(llvm::StringRef instance_name); static size_t GetNumDebuggers(); @@ -359,7 +359,7 @@ bool GetNotifyVoid() const; - ConstString GetInstanceName() { return m_instance_name; } + const std::string &GetInstanceName() { return m_instance_name; } bool LoadPlugin(const FileSpec &spec, Status &error); @@ -644,7 +644,7 @@ llvm::StringMap> m_stream_handlers; std::shared_ptr m_callback_handler_sp; - ConstString m_instance_name; + const std::string m_instance_name; static LoadPluginCallbackType g_load_plugin_callback; typedef std::vector LoadedPluginsList; LoadedPluginsList m_loaded_plugins; diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -1326,7 +1326,10 @@ const char *SBDebugger::GetInstanceName() { LLDB_INSTRUMENT_VA(this); - return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr); + if (!m_opaque_sp) + return nullptr; + + return ConstString(m_opaque_sp->GetInstanceName()).AsCString(); } SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value, @@ -1334,8 +1337,8 @@ LLDB_INSTRUMENT_VA(var_name, value, debugger_instance_name); SBError sb_error; - DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( - ConstString(debugger_instance_name))); + DebuggerSP debugger_sp( + Debugger::FindDebuggerWithInstanceName(debugger_instance_name)); Status error; if (debugger_sp) { ExecutionContext exe_ctx( @@ -1356,8 +1359,8 @@ const char *debugger_instance_name) { LLDB_INSTRUMENT_VA(var_name, debugger_instance_name); - DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( - ConstString(debugger_instance_name))); + DebuggerSP debugger_sp( + Debugger::FindDebuggerWithInstanceName(debugger_instance_name)); Status error; if (debugger_sp) { ExecutionContext exe_ctx( @@ -1487,7 +1490,7 @@ Stream &strm = description.ref(); if (m_opaque_sp) { - const char *name = m_opaque_sp->GetInstanceName().AsCString(); + const char *name = m_opaque_sp->GetInstanceName().c_str(); user_id_t id = m_opaque_sp->GetID(); strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id); } else diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -740,19 +740,20 @@ } } -DebuggerSP Debugger::FindDebuggerWithInstanceName(ConstString instance_name) { - DebuggerSP debugger_sp; - if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) { - std::lock_guard guard(*g_debugger_list_mutex_ptr); - DebuggerList::iterator pos, end = g_debugger_list_ptr->end(); - for (pos = g_debugger_list_ptr->begin(); pos != end; ++pos) { - if ((*pos)->m_instance_name == instance_name) { - debugger_sp = *pos; - break; - } - } +DebuggerSP +Debugger::FindDebuggerWithInstanceName(llvm::StringRef instance_name) { + if (!g_debugger_list_ptr || !g_debugger_list_mutex_ptr) + return DebuggerSP(); + + std::lock_guard guard(*g_debugger_list_mutex_ptr); + for (const DebuggerSP &debugger_sp : *g_debugger_list_ptr) { + if (!debugger_sp) + continue; + + if (llvm::StringRef(debugger_sp->GetInstanceName()) == instance_name) + return debugger_sp; } - return debugger_sp; + return DebuggerSP(); } TargetSP Debugger::FindTargetWithProcessID(lldb::pid_t pid) { @@ -801,13 +802,13 @@ m_source_manager_up(), m_source_file_cache(), m_command_interpreter_up( std::make_unique(*this, false)), - m_io_handler_stack(), m_instance_name(), m_loaded_plugins(), - m_event_handler_thread(), m_io_handler_thread(), + m_io_handler_stack(), + m_instance_name(llvm::formatv("debugger_{0}", GetID()).str()), + m_loaded_plugins(), m_event_handler_thread(), m_io_handler_thread(), m_sync_broadcaster(nullptr, "lldb.debugger.sync"), m_broadcaster(m_broadcaster_manager_sp, GetStaticBroadcasterClass().AsCString()), m_forward_listener_sp(), m_clear_once() { - m_instance_name.SetString(llvm::formatv("debugger_{0}", GetID()).str()); // Initialize the debugger properties as early as possible as other parts of // LLDB will start querying them during construction. m_collection_sp->Initialize(g_debugger_properties); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -408,7 +408,7 @@ m_session_dict(PyInitialValue::Invalid), m_sys_module_dict(PyInitialValue::Invalid), m_run_one_line_function(), m_run_one_line_str_global(), - m_dictionary_name(m_debugger.GetInstanceName().AsCString()), + m_dictionary_name(m_debugger.GetInstanceName()), m_active_io_handler(eIOHandlerNone), m_session_is_active(false), m_pty_secondary_is_open(false), m_valid_session(true), m_lock_count(0), m_command_thread_state(nullptr) {