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 python {
17 class SWIGBridge;
18 }
19 } // namespace lldb_private
20 
21 namespace lldb {
22 
23 class LLDB_API SBError {
24 public:
25   SBError();
26 
27   SBError(const lldb::SBError &rhs);
28 
29   SBError(const char *message);
30 
31   ~SBError();
32 
33   const SBError &operator=(const lldb::SBError &rhs);
34 
35   /// Get the error string as a NULL terminated UTF8 c-string.
36   ///
37   /// This SBError object owns the returned string and this object must be kept
38   /// around long enough to use the returned string.
39   const char *GetCString() const;
40 
41   void Clear();
42 
43   bool Fail() const;
44 
45   bool Success() const;
46 
47   uint32_t GetError() const;
48 
49   lldb::ErrorType GetType() const;
50 
51   void SetError(uint32_t err, lldb::ErrorType type);
52 
53   void SetErrorToErrno();
54 
55   void SetErrorToGenericError();
56 
57   void SetErrorString(const char *err_str);
58 
59 #ifndef SWIG
60   __attribute__((format(printf, 2, 3)))
61 #else
62   // clang-format off
63   %varargs(3, char *str = NULL) SetErrorStringWithFormat;
64   // clang-format on
65 #endif
66   int SetErrorStringWithFormat(const char *format, ...);
67 
68   explicit operator bool() const;
69 
70   bool IsValid() const;
71 
72   bool GetDescription(lldb::SBStream &description);
73 
74 protected:
75   friend class SBBreakpoint;
76   friend class SBBreakpointLocation;
77   friend class SBBreakpointName;
78   friend class SBCommandReturnObject;
79   friend class SBCommunication;
80   friend class SBData;
81   friend class SBDebugger;
82   friend class SBFile;
83   friend class SBFormat;
84   friend class SBHostOS;
85   friend class SBPlatform;
86   friend class SBProcess;
87   friend class SBReproducer;
88   friend class SBStructuredData;
89   friend class SBTarget;
90   friend class SBThread;
91   friend class SBTrace;
92   friend class SBValue;
93   friend class SBValueList;
94   friend class SBWatchpoint;
95 
96   friend class lldb_private::ScriptInterpreter;
97   friend class lldb_private::python::SWIGBridge;
98 
99   SBError(const lldb_private::Status &error);
100 
101   lldb_private::Status *get();
102 
103   lldb_private::Status *operator->();
104 
105   const lldb_private::Status &operator*() const;
106 
107   lldb_private::Status &ref();
108 
109   void SetError(const lldb_private::Status &lldb_error);
110 
111 private:
112   std::unique_ptr<lldb_private::Status> m_opaque_up;
113 
114   void CreateIfNeeded();
115 };
116 
117 } // namespace lldb
118 
119 #endif // LLDB_API_SBERROR_H
120