[Lldb-commits] [lldb] Reapply "[lldb] Convert file address to load address when reading memory for DW_OP_piece" (PR #117168)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 21 06:40:43 PST 2024
https://github.com/kuilpd created https://github.com/llvm/llvm-project/pull/117168
This commit fixes the test in so that the breakpoint is triggered correctly after `array` usage on Aarch64.
Reapplies #116411 with a fix.
>From b59a2114542999fa233e802cbc36500678132cb2 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Thu, 14 Nov 2024 20:15:19 +0500
Subject: [PATCH 1/3] Convert file address to load address when reading memory
for DW_OP_piece
---
lldb/source/Expression/DWARFExpression.cpp | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index f92f25ed342a9c..a7126b25c1cc38 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -1853,12 +1853,25 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
const Value::ValueType curr_piece_source_value_type =
curr_piece_source_value.GetValueType();
Scalar &scalar = curr_piece_source_value.GetScalar();
- const lldb::addr_t addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
+ lldb::addr_t addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
switch (curr_piece_source_value_type) {
case Value::ValueType::Invalid:
return llvm::createStringError("invalid value type");
- case Value::ValueType::LoadAddress:
- case Value::ValueType::FileAddress: {
+ case Value::ValueType::FileAddress:
+ if (target) {
+ curr_piece_source_value.ConvertToLoadAddress(module_sp.get(),
+ target);
+ addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
+ } else {
+ return llvm::createStringError(
+ "unable to convert file address 0x%" PRIx64
+ " to load address "
+ "for DW_OP_piece(%" PRIu64 "): "
+ "no target available",
+ addr, piece_byte_size);
+ }
+ [[fallthrough]];
+ case Value::ValueType::LoadAddress: {
if (target) {
if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
if (target->ReadMemory(addr, curr_piece.GetBuffer().GetBytes(),
>From 930bac5a6b36c29fcbf3b602e5fc619b6469dfb5 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Fri, 15 Nov 2024 20:42:58 +0500
Subject: [PATCH 2/3] Add a test
---
.../Shell/SymbolFile/DWARF/DW_OP_piece-O3.c | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
diff --git a/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c b/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
new file mode 100644
index 00000000000000..d31250426dc112
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
@@ -0,0 +1,23 @@
+// Check that optimized with -O3 values that have a file address can be read
+// DWARF info:
+// 0x00000023: DW_TAG_variable
+// DW_AT_name ("array")
+// DW_AT_type (0x00000032 "char[5]")
+// DW_AT_location (DW_OP_piece 0x2, DW_OP_addrx 0x0, DW_OP_piece 0x1)
+
+// RUN: %clang_host -O3 -gdwarf %s -o %t
+// RUN: %lldb %t \
+// RUN: -o "b 22" \
+// RUN: -o "r" \
+// RUN: -o "p/x array[2]" \
+// RUN: -b | FileCheck %s
+//
+// CHECK: (lldb) p/x array[2]
+// CHECK: (char) 0x03
+
+static char array[5] = {0, 1, 2, 3, 4};
+
+int main(void) {
+ array[2]++;
+ return 0;
+}
\ No newline at end of file
>From ff7cd83f1d99215803bbc3279f93dd8cb7dd1a77 Mon Sep 17 00:00:00 2001
From: Ilia Kuklin <ikuklin at accesssoftek.com>
Date: Wed, 20 Nov 2024 21:50:35 +0500
Subject: [PATCH 3/3] Move array usage to a separate function to ensure there
is a breakpoint afterwards
---
lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c b/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
index d31250426dc112..77ea81f30395f0 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
+++ b/lldb/test/Shell/SymbolFile/DWARF/DW_OP_piece-O3.c
@@ -7,7 +7,7 @@
// RUN: %clang_host -O3 -gdwarf %s -o %t
// RUN: %lldb %t \
-// RUN: -o "b 22" \
+// RUN: -o "b 25" \
// RUN: -o "r" \
// RUN: -o "p/x array[2]" \
// RUN: -b | FileCheck %s
@@ -17,7 +17,10 @@
static char array[5] = {0, 1, 2, 3, 4};
+void func() __attribute__((noinline));
+void func() { ++array[2]; };
+
int main(void) {
- array[2]++;
+ func();
return 0;
-}
\ No newline at end of file
+}
More information about the lldb-commits
mailing list