LLDB mainline
LLDBAssert.h
Go to the documentation of this file.
1//===----------------- LLDBAssert.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_UTILITY_LLDBASSERT_H
10#define LLDB_UTILITY_LLDBASSERT_H
11
12#include "llvm/ADT/StringRef.h"
13#include <mutex>
14
15#ifndef NDEBUG
16#define lldbassert(x) assert(x)
17#else
18#if defined(__clang__)
19// __FILE_NAME__ is a Clang-specific extension that functions similar to
20// __FILE__ but only renders the last path component (the filename) instead of
21// an invocation dependent full path to that file.
22#define lldbassert(x) \
23 do { \
24 static std::once_flag _once_flag; \
25 lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
26 __FILE_NAME__, __LINE__, _once_flag); \
27 } while (0)
28#else
29#define lldbassert(x) \
30 do { \
31 static std::once_flag _once_flag; \
32 lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
33 __FILE__, __LINE__, _once_flag); \
34 } while (0)
35#endif
36#endif
37
38namespace lldb_private {
39
40/// Don't use _lldb_assert directly. Use the lldbassert macro instead so that
41/// LLDB asserts become regular asserts in NDEBUG builds.
42void _lldb_assert(bool expression, const char *expr_text, const char *func,
43 const char *file, unsigned int line,
44 std::once_flag &once_flag);
45
46/// The default LLDB assert callback, which prints to stderr.
47typedef void (*LLDBAssertCallback)(llvm::StringRef message,
48 llvm::StringRef backtrace,
49 llvm::StringRef prompt);
50
51/// Replace the LLDB assert callback.
53
54} // namespace lldb_private
55
56#endif // LLDB_UTILITY_LLDBASSERT_H
A class that represents a running process on the host machine.
void SetLLDBAssertCallback(LLDBAssertCallback callback)
Replace the LLDB assert callback.
void(* LLDBAssertCallback)(llvm::StringRef message, llvm::StringRef backtrace, llvm::StringRef prompt)
The default LLDB assert callback, which prints to stderr.
Definition LLDBAssert.h:47
void _lldb_assert(bool expression, const char *expr_text, const char *func, const char *file, unsigned int line, std::once_flag &once_flag)
Don't use _lldb_assert directly.