/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBError.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- SBError.cpp -------------------------------------------------------===// |
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 | | #include "lldb/API/SBError.h" |
10 | | #include "Utils.h" |
11 | | #include "lldb/API/SBStream.h" |
12 | | #include "lldb/Utility/Instrumentation.h" |
13 | | #include "lldb/Utility/Status.h" |
14 | | |
15 | | #include <cstdarg> |
16 | | |
17 | | using namespace lldb; |
18 | | using namespace lldb_private; |
19 | | |
20 | 53.2k | SBError::SBError() { LLDB_INSTRUMENT_VA(this); } |
21 | | |
22 | 18.3k | SBError::SBError(const SBError &rhs) { |
23 | 18.3k | LLDB_INSTRUMENT_VA(this, rhs); |
24 | | |
25 | 18.3k | m_opaque_up = clone(rhs.m_opaque_up); |
26 | 18.3k | } |
27 | | |
28 | 2 | SBError::SBError(const char *message) { |
29 | 2 | LLDB_INSTRUMENT_VA(this, message); |
30 | | |
31 | 2 | SetErrorString(message); |
32 | 2 | } |
33 | | |
34 | | SBError::SBError(const lldb_private::Status &status) |
35 | 12 | : m_opaque_up(new Status(status)) { |
36 | 12 | LLDB_INSTRUMENT_VA(this, status); |
37 | 12 | } |
38 | | |
39 | 71.5k | SBError::~SBError() = default; |
40 | | |
41 | 18.6k | const SBError &SBError::operator=(const SBError &rhs) { |
42 | 18.6k | LLDB_INSTRUMENT_VA(this, rhs); |
43 | | |
44 | 18.6k | if (this != &rhs) |
45 | 18.6k | m_opaque_up = clone(rhs.m_opaque_up); |
46 | 18.6k | return *this; |
47 | 18.6k | } |
48 | | |
49 | 1.80k | const char *SBError::GetCString() const { |
50 | 1.80k | LLDB_INSTRUMENT_VA(this); |
51 | | |
52 | 1.80k | if (m_opaque_up) |
53 | 1.80k | return m_opaque_up->AsCString(); |
54 | 1 | return nullptr; |
55 | 1.80k | } |
56 | | |
57 | 172 | void SBError::Clear() { |
58 | 172 | LLDB_INSTRUMENT_VA(this); |
59 | | |
60 | 172 | if (m_opaque_up) |
61 | 6 | m_opaque_up->Clear(); |
62 | 172 | } |
63 | | |
64 | 8.71k | bool SBError::Fail() const { |
65 | 8.71k | LLDB_INSTRUMENT_VA(this); |
66 | | |
67 | 8.71k | bool ret_value = false; |
68 | 8.71k | if (m_opaque_up) |
69 | 2.11k | ret_value = m_opaque_up->Fail(); |
70 | | |
71 | | |
72 | 8.71k | return ret_value; |
73 | 8.71k | } |
74 | | |
75 | 18.6k | bool SBError::Success() const { |
76 | 18.6k | LLDB_INSTRUMENT_VA(this); |
77 | | |
78 | 18.6k | bool ret_value = true; |
79 | 18.6k | if (m_opaque_up) |
80 | 18.3k | ret_value = m_opaque_up->Success(); |
81 | | |
82 | 18.6k | return ret_value; |
83 | 18.6k | } |
84 | | |
85 | 1 | uint32_t SBError::GetError() const { |
86 | 1 | LLDB_INSTRUMENT_VA(this); |
87 | | |
88 | 1 | uint32_t err = 0; |
89 | 1 | if (m_opaque_up) |
90 | 0 | err = m_opaque_up->GetError(); |
91 | | |
92 | | |
93 | 1 | return err; |
94 | 1 | } |
95 | | |
96 | 2 | ErrorType SBError::GetType() const { |
97 | 2 | LLDB_INSTRUMENT_VA(this); |
98 | | |
99 | 2 | ErrorType err_type = eErrorTypeInvalid; |
100 | 2 | if (m_opaque_up) |
101 | 1 | err_type = m_opaque_up->GetType(); |
102 | | |
103 | 2 | return err_type; |
104 | 2 | } |
105 | | |
106 | 1 | void SBError::SetError(uint32_t err, ErrorType type) { |
107 | 1 | LLDB_INSTRUMENT_VA(this, err, type); |
108 | | |
109 | 1 | CreateIfNeeded(); |
110 | 1 | m_opaque_up->SetError(err, type); |
111 | 1 | } |
112 | | |
113 | 20.1k | void SBError::SetError(const Status &lldb_error) { |
114 | 20.1k | CreateIfNeeded(); |
115 | 20.1k | *m_opaque_up = lldb_error; |
116 | 20.1k | } |
117 | | |
118 | 1 | void SBError::SetErrorToErrno() { |
119 | 1 | LLDB_INSTRUMENT_VA(this); |
120 | | |
121 | 1 | CreateIfNeeded(); |
122 | 1 | m_opaque_up->SetErrorToErrno(); |
123 | 1 | } |
124 | | |
125 | 2 | void SBError::SetErrorToGenericError() { |
126 | 2 | LLDB_INSTRUMENT_VA(this); |
127 | | |
128 | 2 | CreateIfNeeded(); |
129 | 2 | m_opaque_up->SetErrorToGenericError(); |
130 | 2 | } |
131 | | |
132 | 76 | void SBError::SetErrorString(const char *err_str) { |
133 | 76 | LLDB_INSTRUMENT_VA(this, err_str); |
134 | | |
135 | 76 | CreateIfNeeded(); |
136 | 76 | m_opaque_up->SetErrorString(err_str); |
137 | 76 | } |
138 | | |
139 | 51 | int SBError::SetErrorStringWithFormat(const char *format, ...) { |
140 | 51 | CreateIfNeeded(); |
141 | 51 | va_list args; |
142 | 51 | va_start(args, format); |
143 | 51 | int num_chars = m_opaque_up->SetErrorStringWithVarArg(format, args); |
144 | 51 | va_end(args); |
145 | 51 | return num_chars; |
146 | 51 | } |
147 | | |
148 | 0 | bool SBError::IsValid() const { |
149 | 0 | LLDB_INSTRUMENT_VA(this); |
150 | 0 | return this->operator bool(); |
151 | 0 | } |
152 | 2 | SBError::operator bool() const { |
153 | 2 | LLDB_INSTRUMENT_VA(this); |
154 | | |
155 | 2 | return m_opaque_up != nullptr; |
156 | 2 | } |
157 | | |
158 | 22.7k | void SBError::CreateIfNeeded() { |
159 | 22.7k | if (m_opaque_up == nullptr) |
160 | 22.6k | m_opaque_up = std::make_unique<Status>(); |
161 | 22.7k | } |
162 | | |
163 | 0 | lldb_private::Status *SBError::operator->() { return m_opaque_up.get(); } |
164 | | |
165 | 0 | lldb_private::Status *SBError::get() { return m_opaque_up.get(); } |
166 | | |
167 | 2.46k | lldb_private::Status &SBError::ref() { |
168 | 2.46k | CreateIfNeeded(); |
169 | 2.46k | return *m_opaque_up; |
170 | 2.46k | } |
171 | | |
172 | 0 | const lldb_private::Status &SBError::operator*() const { |
173 | | // Be sure to call "IsValid()" before calling this function or it will crash |
174 | 0 | return *m_opaque_up; |
175 | 0 | } |
176 | | |
177 | 2.12k | bool SBError::GetDescription(SBStream &description) { |
178 | 2.12k | LLDB_INSTRUMENT_VA(this, description); |
179 | | |
180 | 2.12k | if (m_opaque_up) { |
181 | 2.12k | if (m_opaque_up->Success()) |
182 | 2.09k | description.Printf("success"); |
183 | 22 | else { |
184 | 22 | const char *err_string = GetCString(); |
185 | 22 | description.Printf("error: %s", |
186 | 22 | (err_string != nullptr ? err_string : ""0 )); |
187 | 22 | } |
188 | 2.12k | } else |
189 | 1 | description.Printf("error: <NULL>"); |
190 | | |
191 | 2.12k | return true; |
192 | 2.12k | } |