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();
bool GetNotifyVoid() const;
- ConstString GetInstanceName() { return m_instance_name; }
+ const std::string &GetInstanceName() { return m_instance_name; }
bool LoadPlugin(const FileSpec &spec, Status &error);
llvm::StringMap<std::weak_ptr<LogHandler>> m_stream_handlers;
std::shared_ptr<CallbackLogHandler> m_callback_handler_sp;
- ConstString m_instance_name;
+ const std::string m_instance_name;
static LoadPluginCallbackType g_load_plugin_callback;
typedef std::vector<llvm::sys::DynamicLibrary> LoadedPluginsList;
LoadedPluginsList m_loaded_plugins;
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,
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(
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(
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
}
}
-DebuggerSP Debugger::FindDebuggerWithInstanceName(ConstString instance_name) {
- DebuggerSP debugger_sp;
- if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
- std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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) {
m_source_manager_up(), m_source_file_cache(),
m_command_interpreter_up(
std::make_unique<CommandInterpreter>(*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);
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) {