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/Commands/CommandObjectPlatform.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/Commands/CommandObjectPlatform.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectPlatform.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 5b18f2b..f849a38 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -78,16 +78,16 @@ public: case 'v': { if (option_arg.getAsInteger(8, m_permissions)) { m_permissions = 0777; - error.SetErrorStringWithFormat("invalid value for permissions: %s", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid value for permissions: %s", option_arg.str().c_str()); } } break; case 's': { mode_t perms = ParsePermissionString(option_arg); if (perms == (mode_t)-1) - error.SetErrorStringWithFormat("invalid value for permissions: %s", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid value for permissions: %s", option_arg.str().c_str()); else m_permissions = perms; } break; @@ -609,13 +609,13 @@ protected: switch (short_option) { case 'o': if (option_arg.getAsInteger(0, m_offset)) - error.SetErrorStringWithFormat("invalid offset: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid offset: '%s'", + option_arg.str().c_str()); break; case 'c': if (option_arg.getAsInteger(0, m_count)) - error.SetErrorStringWithFormat("invalid offset: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid offset: '%s'", + option_arg.str().c_str()); break; default: llvm_unreachable("Unimplemented option"); @@ -702,8 +702,8 @@ protected: switch (short_option) { case 'o': if (option_arg.getAsInteger(0, m_offset)) - error.SetErrorStringWithFormat("invalid offset: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid offset: '%s'", + option_arg.str().c_str()); break; case 'd': m_data.assign(std::string(option_arg)); @@ -1328,14 +1328,14 @@ protected: case 'p': { match_info.GetProcessInfo().SetProcessID(id); if (!success) - error.SetErrorStringWithFormat("invalid process ID string: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid process ID string: '%s'", option_arg.str().c_str()); break; } case 'P': match_info.GetProcessInfo().SetParentProcessID(id); if (!success) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "invalid parent process ID string: '%s'", option_arg.str().c_str()); break; @@ -1343,15 +1343,15 @@ protected: case 'u': match_info.GetProcessInfo().SetUserID(success ? id : UINT32_MAX); if (!success) - error.SetErrorStringWithFormat("invalid user ID string: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid user ID string: '%s'", option_arg.str().c_str()); break; case 'U': match_info.GetProcessInfo().SetEffectiveUserID(success ? id : UINT32_MAX); if (!success) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "invalid effective user ID string: '%s'", option_arg.str().c_str()); break; @@ -1359,15 +1359,15 @@ protected: case 'g': match_info.GetProcessInfo().SetGroupID(success ? id : UINT32_MAX); if (!success) - error.SetErrorStringWithFormat("invalid group ID string: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid group ID string: '%s'", option_arg.str().c_str()); break; case 'G': match_info.GetProcessInfo().SetEffectiveGroupID(success ? id : UINT32_MAX); if (!success) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "invalid effective group ID string: '%s'", option_arg.str().c_str()); break; @@ -1630,7 +1630,7 @@ public: case 't': uint32_t timeout_sec; if (option_arg.getAsInteger(10, timeout_sec)) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a numeric value.", option_arg.str().c_str()); else @@ -1638,7 +1638,7 @@ public: break; case 's': { if (option_arg.empty()) { - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "missing shell interpreter path for option -i|--interpreter."); return error; } @@ -1734,7 +1734,7 @@ public: } else { result.GetOutputStream().Printf( "error: cannot run remote shell commands without a platform\n"); - error.SetErrorString( + error = Status::FromErrorString( "error: cannot run remote shell commands without a platform"); } |