1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/base/logging.h"
6 
7 #include <cstdio>
8 #include <cstdlib>
9 
10 #include "src/base/debug/stack_trace.h"
11 #include "src/base/platform/platform.h"
12 
13 namespace v8 {
14 namespace base {
15 
16 // Explicit instantiations for commonly used comparisons.
17 #define DEFINE_MAKE_CHECK_OP_STRING(type)              \
18   template std::string* MakeCheckOpString<type, type>( \
19       type const&, type const&, char const*);
20 DEFINE_MAKE_CHECK_OP_STRING(int)
21 DEFINE_MAKE_CHECK_OP_STRING(long)       // NOLINT(runtime/int)
22 DEFINE_MAKE_CHECK_OP_STRING(long long)  // NOLINT(runtime/int)
23 DEFINE_MAKE_CHECK_OP_STRING(unsigned int)
24 DEFINE_MAKE_CHECK_OP_STRING(unsigned long)       // NOLINT(runtime/int)
25 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long)  // NOLINT(runtime/int)
26 DEFINE_MAKE_CHECK_OP_STRING(char const*)
27 DEFINE_MAKE_CHECK_OP_STRING(void const*)
28 #undef DEFINE_MAKE_CHECK_OP_STRING
29 
30 
31 // Explicit instantiations for floating point checks.
32 #define DEFINE_CHECK_OP_IMPL(NAME)                          \
33   template std::string* Check##NAME##Impl<float, float>(    \
34       float const& lhs, float const& rhs, char const* msg); \
35   template std::string* Check##NAME##Impl<double, double>(  \
36       double const& lhs, double const& rhs, char const* msg);
37 DEFINE_CHECK_OP_IMPL(EQ)
38 DEFINE_CHECK_OP_IMPL(NE)
39 DEFINE_CHECK_OP_IMPL(LE)
40 DEFINE_CHECK_OP_IMPL(LT)
41 DEFINE_CHECK_OP_IMPL(GE)
42 DEFINE_CHECK_OP_IMPL(GT)
43 #undef DEFINE_CHECK_OP_IMPL
44 
45 }  // namespace base
46 }  // namespace v8
47 
48 
49 // Contains protection against recursive calls (faults while handling faults).
V8_Fatal(const char * file,int line,const char * format,...)50 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
51   fflush(stdout);
52   fflush(stderr);
53   v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file,
54                            line);
55   va_list arguments;
56   va_start(arguments, format);
57   v8::base::OS::VPrintError(format, arguments);
58   va_end(arguments);
59   v8::base::OS::PrintError("\n#\n");
60 
61   v8::base::debug::StackTrace trace;
62   trace.Print();
63 
64   fflush(stderr);
65   // Avoid dumping stack trace on abort signal.
66   v8::base::debug::DisableSignalStackDump();
67   v8::base::OS::Abort();
68 }
69