5 #include "src/base/logging.h" 12 #include "src/base/debug/stack_trace.h" 13 #include "src/base/platform/platform.h" 20 void DefaultDcheckHandler(
const char* file,
int line,
const char* message);
22 void (*g_print_stack_trace)() =
nullptr;
24 void (*g_dcheck_function)(
const char*,
int,
const char*) = DefaultDcheckHandler;
26 void PrettyPrintChar(std::ostream& os,
int ch) {
28 #define CHAR_PRINT_CASE(ch) \ 43 #undef CHAR_PRINT_CASE 45 if (std::isprint(ch)) {
46 os <<
'\'' << ch <<
'\'';
48 auto flags = os.flags(std::ios_base::hex);
49 os <<
"\\x" <<
static_cast<unsigned int>(ch);
55 void DefaultDcheckHandler(
const char* file,
int line,
const char* message) {
56 V8_Fatal(file, line,
"Debug check failed: %s.", message);
61 void SetPrintStackTrace(
void (*print_stack_trace)()) {
62 g_print_stack_trace = print_stack_trace;
65 void SetDcheckFunction(
void (*dcheck_function)(
const char*,
int,
const char*)) {
66 g_dcheck_function = dcheck_function ? dcheck_function : &DefaultDcheckHandler;
71 #define DEFINE_PRINT_CHECK_OPERAND_CHAR(type) \ 73 void PrintCheckOperand<type>(std::ostream & os, type ch) { \ 74 PrettyPrintChar(os, ch); \ 77 void PrintCheckOperand<type*>(std::ostream & os, type * cstr) { \ 78 os << static_cast<void*>(cstr); \ 81 void PrintCheckOperand<const type*>(std::ostream & os, const type* cstr) { \ 82 os << static_cast<const void*>(cstr); \ 85 DEFINE_PRINT_CHECK_OPERAND_CHAR(
char)
86 DEFINE_PRINT_CHECK_OPERAND_CHAR(
signed char)
87 DEFINE_PRINT_CHECK_OPERAND_CHAR(
unsigned char)
88 #undef DEFINE_PRINT_CHECK_OPERAND_CHAR 91 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ 92 template std::string* MakeCheckOpString<type, type>(type, type, \ 94 template void PrintCheckOperand<type>(std::ostream&, type); 95 DEFINE_MAKE_CHECK_OP_STRING(
int)
96 DEFINE_MAKE_CHECK_OP_STRING(
long)
97 DEFINE_MAKE_CHECK_OP_STRING(
long long)
98 DEFINE_MAKE_CHECK_OP_STRING(
unsigned int)
99 DEFINE_MAKE_CHECK_OP_STRING(
unsigned long)
100 DEFINE_MAKE_CHECK_OP_STRING(
unsigned long long)
101 DEFINE_MAKE_CHECK_OP_STRING(
void const*)
102 #undef DEFINE_MAKE_CHECK_OP_STRING 106 #define DEFINE_CHECK_OP_IMPL(NAME) \ 107 template std::string* Check##NAME##Impl<float, float>(float lhs, float rhs, \ 109 template std::string* Check##NAME##Impl<double, double>( \ 110 double lhs, double rhs, char const* msg); 111 DEFINE_CHECK_OP_IMPL(EQ)
112 DEFINE_CHECK_OP_IMPL(NE)
113 DEFINE_CHECK_OP_IMPL(LE)
114 DEFINE_CHECK_OP_IMPL(LT)
115 DEFINE_CHECK_OP_IMPL(GE)
116 DEFINE_CHECK_OP_IMPL(GT)
117 #undef DEFINE_CHECK_OP_IMPL 128 class FailureMessage {
130 explicit FailureMessage(
const char* format, va_list arguments) {
131 memset(&message_, 0, arraysize(message_));
132 v8::base::OS::VSNPrintF(&message_[0], arraysize(message_), format,
136 static const uintptr_t kStartMarker = 0xdecade10;
137 static const uintptr_t kEndMarker = 0xdecade11;
138 static const int kMessageBufferSize = 512;
141 char message_[kMessageBufferSize];
147 void V8_Fatal(
const char* file,
int line,
const char* format, ...) {
149 va_start(arguments, format);
152 FailureMessage message(format, arguments);
158 v8::base::OS::PrintError(
"\n\n#\n# Fatal error in %s, line %d\n# ", file,
162 va_start(arguments, format);
163 v8::base::OS::VPrintError(format, arguments);
166 v8::base::OS::PrintError(
"\n#\n#\n#\n#FailureMessage Object: %p", &message);
168 if (v8::base::g_print_stack_trace) v8::base::g_print_stack_trace();
171 v8::base::OS::Abort();
174 void V8_Dcheck(
const char* file,
int line,
const char* message) {
175 v8::base::g_dcheck_function(file, line, message);