Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class LLDB_API SBDebugger {

bool SetShowInlineDiagnostics(bool);

bool SetClearSharedModules(bool);

bool SetUseSourceCache(bool use_source_cache);

bool GetUseSourceCache() const;
Expand Down
4 changes: 4 additions & 0 deletions lldb/include/lldb/Core/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ class Debugger : public std::enable_shared_from_this<Debugger>,

bool SetShowInlineDiagnostics(bool);

bool GetClearSharedModules() const;

bool SetClearSharedModules(bool);

bool LoadPlugin(const FileSpec &spec, Status &error);

void RunIOHandlers();
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/Core/ModuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ class ModuleList {

static bool RemoveSharedModuleIfOrphaned(const Module *module_ptr);

/// Empty global cache of modules to release memory, file locks, etc.
static void ClearSharedModules();

/// Applies 'callback' to each module in this ModuleList.
/// If 'callback' returns false, iteration terminates.
/// The 'module_sp' passed to 'callback' is guaranteed to
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/API/SBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,12 @@ bool SBDebugger::SetShowInlineDiagnostics(bool value) {
return (m_opaque_sp ? m_opaque_sp->SetShowInlineDiagnostics(value) : false);
}

bool SBDebugger::SetClearSharedModules(bool value) {
LLDB_INSTRUMENT_VA(this, value);

return (m_opaque_sp ? m_opaque_sp->SetClearSharedModules(value) : false);
}

bool SBDebugger::SetUseSourceCache(bool value) {
LLDB_INSTRUMENT_VA(this, value);

Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Core/CoreProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ let Definition = "debugger" in {
Global,
DefaultFalse,
Desc<"Controls whether diagnostics can refer directly to the command input, drawing arrows to it. If false, diagnostics will echo the input.">;
def ClearSharedModules: Property<"clear-shared-modules", "Boolean">,
Global,
DefaultFalse,
Desc<"Controls whether the debugger clears internal shared modules as it exits.">;
}
15 changes: 15 additions & 0 deletions lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,17 @@ bool Debugger::SetShowInlineDiagnostics(bool b) {
return SetPropertyAtIndex(idx, b);
}

bool Debugger::GetClearSharedModules() const {
const uint32_t idx = ePropertyClearSharedModules;
return GetPropertyAtIndexAs<bool>(
idx, g_debugger_properties[idx].default_uint_value);
}

bool Debugger::SetClearSharedModules(bool b) {
const uint32_t idx = ePropertyClearSharedModules;
return SetPropertyAtIndex(idx, b);
}

#pragma mark Debugger

// const DebuggerPropertiesSP &
Expand Down Expand Up @@ -1099,6 +1110,10 @@ void Debugger::Clear() {
target_sp->Destroy();
}
}

if (GetClearSharedModules())
ModuleList::RemoveOrphanSharedModules(/*mandatory=*/true);

m_broadcaster_manager_sp->Clear();

// Close the input file _before_ we close the input read communications
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/Core/ModuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,13 @@ lldb::ModuleSP ModuleList::FindSharedModule(const UUID &uuid) {
}

size_t ModuleList::RemoveOrphanSharedModules(bool mandatory) {
return GetSharedModuleList().RemoveOrphans(mandatory);
size_t removed = GetSharedModuleList().RemoveOrphans(mandatory);
Log *log = GetLog(LLDBLog::Modules);
if (log != nullptr) {
LLDB_LOGF(log, "removed %lu shared modules, %lu modules remain", removed,
GetSharedModuleList().GetSize());
}
return removed;
}

Status
Expand Down
36 changes: 36 additions & 0 deletions lldb/test/API/python_api/debugger/TestDebuggerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,39 @@ def test_version(self):

self.assertEqual(instance_str, class_str)
self.assertEqual(class_str, property_str)

def test_default_SetClearSharedModules(self):
"""Check that that SBDebugger does not clear shared modules by
default.
"""
messages = list()
self.dbg.SetLoggingCallback(messages.append)
self.runCmd("log enable lldb module")
self.dbg.Destroy(self.dbg)
self.assertFalse(
any("removed 0 shared modules, 0 modules remain" in msg for msg in messages)
)

def test_enable_SetClearSharedModules(self):
"""Check that SetClearSharedModule(true) clears shared module cache."""
messages = list()
self.dbg.SetLoggingCallback(messages.append)
self.dbg.SetClearSharedModules(True)
self.runCmd("log enable lldb module")
self.dbg.Destroy(self.dbg)
self.assertTrue(
any("removed 0 shared modules, 0 modules remain" in msg for msg in messages)
)

def test_enable_clear_shared_modules(self):
"""Check that clear-shared-module setting is equivalent
to SetClearSharedModules(true).
"""
messages = list()
self.dbg.SetLoggingCallback(messages.append)
self.runCmd("settings set clear-shared-modules true")
self.runCmd("log enable lldb module")
self.dbg.Destroy(self.dbg)
self.assertTrue(
any("removed 0 shared modules, 0 modules remain" in msg for msg in messages)
)
Loading