-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Introduce Language::AreEquivalentFunctions #112720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Introduce Language::AreEquivalentFunctions #112720
Conversation
An example usage can be found here: swiftlang#9441 |
@llvm/pr-subscribers-lldb Author: Felipe de Azevedo Piovezan (felipepiovezan) ChangesThis allows languages to provide an opinion on whether two symbol contexts are equivalent (i.e. belong to the same function). It is useful to drive the comparisons done by stepping plans that need to ensure symbol contexts obtained from different points in time are actually the same. Full diff: https://github.com/llvm/llvm-project/pull/112720.diff 2 Files Affected:
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index 41d8eeef469eab..fb1828a4dfd8a9 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -363,6 +363,14 @@ class Language : public PluginInterface {
return false;
}
+ /// Returns a boolean indicating whether two symbol contexts correspond to
+ /// the same function. If the plugin has no opinion, it should return nullopt.
+ virtual std::optional<bool>
+ AreEquivalentFunctions(const SymbolContext &sc1,
+ const SymbolContext &sc2) const {
+ return {};
+ }
+
/// Returns true if this Language supports exception breakpoints on throw via
/// a corresponding LanguageRuntime plugin.
virtual bool SupportsExceptionBreakpointsOnThrow() const { return false; }
diff --git a/lldb/source/Target/ThreadPlanStepOverRange.cpp b/lldb/source/Target/ThreadPlanStepOverRange.cpp
index 934f23b3b21a28..3f2826cb886f2d 100644
--- a/lldb/source/Target/ThreadPlanStepOverRange.cpp
+++ b/lldb/source/Target/ThreadPlanStepOverRange.cpp
@@ -11,6 +11,7 @@
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/LineTable.h"
+#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/Target.h"
@@ -103,6 +104,10 @@ void ThreadPlanStepOverRange::SetupAvoidNoDebug(
bool ThreadPlanStepOverRange::IsEquivalentContext(
const SymbolContext &context) {
+ if (Language *language = Language::FindPlugin(context.GetLanguage()))
+ if (std::optional<bool> maybe_equivalent =
+ language->AreEquivalentFunctions(context, m_addr_context))
+ return *maybe_equivalent;
// Match as much as is specified in the m_addr_context: This is a fairly
// loose sanity check. Note, sometimes the target doesn't get filled in so I
// left out the target check. And sometimes the module comes in as the .o
|
do we have in mind any other languages that will implement this? |
lldb/include/lldb/Target/Language.h
Outdated
/// Returns a boolean indicating whether two symbol contexts correspond to | ||
/// the same function. If the plugin has no opinion, it should return nullopt. | ||
virtual std::optional<bool> | ||
AreEquivalentFunctions(const SymbolContext &sc1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equivalent functions sounds quite vague to my mind. Given that this function operates on symbol contexts, and is called from IsEquivalentContext
, I think this would be better off named AreEquivalentContexts
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I agree. I'll just wait to see if others chime in and then update the patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to somehow indicate the comparison w.r.t. which these functions/contexts are equivalent. "Equivalent" makes it sound like maybe I could use one in place of the other generally (like maybe I can call either one of them???) AreEqualForFrameComparison
is a little verbose, but tells you what statement we are actually making.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that name looks a lot more expressive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed it
I suspect any language wanting to implement this notion of function splitting (e.g. all the users of corosplitter) and virtual frames could have a use for this |
We already have |
This allows languages to provide an opinion on whether two symbol contexts are equivalent (i.e. belong to the same function). It is useful to drive the comparisons done by stepping plans that need to ensure symbol contexts obtained from different points in time are actually the same.
1f9bcfc
to
231afe2
Compare
There are two things that confuse me about this idea:
|
I was speaking loosely, meaning "in the llvm.org not the swift fork of llvm-project (and thus testable there). We'd have to decide which runtime this would go in, maybe we need an "assembly language" or a general fallback runtime for this?
I don't remember whether they push a frame or tail call. |
I looked at the code that creates Maybe some C++-specific construct that could go through the C++ language plugin? I tried their coroutines, but the IR generated wasn't very promising either and TTTT I'm not familiar with how they are compiled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit sad we can't come up with a scenario that uses this for the languages in the llvm.org repo. But the idea is clear the code really simple, and it obviously belongs in the Language, so LGTM.
This allows languages to provide an opinion on whether two symbol contexts are equivalent (i.e. belong to the same function). It is useful to drive the comparisons done by stepping plans that need to ensure symbol contexts obtained from different points in time are actually the same. (cherry picked from commit cd938bf)
…age_api [cherry-pick][lldb] Introduce Language::AreEquivalentFunctions (llvm#112720)
This allows languages to provide an opinion on whether two symbol contexts are equivalent (i.e. belong to the same function).
It is useful to drive the comparisons done by stepping plans that need to ensure symbol contexts obtained from different points in time are actually the same.