Skip to content

[lldb] Fix error reporting in SBTarget::ReadMemory #109764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lldb/source/API/SBTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,14 @@ size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size,
lldb::SBError &error) {
LLDB_INSTRUMENT_VA(this, addr, buf, size, error);

SBError sb_error;
size_t bytes_read = 0;
TargetSP target_sp(GetSP());
if (target_sp) {
std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex());
bytes_read =
target_sp->ReadMemory(addr.ref(), buf, size, sb_error.ref(), true);
target_sp->ReadMemory(addr.ref(), buf, size, error.ref(), true);
} else {
sb_error.SetErrorString("invalid target");
error.SetErrorString("invalid target");
}

return bytes_read;
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/python_api/target/TestTargetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def test_read_memory(self):
self.assertSuccess(error, "Make sure memory read succeeded")
self.assertEqual(len(content), 1)

# Make sure reading from 0x0 fails
sb_addr = lldb.SBAddress(0, target)
self.assertIsNone(target.ReadMemory(sb_addr, 1, error))
self.assertTrue(error.Fail())

@skipIfWindows # stdio manipulation unsupported on Windows
@skipIfRemote # stdio manipulation unsupported on remote iOS devices<rdar://problem/54581135>
@skipIf(oslist=["linux"], archs=["arm", "aarch64"])
Expand Down
Loading