| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #elif(!V8_OS_ANDROID || defined(__BIONIC_HAVE_UCONTEXT_T)) \ | 47 #elif(!V8_OS_ANDROID || defined(__BIONIC_HAVE_UCONTEXT_T)) \ |
| 48 && !V8_OS_OPENBSD | 48 && !V8_OS_OPENBSD |
| 49 #include <ucontext.h> | 49 #include <ucontext.h> |
| 50 #endif | 50 #endif |
| 51 | 51 |
| 52 #include <unistd.h> | 52 #include <unistd.h> |
| 53 | 53 |
| 54 // GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'. | 54 // GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'. |
| 55 // Old versions of the C library <signal.h> didn't define the type. | 55 // Old versions of the C library <signal.h> didn't define the type. |
| 56 #if V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T) && \ | 56 #if V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T) && \ |
| 57 (defined(__arm__) || defined(__aarch64__)) && \ | 57 defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) |
| 58 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT) | |
| 59 #include <asm/sigcontext.h> | 58 #include <asm/sigcontext.h> |
| 60 #endif | 59 #endif |
| 61 | 60 |
| 62 #elif V8_OS_WIN || V8_OS_CYGWIN | 61 #elif V8_OS_WIN || V8_OS_CYGWIN |
| 63 | 62 |
| 64 #include "win32-headers.h" | 63 #include "win32-headers.h" |
| 65 | 64 |
| 66 #endif | 65 #endif |
| 67 | 66 |
| 68 #include "v8.h" | 67 #include "v8.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 91 typedef struct sigcontext mcontext_t; | 90 typedef struct sigcontext mcontext_t; |
| 92 | 91 |
| 93 typedef struct ucontext { | 92 typedef struct ucontext { |
| 94 uint32_t uc_flags; | 93 uint32_t uc_flags; |
| 95 struct ucontext* uc_link; | 94 struct ucontext* uc_link; |
| 96 stack_t uc_stack; | 95 stack_t uc_stack; |
| 97 mcontext_t uc_mcontext; | 96 mcontext_t uc_mcontext; |
| 98 // Other fields are not used by V8, don't define them here. | 97 // Other fields are not used by V8, don't define them here. |
| 99 } ucontext_t; | 98 } ucontext_t; |
| 100 | 99 |
| 101 #elif defined(__aarch64__) | |
| 102 | |
| 103 typedef struct sigcontext mcontext_t; | |
| 104 | |
| 105 typedef struct ucontext { | |
| 106 uint64_t uc_flags; | |
| 107 struct ucontext *uc_link; | |
| 108 stack_t uc_stack; | |
| 109 mcontext_t uc_mcontext; | |
| 110 // Other fields are not used by V8, don't define them here. | |
| 111 } ucontext_t; | |
| 112 | |
| 113 #elif defined(__mips__) | 100 #elif defined(__mips__) |
| 114 // MIPS version of sigcontext, for Android bionic. | 101 // MIPS version of sigcontext, for Android bionic. |
| 115 typedef struct { | 102 typedef struct { |
| 116 uint32_t regmask; | 103 uint32_t regmask; |
| 117 uint32_t status; | 104 uint32_t status; |
| 118 uint64_t pc; | 105 uint64_t pc; |
| 119 uint64_t gregs[32]; | 106 uint64_t gregs[32]; |
| 120 uint64_t fpregs[32]; | 107 uint64_t fpregs[32]; |
| 121 uint32_t acx; | 108 uint32_t acx; |
| 122 uint32_t fpc_csr; | 109 uint32_t fpc_csr; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 #if defined(USE_SIMULATOR) | 219 #if defined(USE_SIMULATOR) |
| 233 class SimulatorHelper { | 220 class SimulatorHelper { |
| 234 public: | 221 public: |
| 235 inline bool Init(Sampler* sampler, Isolate* isolate) { | 222 inline bool Init(Sampler* sampler, Isolate* isolate) { |
| 236 simulator_ = isolate->thread_local_top()->simulator_; | 223 simulator_ = isolate->thread_local_top()->simulator_; |
| 237 // Check if there is active simulator. | 224 // Check if there is active simulator. |
| 238 return simulator_ != NULL; | 225 return simulator_ != NULL; |
| 239 } | 226 } |
| 240 | 227 |
| 241 inline void FillRegisters(RegisterState* state) { | 228 inline void FillRegisters(RegisterState* state) { |
| 242 #if V8_TARGET_ARCH_ARM | |
| 243 state->pc = reinterpret_cast<Address>(simulator_->get_pc()); | 229 state->pc = reinterpret_cast<Address>(simulator_->get_pc()); |
| 244 state->sp = reinterpret_cast<Address>(simulator_->get_register( | 230 state->sp = reinterpret_cast<Address>(simulator_->get_register( |
| 245 Simulator::sp)); | 231 Simulator::sp)); |
| 232 #if V8_TARGET_ARCH_ARM |
| 246 state->fp = reinterpret_cast<Address>(simulator_->get_register( | 233 state->fp = reinterpret_cast<Address>(simulator_->get_register( |
| 247 Simulator::r11)); | 234 Simulator::r11)); |
| 248 #elif V8_TARGET_ARCH_A64 | |
| 249 if (simulator_->sp() == 0 || simulator_->fp() == 0) { | |
| 250 // It possible that the simulator is interrupted while it is updating | |
| 251 // the sp or fp register. A64 simulator does this in two steps: | |
| 252 // first setting it to zero and then setting it to the new value. | |
| 253 // Bailout if sp/fp doesn't contain the new value. | |
| 254 return; | |
| 255 } | |
| 256 state->pc = reinterpret_cast<Address>(simulator_->pc()); | |
| 257 state->sp = reinterpret_cast<Address>(simulator_->sp()); | |
| 258 state->fp = reinterpret_cast<Address>(simulator_->fp()); | |
| 259 #elif V8_TARGET_ARCH_MIPS | 235 #elif V8_TARGET_ARCH_MIPS |
| 260 state->pc = reinterpret_cast<Address>(simulator_->get_pc()); | |
| 261 state->sp = reinterpret_cast<Address>(simulator_->get_register( | |
| 262 Simulator::sp)); | |
| 263 state->fp = reinterpret_cast<Address>(simulator_->get_register( | 236 state->fp = reinterpret_cast<Address>(simulator_->get_register( |
| 264 Simulator::fp)); | 237 Simulator::fp)); |
| 265 #endif | 238 #endif |
| 266 } | 239 } |
| 267 | 240 |
| 268 private: | 241 private: |
| 269 Simulator* simulator_; | 242 Simulator* simulator_; |
| 270 }; | 243 }; |
| 271 #endif // USE_SIMULATOR | 244 #endif // USE_SIMULATOR |
| 272 | 245 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 322 |
| 350 Sampler* sampler = isolate->logger()->sampler(); | 323 Sampler* sampler = isolate->logger()->sampler(); |
| 351 if (sampler == NULL) return; | 324 if (sampler == NULL) return; |
| 352 | 325 |
| 353 RegisterState state; | 326 RegisterState state; |
| 354 | 327 |
| 355 #if defined(USE_SIMULATOR) | 328 #if defined(USE_SIMULATOR) |
| 356 SimulatorHelper helper; | 329 SimulatorHelper helper; |
| 357 if (!helper.Init(sampler, isolate)) return; | 330 if (!helper.Init(sampler, isolate)) return; |
| 358 helper.FillRegisters(&state); | 331 helper.FillRegisters(&state); |
| 359 // It possible that the simulator is interrupted while it is updating | |
| 360 // the sp or fp register. A64 simulator does this in two steps: | |
| 361 // first setting it to zero and then setting it to the new value. | |
| 362 // Bailout if sp/fp doesn't contain the new value. | |
| 363 if (state.sp == 0 || state.fp == 0) return; | |
| 364 #else | 332 #else |
| 365 // Extracting the sample from the context is extremely machine dependent. | 333 // Extracting the sample from the context is extremely machine dependent. |
| 366 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); | 334 ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
| 367 #if !V8_OS_OPENBSD | 335 #if !V8_OS_OPENBSD |
| 368 mcontext_t& mcontext = ucontext->uc_mcontext; | 336 mcontext_t& mcontext = ucontext->uc_mcontext; |
| 369 #endif | 337 #endif |
| 370 #if V8_OS_LINUX | 338 #if V8_OS_LINUX |
| 371 #if V8_HOST_ARCH_IA32 | 339 #if V8_HOST_ARCH_IA32 |
| 372 state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); | 340 state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]); |
| 373 state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); | 341 state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]); |
| 374 state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); | 342 state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]); |
| 375 #elif V8_HOST_ARCH_X64 | 343 #elif V8_HOST_ARCH_X64 |
| 376 state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); | 344 state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]); |
| 377 state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]); | 345 state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]); |
| 378 state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]); | 346 state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]); |
| 379 #elif V8_HOST_ARCH_ARM | 347 #elif V8_HOST_ARCH_ARM |
| 380 #if defined(__GLIBC__) && !defined(__UCLIBC__) && \ | 348 #if defined(__GLIBC__) && !defined(__UCLIBC__) && \ |
| 381 (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | 349 (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
| 382 // Old GLibc ARM versions used a gregs[] array to access the register | 350 // Old GLibc ARM versions used a gregs[] array to access the register |
| 383 // values from mcontext_t. | 351 // values from mcontext_t. |
| 384 state.pc = reinterpret_cast<Address>(mcontext.gregs[R15]); | 352 state.pc = reinterpret_cast<Address>(mcontext.gregs[R15]); |
| 385 state.sp = reinterpret_cast<Address>(mcontext.gregs[R13]); | 353 state.sp = reinterpret_cast<Address>(mcontext.gregs[R13]); |
| 386 state.fp = reinterpret_cast<Address>(mcontext.gregs[R11]); | 354 state.fp = reinterpret_cast<Address>(mcontext.gregs[R11]); |
| 387 #else | 355 #else |
| 388 state.pc = reinterpret_cast<Address>(mcontext.arm_pc); | 356 state.pc = reinterpret_cast<Address>(mcontext.arm_pc); |
| 389 state.sp = reinterpret_cast<Address>(mcontext.arm_sp); | 357 state.sp = reinterpret_cast<Address>(mcontext.arm_sp); |
| 390 state.fp = reinterpret_cast<Address>(mcontext.arm_fp); | 358 state.fp = reinterpret_cast<Address>(mcontext.arm_fp); |
| 391 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && | 359 #endif // defined(__GLIBC__) && !defined(__UCLIBC__) && |
| 392 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) | 360 // (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
| 393 #elif V8_HOST_ARCH_A64 | |
| 394 state.pc = reinterpret_cast<Address>(mcontext.pc); | |
| 395 state.sp = reinterpret_cast<Address>(mcontext.sp); | |
| 396 // FP is an alias for x29. | |
| 397 state.fp = reinterpret_cast<Address>(mcontext.regs[29]); | |
| 398 #elif V8_HOST_ARCH_MIPS | 361 #elif V8_HOST_ARCH_MIPS |
| 399 state.pc = reinterpret_cast<Address>(mcontext.pc); | 362 state.pc = reinterpret_cast<Address>(mcontext.pc); |
| 400 state.sp = reinterpret_cast<Address>(mcontext.gregs[29]); | 363 state.sp = reinterpret_cast<Address>(mcontext.gregs[29]); |
| 401 state.fp = reinterpret_cast<Address>(mcontext.gregs[30]); | 364 state.fp = reinterpret_cast<Address>(mcontext.gregs[30]); |
| 402 #endif // V8_HOST_ARCH_* | 365 #endif // V8_HOST_ARCH_* |
| 403 #elif V8_OS_MACOSX | 366 #elif V8_OS_MACOSX |
| 404 #if V8_HOST_ARCH_X64 | 367 #if V8_HOST_ARCH_X64 |
| 405 #if __DARWIN_UNIX03 | 368 #if __DARWIN_UNIX03 |
| 406 state.pc = reinterpret_cast<Address>(mcontext->__ss.__rip); | 369 state.pc = reinterpret_cast<Address>(mcontext->__ss.__rip); |
| 407 state.sp = reinterpret_cast<Address>(mcontext->__ss.__rsp); | 370 state.sp = reinterpret_cast<Address>(mcontext->__ss.__rsp); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 #endif // USE_SIMULATOR | 696 #endif // USE_SIMULATOR |
| 734 SampleStack(state); | 697 SampleStack(state); |
| 735 } | 698 } |
| 736 ResumeThread(profiled_thread); | 699 ResumeThread(profiled_thread); |
| 737 } | 700 } |
| 738 | 701 |
| 739 #endif // USE_SIGNALS | 702 #endif // USE_SIGNALS |
| 740 | 703 |
| 741 | 704 |
| 742 } } // namespace v8::internal | 705 } } // namespace v8::internal |
| OLD | NEW |