1 //===-- SBError.h -----------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_API_SBERROR_H 10 #define LLDB_API_SBERROR_H 11 12 #include "lldb/API/SBDefines.h" 13 14 namespace lldb_private { 15 class ScriptInterpreter; 16 } // namespace lldb_private 17 18 namespace lldb { 19 20 class LLDB_API SBError { 21 public: 22 SBError(); 23 24 SBError(const lldb::SBError &rhs); 25 26 SBError(const lldb_private::Status &error); 27 28 ~SBError(); 29 30 const SBError &operator=(const lldb::SBError &rhs); 31 32 /// Get the error string as a NULL terminated UTF8 c-string. 33 /// 34 /// This SBError object owns the returned string and this object must be kept 35 /// around long enough to use the returned string. 36 const char *GetCString() const; 37 38 void Clear(); 39 40 bool Fail() const; 41 42 bool Success() const; 43 44 uint32_t GetError() const; 45 46 lldb::ErrorType GetType() const; 47 48 void SetError(uint32_t err, lldb::ErrorType type); 49 50 void SetErrorToErrno(); 51 52 void SetErrorToGenericError(); 53 54 void SetErrorString(const char *err_str); 55 56 int SetErrorStringWithFormat(const char *format, ...) 57 __attribute__((format(printf, 2, 3))); 58 59 explicit operator bool() const; 60 61 bool IsValid() const; 62 63 bool GetDescription(lldb::SBStream &description); 64 65 protected: 66 friend class SBBreakpoint; 67 friend class SBBreakpointLocation; 68 friend class SBBreakpointName; 69 friend class SBCommandReturnObject; 70 friend class SBCommunication; 71 friend class SBData; 72 friend class SBDebugger; 73 friend class SBFile; 74 friend class SBHostOS; 75 friend class SBPlatform; 76 friend class SBProcess; 77 friend class SBReproducer; 78 friend class SBStructuredData; 79 friend class SBTarget; 80 friend class SBThread; 81 friend class SBTrace; 82 friend class SBValue; 83 friend class SBValueList; 84 friend class SBWatchpoint; 85 86 friend class lldb_private::ScriptInterpreter; 87 88 lldb_private::Status *get(); 89 90 lldb_private::Status *operator->(); 91 92 const lldb_private::Status &operator*() const; 93 94 lldb_private::Status &ref(); 95 96 void SetError(const lldb_private::Status &lldb_error); 97 98 private: 99 std::unique_ptr<lldb_private::Status> m_opaque_up; 100 101 void CreateIfNeeded(); 102 }; 103 104 } // namespace lldb 105 106 #endif // LLDB_API_SBERROR_H 107