Skip to content

[lldb] Define lldbassert based on NDEBUG instead of LLDB_CONFIGURATIO… #6987

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 1 commit into from
Jun 15, 2023
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
4 changes: 2 additions & 2 deletions lldb/docs/resources/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ rules of thumb:

* Soft assertions. LLDB provides ``lldb_assert()`` as a soft
alternative to cover the middle ground of situations that indicate a
recoverable bug in LLDB. In a Debug configuration ``lldb_assert()``
behaves like ``assert()``. In a Release configuration it will print a
recoverable bug in LLDB. When asserts are enabled ``lldbassert()``
behaves like ``assert()``. When asserts are disabled, it will print a
warning and encourage the user to file a bug report, similar to
LLVM's crash handler, and then return execution. Use these sparingly
and only if error handling is not otherwise feasible. Specifically,
Expand Down
11 changes: 10 additions & 1 deletion lldb/include/lldb/Utility/LLDBAssert.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
#ifndef LLDB_UTILITY_LLDBASSERT_H
#define LLDB_UTILITY_LLDBASSERT_H

#ifdef LLDB_CONFIGURATION_DEBUG
#ifndef NDEBUG
#define lldbassert(x) assert(x)
#else
#if defined(__clang__)
// __FILE_NAME__ is a Clang-specific extension that functions similar to
// __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__)
#else
#define lldbassert(x) \
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,
Expand Down
8 changes: 2 additions & 6 deletions lldb/source/Utility/LLDBAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ void lldb_private::lldb_assert(bool expression, const char *expr_text,
if (LLVM_LIKELY(expression))
return;

// If asserts are enabled abort here.
assert(false && "lldb_assert failed");

#if LLVM_SUPPORT_XCODE_SIGNPOSTS
if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) {
os_log_fault(OS_LOG_DEFAULT,
Expand All @@ -36,9 +33,8 @@ void lldb_private::lldb_assert(bool expression, const char *expr_text,
}
#endif

// In a release configuration it will print a warning and encourage the user
// to file a bug report, similar to LLVM’s crash handler, and then return
// execution.
// Print a warning and encourage the user to file a bug report, similar to
// LLVM’s crash handler, and then return execution.
errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n",
expr_text, func, file, line);
errs() << "backtrace leading to the failure:\n";
Expand Down