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

Conversation

JDevlieghere
Copy link
Member

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.

@JDevlieghere
Copy link
Member Author

FWIW this in response to seeing lldb_assert being used directly in the Swift fork.

@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/123225.diff

2 Files Affected:

  • (modified) lldb/include/lldb/Utility/LLDBAssert.h (+2-2)
  • (modified) lldb/source/Utility/LLDBAssert.cpp (+3-4)
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..014eb3d83bec80 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,7 +32,7 @@ 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,
+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");
 }

Copy link

github-actions bot commented Jan 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

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.
Copy link
Contributor

@augusto2112 augusto2112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can also add a doxygen comment explaining that it shouldn't be used directly and use the lldbassert macro instead?

@JDevlieghere JDevlieghere merged commit 7ea5f19 into llvm:main Jan 16, 2025
7 checks passed
@JDevlieghere JDevlieghere deleted the _lldb_assert branch January 16, 2025 21:31
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Jan 16, 2025
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.

(cherry picked from commit 7ea5f19)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants