[Lldb-commits] [lldb] [lldb] Rename lldb_assert -> _lldb_assert (NFC) (PR #123225)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 16 11:22:39 PST 2025
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/123225
>From 8db51a67cd5447d51755a7a411b4d5e4857a86fa Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 16 Jan 2025 10:27:10 -0800
Subject: [PATCH 1/2] [lldb] Rename lldb_assert -> _lldb_assert (NFC)
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.
---
lldb/include/lldb/Utility/LLDBAssert.h | 4 ++--
lldb/source/Utility/LLDBAssert.cpp | 9 ++++-----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lldb/include/lldb/Utility/LLDBAssert.h b/lldb/include/lldb/Utility/LLDBAssert.h
index aeef3e51e20a87..5bfbef3c4f85b9 100644
--- a/lldb/include/lldb/Utility/LLDBAssert.h
+++ b/lldb/include/lldb/Utility/LLDBAssert.h
@@ -29,8 +29,8 @@
#endif
namespace lldb_private {
-void lldb_assert(bool expression, const char *expr_text, const char *func,
- const char *file, unsigned int line);
+void _lldb_assert(bool expression, const char *expr_text, const char *func,
+ const char *file, unsigned int line);
typedef void (*LLDBAssertCallback)(llvm::StringRef message,
llvm::StringRef backtrace,
diff --git a/lldb/source/Utility/LLDBAssert.cpp b/lldb/source/Utility/LLDBAssert.cpp
index b0c39a284910b1..3a1874ac2a9dc4 100644
--- a/lldb/source/Utility/LLDBAssert.cpp
+++ b/lldb/source/Utility/LLDBAssert.cpp
@@ -20,6 +20,7 @@
namespace lldb_private {
+/// The default callback prints to stderr.
static void DefaultAssertCallback(llvm::StringRef message,
llvm::StringRef backtrace,
llvm::StringRef prompt) {
@@ -31,8 +32,8 @@ static void DefaultAssertCallback(llvm::StringRef message,
static std::atomic<LLDBAssertCallback> g_lldb_assert_callback =
&DefaultAssertCallback;
-void lldb_assert(bool expression, const char *expr_text, const char *func,
- const char *file, unsigned int line) {
+void _lldb_assert(bool expression, const char *expr_text, const char *func,
+ const char *file, unsigned int line) {
if (LLVM_LIKELY(expression))
return;
@@ -44,8 +45,6 @@ void lldb_assert(bool expression, const char *expr_text, const char *func,
}
#endif
- // Print a warning and encourage the user to file a bug report, similar to
- // LLVM’s crash handler, and then return execution.
std::string buffer;
llvm::raw_string_ostream backtrace(buffer);
llvm::sys::PrintStackTrace(backtrace);
@@ -54,7 +53,7 @@ void lldb_assert(bool expression, const char *expr_text, const char *func,
llvm::formatv("Assertion failed: ({0}), function {1}, file {2}, line {3}",
expr_text, func, file, line)
.str(),
- buffer,
+ backtrace.str(),
"Please file a bug report against lldb reporting this failure log, and "
"as many details as possible");
}
>From b68e4a085c80ab07c803ac2f9de16260c844c046 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Thu, 16 Jan 2025 11:22:24 -0800
Subject: [PATCH 2/2] Address review feedback
---
lldb/include/lldb/Utility/LLDBAssert.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/lldb/include/lldb/Utility/LLDBAssert.h b/lldb/include/lldb/Utility/LLDBAssert.h
index 5bfbef3c4f85b9..21dbdb3b3202d4 100644
--- a/lldb/include/lldb/Utility/LLDBAssert.h
+++ b/lldb/include/lldb/Utility/LLDBAssert.h
@@ -19,24 +19,30 @@
// __FILE__ but only renders the last path component (the filename) instead of
// an invocation dependent full path to that file.
#define lldbassert(x) \
- lldb_private::lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
- __FILE_NAME__, __LINE__)
+ lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, \
+ __FILE_NAME__, __LINE__)
#else
#define lldbassert(x) \
- lldb_private::lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, __FILE__, \
- __LINE__)
+ lldb_private::_lldb_assert(static_cast<bool>(x), #x, __FUNCTION__, __FILE__, \
+ __LINE__)
#endif
#endif
namespace lldb_private {
+
+/// Don't use _lldb_assert directly. Use the lldbassert macro instead so that
+/// LLDB asserts become regular asserts in NDEBUG builds.
void _lldb_assert(bool expression, const char *expr_text, const char *func,
const char *file, unsigned int line);
+/// The default LLDB assert callback, which prints to stderr.
typedef void (*LLDBAssertCallback)(llvm::StringRef message,
llvm::StringRef backtrace,
llvm::StringRef prompt);
+/// Replace the LLDB assert callback.
void SetLLDBAssertCallback(LLDBAssertCallback callback);
+
} // namespace lldb_private
#endif // LLDB_UTILITY_LLDBASSERT_H
More information about the lldb-commits
mailing list