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

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

Issue 42173: Added automatic debug break for processing debugger commands (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/flag-definitions.h ('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 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 3226 matching lines...) Expand 10 before | Expand all | Expand 10 after
3237 // Post 6 commands, filling the command queue and making it expand. 3237 // Post 6 commands, filling the command queue and making it expand.
3238 // These calls return immediately, but the commands stay on the queue 3238 // These calls return immediately, but the commands stay on the queue
3239 // until the execution of source_2. 3239 // until the execution of source_2.
3240 // Note: AsciiToUtf16 executes before SendCommand, so command is copied 3240 // Note: AsciiToUtf16 executes before SendCommand, so command is copied
3241 // to buffer before buffer is sent to SendCommand. 3241 // to buffer before buffer is sent to SendCommand.
3242 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); 3242 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1));
3243 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); 3243 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2));
3244 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 3244 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
3245 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 3245 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
3246 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 3246 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2));
3247 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2));
3248 message_queue_barriers.barrier_2.Wait(); 3247 message_queue_barriers.barrier_2.Wait();
3249 // Main thread compiles and runs source_2. 3248 // Main thread compiles and runs source_2.
3250 // Queued commands are executed at the start of compilation of source_2. 3249 // Queued commands are executed at the start of compilation of source_2.
3251 message_queue_barriers.barrier_3.Wait(); 3250 message_queue_barriers.barrier_3.Wait();
3252 // Free the message handler to process all the messages from the queue. 3251 // Free the message handler to process all the messages from the queue.
3253 for (int i = 0; i < 20 ; ++i) { 3252 for (int i = 0; i < 20 ; ++i) {
3254 message_queue_barriers.semaphore_1->Signal(); 3253 message_queue_barriers.semaphore_1->Signal();
3255 } 3254 }
3256 // Main thread compiles and runs source_3. 3255 // Main thread compiles and runs source_3.
3257 // source_3 includes a debugger statement, which causes a break event. 3256 // source_3 includes a debugger statement, which causes a break event.
(...skipping 21 matching lines...) Expand all
3279 3278
3280 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 3279 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
3281 const char* source_2 = "e = 17;"; 3280 const char* source_2 = "e = 17;";
3282 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;"; 3281 const char* source_3 = "a = 4; debugger; a = 5; a = 6; a = 7;";
3283 3282
3284 // See MessageQueueDebuggerThread::Run for interleaved sequence of 3283 // See MessageQueueDebuggerThread::Run for interleaved sequence of
3285 // API calls and events in the two threads. 3284 // API calls and events in the two threads.
3286 CompileRun(source_1); 3285 CompileRun(source_1);
3287 message_queue_barriers.barrier_1.Wait(); 3286 message_queue_barriers.barrier_1.Wait();
3288 message_queue_barriers.barrier_2.Wait(); 3287 message_queue_barriers.barrier_2.Wait();
3289 v8::Debug::DebugBreak();
3290 CompileRun(source_2); 3288 CompileRun(source_2);
3291 message_queue_barriers.barrier_3.Wait(); 3289 message_queue_barriers.barrier_3.Wait();
3292 CompileRun(source_3); 3290 CompileRun(source_3);
3293 message_queue_debugger_thread.Join(); 3291 message_queue_debugger_thread.Join();
3294 fflush(stdout); 3292 fflush(stdout);
3295 } 3293 }
3296 3294
3297 /* Test ThreadedDebugging */ 3295 /* Test ThreadedDebugging */
3298 /* This test interrupts a running infinite loop that is 3296 /* This test interrupts a running infinite loop that is
3299 * occupying the v8 thread by a break command from the 3297 * occupying the v8 thread by a break command from the
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3457 uint16_t buffer[kBufSize]; 3455 uint16_t buffer[kBufSize];
3458 3456
3459 const char* command_1 = "{\"seq\":101," 3457 const char* command_1 = "{\"seq\":101,"
3460 "\"type\":\"request\"," 3458 "\"type\":\"request\","
3461 "\"command\":\"setbreakpoint\"," 3459 "\"command\":\"setbreakpoint\","
3462 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; 3460 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
3463 const char* command_2 = "{\"seq\":102," 3461 const char* command_2 = "{\"seq\":102,"
3464 "\"type\":\"request\"," 3462 "\"type\":\"request\","
3465 "\"command\":\"setbreakpoint\"," 3463 "\"command\":\"setbreakpoint\","
3466 "\"arguments\":{\"type\":\"function\",\"target\":\"dog\",\"line\":3}}"; 3464 "\"arguments\":{\"type\":\"function\",\"target\":\"dog\",\"line\":3}}";
3467 const char* command_3 = "{\"seq\":103," 3465 const char* command_3 = "{\"seq\":104,"
3468 "\"type\":\"request\","
3469 "\"command\":\"continue\"}";
3470 const char* command_4 = "{\"seq\":104,"
3471 "\"type\":\"request\"," 3466 "\"type\":\"request\","
3472 "\"command\":\"evaluate\"," 3467 "\"command\":\"evaluate\","
3473 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false}}"; 3468 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false}}";
3474 const char* command_5 = "{\"seq\":105," 3469 const char* command_4 = "{\"seq\":105,"
3475 "\"type\":\"request\"," 3470 "\"type\":\"request\","
3476 "\"command\":\"evaluate\"," 3471 "\"command\":\"evaluate\","
3477 "\"arguments\":{\"expression\":\"x\",\"disable_break\":true}}"; 3472 "\"arguments\":{\"expression\":\"x\",\"disable_break\":true}}";
3478 const char* command_6 = "{\"seq\":106," 3473 const char* command_5 = "{\"seq\":106,"
3479 "\"type\":\"request\"," 3474 "\"type\":\"request\","
3480 "\"command\":\"continue\"}"; 3475 "\"command\":\"continue\"}";
3481 const char* command_7 = "{\"seq\":107," 3476 const char* command_6 = "{\"seq\":107,"
3482 "\"type\":\"request\"," 3477 "\"type\":\"request\","
3483 "\"command\":\"continue\"}"; 3478 "\"command\":\"continue\"}";
3484 const char* command_8 = "{\"seq\":108," 3479 const char* command_7 = "{\"seq\":108,"
3485 "\"type\":\"request\"," 3480 "\"type\":\"request\","
3486 "\"command\":\"evaluate\"," 3481 "\"command\":\"evaluate\","
3487 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}"; 3482 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}";
3488 const char* command_9 = "{\"seq\":109," 3483 const char* command_8 = "{\"seq\":109,"
3489 "\"type\":\"request\"," 3484 "\"type\":\"request\","
3490 "\"command\":\"continue\"}"; 3485 "\"command\":\"continue\"}";
3491 3486
3492 3487
3493 // v8 thread initializes, runs source_1 3488 // v8 thread initializes, runs source_1
3494 breakpoints_barriers->barrier_1.Wait(); 3489 breakpoints_barriers->barrier_1.Wait();
3495 // 1:Set breakpoint in cat(). 3490 // 1:Set breakpoint in cat().
3496 v8::Debug::DebugBreak();
3497 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 3491 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
3498 // 2:Set breakpoint in dog() 3492 // 2:Set breakpoint in dog()
3499 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 3493 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
3500 // 3:Continue
3501 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer));
3502 breakpoints_barriers->barrier_2.Wait(); 3494 breakpoints_barriers->barrier_2.Wait();
3503 // v8 thread starts compiling source_2. 3495 // v8 thread starts compiling source_2.
3504 // Automatic break happens, to run queued commands 3496 // Automatic break happens, to run queued commands
3505 // breakpoints_barriers->semaphore_1->Wait(); 3497 // breakpoints_barriers->semaphore_1->Wait();
3506 // Commands 1 through 3 run, thread continues. 3498 // Commands 1 through 3 run, thread continues.
3507 // v8 thread runs source_2 to breakpoint in cat(). 3499 // v8 thread runs source_2 to breakpoint in cat().
3508 // message callback receives break event. 3500 // message callback receives break event.
3509 breakpoints_barriers->semaphore_1->Wait(); 3501 breakpoints_barriers->semaphore_1->Wait();
3510 // 4:Evaluate dog() (which has a breakpoint). 3502 // 4:Evaluate dog() (which has a breakpoint).
3511 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer)); 3503 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer));
3512 // v8 thread hits breakpoint in dog() 3504 // v8 thread hits breakpoint in dog()
3513 breakpoints_barriers->semaphore_1->Wait(); // wait for break event 3505 breakpoints_barriers->semaphore_1->Wait(); // wait for break event
3514 // 5:Evaluate x 3506 // 5:Evaluate x
3507 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer));
3508 // 6:Continue evaluation of dog()
3515 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer)); 3509 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer));
3516 // 6:Continue evaluation of dog()
3517 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer));
3518 // dog() finishes. 3510 // dog() finishes.
3519 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint 3511 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint
3520 // in cat(19). 3512 // in cat(19).
3521 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer)); 3513 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer));
3522 // message callback gets break event 3514 // message callback gets break event
3523 breakpoints_barriers->semaphore_1->Wait(); // wait for break event 3515 breakpoints_barriers->semaphore_1->Wait(); // wait for break event
3524 // 8: Evaluate dog() with breaks disabled 3516 // 8: Evaluate dog() with breaks disabled
3517 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer));
3518 // 9: Continue evaluation of source2, reach end.
3525 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); 3519 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer));
3526 // 9: Continue evaluation of source2, reach end.
3527 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_9, buffer));
3528 } 3520 }
3529 3521
3530 BreakpointsDebuggerThread breakpoints_debugger_thread; 3522 BreakpointsDebuggerThread breakpoints_debugger_thread;
3531 BreakpointsV8Thread breakpoints_v8_thread; 3523 BreakpointsV8Thread breakpoints_v8_thread;
3532 3524
3533 TEST(RecursiveBreakpoints) { 3525 TEST(RecursiveBreakpoints) {
3526 i::FLAG_debugger_auto_break = true;
3527
3534 // Create a V8 environment 3528 // Create a V8 environment
3535 Barriers stack_allocated_breakpoints_barriers; 3529 Barriers stack_allocated_breakpoints_barriers;
3536 stack_allocated_breakpoints_barriers.Initialize(); 3530 stack_allocated_breakpoints_barriers.Initialize();
3537 breakpoints_barriers = &stack_allocated_breakpoints_barriers; 3531 breakpoints_barriers = &stack_allocated_breakpoints_barriers;
3538 3532
3539 breakpoints_v8_thread.Start(); 3533 breakpoints_v8_thread.Start();
3540 breakpoints_debugger_thread.Start(); 3534 breakpoints_debugger_thread.Start();
3541 3535
3542 breakpoints_v8_thread.Join(); 3536 breakpoints_v8_thread.Join();
3543 breakpoints_debugger_thread.Join(); 3537 breakpoints_debugger_thread.Join();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
3795 3789
3796 int host_dispatch_hit_count = 0; 3790 int host_dispatch_hit_count = 0;
3797 static void HostDispatchHandlerHitCount(void* dispatch, void *data) { 3791 static void HostDispatchHandlerHitCount(void* dispatch, void *data) {
3798 host_dispatch_hit_count++; 3792 host_dispatch_hit_count++;
3799 } 3793 }
3800 3794
3801 3795
3802 // Test that clearing the debug event listener actually clears all break points 3796 // Test that clearing the debug event listener actually clears all break points
3803 // and related information. 3797 // and related information.
3804 TEST(DebuggerHostDispatch) { 3798 TEST(DebuggerHostDispatch) {
3799 i::FLAG_debugger_auto_break = true;
3800
3805 v8::HandleScope scope; 3801 v8::HandleScope scope;
3806 DebugLocalContext env; 3802 DebugLocalContext env;
3807 3803
3808 const int kBufferSize = 1000; 3804 const int kBufferSize = 1000;
3809 uint16_t buffer[kBufferSize]; 3805 uint16_t buffer[kBufferSize];
3810 const char* command_continue = 3806 const char* command_continue =
3811 "{\"seq\":106," 3807 "{\"seq\":0,"
3812 "\"type\":\"request\"," 3808 "\"type\":\"request\","
3813 "\"command\":\"continue\"}"; 3809 "\"command\":\"continue\"}";
3814 3810
3815 // Setup message and host dispatch handlers. 3811 // Setup message and host dispatch handlers.
3816 v8::Debug::SetMessageHandler(DummyMessageHandler); 3812 v8::Debug::SetMessageHandler(DummyMessageHandler);
3817 v8::Debug::SetHostDispatchHandler(HostDispatchHandlerHitCount, 3813 v8::Debug::SetHostDispatchHandler(HostDispatchHandlerHitCount,
3818 NULL); 3814 NULL);
3819 3815
3820 // Fill a host dispatch and a continue command on the command queue before 3816 // Fill a host dispatch and a continue command on the command queue before
3821 // generating a debug break. 3817 // running some code.
3822 v8::Debug::SendHostDispatch(NULL); 3818 v8::Debug::SendHostDispatch(NULL);
3823 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 3819 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer));
3824 CompileRun("debugger"); 3820 CompileRun("void 0");
3825 3821
3826 // The host dispatch callback should be called. 3822 // The host dispatch callback should be called.
3827 CHECK_EQ(1, host_dispatch_hit_count); 3823 CHECK_EQ(1, host_dispatch_hit_count);
3828 } 3824 }
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698