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 3418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3429 | 3429 |
3430 static void MessageHandler(const uint16_t* message, int length, | 3430 static void MessageHandler(const uint16_t* message, int length, |
3431 v8::Debug::ClientData* client_data) { | 3431 v8::Debug::ClientData* client_data) { |
3432 static char print_buffer[1000]; | 3432 static char print_buffer[1000]; |
3433 Utf16ToAscii(message, length, print_buffer); | 3433 Utf16ToAscii(message, length, print_buffer); |
3434 if (IsBreakEventMessage(print_buffer)) { | 3434 if (IsBreakEventMessage(print_buffer)) { |
3435 // Lets test script wait until break occurs to send commands. | 3435 // Lets test script wait until break occurs to send commands. |
3436 // Signals when a break is reported. | 3436 // Signals when a break is reported. |
3437 message_queue_barriers.semaphore_2->Signal(); | 3437 message_queue_barriers.semaphore_2->Signal(); |
3438 } | 3438 } |
| 3439 |
3439 // Allow message handler to block on a semaphore, to test queueing of | 3440 // Allow message handler to block on a semaphore, to test queueing of |
3440 // messages while blocked. | 3441 // messages while blocked. |
3441 message_queue_barriers.semaphore_1->Wait(); | 3442 message_queue_barriers.semaphore_1->Wait(); |
3442 printf("%s\n", print_buffer); | 3443 printf("%s\n", print_buffer); |
3443 fflush(stdout); | 3444 fflush(stdout); |
3444 } | 3445 } |
3445 | 3446 |
3446 void MessageQueueDebuggerThread::Run() { | 3447 void MessageQueueDebuggerThread::Run() { |
3447 const int kBufferSize = 1000; | 3448 const int kBufferSize = 1000; |
3448 uint16_t buffer_1[kBufferSize]; | 3449 uint16_t buffer_1[kBufferSize]; |
(...skipping 18 matching lines...) Expand all Loading... |
3467 "\"type\":\"request\"," | 3468 "\"type\":\"request\"," |
3468 "\"command\":\"continue\"}"; | 3469 "\"command\":\"continue\"}"; |
3469 const char* command_single_step = | 3470 const char* command_single_step = |
3470 "{\"seq\":107," | 3471 "{\"seq\":107," |
3471 "\"type\":\"request\"," | 3472 "\"type\":\"request\"," |
3472 "\"command\":\"continue\"," | 3473 "\"command\":\"continue\"," |
3473 "\"arguments\":{\"stepaction\":\"next\"}}"; | 3474 "\"arguments\":{\"stepaction\":\"next\"}}"; |
3474 | 3475 |
3475 /* Interleaved sequence of actions by the two threads:*/ | 3476 /* Interleaved sequence of actions by the two threads:*/ |
3476 // Main thread compiles and runs source_1 | 3477 // Main thread compiles and runs source_1 |
| 3478 message_queue_barriers.semaphore_1->Signal(); |
3477 message_queue_barriers.barrier_1.Wait(); | 3479 message_queue_barriers.barrier_1.Wait(); |
3478 // Post 6 commands, filling the command queue and making it expand. | 3480 // Post 6 commands, filling the command queue and making it expand. |
3479 // These calls return immediately, but the commands stay on the queue | 3481 // These calls return immediately, but the commands stay on the queue |
3480 // until the execution of source_2. | 3482 // until the execution of source_2. |
3481 // Note: AsciiToUtf16 executes before SendCommand, so command is copied | 3483 // Note: AsciiToUtf16 executes before SendCommand, so command is copied |
3482 // to buffer before buffer is sent to SendCommand. | 3484 // to buffer before buffer is sent to SendCommand. |
3483 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); | 3485 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); |
3484 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); | 3486 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); |
3485 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); | 3487 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); |
3486 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); | 3488 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); |
3487 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); | 3489 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); |
3488 message_queue_barriers.barrier_2.Wait(); | 3490 message_queue_barriers.barrier_2.Wait(); |
3489 // Main thread compiles and runs source_2. | 3491 // Main thread compiles and runs source_2. |
3490 // Queued commands are executed at the start of compilation of source_2. | 3492 // Queued commands are executed at the start of compilation of source_2( |
3491 message_queue_barriers.barrier_3.Wait(); | 3493 // beforeCompile event). |
3492 // Free the message handler to process all the messages from the queue. | 3494 // Free the message handler to process all the messages from the queue. 7 |
3493 for (int i = 0; i < 20 ; ++i) { | 3495 // messages are expected: 2 afterCompile events and 5 responses. |
| 3496 // All the commands added so far will fail to execute as long as call stack |
| 3497 // is empty on beforeCompile event. |
| 3498 for (int i = 0; i < 6 ; ++i) { |
3494 message_queue_barriers.semaphore_1->Signal(); | 3499 message_queue_barriers.semaphore_1->Signal(); |
3495 } | 3500 } |
| 3501 message_queue_barriers.barrier_3.Wait(); |
3496 // Main thread compiles and runs source_3. | 3502 // Main thread compiles and runs source_3. |
| 3503 // Don't stop in the afterCompile handler. |
| 3504 message_queue_barriers.semaphore_1->Signal(); |
3497 // source_3 includes a debugger statement, which causes a break event. | 3505 // source_3 includes a debugger statement, which causes a break event. |
3498 // Wait on break event from hitting "debugger" statement | 3506 // Wait on break event from hitting "debugger" statement |
3499 message_queue_barriers.semaphore_2->Wait(); | 3507 message_queue_barriers.semaphore_2->Wait(); |
3500 // These should execute after the "debugger" statement in source_2 | 3508 // These should execute after the "debugger" statement in source_2 |
| 3509 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); |
| 3510 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); |
| 3511 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); |
3501 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2)); | 3512 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2)); |
| 3513 // Run after 2 break events, 4 responses. |
| 3514 for (int i = 0; i < 6 ; ++i) { |
| 3515 message_queue_barriers.semaphore_1->Signal(); |
| 3516 } |
3502 // Wait on break event after a single step executes. | 3517 // Wait on break event after a single step executes. |
3503 message_queue_barriers.semaphore_2->Wait(); | 3518 message_queue_barriers.semaphore_2->Wait(); |
3504 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1)); | 3519 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1)); |
3505 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2)); | 3520 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2)); |
| 3521 // Run after 2 responses. |
| 3522 for (int i = 0; i < 2 ; ++i) { |
| 3523 message_queue_barriers.semaphore_1->Signal(); |
| 3524 } |
3506 // Main thread continues running source_3 to end, waits for this thread. | 3525 // Main thread continues running source_3 to end, waits for this thread. |
3507 } | 3526 } |
3508 | 3527 |
3509 MessageQueueDebuggerThread message_queue_debugger_thread; | 3528 MessageQueueDebuggerThread message_queue_debugger_thread; |
3510 | 3529 |
3511 // This thread runs the v8 engine. | 3530 // This thread runs the v8 engine. |
3512 TEST(MessageQueues) { | 3531 TEST(MessageQueues) { |
3513 // Create a V8 environment | 3532 // Create a V8 environment |
3514 v8::HandleScope scope; | 3533 v8::HandleScope scope; |
3515 DebugLocalContext env; | 3534 DebugLocalContext env; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3603 | 3622 |
3604 | 3623 |
3605 // Tests that all client data passed to the debugger are sent to the handler. | 3624 // Tests that all client data passed to the debugger are sent to the handler. |
3606 TEST(SendClientDataToHandler) { | 3625 TEST(SendClientDataToHandler) { |
3607 // Create a V8 environment | 3626 // Create a V8 environment |
3608 v8::HandleScope scope; | 3627 v8::HandleScope scope; |
3609 DebugLocalContext env; | 3628 DebugLocalContext env; |
3610 TestClientData::ResetCounters(); | 3629 TestClientData::ResetCounters(); |
3611 handled_client_data_instances_count = 0; | 3630 handled_client_data_instances_count = 0; |
3612 v8::Debug::SetMessageHandler(MessageHandlerCountingClientData); | 3631 v8::Debug::SetMessageHandler(MessageHandlerCountingClientData); |
3613 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5; debugger;"; | 3632 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; |
3614 const int kBufferSize = 1000; | 3633 const int kBufferSize = 1000; |
3615 uint16_t buffer[kBufferSize]; | 3634 uint16_t buffer[kBufferSize]; |
3616 const char* command_1 = | 3635 const char* command_1 = |
3617 "{\"seq\":117," | 3636 "{\"seq\":117," |
3618 "\"type\":\"request\"," | 3637 "\"type\":\"request\"," |
3619 "\"command\":\"evaluate\"," | 3638 "\"command\":\"evaluate\"," |
3620 "\"arguments\":{\"expression\":\"1+2\"}}"; | 3639 "\"arguments\":{\"expression\":\"1+2\"}}"; |
3621 const char* command_2 = | 3640 const char* command_2 = |
3622 "{\"seq\":118," | 3641 "{\"seq\":118," |
3623 "\"type\":\"request\"," | 3642 "\"type\":\"request\"," |
3624 "\"command\":\"evaluate\"," | 3643 "\"command\":\"evaluate\"," |
3625 "\"arguments\":{\"expression\":\"1+a\"}}"; | 3644 "\"arguments\":{\"expression\":\"1+a\"}}"; |
3626 const char* command_continue = | 3645 const char* command_continue = |
3627 "{\"seq\":106," | 3646 "{\"seq\":106," |
3628 "\"type\":\"request\"," | 3647 "\"type\":\"request\"," |
3629 "\"command\":\"continue\"}"; | 3648 "\"command\":\"continue\"}"; |
3630 | 3649 |
3631 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), | 3650 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), |
3632 new TestClientData()); | 3651 new TestClientData()); |
3633 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); | 3652 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); |
3634 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), | 3653 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), |
3635 new TestClientData()); | 3654 new TestClientData()); |
3636 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), | 3655 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), |
3637 new TestClientData()); | 3656 new TestClientData()); |
| 3657 // All the messages will be processed on beforeCompile event. |
| 3658 CompileRun(source_1); |
3638 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 3659 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
3639 CompileRun(source_1); | |
3640 CHECK_EQ(3, TestClientData::constructor_call_counter); | 3660 CHECK_EQ(3, TestClientData::constructor_call_counter); |
3641 CHECK_EQ(TestClientData::constructor_call_counter, | 3661 CHECK_EQ(TestClientData::constructor_call_counter, |
3642 handled_client_data_instances_count); | 3662 handled_client_data_instances_count); |
3643 CHECK_EQ(TestClientData::constructor_call_counter, | 3663 CHECK_EQ(TestClientData::constructor_call_counter, |
3644 TestClientData::destructor_call_counter); | 3664 TestClientData::destructor_call_counter); |
3645 } | 3665 } |
3646 | 3666 |
3647 | 3667 |
3648 /* Test ThreadedDebugging */ | 3668 /* Test ThreadedDebugging */ |
3649 /* This test interrupts a running infinite loop that is | 3669 /* This test interrupts a running infinite loop that is |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4571 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); | 4591 v8::ScriptOrigin origin2 = v8::ScriptOrigin(v8::String::New("new name")); |
4572 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); | 4592 v8::Handle<v8::Script> script2 = v8::Script::Compile(script, &origin2); |
4573 script2->Run(); | 4593 script2->Run(); |
4574 script2->SetData(data_obj); | 4594 script2->SetData(data_obj); |
4575 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 4595 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
4576 f->Call(env->Global(), 0, NULL); | 4596 f->Call(env->Global(), 0, NULL); |
4577 CHECK_EQ(2, break_point_hit_count); | 4597 CHECK_EQ(2, break_point_hit_count); |
4578 CHECK_EQ("new name", last_script_name_hit); | 4598 CHECK_EQ("new name", last_script_name_hit); |
4579 CHECK_EQ("abc 123", last_script_data_hit); | 4599 CHECK_EQ("abc 123", last_script_data_hit); |
4580 } | 4600 } |
OLD | NEW |