This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Define lldbassert based on NDEBUG instead of LLDB_CONFIGURATION_DEBUG
ClosedPublic

Authored by JDevlieghere on May 15 2023, 10:44 PM.

Details

Summary

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.

Diff Detail

Event Timeline

JDevlieghere created this revision.May 15 2023, 10:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2023, 10:44 PM
JDevlieghere requested review of this revision.May 15 2023, 10:44 PM

This patch also uses __FILE_NAME__ (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.) when building with clang.

rupprecht accepted this revision.May 16 2023, 6:46 AM
rupprecht added a subscriber: rupprecht.

+1 to being surprised this is not already the case

Some other places should be updated after this, e.g. lldb/source/Symbol/SymbolFile.cpp also has a use that can be trivially updated:

#if defined(LLDB_CONFIGURATION_DEBUG)
  // We assert that we have to module lock by trying to acquire the lock from a
  // different thread. Note that we must abort if the result is true to
  // guarantee correctness.
  assert(std::async(
             std::launch::async,
             [this] {
               return this->GetModuleMutex().try_lock();
             }).get() == false &&
         "Module is not locked");
#endif

-> just wrap it in lldbassert

This patch also uses __FILE_NAME__ (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.) when building with clang.

Can you put this comment in LLDBAssert.h itself?

This revision is now accepted and ready to land.May 16 2023, 6:46 AM

+1 to being surprised this is not already the case

Some other places should be updated after this, e.g. lldb/source/Symbol/SymbolFile.cpp also has a use that can be trivially updated:

#if defined(LLDB_CONFIGURATION_DEBUG)
  // We assert that we have to module lock by trying to acquire the lock from a
  // different thread. Note that we must abort if the result is true to
  // guarantee correctness.
  assert(std::async(
             std::launch::async,
             [this] {
               return this->GetModuleMutex().try_lock();
             }).get() == false &&
         "Module is not locked");
#endif

-> just wrap it in lldbassert

This code actually has a comment right above it explaining that it's too expensive to do in release builds, so this isn't a good candidate for lldbassert. But this logic can be improved: it duplicates checking the LLDB_CONFIGURATION_DEBUG in both ASSERT_MODULE_LOCK and AssertModuleLock and should use NDEBUG too. I'll address that in a separate patch.

This patch also uses __FILE_NAME__ (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.) when building with clang.

Can you put this comment in LLDBAssert.h itself?

Good idea.

Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 9:27 AM

+1 to being surprised this is not already the case

Some other places should be updated after this, e.g. lldb/source/Symbol/SymbolFile.cpp also has a use that can be trivially updated:

#if defined(LLDB_CONFIGURATION_DEBUG)
  // We assert that we have to module lock by trying to acquire the lock from a
  // different thread. Note that we must abort if the result is true to
  // guarantee correctness.
  assert(std::async(
             std::launch::async,
             [this] {
               return this->GetModuleMutex().try_lock();
             }).get() == false &&
         "Module is not locked");
#endif

-> just wrap it in lldbassert

This code actually has a comment right above it explaining that it's too expensive to do in release builds, so this isn't a good candidate for lldbassert. But this logic can be improved: it duplicates checking the LLDB_CONFIGURATION_DEBUG in both ASSERT_MODULE_LOCK and AssertModuleLock and should use NDEBUG too. I'll address that in a separate patch.

WDYT about just replacing LLDB_CONFIGURATION_DEBUG with LLVM's EXPENSIVE_CHECKS in this case?

This patch also uses __FILE_NAME__ (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.) when building with clang.

Can you put this comment in LLDBAssert.h itself?

Good idea.