[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits


@@ -53,6 +53,27 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
   return GetExpressionAtAddress(func_load_addr, addr) != nullptr;
 }
 
+llvm::Expected
+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,

UltimateForce21 wrote:

As you know the new function GetExpressionEntryAtAddress, does almost exact 
same thing as this one. I don't see this function being used anywhere else in 
the lldb code base, so maybe it can be removed, but to be safe I did not want 
to alter it. But from what I can tell, it should be okay to remove it. We can 
also choose to keep it and maybe refactor it to just call the 
GetExpressionEntryAtAddress and just return the `DWARFExpression *expr`.

https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/2] [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
+  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::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/2] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere 
---
 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;

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


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/3] [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
+  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::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/3] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere 
---
 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/3] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Updated comment for GetExpressionEntryAtAddress to directly refer to struct 
DWARFExpressionEntry

Co-authored-by: Jonas Devlieghere 
---
 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/includ

[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/4] [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
+  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::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/4] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere 
---
 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/4] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Updated comment for GetExpressionEntryAtAddress to directly refer to struct 
DWARFExpressionEntry

Co-authored-by: Jonas Devlieghere 
---
 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/includ

[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits


@@ -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;

UltimateForce21 wrote:

These are file addresses (without offsets applied), I will try to make that 
more clear both in the comments and in the variable names. I'll also take a 
look into the AddressRange class and see if I can utilize it, thank you for the 
pointers.


https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-19 Thread Abdullah Mohammad Amin via lldb-commits


@@ -53,6 +53,27 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
   return GetExpressionAtAddress(func_load_addr, addr) != nullptr;
 }
 
+llvm::Expected
+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);

UltimateForce21 wrote:

Sounds good, I will refactor it to return std::optional instead.

https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-14 Thread Abdullah Mohammad Amin via lldb-commits

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

This patch introduces a new struct and helper API in `DWARFExpressionList` to 
expose 
variable location metadata (base address, end address, and DWARFExpression 
pointer) for 
a given PC address. It will be used in later patches to annotate disassembly 
instructions 
with source-level variable locations.

## New struct
```
/// Represents one entry in a DWARFExpressionList, with its range and expr.
struct DWARFExpressionEntry {
  lldb::addr_t base;   // file‐address start of this location range
  lldb::addr_t end;// file‐address end of this range (exclusive)
  const DWARFExpression *expr; // the DWARF expression for this range
};
```

## New API
```
/// Retrieve the DWARFExpressionEntry covering a particular instruction.
///
/// \param func_load_addr
/// The load address of the start of the function containing this location 
list;
/// used to translate between file offsets and load addresses. If this is
/// LLDB_INVALID_ADDRESS, the stored CU base (m_func_file_addr) is used.
///
/// \param load_addr
/// The load address of the *current* PC (i.e., the instruction for which
/// we want its variable‐location entry). We first convert this back into
/// the function’s file‐address space to find the correct DWARF range.
///
/// \returns
/// On success, an entry whose `[base,end)` covers this PC; else an Error.
llvm::Expected
GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
lldb::addr_t load_addr) const;
```

## Rationale
LLDB already provides:
```
const DWARFExpression *
GetExpressionAtAddress(lldb::addr_t func_load_addr,
   lldb::addr_t load_addr) const;

```
However, this only returns the DWARF expression itself, without the 
file‐address start (base) and end (end) of the location range. Those bounds are 
crucial for:

1) Detecting range beginnings: render a var =  annotation exactly 
when a variable’s live‐range starts.

2) Detecting range continuation: optionally display a “|” on subsequent 
instructions in the same range.

3) Detecting state changes: know when a variable moves (e.g. from one register 
to another), becomes a constant, or goes out of scope.

These primitives form the foundation for the Rich Disassembler feature proposed 
for GSoC 25.

  
 


>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH] [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
+  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::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_fil

[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-14 Thread Abdullah Mohammad Amin via lldb-commits

UltimateForce21 wrote:

@adrian-prantl @JDevlieghere I’ve opened my first PR for the new 
DWARFExpression API. Looking forward to your feedback!

https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/9] [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
+  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::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/9] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere 
---
 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/9] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Updated comment for GetExpressionEntryAtAddress to directly refer to struct 
DWARFExpressionEntry

Co-authored-by: Jonas Devlieghere 
---
 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/includ

[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
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
+  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::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 
---
 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 
---
 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/includ

[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits


@@ -53,6 +54,29 @@ bool DWARFExpressionList::ContainsAddress(lldb::addr_t 
func_load_addr,
   return GetExpressionAtAddress(func_load_addr, addr) != nullptr;
 }
 
+llvm::Expected
+DWARFExpressionList::GetExpressionEntryAtAddress(lldb::addr_t func_load_addr,
+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;
+
+  uint32_t idx = m_exprs.FindEntryIndexThatContains(file_pc);

UltimateForce21 wrote:

for sure, seems like it would be easier for implementation, i was just 
following the same logic, as 
```
const DWARFExpression *
DWARFExpressionList::GetExpressionAtAddress(lldb::addr_t func_load_addr,
lldb::addr_t load_addr) const
```

will update to use `const Entry *FindEntryThatContains(B addr) const ()` instead

https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits

https://github.com/UltimateForce21 edited 
https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits

https://github.com/UltimateForce21 edited 
https://github.com/llvm/llvm-project/pull/144238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Add DWARFExpressionEntry and GetExpressionEntryAtAddress() to … (PR #144238)

2025-06-28 Thread Abdullah Mohammad Amin via lldb-commits

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

>From 8ed8c540e7600d720a63bc2882a81a2c65c11d41 Mon Sep 17 00:00:00 2001
From: ultimateforce21 
Date: Wed, 11 Jun 2025 00:11:09 -0400
Subject: [PATCH 1/8] [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
+  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::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/8] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Co-authored-by: Jonas Devlieghere 
---
 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/8] Update lldb/include/lldb/Expression/DWARFExpressionList.h

Updated comment for GetExpressionEntryAtAddress to directly refer to struct 
DWARFExpressionEntry

Co-authored-by: Jonas Devlieghere 
---
 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/includ