Files
carbon-lang/common/check_internal.cpp
T
Jon Ross-Perkins 8c354ca232 Switch to PrettyStackTrace for CHECK/FATAL (#2373)
At present, CHECK/FATAL print their own stack trace. This switches to just using std::abort for the stack trace, as well as the CHECK printing more completely.

This has a few consequences:

1) I'm now buffering the FATAL strings in order to print it later.
2) We now print the bug report message and program arguments on failure. This is part of pretty printing and was elided before.
3) We can now have pretty printing on FATAL, e.g. to show the stacks we're building in the parser.
2022-11-04 14:59:39 -07:00

35 lines
1.2 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "common/check_internal.h"
namespace Carbon::Internal {
// Prints the buffered message.
auto PrintAfterStackTrace(void* str) -> void {
llvm::errs() << reinterpret_cast<char*>(str);
}
ExitingStream::~ExitingStream() {
llvm_unreachable(
"Exiting streams should only be constructed by check.h macros that "
"ensure the special operator| exits the program prior to their "
"destruction!");
}
auto ExitingStream::Done() -> void {
buffer_ << "\n";
// Register another signal handler to print the buffered message. This is
// because we want it at the bottom of output, after LLVM's builtin stack
// output, rather than the top.
llvm::sys::AddSignalHandler(PrintAfterStackTrace,
const_cast<char*>(buffer_str_.c_str()));
// It's useful to exit the program with `std::abort()` for integration with
// debuggers and other tools. We also assume LLVM's exit handling is
// installed, which will stack trace on `std::abort()`.
std::abort();
}
} // namespace Carbon::Internal