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 3521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3532 // We match parts of the message to decide if it is a break message. | 3532 // We match parts of the message to decide if it is a break message. |
3533 bool IsBreakEventMessage(char *message) { | 3533 bool IsBreakEventMessage(char *message) { |
3534 const char* type_event = "\"type\":\"event\""; | 3534 const char* type_event = "\"type\":\"event\""; |
3535 const char* event_break = "\"event\":\"break\""; | 3535 const char* event_break = "\"event\":\"break\""; |
3536 // Does the message contain both type:event and event:break? | 3536 // Does the message contain both type:event and event:break? |
3537 return strstr(message, type_event) != NULL && | 3537 return strstr(message, type_event) != NULL && |
3538 strstr(message, event_break) != NULL; | 3538 strstr(message, event_break) != NULL; |
3539 } | 3539 } |
3540 | 3540 |
3541 | 3541 |
| 3542 // We match parts of the message to decide if it is a exception message. |
| 3543 bool IsExceptionEventMessage(char *message) { |
| 3544 const char* type_event = "\"type\":\"event\""; |
| 3545 const char* event_exception = "\"event\":\"exception\""; |
| 3546 // Does the message contain both type:event and event:exception? |
| 3547 return strstr(message, type_event) != NULL && |
| 3548 strstr(message, event_exception) != NULL; |
| 3549 } |
| 3550 |
| 3551 |
| 3552 // We match the message wether it is an evaluate response message. |
| 3553 bool IsEvaluateResponseMessage(char* message) { |
| 3554 const char* type_response = "\"type\":\"response\""; |
| 3555 const char* command_evaluate = "\"command\":\"evaluate\""; |
| 3556 // Does the message contain both type:response and command:evaluate? |
| 3557 return strstr(message, type_response) != NULL && |
| 3558 strstr(message, command_evaluate) != NULL; |
| 3559 } |
| 3560 |
| 3561 |
| 3562 // We match parts of the message to get evaluate result int value. |
| 3563 int GetEvaluateIntResult(char *message) { |
| 3564 const char* value = "\"value\":"; |
| 3565 char* pos = strstr(message, value); |
| 3566 if (pos == NULL) { |
| 3567 return -1; |
| 3568 } |
| 3569 int res = -1; |
| 3570 sscanf(pos + strlen(value), "%d", &res); |
| 3571 return res; |
| 3572 } |
| 3573 |
| 3574 |
| 3575 // We match parts of the message to get hit breakpoint id. |
| 3576 int GetBreakpointIdFromBreakEventMessage(char *message) { |
| 3577 const char* breakpoints = "\"breakpoints\":["; |
| 3578 char* pos = strstr(message, breakpoints); |
| 3579 if (pos == NULL) { |
| 3580 return -1; |
| 3581 } |
| 3582 int res = -1; |
| 3583 sscanf(pos + strlen(breakpoints), "%d", &res); |
| 3584 return res; |
| 3585 } |
| 3586 |
| 3587 |
3542 /* Test MessageQueues */ | 3588 /* Test MessageQueues */ |
3543 /* Tests the message queues that hold debugger commands and | 3589 /* Tests the message queues that hold debugger commands and |
3544 * response messages to the debugger. Fills queues and makes | 3590 * response messages to the debugger. Fills queues and makes |
3545 * them grow. | 3591 * them grow. |
3546 */ | 3592 */ |
3547 Barriers message_queue_barriers; | 3593 Barriers message_queue_barriers; |
3548 | 3594 |
3549 // This is the debugger thread, that executes no v8 calls except | 3595 // This is the debugger thread, that executes no v8 calls except |
3550 // placing JSON debugger commands in the queue. | 3596 // placing JSON debugger commands in the queue. |
3551 class MessageQueueDebuggerThread : public v8::internal::Thread { | 3597 class MessageQueueDebuggerThread : public v8::internal::Thread { |
3552 public: | 3598 public: |
3553 void Run(); | 3599 void Run(); |
3554 }; | 3600 }; |
3555 | 3601 |
3556 static void MessageHandler(const uint16_t* message, int length, | 3602 static void MessageHandler(const uint16_t* message, int length, |
3557 v8::Debug::ClientData* client_data) { | 3603 v8::Debug::ClientData* client_data) { |
3558 static char print_buffer[1000]; | 3604 static char print_buffer[1000]; |
3559 Utf16ToAscii(message, length, print_buffer); | 3605 Utf16ToAscii(message, length, print_buffer); |
3560 if (IsBreakEventMessage(print_buffer)) { | 3606 if (IsBreakEventMessage(print_buffer)) { |
3561 // Lets test script wait until break occurs to send commands. | 3607 // Lets test script wait until break occurs to send commands. |
3562 // Signals when a break is reported. | 3608 // Signals when a break is reported. |
3563 message_queue_barriers.semaphore_2->Signal(); | 3609 message_queue_barriers.semaphore_2->Signal(); |
3564 } | 3610 } |
3565 | 3611 |
3566 // Allow message handler to block on a semaphore, to test queueing of | 3612 // Allow message handler to block on a semaphore, to test queueing of |
3567 // messages while blocked. | 3613 // messages while blocked. |
3568 message_queue_barriers.semaphore_1->Wait(); | 3614 message_queue_barriers.semaphore_1->Wait(); |
3569 printf("%s\n", print_buffer); | |
3570 fflush(stdout); | |
3571 } | 3615 } |
3572 | 3616 |
3573 void MessageQueueDebuggerThread::Run() { | 3617 void MessageQueueDebuggerThread::Run() { |
3574 const int kBufferSize = 1000; | 3618 const int kBufferSize = 1000; |
3575 uint16_t buffer_1[kBufferSize]; | 3619 uint16_t buffer_1[kBufferSize]; |
3576 uint16_t buffer_2[kBufferSize]; | 3620 uint16_t buffer_2[kBufferSize]; |
3577 const char* command_1 = | 3621 const char* command_1 = |
3578 "{\"seq\":117," | 3622 "{\"seq\":117," |
3579 "\"type\":\"request\"," | 3623 "\"type\":\"request\"," |
3580 "\"command\":\"evaluate\"," | 3624 "\"command\":\"evaluate\"," |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3815 } | 3859 } |
3816 | 3860 |
3817 | 3861 |
3818 static void ThreadedMessageHandler(const v8::Debug::Message& message) { | 3862 static void ThreadedMessageHandler(const v8::Debug::Message& message) { |
3819 static char print_buffer[1000]; | 3863 static char print_buffer[1000]; |
3820 v8::String::Value json(message.GetJSON()); | 3864 v8::String::Value json(message.GetJSON()); |
3821 Utf16ToAscii(*json, json.length(), print_buffer); | 3865 Utf16ToAscii(*json, json.length(), print_buffer); |
3822 if (IsBreakEventMessage(print_buffer)) { | 3866 if (IsBreakEventMessage(print_buffer)) { |
3823 threaded_debugging_barriers.barrier_2.Wait(); | 3867 threaded_debugging_barriers.barrier_2.Wait(); |
3824 } | 3868 } |
3825 printf("%s\n", print_buffer); | |
3826 fflush(stdout); | |
3827 } | 3869 } |
3828 | 3870 |
3829 | 3871 |
3830 void V8Thread::Run() { | 3872 void V8Thread::Run() { |
3831 const char* source = | 3873 const char* source = |
3832 "flag = true;\n" | 3874 "flag = true;\n" |
3833 "function bar( new_value ) {\n" | 3875 "function bar( new_value ) {\n" |
3834 " flag = new_value;\n" | 3876 " flag = new_value;\n" |
3835 " return \"Return from bar(\" + new_value + \")\";\n" | 3877 " return \"Return from bar(\" + new_value + \")\";\n" |
3836 "}\n" | 3878 "}\n" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3904 void Run(); | 3946 void Run(); |
3905 }; | 3947 }; |
3906 | 3948 |
3907 class BreakpointsDebuggerThread : public v8::internal::Thread { | 3949 class BreakpointsDebuggerThread : public v8::internal::Thread { |
3908 public: | 3950 public: |
3909 void Run(); | 3951 void Run(); |
3910 }; | 3952 }; |
3911 | 3953 |
3912 | 3954 |
3913 Barriers* breakpoints_barriers; | 3955 Barriers* breakpoints_barriers; |
| 3956 int break_event_breakpoint_id; |
| 3957 int evaluate_int_result; |
3914 | 3958 |
3915 static void BreakpointsMessageHandler(const v8::Debug::Message& message) { | 3959 static void BreakpointsMessageHandler(const v8::Debug::Message& message) { |
3916 static char print_buffer[1000]; | 3960 static char print_buffer[1000]; |
3917 v8::String::Value json(message.GetJSON()); | 3961 v8::String::Value json(message.GetJSON()); |
3918 Utf16ToAscii(*json, json.length(), print_buffer); | 3962 Utf16ToAscii(*json, json.length(), print_buffer); |
3919 printf("%s\n", print_buffer); | |
3920 fflush(stdout); | |
3921 | 3963 |
3922 // Is break_template a prefix of the message? | |
3923 if (IsBreakEventMessage(print_buffer)) { | 3964 if (IsBreakEventMessage(print_buffer)) { |
| 3965 break_event_breakpoint_id = |
| 3966 GetBreakpointIdFromBreakEventMessage(print_buffer); |
| 3967 breakpoints_barriers->semaphore_1->Signal(); |
| 3968 } else if (IsEvaluateResponseMessage(print_buffer)) { |
| 3969 evaluate_int_result = GetEvaluateIntResult(print_buffer); |
3924 breakpoints_barriers->semaphore_1->Signal(); | 3970 breakpoints_barriers->semaphore_1->Signal(); |
3925 } | 3971 } |
3926 } | 3972 } |
3927 | 3973 |
3928 | 3974 |
3929 void BreakpointsV8Thread::Run() { | 3975 void BreakpointsV8Thread::Run() { |
3930 const char* source_1 = "var y_global = 3;\n" | 3976 const char* source_1 = "var y_global = 3;\n" |
3931 "function cat( new_value ) {\n" | 3977 "function cat( new_value ) {\n" |
3932 " var x = new_value;\n" | 3978 " var x = new_value;\n" |
3933 " y_global = 4;\n" | 3979 " y_global = y_global + 4;\n" |
3934 " x = 3 * x + 1;\n" | 3980 " x = 3 * x + 1;\n" |
3935 " y_global = 5;\n" | 3981 " y_global = y_global + 5;\n" |
3936 " return x;\n" | 3982 " return x;\n" |
3937 "}\n" | 3983 "}\n" |
3938 "\n" | 3984 "\n" |
3939 "function dog() {\n" | 3985 "function dog() {\n" |
3940 " var x = 1;\n" | 3986 " var x = 1;\n" |
3941 " x = y_global;" | 3987 " x = y_global;" |
3942 " var z = 3;" | 3988 " var z = 3;" |
3943 " x += 100;\n" | 3989 " x += 100;\n" |
3944 " return x;\n" | 3990 " return x;\n" |
3945 "}\n" | 3991 "}\n" |
(...skipping 17 matching lines...) Expand all Loading... |
3963 uint16_t buffer[kBufSize]; | 4009 uint16_t buffer[kBufSize]; |
3964 | 4010 |
3965 const char* command_1 = "{\"seq\":101," | 4011 const char* command_1 = "{\"seq\":101," |
3966 "\"type\":\"request\"," | 4012 "\"type\":\"request\"," |
3967 "\"command\":\"setbreakpoint\"," | 4013 "\"command\":\"setbreakpoint\"," |
3968 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; | 4014 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; |
3969 const char* command_2 = "{\"seq\":102," | 4015 const char* command_2 = "{\"seq\":102," |
3970 "\"type\":\"request\"," | 4016 "\"type\":\"request\"," |
3971 "\"command\":\"setbreakpoint\"," | 4017 "\"command\":\"setbreakpoint\"," |
3972 "\"arguments\":{\"type\":\"function\",\"target\":\"dog\",\"line\":3}}"; | 4018 "\"arguments\":{\"type\":\"function\",\"target\":\"dog\",\"line\":3}}"; |
3973 const char* command_3 = "{\"seq\":104," | 4019 const char* command_3 = "{\"seq\":103," |
3974 "\"type\":\"request\"," | 4020 "\"type\":\"request\"," |
3975 "\"command\":\"evaluate\"," | 4021 "\"command\":\"evaluate\"," |
3976 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false}}"; | 4022 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false}}"; |
3977 const char* command_4 = "{\"seq\":105," | 4023 const char* command_4 = "{\"seq\":104," |
3978 "\"type\":\"request\"," | 4024 "\"type\":\"request\"," |
3979 "\"command\":\"evaluate\"," | 4025 "\"command\":\"evaluate\"," |
3980 "\"arguments\":{\"expression\":\"x\",\"disable_break\":true}}"; | 4026 "\"arguments\":{\"expression\":\"x + 1\",\"disable_break\":true}}"; |
3981 const char* command_5 = "{\"seq\":106," | 4027 const char* command_5 = "{\"seq\":105," |
3982 "\"type\":\"request\"," | 4028 "\"type\":\"request\"," |
3983 "\"command\":\"continue\"}"; | 4029 "\"command\":\"continue\"}"; |
3984 const char* command_6 = "{\"seq\":107," | 4030 const char* command_6 = "{\"seq\":106," |
3985 "\"type\":\"request\"," | 4031 "\"type\":\"request\"," |
3986 "\"command\":\"continue\"}"; | 4032 "\"command\":\"continue\"}"; |
3987 const char* command_7 = "{\"seq\":108," | 4033 const char* command_7 = "{\"seq\":107," |
3988 "\"type\":\"request\"," | 4034 "\"type\":\"request\"," |
3989 "\"command\":\"evaluate\"," | 4035 "\"command\":\"evaluate\"," |
3990 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}"; | 4036 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}"; |
3991 const char* command_8 = "{\"seq\":109," | 4037 const char* command_8 = "{\"seq\":108," |
3992 "\"type\":\"request\"," | 4038 "\"type\":\"request\"," |
3993 "\"command\":\"continue\"}"; | 4039 "\"command\":\"continue\"}"; |
3994 | 4040 |
3995 | 4041 |
3996 // v8 thread initializes, runs source_1 | 4042 // v8 thread initializes, runs source_1 |
3997 breakpoints_barriers->barrier_1.Wait(); | 4043 breakpoints_barriers->barrier_1.Wait(); |
3998 // 1:Set breakpoint in cat(). | 4044 // 1:Set breakpoint in cat() (will get id 1). |
3999 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); | 4045 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); |
4000 // 2:Set breakpoint in dog() | 4046 // 2:Set breakpoint in dog() (will get id 2). |
4001 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); | 4047 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); |
4002 breakpoints_barriers->barrier_2.Wait(); | 4048 breakpoints_barriers->barrier_2.Wait(); |
4003 // v8 thread starts compiling source_2. | 4049 // V8 thread starts compiling source_2. |
4004 // Automatic break happens, to run queued commands | 4050 // Automatic break happens, to run queued commands |
4005 // breakpoints_barriers->semaphore_1->Wait(); | 4051 // breakpoints_barriers->semaphore_1->Wait(); |
4006 // Commands 1 through 3 run, thread continues. | 4052 // Commands 1 through 3 run, thread continues. |
4007 // v8 thread runs source_2 to breakpoint in cat(). | 4053 // v8 thread runs source_2 to breakpoint in cat(). |
4008 // message callback receives break event. | 4054 // message callback receives break event. |
4009 breakpoints_barriers->semaphore_1->Wait(); | 4055 breakpoints_barriers->semaphore_1->Wait(); |
| 4056 // Must have hit breakpoint #1. |
| 4057 CHECK_EQ(1, break_event_breakpoint_id); |
4010 // 4:Evaluate dog() (which has a breakpoint). | 4058 // 4:Evaluate dog() (which has a breakpoint). |
4011 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer)); | 4059 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer)); |
4012 // v8 thread hits breakpoint in dog() | 4060 // V8 thread hits breakpoint in dog(). |
4013 breakpoints_barriers->semaphore_1->Wait(); // wait for break event | 4061 breakpoints_barriers->semaphore_1->Wait(); // wait for break event |
4014 // 5:Evaluate x | 4062 // Must have hit breakpoint #2. |
| 4063 CHECK_EQ(2, break_event_breakpoint_id); |
| 4064 // 5:Evaluate (x + 1). |
4015 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer)); | 4065 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer)); |
4016 // 6:Continue evaluation of dog() | 4066 // Evaluate (x + 1) finishes. |
| 4067 breakpoints_barriers->semaphore_1->Wait(); |
| 4068 // Must have result 108. |
| 4069 CHECK_EQ(108, evaluate_int_result); |
| 4070 // 6:Continue evaluation of dog(). |
4017 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer)); | 4071 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer)); |
4018 // dog() finishes. | 4072 // Evaluate dog() finishes. |
| 4073 breakpoints_barriers->semaphore_1->Wait(); |
| 4074 // Must have result 107. |
| 4075 CHECK_EQ(107, evaluate_int_result); |
4019 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint | 4076 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint |
4020 // in cat(19). | 4077 // in cat(19). |
4021 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer)); | 4078 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer)); |
4022 // message callback gets break event | 4079 // Message callback gets break event. |
4023 breakpoints_barriers->semaphore_1->Wait(); // wait for break event | 4080 breakpoints_barriers->semaphore_1->Wait(); // wait for break event |
4024 // 8: Evaluate dog() with breaks disabled | 4081 // Must have hit breakpoint #1. |
| 4082 CHECK_EQ(1, break_event_breakpoint_id); |
| 4083 // 8: Evaluate dog() with breaks disabled. |
4025 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer)); | 4084 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer)); |
| 4085 // Evaluate dog() finishes. |
| 4086 breakpoints_barriers->semaphore_1->Wait(); |
| 4087 // Must have result 116. |
| 4088 CHECK_EQ(116, evaluate_int_result); |
4026 // 9: Continue evaluation of source2, reach end. | 4089 // 9: Continue evaluation of source2, reach end. |
4027 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); | 4090 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); |
4028 } | 4091 } |
4029 | 4092 |
4030 BreakpointsDebuggerThread breakpoints_debugger_thread; | 4093 BreakpointsDebuggerThread breakpoints_debugger_thread; |
4031 BreakpointsV8Thread breakpoints_v8_thread; | 4094 BreakpointsV8Thread breakpoints_v8_thread; |
4032 | 4095 |
4033 TEST(RecursiveBreakpoints) { | 4096 TEST(RecursiveBreakpoints) { |
4034 i::FLAG_debugger_auto_break = true; | 4097 i::FLAG_debugger_auto_break = true; |
4035 | 4098 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4318 | 4381 |
4319 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); | 4382 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
4320 } | 4383 } |
4321 | 4384 |
4322 | 4385 |
4323 // Debugger message handler which counts the number of times it is called. | 4386 // Debugger message handler which counts the number of times it is called. |
4324 static int message_handler_hit_count = 0; | 4387 static int message_handler_hit_count = 0; |
4325 static void MessageHandlerHitCount(const v8::Debug::Message& message) { | 4388 static void MessageHandlerHitCount(const v8::Debug::Message& message) { |
4326 message_handler_hit_count++; | 4389 message_handler_hit_count++; |
4327 | 4390 |
4328 SendContinueCommand(); | 4391 static char print_buffer[1000]; |
| 4392 v8::String::Value json(message.GetJSON()); |
| 4393 Utf16ToAscii(*json, json.length(), print_buffer); |
| 4394 if (IsExceptionEventMessage(print_buffer)) { |
| 4395 // Send a continue command for exception events. |
| 4396 SendContinueCommand(); |
| 4397 } |
4329 } | 4398 } |
4330 | 4399 |
4331 | 4400 |
4332 // Test clearing the debug message handler. | 4401 // Test clearing the debug message handler. |
4333 TEST(DebuggerClearMessageHandler) { | 4402 TEST(DebuggerClearMessageHandler) { |
4334 v8::HandleScope scope; | 4403 v8::HandleScope scope; |
4335 DebugLocalContext env; | 4404 DebugLocalContext env; |
4336 | 4405 |
4337 // Check debugger is unloaded before it is used. | 4406 // Check debugger is unloaded before it is used. |
4338 CheckDebuggerUnloaded(); | 4407 CheckDebuggerUnloaded(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4408 public: | 4477 public: |
4409 void Run(); | 4478 void Run(); |
4410 }; | 4479 }; |
4411 | 4480 |
4412 Barriers* host_dispatch_barriers; | 4481 Barriers* host_dispatch_barriers; |
4413 | 4482 |
4414 static void HostDispatchMessageHandler(const v8::Debug::Message& message) { | 4483 static void HostDispatchMessageHandler(const v8::Debug::Message& message) { |
4415 static char print_buffer[1000]; | 4484 static char print_buffer[1000]; |
4416 v8::String::Value json(message.GetJSON()); | 4485 v8::String::Value json(message.GetJSON()); |
4417 Utf16ToAscii(*json, json.length(), print_buffer); | 4486 Utf16ToAscii(*json, json.length(), print_buffer); |
4418 printf("%s\n", print_buffer); | |
4419 fflush(stdout); | |
4420 } | 4487 } |
4421 | 4488 |
4422 | 4489 |
4423 static void HostDispatchDispatchHandler() { | 4490 static void HostDispatchDispatchHandler() { |
4424 host_dispatch_barriers->semaphore_1->Signal(); | 4491 host_dispatch_barriers->semaphore_1->Signal(); |
4425 } | 4492 } |
4426 | 4493 |
4427 | 4494 |
4428 void HostDispatchV8Thread::Run() { | 4495 void HostDispatchV8Thread::Run() { |
4429 const char* source_1 = "var y_global = 3;\n" | 4496 const char* source_1 = "var y_global = 3;\n" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4768 static v8::Handle<v8::Value> expected_context_data; | 4835 static v8::Handle<v8::Value> expected_context_data; |
4769 | 4836 |
4770 | 4837 |
4771 // Check that the expected context is the one generating the debug event. | 4838 // Check that the expected context is the one generating the debug event. |
4772 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { | 4839 static void ContextCheckMessageHandler(const v8::Debug::Message& message) { |
4773 CHECK(message.GetEventContext() == expected_context); | 4840 CHECK(message.GetEventContext() == expected_context); |
4774 CHECK(message.GetEventContext()->GetData()->StrictEquals( | 4841 CHECK(message.GetEventContext()->GetData()->StrictEquals( |
4775 expected_context_data)); | 4842 expected_context_data)); |
4776 message_handler_hit_count++; | 4843 message_handler_hit_count++; |
4777 | 4844 |
| 4845 static char print_buffer[1000]; |
| 4846 v8::String::Value json(message.GetJSON()); |
| 4847 Utf16ToAscii(*json, json.length(), print_buffer); |
| 4848 |
4778 // Send a continue command for break events. | 4849 // Send a continue command for break events. |
4779 if (message.GetEvent() == v8::Break) { | 4850 if (IsBreakEventMessage(print_buffer)) { |
4780 SendContinueCommand(); | 4851 SendContinueCommand(); |
4781 } | 4852 } |
4782 } | 4853 } |
4783 | 4854 |
4784 | 4855 |
4785 // Test which creates two contexts and sets different embedder data on each. | 4856 // Test which creates two contexts and sets different embedder data on each. |
4786 // Checks that this data is set correctly and that when the debug message | 4857 // Checks that this data is set correctly and that when the debug message |
4787 // handler is called the expected context is the one active. | 4858 // handler is called the expected context is the one active. |
4788 TEST(ContextData) { | 4859 TEST(ContextData) { |
4789 v8::HandleScope scope; | 4860 v8::HandleScope scope; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5008 static int continue_command_send_count = 0; | 5079 static int continue_command_send_count = 0; |
5009 // Check that the expected context is the one generating the debug event | 5080 // Check that the expected context is the one generating the debug event |
5010 // including the case of nested break event. | 5081 // including the case of nested break event. |
5011 static void DebugEvalContextCheckMessageHandler( | 5082 static void DebugEvalContextCheckMessageHandler( |
5012 const v8::Debug::Message& message) { | 5083 const v8::Debug::Message& message) { |
5013 CHECK(message.GetEventContext() == expected_context); | 5084 CHECK(message.GetEventContext() == expected_context); |
5014 CHECK(message.GetEventContext()->GetData()->StrictEquals( | 5085 CHECK(message.GetEventContext()->GetData()->StrictEquals( |
5015 expected_context_data)); | 5086 expected_context_data)); |
5016 message_handler_hit_count++; | 5087 message_handler_hit_count++; |
5017 | 5088 |
5018 if (message.IsEvent() && message.GetEvent() == v8::Break) { | 5089 static char print_buffer[1000]; |
| 5090 v8::String::Value json(message.GetJSON()); |
| 5091 Utf16ToAscii(*json, json.length(), print_buffer); |
| 5092 |
| 5093 if (IsBreakEventMessage(print_buffer)) { |
5019 break_count++; | 5094 break_count++; |
5020 if (!sent_eval) { | 5095 if (!sent_eval) { |
5021 sent_eval = true; | 5096 sent_eval = true; |
5022 | 5097 |
5023 const int kBufferSize = 1000; | 5098 const int kBufferSize = 1000; |
5024 uint16_t buffer[kBufferSize]; | 5099 uint16_t buffer[kBufferSize]; |
5025 const char* eval_command = | 5100 const char* eval_command = |
5026 "{\"seq\":0," | 5101 "{\"seq\":0," |
5027 "\"type\":\"request\"," | 5102 "\"type\":\"request\"," |
5028 "\"command\":\"evaluate\"," | 5103 "\"command\":\"evaluate\"," |
5029 "arguments:{\"expression\":\"debugger;\"," | 5104 "arguments:{\"expression\":\"debugger;\"," |
5030 "\"global\":true,\"disable_break\":false}}"; | 5105 "\"global\":true,\"disable_break\":false}}"; |
5031 | 5106 |
5032 // Send evaluate command. | 5107 // Send evaluate command. |
5033 v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer)); | 5108 v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer)); |
5034 return; | 5109 return; |
5035 } else { | 5110 } else { |
5036 // It's a break event caused by the evaluation request above. | 5111 // It's a break event caused by the evaluation request above. |
5037 SendContinueCommand(); | 5112 SendContinueCommand(); |
5038 continue_command_send_count++; | 5113 continue_command_send_count++; |
5039 } | 5114 } |
5040 } else if (message.IsResponse() && continue_command_send_count < 2) { | 5115 } else if (IsEvaluateResponseMessage(print_buffer) && |
| 5116 continue_command_send_count < 2) { |
5041 // Response to the evaluation request. We're still on the breakpoint so | 5117 // Response to the evaluation request. We're still on the breakpoint so |
5042 // send continue. | 5118 // send continue. |
5043 SendContinueCommand(); | 5119 SendContinueCommand(); |
5044 continue_command_send_count++; | 5120 continue_command_send_count++; |
5045 } | 5121 } |
5046 } | 5122 } |
5047 | 5123 |
5048 | 5124 |
5049 // Tests that context returned for break event is correct when the event occurs | 5125 // Tests that context returned for break event is correct when the event occurs |
5050 // in 'evaluate' debugger request. | 5126 // in 'evaluate' debugger request. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5360 v8::Script::New( | 5436 v8::Script::New( |
5361 v8::String::New( | 5437 v8::String::New( |
5362 "function runTest(mirror) {" | 5438 "function runTest(mirror) {" |
5363 " return mirror.isString() && (mirror.length() == 5);" | 5439 " return mirror.isString() && (mirror.length() == 5);" |
5364 "}" | 5440 "}" |
5365 "" | 5441 "" |
5366 "runTest;"))->Run()); | 5442 "runTest;"))->Run()); |
5367 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); | 5443 v8::Handle<v8::Value> result = run_test->Call(env->Global(), 1, &obj); |
5368 CHECK(result->IsTrue()); | 5444 CHECK(result->IsTrue()); |
5369 } | 5445 } |
OLD | NEW |