Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index 3c042d7ab493b5b0b29b8dc57bf4aa99372813aa..50b0ab9bce8f818eb3bbc15c86b3e00f5a248aec 100644 |
| --- a/src/api.cc |
| +++ b/src/api.cc |
| @@ -40,6 +40,7 @@ |
| #include "src/prototype.h" |
| #include "src/runtime.h" |
| #include "src/runtime-profiler.h" |
| +#include "src/sampler.h" |
| #include "src/scanner-character-streams.h" |
| #include "src/simulator.h" |
| #include "src/snapshot.h" |
| @@ -6625,6 +6626,134 @@ void V8::CancelTerminateExecution(Isolate* isolate) { |
| } |
| +RegisterState::RegisterState(const context_t& context) { |
| +#if V8_OS_POSIX && !V8_OS_CYGWIN |
|
yurys
2014/09/19 08:08:12
One of the goals of having sampler API is to event
|
| +#if !V8_OS_OPENBSD |
| + const mcontext_t& mcontext = context.uc_mcontext; |
| +#endif |
| +#if V8_OS_LINUX |
| +#if V8_HOST_ARCH_IA32 |
| + pc = reinterpret_cast<void*>(mcontext.gregs[REG_EIP]); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[REG_ESP]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[REG_EBP]); |
| +#elif V8_HOST_ARCH_X64 |
| + pc = reinterpret_cast<void*>(mcontext.gregs[REG_RIP]); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[REG_RSP]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[REG_RBP]); |
| +#elif V8_HOST_ARCH_ARM |
| +#if defined(__GLIBC__) && !defined(__UCLIBC__) && \ |
| + (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
| + // Old GLibc ARM versions used a gregs[] array to access the register |
| + // values from mcontext_t. |
| + pc = reinterpret_cast<void*>(mcontext.gregs[R15]); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[R13]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[R11]); |
| +#else |
| + pc = reinterpret_cast<void*>(mcontext.arm_pc); |
| + sp = reinterpret_cast<void*>(mcontext.arm_sp); |
| + fp = reinterpret_cast<void*>(mcontext.arm_fp); |
| +#endif // defined(__GLIBC__) && !defined(__UCLIBC__) && |
| +// (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
| +#elif V8_HOST_ARCH_ARM64 |
| + pc = reinterpret_cast<void*>(mcontext.pc); |
| + sp = reinterpret_cast<void*>(mcontext.sp); |
| + // FP is an alias for x29. |
| + fp = reinterpret_cast<void*>(mcontext.regs[29]); |
| +#elif V8_HOST_ARCH_MIPS |
| + pc = reinterpret_cast<void*>(mcontext.pc); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[29]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[30]); |
| +#elif V8_HOST_ARCH_MIPS64 |
| + pc = reinterpret_cast<void*>(mcontext.pc); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[29]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[30]); |
| +#endif // V8_HOST_ARCH_* |
| +#elif V8_OS_MACOSX |
| +#if V8_HOST_ARCH_X64 |
| +#if __DARWIN_UNIX03 |
| + pc = reinterpret_cast<void*>(mcontext->__ss.__rip); |
| + sp = reinterpret_cast<void*>(mcontext->__ss.__rsp); |
| + fp = reinterpret_cast<void*>(mcontext->__ss.__rbp); |
| +#else // !__DARWIN_UNIX03 |
| + pc = reinterpret_cast<void*>(mcontext->ss.rip); |
| + sp = reinterpret_cast<void*>(mcontext->ss.rsp); |
| + fp = reinterpret_cast<void*>(mcontext->ss.rbp); |
| +#endif // __DARWIN_UNIX03 |
| +#elif V8_HOST_ARCH_IA32 |
| +#if __DARWIN_UNIX03 |
| + pc = reinterpret_cast<void*>(mcontext->__ss.__eip); |
| + sp = reinterpret_cast<void*>(mcontext->__ss.__esp); |
| + fp = reinterpret_cast<void*>(mcontext->__ss.__ebp); |
| +#else // !__DARWIN_UNIX03 |
| + pc = reinterpret_cast<void*>(mcontext->ss.eip); |
| + sp = reinterpret_cast<void*>(mcontext->ss.esp); |
| + fp = reinterpret_cast<void*>(mcontext->ss.ebp); |
| +#endif // __DARWIN_UNIX03 |
| +#endif // V8_HOST_ARCH_IA32 |
| +#elif V8_OS_FREEBSD |
| +#if V8_HOST_ARCH_IA32 |
| + pc = reinterpret_cast<void*>(mcontext.mc_eip); |
| + sp = reinterpret_cast<void*>(mcontext.mc_esp); |
| + fp = reinterpret_cast<void*>(mcontext.mc_ebp); |
| +#elif V8_HOST_ARCH_X64 |
| + pc = reinterpret_cast<void*>(mcontext.mc_rip); |
| + sp = reinterpret_cast<void*>(mcontext.mc_rsp); |
| + fp = reinterpret_cast<void*>(mcontext.mc_rbp); |
| +#elif V8_HOST_ARCH_ARM |
| + pc = reinterpret_cast<void*>(mcontext.mc_r15); |
| + sp = reinterpret_cast<void*>(mcontext.mc_r13); |
| + fp = reinterpret_cast<void*>(mcontext.mc_r11); |
| +#endif // V8_HOST_ARCH_* |
| +#elif V8_OS_NETBSD |
| +#if V8_HOST_ARCH_IA32 |
| + pc = reinterpret_cast<void*>(mcontext.__gregs[_REG_EIP]); |
| + sp = reinterpret_cast<void*>(mcontext.__gregs[_REG_ESP]); |
| + fp = reinterpret_cast<void*>(mcontext.__gregs[_REG_EBP]); |
| +#elif V8_HOST_ARCH_X64 |
| + pc = reinterpret_cast<void*>(mcontext.__gregs[_REG_RIP]); |
| + sp = reinterpret_cast<void*>(mcontext.__gregs[_REG_RSP]); |
| + fp = reinterpret_cast<void*>(mcontext.__gregs[_REG_RBP]); |
| +#endif // V8_HOST_ARCH_* |
| +#elif V8_OS_OPENBSD |
| +#if V8_HOST_ARCH_IA32 |
| + pc = reinterpret_cast<void*>(ucontext->sc_eip); |
| + sp = reinterpret_cast<void*>(ucontext->sc_esp); |
| + fp = reinterpret_cast<void*>(ucontext->sc_ebp); |
| +#elif V8_HOST_ARCH_X64 |
| + pc = reinterpret_cast<void*>(ucontext->sc_rip); |
| + sp = reinterpret_cast<void*>(ucontext->sc_rsp); |
| + fp = reinterpret_cast<void*>(ucontext->sc_rbp); |
| +#endif // V8_HOST_ARCH_* |
| +#elif V8_OS_SOLARIS |
| + pc = reinterpret_cast<void*>(mcontext.gregs[REG_PC]); |
| + sp = reinterpret_cast<void*>(mcontext.gregs[REG_SP]); |
| + fp = reinterpret_cast<void*>(mcontext.gregs[REG_FP]); |
| +#elif V8_OS_QNX |
| +#if V8_HOST_ARCH_IA32 |
| + pc = reinterpret_cast<void*>(mcontext.cpu.eip); |
| + sp = reinterpret_cast<void*>(mcontext.cpu.esp); |
| + fp = reinterpret_cast<void*>(mcontext.cpu.ebp); |
| +#elif V8_HOST_ARCH_ARM |
| + pc = reinterpret_cast<void*>(mcontext.cpu.gpr[ARM_REG_PC]); |
| + sp = reinterpret_cast<void*>(mcontext.cpu.gpr[ARM_REG_SP]); |
| + fp = reinterpret_cast<void*>(mcontext.cpu.gpr[ARM_REG_FP]); |
| +#endif // V8_HOST_ARCH_* |
| +#endif // V8_OS_QNX |
| + |
| +#elif V8_OS_WIN || V8_OS_CYGWIN |
| +#if V8_HOST_ARCH_X64 |
| + pc = reinterpret_cast<void*>(context.Rip); |
| + sp = reinterpret_cast<void*>(context.Rsp); |
| + fp = reinterpret_cast<void*>(context.Rbp); |
| +#else |
| + pc = reinterpret_cast<void*>(context.Eip); |
| + sp = reinterpret_cast<void*>(context.Esp); |
| + fp = reinterpret_cast<void*>(context.Ebp); |
| +#endif // V8_HOST_ARCH_X64 |
| +#endif // V8_OS_POSIX && !V8_OS_CYGWIN / V8_OS_WIN || V8_OS_CYGWIN |
| +} |
| + |
| + |
| void Isolate::RequestInterrupt(InterruptCallback callback, void* data) { |
| i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this); |
| i_isolate->set_api_interrupt_callback(callback); |
| @@ -6775,6 +6904,15 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { |
| } |
| +void Isolate::GetSample(const RegisterState& state, Sample* sample) { |
| + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); |
| + i::TickSample tick_sample; |
| + tick_sample.Init(isolate, state); |
|
loislo
2014/09/19 08:58:16
can we pass sample into Init method and fill it th
|
| + sample = new (sample) Sample(&tick_sample.stack[0], |
| + &tick_sample.stack[tick_sample.frames_count]); |
| +} |
| + |
| + |
| void Isolate::SetEventLogger(LogEventCallback that) { |
| // Do not overwrite the event logger if we want to log explicitly. |
| if (i::FLAG_log_timer_events) return; |