xref: /freebsd/contrib/llvm-project/lldb/include/lldb/API/SBError.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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 SBHostOS;
84   friend class SBPlatform;
85   friend class SBProcess;
86   friend class SBReproducer;
87   friend class SBStructuredData;
88   friend class SBTarget;
89   friend class SBThread;
90   friend class SBTrace;
91   friend class SBValue;
92   friend class SBValueList;
93   friend class SBWatchpoint;
94 
95   friend class lldb_private::ScriptInterpreter;
96   friend class lldb_private::python::SWIGBridge;
97 
98   SBError(const lldb_private::Status &error);
99 
100   lldb_private::Status *get();
101 
102   lldb_private::Status *operator->();
103 
104   const lldb_private::Status &operator*() const;
105 
106   lldb_private::Status &ref();
107 
108   void SetError(const lldb_private::Status &lldb_error);
109 
110 private:
111   std::unique_ptr<lldb_private::Status> m_opaque_up;
112 
113   void CreateIfNeeded();
114 };
115 
116 } // namespace lldb
117 
118 #endif // LLDB_API_SBERROR_H
119