Skip to content

Commit 915d588

Browse files
authored
Reapply "[lldb] Convert file address to load address when reading memory for DW_OP_piece" (#117168)
This commit fixes the test so that the breakpoint is triggered correctly after `array` usage on AArch64. Reapplies #116411 with a fix.
1 parent 32da1fd commit 915d588

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,12 +1853,25 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
18531853
const Value::ValueType curr_piece_source_value_type =
18541854
curr_piece_source_value.GetValueType();
18551855
Scalar &scalar = curr_piece_source_value.GetScalar();
1856-
const lldb::addr_t addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1856+
lldb::addr_t addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
18571857
switch (curr_piece_source_value_type) {
18581858
case Value::ValueType::Invalid:
18591859
return llvm::createStringError("invalid value type");
1860-
case Value::ValueType::LoadAddress:
1861-
case Value::ValueType::FileAddress: {
1860+
case Value::ValueType::FileAddress:
1861+
if (target) {
1862+
curr_piece_source_value.ConvertToLoadAddress(module_sp.get(),
1863+
target);
1864+
addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1865+
} else {
1866+
return llvm::createStringError(
1867+
"unable to convert file address 0x%" PRIx64
1868+
" to load address "
1869+
"for DW_OP_piece(%" PRIu64 "): "
1870+
"no target available",
1871+
addr, piece_byte_size);
1872+
}
1873+
[[fallthrough]];
1874+
case Value::ValueType::LoadAddress: {
18621875
if (target) {
18631876
if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
18641877
if (target->ReadMemory(addr, curr_piece.GetBuffer().GetBytes(),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Check that optimized with -O3 values that have a file address can be read
2+
// DWARF info:
3+
// 0x00000023: DW_TAG_variable
4+
// DW_AT_name ("array")
5+
// DW_AT_type (0x00000032 "char[5]")
6+
// DW_AT_location (DW_OP_piece 0x2, DW_OP_addrx 0x0, DW_OP_piece 0x1)
7+
8+
// RUN: %clang_host -O3 -gdwarf %s -o %t
9+
// RUN: %lldb %t \
10+
// RUN: -o "b 25" \
11+
// RUN: -o "r" \
12+
// RUN: -o "p/x array[2]" \
13+
// RUN: -b | FileCheck %s
14+
//
15+
// CHECK: (lldb) p/x array[2]
16+
// CHECK: (char) 0x03
17+
18+
static char array[5] = {0, 1, 2, 3, 4};
19+
20+
void func() __attribute__((noinline));
21+
void func() { ++array[2]; };
22+
23+
int main(void) {
24+
func();
25+
return 0;
26+
}

0 commit comments

Comments
 (0)