Skip to content

Commit a8de649

Browse files
authored
[NFC][LLDB][BoundsSatety] Add InstrumentationRuntime::MatchAllModules (llvm#166001)
This adds a virtual method that allows `InstrumentationRuntime` sub classes to match against all modules rather than just a library that matches a particular regex. When the implementation returns true `GetPatternForRuntimeLibrary()` is ignored and all modules are iterated over. The default implementation returns false which was the previous behavior which uses `GetPatternForRuntimeLibrary()` to only match a particular runtime library. The intended use case here is for implementing an `InstrumentationRuntime` where the runtime library of interest can have multiple implementations and whose name is not known ahead of time. The concrete use case here is for a `InstrumentationRuntime` plugin for implementations of the `-fbounds-safety` soft-trap runtime which can have multiple different implementations and so the module containing the runtime functions isn't known ahead of time. This plug-in will be upstreamed as part of the process of upstreaming `-fbounds-safety`. An alternative to this would be for the `GetPatternForRuntimeLibrary()` function to return a regex that matches everything. While that technically works this new API more clearly indicates in the intent. We probably also save a little perf by not executing the regex match for every loaded module but I have not measured this. rdar://163230807
1 parent 1d8d8dc commit a8de649

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lldb/include/lldb/Target/InstrumentationRuntime.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class InstrumentationRuntime
7373
/// is guaranteed to be loaded.
7474
virtual void Activate() = 0;
7575

76+
/// \return true if `CheckIfRuntimeIsValid` should be called on all modules.
77+
/// In this case the return value of `GetPatternForRuntimeLibrary` will be
78+
/// ignored. Return false if `CheckIfRuntimeIsValid` should only be called
79+
/// for modules whose name matches `GetPatternForRuntimeLibrary`.
80+
///
81+
virtual bool MatchAllModules() { return false; }
82+
7683
public:
7784
static void ModulesDidLoad(lldb_private::ModuleList &module_list,
7885
Process *process,

lldb/source/Target/InstrumentationRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void InstrumentationRuntime::ModulesDidLoad(
5555
return IterationAction::Continue;
5656

5757
const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary();
58-
if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) ||
58+
if (MatchAllModules() ||
59+
runtime_regex.Execute(file_spec.GetFilename().GetCString()) ||
5960
module_sp->IsExecutable()) {
6061
if (CheckIfRuntimeIsValid(module_sp)) {
6162
SetRuntimeModuleSP(module_sp);

0 commit comments

Comments
 (0)