[Lldb-commits] [lldb] [lldb] Introduce Language::AreEquivalentFunctions (PR #112720)

Felipe de Azevedo Piovezan via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 17 07:41:01 PDT 2024


https://github.com/felipepiovezan created https://github.com/llvm/llvm-project/pull/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.

>From 1f9bcfcb01aa23519ba2fff103ccff1d2e53cdd5 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Thu, 17 Oct 2024 06:00:31 -0700
Subject: [PATCH] [lldb] Introduce Language::AreEquivalentFunctions

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.
---
 lldb/include/lldb/Target/Language.h            | 8 ++++++++
 lldb/source/Target/ThreadPlanStepOverRange.cpp | 5 +++++
 2 files changed, 13 insertions(+)

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



More information about the lldb-commits mailing list