⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-debug.cc.svn-base

📁 Google浏览器V8内核代码
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
  ClearBreakPoint(bp2);  CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());  CHECK(!HasDebugInfo(foo));  CHECK(!HasDebugInfo(bar));}// Test that a break point can be set at an IC store location.TEST(BreakPointICStore) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run();  v8::Local<v8::Function> foo =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));  // Run without breakpoints.  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Run with breakpoint  int bp = SetBreakPoint(foo, 0);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  // Run without breakpoints.  ClearBreakPoint(bp);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test that a break point can be set at an IC load location.TEST(BreakPointICLoad) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("bar=1"))->Run();  v8::Script::Compile(v8::String::New("function foo(){var x=bar;}"))->Run();  v8::Local<v8::Function> foo =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));  // Run without breakpoints.  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Run with breakpoint  int bp = SetBreakPoint(foo, 0);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  // Run without breakpoints.  ClearBreakPoint(bp);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test that a break point can be set at an IC call location.TEST(BreakPointICCall) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("function bar(){}"))->Run();  v8::Script::Compile(v8::String::New("function foo(){bar();}"))->Run();  v8::Local<v8::Function> foo =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));  // Run without breakpoints.  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Run with breakpoint  int bp = SetBreakPoint(foo, 0);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  // Run without breakpoints.  ClearBreakPoint(bp);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test that a break point can be set at a return store location.TEST(BreakPointReturn) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("function foo(){}"))->Run();  v8::Local<v8::Function> foo =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo")));  // Run without breakpoints.  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Run with breakpoint  int bp = SetBreakPoint(foo, 0);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  // Run without breakpoints.  ClearBreakPoint(bp);  foo->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}static void CallWithBreakPoints(v8::Local<v8::Object> recv,                                v8::Local<v8::Function> f,                                int break_point_count,                                int call_count) {  break_point_hit_count = 0;  for (int i = 0; i < call_count; i++) {    f->Call(recv, 0, NULL);    CHECK_EQ((i + 1) * break_point_count, break_point_hit_count);  }}// Test GC during break point processing.TEST(GCDuringBreakPointProcessing) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointCollectGarbage,                                   v8::Undefined());  v8::Local<v8::Function> foo;  // Test IC store break point with garbage collection.  foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");  SetBreakPoint(foo, 0);  CallWithBreakPoints(env->Global(), foo, 1, 10);  // Test IC load break point with garbage collection.  foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo");  SetBreakPoint(foo, 0);  CallWithBreakPoints(env->Global(), foo, 1, 10);  // Test IC call break point with garbage collection.  foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo");  SetBreakPoint(foo, 0);  CallWithBreakPoints(env->Global(), foo, 1, 10);  // Test return break point with garbage collection.  foo = CompileFunction(&env, "function foo(){}", "foo");  SetBreakPoint(foo, 0);  CallWithBreakPoints(env->Global(), foo, 1, 25);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointCollectGarbage);}// Call the function three times with different garbage collections in between// and make sure that the break point survives.static void CallAndGC(v8::Local<v8::Object> recv, v8::Local<v8::Function> f) {  break_point_hit_count = 0;  for (int i = 0; i < 3; i++) {    // Call function.    f->Call(recv, 0, NULL);    CHECK_EQ(1 + i * 3, break_point_hit_count);    // Scavenge and call function.    Heap::CollectGarbage(0, v8::internal::NEW_SPACE);    f->Call(recv, 0, NULL);    CHECK_EQ(2 + i * 3, break_point_hit_count);    // Mark sweep (and perhaps compact) and call function.    Heap::CollectAllGarbage();    f->Call(recv, 0, NULL);    CHECK_EQ(3 + i * 3, break_point_hit_count);  }}// Test that a break point can be set at a return store location.TEST(BreakPointSurviveGC) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Local<v8::Function> foo;  // Test IC store break point with garbage collection.  foo = CompileFunction(&env, "function foo(){bar=0;}", "foo");  SetBreakPoint(foo, 0);  CallAndGC(env->Global(), foo);  // Test IC load break point with garbage collection.  foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo");  SetBreakPoint(foo, 0);  CallAndGC(env->Global(), foo);  // Test IC call break point with garbage collection.  foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo");  SetBreakPoint(foo, 0);  CallAndGC(env->Global(), foo);  // Test return break point with garbage collection.  foo = CompileFunction(&env, "function foo(){}", "foo");  SetBreakPoint(foo, 0);  CallAndGC(env->Global(), foo);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);}// Test that break points can be set using the global Debug object.TEST(BreakPointThroughJavaScript) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  env.ExposeDebug();  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("function bar(){}"))->Run();  v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run();  //                                               012345678901234567890  //                                                         1         2  // Break points are set at position 3 and 9  v8::Local<v8::Script> foo = v8::Script::Compile(v8::String::New("foo()"));  // Run without breakpoints.  foo->Run();  CHECK_EQ(0, break_point_hit_count);  // Run with one breakpoint  int bp1 = SetBreakPointFromJS("foo", 0, 3);  foo->Run();  CHECK_EQ(1, break_point_hit_count);  foo->Run();  CHECK_EQ(2, break_point_hit_count);  // Run with two breakpoints  int bp2 = SetBreakPointFromJS("foo", 0, 9);  foo->Run();  CHECK_EQ(4, break_point_hit_count);  foo->Run();  CHECK_EQ(6, break_point_hit_count);  // Run with one breakpoint  ClearBreakPointFromJS(bp2);  foo->Run();  CHECK_EQ(7, break_point_hit_count);  foo->Run();  CHECK_EQ(8, break_point_hit_count);  // Run without breakpoints.  ClearBreakPointFromJS(bp1);  foo->Run();  CHECK_EQ(8, break_point_hit_count);  v8::Debug::RemoveDebugEventListener(DebugEventBreakPointHitCount);  // Make sure that the break point numbers are consecutive.  CHECK_EQ(1, bp1);  CHECK_EQ(2, bp2);}// Test that break points can be set using the global Debug object.TEST(ScriptBreakPointThroughJavaScript) {  break_point_hit_count = 0;  v8::HandleScope scope;  DebugLocalContext env;  env.ExposeDebug();  v8::Debug::AddDebugEventListener(DebugEventBreakPointHitCount,                                   v8::Undefined());  v8::Script::Compile(v8::String::New("function foo(){bar();bar();}"))->Run();  v8::Local<v8::String> script = v8::String::New(    "function f() {\n"    "  function h() {\n"    "    a = 0;  // line 2\n"    "  }\n"    "  b = 1;  // line 4\n"    "  return h();\n"    "}\n"    "\n"    "function g() {\n"    "  function h() {\n"    "    a = 0;\n"    "  }\n"    "  b = 2;  // line 12\n"    "  h();\n"    "  b = 3;  // line 14\n"    "  f();    // line 15\n"    "}");  // Compile the script and get the two functions.  v8::ScriptOrigin origin =      v8::ScriptOrigin(v8::String::New("test"));  v8::Script::Compile(script, &origin)->Run();  v8::Local<v8::Function> f =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));  v8::Local<v8::Function> g =      v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g")));  // Call f and g without break points.  break_point_hit_count = 0;  f->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Call f and g with break point on line 12.  int sbp1 = SetScriptBreakPointFromJS("test", 12, 0);  break_point_hit_count = 0;  f->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  // Remove the break point again.  break_point_hit_count = 0;  ClearBreakPointFromJS(sbp1);  f->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  // Call f and g with break point on line 2.  int sbp2 = SetScriptBreakPointFromJS("test", 2, 0);  break_point_hit_count = 0;  f->Call(env->Global(), 0, NULL);  CHECK_EQ(1, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  // Call f and g with break point on line 2, 4, 12, 14 and 15.  int sbp3 = SetScriptBreakPointFromJS("test", 4, 0);  int sbp4 = SetScriptBreakPointFromJS("test", 12, 0);  int sbp5 = SetScriptBreakPointFromJS("test", 14, 0);  int sbp6 = SetScriptBreakPointFromJS("test", 15, 0);  break_point_hit_count = 0;  f->Call(env->Global(), 0, NULL);  CHECK_EQ(2, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(7, break_point_hit_count);  // Remove the all the break points again.  break_point_hit_count = 0;  ClearBreakPointFromJS(sbp2);  ClearBreakPointFromJS(sbp3);  ClearBreakPointFromJS(sbp4);  ClearBreakPointFromJS(sbp5);  ClearBreakPointFromJS(sbp6);  f->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);  g->Call(env->Global(), 0, NULL);  CHECK_EQ(0, break_point_hit_count);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -