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/Interpreter/CommandInterpreter.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/Interpreter/CommandInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 8729880..df539d5 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -961,20 +961,23 @@ CommandObjectMultiword *CommandInterpreter::VerifyUserMultiwordCmdPath( [&result](CommandObjectSP cmd_sp, const char *name) -> CommandObjectMultiword * { if (!cmd_sp) { - result.SetErrorStringWithFormat("Path component: '%s' not found", name); + result = Status::FromErrorStringWithFormat( + "Path component: '%s' not found", name); return nullptr; } if (!cmd_sp->IsUserCommand()) { - result.SetErrorStringWithFormat("Path component: '%s' is not a user " - "command", - name); + result = Status::FromErrorStringWithFormat( + "Path component: '%s' is not a user " + "command", + name); return nullptr; } CommandObjectMultiword *cmd_as_multi = cmd_sp->GetAsMultiwordCommand(); if (!cmd_as_multi) { - result.SetErrorStringWithFormat("Path component: '%s' is not a container " - "command", - name); + result = Status::FromErrorStringWithFormat( + "Path component: '%s' is not a container " + "command", + name); return nullptr; } return cmd_as_multi; @@ -982,7 +985,7 @@ CommandObjectMultiword *CommandInterpreter::VerifyUserMultiwordCmdPath( size_t num_args = path.GetArgumentCount(); if (num_args == 0) { - result.SetErrorString("empty command path"); + result = Status::FromErrorString("empty command path"); return nullptr; } @@ -1169,18 +1172,19 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name, lldbassert((this == &cmd_sp->GetCommandInterpreter()) && "tried to add a CommandObject from a different interpreter"); if (name.empty()) { - result.SetErrorString("can't use the empty string for a command name"); + result = Status::FromErrorString( + "can't use the empty string for a command name"); return result; } // do not allow replacement of internal commands if (CommandExists(name)) { - result.SetErrorString("can't replace builtin command"); + result = Status::FromErrorString("can't replace builtin command"); return result; } if (UserCommandExists(name)) { if (!can_replace) { - result.SetErrorStringWithFormatv( + result = Status::FromErrorStringWithFormatv( "user command \"{0}\" already exists and force replace was not set " "by --overwrite or 'settings set interpreter.require-overwrite " "false'", @@ -1189,13 +1193,14 @@ Status CommandInterpreter::AddUserCommand(llvm::StringRef name, } if (cmd_sp->IsMultiwordObject()) { if (!m_user_mw_dict[std::string(name)]->IsRemovable()) { - result.SetErrorString( + result = Status::FromErrorString( "can't replace explicitly non-removable multi-word command"); return result; } } else { if (!m_user_dict[std::string(name)]->IsRemovable()) { - result.SetErrorString("can't replace explicitly non-removable command"); + result = Status::FromErrorString( + "can't replace explicitly non-removable command"); return result; } } @@ -1835,16 +1840,18 @@ CommandInterpreter::PreprocessToken(std::string &expr_str) { if (value_string_size) { expr_str = value_strm.GetData(); } else { - error.SetErrorStringWithFormat("expression value didn't result " - "in a scalar value for the " - "expression '%s'", - expr_str.c_str()); + error = + Status::FromErrorStringWithFormat("expression value didn't result " + "in a scalar value for the " + "expression '%s'", + expr_str.c_str()); } } else { - error.SetErrorStringWithFormat("expression value didn't result " - "in a scalar value for the " - "expression '%s'", - expr_str.c_str()); + error = + Status::FromErrorStringWithFormat("expression value didn't result " + "in a scalar value for the " + "expression '%s'", + expr_str.c_str()); } return error; } @@ -1857,8 +1864,9 @@ CommandInterpreter::PreprocessToken(std::string &expr_str) { error = expr_result_valobj_sp->GetError(); if (error.Success()) { - std::string result = lldb_private::toString(expr_result); - error.SetErrorString(result + "for the expression '" + expr_str + "'"); + std::string result = lldb_private::toString(expr_result) + + "for the expression '" + expr_str + "'"; + error = Status(result); } return error; } |