1 //===-- LLDBAssert.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Utility/LLDBAssert.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/Signals.h"
13 #include "llvm/Support/raw_ostream.h"
14 
15 #if LLVM_SUPPORT_XCODE_SIGNPOSTS
16 #include <os/log.h>
17 #endif
18 
19 using namespace llvm;
20 using namespace lldb_private;
21 
22 void lldb_private::lldb_assert(bool expression, const char *expr_text,
23                                const char *func, const char *file,
24                                unsigned int line) {
25   if (LLVM_LIKELY(expression))
26     return;
27 
28   // If asserts are enabled abort here.
29   assert(false && "lldb_assert failed");
30 
31 #if LLVM_SUPPORT_XCODE_SIGNPOSTS
32   if (__builtin_available(macos 10.12, iOS 10, tvOS 10, watchOS 3, *)) {
33     os_log_fault(OS_LOG_DEFAULT,
34                  "Assertion failed: (%s), function %s, file %s, line %u\n",
35                  expr_text, func, file, line);
36   }
37 #endif
38 
39   // In a release configuration it will print a warning and encourage the user
40   // to file a bug report, similar to LLVM’s crash handler, and then return
41   // execution.
42   errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n",
43                    expr_text, func, file, line);
44   errs() << "backtrace leading to the failure:\n";
45   llvm::sys::PrintStackTrace(errs());
46   errs() << "please file a bug report against lldb reporting this failure "
47             "log, and as many details as possible\n";
48 }
49