Skip to content

Commit

Permalink
[lldb][NFCI] Change type of SBDebugger::m_instance_name
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bulbazord committed May 30, 2023
1 parent db7f639 commit f46638b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions lldb/source/API/SBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,16 +1326,19 @@ 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,
const char *debugger_instance_name) {
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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f46638b

Please sign in to comment.