JDevlieghere created this revision. JDevlieghere added reviewers: bulbazord, labath, mib. Herald added a project: All. JDevlieghere requested review of this revision.
Whether assertions are enabled or not is orthogonal to the build type which could lead to surprising behavior for lldbassert. Previously, when doing a debug build with assertions disabled, lldbassert would become a NOOP, rather than printing an error like it does in a release build. By definining lldbassert in terms of NDEBUG, it behaves like a regular assert when assertions are enabled, and like a soft assert. https://reviews.llvm.org/D150639 Files: lldb/include/lldb/Utility/LLDBAssert.h lldb/source/Utility/LLDBAssert.cpp Index: lldb/source/Utility/LLDBAssert.cpp =================================================================== --- lldb/source/Utility/LLDBAssert.cpp +++ lldb/source/Utility/LLDBAssert.cpp @@ -25,9 +25,6 @@ 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, @@ -36,9 +33,8 @@ } #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"; Index: lldb/include/lldb/Utility/LLDBAssert.h =================================================================== --- lldb/include/lldb/Utility/LLDBAssert.h +++ lldb/include/lldb/Utility/LLDBAssert.h @@ -9,13 +9,19 @@ #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__) +#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,
Index: lldb/source/Utility/LLDBAssert.cpp =================================================================== --- lldb/source/Utility/LLDBAssert.cpp +++ lldb/source/Utility/LLDBAssert.cpp @@ -25,9 +25,6 @@ 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, @@ -36,9 +33,8 @@ } #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"; Index: lldb/include/lldb/Utility/LLDBAssert.h =================================================================== --- lldb/include/lldb/Utility/LLDBAssert.h +++ lldb/include/lldb/Utility/LLDBAssert.h @@ -9,13 +9,19 @@ #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__) +#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,
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits