OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Column not specified set script break point on line. | 225 // Column not specified set script break point on line. |
226 OS::SNPrintF(buffer, | 226 OS::SNPrintF(buffer, |
227 "debug.Debug.setScriptBreakPointById(%d,%d)", | 227 "debug.Debug.setScriptBreakPointById(%d,%d)", |
228 script_id, line); | 228 script_id, line); |
229 } | 229 } |
230 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 230 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
231 { | 231 { |
232 v8::TryCatch try_catch; | 232 v8::TryCatch try_catch; |
233 v8::Handle<v8::String> str = v8::String::New(buffer.start()); | 233 v8::Handle<v8::String> str = v8::String::New(buffer.start()); |
234 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); | 234 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
235 ASSERT(!try_catch.HasCaught()); | 235 CHECK(!try_catch.HasCaught()); |
236 return value->Int32Value(); | 236 return value->Int32Value(); |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 | 240 |
241 // Set a break point in a script identified by name using the global Debug | 241 // Set a break point in a script identified by name using the global Debug |
242 // object. | 242 // object. |
243 static int SetScriptBreakPointByNameFromJS(const char* script_name, | 243 static int SetScriptBreakPointByNameFromJS(const char* script_name, |
244 int line, int column) { | 244 int line, int column) { |
245 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; | 245 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer; |
246 if (column >= 0) { | 246 if (column >= 0) { |
247 // Column specified set script break point on precise location. | 247 // Column specified set script break point on precise location. |
248 OS::SNPrintF(buffer, | 248 OS::SNPrintF(buffer, |
249 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)", | 249 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)", |
250 script_name, line, column); | 250 script_name, line, column); |
251 } else { | 251 } else { |
252 // Column not specified set script break point on line. | 252 // Column not specified set script break point on line. |
253 OS::SNPrintF(buffer, | 253 OS::SNPrintF(buffer, |
254 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)", | 254 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)", |
255 script_name, line); | 255 script_name, line); |
256 } | 256 } |
257 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; | 257 buffer[SMALL_STRING_BUFFER_SIZE - 1] = '\0'; |
258 { | 258 { |
259 v8::TryCatch try_catch; | 259 v8::TryCatch try_catch; |
260 v8::Handle<v8::String> str = v8::String::New(buffer.start()); | 260 v8::Handle<v8::String> str = v8::String::New(buffer.start()); |
261 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); | 261 v8::Handle<v8::Value> value = v8::Script::Compile(str)->Run(); |
262 ASSERT(!try_catch.HasCaught()); | 262 CHECK(!try_catch.HasCaught()); |
263 return value->Int32Value(); | 263 return value->Int32Value(); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 | 267 |
268 // Clear a break point. | 268 // Clear a break point. |
269 static void ClearBreakPoint(int break_point) { | 269 static void ClearBreakPoint(int break_point) { |
270 Debug::ClearBreakPoint( | 270 Debug::ClearBreakPoint( |
271 Handle<Object>(v8::internal::Smi::FromInt(break_point))); | 271 Handle<Object>(v8::internal::Smi::FromInt(break_point))); |
272 } | 272 } |
(...skipping 2665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2938 // Get rid of the debug event listener. | 2938 // Get rid of the debug event listener. |
2939 v8::Debug::SetDebugEventListener(NULL); | 2939 v8::Debug::SetDebugEventListener(NULL); |
2940 CheckDebuggerUnloaded(); | 2940 CheckDebuggerUnloaded(); |
2941 } | 2941 } |
2942 | 2942 |
2943 | 2943 |
2944 TEST(DebugBreak) { | 2944 TEST(DebugBreak) { |
2945 v8::HandleScope scope; | 2945 v8::HandleScope scope; |
2946 DebugLocalContext env; | 2946 DebugLocalContext env; |
2947 | 2947 |
2948 // This test should be run with option --verify-heap. This is an ASSERT and | 2948 // This test should be run with option --verify-heap. As --verify-heap is |
2949 // not a CHECK as --verify-heap is only available in debug mode. | 2949 // only available in debug mode only check for it in that case. |
2950 ASSERT(v8::internal::FLAG_verify_heap); | 2950 #ifdef DEBUG |
| 2951 CHECK(v8::internal::FLAG_verify_heap); |
| 2952 #endif |
2951 | 2953 |
2952 // Register a debug event listener which sets the break flag and counts. | 2954 // Register a debug event listener which sets the break flag and counts. |
2953 v8::Debug::SetDebugEventListener(DebugEventBreak); | 2955 v8::Debug::SetDebugEventListener(DebugEventBreak); |
2954 | 2956 |
2955 // Create a function for testing stepping. | 2957 // Create a function for testing stepping. |
2956 const char* src = "function f0() {}" | 2958 const char* src = "function f0() {}" |
2957 "function f1(x1) {}" | 2959 "function f1(x1) {}" |
2958 "function f2(x1,x2) {}" | 2960 "function f2(x1,x2) {}" |
2959 "function f3(x1,x2,x3) {}"; | 2961 "function f3(x1,x2,x3) {}"; |
2960 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); | 2962 v8::Local<v8::Function> f0 = CompileFunction(&env, src, "f0"); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3354 // Do not call, due to race condition with Wait(). | 3356 // Do not call, due to race condition with Wait(). |
3355 // Could be resolved with Pthread condition variables. | 3357 // Could be resolved with Pthread condition variables. |
3356 ThreadBarrier::~ThreadBarrier() { | 3358 ThreadBarrier::~ThreadBarrier() { |
3357 lock_->Lock(); | 3359 lock_->Lock(); |
3358 delete lock_; | 3360 delete lock_; |
3359 delete sem_; | 3361 delete sem_; |
3360 } | 3362 } |
3361 | 3363 |
3362 void ThreadBarrier::Wait() { | 3364 void ThreadBarrier::Wait() { |
3363 lock_->Lock(); | 3365 lock_->Lock(); |
3364 ASSERT(!invalid_); | 3366 CHECK(!invalid_); |
3365 if (num_blocked_ == num_threads_ - 1) { | 3367 if (num_blocked_ == num_threads_ - 1) { |
3366 // Signal and unblock all waiting threads. | 3368 // Signal and unblock all waiting threads. |
3367 for (int i = 0; i < num_threads_ - 1; ++i) { | 3369 for (int i = 0; i < num_threads_ - 1; ++i) { |
3368 sem_->Signal(); | 3370 sem_->Signal(); |
3369 } | 3371 } |
3370 invalid_ = true; | 3372 invalid_ = true; |
3371 printf("BARRIER\n\n"); | 3373 printf("BARRIER\n\n"); |
3372 fflush(stdout); | 3374 fflush(stdout); |
3373 lock_->Unlock(); | 3375 lock_->Unlock(); |
3374 } else { // Wait for the semaphore. | 3376 } else { // Wait for the semaphore. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3559 TEST(MessageQueueExpandAndDestroy) { | 3561 TEST(MessageQueueExpandAndDestroy) { |
3560 TestClientData::ResetCounters(); | 3562 TestClientData::ResetCounters(); |
3561 { // Create a scope for the queue. | 3563 { // Create a scope for the queue. |
3562 CommandMessageQueue queue(1); | 3564 CommandMessageQueue queue(1); |
3563 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3565 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3564 new TestClientData())); | 3566 new TestClientData())); |
3565 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3567 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3566 new TestClientData())); | 3568 new TestClientData())); |
3567 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3569 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3568 new TestClientData())); | 3570 new TestClientData())); |
3569 ASSERT_EQ(0, TestClientData::destructor_call_counter); | 3571 CHECK_EQ(0, TestClientData::destructor_call_counter); |
3570 queue.Get().Dispose(); | 3572 queue.Get().Dispose(); |
3571 ASSERT_EQ(1, TestClientData::destructor_call_counter); | 3573 CHECK_EQ(1, TestClientData::destructor_call_counter); |
3572 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3574 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3573 new TestClientData())); | 3575 new TestClientData())); |
3574 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3576 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3575 new TestClientData())); | 3577 new TestClientData())); |
3576 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3578 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3577 new TestClientData())); | 3579 new TestClientData())); |
3578 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3580 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3579 new TestClientData())); | 3581 new TestClientData())); |
3580 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), | 3582 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(), |
3581 new TestClientData())); | 3583 new TestClientData())); |
3582 ASSERT_EQ(1, TestClientData::destructor_call_counter); | 3584 CHECK_EQ(1, TestClientData::destructor_call_counter); |
3583 queue.Get().Dispose(); | 3585 queue.Get().Dispose(); |
3584 ASSERT_EQ(2, TestClientData::destructor_call_counter); | 3586 CHECK_EQ(2, TestClientData::destructor_call_counter); |
3585 } | 3587 } |
3586 // All the client data should be destroyed when the queue is destroyed. | 3588 // All the client data should be destroyed when the queue is destroyed. |
3587 ASSERT_EQ(TestClientData::destructor_call_counter, | 3589 CHECK_EQ(TestClientData::destructor_call_counter, |
3588 TestClientData::destructor_call_counter); | 3590 TestClientData::destructor_call_counter); |
3589 } | 3591 } |
3590 | 3592 |
3591 | 3593 |
3592 static int handled_client_data_instances_count = 0; | 3594 static int handled_client_data_instances_count = 0; |
3593 static void MessageHandlerCountingClientData( | 3595 static void MessageHandlerCountingClientData( |
3594 const uint16_t* message, | 3596 const uint16_t* message, |
3595 int length, | 3597 int length, |
3596 v8::Debug::ClientData* client_data) { | 3598 v8::Debug::ClientData* client_data) { |
3597 if (client_data) { | 3599 if (client_data) { |
3598 handled_client_data_instances_count++; | 3600 handled_client_data_instances_count++; |
(...skipping 29 matching lines...) Expand all Loading... |
3628 | 3630 |
3629 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), | 3631 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), |
3630 new TestClientData()); | 3632 new TestClientData()); |
3631 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); | 3633 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); |
3632 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), | 3634 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), |
3633 new TestClientData()); | 3635 new TestClientData()); |
3634 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), | 3636 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), |
3635 new TestClientData()); | 3637 new TestClientData()); |
3636 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 3638 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
3637 CompileRun(source_1); | 3639 CompileRun(source_1); |
3638 ASSERT_EQ(3, TestClientData::constructor_call_counter); | 3640 CHECK_EQ(3, TestClientData::constructor_call_counter); |
3639 ASSERT_EQ(TestClientData::constructor_call_counter, | 3641 CHECK_EQ(TestClientData::constructor_call_counter, |
3640 handled_client_data_instances_count); | 3642 handled_client_data_instances_count); |
3641 ASSERT_EQ(TestClientData::constructor_call_counter, | 3643 CHECK_EQ(TestClientData::constructor_call_counter, |
3642 TestClientData::destructor_call_counter); | 3644 TestClientData::destructor_call_counter); |
3643 } | 3645 } |
3644 | 3646 |
3645 | 3647 |
3646 /* Test ThreadedDebugging */ | 3648 /* Test ThreadedDebugging */ |
3647 /* This test interrupts a running infinite loop that is | 3649 /* This test interrupts a running infinite loop that is |
3648 * occupying the v8 thread by a break command from the | 3650 * occupying the v8 thread by a break command from the |
3649 * debugger thread. It then changes the value of a | 3651 * debugger thread. It then changes the value of a |
3650 * global object, to make the loop terminate. | 3652 * global object, to make the loop terminate. |
3651 */ | 3653 */ |
3652 | 3654 |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4569 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); | 4571 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); |
4570 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 4572 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
4571 script2->Run(); | 4573 script2->Run(); |
4572 script2->SetData(data_obj); | 4574 script2->SetData(data_obj); |
4573 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 4575 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
4574 f->Call(env->Global(), 0, NULL); | 4576 f->Call(env->Global(), 0, NULL); |
4575 CHECK_EQ(2, break_point_hit_count); | 4577 CHECK_EQ(2, break_point_hit_count); |
4576 CHECK_EQ("new name", last_script_name_hit); | 4578 CHECK_EQ("new name", last_script_name_hit); |
4577 CHECK_EQ("abc 123", last_script_data_hit); | 4579 CHECK_EQ("abc 123", last_script_data_hit); |
4578 } | 4580 } |
OLD | NEW |