diff options
author | Adrian Prantl <aprantl@apple.com> | 2024-08-27 10:59:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-27 10:59:31 -0700 |
commit | 0642cd768b80665585c8500bed2933a3b99123dc (patch) | |
tree | a412a5eafff54ef9a7cb884e01907a4f521f5140 /lldb/source/Host/common/NativeProcessProtocol.cpp | |
parent | acb33a0c9bc902dc1aef703c02b8fd3a1132cb14 (diff) | |
download | llvm-0642cd768b80665585c8500bed2933a3b99123dc.zip llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.gz llvm-0642cd768b80665585c8500bed2933a3b99123dc.tar.bz2 |
[lldb] Turn lldb_private::Status into a value type. (#106163)
This patch removes all of the Set.* methods from Status.
This cleanup is part of a series of patches that make it harder use the
anti-pattern of keeping a long-lives Status object around and updating
it while dropping any errors it contains on the floor.
This patch is largely NFC, the more interesting next steps this enables
is to:
1. remove Status.Clear()
2. assert that Status::operator=() never overwrites an error
3. remove Status::operator=()
Note that step (2) will bring 90% of the benefits for users, and step
(3) will dramatically clean up the error handling code in various
places. In the end my goal is to convert all APIs that are of the form
` ResultTy DoFoo(Status& error)
`
to
` llvm::Expected<ResultTy> DoFoo()
`
How to read this patch?
The interesting changes are in Status.h and Status.cpp, all other
changes are mostly
` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git
grep -l SetErrorString lldb/source)
`
plus the occasional manual cleanup.
Diffstat (limited to 'lldb/source/Host/common/NativeProcessProtocol.cpp')
-rw-r--r-- | lldb/source/Host/common/NativeProcessProtocol.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lldb/source/Host/common/NativeProcessProtocol.cpp b/lldb/source/Host/common/NativeProcessProtocol.cpp index b3ef8f0..d3b9dde 100644 --- a/lldb/source/Host/common/NativeProcessProtocol.cpp +++ b/lldb/source/Host/common/NativeProcessProtocol.cpp @@ -34,7 +34,7 @@ NativeProcessProtocol::NativeProcessProtocol(lldb::pid_t pid, int terminal_fd, lldb_private::Status NativeProcessProtocol::Interrupt() { Status error; #if !defined(SIGSTOP) - error.SetErrorString("local host does not support signaling"); + error = Status::FromErrorString("local host does not support signaling"); return error; #else return Signal(SIGSTOP); @@ -51,20 +51,20 @@ lldb_private::Status NativeProcessProtocol::GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) { // Default: not implemented. - return Status("not implemented"); + return Status::FromErrorString("not implemented"); } lldb_private::Status NativeProcessProtocol::ReadMemoryTags(int32_t type, lldb::addr_t addr, size_t len, std::vector<uint8_t> &tags) { - return Status("not implemented"); + return Status::FromErrorString("not implemented"); } lldb_private::Status NativeProcessProtocol::WriteMemoryTags(int32_t type, lldb::addr_t addr, size_t len, const std::vector<uint8_t> &tags) { - return Status("not implemented"); + return Status::FromErrorString("not implemented"); } std::optional<WaitStatus> NativeProcessProtocol::GetExitStatus() { @@ -248,7 +248,8 @@ Status NativeProcessProtocol::SetHardwareBreakpoint(lldb::addr_t addr, if (hw_debug_cap == std::nullopt || hw_debug_cap->first == 0 || hw_debug_cap->first <= m_hw_breakpoints_map.size()) - return Status("Target does not have required no of hardware breakpoints"); + return Status::FromErrorString( + "Target does not have required no of hardware breakpoints"); // Vector below stores all thread pointer for which we have we successfully // set this hardware breakpoint. If any of the current process threads fails @@ -360,7 +361,7 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) { LLDB_LOG(log, "addr = {0:x}", addr); auto it = m_software_breakpoints.find(addr); if (it == m_software_breakpoints.end()) - return Status("Breakpoint not found."); + return Status::FromErrorString("Breakpoint not found."); assert(it->second.ref_count > 0); if (--it->second.ref_count > 0) return Status(); @@ -377,15 +378,16 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) { error = ReadMemory(addr, curr_break_op.data(), curr_break_op.size(), bytes_read); if (error.Fail() || bytes_read < curr_break_op.size()) { - return Status("addr=0x%" PRIx64 - ": tried to read %zu bytes but only read %zu", - addr, curr_break_op.size(), bytes_read); + return Status::FromErrorStringWithFormat( + "addr=0x%" PRIx64 ": tried to read %zu bytes but only read %zu", addr, + curr_break_op.size(), bytes_read); } const auto &saved = it->second.saved_opcodes; // Make sure the breakpoint opcode exists at this address if (llvm::ArrayRef(curr_break_op) != it->second.breakpoint_opcodes) { if (curr_break_op != it->second.saved_opcodes) - return Status("Original breakpoint trap is no longer in memory."); + return Status::FromErrorString( + "Original breakpoint trap is no longer in memory."); LLDB_LOG(log, "Saved opcodes ({0:@[x]}) have already been restored at {1:x}.", llvm::make_range(saved.begin(), saved.end()), addr); @@ -395,9 +397,9 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) { size_t bytes_written = 0; error = WriteMemory(addr, saved.data(), saved.size(), bytes_written); if (error.Fail() || bytes_written < saved.size()) { - return Status("addr=0x%" PRIx64 - ": tried to write %zu bytes but only wrote %zu", - addr, saved.size(), bytes_written); + return Status::FromErrorStringWithFormat( + "addr=0x%" PRIx64 ": tried to write %zu bytes but only wrote %zu", + addr, saved.size(), bytes_written); } // Verify that our original opcode made it back to the inferior @@ -406,9 +408,10 @@ Status NativeProcessProtocol::RemoveSoftwareBreakpoint(lldb::addr_t addr) { error = ReadMemory(addr, verify_opcode.data(), verify_opcode.size(), verify_bytes_read); if (error.Fail() || verify_bytes_read < verify_opcode.size()) { - return Status("addr=0x%" PRIx64 - ": tried to read %zu verification bytes but only read %zu", - addr, verify_opcode.size(), verify_bytes_read); + return Status::FromErrorStringWithFormat( + "addr=0x%" PRIx64 + ": tried to read %zu verification bytes but only read %zu", + addr, verify_opcode.size(), verify_bytes_read); } if (verify_opcode != saved) LLDB_LOG(log, "Restoring bytes at {0:x}: {1:@[x]}", addr, |