Skip to content

Conversation

@delcypher
Copy link
Contributor

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

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
@delcypher delcypher requested a review from jimingham November 1, 2025 16:05
@delcypher delcypher self-assigned this Nov 1, 2025
@delcypher delcypher added the clang:bounds-safety Issue/PR relating to the experimental -fbounds-safety feature in Clang label Nov 1, 2025
@llvmbot llvmbot added the lldb label Nov 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 1, 2025

@llvm/pr-subscribers-lldb

Author: Dan Liew (delcypher)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/166001.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Target/InstrumentationRuntime.h (+7)
  • (modified) lldb/source/Target/InstrumentationRuntime.cpp (+2-1)
diff --git a/lldb/include/lldb/Target/InstrumentationRuntime.h b/lldb/include/lldb/Target/InstrumentationRuntime.h
index a6121c24b9560..d2499528e97ab 100644
--- a/lldb/include/lldb/Target/InstrumentationRuntime.h
+++ b/lldb/include/lldb/Target/InstrumentationRuntime.h
@@ -73,6 +73,13 @@ class InstrumentationRuntime
   /// is guaranteed to be loaded.
   virtual void Activate() = 0;
 
+  /// \return true if `CheckIfRuntimeIsValid` should be called on all modules.
+  /// In this case the return value of `GetPatternForRuntimeLibrary` will be
+  /// ignored. Return false if `CheckIfRuntimeIsValid` should only be called
+  /// for modules whose name matches `GetPatternForRuntimeLibrary`.
+  ///
+  virtual bool MatchAllModules() { return false; }
+
 public:
   static void ModulesDidLoad(lldb_private::ModuleList &module_list,
                              Process *process,
diff --git a/lldb/source/Target/InstrumentationRuntime.cpp b/lldb/source/Target/InstrumentationRuntime.cpp
index 7e58e8bf26cb1..d9800a8541f4e 100644
--- a/lldb/source/Target/InstrumentationRuntime.cpp
+++ b/lldb/source/Target/InstrumentationRuntime.cpp
@@ -55,7 +55,8 @@ void InstrumentationRuntime::ModulesDidLoad(
       return IterationAction::Continue;
 
     const RegularExpression &runtime_regex = GetPatternForRuntimeLibrary();
-    if (runtime_regex.Execute(file_spec.GetFilename().GetCString()) ||
+    if (MatchAllModules() ||
+        runtime_regex.Execute(file_spec.GetFilename().GetCString()) ||
         module_sp->IsExecutable()) {
       if (CheckIfRuntimeIsValid(module_sp)) {
         SetRuntimeModuleSP(module_sp);

Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too.

@delcypher delcypher merged commit a8de649 into llvm:main Nov 3, 2025
13 checks passed
@delcypher
Copy link
Contributor Author

Thanks for the reviews.

delcypher added a commit to delcypher/apple-llvm-project that referenced this pull request Nov 3, 2025
…s` (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
(cherry picked from commit a8de649)
delcypher added a commit to swiftlang/llvm-project that referenced this pull request Nov 4, 2025
…s` (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
(cherry picked from commit a8de649)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue/PR relating to the experimental -fbounds-safety feature in Clang lldb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants