1 //===--------------------- LLDBAssert.cpp ------------------------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/LLDBAssert.h"
11 #include "llvm/Support/Format.h"
12 #include "llvm/Support/Signals.h"
13 #include "llvm/Support/raw_ostream.h"
16 using namespace lldb_private;
18 void lldb_private::lldb_assert(bool expression, const char *expr_text,
19 const char *func, const char *file,
21 if (LLVM_LIKELY(expression))
24 // In a Debug configuration lldb_assert() behaves like assert(0).
25 llvm_unreachable("lldb_assert failed");
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
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";