https://github.com/labath created https://github.com/llvm/llvm-project/pull/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). >From 671ca69cdd7e5b6ce5e4563a38c5af25f4c36fe9 Mon Sep 17 00:00:00 2001 From: Pavel Labath <pa...@labath.sk> Date: Tue, 24 Sep 2024 09:57:50 +0200 Subject: [PATCH] [lldb] Fix error reporting in SBTarget::ReadMemory 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). --- lldb/source/API/SBTarget.cpp | 5 ++--- lldb/test/API/python_api/target/TestTargetAPI.py | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 1c1f7e2a03def8..d5017ad6bff166 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -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; diff --git a/lldb/test/API/python_api/target/TestTargetAPI.py b/lldb/test/API/python_api/target/TestTargetAPI.py index 2e8d6a5b1e53f6..155a25b576b03a 100644 --- a/lldb/test/API/python_api/target/TestTargetAPI.py +++ b/lldb/test/API/python_api/target/TestTargetAPI.py @@ -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"]) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits