Skip to content

Commit 7ea5f19

Browse files
authored
[lldb] Rename lldb_assert -> _lldb_assert (NFC) (llvm#123225)
Rename `lldb_assert` to `_lldb_assert` to make it more obvious that you shouldn't be using this function directly. Instead, you should use the `lldbassert` macro which becomes a regular assert in a debug/asserts build.
1 parent 1c00d0d commit 7ea5f19

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lldb/include/lldb/Utility/LLDBAssert.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,30 @@
1919
// __FILE__ but only renders the last path component (the filename) instead of
2020
// an invocation dependent full path to that file.
2121
#define lldbassert(x) \
22-
lldb_private::lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
23-
__FILE_NAME__, __LINE__)
22+
lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
23+
__FILE_NAME__, __LINE__)
2424
#else
2525
#define lldbassert(x) \
26-
lldb_private::lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, __FILE__, \
27-
__LINE__)
26+
lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, __FILE__, \
27+
__LINE__)
2828
#endif
2929
#endif
3030

3131
namespace lldb_private {
32-
void lldb_assert(bool expression, const char *expr_text, const char *func,
33-
const char *file, unsigned int line);
3432

33+
/// Don't use _lldb_assert directly. Use the lldbassert macro instead so that
34+
/// LLDB asserts become regular asserts in NDEBUG builds.
35+
void _lldb_assert(bool expression, const char *expr_text, const char *func,
36+
const char *file, unsigned int line);
37+
38+
/// The default LLDB assert callback, which prints to stderr.
3539
typedef void (*LLDBAssertCallback)(llvm::StringRef message,
3640
llvm::StringRef backtrace,
3741
llvm::StringRef prompt);
3842

43+
/// Replace the LLDB assert callback.
3944
void SetLLDBAssertCallback(LLDBAssertCallback callback);
45+
4046
} // namespace lldb_private
4147

4248
#endif // LLDB_UTILITY_LLDBASSERT_H

lldb/source/Utility/LLDBAssert.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace lldb_private {
2222

23+
/// The default callback prints to stderr.
2324
static void DefaultAssertCallback(llvm::StringRef message,
2425
llvm::StringRef backtrace,
2526
llvm::StringRef prompt) {
@@ -31,8 +32,8 @@ static void DefaultAssertCallback(llvm::StringRef message,
3132
static std::atomic<LLDBAssertCallback> g_lldb_assert_callback =
3233
&DefaultAssertCallback;
3334

34-
void lldb_assert(bool expression, const char *expr_text, const char *func,
35-
const char *file, unsigned int line) {
35+
void _lldb_assert(bool expression, const char *expr_text, const char *func,
36+
const char *file, unsigned int line) {
3637
if (LLVM_LIKELY(expression))
3738
return;
3839

@@ -44,8 +45,6 @@ void lldb_assert(bool expression, const char *expr_text, const char *func,
4445
}
4546
#endif
4647

47-
// Print a warning and encourage the user to file a bug report, similar to
48-
// LLVM’s crash handler, and then return execution.
4948
std::string buffer;
5049
llvm::raw_string_ostream backtrace(buffer);
5150
llvm::sys::PrintStackTrace(backtrace);
@@ -54,7 +53,7 @@ void lldb_assert(bool expression, const char *expr_text, const char *func,
5453
llvm::formatv("Assertion failed: ({0}), function {1}, file {2}, line {3}",
5554
expr_text, func, file, line)
5655
.str(),
57-
buffer,
56+
backtrace.str(),
5857
"Please file a bug report against lldb reporting this failure log, and "
5958
"as many details as possible");
6059
}

0 commit comments

Comments
 (0)