From 0642cd768b80665585c8500bed2933a3b99123dc Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 27 Aug 2024 10:59:31 -0700 Subject: [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 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. --- lldb/source/Commands/CommandObjectExpression.cpp | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lldb/source/Commands/CommandObjectExpression.cpp') diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp index 769f01d..7711946 100644 --- a/lldb/source/Commands/CommandObjectExpression.cpp +++ b/lldb/source/Commands/CommandObjectExpression.cpp @@ -52,7 +52,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( option_arg.str().c_str()); Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n"); - error.SetErrorString(sstr.GetString()); + error = Status(sstr.GetString().str()); } break; @@ -61,7 +61,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( bool result; result = OptionArgParser::ToBoolean(option_arg, true, &success); if (!success) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "invalid all-threads value setting: \"%s\"", option_arg.str().c_str()); else @@ -74,7 +74,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( if (success) ignore_breakpoints = tmp_value; else - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a boolean value.", option_arg.str().c_str()); break; @@ -86,7 +86,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( if (success) allow_jit = tmp_value; else - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a boolean value.", option_arg.str().c_str()); break; @@ -95,8 +95,8 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( case 't': if (option_arg.getAsInteger(0, timeout)) { timeout = 0; - error.SetErrorStringWithFormat("invalid timeout setting \"%s\"", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat( + "invalid timeout setting \"%s\"", option_arg.str().c_str()); } break; @@ -106,7 +106,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( if (success) unwind_on_error = tmp_value; else - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a boolean value.", option_arg.str().c_str()); break; @@ -121,7 +121,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( OptionArgParser::ToOptionEnum( option_arg, GetDefinitions()[option_idx].enum_values, 0, error); if (!error.Success()) - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "unrecognized value for description-verbosity '%s'", option_arg.str().c_str()); break; @@ -142,7 +142,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( if (success) auto_apply_fixits = tmp_value ? eLazyBoolYes : eLazyBoolNo; else - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a boolean value.", option_arg.str().c_str()); break; @@ -155,7 +155,7 @@ Status CommandObjectExpression::CommandOptions::SetOptionValue( if (success) suppress_persistent_result = !persist_result ? eLazyBoolYes : eLazyBoolNo; else - error.SetErrorStringWithFormat( + error = Status::FromErrorStringWithFormat( "could not convert \"%s\" to a boolean value.", option_arg.str().c_str()); break; @@ -392,9 +392,9 @@ CanBeUsedForElementCountPrinting(ValueObject &valobj) { CompilerType type(valobj.GetCompilerType()); CompilerType pointee; if (!type.IsPointerType(&pointee)) - return Status("as it does not refer to a pointer"); + return Status::FromErrorString("as it does not refer to a pointer"); if (pointee.IsVoidType()) - return Status("as it refers to a pointer to void"); + return Status::FromErrorString("as it refers to a pointer to void"); return Status(); } @@ -650,7 +650,7 @@ void CommandObjectExpression::DoExecute(llvm::StringRef command, io_handler_sp->SetIsDone(false); debugger.RunIOHandlerAsync(io_handler_sp); } else { - repl_error.SetErrorStringWithFormat( + repl_error = Status::FromErrorStringWithFormat( "Couldn't create a REPL for %s", Language::GetNameForLanguageType(m_command_options.language)); result.SetError(repl_error); -- cgit v1.1