1*6777b538SAndroid Build Coastguard Worker // Copyright 2020 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_CHECK_H_
6*6777b538SAndroid Build Coastguard Worker #define BASE_CHECK_H_
7*6777b538SAndroid Build Coastguard Worker
8*6777b538SAndroid Build Coastguard Worker #include <iosfwd>
9*6777b538SAndroid Build Coastguard Worker #include <memory>
10*6777b538SAndroid Build Coastguard Worker
11*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h"
12*6777b538SAndroid Build Coastguard Worker #include "base/compiler_specific.h"
13*6777b538SAndroid Build Coastguard Worker #include "base/dcheck_is_on.h"
14*6777b538SAndroid Build Coastguard Worker #include "base/immediate_crash.h"
15*6777b538SAndroid Build Coastguard Worker #include "base/location.h"
16*6777b538SAndroid Build Coastguard Worker #include "base/macros/if.h"
17*6777b538SAndroid Build Coastguard Worker #include "base/macros/is_empty.h"
18*6777b538SAndroid Build Coastguard Worker #include "base/memory/raw_ptr.h"
19*6777b538SAndroid Build Coastguard Worker #include "base/not_fatal_until.h"
20*6777b538SAndroid Build Coastguard Worker
21*6777b538SAndroid Build Coastguard Worker // This header defines the CHECK, DCHECK, and DPCHECK macros.
22*6777b538SAndroid Build Coastguard Worker //
23*6777b538SAndroid Build Coastguard Worker // CHECK dies with a fatal error if its condition is not true. It is not
24*6777b538SAndroid Build Coastguard Worker // controlled by NDEBUG, so the check will be executed regardless of compilation
25*6777b538SAndroid Build Coastguard Worker // mode.
26*6777b538SAndroid Build Coastguard Worker //
27*6777b538SAndroid Build Coastguard Worker // DCHECK, the "debug mode" check, is enabled depending on NDEBUG and
28*6777b538SAndroid Build Coastguard Worker // DCHECK_ALWAYS_ON, and its severity depends on DCHECK_IS_CONFIGURABLE.
29*6777b538SAndroid Build Coastguard Worker //
30*6777b538SAndroid Build Coastguard Worker // (D)PCHECK is like (D)CHECK, but includes the system error code (c.f.
31*6777b538SAndroid Build Coastguard Worker // perror(3)).
32*6777b538SAndroid Build Coastguard Worker //
33*6777b538SAndroid Build Coastguard Worker // Additional information can be streamed to these macros and will be included
34*6777b538SAndroid Build Coastguard Worker // in the log output if the condition doesn't hold (you may need to include
35*6777b538SAndroid Build Coastguard Worker // <ostream>):
36*6777b538SAndroid Build Coastguard Worker //
37*6777b538SAndroid Build Coastguard Worker // CHECK(condition) << "Additional info.";
38*6777b538SAndroid Build Coastguard Worker //
39*6777b538SAndroid Build Coastguard Worker // The condition is evaluated exactly once. Even in build modes where e.g.
40*6777b538SAndroid Build Coastguard Worker // DCHECK is disabled, the condition and any stream arguments are still
41*6777b538SAndroid Build Coastguard Worker // referenced to avoid warnings about unused variables and functions.
42*6777b538SAndroid Build Coastguard Worker //
43*6777b538SAndroid Build Coastguard Worker // An optional base::NotFatalUntil argument can be provided to make the
44*6777b538SAndroid Build Coastguard Worker // instance non-fatal (dumps without crashing) before a provided milestone. That
45*6777b538SAndroid Build Coastguard Worker // is: CHECK(false, base::NotFatalUntil::M120); starts crashing in M120. CHECKs
46*6777b538SAndroid Build Coastguard Worker // with a milestone argument preserve logging even in official builds, and
47*6777b538SAndroid Build Coastguard Worker // will upload the CHECK's log message in crash reports for remote diagnostics.
48*6777b538SAndroid Build Coastguard Worker // This is recommended for use in situations that are not flag guarded, or where
49*6777b538SAndroid Build Coastguard Worker // we have low pre-stable coverage. Using this lets us probe for would-be CHECK
50*6777b538SAndroid Build Coastguard Worker // failures for a milestone or two before rolling out a CHECK.
51*6777b538SAndroid Build Coastguard Worker //
52*6777b538SAndroid Build Coastguard Worker // For the (D)CHECK_EQ, etc. macros, see base/check_op.h. However, that header
53*6777b538SAndroid Build Coastguard Worker // is *significantly* larger than check.h, so try to avoid including it in
54*6777b538SAndroid Build Coastguard Worker // header files.
55*6777b538SAndroid Build Coastguard Worker
56*6777b538SAndroid Build Coastguard Worker namespace logging {
57*6777b538SAndroid Build Coastguard Worker
58*6777b538SAndroid Build Coastguard Worker // Class used to explicitly ignore an ostream, and optionally a boolean value.
59*6777b538SAndroid Build Coastguard Worker class VoidifyStream {
60*6777b538SAndroid Build Coastguard Worker public:
61*6777b538SAndroid Build Coastguard Worker VoidifyStream() = default;
VoidifyStream(bool)62*6777b538SAndroid Build Coastguard Worker explicit VoidifyStream(bool) {}
63*6777b538SAndroid Build Coastguard Worker
64*6777b538SAndroid Build Coastguard Worker // Binary & has lower precedence than << but higher than ?:
65*6777b538SAndroid Build Coastguard Worker void operator&(std::ostream&) {}
66*6777b538SAndroid Build Coastguard Worker };
67*6777b538SAndroid Build Coastguard Worker
68*6777b538SAndroid Build Coastguard Worker // Macro which uses but does not evaluate expr and any stream parameters.
69*6777b538SAndroid Build Coastguard Worker #define EAT_CHECK_STREAM_PARAMS(expr) \
70*6777b538SAndroid Build Coastguard Worker true ? (void)0 \
71*6777b538SAndroid Build Coastguard Worker : ::logging::VoidifyStream(expr) & (*::logging::g_swallow_stream)
72*6777b538SAndroid Build Coastguard Worker BASE_EXPORT extern std::ostream* g_swallow_stream;
73*6777b538SAndroid Build Coastguard Worker
74*6777b538SAndroid Build Coastguard Worker class LogMessage;
75*6777b538SAndroid Build Coastguard Worker
76*6777b538SAndroid Build Coastguard Worker // Class used for raising a check error upon destruction.
77*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT CheckError {
78*6777b538SAndroid Build Coastguard Worker public:
79*6777b538SAndroid Build Coastguard Worker static CheckError Check(
80*6777b538SAndroid Build Coastguard Worker const char* condition,
81*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil fatal_milestone =
82*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil::NoSpecifiedMilestoneInternal,
83*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
84*6777b538SAndroid Build Coastguard Worker // Takes ownership over (free()s after using) `log_message_str`, for use with
85*6777b538SAndroid Build Coastguard Worker // CHECK_op macros.
86*6777b538SAndroid Build Coastguard Worker static CheckError CheckOp(
87*6777b538SAndroid Build Coastguard Worker char* log_message_str,
88*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil fatal_milestone =
89*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil::NoSpecifiedMilestoneInternal,
90*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
91*6777b538SAndroid Build Coastguard Worker
92*6777b538SAndroid Build Coastguard Worker static CheckError DCheck(
93*6777b538SAndroid Build Coastguard Worker const char* condition,
94*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
95*6777b538SAndroid Build Coastguard Worker // Takes ownership over (free()s after using) `log_message_str`, for use with
96*6777b538SAndroid Build Coastguard Worker // DCHECK_op macros.
97*6777b538SAndroid Build Coastguard Worker static CheckError DCheckOp(
98*6777b538SAndroid Build Coastguard Worker char* log_message_str,
99*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
100*6777b538SAndroid Build Coastguard Worker
101*6777b538SAndroid Build Coastguard Worker static CheckError DumpWillBeCheck(
102*6777b538SAndroid Build Coastguard Worker const char* condition,
103*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
104*6777b538SAndroid Build Coastguard Worker // Takes ownership over (free()s after using) `log_message_str`, for use with
105*6777b538SAndroid Build Coastguard Worker // DUMP_WILL_BE_CHECK_op macros.
106*6777b538SAndroid Build Coastguard Worker static CheckError DumpWillBeCheckOp(
107*6777b538SAndroid Build Coastguard Worker char* log_message_str,
108*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
109*6777b538SAndroid Build Coastguard Worker
110*6777b538SAndroid Build Coastguard Worker static CheckError PCheck(
111*6777b538SAndroid Build Coastguard Worker const char* condition,
112*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
113*6777b538SAndroid Build Coastguard Worker static CheckError PCheck(
114*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
115*6777b538SAndroid Build Coastguard Worker
116*6777b538SAndroid Build Coastguard Worker static CheckError DPCheck(
117*6777b538SAndroid Build Coastguard Worker const char* condition,
118*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
119*6777b538SAndroid Build Coastguard Worker
120*6777b538SAndroid Build Coastguard Worker static CheckError DumpWillBeNotReachedNoreturn(
121*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
122*6777b538SAndroid Build Coastguard Worker
123*6777b538SAndroid Build Coastguard Worker static CheckError NotImplemented(
124*6777b538SAndroid Build Coastguard Worker const char* function,
125*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
126*6777b538SAndroid Build Coastguard Worker
127*6777b538SAndroid Build Coastguard Worker // Stream for adding optional details to the error message.
128*6777b538SAndroid Build Coastguard Worker std::ostream& stream();
129*6777b538SAndroid Build Coastguard Worker
130*6777b538SAndroid Build Coastguard Worker // Try really hard to get the call site and callee as separate stack frames in
131*6777b538SAndroid Build Coastguard Worker // crash reports.
132*6777b538SAndroid Build Coastguard Worker NOMERGE NOINLINE NOT_TAIL_CALLED ~CheckError();
133*6777b538SAndroid Build Coastguard Worker
134*6777b538SAndroid Build Coastguard Worker CheckError(const CheckError&) = delete;
135*6777b538SAndroid Build Coastguard Worker CheckError& operator=(const CheckError&) = delete;
136*6777b538SAndroid Build Coastguard Worker
137*6777b538SAndroid Build Coastguard Worker template <typename T>
138*6777b538SAndroid Build Coastguard Worker std::ostream& operator<<(T&& streamed_type) {
139*6777b538SAndroid Build Coastguard Worker return stream() << streamed_type;
140*6777b538SAndroid Build Coastguard Worker }
141*6777b538SAndroid Build Coastguard Worker
142*6777b538SAndroid Build Coastguard Worker protected:
143*6777b538SAndroid Build Coastguard Worker // Takes ownership of `log_message`.
144*6777b538SAndroid Build Coastguard Worker explicit CheckError(LogMessage* log_message);
145*6777b538SAndroid Build Coastguard Worker
146*6777b538SAndroid Build Coastguard Worker std::unique_ptr<LogMessage> log_message_;
147*6777b538SAndroid Build Coastguard Worker };
148*6777b538SAndroid Build Coastguard Worker
149*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT NotReachedError : public CheckError {
150*6777b538SAndroid Build Coastguard Worker public:
151*6777b538SAndroid Build Coastguard Worker static NotReachedError NotReached(
152*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil fatal_milestone =
153*6777b538SAndroid Build Coastguard Worker base::NotFatalUntil::NoSpecifiedMilestoneInternal,
154*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
155*6777b538SAndroid Build Coastguard Worker
156*6777b538SAndroid Build Coastguard Worker // Used to trigger a NOTREACHED() without providing file or line while also
157*6777b538SAndroid Build Coastguard Worker // discarding log-stream arguments. See base/notreached.h.
158*6777b538SAndroid Build Coastguard Worker NOMERGE NOINLINE NOT_TAIL_CALLED static void TriggerNotReached();
159*6777b538SAndroid Build Coastguard Worker
160*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/851128): Mark [[noreturn]] once this is CHECK-fatal on all
161*6777b538SAndroid Build Coastguard Worker // builds.
162*6777b538SAndroid Build Coastguard Worker NOMERGE NOINLINE NOT_TAIL_CALLED ~NotReachedError();
163*6777b538SAndroid Build Coastguard Worker
164*6777b538SAndroid Build Coastguard Worker private:
165*6777b538SAndroid Build Coastguard Worker using CheckError::CheckError;
166*6777b538SAndroid Build Coastguard Worker };
167*6777b538SAndroid Build Coastguard Worker
168*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/851128): This should take the name of the above class once all
169*6777b538SAndroid Build Coastguard Worker // callers of NOTREACHED() have migrated to the CHECK-fatal version.
170*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT NotReachedNoreturnError : public CheckError {
171*6777b538SAndroid Build Coastguard Worker public:
172*6777b538SAndroid Build Coastguard Worker explicit NotReachedNoreturnError(
173*6777b538SAndroid Build Coastguard Worker const base::Location& location = base::Location::Current());
174*6777b538SAndroid Build Coastguard Worker
175*6777b538SAndroid Build Coastguard Worker [[noreturn]] NOMERGE NOINLINE NOT_TAIL_CALLED ~NotReachedNoreturnError();
176*6777b538SAndroid Build Coastguard Worker };
177*6777b538SAndroid Build Coastguard Worker
178*6777b538SAndroid Build Coastguard Worker // A helper macro for checks that log to streams that makes it easier for the
179*6777b538SAndroid Build Coastguard Worker // compiler to identify and warn about dead code, e.g.:
180*6777b538SAndroid Build Coastguard Worker //
181*6777b538SAndroid Build Coastguard Worker // return 2;
182*6777b538SAndroid Build Coastguard Worker // NOTREACHED();
183*6777b538SAndroid Build Coastguard Worker //
184*6777b538SAndroid Build Coastguard Worker // The 'switch' is used to prevent the 'else' from being ambiguous when the
185*6777b538SAndroid Build Coastguard Worker // macro is used in an 'if' clause such as:
186*6777b538SAndroid Build Coastguard Worker // if (a == 1)
187*6777b538SAndroid Build Coastguard Worker // CHECK(Foo());
188*6777b538SAndroid Build Coastguard Worker //
189*6777b538SAndroid Build Coastguard Worker // TODO(crbug.com/1380930): Remove the const bool when the blink-gc plugin has
190*6777b538SAndroid Build Coastguard Worker // been updated to accept `if (LIKELY(!field_))` as well as `if (!field_)`.
191*6777b538SAndroid Build Coastguard Worker #define LOGGING_CHECK_FUNCTION_IMPL(check_stream, condition) \
192*6777b538SAndroid Build Coastguard Worker switch (0) \
193*6777b538SAndroid Build Coastguard Worker case 0: \
194*6777b538SAndroid Build Coastguard Worker default: \
195*6777b538SAndroid Build Coastguard Worker /* Hint to the optimizer that `condition` is unlikely to be false. */ \
196*6777b538SAndroid Build Coastguard Worker /* The optimizer can use this as a hint to place the failure path */ \
197*6777b538SAndroid Build Coastguard Worker /* out-of-line, e.g. at the tail of the function. */ \
198*6777b538SAndroid Build Coastguard Worker if (const bool probably_true = static_cast<bool>(condition); \
199*6777b538SAndroid Build Coastguard Worker LIKELY(ANALYZER_ASSUME_TRUE(probably_true))) \
200*6777b538SAndroid Build Coastguard Worker ; \
201*6777b538SAndroid Build Coastguard Worker else \
202*6777b538SAndroid Build Coastguard Worker (check_stream)
203*6777b538SAndroid Build Coastguard Worker
204*6777b538SAndroid Build Coastguard Worker #if defined(OFFICIAL_BUILD) && !defined(NDEBUG)
205*6777b538SAndroid Build Coastguard Worker #error "Debug builds are not expected to be optimized as official builds."
206*6777b538SAndroid Build Coastguard Worker #endif // defined(OFFICIAL_BUILD) && !defined(NDEBUG)
207*6777b538SAndroid Build Coastguard Worker
208*6777b538SAndroid Build Coastguard Worker #if defined(OFFICIAL_BUILD) && !DCHECK_IS_ON()
209*6777b538SAndroid Build Coastguard Worker // Note that this uses IMMEDIATE_CRASH_ALWAYS_INLINE to force-inline in debug
210*6777b538SAndroid Build Coastguard Worker // mode as well. See LoggingTest.CheckCausesDistinctBreakpoints.
CheckFailure()211*6777b538SAndroid Build Coastguard Worker [[noreturn]] IMMEDIATE_CRASH_ALWAYS_INLINE void CheckFailure() {
212*6777b538SAndroid Build Coastguard Worker base::ImmediateCrash();
213*6777b538SAndroid Build Coastguard Worker }
214*6777b538SAndroid Build Coastguard Worker
215*6777b538SAndroid Build Coastguard Worker // Discard log strings to reduce code bloat when there is no NotFatalUntil
216*6777b538SAndroid Build Coastguard Worker // argument (which temporarily preserves logging both locally and in crash
217*6777b538SAndroid Build Coastguard Worker // reports).
218*6777b538SAndroid Build Coastguard Worker //
219*6777b538SAndroid Build Coastguard Worker // This is not calling BreakDebugger since this is called frequently, and
220*6777b538SAndroid Build Coastguard Worker // calling an out-of-line function instead of a noreturn inline macro prevents
221*6777b538SAndroid Build Coastguard Worker // compiler optimizations. Unlike the other check macros, this one does not use
222*6777b538SAndroid Build Coastguard Worker // LOGGING_CHECK_FUNCTION_IMPL(), since it is incompatible with
223*6777b538SAndroid Build Coastguard Worker // EAT_CHECK_STREAM_PARAMETERS().
224*6777b538SAndroid Build Coastguard Worker #define CHECK(condition, ...) \
225*6777b538SAndroid Build Coastguard Worker BASE_IF(BASE_IS_EMPTY(__VA_ARGS__), \
226*6777b538SAndroid Build Coastguard Worker UNLIKELY(!(condition)) ? logging::CheckFailure() \
227*6777b538SAndroid Build Coastguard Worker : EAT_CHECK_STREAM_PARAMS(), \
228*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL( \
229*6777b538SAndroid Build Coastguard Worker logging::CheckError::Check(#condition, __VA_ARGS__), condition))
230*6777b538SAndroid Build Coastguard Worker
231*6777b538SAndroid Build Coastguard Worker #define CHECK_WILL_STREAM() false
232*6777b538SAndroid Build Coastguard Worker
233*6777b538SAndroid Build Coastguard Worker // Strip the conditional string from official builds.
234*6777b538SAndroid Build Coastguard Worker #define PCHECK(condition) \
235*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL(::logging::CheckError::PCheck(), condition)
236*6777b538SAndroid Build Coastguard Worker
237*6777b538SAndroid Build Coastguard Worker #else
238*6777b538SAndroid Build Coastguard Worker
239*6777b538SAndroid Build Coastguard Worker #define CHECK_WILL_STREAM() true
240*6777b538SAndroid Build Coastguard Worker
241*6777b538SAndroid Build Coastguard Worker #define CHECK(condition, ...) \
242*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL( \
243*6777b538SAndroid Build Coastguard Worker ::logging::CheckError::Check(#condition __VA_OPT__(, ) __VA_ARGS__), \
244*6777b538SAndroid Build Coastguard Worker condition)
245*6777b538SAndroid Build Coastguard Worker
246*6777b538SAndroid Build Coastguard Worker #define PCHECK(condition) \
247*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL(::logging::CheckError::PCheck(#condition), \
248*6777b538SAndroid Build Coastguard Worker condition)
249*6777b538SAndroid Build Coastguard Worker
250*6777b538SAndroid Build Coastguard Worker #endif
251*6777b538SAndroid Build Coastguard Worker
252*6777b538SAndroid Build Coastguard Worker #if DCHECK_IS_ON()
253*6777b538SAndroid Build Coastguard Worker
254*6777b538SAndroid Build Coastguard Worker #define DCHECK(condition) \
255*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL(::logging::CheckError::DCheck(#condition), \
256*6777b538SAndroid Build Coastguard Worker condition)
257*6777b538SAndroid Build Coastguard Worker #define DPCHECK(condition) \
258*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL(::logging::CheckError::DPCheck(#condition), \
259*6777b538SAndroid Build Coastguard Worker condition)
260*6777b538SAndroid Build Coastguard Worker
261*6777b538SAndroid Build Coastguard Worker #else
262*6777b538SAndroid Build Coastguard Worker
263*6777b538SAndroid Build Coastguard Worker #define DCHECK(condition) EAT_CHECK_STREAM_PARAMS(!(condition))
264*6777b538SAndroid Build Coastguard Worker #define DPCHECK(condition) EAT_CHECK_STREAM_PARAMS(!(condition))
265*6777b538SAndroid Build Coastguard Worker
266*6777b538SAndroid Build Coastguard Worker #endif // DCHECK_IS_ON()
267*6777b538SAndroid Build Coastguard Worker
268*6777b538SAndroid Build Coastguard Worker // The DUMP_WILL_BE_CHECK() macro provides a convenient way to non-fatally dump
269*6777b538SAndroid Build Coastguard Worker // in official builds if a condition is false. This is used to more cautiously
270*6777b538SAndroid Build Coastguard Worker // roll out a new CHECK() (or upgrade a DCHECK) where the caller isn't entirely
271*6777b538SAndroid Build Coastguard Worker // sure that something holds true in practice (but asserts that it should). This
272*6777b538SAndroid Build Coastguard Worker // is especially useful for platforms that have a low pre-stable population and
273*6777b538SAndroid Build Coastguard Worker // code areas that are rarely exercised.
274*6777b538SAndroid Build Coastguard Worker //
275*6777b538SAndroid Build Coastguard Worker // On DCHECK builds this macro matches DCHECK behavior.
276*6777b538SAndroid Build Coastguard Worker //
277*6777b538SAndroid Build Coastguard Worker // This macro isn't optimized (preserves filename, line number and log messages
278*6777b538SAndroid Build Coastguard Worker // in official builds), as they are expected to be in product temporarily. When
279*6777b538SAndroid Build Coastguard Worker // using this macro, leave a TODO(crbug.com/nnnn) entry referring to a bug
280*6777b538SAndroid Build Coastguard Worker // related to its rollout. Then put a NextAction on the bug to come back and
281*6777b538SAndroid Build Coastguard Worker // clean this up (replace with a CHECK). A DUMP_WILL_BE_CHECK() that's been left
282*6777b538SAndroid Build Coastguard Worker // untouched for a long time without bug updates suggests that issues that
283*6777b538SAndroid Build Coastguard Worker // would've prevented enabling this CHECK have either not been discovered or
284*6777b538SAndroid Build Coastguard Worker // have been resolved.
285*6777b538SAndroid Build Coastguard Worker //
286*6777b538SAndroid Build Coastguard Worker // Using this macro is preferred over direct base::debug::DumpWithoutCrashing()
287*6777b538SAndroid Build Coastguard Worker // invocations as it communicates intent to eventually end up as a CHECK. It
288*6777b538SAndroid Build Coastguard Worker // also preserves the log message so setting crash keys to get additional debug
289*6777b538SAndroid Build Coastguard Worker // info isn't required as often.
290*6777b538SAndroid Build Coastguard Worker #define DUMP_WILL_BE_CHECK(condition, ...) \
291*6777b538SAndroid Build Coastguard Worker LOGGING_CHECK_FUNCTION_IMPL(::logging::CheckError::DumpWillBeCheck( \
292*6777b538SAndroid Build Coastguard Worker #condition __VA_OPT__(, ) __VA_ARGS__), \
293*6777b538SAndroid Build Coastguard Worker condition)
294*6777b538SAndroid Build Coastguard Worker
295*6777b538SAndroid Build Coastguard Worker // Async signal safe checking mechanism.
296*6777b538SAndroid Build Coastguard Worker [[noreturn]] BASE_EXPORT void RawCheckFailure(const char* message);
297*6777b538SAndroid Build Coastguard Worker #define RAW_CHECK(condition) \
298*6777b538SAndroid Build Coastguard Worker do { \
299*6777b538SAndroid Build Coastguard Worker if (UNLIKELY(!(condition))) { \
300*6777b538SAndroid Build Coastguard Worker ::logging::RawCheckFailure("Check failed: " #condition "\n"); \
301*6777b538SAndroid Build Coastguard Worker } \
302*6777b538SAndroid Build Coastguard Worker } while (0)
303*6777b538SAndroid Build Coastguard Worker
304*6777b538SAndroid Build Coastguard Worker } // namespace logging
305*6777b538SAndroid Build Coastguard Worker
306*6777b538SAndroid Build Coastguard Worker #endif // BASE_CHECK_H_
307