[Lldb-commits] [lldb] f46638b - [lldb][NFCI] Change type of SBDebugger::m_instance_name
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Tue May 30 13:22:06 PDT 2023
Author: Alex Langford
Date: 2023-05-30T13:21:56-07:00
New Revision: f46638b01d1bd66aa879188132e0d19a0a7f5928
URL: https://github.com/llvm/llvm-project/commit/f46638b01d1bd66aa879188132e0d19a0a7f5928
DIFF: https://github.com/llvm/llvm-project/commit/f46638b01d1bd66aa879188132e0d19a0a7f5928.diff
LOG: [lldb][NFCI] Change type of SBDebugger::m_instance_name
This doesn't need to be in the ConstString StringPool. There's little
benefit to having these be unique, and we don't need fast comparisons on
them.
Differential Revision: https://reviews.llvm.org/D151524
Added:
Modified:
lldb/include/lldb/Core/Debugger.h
lldb/source/API/SBDebugger.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index 54f7d5c0edb4a..b63597fc71b4c 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -116,7 +116,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
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 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
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 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
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;
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 9e9b01f830b59..9641e2f9c8a08 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -1326,7 +1326,10 @@ SBDebugger SBDebugger::FindDebuggerWithID(int id) {
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 @@ 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(
@@ -1356,8 +1359,8 @@ SBDebugger::GetInternalVariableValue(const char *var_name,
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 @@ bool SBDebugger::GetDescription(SBStream &description) {
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
index 1d92f2f52c2f7..ad177637f45b4 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -740,19 +740,20 @@ void Debugger::Destroy(DebuggerSP &debugger_sp) {
}
}
-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) {
@@ -801,13 +802,13 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
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);
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index ebc5990850942..902c7fad1105f 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -408,7 +408,7 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
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) {
More information about the lldb-commits
mailing list