2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2013-09-23 14:11:59 +00:00
|
|
|
#include "checks.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-09-23 14:11:59 +00:00
|
|
|
#if V8_LIBC_GLIBC || V8_OS_BSD
|
|
|
|
# include <cxxabi.h>
|
|
|
|
# include <execinfo.h>
|
2014-01-02 07:04:05 +00:00
|
|
|
#elif V8_OS_QNX
|
|
|
|
# include <backtrace.h>
|
2013-09-23 14:11:59 +00:00
|
|
|
#endif // V8_LIBC_GLIBC || V8_OS_BSD
|
|
|
|
#include <stdio.h>
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#include "platform.h"
|
2013-09-23 14:11:59 +00:00
|
|
|
#include "v8.h"
|
|
|
|
|
2014-03-17 13:33:19 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
|
2013-09-23 14:11:59 +00:00
|
|
|
|
|
|
|
// Attempts to dump a backtrace (if supported).
|
2014-03-17 13:33:19 +00:00
|
|
|
void DumpBacktrace() {
|
2013-09-23 14:11:59 +00:00
|
|
|
#if V8_LIBC_GLIBC || V8_OS_BSD
|
|
|
|
void* trace[100];
|
|
|
|
int size = backtrace(trace, ARRAY_SIZE(trace));
|
|
|
|
char** symbols = backtrace_symbols(trace, size);
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("\n==== C stack trace ===============================\n\n");
|
2013-09-23 14:11:59 +00:00
|
|
|
if (size == 0) {
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("(empty)\n");
|
2013-09-23 14:11:59 +00:00
|
|
|
} else if (symbols == NULL) {
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("(no symbols)\n");
|
2013-09-23 14:11:59 +00:00
|
|
|
} else {
|
|
|
|
for (int i = 1; i < size; ++i) {
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("%2d: ", i);
|
2013-09-23 14:11:59 +00:00
|
|
|
char mangled[201];
|
|
|
|
if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
|
|
|
|
int status;
|
|
|
|
size_t length;
|
|
|
|
char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
|
2013-09-23 14:11:59 +00:00
|
|
|
free(demangled);
|
|
|
|
} else {
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("??\n");
|
2013-09-23 14:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(symbols);
|
2014-01-02 07:04:05 +00:00
|
|
|
#elif V8_OS_QNX
|
|
|
|
char out[1024];
|
|
|
|
bt_accessor_t acc;
|
|
|
|
bt_memmap_t memmap;
|
|
|
|
bt_init_accessor(&acc, BT_SELF);
|
|
|
|
bt_load_memmap(&acc, &memmap);
|
|
|
|
bt_sprn_memmap(&memmap, out, sizeof(out));
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError(out);
|
2014-01-02 07:04:05 +00:00
|
|
|
bt_addr_t trace[100];
|
|
|
|
int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace));
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("\n==== C stack trace ===============================\n\n");
|
2014-01-02 07:04:05 +00:00
|
|
|
if (size == 0) {
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError("(empty)\n");
|
2014-01-02 07:04:05 +00:00
|
|
|
} else {
|
|
|
|
bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
|
|
|
|
out, sizeof(out), NULL);
|
2014-03-17 13:33:19 +00:00
|
|
|
OS::PrintError(out);
|
2014-01-02 07:04:05 +00:00
|
|
|
}
|
|
|
|
bt_unload_memmap(&memmap);
|
|
|
|
bt_release_accessor(&acc);
|
2013-09-23 14:11:59 +00:00
|
|
|
#endif // V8_LIBC_GLIBC || V8_OS_BSD
|
|
|
|
}
|
|
|
|
|
2014-03-17 13:33:19 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Contains protection against recursive calls (faults while handling faults).
|
|
|
|
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
|
2009-11-16 12:08:40 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2013-09-11 08:39:38 +00:00
|
|
|
i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line);
|
|
|
|
va_list arguments;
|
|
|
|
va_start(arguments, format);
|
|
|
|
i::OS::VPrintError(format, arguments);
|
|
|
|
va_end(arguments);
|
|
|
|
i::OS::PrintError("\n#\n");
|
2014-03-17 13:33:19 +00:00
|
|
|
v8::internal::DumpBacktrace();
|
2013-09-23 14:11:59 +00:00
|
|
|
fflush(stderr);
|
2009-03-02 09:09:07 +00:00
|
|
|
i::OS::Abort();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CheckEqualsHelper(const char* file,
|
|
|
|
int line,
|
|
|
|
const char* expected_source,
|
|
|
|
v8::Handle<v8::Value> expected,
|
|
|
|
const char* value_source,
|
|
|
|
v8::Handle<v8::Value> value) {
|
|
|
|
if (!expected->Equals(value)) {
|
2008-09-10 11:41:48 +00:00
|
|
|
v8::String::Utf8Value value_str(value);
|
|
|
|
v8::String::Utf8Value expected_str(expected);
|
2008-07-03 15:10:15 +00:00
|
|
|
V8_Fatal(file, line,
|
|
|
|
"CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
|
|
|
|
expected_source, value_source, *expected_str, *value_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CheckNonEqualsHelper(const char* file,
|
|
|
|
int line,
|
|
|
|
const char* unexpected_source,
|
|
|
|
v8::Handle<v8::Value> unexpected,
|
|
|
|
const char* value_source,
|
|
|
|
v8::Handle<v8::Value> value) {
|
|
|
|
if (unexpected->Equals(value)) {
|
2008-09-10 11:41:48 +00:00
|
|
|
v8::String::Utf8Value value_str(value);
|
2008-07-03 15:10:15 +00:00
|
|
|
V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s",
|
|
|
|
unexpected_source, value_source, *value_str);
|
|
|
|
}
|
|
|
|
}
|