remove OS::StackWalk
R=bmeurer@chromium.org BUG= Review URL: https://codereview.chromium.org/23703013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16711 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
564a9a68b8
commit
cb490c9995
@ -205,12 +205,6 @@ void OS::SignalCodeMovingGC() {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
// Not supported on Cygwin.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// The VirtualMemory implementation is taken from platform-win32.cc.
|
||||
// The mmap-based virtual memory implementation as it is used on most posix
|
||||
// platforms does not work well because Cygwin does not support MAP_FIXED.
|
||||
|
@ -199,10 +199,6 @@ void OS::SignalCodeMovingGC() {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
|
||||
}
|
||||
|
||||
|
||||
// Constants used for mmap.
|
||||
static const int kMmapFd = -1;
|
||||
|
@ -313,16 +313,6 @@ void OS::SignalCodeMovingGC() {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
// backtrace is a glibc extension.
|
||||
#if defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Constants used for mmap.
|
||||
static const int kMmapFd = -1;
|
||||
static const int kMmapFdOffset = 0;
|
||||
|
@ -220,14 +220,6 @@ double OS::LocalTimeOffset() {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<StackFrame> frames) {
|
||||
// If weak link to execinfo lib has failed, ie because we are on 10.4, abort.
|
||||
if (backtrace == NULL) return 0;
|
||||
|
||||
return POSIXBacktraceHelper<backtrace, backtrace_symbols>::StackWalk(frames);
|
||||
}
|
||||
|
||||
|
||||
VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
|
||||
|
||||
|
||||
|
@ -231,34 +231,6 @@ void OS::SignalCodeMovingGC() {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
// backtrace is a glibc extension.
|
||||
int frames_size = frames.length();
|
||||
ScopedVector<void*> addresses(frames_size);
|
||||
|
||||
int frames_count = backtrace(addresses.start(), frames_size);
|
||||
|
||||
char** symbols = backtrace_symbols(addresses.start(), frames_count);
|
||||
if (symbols == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// Constants used for mmap.
|
||||
static const int kMmapFd = -1;
|
||||
|
@ -39,7 +39,6 @@ namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// Used by platform implementation files during OS::DumpBacktrace()
|
||||
// and OS::StackWalk().
|
||||
template<int (*backtrace)(void**, int),
|
||||
char** (*backtrace_symbols)(void* const*, int)>
|
||||
struct POSIXBacktraceHelper {
|
||||
@ -73,32 +72,6 @@ struct POSIXBacktraceHelper {
|
||||
fflush(stderr);
|
||||
free(symbols);
|
||||
}
|
||||
|
||||
static int StackWalk(Vector<OS::StackFrame> frames) {
|
||||
int frames_size = frames.length();
|
||||
ScopedVector<void*> addresses(frames_size);
|
||||
|
||||
int frames_count = backtrace(addresses.start(), frames_size);
|
||||
|
||||
char** symbols = backtrace_symbols(addresses.start(), frames_count);
|
||||
if (symbols == NULL) {
|
||||
return OS::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.
|
||||
OS::SNPrintF(MutableCStrVector(frames[i].text, OS::kStackWalkMaxTextLen),
|
||||
"%s", symbols[i]);
|
||||
// Make sure line termination is in place.
|
||||
frames[i].text[OS::kStackWalkMaxTextLen - 1] = '\0';
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
|
||||
return frames_count;
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace v8::internal
|
||||
|
@ -211,20 +211,6 @@ static int StackWalkCallback(uintptr_t pc, int signo, void* data) {
|
||||
}
|
||||
|
||||
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
ucontext_t ctx;
|
||||
struct StackWalker walker = { frames, 0 };
|
||||
|
||||
if (getcontext(&ctx) < 0) return kStackWalkError;
|
||||
|
||||
if (!walkcontext(&ctx, StackWalkCallback, &walker)) {
|
||||
return kStackWalkError;
|
||||
}
|
||||
|
||||
return walker.index;
|
||||
}
|
||||
|
||||
|
||||
// Constants used for mmap.
|
||||
static const int kMmapFd = -1;
|
||||
static const int kMmapFdOffset = 0;
|
||||
|
@ -1208,133 +1208,9 @@ void OS::SignalCodeMovingGC() {
|
||||
}
|
||||
|
||||
|
||||
// Walk the stack using the facilities in dbghelp.dll and tlhelp32.dll
|
||||
|
||||
// Switch off warning 4748 (/GS can not protect parameters and local variables
|
||||
// from local buffer overrun because optimizations are disabled in function) as
|
||||
// it is triggered by the use of inline assembler.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4748)
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) {
|
||||
BOOL ok;
|
||||
|
||||
// Load the required functions from DLL's.
|
||||
if (!LoadDbgHelpAndTlHelp32()) return kStackWalkError;
|
||||
|
||||
// Get the process and thread handles.
|
||||
HANDLE process_handle = GetCurrentProcess();
|
||||
HANDLE thread_handle = GetCurrentThread();
|
||||
|
||||
// Read the symbols.
|
||||
if (!LoadSymbols(Isolate::Current(), process_handle)) return kStackWalkError;
|
||||
|
||||
// Capture current context.
|
||||
CONTEXT context;
|
||||
RtlCaptureContext(&context);
|
||||
|
||||
// Initialize the stack walking
|
||||
STACKFRAME64 stack_frame;
|
||||
memset(&stack_frame, 0, sizeof(stack_frame));
|
||||
#ifdef _WIN64
|
||||
stack_frame.AddrPC.Offset = context.Rip;
|
||||
stack_frame.AddrFrame.Offset = context.Rbp;
|
||||
stack_frame.AddrStack.Offset = context.Rsp;
|
||||
#else
|
||||
stack_frame.AddrPC.Offset = context.Eip;
|
||||
stack_frame.AddrFrame.Offset = context.Ebp;
|
||||
stack_frame.AddrStack.Offset = context.Esp;
|
||||
#endif
|
||||
stack_frame.AddrPC.Mode = AddrModeFlat;
|
||||
stack_frame.AddrFrame.Mode = AddrModeFlat;
|
||||
stack_frame.AddrStack.Mode = AddrModeFlat;
|
||||
int frames_count = 0;
|
||||
|
||||
// Collect stack frames.
|
||||
int frames_size = frames.length();
|
||||
while (frames_count < frames_size) {
|
||||
ok = _StackWalk64(
|
||||
IMAGE_FILE_MACHINE_I386, // MachineType
|
||||
process_handle, // hProcess
|
||||
thread_handle, // hThread
|
||||
&stack_frame, // StackFrame
|
||||
&context, // ContextRecord
|
||||
NULL, // ReadMemoryRoutine
|
||||
_SymFunctionTableAccess64, // FunctionTableAccessRoutine
|
||||
_SymGetModuleBase64, // GetModuleBaseRoutine
|
||||
NULL); // TranslateAddress
|
||||
if (!ok) break;
|
||||
|
||||
// Store the address.
|
||||
ASSERT((stack_frame.AddrPC.Offset >> 32) == 0); // 32-bit address.
|
||||
frames[frames_count].address =
|
||||
reinterpret_cast<void*>(stack_frame.AddrPC.Offset);
|
||||
|
||||
// Try to locate a symbol for this frame.
|
||||
DWORD64 symbol_displacement;
|
||||
SmartArrayPointer<IMAGEHLP_SYMBOL64> symbol(
|
||||
NewArray<IMAGEHLP_SYMBOL64>(kStackWalkMaxNameLen));
|
||||
if (symbol.is_empty()) return kStackWalkError; // Out of memory.
|
||||
memset(*symbol, 0, sizeof(IMAGEHLP_SYMBOL64) + kStackWalkMaxNameLen);
|
||||
(*symbol)->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||
(*symbol)->MaxNameLength = kStackWalkMaxNameLen;
|
||||
ok = _SymGetSymFromAddr64(process_handle, // hProcess
|
||||
stack_frame.AddrPC.Offset, // Address
|
||||
&symbol_displacement, // Displacement
|
||||
*symbol); // Symbol
|
||||
if (ok) {
|
||||
// Try to locate more source information for the symbol.
|
||||
IMAGEHLP_LINE64 Line;
|
||||
memset(&Line, 0, sizeof(Line));
|
||||
Line.SizeOfStruct = sizeof(Line);
|
||||
DWORD line_displacement;
|
||||
ok = _SymGetLineFromAddr64(
|
||||
process_handle, // hProcess
|
||||
stack_frame.AddrPC.Offset, // dwAddr
|
||||
&line_displacement, // pdwDisplacement
|
||||
&Line); // Line
|
||||
// Format a text representation of the frame based on the information
|
||||
// available.
|
||||
if (ok) {
|
||||
SNPrintF(MutableCStrVector(frames[frames_count].text,
|
||||
kStackWalkMaxTextLen),
|
||||
"%s %s:%d:%d",
|
||||
(*symbol)->Name, Line.FileName, Line.LineNumber,
|
||||
line_displacement);
|
||||
} else {
|
||||
SNPrintF(MutableCStrVector(frames[frames_count].text,
|
||||
kStackWalkMaxTextLen),
|
||||
"%s",
|
||||
(*symbol)->Name);
|
||||
}
|
||||
// Make sure line termination is in place.
|
||||
frames[frames_count].text[kStackWalkMaxTextLen - 1] = '\0';
|
||||
} else {
|
||||
// No text representation of this frame
|
||||
frames[frames_count].text[0] = '\0';
|
||||
|
||||
// Continue if we are just missing a module (for non C/C++ frames a
|
||||
// module will never be found).
|
||||
int err = GetLastError();
|
||||
if (err != ERROR_MOD_NOT_FOUND) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
frames_count++;
|
||||
}
|
||||
|
||||
// Return the number of frames filled in.
|
||||
return frames_count;
|
||||
}
|
||||
|
||||
|
||||
// Restore warnings to previous settings.
|
||||
#pragma warning(pop)
|
||||
|
||||
#else // __MINGW32__
|
||||
void OS::LogSharedLibraryAddresses(Isolate* isolate) { }
|
||||
void OS::SignalCodeMovingGC() { }
|
||||
int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; }
|
||||
#endif // __MINGW32__
|
||||
|
||||
|
||||
|
@ -264,8 +264,6 @@ class OS {
|
||||
char text[kStackWalkMaxTextLen];
|
||||
};
|
||||
|
||||
static int StackWalk(Vector<StackFrame> frames);
|
||||
|
||||
class MemoryMappedFile {
|
||||
public:
|
||||
static MemoryMappedFile* open(const char* name);
|
||||
|
Loading…
Reference in New Issue
Block a user