https://github.com/UltimateForce21 updated 
https://github.com/llvm/llvm-project/pull/144238

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 <abdullahmohammad...@gmail.com>
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/7] [lldb] Add DWARFExpressionEntry and
 GetExpressionEntryAtAddress() to DWARFExpressionList

This introduces a new API for retrieving DWARF expression metadata associated 
with variable location entries at a given PC address. It provides the base, 
end, and expression pointer for downstream consumers such as disassembler 
annotations.

Intended for use in richer instruction annotations in Instruction::Dump().
---
 .../lldb/Expression/DWARFExpressionList.h     | 12 +++++++++++
 .../source/Expression/DWARFExpressionList.cpp | 21 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index d8f8ec247ed56..a329b37393018 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -59,6 +59,18 @@ class DWARFExpressionList {
 
   lldb::addr_t GetFuncFileAddress() { return m_func_file_addr; }
 
+  /// Represents an entry in the DWARFExpressionList with all needed metadata
+  struct DWARFExpressionEntry {
+    lldb::addr_t base;
+    lldb::addr_t end;
+    const DWARFExpression *expr;
+  };
+
+  /// Returns the entry (base, end, data) for a given PC address
+  llvm::Expected<DWARFExpressionEntry>
+  GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
+                              lldb::addr_t load_addr) const;
+
   const DWARFExpression *GetExpressionAtAddress(lldb::addr_t func_load_addr,
                                                 lldb::addr_t load_addr) const;
 
diff --git a/lldb/source/Expression/DWARFExpressionList.cpp 
b/lldb/source/Expression/DWARFExpressionList.cpp
index 04592a1eb7ff4..b55bc7120c4af 100644
--- a/lldb/source/Expression/DWARFExpressionList.cpp
+++ b/lldb/source/Expression/DWARFExpressionList.cpp
@@ -53,6 +53,27 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
   return GetExpressionAtAddress(func_load_addr, addr) != nullptr;
 }
 
