[Lldb-commits] [lldb] [lldb] Clear ModuleList shared modules in SBDebugger::Clear (PR #147289)

Andrew Savonichev via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 7 15:03:26 PDT 2025


asavonic wrote:

> > However, when lldb is used as a library, we need a way to manage opened modules to avoid problems with file locks (on some systems) for modules that we no longer need.
> 
> Can you give a concrete example? This seems like its own issue that should be solved rather than worked around. I wouldn't expect us to need to keep files open for as long as a module exists.

Right, it is a separate issue. I'll follow up later.

> 
> > It should be possible to record all loaded modules and use `ModuleList::RemoveSharedModule` and `RemoveOrphanSharedModules` functions to clear the cache, but these functions are not available in the API. This approach is also way too complicated when we just need to cleanup the library.
> 
> This is exposed from the SB API through `SBDebugger::MemoryPressureDetected`. Not sure what's "complicated" about calling his function, but I do agree that this shouldn't necessary be an explicit operation and would make a good default. The natural place to do this is in `SBDebugger::Destroy`. You can have many debuggers and it seems like a bad idea to clear the modules when you clear one of them.

How should a proper debugger shutdown sequence look like?

1. Release all `SBModule` pointers.
2. Call `SBDebugger::MemoryPressureDetected`.
3. Call `SBDebugger::Destroy`.

`SBDebugger::MemoryPressureDetected` only removes shared pointers to modules with `use_count == 1`. Assuming that the calling program releases all its modules in (1), we need to make sure that the debugger does not keep any pointers elsewhere before (2). Can we rely on this?

If any module survives `MemoryPressureDetected`, they will not be released by `SBDebugger::Destroy`.

https://github.com/llvm/llvm-project/pull/147289


More information about the lldb-commits mailing list