JDevlieghere created this revision.
JDevlieghere added reviewers: LLDB, aprantl.
JDevlieghere requested review of this revision.

Call `os_log_fault` when an lldb assert fails. We piggyback off of the 
`LLVM_SUPPORT_XCODE_SIGNPOSTS` to for `os_log` support rather than introducing 
another check and define just for this. This patch also adds a small test using 
`lldb-test`.


https://reviews.llvm.org/D98987

Files:
  lldb/include/lldb/Utility/LLDBAssert.h
  lldb/source/Utility/LLDBAssert.cpp
  lldb/test/Shell/Error/assert.test
  lldb/tools/lldb-test/lldb-test.cpp

Index: lldb/tools/lldb-test/lldb-test.cpp
===================================================================
--- lldb/tools/lldb-test/lldb-test.cpp
+++ lldb/tools/lldb-test/lldb-test.cpp
@@ -29,6 +29,7 @@
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/LLDBAssert.h"
 #include "lldb/Utility/State.h"
 #include "lldb/Utility/StreamString.h"
 
@@ -57,6 +58,7 @@
                                     "Display LLDB object file information");
 cl::SubCommand SymbolsSubcommand("symbols", "Dump symbols for an object file");
 cl::SubCommand IRMemoryMapSubcommand("ir-memory-map", "Test IRMemoryMap");
+cl::SubCommand AssertSubcommand("assert", "Test assert handling");
 
 cl::opt<std::string> Log("log", cl::desc("Path to a log file"), cl::init(""),
                          cl::sub(BreakpointSubcommand),
@@ -236,6 +238,9 @@
 int evaluateMemoryMapCommands(Debugger &Dbg);
 } // namespace irmemorymap
 
+namespace assert {
+int lldb_assert(Debugger &Dbg);
+} // namespace assert
 } // namespace opts
 
 std::vector<CompilerContext> parseCompilerContext() {
@@ -1077,6 +1082,11 @@
   return 0;
 }
 
+int opts::assert::lldb_assert(Debugger &Dbg) {
+  lldbassert(false && "lldb-test assert");
+  return 1;
+}
+
 int main(int argc, const char *argv[]) {
   StringRef ToolName = argv[0];
   sys::PrintStackTraceOnErrorSignal(ToolName);
@@ -1120,6 +1130,8 @@
     return opts::symbols::dumpSymbols(*Dbg);
   if (opts::IRMemoryMapSubcommand)
     return opts::irmemorymap::evaluateMemoryMapCommands(*Dbg);
+  if (opts::AssertSubcommand)
+    return opts::assert::lldb_assert(*Dbg);
 
   WithColor::error() << "No command specified.\n";
   return 1;
Index: lldb/test/Shell/Error/assert.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Error/assert.test
@@ -0,0 +1,4 @@
+# REQUIRES: asserts
+# RUN: not --crash lldb-test assert > %t.error 2>&1
+# RUN: cat %t.error | FileCheck %s
+# CHECK: Assertion failed: (false && "lldb_assert failed")
Index: lldb/source/Utility/LLDBAssert.cpp
===================================================================
--- lldb/source/Utility/LLDBAssert.cpp
+++ lldb/source/Utility/LLDBAssert.cpp
@@ -7,11 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Utility/LLDBAssert.h"
-
+#include "llvm/Config/config.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
 
+#if LLVM_SUPPORT_XCODE_SIGNPOSTS
+#include <os/log.h>
+#endif
+
 using namespace llvm;
 using namespace lldb_private;
 
@@ -21,6 +25,14 @@
   if (LLVM_LIKELY(expression))
     return;
 
+#if LLVM_SUPPORT_XCODE_SIGNPOSTS
+  if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) {
+    os_log_fault(OS_LOG_DEFAULT,
+                 "Assertion failed: (%s), function %s, file %s, line %u\n",
+                 expr_text, func, file, line);
+  }
+#endif
+
   // If asserts are enabled abort here.
   assert(false && "lldb_assert failed");
 
Index: lldb/include/lldb/Utility/LLDBAssert.h
===================================================================
--- lldb/include/lldb/Utility/LLDBAssert.h
+++ lldb/include/lldb/Utility/LLDBAssert.h
@@ -20,6 +20,6 @@
 namespace lldb_private {
 void lldb_assert(bool expression, const char *expr_text, const char *func,
                  const char *file, unsigned int line);
-}
+} // namespace lldb_private
 
 #endif // LLDB_UTILITY_LLDBASSERT_H
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH] ... Jonas Devlieghere via Phabricator via lldb-commits

Reply via email to