Skip to content

[lldb] Turn lldb_private::Status into a value type. #106163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

adrian-prantl
Copy link
Collaborator

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.

@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2024

@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)

Changes

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&amp; error)
to

llvm::Expected&lt;ResultTy&gt; 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.


Patch is 904.59 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/106163.diff

260 Files Affected:

  • (modified) lldb/bindings/python/python-wrapper.swig (+11-9)
  • (modified) lldb/include/lldb/Core/StructuredDataImpl.h (+9-19)
  • (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h (+1-1)
  • (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h (+6-3)
  • (modified) lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h (+10-5)
  • (modified) lldb/include/lldb/Interpreter/OptionValue.h (+2-1)
  • (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+15-28)
  • (modified) lldb/include/lldb/Target/Process.h (+22-47)
  • (modified) lldb/include/lldb/Target/ProcessTrace.h (+1-3)
  • (modified) lldb/include/lldb/Utility/Status.h (+27-66)
  • (modified) lldb/source/API/SBBreakpoint.cpp (+9-8)
  • (modified) lldb/source/API/SBBreakpointLocation.cpp (+2-2)
  • (modified) lldb/source/API/SBBreakpointName.cpp (+1-1)
  • (modified) lldb/source/API/SBDebugger.cpp (+28-24)
  • (modified) lldb/source/API/SBError.cpp (+13-6)
  • (modified) lldb/source/API/SBFile.cpp (+3-3)
  • (modified) lldb/source/API/SBFrame.cpp (+5-5)
  • (modified) lldb/source/API/SBPlatform.cpp (+15-17)
  • (modified) lldb/source/API/SBProcess.cpp (+44-42)
  • (modified) lldb/source/API/SBStructuredData.cpp (+1-1)
  • (modified) lldb/source/API/SBTarget.cpp (+7-6)
  • (modified) lldb/source/API/SBThread.cpp (+36-34)
  • (modified) lldb/source/API/SBTrace.cpp (+16-14)
  • (modified) lldb/source/API/SBValue.cpp (+22-21)
  • (modified) lldb/source/Breakpoint/Breakpoint.cpp (+8-7)
  • (modified) lldb/source/Breakpoint/BreakpointID.cpp (+9-7)
  • (modified) lldb/source/Breakpoint/BreakpointLocation.cpp (+7-6)
  • (modified) lldb/source/Breakpoint/BreakpointOptions.cpp (+19-14)
  • (modified) lldb/source/Breakpoint/BreakpointPrecondition.cpp (+2-3)
  • (modified) lldb/source/Breakpoint/BreakpointResolver.cpp (+11-7)
  • (modified) lldb/source/Breakpoint/BreakpointResolverAddress.cpp (+4-2)
  • (modified) lldb/source/Breakpoint/BreakpointResolverFileLine.cpp (+10-5)
  • (modified) lldb/source/Breakpoint/BreakpointResolverFileRegex.cpp (+5-4)
  • (modified) lldb/source/Breakpoint/BreakpointResolverName.cpp (+13-10)
  • (modified) lldb/source/Breakpoint/BreakpointResolverScripted.cpp (+2-1)
  • (modified) lldb/source/Commands/CommandObjectBreakpointCommand.cpp (+2-3)
  • (modified) lldb/source/Commands/CommandObjectCommands.cpp (+111-73)
  • (modified) lldb/source/Commands/CommandObjectDisassemble.cpp (+6-5)
  • (modified) lldb/source/Commands/CommandObjectExpression.cpp (+13-13)
  • (modified) lldb/source/Commands/CommandObjectFrame.cpp (+7-7)
  • (modified) lldb/source/Commands/CommandObjectLog.cpp (+4-6)
  • (modified) lldb/source/Commands/CommandObjectMemory.cpp (+8-8)
  • (modified) lldb/source/Commands/CommandObjectPlatform.cpp (+22-22)
  • (modified) lldb/source/Commands/CommandObjectProcess.cpp (+3-3)
  • (modified) lldb/source/Commands/CommandObjectScripting.cpp (+3-3)
  • (modified) lldb/source/Commands/CommandObjectSource.cpp (+12-13)
  • (modified) lldb/source/Commands/CommandObjectTarget.cpp (+21-20)
  • (modified) lldb/source/Commands/CommandObjectThread.cpp (+25-21)
  • (modified) lldb/source/Commands/CommandObjectType.cpp (+30-28)
  • (modified) lldb/source/Commands/CommandObjectWatchpoint.cpp (+2-2)
  • (modified) lldb/source/Commands/CommandObjectWatchpointCommand.cpp (+2-3)
  • (modified) lldb/source/Commands/CommandOptionsProcessAttach.cpp (+2-2)
  • (modified) lldb/source/Commands/CommandOptionsProcessLaunch.cpp (+4-5)
  • (modified) lldb/source/Core/Communication.cpp (+3-3)
  • (modified) lldb/source/Core/Debugger.cpp (+13-11)
  • (modified) lldb/source/Core/FormatEntity.cpp (+21-16)
  • (modified) lldb/source/Core/Module.cpp (+9-8)
  • (modified) lldb/source/Core/ModuleList.cpp (+15-13)
  • (modified) lldb/source/Core/PluginManager.cpp (+3-3)
  • (modified) lldb/source/Core/SearchFilter.cpp (+19-12)
  • (modified) lldb/source/Core/ThreadedCommunication.cpp (+3-3)
  • (modified) lldb/source/Core/UserSettingsController.cpp (+2-6)
  • (modified) lldb/source/Core/Value.cpp (+30-25)
  • (modified) lldb/source/Core/ValueObject.cpp (+61-53)
  • (modified) lldb/source/Core/ValueObjectChild.cpp (+6-5)
  • (modified) lldb/source/Core/ValueObjectDynamicValue.cpp (+7-7)
  • (modified) lldb/source/Core/ValueObjectMemory.cpp (+1-1)
  • (modified) lldb/source/Core/ValueObjectRegister.cpp (+4-4)
  • (modified) lldb/source/Core/ValueObjectVTable.cpp (+10-10)
  • (modified) lldb/source/Core/ValueObjectVariable.cpp (+8-8)
  • (modified) lldb/source/Expression/ExpressionParser.cpp (+6-4)
  • (modified) lldb/source/Expression/IRExecutionUnit.cpp (+17-26)
  • (modified) lldb/source/Expression/IRInterpreter.cpp (+74-101)
  • (modified) lldb/source/Expression/IRMemoryMap.cpp (+41-57)
  • (modified) lldb/source/Expression/Materializer.cpp (+100-90)
  • (modified) lldb/source/Expression/UserExpression.cpp (+24-23)
  • (modified) lldb/source/Expression/UtilityFunction.cpp (+5-4)
  • (modified) lldb/source/Host/common/File.cpp (+34-34)
  • (modified) lldb/source/Host/common/FileCache.cpp (+13-10)
  • (modified) lldb/source/Host/common/Host.cpp (+4-3)
  • (modified) lldb/source/Host/common/LockFileBase.cpp (+5-3)
  • (modified) lldb/source/Host/common/MonitoringProcessLauncher.cpp (+7-5)
  • (modified) lldb/source/Host/common/NativeProcessProtocol.cpp (+19-16)
  • (modified) lldb/source/Host/common/NativeRegisterContext.cpp (+21-21)
  • (modified) lldb/source/Host/common/ProcessLaunchInfo.cpp (+2-2)
  • (modified) lldb/source/Host/common/Socket.cpp (+3-3)
  • (modified) lldb/source/Host/common/TCPSocket.cpp (+2-2)
  • (modified) lldb/source/Host/common/UDPSocket.cpp (+5-5)
  • (modified) lldb/source/Host/macosx/objcxx/Host.mm (+66-59)
  • (modified) lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp (+15-14)
  • (modified) lldb/source/Host/posix/DomainSocket.cpp (+2-2)
  • (modified) lldb/source/Host/posix/FileSystemPosix.cpp (+9-11)
  • (modified) lldb/source/Host/posix/HostProcessPosix.cpp (+3-4)
  • (modified) lldb/source/Host/posix/HostThreadPosix.cpp (+4-4)
  • (modified) lldb/source/Host/posix/LockFilePosix.cpp (+2-3)
  • (modified) lldb/source/Host/posix/MainLoopPosix.cpp (+4-3)
  • (modified) lldb/source/Host/posix/PipePosix.cpp (+11-11)
  • (modified) lldb/source/Host/posix/ProcessLauncherPosixFork.cpp (+3-3)
  • (modified) lldb/source/Host/windows/ConnectionGenericFileWindows.cpp (+1-1)
  • (modified) lldb/source/Host/windows/FileSystem.cpp (+3-3)
  • (modified) lldb/source/Host/windows/Host.cpp (+10-9)
  • (modified) lldb/source/Host/windows/MainLoopWindows.cpp (+7-5)
  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+31-23)
  • (modified) lldb/source/Interpreter/OptionArgParser.cpp (+12-11)
  • (modified) lldb/source/Interpreter/OptionGroupFormat.cpp (+11-10)
  • (modified) lldb/source/Interpreter/OptionGroupPlatform.cpp (+6-6)
  • (modified) lldb/source/Interpreter/OptionGroupPythonClassWithDict.cpp (+7-7)
  • (modified) lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp (+12-12)
  • (modified) lldb/source/Interpreter/OptionGroupVariable.cpp (+6-3)
  • (modified) lldb/source/Interpreter/OptionGroupWatchpoint.cpp (+3-3)
  • (modified) lldb/source/Interpreter/OptionValue.cpp (+11-13)
  • (modified) lldb/source/Interpreter/OptionValueArch.cpp (+2-2)
  • (modified) lldb/source/Interpreter/OptionValueArray.cpp (+28-24)
  • (modified) lldb/source/Interpreter/OptionValueBoolean.cpp (+3-3)
  • (modified) lldb/source/Interpreter/OptionValueChar.cpp (+2-2)
  • (modified) lldb/source/Interpreter/OptionValueDictionary.cpp (+28-22)
  • (modified) lldb/source/Interpreter/OptionValueEnumeration.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueFileColonLine.cpp (+11-10)
  • (modified) lldb/source/Interpreter/OptionValueFileSpec.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueFileSpecList.cpp (+12-9)
  • (modified) lldb/source/Interpreter/OptionValueFormatEntity.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueLanguage.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValuePathMappings.cpp (+18-13)
  • (modified) lldb/source/Interpreter/OptionValueProperties.cpp (+2-2)
  • (modified) lldb/source/Interpreter/OptionValueRegex.cpp (+2-2)
  • (modified) lldb/source/Interpreter/OptionValueSInt64.cpp (+3-3)
  • (modified) lldb/source/Interpreter/OptionValueString.cpp (+1-1)
  • (modified) lldb/source/Interpreter/OptionValueUInt64.cpp (+3-3)
  • (modified) lldb/source/Interpreter/OptionValueUUID.cpp (+2-2)
  • (modified) lldb/source/Interpreter/Options.cpp (+9-7)
  • (modified) lldb/source/Interpreter/ScriptInterpreter.cpp (+1-1)
  • (modified) lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp (+18-14)
  • (modified) lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp (+18-14)
  • (modified) lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp (+10-9)
  • (modified) lldb/source/Plugins/ABI/ARM/ABIMacOSX_arm.cpp (+9-8)
  • (modified) lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp (+9-8)
  • (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips.cpp (+9-8)
  • (modified) lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp (+13-11)
  • (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp (+16-20)
  • (modified) lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp (+13-11)
  • (modified) lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp (+10-9)
  • (modified) lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp (+13-11)
  • (modified) lldb/source/Plugins/ABI/X86/ABIMacOSX_i386.cpp (+9-8)
  • (modified) lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp (+14-10)
  • (modified) lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp (+13-11)
  • (modified) lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp (+13-11)
  • (modified) lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (+1-1)
  • (modified) lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp (+1-2)
  • (modified) lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp (+4-3)
  • (modified) lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (+1-1)
  • (modified) lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp (+2-3)
  • (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (+14-14)
  • (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (+14-14)
  • (modified) lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (+6-6)
  • (modified) lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp (+1-1)
  • (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (+13-8)
  • (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+7-6)
  • (modified) lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp (+29-25)
  • (modified) lldb/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp (+1-1)
  • (modified) lldb/source/Plugins/Platform/Android/AdbClient.cpp (+56-37)
  • (modified) lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp (+19-13)
  • (modified) lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp (+5-6)
  • (modified) lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp (+9-8)
  • (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (+4-3)
  • (modified) lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp (+3-3)
  • (modified) lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp (+2-2)
  • (modified) lldb/source/Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.mm (+12-12)
  • (modified) lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (+61-46)
  • (modified) lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp (+1-1)
  • (modified) lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h (+1-1)
  • (modified) lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp (+70-47)
  • (modified) lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (+34-36)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp (+8-7)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm64.cpp (+8-7)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_mips64.cpp (+12-11)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_powerpc.cpp (+12-11)
  • (modified) lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_x86_64.cpp (+23-20)
  • (modified) lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp (+4-2)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp (+10-9)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp (+8-7)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_ppc64le.cpp (+8-7)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp (+8-7)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_s390x.cpp (+7-6)
  • (modified) lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_x86_64.cpp (+25-22)
  • (modified) lldb/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.cpp (+15-15)
  • (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (+28-28)
  • (modified) lldb/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (+2-2)
  • (modified) lldb/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp (+23-20)
  • (modified) lldb/source/Plugins/Process/Utility/NativeProcessSoftwareSingleStep.cpp (+5-4)
  • (modified) lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_x86.cpp (+7-7)
  • (modified) lldb/source/Plugins/Process/Utility/RegisterContextThreadMemory.cpp (+2-6)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp (+7-5)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_i386.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.cpp (+12-10)
  • (modified) lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp (+9-9)
  • (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp (+14-13)
  • (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+5-5)
  • (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.h (+1-3)
  • (modified) lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (+4-4)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+64-56)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (+27-21)
  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+82-67)
  • (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/minidump/MinidumpTypes.h (+3-6)
  • (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+3-3)
  • (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.h (+1-3)
  • (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp (+12-11)
  • (modified) lldb/source/Plugins/REPL/Clang/ClangREPL.cpp (+1-1)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp (+3-2)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.cpp (+11-8)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPythonInterface.h (+3-4)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (+6-3)
  • (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+51-46)
  • (modified) lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp (+31-26)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (+3-3)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+6-5)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (+9-7)
  • (modified) lldb/source/Plugins/SymbolLocator/DebugSymbols/SymbolLocatorDebugSymbols.cpp (+1-1)
  • (modified) lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetItemInfoHandler.cpp (+12-8)
  • (modified) lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetPendingItemsHandler.cpp (+9-6)
  • (modified) lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetQueuesHandler.cpp (+7-5)
  • (modified) lldb/source/Plugins/SystemRuntime/MacOSX/AppleGetThreadItemInfoHandler.cpp (+12-8)
  • (modified) lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp (+10-10)
  • (modified) lldb/source/Plugins/TraceExporter/ctf/CommandObjectThreadTraceExportCTF.cpp (+2-2)
  • (modified) lldb/source/Symbol/SaveCoreOptions.cpp (+6-5)
  • (modified) lldb/source/Symbol/SymbolContext.cpp (+7-7)
  • (modified) lldb/source/Symbol/Variable.cpp (+7-7)
  • (modified) lldb/source/Target/Memory.cpp (+4-3)
  • (modified) lldb/source/Target/ModuleCache.cpp (+24-19)
  • (modified) lldb/source/Target/Platform.cpp (+73-60)
  • (modified) lldb/source/Target/Process.cpp (+92-77)
  • (modified) lldb/source/Target/RegisterContext.cpp (+11-13)
  • (modified) lldb/source/Target/ScriptedThreadPlan.cpp (+2-2)
  • (modified) lldb/source/Target/StackFrame.cpp (+44-40)
  • (modified) lldb/source/Target/Target.cpp (+84-75)
  • (modified) lldb/source/Target/TargetList.cpp (+9-8)
  • (modified) lldb/source/Target/Thread.cpp (+28-21)
  • (modified) lldb/source/Utility/RegisterValue.cpp (+33-32)
  • (modified) lldb/source/Utility/Scalar.cpp (+12-13)
  • (modified) lldb/source/Utility/SelectHelper.cpp (+8-8)
  • (modified) lldb/source/Utility/Status.cpp (+28-103)
  • (modified) lldb/source/Utility/StringExtractorGDBRemote.cpp (+2-4)
  • (modified) lldb/source/Utility/StructuredData.cpp (+4-4)
  • (modified) lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py (+4-4)
  • (modified) lldb/test/API/functionalities/postmortem/FreeBSDKernel/tools/lldb-minimize-processes.patch (+1-1)
  • (modified) lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py (+1-1)
  • (modified) lldb/tools/lldb-server/Acceptor.cpp (+2-2)
  • (modified) lldb/tools/lldb-server/lldb-platform.cpp (+7-6)
  • (modified) lldb/unittests/Platform/Android/PlatformAndroidTest.cpp (+2-1)
  • (modified) lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp (+1-4)
  • (modified) lldb/unittests/Target/LocateModuleCallbackTest.cpp (+6-6)
  • (modified) lldb/unittests/Target/ModuleCacheTest.cpp (+1-1)
  • (modified) lldb/unittests/Utility/StatusTest.cpp (+7-3)
diff --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index 360c392235a866..810673aaec5d19 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -306,11 +306,11 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
     const char *session_dictionary_name, const StructuredDataImpl &args_impl,
     Status &error) {
   if (python_class_name == NULL || python_class_name[0] == '\0') {
-    error.SetErrorString("Empty class name.");
+    error = Status::FromErrorString("Empty class name.");
     return PythonObject();
   }
   if (!session_dictionary_name) {
-    error.SetErrorString("No session dictionary");
+    error = Status::FromErrorString("No session dictionary");
     return PythonObject();
   }
 
@@ -322,7 +322,7 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
       python_class_name, dict);
 
   if (!pfunc.IsAllocated()) {
-    error.SetErrorStringWithFormat("Could not find class: %s.",
+    error = Status::FromErrorStringWithFormat("Could not find class: %s.",
                                    python_class_name);
     return PythonObject();
   }
@@ -337,7 +337,7 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
       if (auto args_info = callback_func.GetArgInfo()) {
         size_t num_args = (*args_info).max_positional_args;
         if (num_args != 2) {
-          error.SetErrorStringWithFormat(
+          error = Status::FromErrorStringWithFormat(
               "Wrong number of args for "
               "handle_stop callback, should be 2 (excluding self), got: %zu",
               num_args);
@@ -345,15 +345,17 @@ PythonObject lldb_private::python::SWIGBridge::LLDBSwigPythonCreateScriptedStopH
         } else
           return result;
       } else {
-        error.SetErrorString("Couldn't get num arguments for handle_stop "
-                             "callback.");
+        error = Status::FromErrorString(
+            "Couldn't get num arguments for handle_stop "
+            "callback.");
         return PythonObject();
       }
       return result;
     } else {
-      error.SetErrorStringWithFormat("Class \"%s\" is missing the required "
-                                     "handle_stop callback.",
-                                     python_class_name);
+      error = Status::FromErrorStringWithFormat(
+          "Class \"%s\" is missing the required "
+          "handle_stop callback.",
+          python_class_name);
     }
   }
   return PythonObject();
diff --git a/lldb/include/lldb/Core/StructuredDataImpl.h b/lldb/include/lldb/Core/StructuredDataImpl.h
index 0e068b4598cdda..fd0a7b94d3a6cf 100644
--- a/lldb/include/lldb/Core/StructuredDataImpl.h
+++ b/lldb/include/lldb/Core/StructuredDataImpl.h
@@ -50,38 +50,28 @@ class StructuredDataImpl {
   }
 
   Status GetAsJSON(Stream &stream) const {
-    Status error;
-
-    if (!m_data_sp) {
-      error.SetErrorString("No structured data.");
-      return error;
-    }
+    if (!m_data_sp)
+      return Status::FromErrorString("No structured data.");
 
     llvm::json::OStream s(stream.AsRawOstream());
     m_data_sp->Serialize(s);
-    return error;
+    return Status();
   }
 
   Status GetDescription(Stream &stream) const {
-    Status error;
-
-    if (!m_data_sp) {
-      error.SetErrorString("Cannot pretty print structured data: "
-                           "no data to print.");
-      return error;
-    }
+    if (!m_data_sp)
+      return Status::FromErrorString("Cannot pretty print structured data: "
+                                     "no data to print.");
 
     // Grab the plugin
     lldb::StructuredDataPluginSP plugin_sp = m_plugin_wp.lock();
 
     // If there's no plugin, call underlying data's dump method:
     if (!plugin_sp) {
-      if (!m_data_sp) {
-        error.SetErrorString("No data to describe.");
-        return error;
-      }
+      if (!m_data_sp)
+        return Status::FromErrorString("No data to describe.");
       m_data_sp->GetDescription(stream);
-      return error;
+      return Status();
     }
     // Get the data's description.
     return plugin_sp->GetDescription(m_data_sp, stream);
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
index 3850edf879ac45..790229bf1b0639 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
@@ -48,7 +48,7 @@ class ScriptedInterface {
           llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
                       llvm::Twine(")"))
               .str();
-    error.SetErrorString(full_error_message);
+    error = Status(full_error_message);
     return {};
   }
 
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
index 7feaa01fe89b86..ac349de57c143d 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h
@@ -31,15 +31,18 @@ class ScriptedPlatformInterface : virtual public ScriptedInterface {
   }
 
   virtual Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) {
-    return Status("ScriptedPlatformInterface cannot attach to a process");
+    return Status::FromErrorString(
+        "ScriptedPlatformInterface cannot attach to a process");
   }
 
   virtual Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) {
-    return Status("ScriptedPlatformInterface cannot launch process");
+    return Status::FromErrorString(
+        "ScriptedPlatformInterface cannot launch process");
   }
 
   virtual Status KillProcess(lldb::pid_t pid) {
-    return Status("ScriptedPlatformInterface cannot kill process");
+    return Status::FromErrorString(
+        "ScriptedPlatformInterface cannot kill process");
   }
 };
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
index 10203b1f8baa7a..076ca43d451118 100644
--- a/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/Interfaces/ScriptedProcessInterface.h
@@ -29,23 +29,28 @@ class ScriptedProcessInterface : virtual public ScriptedInterface {
   virtual StructuredData::DictionarySP GetCapabilities() { return {}; }
 
   virtual Status Attach(const ProcessAttachInfo &attach_info) {
-    return Status("ScriptedProcess did not attach");
+    return Status::FromErrorString("ScriptedProcess did not attach");
   }
 
-  virtual Status Launch() { return Status("ScriptedProcess did not launch"); }
+  virtual Status Launch() {
+    return Status::FromErrorString("ScriptedProcess did not launch");
+  }
 
-  virtual Status Resume() { return Status("ScriptedProcess did not resume"); }
+  virtual Status Resume() {
+    return Status::FromErrorString("ScriptedProcess did not resume");
+  }
 
   virtual std::optional<MemoryRegionInfo>
   GetMemoryRegionContainingAddress(lldb::addr_t address, Status &error) {
-    error.SetErrorString("ScriptedProcess have no memory region.");
+    error = Status::FromErrorString("ScriptedProcess have no memory region.");
     return {};
   }
 
   virtual StructuredData::DictionarySP GetThreadsInfo() { return {}; }
 
   virtual bool CreateBreakpoint(lldb::addr_t addr, Status &error) {
-    error.SetErrorString("ScriptedProcess don't support creating breakpoints.");
+    error = Status::FromErrorString(
+        "ScriptedProcess don't support creating breakpoints.");
     return {};
   }
 
diff --git a/lldb/include/lldb/Interpreter/OptionValue.h b/lldb/include/lldb/Interpreter/OptionValue.h
index bfbdbead72c66d..d19c8b8fab6222 100644
--- a/lldb/include/lldb/Interpreter/OptionValue.h
+++ b/lldb/include/lldb/Interpreter/OptionValue.h
@@ -119,7 +119,8 @@ class OptionValue {
   virtual lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx,
                                           llvm::StringRef name,
                                           Status &error) const {
-    error.SetErrorStringWithFormatv("'{0}' is not a valid subvalue", name);
+    error = Status::FromErrorStringWithFormatv("'{0}' is not a valid subvalue",
+                                               name);
     return lldb::OptionValueSP();
   }
 
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
index 89a480a28880aa..addb1394ab5652 100644
--- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h
+++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h
@@ -176,25 +176,19 @@ class ScriptInterpreter : public PluginInterface {
   virtual Status ExecuteMultipleLines(
       const char *in_string,
       const ExecuteScriptOptions &options = ExecuteScriptOptions()) {
-    Status error;
-    error.SetErrorString("not implemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   virtual Status
   ExportFunctionDefinitionToInterpreter(StringList &function_def) {
-    Status error;
-    error.SetErrorString("not implemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   virtual Status GenerateBreakpointCommandCallbackData(StringList &input,
                                                        std::string &output,
                                                        bool has_extra_args,
                                                        bool is_callback) {
-    Status error;
-    error.SetErrorString("not implemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   virtual bool GenerateWatchpointCommandCallbackData(StringList &input,
@@ -280,8 +274,9 @@ class ScriptInterpreter : public PluginInterface {
   virtual StructuredData::GenericSP
   CreateScriptedStopHook(lldb::TargetSP target_sp, const char *class_name,
                          const StructuredDataImpl &args_data, Status &error) {
-    error.SetErrorString("Creating scripted stop-hooks with the current "
-                         "script interpreter is not supported.");
+    error =
+        Status::FromErrorString("Creating scripted stop-hooks with the current "
+                                "script interpreter is not supported.");
     return StructuredData::GenericSP();
   }
 
@@ -308,9 +303,7 @@ class ScriptInterpreter : public PluginInterface {
   virtual Status GenerateFunction(const char *signature,
                                   const StringList &input,
                                   bool is_callback) {
-    Status error;
-    error.SetErrorString("unimplemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   virtual void CollectDataForBreakpointCommandCallback(
@@ -329,18 +322,14 @@ class ScriptInterpreter : public PluginInterface {
   virtual Status SetBreakpointCommandCallback(BreakpointOptions &bp_options,
                                               const char *callback_text,
                                               bool is_callback) {
-    Status error;
-    error.SetErrorString("unimplemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   /// This one is for deserialization:
   virtual Status SetBreakpointCommandCallback(
       BreakpointOptions &bp_options,
       std::unique_ptr<BreakpointOptions::CommandData> &data_up) {
-    Status error;
-    error.SetErrorString("unimplemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   Status SetBreakpointCommandCallbackFunction(
@@ -352,9 +341,7 @@ class ScriptInterpreter : public PluginInterface {
   SetBreakpointCommandCallbackFunction(BreakpointOptions &bp_options,
                                        const char *function_name,
                                        StructuredData::ObjectSP extra_args_sp) {
-    Status error;
-    error.SetErrorString("unimplemented");
-    return error;
+    return Status::FromErrorString("not implemented");
   }
 
   /// Set a one-liner as the callback for the watchpoint.
@@ -453,33 +440,33 @@ class ScriptInterpreter : public PluginInterface {
   virtual bool RunScriptFormatKeyword(const char *impl_function,
                                       Process *process, std::string &output,
                                       Status &error) {
-    error.SetErrorString("unimplemented");
+    error = Status::FromErrorString("unimplemented");
     return false;
   }
 
   virtual bool RunScriptFormatKeyword(const char *impl_function, Thread *thread,
                                       std::string &output, Status &error) {
-    error.SetErrorString("unimplemented");
+    error = Status::FromErrorString("unimplemented");
     return false;
   }
 
   virtual bool RunScriptFormatKeyword(const char *impl_function, Target *target,
                                       std::string &output, Status &error) {
-    error.SetErrorString("unimplemented");
+    error = Status::FromErrorString("unimplemented");
     return false;
   }
 
   virtual bool RunScriptFormatKeyword(const char *impl_function,
                                       StackFrame *frame, std::string &output,
                                       Status &error) {
-    error.SetErrorString("unimplemented");
+    error = Status::FromErrorString("unimplemented");
     return false;
   }
 
   virtual bool RunScriptFormatKeyword(const char *impl_function,
                                       ValueObject *value, std::string &output,
                                       Status &error) {
-    error.SetErrorString("unimplemented");
+    error = Status::FromErrorString("unimplemented");
     return false;
   }
 
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 9cf6f50558570b..a7de991104434d 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -616,10 +616,8 @@ class Process : public std::enable_shared_from_this<Process>,
   virtual Status LoadCore();
 
   virtual Status DoLoadCore() {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support loading core files.", GetPluginName());
-    return error;
   }
 
   /// The "ShadowListener" for a process is just an ordinary Listener that
@@ -990,9 +988,7 @@ class Process : public std::enable_shared_from_this<Process>,
   /// \return
   ///     Returns an error object.
   virtual Status DoConnectRemote(llvm::StringRef remote_url) {
-    Status error;
-    error.SetErrorString("remote connections are not supported");
-    return error;
+    return Status::FromErrorString("remote connections are not supported");
   }
 
   /// Attach to an existing process using a process ID.
@@ -1011,11 +1007,9 @@ class Process : public std::enable_shared_from_this<Process>,
   /// hanming : need flag
   virtual Status DoAttachToProcessWithID(lldb::pid_t pid,
                                          const ProcessAttachInfo &attach_info) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support attaching to a process by pid",
         GetPluginName());
-    return error;
   }
 
   /// Attach to an existing process using a partial process name.
@@ -1034,9 +1028,7 @@ class Process : public std::enable_shared_from_this<Process>,
   virtual Status
   DoAttachToProcessWithName(const char *process_name,
                             const ProcessAttachInfo &attach_info) {
-    Status error;
-    error.SetErrorString("attach by name is not supported");
-    return error;
+    return Status::FromErrorString("attach by name is not supported");
   }
 
   /// Called after attaching a process.
@@ -1101,10 +1093,8 @@ class Process : public std::enable_shared_from_this<Process>,
   ///     An Status instance indicating success or failure of the
   ///     operation.
   virtual Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support launching processes", GetPluginName());
-    return error;
   }
 
   /// Called after launching a process.
@@ -1136,10 +1126,8 @@ class Process : public std::enable_shared_from_this<Process>,
   /// \see Thread:Step()
   /// \see Thread:Suspend()
   virtual Status DoResume() {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support resuming processes", GetPluginName());
-    return error;
   }
 
   /// Called after resuming a process.
@@ -1171,10 +1159,8 @@ class Process : public std::enable_shared_from_this<Process>,
   ///     Returns \b true if the process successfully halts, \b false
   ///     otherwise.
   virtual Status DoHalt(bool &caused_stop) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support halting processes", GetPluginName());
-    return error;
   }
 
   /// Called after halting a process.
@@ -1197,11 +1183,9 @@ class Process : public std::enable_shared_from_this<Process>,
   ///     Returns \b true if the process successfully detaches, \b
   ///     false otherwise.
   virtual Status DoDetach(bool keep_stopped) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support detaching from processes",
         GetPluginName());
-    return error;
   }
 
   /// Called after detaching from a process.
@@ -1228,11 +1212,9 @@ class Process : public std::enable_shared_from_this<Process>,
   /// \return
   ///     Returns an error object.
   virtual Status DoSignal(int signal) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support sending signals to processes",
         GetPluginName());
-    return error;
   }
 
   virtual Status WillDestroy() { return Status(); }
@@ -1686,7 +1668,7 @@ class Process : public std::enable_shared_from_this<Process>,
   ///     The number of bytes that were actually written.
   virtual size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
                                size_t size, Status &error) {
-    error.SetErrorStringWithFormatv(
+    error = Status::FromErrorStringWithFormatv(
         "error: {0} does not support writing to processes", GetPluginName());
     return 0;
   }
@@ -1769,7 +1751,7 @@ class Process : public std::enable_shared_from_this<Process>,
 
   virtual lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
                                         Status &error) {
-    error.SetErrorStringWithFormatv(
+    error = Status::FromErrorStringWithFormatv(
         "error: {0} does not support allocating in the debug process",
         GetPluginName());
     return LLDB_INVALID_ADDRESS;
@@ -2036,11 +2018,9 @@ class Process : public std::enable_shared_from_this<Process>,
   /// \return
   ///     \b true if the memory was deallocated, \b false otherwise.
   virtual Status DoDeallocateMemory(lldb::addr_t ptr) {
-    Status error;
-    error.SetErrorStringWithFormatv(
+    return Status::FromErrorStringWithFormatv(
         "error: {0} does not support deallocating in the debug process",
         GetPluginName());
-    return error;
   }
 
   /// The public interface to deallocating memory in the process.
@@ -2133,7 +2113,7 @@ class Process : public std::enable_shared_from_this<Process>,
   ///     less than \a buf_size, another call to this function should
   ///     be made to write the rest of the data.
   virtual size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) {
-    error.SetErrorString("stdin unsupported");
+    error = Status::FromErrorString("stdin unsupported");
     return 0;
   }
 
@@ -2156,17 +2136,13 @@ class Process : public std::enable_shared_from_this<Process>,
   size_t GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site);
 
   virtual Status EnableBreakpointSite(BreakpointSite *bp_site) {
-    Status error;
-    error.SetErrorStringW...
[truncated]

Copy link
Member

@medismailben medismailben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff! I think this is fine except for the python files.

Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry the assert will kill the LLDB library and cause issues. Can we add a temporary setting that can override this in case it does cause crashes? I really don't want LLDB crashing if we can help it. It will be hard to test all of the error code paths that can happen out in the wild

@labath
Copy link
Collaborator

labath commented Aug 27, 2024

I like this. I have just two remarks:

  • it might be better to split this into three steps (add new APIs, port to new APIs, remove old APIs), as that will make reverts easier/less disruptive (I don't know how much we can trust pre-commit CI these days, but I wouldn't be surprised if this breaks some platform-specific code).
  • since this seems like a perfect opportunity to bikesh^Wdiscuss the names, I'm going to ask if there's any appetite for shortening some of the new factory functions. Status::FromErrorStringWithFormatv is a bit of a mouthful, so I was thinking if we could use something shorter instead (Status::FromFormatv or even Status::Formatv) ?

@adrian-prantl
Copy link
Collaborator Author

I worry the assert will kill the LLDB library and cause issues. Can we add a temporary setting that can override this in case it does cause crashes? I really don't want LLDB crashing if we can help it. It will be hard to test all of the error code paths that can happen out in the wild

@clayborg When I say assert I had in mind something like this:

Status &Status::operator=() {
  assert(IsSuccess() && "dropping an error Status without checking first");
  #if NDEBUG
  if (!IsSuccess())
    Debugger::ReportWarning("dropping an error Status without checking first");
  #endif
  ...

So it would only "crash" in an asserts build, but otherwise keep working in production. Does that address you concern?
I'm also not planning to change the contract of the SBAPI. You'll still be able to modify SBError without triggering an assertion. It will check and log m_status under the hood.

@adrian-prantl
Copy link
Collaborator Author

I like this. I have just two remarks:

  • it might be better to split this into three steps (add new APIs, port to new APIs, remove old APIs), as that will make reverts easier/less disruptive (I don't know how much we can trust pre-commit CI these days, but I wouldn't be surprised if this breaks some platform-specific code).

From previous experience, I'm convinced that I'm going to break some platform-specific bots with this commit. I like the idea of only reverting the commit that removes the old API while that process is ongoing!

  • since this seems like a perfect opportunity to bikesh^Wdiscuss the names, I'm going to ask if there's any appetite for shortening some of the new factory functions. Status::FromErrorStringWithFormatv is a bit of a mouthful, so I was thinking if we could use something shorter instead (Status::FromFormatv or even Status::Formatv) ?

I picked these names, because they are in line with the old names, which made the regex replacement feasible. Renaming them afterwards is going to be easier.
My 2 cents on the naming: I had Status::FromFormatv in a previous iteration of this patch and changed my mind, because it doesn't indicate that this is going to be an error. What do you think about the slightly shorter Status::ErrorFromFromatv()?
Or, more radical, and potentially really confusing with LLVM code: rename lldb_private::Status to lldb_private::Error. I don't think I'd like that.

Copy link

github-actions bot commented Aug 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@adrian-prantl adrian-prantl force-pushed the status-valuetype branch 2 times, most recently from 000d1cf to 016a797 Compare August 27, 2024 16:15
@jimingham
Copy link
Collaborator

jimingham commented Aug 27, 2024 via email

@jimingham
Copy link
Collaborator

jimingham commented Aug 27, 2024 via email

@adrian-prantl adrian-prantl force-pushed the status-valuetype branch 3 times, most recently from f24793d to afd926c Compare August 27, 2024 17:13
@adrian-prantl
Copy link
Collaborator Author

Updated all the non-Darwin plugins. I believe to have addressed all outstanding comments now.

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed every single file but the ones I did look at look straightforward and correct. The changes to Status itself I feel positively about. I agree with the direction that this takes Status in.

@clayborg
Copy link
Collaborator

My concerns are addressed, thanks @adrian-prantl

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. It's something I've wanted since the first day I started working on LLDB. We've made a lot of progress in this direction so it's great to see that we've reached a point where we can make this actually happen.

@adrian-prantl adrian-prantl force-pushed the status-valuetype branch 2 times, most recently from 8c7cc31 to d9e2226 Compare August 27, 2024 17:54
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.
@adrian-prantl adrian-prantl merged commit 0642cd7 into llvm:main Aug 27, 2024
3 of 5 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 27, 2024

LLVM Buildbot has detected a new failure on builder llvm-x86_64-debian-dylib running on gribozavr4 while building lldb at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/6005

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
33.001 [1386/50/5533] Building CXX object unittests/Analysis/InlineAdvisorPlugin/CMakeFiles/InlineAdvisorPlugin.dir/InlineAdvisorPlugin.cpp.o
33.001 [1386/49/5534] Building CXX object unittests/Analysis/InlineOrderPlugin/CMakeFiles/InlineOrderPlugin.dir/InlineOrderPlugin.cpp.o
33.001 [1386/48/5535] Building CXX object unittests/Passes/Plugins/DoublerPlugin/CMakeFiles/DoublerPlugin.dir/DoublerPlugin.cpp.o
33.063 [1386/47/5536] Building CXX object tools/lldb/tools/lldb-instr/CMakeFiles/lldb-instr.dir/Instrument.cpp.o
33.620 [1386/46/5537] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/LockFileBase.cpp.o
33.624 [1386/45/5538] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/HostThread.cpp.o
33.720 [1386/44/5539] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/LockFilePosix.cpp.o
33.730 [1386/43/5540] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/HostThreadPosix.cpp.o
33.784 [1386/42/5541] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/linux/AbstractSocket.cpp.o
33.788 [1386/41/5542] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/SelectHelper.cpp.o
FAILED: tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/SelectHelper.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/source/Utility -I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Utility -I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/include -I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/include -I/b/1/llvm-x86_64-debian-dylib/build/include -I/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/include -I/b/1/llvm-x86_64-debian-dylib/llvm-project/llvm/../clang/include -I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/../clang/include -I/usr/include/libxml2 -I/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source -I/b/1/llvm-x86_64-debian-dylib/build/tools/lldb/source -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-deprecated-register -Wno-vla-extension -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/SelectHelper.cpp.o -MF tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/SelectHelper.cpp.o.d -o tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/SelectHelper.cpp.o -c /b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Utility/SelectHelper.cpp
/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/source/Utility/SelectHelper.cpp:115:11: error: use of undeclared identifier 'Status'; did you mean 'lldb_private::Status'?
          Status::FromErrorStringWithFormat("%i is too large for select()", fd);
          ^~~~~~
          lldb_private::Status
/b/1/llvm-x86_64-debian-dylib/llvm-project/lldb/include/lldb/Utility/Status.h:44:7: note: 'lldb_private::Status' declared here
class Status {
      ^
1 error generated.
33.834 [1386/40/5543] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/ThreadLauncher.cpp.o
33.842 [1386/39/5544] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PipeBase.cpp.o
33.849 [1386/38/5545] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/MainLoopBase.cpp.o
33.854 [1386/37/5546] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/StringExtractorGDBRemote.cpp.o
33.884 [1386/36/5547] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/DomainSocket.cpp.o
33.959 [1386/35/5548] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/NativeWatchpointList.cpp.o
34.043 [1386/34/5549] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/HostProcess.cpp.o
34.055 [1386/33/5550] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/Status.cpp.o
34.218 [1386/32/5551] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/UDPSocket.cpp.o
34.240 [1386/31/5552] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/HostNativeThreadBase.cpp.o
34.240 [1386/30/5553] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/Alarm.cpp.o
34.246 [1386/29/5554] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/PseudoTerminal.cpp.o
34.298 [1386/28/5555] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/ZipFileResolver.cpp.o
34.310 [1386/27/5556] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/FileSystemPosix.cpp.o
34.338 [1386/26/5557] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/FileCache.cpp.o
34.366 [1386/25/5558] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/RegisterValue.cpp.o
34.375 [1386/24/5559] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/MainLoopPosix.cpp.o
34.468 [1386/23/5560] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/Socket.cpp.o
34.481 [1386/22/5561] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/TCPSocket.cpp.o
34.490 [1386/21/5562] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/HostProcessPosix.cpp.o
34.671 [1386/20/5563] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/FileSystem.cpp.o
34.686 [1386/19/5564] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/StreamFile.cpp.o
34.690 [1386/18/5565] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/linux/HostInfoLinux.cpp.o
34.691 [1386/17/5566] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/NativeThreadProtocol.cpp.o
34.844 [1386/16/5567] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/posix/PipePosix.cpp.o
34.860 [1386/15/5568] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/Scalar.cpp.o
35.017 [1386/14/5569] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/NativeRegisterContext.cpp.o
35.089 [1386/13/5570] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/MonitoringProcessLauncher.cpp.o
35.107 [1386/12/5571] Building CXX object tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/File.cpp.o

@labath
Copy link
Collaborator

labath commented Aug 28, 2024

  • since this seems like a perfect opportunity to bikesh^Wdiscuss the names, I'm going to ask if there's any appetite for shortening some of the new factory functions. Status::FromErrorStringWithFormatv is a bit of a mouthful, so I was thinking if we could use something shorter instead (Status::FromFormatv or even Status::Formatv) ?

I picked these names, because they are in line with the old names, which made the regex replacement feasible. Renaming them afterwards is going to be easier. My 2 cents on the naming: I had Status::FromFormatv in a previous iteration of this patch and changed my mind, because it doesn't indicate that this is going to be an error. What do you think about the slightly shorter Status::ErrorFromFromatv()?

I think it's better (because its shorter), though it's still a bit long for my taste. FWIW, I don't find the short name at all confusing, because my mental model of these error types is (and all types I know behave that way) is that they have only one "success" value, and everything else represents some kind of an error/failure. So, when I see anything more complicated than Status() (or whatever the final API is for constructing success values), I immediately expect an error status.

I guess one difference is that I'm used to working with absl::Status (which I believe was zturner's inspiration for this name), so "status" feels just like a synonym for "error" to me. If you think having the word "error" in the name helps, I'd also be fine with Status::Errorf and Status::Errorv (for printf vs formatv styles) or something like that.

@adrian-prantl
Copy link
Collaborator Author

Thankfully this time around the renaming can actually be handled by sed since the different variants of constructors now have unique names. If we can come to a consensus on the right name I'm happy to land a follow-up patch doing that!

adrian-prantl added a commit to adrian-prantl/llvm-project that referenced this pull request Oct 11, 2024
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.

(cherry picked from commit 0642cd7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants