Skip to content

Commit df6822f

Browse files
authored
[lldb] Fix error reporting in SBTarget::ReadMemory (#109764)
The function should use the by-ref SBError argument instead of creating a new one. This code has been here since ~forever, and was probably copied from methods which return an SBError result (where one needs to create a local variable).
1 parent a6ea0b0 commit df6822f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lldb/source/API/SBTarget.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,15 +662,14 @@ size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
662662
lldb::SBError &error) {
663663
LLDB_INSTRUMENT_VA(this, addr, buf, size, error);
664664

665-
SBError sb_error;
666665
size_t bytes_read = 0;
667666
TargetSP target_sp(GetSP());
668667
if (target_sp) {
669668
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
670669
bytes_read =
671-
target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true);
670+
target_sp->ReadMemory(addr.ref(), buf, size, error.ref(), true);
672671
} else {
673-
sb_error.SetErrorString("invalid target");
672+
error.SetErrorString("invalid target");
674673
}
675674

676675
return bytes_read;

lldb/test/API/python_api/target/TestTargetAPI.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def test_read_memory(self):
153153
self.assertSuccess(error, "Make sure memory read succeeded")
154154
self.assertEqual(len(content), 1)
155155

156+
# Make sure reading from 0x0 fails
157+
sb_addr = lldb.SBAddress(0, target)
158+
self.assertIsNone(target.ReadMemory(sb_addr, 1, error))
159+
self.assertTrue(error.Fail())
160+
156161
@skipIfWindows # stdio manipulation unsupported on Windows
157162
@skipIfRemote # stdio manipulation unsupported on remote iOS devices<rdar://problem/54581135>
158163
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])

0 commit comments

Comments
 (0)