mirror of https://github.com/nodejs/node.git
Changes to work on Solaris 10
parent
a9b962a653
commit
ac3a2d899a
|
@ -35,7 +35,8 @@
|
|||
#include <sys/stack.h> // for stack alignment
|
||||
#include <unistd.h> // getpagesize(), usleep()
|
||||
#include <sys/mman.h> // mmap()
|
||||
#include <execinfo.h> // backtrace(), backtrace_symbols()
|
||||
#include <ucontext.h> // walkstack(), getcontext()
|
||||
#include <dlfcn.h> // dladdr1
|
||||
#include <pthread.h>
|
||||
#include <sched.h> // for sched_yield
|
||||
#include <semaphore.h>
|
||||
|
@ -53,6 +54,19 @@
|
|||
#include "platform.h"
|
||||
|
||||
|
||||
#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 {
|
||||
return x < 0;
|
||||
}
|
||||
}
|
||||
#endif // signbit
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
|
@ -231,31 +245,55 @@ void OS::LogSharedLibraryAddresses() {
|
|||
}
|
||||
|
||||
|
||||
struct stack_walker {
|
||||
Vector<OS::StackFrame> &frames;
|
||||
int index;
|
||||
};
|
||||
|
||||
|
||||
static int StackWalkCallback(uintptr_t pc, int signo, void *data) {
|
||||
struct stack_walker * walker = static_cast<struct stack_walker *>(data);
|
||||
Dl_info info;
|
||||
|
||||
int i = walker->index;
|
||||
|
||||
walker->frames[i].address = (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((void*)pc, &info) == 0) {
|
||||
OS::SNPrintF(text, "[0x%p]", pc);
|
||||
} else if ((info.dli_fname != NULL && info.dli_sname != NULL)) {
|
||||
// we have containing 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,
|
||||
(unsigned long)pc - (unsigned long)info.dli_fbase,
|
||||
pc);
|
||||
}
|
||||
walker->index++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
int frames_size = frames.length();
|
||||
ScopedVector<void*> addresses(frames_size);
|
||||
ucontext_t ctx;
|
||||
struct stack_walker 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 (symbols == NULL) {
|
||||
if (!walkcontext(&ctx, StackWalkCallback, (void*)(&walker))) {
|
||||
return kStackWalkError;
|
||||
}
|
||||
|
||||
for (int i = 0; i < frames_count; i++) {
|
||||
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;
|
||||
return walker.index;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -83,6 +83,13 @@ int random();
|
|||
|
||||
#endif // WIN32
|
||||
|
||||
#ifdef __sun
|
||||
# if !defined(signbit)
|
||||
int signbit(double x);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// GCC specific stuff
|
||||
#ifdef __GNUC__
|
||||
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
// No copying is performed when slicing the buffer, only small reference
|
||||
// allocations.
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace node {
|
||||
|
||||
|
|
Loading…
Reference in New Issue