Fixes to Solaris build. signbit and StackWalker. This is a commit for
ry (coldredlemur@gmail.com). See http://codereview.chromium.org/2092007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4677 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
19d98493fc
commit
c5b8a2c9ec
@ -35,7 +35,8 @@
|
|||||||
#include <sys/stack.h> // for stack alignment
|
#include <sys/stack.h> // for stack alignment
|
||||||
#include <unistd.h> // getpagesize(), usleep()
|
#include <unistd.h> // getpagesize(), usleep()
|
||||||
#include <sys/mman.h> // mmap()
|
#include <sys/mman.h> // mmap()
|
||||||
#include <execinfo.h> // backtrace(), backtrace_symbols()
|
#include <ucontext.h> // walkstack(), getcontext()
|
||||||
|
#include <dlfcn.h> // dladdr
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sched.h> // for sched_yield
|
#include <sched.h> // for sched_yield
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
@ -53,6 +54,24 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
|
||||||
|
// It seems there is a bug in some Solaris distributions (experienced in
|
||||||
|
// SunOS 5.10 Generic_141445-09) which make it difficult or impossible to
|
||||||
|
// access signbit() despite the availability of other C99 math functions.
|
||||||
|
#ifndef signbit
|
||||||
|
// Test sign - usually defined in math.h
|
||||||
|
int signbit(double x) {
|
||||||
|
// We need to take care of the special case of both positive and negative
|
||||||
|
// versions of zero.
|
||||||
|
if (x == 0) {
|
||||||
|
return fpclass(x) & FP_NZERO;
|
||||||
|
} else {
|
||||||
|
// This won't detect negative NaN but that should be okay since we don't
|
||||||
|
// assume that behavior.
|
||||||
|
return x < 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // signbit
|
||||||
|
|
||||||
namespace v8 {
|
namespace v8 {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
@ -231,31 +250,55 @@ void OS::LogSharedLibraryAddresses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct StackWalker {
|
||||||
|
Vector<OS::StackFrame>& frames;
|
||||||
|
int index;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int StackWalkCallback(uintptr_t pc, int signo, void* data) {
|
||||||
|
struct StackWalker* walker = static_cast<struct StackWalker*>(data);
|
||||||
|
Dl_info info;
|
||||||
|
|
||||||
|
int i = walker->index;
|
||||||
|
|
||||||
|
walker->frames[i].address = reinterpret_cast<void*>(pc);
|
||||||
|
|
||||||
|
// Make sure line termination is in place.
|
||||||
|
walker->frames[i].text[OS::kStackWalkMaxTextLen - 1] = '\0';
|
||||||
|
|
||||||
|
Vector<char> text = MutableCStrVector(walker->frames[i].text,
|
||||||
|
OS::kStackWalkMaxTextLen);
|
||||||
|
|
||||||
|
if (dladdr(reinterpret_cast<void*>(pc), &info) == 0) {
|
||||||
|
OS::SNPrintF(text, "[0x%p]", pc);
|
||||||
|
} else if ((info.dli_fname != NULL && info.dli_sname != NULL)) {
|
||||||
|
// We have symbol info.
|
||||||
|
OS::SNPrintF(text, "%s'%s+0x%x", info.dli_fname, info.dli_sname, pc);
|
||||||
|
} else {
|
||||||
|
// No local symbol info.
|
||||||
|
OS::SNPrintF(text,
|
||||||
|
"%s'0x%p [0x%p]",
|
||||||
|
info.dli_fname,
|
||||||
|
pc - reinterpret_cast<uintptr_t>(info.dli_fbase),
|
||||||
|
pc);
|
||||||
|
}
|
||||||
|
walker->index++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||||
int frames_size = frames.length();
|
ucontext_t ctx;
|
||||||
ScopedVector<void*> addresses(frames_size);
|
struct StackWalker walker = { frames, 0 };
|
||||||
|
|
||||||
int frames_count = backtrace(addresses.start(), frames_size);
|
if (getcontext(&ctx) < 0) return kStackWalkError;
|
||||||
|
|
||||||
char** symbols = backtrace_symbols(addresses.start(), frames_count);
|
if (!walkcontext(&ctx, StackWalkCallback, &walker)) {
|
||||||
if (symbols == NULL) {
|
|
||||||
return kStackWalkError;
|
return kStackWalkError;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < frames_count; i++) {
|
return walker.index;
|
||||||
frames[i].address = addresses[i];
|
|
||||||
// Format a text representation of the frame based on the information
|
|
||||||
// available.
|
|
||||||
SNPrintF(MutableCStrVector(frames[i].text, kStackWalkMaxTextLen),
|
|
||||||
"%s",
|
|
||||||
symbols[i]);
|
|
||||||
// Make sure line termination is in place.
|
|
||||||
frames[i].text[kStackWalkMaxTextLen - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
free(symbols);
|
|
||||||
|
|
||||||
return frames_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,14 @@ int random();
|
|||||||
|
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __sun
|
||||||
|
# ifndef signbit
|
||||||
|
int signbit(double x);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// GCC specific stuff
|
// GCC specific stuff
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user