xref: /llvm-project/lldb/include/lldb/API/SBError.h (revision d9cc37fea7b02954079ca59e8f7f28cffacc7e9e)
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   /// Get the error code.
48   uint32_t GetError() const;
49 
50   /// Get the error in machine-readable form. Particularly useful for
51   /// compiler diagnostics.
52   SBStructuredData GetErrorData() const;
53 
54   lldb::ErrorType GetType() const;
55 
56   void SetError(uint32_t err, lldb::ErrorType type);
57 
58   void SetErrorToErrno();
59 
60   void SetErrorToGenericError();
61 
62   void SetErrorString(const char *err_str);
63 
64 #ifndef SWIG
65   __attribute__((format(printf, 2, 3)))
66 #else
67   // clang-format off
68   %varargs(3, char *str = NULL) SetErrorStringWithFormat;
69   // clang-format on
70 #endif
71   int SetErrorStringWithFormat(const char *format, ...);
72 
73   explicit operator bool() const;
74 
75   bool IsValid() const;
76 
77   bool GetDescription(lldb::SBStream &description);
78 
79 protected:
80   friend class SBBreakpoint;
81   friend class SBBreakpointLocation;
82   friend class SBBreakpointName;
83   friend class SBCommandReturnObject;
84   friend class SBCommunication;
85   friend class SBSaveCoreOptions;
86   friend class SBData;
87   friend class SBDebugger;
88   friend class SBFile;
89   friend class SBFormat;
90   friend class SBHostOS;
91   friend class SBPlatform;
92   friend class SBProcess;
93   friend class SBReproducer;
94   friend class SBStructuredData;
95   friend class SBTarget;
96   friend class SBThread;
97   friend class SBTrace;
98   friend class SBValue;
99   friend class SBValueList;
100   friend class SBWatchpoint;
101 
102   friend class lldb_private::ScriptInterpreter;
103   friend class lldb_private::python::SWIGBridge;
104 
105   SBError(lldb_private::Status &&error);
106 
107   lldb_private::Status *get();
108 
109   lldb_private::Status *operator->();
110 
111   const lldb_private::Status &operator*() const;
112 
113   lldb_private::Status &ref();
114 
115   void SetError(lldb_private::Status &&lldb_error);
116 
117 private:
118   std::unique_ptr<lldb_private::Status> m_opaque_up;
119 
120   void CreateIfNeeded();
121 };
122 
123 } // namespace lldb
124 
125 #endif // LLDB_API_SBERROR_H
126