24 #include "common_priv.h"
35 int line,
const char *func,
const char *msg) {
36 std::ostringstream oss;
37 oss <<
"Assert failed in " << file <<
":" << line;
38 oss <<
" in " << func;
39 oss <<
" : " << exp <<
'\n' << msg <<
'\n';
46 std::ostringstream oss;
47 oss << msg <<
"\nBacktrace:\n" << GetStackTrace() <<
"\n";
59 bool __ASSERT(
const char *exp,
const char *file,
int line,
const char *func,
bool die) {
61 fprintf(stderr,
"%s\nBacktrace:\n%s\n",
69 bool __ASSERT(
const char *exp,
const char *file,
int line,
const char *func,
bool die,
const std::string &msg) {
71 fprintf(stderr,
"%s\nBacktrace:\n%s\n",
79 bool __ASSERT(
const char *exp,
const char *file,
int line,
const char *func,
bool die,
const char *fmt, ...) {
80 std::vector<char> buff(128,
'\0');
86 int n = vsnprintf(&buff[0], buff.size(), fmt, ap);
89 if (n > -1 &&
unsigned(n) < buff.size()) {
94 buff.resize(n+1,
'\0');
97 buff.resize(buff.size()*2,
'\0');
100 std::string msg =
CreateMessage(exp, file, line, func, &buff[0]);
102 fprintf(stderr,
"%s\nBacktrace:\n%s\n", msg.c_str(),
GetStack(2).c_str());
bool __ASSERT(const char *exp, const char *file, int line, const char *func, bool die) __attribute__((noreturn))
std::string CreateMessage(const char *exp, const char *file, int line, const char *func, const char *msg)
The exception thrown by the ASSERT macro.
std::string GetStack(unsigned ignore=0)
function for printing out a stack trace Note that we need to pass -rdynamic to the linker to be able ...
AssertException(const std::string &msg)
virtual ~AssertException()
virtual const char * what() const