+llvm::Expected<DWARFExpressionList::DWARFExpressionEntry>
+DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
+                                                 lldb::addr_t load_addr) const 
{
+  if (const DWARFExpression *expr = GetAlwaysValidExpr()) {
+    return DWARFExpressionEntry{0, LLDB_INVALID_ADDRESS, expr};
+  }
+
+  if (func_load_addr == LLDB_INVALID_ADDRESS)
+    func_load_addr = m_func_file_addr;
+
+  addr_t addr = load_addr - func_load_addr + m_func_file_addr;
+  uint32_t index = m_exprs.FindEntryIndexThatContains(addr);
+  if (index == UINT32_MAX) {
+    return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                   "No DWARF expression found for address 
0x%llx", addr);
+  }
+
+  const Entry &entry = *m_exprs.GetEntryAtIndex(index);
+  return DWARFExpressionEntry{entry.base, entry.GetRangeEnd(), &entry.data};
+}
+
 const DWARFExpression *
 DWARFExpressionList::GetExpressionAtAddress(lldb::addr_t func_load_addr,
                                             lldb::addr_t load_addr) const {

>From 1db5002a69dba4f88aaac56d61520b7b4b214b01 Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Thu, 19 Jun 2025 11:55:35 -0400
Subject: [PATCH 2/7] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere <jo...@devlieghere.com>
---
 lldb/include/lldb/Expression/DWARFExpressionList.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index a329b37393018..89e55ffc07659 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -59,7 +59,7 @@ class DWARFExpressionList {
 
   lldb::addr_t GetFuncFileAddress() { return m_func_file_addr; }
 
-  /// Represents an entry in the DWARFExpressionList with all needed metadata
+  /// Represents an entry in the DWARFExpressionList with all needed metadata.
   struct DWARFExpressionEntry {
     lldb::addr_t base;
     lldb::addr_t end;

>From a26010b06e5067b8b3b223cbd76e8848ecb9a289 Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Thu, 19 Jun 2025 11:58:28 -0400
Subject: [PATCH 3/7] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Updated comment for GetExpressionEntryAtAddress to directly refer to struct 
DWARFExpressionEntry

Co-authored-by: Jonas Devlieghere <jo...@devlieghere.com>
---
 lldb/include/lldb/Expression/DWARFExpressionList.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index 89e55ffc07659..f6a269809decc 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -66,7 +66,7 @@ class DWARFExpressionList {
     const DWARFExpression *expr;
   };
 
-  /// Returns the entry (base, end, data) for a given PC address
+  /// Returns the DWARFExpressionEntry for a given PC address.
   llvm::Expected<DWARFExpressionEntry>
   GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
                               lldb::addr_t load_addr) const;

>From 72237b75a12daa94f887f7492b2dfc141519b8a8 Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Thu, 19 Jun 2025 11:59:35 -0400
Subject: [PATCH 4/7] Update lldb/source/Expression/DWARFExpressionList.cpp

updating code style for function GetExpressionEntryAtAddress

Co-authored-by: Jonas Devlieghere <jo...@devlieghere.com>
---
 lldb/source/Expression/DWARFExpressionList.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Expression/DWARFExpressionList.cpp 
b/lldb/source/Expression/DWARFExpressionList.cpp
index b55bc7120c4af..ebf57dd457769 100644
--- a/lldb/source/Expression/DWARFExpressionList.cpp
+++ b/lldb/source/Expression/DWARFExpressionList.cpp
@@ -56,9 +56,8 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
 llvm::Expected<DWARFExpressionList::DWARFExpressionEntry>
 DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
                                                  lldb::addr_t load_addr) const 
{
-  if (const DWARFExpression *expr = GetAlwaysValidExpr()) {
+  if (const DWARFExpression *expr = GetAlwaysValidExpr())
     return DWARFExpressionEntry{0, LLDB_INVALID_ADDRESS, expr};
-  }
 
   if (func_load_addr == LLDB_INVALID_ADDRESS)
     func_load_addr = m_func_file_addr;

>From 94e4951ac8eb39f078b783c2d3a7006c395ae4b2 Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Tue, 24 Jun 2025 16:28:14 -0400
Subject: [PATCH 5/7] Update DWARFExpressionList.h

Replace raw base/end with `AddressRange` in `DWARFExpressionEntry` and cleans 
up helper comments to follow Doxygen convention.

Using `AddressRange` makes the intent clearer, avoids duplication of basic 
`AddressRange` logic usage
---
 lldb/include/lldb/Expression/DWARFExpressionList.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index f6a269809decc..4af6f99b9c23a 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -9,6 +9,7 @@
 #ifndef LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
 #define LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
 
+#include "lldb/Core/AddressRange.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Expression/DWARFExpression.h"
 #include "lldb/Utility/RangeMap.h"
@@ -58,15 +59,16 @@ class DWARFExpressionList {
   }
 
   lldb::addr_t GetFuncFileAddress() { return m_func_file_addr; }
-
+  
   /// Represents an entry in the DWARFExpressionList with all needed metadata.
   struct DWARFExpressionEntry {
-    lldb::addr_t base;
-    lldb::addr_t end;
+    AddressRange file_range; /// Represents a DWARF location range in the 
DWARF unit’s file‐address space
     const DWARFExpression *expr;
   };
 
-  /// Returns the DWARFExpressionEntry for a given PC address.
+  /// Returns a DWARFExpressionEntry whose file_range contains the given
+  /// load‐address.  `func_load_addr` is the load‐address of the function
+  /// start; `load_addr` is the full runtime PC.  On success, `expr` is 
non-null.
   llvm::Expected<DWARFExpressionEntry>
   GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
                               lldb::addr_t load_addr) const;

>From e8142dab5a1c90f05deb659a57059313c055b99d Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Tue, 24 Jun 2025 16:36:41 -0400
Subject: [PATCH 6/7] Update DWARFExpressionList.cpp

Converts `GetExpressionEntryAtAddress` to return 
`llvm::Expected<DWARFExpressionEntry>` using the updated 
`DWARFExpressionEntry`. Updates the implementation to compute a single 
`AddressRange file_range` for each DWARF location interval.
---
 .../source/Expression/DWARFExpressionList.cpp | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lldb/source/Expression/DWARFExpressionList.cpp 
b/lldb/source/Expression/DWARFExpressionList.cpp
index ebf57dd457769..8b8378eb895d3 100644
--- a/lldb/source/Expression/DWARFExpressionList.cpp
+++ b/lldb/source/Expression/DWARFExpressionList.cpp
@@ -6,6 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
+#include "lldb/Core/AddressRange.h"
 #include "lldb/Expression/DWARFExpressionList.h"
 #include "lldb/Symbol/Function.h"
 #include "lldb/Target/RegisterContext.h"
@@ -55,22 +56,25 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
 
 llvm::Expected<DWARFExpressionList::DWARFExpressionEntry>
 DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
-                                                 lldb::addr_t load_addr) const 
{
-  if (const DWARFExpression *expr = GetAlwaysValidExpr())
-    return DWARFExpressionEntry{0, LLDB_INVALID_ADDRESS, expr};
+                                                lldb::addr_t load_addr) const {
+  if (const DWARFExpression *always = GetAlwaysValidExpr()) {
+    AddressRange full_range(m_func_file_addr, /*size=*/LLDB_INVALID_ADDRESS);
+    return DWARFExpressionEntry{full_range, always};
+  }
 
   if (func_load_addr == LLDB_INVALID_ADDRESS)
     func_load_addr = m_func_file_addr;
+  lldb::addr_t file_pc = load_addr - func_load_addr + m_func_file_addr;
 
-  addr_t addr = load_addr - func_load_addr + m_func_file_addr;
-  uint32_t index = m_exprs.FindEntryIndexThatContains(addr);
-  if (index == UINT32_MAX) {
-    return llvm::createStringError(llvm::inconvertibleErrorCode(),
-                                   "No DWARF expression found for address 
0x%llx", addr);
-  }
+  uint32_t idx = m_exprs.FindEntryIndexThatContains(file_pc);
+  if (idx == UINT32_MAX)
+    return llvm::createStringError(
+        llvm::inconvertibleErrorCode(),
+        "no DWARF location list entry for PC 0x%" PRIx64, load_addr);
 
-  const Entry &entry = *m_exprs.GetEntryAtIndex(index);
-  return DWARFExpressionEntry{entry.base, entry.GetRangeEnd(), &entry.data};
+  const auto &entry = *m_exprs.GetEntryAtIndex(idx);
+  AddressRange range_in_file(entry.base, entry.GetRangeEnd() - entry.base);
+  return DWARFExpressionEntry{range_in_file, &entry.data};
 }
 
 const DWARFExpression *

>From 7e8741edfefa6989d06b4e50e11dfd4a47d57d28 Mon Sep 17 00:00:00 2001
From: Abdullah Mohammad Amin
 <67847674+ultimateforc...@users.noreply.github.com>
Date: Sat, 28 Jun 2025 12:59:08 -0400
Subject: [PATCH 7/7] Update DWARFExpressionList.h

Updated commenting style for struct DWARFExpressionEntry
---
 lldb/include/lldb/Expression/DWARFExpressionList.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index 4af6f99b9c23a..31b852eb1ec80 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -62,7 +62,8 @@ class DWARFExpressionList {
   
   /// Represents an entry in the DWARFExpressionList with all needed metadata.
   struct DWARFExpressionEntry {
-    AddressRange file_range; /// Represents a DWARF location range in the 
DWARF unit’s file‐address space
+    /// Represents a DWARF location range in the DWARF unit’s file‐address 
space
+    AddressRange file_range;
     const DWARFExpression *expr;
   };
 

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to