Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/cctest/test-debug.cc

Issue 1321543004: [futex] Allow debugger to break in the middle of a futexWait Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: enable debugging scope Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/debug/debug.cc ('K') | « src/futex-emulation.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 18 matching lines...) Expand all
29 29
30 #include "src/v8.h" 30 #include "src/v8.h"
31 31
32 #include "src/api.h" 32 #include "src/api.h"
33 #include "src/base/platform/condition-variable.h" 33 #include "src/base/platform/condition-variable.h"
34 #include "src/base/platform/platform.h" 34 #include "src/base/platform/platform.h"
35 #include "src/compilation-cache.h" 35 #include "src/compilation-cache.h"
36 #include "src/debug/debug.h" 36 #include "src/debug/debug.h"
37 #include "src/deoptimizer.h" 37 #include "src/deoptimizer.h"
38 #include "src/frames.h" 38 #include "src/frames.h"
39 #include "src/futex-emulation.h"
39 #include "src/utils.h" 40 #include "src/utils.h"
40 #include "test/cctest/cctest.h" 41 #include "test/cctest/cctest.h"
41 42
42 43
43 using ::v8::base::Mutex; 44 using ::v8::base::Mutex;
44 using ::v8::base::LockGuard; 45 using ::v8::base::LockGuard;
45 using ::v8::base::ConditionVariable; 46 using ::v8::base::ConditionVariable;
46 using ::v8::base::OS; 47 using ::v8::base::OS;
47 using ::v8::base::Semaphore; 48 using ::v8::base::Semaphore;
48 using ::v8::internal::EmbeddedVector; 49 using ::v8::internal::EmbeddedVector;
(...skipping 7570 matching lines...) Expand 10 before | Expand all | Expand 10 after
7619 "let y = 2; \n" 7620 "let y = 2; \n"
7620 "debugger; \n" 7621 "debugger; \n"
7621 "x * y", 7622 "x * y",
7622 30); 7623 30);
7623 ExpectInt32( 7624 ExpectInt32(
7624 "x = 1; y = 2; \n" 7625 "x = 1; y = 2; \n"
7625 "debugger;" 7626 "debugger;"
7626 "x * y", 7627 "x * y",
7627 30); 7628 30);
7628 } 7629 }
7630
7631
7632 Barriers futex_barriers;
7633
7634
7635 class FutexV8Thread : public v8::base::Thread {
7636 public:
7637 FutexV8Thread(void* sab_data, size_t sab_size)
7638 : Thread(Options("V8Thread")), sab_data_(sab_data), sab_size_(sab_size) {}
7639 void Run();
7640 v8::Isolate* isolate() { return isolate_; }
7641
7642 private:
7643 v8::Isolate* isolate_;
7644 void* sab_data_;
7645 size_t sab_size_;
7646 };
7647
7648
7649 class FutexDebuggerThread : public v8::base::Thread {
7650 public:
7651 explicit FutexDebuggerThread(v8::Isolate* v8_isolate, void* sab_data,
7652 size_t sab_size)
7653 : Thread(Options("DebuggerThread")),
7654 v8_isolate_(v8_isolate),
7655 sab_data_(sab_data),
7656 sab_size_(sab_size) {}
7657 void Run();
7658
7659 private:
7660 v8::Isolate* v8_isolate_;
7661 void* sab_data_;
7662 size_t sab_size_;
7663 };
7664
7665
7666 static void FutexMessageHandler(const v8::Debug::Message& message) {
7667 static char print_buffer[1000];
7668 v8::String::Value json(message.GetJSON());
7669 Utf16ToAscii(*json, json.length(), print_buffer);
7670 if (IsBreakEventMessage(print_buffer)) {
7671 // Check that we are inside the futex.
7672 int source_line = GetSourceLineFromBreakEventMessage(print_buffer);
7673 CHECK(source_line == 1);
7674 futex_barriers.barrier_2.Wait();
7675 }
7676 }
7677
7678
7679 void FutexV8Thread::Run() {
7680 const char* source =
7681 "var i32a = new Int32Array(sab);\n"
7682 "Atomics.futexWait(i32a, 0, 0, Infinity)\n";
7683
7684 v8::Isolate::CreateParams create_params;
7685 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
7686 isolate_ = v8::Isolate::New(create_params);
7687 futex_barriers.barrier_3.Wait();
7688 {
7689 v8::Isolate::Scope isolate_scope(isolate_);
7690 DebugLocalContext env(isolate_);
7691 v8::HandleScope scope(isolate_);
7692 v8::Debug::SetMessageHandler(&FutexMessageHandler);
7693 v8::Handle<v8::ObjectTemplate> global_template =
7694 v8::ObjectTemplate::New(env->GetIsolate());
7695 global_template->Set(
7696 v8::String::NewFromUtf8(env->GetIsolate(), "sab"),
7697 v8::SharedArrayBuffer::New(isolate_, sab_data_, sab_size_));
7698
7699 v8::Handle<v8::Context> context =
7700 v8::Context::New(isolate_, NULL, global_template);
7701 v8::Context::Scope context_scope(context);
7702
7703 CompileRun(source);
7704 }
7705 futex_barriers.barrier_4.Wait();
7706 isolate_->Dispose();
7707 }
7708
7709
7710 void FutexDebuggerThread::Run() {
7711 v8::Isolate::CreateParams create_params;
7712 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
7713 v8::Isolate* debug_isolate = v8::Isolate::New(create_params);
7714 {
7715 v8::Isolate::Scope isolate_scope(debug_isolate);
7716 DebugLocalContext env(debug_isolate);
7717 v8::HandleScope scope(debug_isolate);
7718 v8::Handle<v8::SharedArrayBuffer> sab(
7719 v8::SharedArrayBuffer::New(debug_isolate, sab_data_, sab_size_));
7720
7721 i::Handle<i::JSArrayBuffer> i_sab = v8::Utils::OpenHandle(*sab);
7722 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(debug_isolate);
7723 // Spin loop until v8 thread is waiting on futex.
7724 while (true) {
7725 i::Object* num_waiters =
7726 i::FutexEmulation::NumWaitersForTesting(i_isolate, i_sab, 0);
7727 if (num_waiters->IsSmi() && i::Smi::cast(num_waiters)->value() > 0) {
7728 break;
7729 }
7730 }
7731
7732 v8::Debug::DebugBreak(v8_isolate_);
7733 futex_barriers.barrier_2.Wait();
7734
7735 i::FutexEmulation::Wake(i_isolate, i_sab, 0, 1);
7736 {
7737 const int kBufferSize = 1000;
7738 uint16_t buffer[kBufferSize];
7739 const char* command_continue =
7740 "{\"seq\":0,"
7741 "\"type\":\"request\","
7742 "\"command\":\"continue\"}";
7743
7744 v8::Debug::SendCommand(v8_isolate_, buffer,
7745 AsciiToUtf16(command_continue, buffer));
7746 }
7747 futex_barriers.barrier_4.Wait();
7748 }
7749 debug_isolate->Dispose();
7750 }
7751
7752
7753 TEST(FutexDebugging) {
7754 i::FLAG_harmony_sharedarraybuffer = true;
7755 i::FLAG_harmony_atomics = true;
7756
7757 size_t size = 16;
7758 v8::ArrayBuffer::Allocator* array_buffer_allocator =
7759 CcTest::array_buffer_allocator();
7760 void* data = array_buffer_allocator->Allocate(size);
7761
7762 FutexV8Thread v8_thread(data, size);
7763
7764 // Create a V8 environment
7765 v8_thread.Start();
7766 futex_barriers.barrier_3.Wait();
7767 FutexDebuggerThread debugger_thread(v8_thread.isolate(), data, size);
7768 debugger_thread.Start();
7769
7770 v8_thread.Join();
7771 debugger_thread.Join();
7772 array_buffer_allocator->Free(data, size);
7773 }
OLDNEW
« src/debug/debug.cc ('K') | « src/futex-emulation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698