Skip to content

[lldb] Rename lldb_assert -> _lldb_assert (NFC) #123225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lldb/include/lldb/Utility/LLDBAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
void lldb_assert(bool expression, const char *expr_text, const char *func,
const char *file, unsigned int line);

/// 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
9 changes: 4 additions & 5 deletions lldb/source/Utility/LLDBAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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");
}
Expand Down
Loading