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/CommandObjectSource.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lldb/source/Commands/CommandObjectSource.cpp') diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index 98907c4..5ddd46a 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -50,20 +50,20 @@ class CommandObjectSourceInfo : public CommandObjectParsed { switch (short_option) { case 'l': if (option_arg.getAsInteger(0, start_line)) - error.SetErrorStringWithFormat("invalid line number: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid line number: '%s'", + option_arg.str().c_str()); break; case 'e': if (option_arg.getAsInteger(0, end_line)) - error.SetErrorStringWithFormat("invalid line number: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid line number: '%s'", + option_arg.str().c_str()); break; case 'c': if (option_arg.getAsInteger(0, num_lines)) - error.SetErrorStringWithFormat("invalid line count: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid line count: '%s'", + option_arg.str().c_str()); break; case 'f': @@ -612,14 +612,14 @@ class CommandObjectSourceList : public CommandObjectParsed { switch (short_option) { case 'l': if (option_arg.getAsInteger(0, start_line)) - error.SetErrorStringWithFormat("invalid line number: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid line number: '%s'", + option_arg.str().c_str()); break; case 'c': if (option_arg.getAsInteger(0, num_lines)) - error.SetErrorStringWithFormat("invalid line count: '%s'", - option_arg.str().c_str()); + error = Status::FromErrorStringWithFormat("invalid line count: '%s'", + option_arg.str().c_str()); break; case 'f': @@ -649,9 +649,8 @@ class CommandObjectSourceList : public CommandObjectParsed { OptionValueFileColonLine value; Status fcl_err = value.SetValueFromString(option_arg); if (!fcl_err.Success()) { - error.SetErrorStringWithFormat( - "Invalid value for file:line specifier: %s", - fcl_err.AsCString()); + error = Status::FromErrorStringWithFormat( + "Invalid value for file:line specifier: %s", fcl_err.AsCString()); } else { file_name = value.GetFileSpec().GetPath(); start_line = value.GetLineNumber(); -- cgit v1.1