Commit 75de923f authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Move DumpBacktrace() to checks.cc and cleanup both the code and the necessary platform checks.

This also removes the platform-posix.h header file.

R=machenbach@chromium.org

Review URL: https://codereview.chromium.org/23497009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16890 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c5751ce7
......@@ -25,11 +25,48 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdarg.h>
#include "checks.h"
#include "v8.h"
#if V8_LIBC_GLIBC || V8_OS_BSD
# include <cxxabi.h>
# include <execinfo.h>
#endif // V8_LIBC_GLIBC || V8_OS_BSD
#include <stdio.h>
#include "platform.h"
#include "v8.h"
// Attempts to dump a backtrace (if supported).
static V8_INLINE void DumpBacktrace() {
#if V8_LIBC_GLIBC || V8_OS_BSD
void* trace[100];
int size = backtrace(trace, ARRAY_SIZE(trace));
char** symbols = backtrace_symbols(trace, size);
i::OS::PrintError("\n==== C stack trace ===============================\n\n");
if (size == 0) {
i::OS::PrintError("(empty)\n");
} else if (symbols == NULL) {
i::OS::PrintError("(no symbols)\n");
} else {
for (int i = 1; i < size; ++i) {
i::OS::PrintError("%2d: ", i);
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);
i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
free(demangled);
} else {
i::OS::PrintError("??\n");
}
}
}
free(symbols);
#endif // V8_LIBC_GLIBC || V8_OS_BSD
}
// Contains protection against recursive calls (faults while handling faults).
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
......@@ -43,7 +80,8 @@ extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
i::OS::VPrintError(format, arguments);
va_end(arguments);
i::OS::PrintError("\n#\n");
i::OS::DumpBacktrace();
DumpBacktrace();
fflush(stderr);
i::OS::Abort();
}
......
......@@ -41,7 +41,6 @@
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "simulator.h"
#include "v8threads.h"
......@@ -88,11 +87,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
// Currently unsupported.
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -43,7 +43,6 @@
#include <sys/fcntl.h> // open
#include <unistd.h> // getpagesize
// If you don't have execinfo.h then you need devel/libexecinfo from ports.
#include <execinfo.h> // backtrace, backtrace_symbols
#include <strings.h> // index
#include <errno.h>
#include <stdarg.h>
......@@ -54,7 +53,6 @@
#include "v8.h"
#include "v8threads.h"
#include "platform-posix.h"
#include "platform.h"
#include "vm-state-inl.h"
......@@ -97,11 +95,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -38,11 +38,6 @@
#include <sys/types.h>
#include <stdlib.h>
#if defined(__GLIBC__) && !defined(__UCLIBC__)
#include <execinfo.h>
#include <cxxabi.h>
#endif
// Ubuntu Dapper requires memory pages to be marked as
// executable. Otherwise, OS raises an exception when executing code
// in that page.
......@@ -66,7 +61,6 @@
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "v8threads.h"
#include "vm-state-inl.h"
......@@ -154,14 +148,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
// backtrace is a glibc extension.
#if defined(__GLIBC__) && !defined(__UCLIBC__)
POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
#endif
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -53,27 +53,15 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <cxxabi.h>
#undef MAP_TYPE
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "simulator.h"
#include "vm-state-inl.h"
// Manually define these here as weak imports, rather than including execinfo.h.
// This lets us launch on 10.4 which does not have these calls.
extern "C" {
extern int backtrace(void**, int) __attribute__((weak_import));
extern char** backtrace_symbols(void* const*, int)
__attribute__((weak_import));
extern void backtrace_symbols_fd(void* const*, int, int)
__attribute__((weak_import));
}
namespace v8 {
namespace internal {
......@@ -107,14 +95,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
// If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
if (backtrace == NULL) return;
POSIXBacktraceHelper<backtrace, backtrace_symbols>::DumpBacktrace();
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -42,7 +42,6 @@
#include <sys/stat.h> // open
#include <fcntl.h> // open
#include <unistd.h> // sysconf
#include <execinfo.h> // backtrace, backtrace_symbols
#include <strings.h> // index
#include <errno.h>
#include <stdarg.h>
......@@ -51,7 +50,6 @@
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "v8threads.h"
#include "vm-state-inl.h"
......@@ -96,11 +94,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
// Currently unsupported.
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -29,8 +29,6 @@
// own but contains the parts which are the same across POSIX platforms Linux,
// Mac OS, FreeBSD and OpenBSD.
#include "platform-posix.h"
#include <dlfcn.h>
#include <pthread.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
......
// Copyright 2012 the V8 project authors. All rights reserved.
// 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.
#ifndef V8_PLATFORM_POSIX_H_
#define V8_PLATFORM_POSIX_H_
#if !defined(ANDROID)
#include <cxxabi.h>
#endif
#include <stdio.h>
#include "platform.h"
namespace v8 {
namespace internal {
// Used by platform implementation files during OS::DumpBacktrace()
template<int (*backtrace)(void**, int),
char** (*backtrace_symbols)(void* const*, int)>
struct POSIXBacktraceHelper {
static void DumpBacktrace() {
void* trace[100];
int size = backtrace(trace, ARRAY_SIZE(trace));
char** symbols = backtrace_symbols(trace, size);
fprintf(stderr, "\n==== C stack trace ===============================\n\n");
if (size == 0) {
fprintf(stderr, "(empty)\n");
} else if (symbols == NULL) {
fprintf(stderr, "(no symbols)\n");
} else {
for (int i = 1; i < size; ++i) {
fprintf(stderr, "%2d: ", i);
char mangled[201];
if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) {// NOLINT
char* demangled = NULL;
#if !defined(ANDROID)
int status;
size_t length;
demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
#endif
fprintf(stderr, "%s\n", demangled != NULL ? demangled : mangled);
free(demangled);
} else {
fprintf(stderr, "??\n");
}
}
}
fflush(stderr);
free(symbols);
}
};
} } // namespace v8::internal
#endif // V8_PLATFORM_POSIX_H_
......@@ -51,7 +51,6 @@
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "v8threads.h"
#include "vm-state-inl.h"
......@@ -112,11 +111,6 @@ void* OS::Allocate(const size_t requested,
}
void OS::DumpBacktrace() {
// Currently unsupported.
}
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
......
......@@ -891,11 +891,6 @@ void OS::DebugBreak() {
}
void OS::DumpBacktrace() {
// Currently unsupported.
}
class Win32MemoryMappedFile : public OS::MemoryMappedFile {
public:
Win32MemoryMappedFile(HANDLE file,
......
......@@ -256,9 +256,6 @@ class OS {
// Debug break.
static void DebugBreak();
// Dump C++ current stack trace (only functional on Linux).
static void DumpBacktrace();
// Walk the stack.
static const int kStackWalkError = -1;
static const int kStackWalkMaxNameLen = 256;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment