1 //===--------------------- LLDBAssert.cpp ------------------------*- C++-*-===//
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 
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/Signals.h"
13 #include "llvm/Support/raw_ostream.h"
14 
15 using namespace llvm;
16 using namespace lldb_private;
17 
18 void lldb_private::lldb_assert(bool expression, const char *expr_text,
19                                const char *func, const char *file,
20                                unsigned int line) {
21   if (LLVM_LIKELY(expression))
22     return;
23 
24   // If asserts are enabled abort here.
25   assert(false && "lldb_assert failed");
26 
27   // In a release configuration it will print a warning and encourage the user
28   // to file a bug report, similar to LLVM’s crash handler, and then return
29   // execution.
30   errs() << format("Assertion failed: (%s), function %s, file %s, line %u\n",
31                    expr_text, func, file, line);
32   errs() << "backtrace leading to the failure:\n";
33   llvm::sys::PrintStackTrace(errs());
34   errs() << "please file a bug report against lldb reporting this failure "
35             "log, and as many details as possible\n";
36 }
37