This revision was automatically updated to reflect the committed changes. Closed by commit rG83a6a0a62047: [lldb] Print lldbassert to debugger diagnostics (authored by JDevlieghere). Herald added a project: LLDB.
Changed prior to commit: https://reviews.llvm.org/D152866?vs=531126&id=531161#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D152866/new/ https://reviews.llvm.org/D152866 Files: lldb/include/lldb/Core/Debugger.h lldb/include/lldb/Utility/LLDBAssert.h lldb/source/API/SystemInitializerFull.cpp lldb/source/Core/Debugger.cpp lldb/source/Utility/LLDBAssert.cpp
Index: lldb/source/Utility/LLDBAssert.cpp =================================================================== --- lldb/source/Utility/LLDBAssert.cpp +++ lldb/source/Utility/LLDBAssert.cpp @@ -8,7 +8,7 @@ #include "lldb/Utility/LLDBAssert.h" #include "llvm/Config/llvm-config.h" -#include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" @@ -16,12 +16,21 @@ #include <os/log.h> #endif -using namespace llvm; -using namespace lldb_private; +namespace lldb_private { -void lldb_private::lldb_assert(bool expression, const char *expr_text, - const char *func, const char *file, - unsigned int line) { +static void DefaultAssertCallback(llvm::StringRef message, + llvm::StringRef backtrace, + llvm::StringRef prompt) { + llvm::errs() << message << '\n'; + llvm::errs() << backtrace; // Backtrace includes a newline. + llvm::errs() << prompt << '\n'; +} + +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) { if (LLVM_LIKELY(expression)) return; @@ -35,10 +44,21 @@ // 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"; - llvm::sys::PrintStackTrace(errs()); - errs() << "please file a bug report against lldb reporting this failure " - "log, and as many details as possible\n"; + std::string buffer; + llvm::raw_string_ostream backtrace(buffer); + llvm::sys::PrintStackTrace(backtrace); + + (*g_lldb_assert_callback.load())( + llvm::formatv("Assertion failed: ({0}), function {1}, file {2}, line {3}", + expr_text, func, file, line) + .str(), + backtrace.str(), + "Please file a bug report against lldb reporting this failure log, and " + "as many details as possible"); } + +void SetLLDBAssertCallback(LLDBAssertCallback callback) { + g_lldb_assert_callback.exchange(callback); +} + +} // namespace lldb_private Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -1352,6 +1352,13 @@ function_changed, initial_function); } +void Debugger::AssertCallback(llvm::StringRef message, + llvm::StringRef backtrace, + llvm::StringRef prompt) { + Debugger::ReportError( + llvm::formatv("{0}\n{1}{2}", message, backtrace, prompt).str()); +} + void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, void *baton) { // For simplicity's sake, I am not going to deal with how to close down any Index: lldb/source/API/SystemInitializerFull.cpp =================================================================== --- lldb/source/API/SystemInitializerFull.cpp +++ lldb/source/API/SystemInitializerFull.cpp @@ -78,6 +78,9 @@ // Settings must be initialized AFTER PluginManager::Initialize is called. Debugger::SettingsInitialize(); + // Use the Debugger's LLDBAssert callback. + SetLLDBAssertCallback(Debugger::AssertCallback); + return llvm::Error::success(); } Index: lldb/include/lldb/Utility/LLDBAssert.h =================================================================== --- lldb/include/lldb/Utility/LLDBAssert.h +++ lldb/include/lldb/Utility/LLDBAssert.h @@ -9,6 +9,8 @@ #ifndef LLDB_UTILITY_LLDBASSERT_H #define LLDB_UTILITY_LLDBASSERT_H +#include "llvm/ADT/StringRef.h" + #ifndef NDEBUG #define lldbassert(x) assert(x) #else @@ -29,6 +31,12 @@ namespace lldb_private { 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, + llvm::StringRef prompt); + +void SetLLDBAssertCallback(LLDBAssertCallback callback); } // namespace lldb_private #endif // LLDB_UTILITY_LLDBASSERT_H Index: lldb/include/lldb/Core/Debugger.h =================================================================== --- lldb/include/lldb/Core/Debugger.h +++ lldb/include/lldb/Core/Debugger.h @@ -128,6 +128,9 @@ const ExecutionContext *exe_ctx, const Address *addr, Stream &s); + static void AssertCallback(llvm::StringRef message, llvm::StringRef backtrace, + llvm::StringRef prompt); + void Clear(); bool GetAsyncExecution();
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits