| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 return debugged_functions; | 357 return debugged_functions; |
| 358 } | 358 } |
| 359 | 359 |
| 360 | 360 |
| 361 static Handle<Code> ComputeCallDebugBreak(int argc) { | 361 static Handle<Code> ComputeCallDebugBreak(int argc) { |
| 362 CALL_HEAP_FUNCTION(v8::internal::StubCache::ComputeCallDebugBreak(argc), | 362 CALL_HEAP_FUNCTION(v8::internal::StubCache::ComputeCallDebugBreak(argc), |
| 363 Code); | 363 Code); |
| 364 } | 364 } |
| 365 | 365 |
| 366 |
| 367 // Check that the debugger is loaded. |
| 368 static void CheckDebuggerLoaded() { |
| 369 CHECK(Debug::debug_context().is_null()); |
| 370 } |
| 371 |
| 372 |
| 373 // Check that the debugger has been fully unloaded. |
| 374 static void CheckDebuggerUnloaded(bool check_functions) { |
| 375 // Check that the debugger context is cleared and that there is no debug |
| 376 // information stored for the debugger. |
| 377 CHECK(Debug::debug_context().is_null()); |
| 378 CHECK_EQ(NULL, Debug::debug_info_list_); |
| 379 |
| 380 // Collect garbage to ensure weak handles are cleared. |
| 381 Heap::CollectAllGarbage(); |
| 382 Heap::CollectAllGarbage(); |
| 383 |
| 384 // Iterate the head and check that there are no debugger related objects left. |
| 385 HeapIterator iterator; |
| 386 while (iterator.has_next()) { |
| 387 HeapObject* obj = iterator.next(); |
| 388 CHECK(obj != NULL); |
| 389 CHECK(!obj->IsDebugInfo()); |
| 390 CHECK(!obj->IsBreakPointInfo()); |
| 391 |
| 392 // If deep check of functions is requested check that no debug break code |
| 393 // is left in all functions. |
| 394 if (check_functions) { |
| 395 if (obj->IsJSFunction()) { |
| 396 JSFunction* fun = JSFunction::cast(obj); |
| 397 for (RelocIterator it(fun->shared()->code()); !it.done(); it.next()) { |
| 398 RelocInfo::Mode rmode = it.rinfo()->rmode(); |
| 399 if (RelocInfo::IsCodeTarget(rmode)) { |
| 400 CHECK(!Debug::IsDebugBreak(it.rinfo()->target_address())); |
| 401 } else if (RelocInfo::IsJSReturn(rmode)) { |
| 402 CHECK(!Debug::IsDebugBreakAtReturn(it.rinfo())); |
| 403 } |
| 404 } |
| 405 } |
| 406 } |
| 407 } |
| 408 } |
| 409 |
| 410 |
| 366 } } // namespace v8::internal | 411 } } // namespace v8::internal |
| 367 | 412 |
| 413 |
| 414 // Check that the debugger is loaded. |
| 415 static void CheckDebuggerLoaded() { |
| 416 v8::internal::CheckDebuggerLoaded(); |
| 417 } |
| 418 |
| 419 |
| 420 // Check that the debugger has been fully unloaded. |
| 421 static void CheckDebuggerUnloaded(bool check_functions = false) { |
| 422 v8::internal::CheckDebuggerUnloaded(check_functions); |
| 423 } |
| 424 |
| 425 |
| 368 // Inherit from BreakLocationIterator to get access to protected parts for | 426 // Inherit from BreakLocationIterator to get access to protected parts for |
| 369 // testing. | 427 // testing. |
| 370 class TestBreakLocationIterator: public v8::internal::BreakLocationIterator { | 428 class TestBreakLocationIterator: public v8::internal::BreakLocationIterator { |
| 371 public: | 429 public: |
| 372 explicit TestBreakLocationIterator(Handle<v8::internal::DebugInfo> debug_info) | 430 explicit TestBreakLocationIterator(Handle<v8::internal::DebugInfo> debug_info) |
| 373 : BreakLocationIterator(debug_info, v8::internal::SOURCE_BREAK_LOCATIONS) {} | 431 : BreakLocationIterator(debug_info, v8::internal::SOURCE_BREAK_LOCATIONS) {} |
| 374 v8::internal::RelocIterator* it() { return reloc_iterator_; } | 432 v8::internal::RelocIterator* it() { return reloc_iterator_; } |
| 375 v8::internal::RelocIterator* it_original() { | 433 v8::internal::RelocIterator* it_original() { |
| 376 return reloc_iterator_original_; | 434 return reloc_iterator_original_; |
| 377 } | 435 } |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 CHECK(!HasDebugInfo(foo)); | 874 CHECK(!HasDebugInfo(foo)); |
| 817 CHECK(!HasDebugInfo(bar)); | 875 CHECK(!HasDebugInfo(bar)); |
| 818 } | 876 } |
| 819 | 877 |
| 820 | 878 |
| 821 // Test that a break point can be set at an IC store location. | 879 // Test that a break point can be set at an IC store location. |
| 822 TEST(BreakPointICStore) { | 880 TEST(BreakPointICStore) { |
| 823 break_point_hit_count = 0; | 881 break_point_hit_count = 0; |
| 824 v8::HandleScope scope; | 882 v8::HandleScope scope; |
| 825 DebugLocalContext env; | 883 DebugLocalContext env; |
| 884 |
| 826 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 885 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 827 v8::Undefined()); | 886 v8::Undefined()); |
| 828 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run(); | 887 v8::Script::Compile(v8::String::New("function foo(){bar=0;}"))->Run(); |
| 829 v8::Local<v8::Function> foo = | 888 v8::Local<v8::Function> foo = |
| 830 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 889 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
| 831 | 890 |
| 832 // Run without breakpoints. | 891 // Run without breakpoints. |
| 833 foo->Call(env->Global(), 0, NULL); | 892 foo->Call(env->Global(), 0, NULL); |
| 834 CHECK_EQ(0, break_point_hit_count); | 893 CHECK_EQ(0, break_point_hit_count); |
| 835 | 894 |
| 836 // Run with breakpoint | 895 // Run with breakpoint |
| 837 int bp = SetBreakPoint(foo, 0); | 896 int bp = SetBreakPoint(foo, 0); |
| 838 foo->Call(env->Global(), 0, NULL); | 897 foo->Call(env->Global(), 0, NULL); |
| 839 CHECK_EQ(1, break_point_hit_count); | 898 CHECK_EQ(1, break_point_hit_count); |
| 840 foo->Call(env->Global(), 0, NULL); | 899 foo->Call(env->Global(), 0, NULL); |
| 841 CHECK_EQ(2, break_point_hit_count); | 900 CHECK_EQ(2, break_point_hit_count); |
| 842 | 901 |
| 843 // Run without breakpoints. | 902 // Run without breakpoints. |
| 844 ClearBreakPoint(bp); | 903 ClearBreakPoint(bp); |
| 845 foo->Call(env->Global(), 0, NULL); | 904 foo->Call(env->Global(), 0, NULL); |
| 846 CHECK_EQ(2, break_point_hit_count); | 905 CHECK_EQ(2, break_point_hit_count); |
| 847 | 906 |
| 848 v8::Debug::SetDebugEventListener(NULL); | 907 v8::Debug::SetDebugEventListener(NULL); |
| 908 CheckDebuggerUnloaded(); |
| 849 } | 909 } |
| 850 | 910 |
| 851 | 911 |
| 852 // Test that a break point can be set at an IC load location. | 912 // Test that a break point can be set at an IC load location. |
| 853 TEST(BreakPointICLoad) { | 913 TEST(BreakPointICLoad) { |
| 854 break_point_hit_count = 0; | 914 break_point_hit_count = 0; |
| 855 v8::HandleScope scope; | 915 v8::HandleScope scope; |
| 856 DebugLocalContext env; | 916 DebugLocalContext env; |
| 857 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 917 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 858 v8::Undefined()); | 918 v8::Undefined()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 871 CHECK_EQ(1, break_point_hit_count); | 931 CHECK_EQ(1, break_point_hit_count); |
| 872 foo->Call(env->Global(), 0, NULL); | 932 foo->Call(env->Global(), 0, NULL); |
| 873 CHECK_EQ(2, break_point_hit_count); | 933 CHECK_EQ(2, break_point_hit_count); |
| 874 | 934 |
| 875 // Run without breakpoints. | 935 // Run without breakpoints. |
| 876 ClearBreakPoint(bp); | 936 ClearBreakPoint(bp); |
| 877 foo->Call(env->Global(), 0, NULL); | 937 foo->Call(env->Global(), 0, NULL); |
| 878 CHECK_EQ(2, break_point_hit_count); | 938 CHECK_EQ(2, break_point_hit_count); |
| 879 | 939 |
| 880 v8::Debug::SetDebugEventListener(NULL); | 940 v8::Debug::SetDebugEventListener(NULL); |
| 941 CheckDebuggerUnloaded(); |
| 881 } | 942 } |
| 882 | 943 |
| 883 | 944 |
| 884 // Test that a break point can be set at an IC call location. | 945 // Test that a break point can be set at an IC call location. |
| 885 TEST(BreakPointICCall) { | 946 TEST(BreakPointICCall) { |
| 886 break_point_hit_count = 0; | 947 break_point_hit_count = 0; |
| 887 v8::HandleScope scope; | 948 v8::HandleScope scope; |
| 888 DebugLocalContext env; | 949 DebugLocalContext env; |
| 889 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 950 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 890 v8::Undefined()); | 951 v8::Undefined()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 903 CHECK_EQ(1, break_point_hit_count); | 964 CHECK_EQ(1, break_point_hit_count); |
| 904 foo->Call(env->Global(), 0, NULL); | 965 foo->Call(env->Global(), 0, NULL); |
| 905 CHECK_EQ(2, break_point_hit_count); | 966 CHECK_EQ(2, break_point_hit_count); |
| 906 | 967 |
| 907 // Run without breakpoints. | 968 // Run without breakpoints. |
| 908 ClearBreakPoint(bp); | 969 ClearBreakPoint(bp); |
| 909 foo->Call(env->Global(), 0, NULL); | 970 foo->Call(env->Global(), 0, NULL); |
| 910 CHECK_EQ(2, break_point_hit_count); | 971 CHECK_EQ(2, break_point_hit_count); |
| 911 | 972 |
| 912 v8::Debug::SetDebugEventListener(NULL); | 973 v8::Debug::SetDebugEventListener(NULL); |
| 974 CheckDebuggerUnloaded(); |
| 913 } | 975 } |
| 914 | 976 |
| 915 | 977 |
| 916 // Test that a break point can be set at a return store location. | 978 // Test that a break point can be set at a return store location. |
| 917 TEST(BreakPointReturn) { | 979 TEST(BreakPointReturn) { |
| 918 break_point_hit_count = 0; | 980 break_point_hit_count = 0; |
| 919 v8::HandleScope scope; | 981 v8::HandleScope scope; |
| 920 DebugLocalContext env; | 982 DebugLocalContext env; |
| 921 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 983 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 922 v8::Undefined()); | 984 v8::Undefined()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 934 CHECK_EQ(1, break_point_hit_count); | 996 CHECK_EQ(1, break_point_hit_count); |
| 935 foo->Call(env->Global(), 0, NULL); | 997 foo->Call(env->Global(), 0, NULL); |
| 936 CHECK_EQ(2, break_point_hit_count); | 998 CHECK_EQ(2, break_point_hit_count); |
| 937 | 999 |
| 938 // Run without breakpoints. | 1000 // Run without breakpoints. |
| 939 ClearBreakPoint(bp); | 1001 ClearBreakPoint(bp); |
| 940 foo->Call(env->Global(), 0, NULL); | 1002 foo->Call(env->Global(), 0, NULL); |
| 941 CHECK_EQ(2, break_point_hit_count); | 1003 CHECK_EQ(2, break_point_hit_count); |
| 942 | 1004 |
| 943 v8::Debug::SetDebugEventListener(NULL); | 1005 v8::Debug::SetDebugEventListener(NULL); |
| 1006 CheckDebuggerUnloaded(); |
| 944 } | 1007 } |
| 945 | 1008 |
| 946 | 1009 |
| 947 static void CallWithBreakPoints(v8::Local<v8::Object> recv, | 1010 static void CallWithBreakPoints(v8::Local<v8::Object> recv, |
| 948 v8::Local<v8::Function> f, | 1011 v8::Local<v8::Function> f, |
| 949 int break_point_count, | 1012 int break_point_count, |
| 950 int call_count) { | 1013 int call_count) { |
| 951 break_point_hit_count = 0; | 1014 break_point_hit_count = 0; |
| 952 for (int i = 0; i < call_count; i++) { | 1015 for (int i = 0; i < call_count; i++) { |
| 953 f->Call(recv, 0, NULL); | 1016 f->Call(recv, 0, NULL); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 979 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); | 1042 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); |
| 980 SetBreakPoint(foo, 0); | 1043 SetBreakPoint(foo, 0); |
| 981 CallWithBreakPoints(env->Global(), foo, 1, 10); | 1044 CallWithBreakPoints(env->Global(), foo, 1, 10); |
| 982 | 1045 |
| 983 // Test return break point with garbage collection. | 1046 // Test return break point with garbage collection. |
| 984 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1047 foo = CompileFunction(&env, "function foo(){}", "foo"); |
| 985 SetBreakPoint(foo, 0); | 1048 SetBreakPoint(foo, 0); |
| 986 CallWithBreakPoints(env->Global(), foo, 1, 25); | 1049 CallWithBreakPoints(env->Global(), foo, 1, 25); |
| 987 | 1050 |
| 988 v8::Debug::SetDebugEventListener(NULL); | 1051 v8::Debug::SetDebugEventListener(NULL); |
| 1052 CheckDebuggerUnloaded(); |
| 989 } | 1053 } |
| 990 | 1054 |
| 991 | 1055 |
| 992 // Call the function three times with different garbage collections in between | 1056 // Call the function three times with different garbage collections in between |
| 993 // and make sure that the break point survives. | 1057 // and make sure that the break point survives. |
| 994 static void CallAndGC(v8::Local<v8::Object> recv, v8::Local<v8::Function> f) { | 1058 static void CallAndGC(v8::Local<v8::Object> recv, v8::Local<v8::Function> f) { |
| 995 break_point_hit_count = 0; | 1059 break_point_hit_count = 0; |
| 996 | 1060 |
| 997 for (int i = 0; i < 3; i++) { | 1061 for (int i = 0; i < 3; i++) { |
| 998 // Call function. | 1062 // Call function. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); | 1100 foo = CompileFunction(&env, "function bar(){};function foo(){bar();}", "foo"); |
| 1037 SetBreakPoint(foo, 0); | 1101 SetBreakPoint(foo, 0); |
| 1038 CallAndGC(env->Global(), foo); | 1102 CallAndGC(env->Global(), foo); |
| 1039 | 1103 |
| 1040 // Test return break point with garbage collection. | 1104 // Test return break point with garbage collection. |
| 1041 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1105 foo = CompileFunction(&env, "function foo(){}", "foo"); |
| 1042 SetBreakPoint(foo, 0); | 1106 SetBreakPoint(foo, 0); |
| 1043 CallAndGC(env->Global(), foo); | 1107 CallAndGC(env->Global(), foo); |
| 1044 | 1108 |
| 1045 v8::Debug::SetDebugEventListener(NULL); | 1109 v8::Debug::SetDebugEventListener(NULL); |
| 1110 CheckDebuggerUnloaded(); |
| 1046 } | 1111 } |
| 1047 | 1112 |
| 1048 | 1113 |
| 1049 // Test that break points can be set using the global Debug object. | 1114 // Test that break points can be set using the global Debug object. |
| 1050 TEST(BreakPointThroughJavaScript) { | 1115 TEST(BreakPointThroughJavaScript) { |
| 1051 break_point_hit_count = 0; | 1116 break_point_hit_count = 0; |
| 1052 v8::HandleScope scope; | 1117 v8::HandleScope scope; |
| 1053 DebugLocalContext env; | 1118 DebugLocalContext env; |
| 1054 env.ExposeDebug(); | 1119 env.ExposeDebug(); |
| 1055 | 1120 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1086 CHECK_EQ(7, break_point_hit_count); | 1151 CHECK_EQ(7, break_point_hit_count); |
| 1087 foo->Run(); | 1152 foo->Run(); |
| 1088 CHECK_EQ(8, break_point_hit_count); | 1153 CHECK_EQ(8, break_point_hit_count); |
| 1089 | 1154 |
| 1090 // Run without breakpoints. | 1155 // Run without breakpoints. |
| 1091 ClearBreakPointFromJS(bp1); | 1156 ClearBreakPointFromJS(bp1); |
| 1092 foo->Run(); | 1157 foo->Run(); |
| 1093 CHECK_EQ(8, break_point_hit_count); | 1158 CHECK_EQ(8, break_point_hit_count); |
| 1094 | 1159 |
| 1095 v8::Debug::SetDebugEventListener(NULL); | 1160 v8::Debug::SetDebugEventListener(NULL); |
| 1161 CheckDebuggerUnloaded(); |
| 1096 | 1162 |
| 1097 // Make sure that the break point numbers are consecutive. | 1163 // Make sure that the break point numbers are consecutive. |
| 1098 CHECK_EQ(1, bp1); | 1164 CHECK_EQ(1, bp1); |
| 1099 CHECK_EQ(2, bp2); | 1165 CHECK_EQ(2, bp2); |
| 1100 } | 1166 } |
| 1101 | 1167 |
| 1102 | 1168 |
| 1103 // Test that break points can be set using the global Debug object. | 1169 // Test that break points can be set using the global Debug object. |
| 1104 TEST(ScriptBreakPointThroughJavaScript) { | 1170 TEST(ScriptBreakPointThroughJavaScript) { |
| 1105 break_point_hit_count = 0; | 1171 break_point_hit_count = 0; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 | 1266 |
| 1201 // Reload the script and get g again checking that the break point survives. | 1267 // Reload the script and get g again checking that the break point survives. |
| 1202 // This tests that the function break point was converted to a script break | 1268 // This tests that the function break point was converted to a script break |
| 1203 // point. | 1269 // point. |
| 1204 v8::Script::Compile(script, &origin)->Run(); | 1270 v8::Script::Compile(script, &origin)->Run(); |
| 1205 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); | 1271 g = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("g"))); |
| 1206 g->Call(env->Global(), 0, NULL); | 1272 g->Call(env->Global(), 0, NULL); |
| 1207 CHECK_EQ(2, break_point_hit_count); | 1273 CHECK_EQ(2, break_point_hit_count); |
| 1208 | 1274 |
| 1209 v8::Debug::SetDebugEventListener(NULL); | 1275 v8::Debug::SetDebugEventListener(NULL); |
| 1276 CheckDebuggerUnloaded(); |
| 1210 | 1277 |
| 1211 // Make sure that the break point numbers are consecutive. | 1278 // Make sure that the break point numbers are consecutive. |
| 1212 CHECK_EQ(1, sbp1); | 1279 CHECK_EQ(1, sbp1); |
| 1213 CHECK_EQ(2, sbp2); | 1280 CHECK_EQ(2, sbp2); |
| 1214 CHECK_EQ(3, sbp3); | 1281 CHECK_EQ(3, sbp3); |
| 1215 CHECK_EQ(4, sbp4); | 1282 CHECK_EQ(4, sbp4); |
| 1216 CHECK_EQ(5, sbp5); | 1283 CHECK_EQ(5, sbp5); |
| 1217 CHECK_EQ(6, sbp6); | 1284 CHECK_EQ(6, sbp6); |
| 1218 CHECK_EQ(7, bp7); | 1285 CHECK_EQ(7, bp7); |
| 1219 } | 1286 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 v8::Script::Compile(script, &origin)->Run(); | 1332 v8::Script::Compile(script, &origin)->Run(); |
| 1266 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1333 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 1267 f->Call(env->Global(), 0, NULL); | 1334 f->Call(env->Global(), 0, NULL); |
| 1268 CHECK_EQ(2, break_point_hit_count); | 1335 CHECK_EQ(2, break_point_hit_count); |
| 1269 | 1336 |
| 1270 EnableScriptBreakPointFromJS(sbp); | 1337 EnableScriptBreakPointFromJS(sbp); |
| 1271 f->Call(env->Global(), 0, NULL); | 1338 f->Call(env->Global(), 0, NULL); |
| 1272 CHECK_EQ(3, break_point_hit_count); | 1339 CHECK_EQ(3, break_point_hit_count); |
| 1273 | 1340 |
| 1274 v8::Debug::SetDebugEventListener(NULL); | 1341 v8::Debug::SetDebugEventListener(NULL); |
| 1342 CheckDebuggerUnloaded(); |
| 1275 } | 1343 } |
| 1276 | 1344 |
| 1277 | 1345 |
| 1278 // Test conditional script break points. | 1346 // Test conditional script break points. |
| 1279 TEST(ConditionalScriptBreakPoint) { | 1347 TEST(ConditionalScriptBreakPoint) { |
| 1280 break_point_hit_count = 0; | 1348 break_point_hit_count = 0; |
| 1281 v8::HandleScope scope; | 1349 v8::HandleScope scope; |
| 1282 DebugLocalContext env; | 1350 DebugLocalContext env; |
| 1283 env.ExposeDebug(); | 1351 env.ExposeDebug(); |
| 1284 | 1352 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 v8::Script::Compile(script, &origin)->Run(); | 1394 v8::Script::Compile(script, &origin)->Run(); |
| 1327 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1395 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 1328 | 1396 |
| 1329 break_point_hit_count = 0; | 1397 break_point_hit_count = 0; |
| 1330 for (int i = 0; i < 10; i++) { | 1398 for (int i = 0; i < 10; i++) { |
| 1331 f->Call(env->Global(), 0, NULL); | 1399 f->Call(env->Global(), 0, NULL); |
| 1332 } | 1400 } |
| 1333 CHECK_EQ(5, break_point_hit_count); | 1401 CHECK_EQ(5, break_point_hit_count); |
| 1334 | 1402 |
| 1335 v8::Debug::SetDebugEventListener(NULL); | 1403 v8::Debug::SetDebugEventListener(NULL); |
| 1404 CheckDebuggerUnloaded(); |
| 1336 } | 1405 } |
| 1337 | 1406 |
| 1338 | 1407 |
| 1339 // Test ignore count on script break points. | 1408 // Test ignore count on script break points. |
| 1340 TEST(ScriptBreakPointIgnoreCount) { | 1409 TEST(ScriptBreakPointIgnoreCount) { |
| 1341 break_point_hit_count = 0; | 1410 break_point_hit_count = 0; |
| 1342 v8::HandleScope scope; | 1411 v8::HandleScope scope; |
| 1343 DebugLocalContext env; | 1412 DebugLocalContext env; |
| 1344 env.ExposeDebug(); | 1413 env.ExposeDebug(); |
| 1345 | 1414 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 v8::Script::Compile(script, &origin)->Run(); | 1449 v8::Script::Compile(script, &origin)->Run(); |
| 1381 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1450 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 1382 | 1451 |
| 1383 break_point_hit_count = 0; | 1452 break_point_hit_count = 0; |
| 1384 for (int i = 0; i < 10; i++) { | 1453 for (int i = 0; i < 10; i++) { |
| 1385 f->Call(env->Global(), 0, NULL); | 1454 f->Call(env->Global(), 0, NULL); |
| 1386 } | 1455 } |
| 1387 CHECK_EQ(5, break_point_hit_count); | 1456 CHECK_EQ(5, break_point_hit_count); |
| 1388 | 1457 |
| 1389 v8::Debug::SetDebugEventListener(NULL); | 1458 v8::Debug::SetDebugEventListener(NULL); |
| 1459 CheckDebuggerUnloaded(); |
| 1390 } | 1460 } |
| 1391 | 1461 |
| 1392 | 1462 |
| 1393 // Test that script break points survive when a script is reloaded. | 1463 // Test that script break points survive when a script is reloaded. |
| 1394 TEST(ScriptBreakPointReload) { | 1464 TEST(ScriptBreakPointReload) { |
| 1395 break_point_hit_count = 0; | 1465 break_point_hit_count = 0; |
| 1396 v8::HandleScope scope; | 1466 v8::HandleScope scope; |
| 1397 DebugLocalContext env; | 1467 DebugLocalContext env; |
| 1398 env.ExposeDebug(); | 1468 env.ExposeDebug(); |
| 1399 | 1469 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 // Compile the script again and get the function. | 1508 // Compile the script again and get the function. |
| 1439 v8::Script::Compile(script, &origin_1)->Run(); | 1509 v8::Script::Compile(script, &origin_1)->Run(); |
| 1440 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); | 1510 f = v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); |
| 1441 | 1511 |
| 1442 // Call f and check that the script break point is active. | 1512 // Call f and check that the script break point is active. |
| 1443 break_point_hit_count = 0; | 1513 break_point_hit_count = 0; |
| 1444 f->Call(env->Global(), 0, NULL); | 1514 f->Call(env->Global(), 0, NULL); |
| 1445 CHECK_EQ(1, break_point_hit_count); | 1515 CHECK_EQ(1, break_point_hit_count); |
| 1446 | 1516 |
| 1447 v8::Debug::SetDebugEventListener(NULL); | 1517 v8::Debug::SetDebugEventListener(NULL); |
| 1518 CheckDebuggerUnloaded(); |
| 1448 } | 1519 } |
| 1449 | 1520 |
| 1450 | 1521 |
| 1451 // Test when several scripts has the same script data | 1522 // Test when several scripts has the same script data |
| 1452 TEST(ScriptBreakPointMultiple) { | 1523 TEST(ScriptBreakPointMultiple) { |
| 1453 break_point_hit_count = 0; | 1524 break_point_hit_count = 0; |
| 1454 v8::HandleScope scope; | 1525 v8::HandleScope scope; |
| 1455 DebugLocalContext env; | 1526 DebugLocalContext env; |
| 1456 env.ExposeDebug(); | 1527 env.ExposeDebug(); |
| 1457 | 1528 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 sbp = SetScriptBreakPointFromJS("test", 1, 0); | 1574 sbp = SetScriptBreakPointFromJS("test", 1, 0); |
| 1504 | 1575 |
| 1505 // Call f and g and check that the script break point is active. | 1576 // Call f and g and check that the script break point is active. |
| 1506 break_point_hit_count = 0; | 1577 break_point_hit_count = 0; |
| 1507 f->Call(env->Global(), 0, NULL); | 1578 f->Call(env->Global(), 0, NULL); |
| 1508 CHECK_EQ(1, break_point_hit_count); | 1579 CHECK_EQ(1, break_point_hit_count); |
| 1509 g->Call(env->Global(), 0, NULL); | 1580 g->Call(env->Global(), 0, NULL); |
| 1510 CHECK_EQ(2, break_point_hit_count); | 1581 CHECK_EQ(2, break_point_hit_count); |
| 1511 | 1582 |
| 1512 v8::Debug::SetDebugEventListener(NULL); | 1583 v8::Debug::SetDebugEventListener(NULL); |
| 1584 CheckDebuggerUnloaded(); |
| 1513 } | 1585 } |
| 1514 | 1586 |
| 1515 | 1587 |
| 1516 // Test the script origin which has both name and line offset. | 1588 // Test the script origin which has both name and line offset. |
| 1517 TEST(ScriptBreakPointLineOffset) { | 1589 TEST(ScriptBreakPointLineOffset) { |
| 1518 break_point_hit_count = 0; | 1590 break_point_hit_count = 0; |
| 1519 v8::HandleScope scope; | 1591 v8::HandleScope scope; |
| 1520 DebugLocalContext env; | 1592 DebugLocalContext env; |
| 1521 env.ExposeDebug(); | 1593 env.ExposeDebug(); |
| 1522 | 1594 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 | 1630 |
| 1559 // Set a script break point with the script loaded. | 1631 // Set a script break point with the script loaded. |
| 1560 sbp1 = SetScriptBreakPointFromJS("test.html", 9, 0); | 1632 sbp1 = SetScriptBreakPointFromJS("test.html", 9, 0); |
| 1561 | 1633 |
| 1562 // Call f and check that the script break point is active. | 1634 // Call f and check that the script break point is active. |
| 1563 break_point_hit_count = 0; | 1635 break_point_hit_count = 0; |
| 1564 f->Call(env->Global(), 0, NULL); | 1636 f->Call(env->Global(), 0, NULL); |
| 1565 CHECK_EQ(1, break_point_hit_count); | 1637 CHECK_EQ(1, break_point_hit_count); |
| 1566 | 1638 |
| 1567 v8::Debug::SetDebugEventListener(NULL); | 1639 v8::Debug::SetDebugEventListener(NULL); |
| 1640 CheckDebuggerUnloaded(); |
| 1568 } | 1641 } |
| 1569 | 1642 |
| 1570 | 1643 |
| 1571 // Test script break points set on lines. | 1644 // Test script break points set on lines. |
| 1572 TEST(ScriptBreakPointLine) { | 1645 TEST(ScriptBreakPointLine) { |
| 1573 v8::HandleScope scope; | 1646 v8::HandleScope scope; |
| 1574 DebugLocalContext env; | 1647 DebugLocalContext env; |
| 1575 env.ExposeDebug(); | 1648 env.ExposeDebug(); |
| 1576 | 1649 |
| 1577 // Create a function for checking the function when hitting a break point. | 1650 // Create a function for checking the function when hitting a break point. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 // Clear the last break points, and reload the script which should not hit any | 1736 // Clear the last break points, and reload the script which should not hit any |
| 1664 // break points. | 1737 // break points. |
| 1665 ClearBreakPointFromJS(sbp1); | 1738 ClearBreakPointFromJS(sbp1); |
| 1666 ClearBreakPointFromJS(sbp5); | 1739 ClearBreakPointFromJS(sbp5); |
| 1667 ClearBreakPointFromJS(sbp6); | 1740 ClearBreakPointFromJS(sbp6); |
| 1668 break_point_hit_count = 0; | 1741 break_point_hit_count = 0; |
| 1669 v8::Script::Compile(script, &origin)->Run(); | 1742 v8::Script::Compile(script, &origin)->Run(); |
| 1670 CHECK_EQ(0, break_point_hit_count); | 1743 CHECK_EQ(0, break_point_hit_count); |
| 1671 | 1744 |
| 1672 v8::Debug::SetDebugEventListener(NULL); | 1745 v8::Debug::SetDebugEventListener(NULL); |
| 1746 CheckDebuggerUnloaded(); |
| 1673 } | 1747 } |
| 1674 | 1748 |
| 1675 | 1749 |
| 1676 // Test that it is possible to remove the last break point for a function | 1750 // Test that it is possible to remove the last break point for a function |
| 1677 // inside the break handling of that break point. | 1751 // inside the break handling of that break point. |
| 1678 TEST(RemoveBreakPointInBreak) { | 1752 TEST(RemoveBreakPointInBreak) { |
| 1679 v8::HandleScope scope; | 1753 v8::HandleScope scope; |
| 1680 DebugLocalContext env; | 1754 DebugLocalContext env; |
| 1681 | 1755 |
| 1682 v8::Local<v8::Function> foo = | 1756 v8::Local<v8::Function> foo = |
| 1683 CompileFunction(&env, "function foo(){a=1;}", "foo"); | 1757 CompileFunction(&env, "function foo(){a=1;}", "foo"); |
| 1684 debug_event_remove_break_point = SetBreakPoint(foo, 0); | 1758 debug_event_remove_break_point = SetBreakPoint(foo, 0); |
| 1685 | 1759 |
| 1686 // Register the debug event listener pasing the function | 1760 // Register the debug event listener pasing the function |
| 1687 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); | 1761 v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); |
| 1688 | 1762 |
| 1689 break_point_hit_count = 0; | 1763 break_point_hit_count = 0; |
| 1690 foo->Call(env->Global(), 0, NULL); | 1764 foo->Call(env->Global(), 0, NULL); |
| 1691 CHECK_EQ(1, break_point_hit_count); | 1765 CHECK_EQ(1, break_point_hit_count); |
| 1692 | 1766 |
| 1693 break_point_hit_count = 0; | 1767 break_point_hit_count = 0; |
| 1694 foo->Call(env->Global(), 0, NULL); | 1768 foo->Call(env->Global(), 0, NULL); |
| 1695 CHECK_EQ(0, break_point_hit_count); | 1769 CHECK_EQ(0, break_point_hit_count); |
| 1696 | 1770 |
| 1697 v8::Debug::SetDebugEventListener(NULL); | 1771 v8::Debug::SetDebugEventListener(NULL); |
| 1772 CheckDebuggerUnloaded(); |
| 1698 } | 1773 } |
| 1699 | 1774 |
| 1700 | 1775 |
| 1701 // Test that the debugger statement causes a break. | 1776 // Test that the debugger statement causes a break. |
| 1702 TEST(DebuggerStatement) { | 1777 TEST(DebuggerStatement) { |
| 1703 break_point_hit_count = 0; | 1778 break_point_hit_count = 0; |
| 1704 v8::HandleScope scope; | 1779 v8::HandleScope scope; |
| 1705 DebugLocalContext env; | 1780 DebugLocalContext env; |
| 1706 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1781 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 1707 v8::Undefined()); | 1782 v8::Undefined()); |
| 1708 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run(); | 1783 v8::Script::Compile(v8::String::New("function bar(){debugger}"))->Run(); |
| 1709 v8::Script::Compile(v8::String::New( | 1784 v8::Script::Compile(v8::String::New( |
| 1710 "function foo(){debugger;debugger;}"))->Run(); | 1785 "function foo(){debugger;debugger;}"))->Run(); |
| 1711 v8::Local<v8::Function> foo = | 1786 v8::Local<v8::Function> foo = |
| 1712 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 1787 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); |
| 1713 v8::Local<v8::Function> bar = | 1788 v8::Local<v8::Function> bar = |
| 1714 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar"))); | 1789 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("bar"))); |
| 1715 | 1790 |
| 1716 // Run function with debugger statement | 1791 // Run function with debugger statement |
| 1717 bar->Call(env->Global(), 0, NULL); | 1792 bar->Call(env->Global(), 0, NULL); |
| 1718 CHECK_EQ(1, break_point_hit_count); | 1793 CHECK_EQ(1, break_point_hit_count); |
| 1719 | 1794 |
| 1720 // Run function with two debugger statement | 1795 // Run function with two debugger statement |
| 1721 foo->Call(env->Global(), 0, NULL); | 1796 foo->Call(env->Global(), 0, NULL); |
| 1722 CHECK_EQ(3, break_point_hit_count); | 1797 CHECK_EQ(3, break_point_hit_count); |
| 1723 | 1798 |
| 1724 v8::Debug::SetDebugEventListener(NULL); | 1799 v8::Debug::SetDebugEventListener(NULL); |
| 1800 CheckDebuggerUnloaded(); |
| 1725 } | 1801 } |
| 1726 | 1802 |
| 1727 | 1803 |
| 1728 // Thest that the evaluation of expressions when a break point is hit generates | 1804 // Thest that the evaluation of expressions when a break point is hit generates |
| 1729 // the correct results. | 1805 // the correct results. |
| 1730 TEST(DebugEvaluate) { | 1806 TEST(DebugEvaluate) { |
| 1731 v8::HandleScope scope; | 1807 v8::HandleScope scope; |
| 1732 DebugLocalContext env; | 1808 DebugLocalContext env; |
| 1733 env.ExposeDebug(); | 1809 env.ExposeDebug(); |
| 1734 | 1810 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 // Call bar setting breakpoint after a=x in barbar and parameter | 1905 // Call bar setting breakpoint after a=x in barbar and parameter |
| 1830 // "Hello, world!". | 1906 // "Hello, world!". |
| 1831 checks = checks_hh; | 1907 checks = checks_hh; |
| 1832 v8::Handle<v8::Value> argv_bar_3[2] = { | 1908 v8::Handle<v8::Value> argv_bar_3[2] = { |
| 1833 v8::String::New("Hello, world!"), | 1909 v8::String::New("Hello, world!"), |
| 1834 v8::Number::New(barbar_break_position + 1) | 1910 v8::Number::New(barbar_break_position + 1) |
| 1835 }; | 1911 }; |
| 1836 bar->Call(env->Global(), 2, argv_bar_3); | 1912 bar->Call(env->Global(), 2, argv_bar_3); |
| 1837 | 1913 |
| 1838 v8::Debug::SetDebugEventListener(NULL); | 1914 v8::Debug::SetDebugEventListener(NULL); |
| 1915 CheckDebuggerUnloaded(); |
| 1839 } | 1916 } |
| 1840 | 1917 |
| 1841 | 1918 |
| 1842 // Simple test of the stepping mechanism using only store ICs. | 1919 // Simple test of the stepping mechanism using only store ICs. |
| 1843 TEST(DebugStepLinear) { | 1920 TEST(DebugStepLinear) { |
| 1844 v8::HandleScope scope; | 1921 v8::HandleScope scope; |
| 1845 DebugLocalContext env; | 1922 DebugLocalContext env; |
| 1846 | 1923 |
| 1847 // Create a function for testing stepping. | 1924 // Create a function for testing stepping. |
| 1848 v8::Local<v8::Function> foo = CompileFunction(&env, | 1925 v8::Local<v8::Function> foo = CompileFunction(&env, |
| 1849 "function foo(){a=1;b=1;c=1;}", | 1926 "function foo(){a=1;b=1;c=1;}", |
| 1850 "foo"); | 1927 "foo"); |
| 1851 SetBreakPoint(foo, 3); | 1928 SetBreakPoint(foo, 3); |
| 1852 | 1929 |
| 1853 // Register a debug event listener which steps and counts. | 1930 // Register a debug event listener which steps and counts. |
| 1854 v8::Debug::SetDebugEventListener(DebugEventStep); | 1931 v8::Debug::SetDebugEventListener(DebugEventStep); |
| 1855 | 1932 |
| 1856 step_action = StepIn; | 1933 step_action = StepIn; |
| 1857 break_point_hit_count = 0; | 1934 break_point_hit_count = 0; |
| 1858 foo->Call(env->Global(), 0, NULL); | 1935 foo->Call(env->Global(), 0, NULL); |
| 1859 | 1936 |
| 1860 // With stepping all break locations are hit. | 1937 // With stepping all break locations are hit. |
| 1861 CHECK_EQ(4, break_point_hit_count); | 1938 CHECK_EQ(4, break_point_hit_count); |
| 1862 | 1939 |
| 1863 v8::Debug::SetDebugEventListener(NULL); | 1940 v8::Debug::SetDebugEventListener(NULL); |
| 1941 CheckDebuggerUnloaded(); |
| 1864 | 1942 |
| 1865 // Register a debug event listener which just counts. | 1943 // Register a debug event listener which just counts. |
| 1866 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 1944 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
| 1867 | 1945 |
| 1946 SetBreakPoint(foo, 3); |
| 1868 break_point_hit_count = 0; | 1947 break_point_hit_count = 0; |
| 1869 foo->Call(env->Global(), 0, NULL); | 1948 foo->Call(env->Global(), 0, NULL); |
| 1870 | 1949 |
| 1871 // Without stepping only active break points are hit. | 1950 // Without stepping only active break points are hit. |
| 1872 CHECK_EQ(1, break_point_hit_count); | 1951 CHECK_EQ(1, break_point_hit_count); |
| 1873 | 1952 |
| 1874 v8::Debug::SetDebugEventListener(NULL); | 1953 v8::Debug::SetDebugEventListener(NULL); |
| 1954 CheckDebuggerUnloaded(); |
| 1875 } | 1955 } |
| 1876 | 1956 |
| 1877 | 1957 |
| 1878 // Test the stepping mechanism with different ICs. | 1958 // Test the stepping mechanism with different ICs. |
| 1879 TEST(DebugStepLinearMixedICs) { | 1959 TEST(DebugStepLinearMixedICs) { |
| 1880 v8::HandleScope scope; | 1960 v8::HandleScope scope; |
| 1881 DebugLocalContext env; | 1961 DebugLocalContext env; |
| 1882 | 1962 |
| 1883 // Create a function for testing stepping. | 1963 // Create a function for testing stepping. |
| 1884 v8::Local<v8::Function> foo = CompileFunction(&env, | 1964 v8::Local<v8::Function> foo = CompileFunction(&env, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1899 | 1979 |
| 1900 // With stepping all break locations are hit. For ARM the keyed load/store | 1980 // With stepping all break locations are hit. For ARM the keyed load/store |
| 1901 // is not hit as they are not implemented as ICs. | 1981 // is not hit as they are not implemented as ICs. |
| 1902 #if defined (__arm__) || defined(__thumb__) | 1982 #if defined (__arm__) || defined(__thumb__) |
| 1903 CHECK_EQ(6, break_point_hit_count); | 1983 CHECK_EQ(6, break_point_hit_count); |
| 1904 #else | 1984 #else |
| 1905 CHECK_EQ(8, break_point_hit_count); | 1985 CHECK_EQ(8, break_point_hit_count); |
| 1906 #endif | 1986 #endif |
| 1907 | 1987 |
| 1908 v8::Debug::SetDebugEventListener(NULL); | 1988 v8::Debug::SetDebugEventListener(NULL); |
| 1989 CheckDebuggerUnloaded(); |
| 1909 | 1990 |
| 1910 // Register a debug event listener which just counts. | 1991 // Register a debug event listener which just counts. |
| 1911 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 1992 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
| 1912 | 1993 |
| 1994 SetBreakPoint(foo, 0); |
| 1913 break_point_hit_count = 0; | 1995 break_point_hit_count = 0; |
| 1914 foo->Call(env->Global(), 0, NULL); | 1996 foo->Call(env->Global(), 0, NULL); |
| 1915 | 1997 |
| 1916 // Without stepping only active break points are hit. | 1998 // Without stepping only active break points are hit. |
| 1917 CHECK_EQ(1, break_point_hit_count); | 1999 CHECK_EQ(1, break_point_hit_count); |
| 1918 | 2000 |
| 1919 v8::Debug::SetDebugEventListener(NULL); | 2001 v8::Debug::SetDebugEventListener(NULL); |
| 2002 CheckDebuggerUnloaded(); |
| 1920 } | 2003 } |
| 1921 | 2004 |
| 1922 | 2005 |
| 1923 TEST(DebugStepIf) { | 2006 TEST(DebugStepIf) { |
| 1924 v8::HandleScope scope; | 2007 v8::HandleScope scope; |
| 1925 DebugLocalContext env; | 2008 DebugLocalContext env; |
| 1926 | 2009 |
| 1927 // Register a debug event listener which steps and counts. | 2010 // Register a debug event listener which steps and counts. |
| 1928 v8::Debug::SetDebugEventListener(DebugEventStep); | 2011 v8::Debug::SetDebugEventListener(DebugEventStep); |
| 1929 | 2012 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1950 | 2033 |
| 1951 // Stepping through the false part. | 2034 // Stepping through the false part. |
| 1952 step_action = StepIn; | 2035 step_action = StepIn; |
| 1953 break_point_hit_count = 0; | 2036 break_point_hit_count = 0; |
| 1954 v8::Handle<v8::Value> argv_false[argc] = { v8::False() }; | 2037 v8::Handle<v8::Value> argv_false[argc] = { v8::False() }; |
| 1955 foo->Call(env->Global(), argc, argv_false); | 2038 foo->Call(env->Global(), argc, argv_false); |
| 1956 CHECK_EQ(4, break_point_hit_count); | 2039 CHECK_EQ(4, break_point_hit_count); |
| 1957 | 2040 |
| 1958 // Get rid of the debug event listener. | 2041 // Get rid of the debug event listener. |
| 1959 v8::Debug::SetDebugEventListener(NULL); | 2042 v8::Debug::SetDebugEventListener(NULL); |
| 2043 CheckDebuggerUnloaded(); |
| 1960 } | 2044 } |
| 1961 | 2045 |
| 1962 | 2046 |
| 1963 TEST(DebugStepSwitch) { | 2047 TEST(DebugStepSwitch) { |
| 1964 v8::HandleScope scope; | 2048 v8::HandleScope scope; |
| 1965 DebugLocalContext env; | 2049 DebugLocalContext env; |
| 1966 | 2050 |
| 1967 // Register a debug event listener which steps and counts. | 2051 // Register a debug event listener which steps and counts. |
| 1968 v8::Debug::SetDebugEventListener(DebugEventStep); | 2052 v8::Debug::SetDebugEventListener(DebugEventStep); |
| 1969 | 2053 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 | 2086 |
| 2003 // Last case. | 2087 // Last case. |
| 2004 step_action = StepIn; | 2088 step_action = StepIn; |
| 2005 break_point_hit_count = 0; | 2089 break_point_hit_count = 0; |
| 2006 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) }; | 2090 v8::Handle<v8::Value> argv_3[argc] = { v8::Number::New(3) }; |
| 2007 foo->Call(env->Global(), argc, argv_3); | 2091 foo->Call(env->Global(), argc, argv_3); |
| 2008 CHECK_EQ(4, break_point_hit_count); | 2092 CHECK_EQ(4, break_point_hit_count); |
| 2009 | 2093 |
| 2010 // Get rid of the debug event listener. | 2094 // Get rid of the debug event listener. |
| 2011 v8::Debug::SetDebugEventListener(NULL); | 2095 v8::Debug::SetDebugEventListener(NULL); |
| 2096 CheckDebuggerUnloaded(); |
| 2012 } | 2097 } |
| 2013 | 2098 |
| 2014 | 2099 |
| 2015 TEST(DebugStepFor) { | 2100 TEST(DebugStepFor) { |
| 2016 v8::HandleScope scope; | 2101 v8::HandleScope scope; |
| 2017 DebugLocalContext env; | 2102 DebugLocalContext env; |
| 2018 | 2103 |
| 2019 // Register a debug event listener which steps and counts. | 2104 // Register a debug event listener which steps and counts. |
| 2020 v8::Debug::SetDebugEventListener(DebugEventStep); | 2105 v8::Debug::SetDebugEventListener(DebugEventStep); |
| 2021 | 2106 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2039 | 2124 |
| 2040 // Looping 100 times. | 2125 // Looping 100 times. |
| 2041 step_action = StepIn; | 2126 step_action = StepIn; |
| 2042 break_point_hit_count = 0; | 2127 break_point_hit_count = 0; |
| 2043 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; | 2128 v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; |
| 2044 foo->Call(env->Global(), argc, argv_100); | 2129 foo->Call(env->Global(), argc, argv_100); |
| 2045 CHECK_EQ(203, break_point_hit_count); | 2130 CHECK_EQ(203, break_point_hit_count); |
| 2046 | 2131 |
| 2047 // Get rid of the debug event listener. | 2132 // Get rid of the debug event listener. |
| 2048 v8::Debug::SetDebugEventListener(NULL); | 2133 v8::Debug::SetDebugEventListener(NULL); |
| 2134 CheckDebuggerUnloaded(); |
| 2049 } | 2135 } |
| 2050 | 2136 |
| 2051 | 2137 |
| 2052 TEST(StepInOutSimple) { | 2138 TEST(StepInOutSimple) { |
| 2053 v8::HandleScope scope; | 2139 v8::HandleScope scope; |
| 2054 DebugLocalContext env; | 2140 DebugLocalContext env; |
| 2055 | 2141 |
| 2056 // Create a function for checking the function when hitting a break point. | 2142 // Create a function for checking the function when hitting a break point. |
| 2057 frame_function_name = CompileFunction(&env, | 2143 frame_function_name = CompileFunction(&env, |
| 2058 frame_function_name_source, | 2144 frame_function_name_source, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2084 | 2170 |
| 2085 // Step through invocation of a with step out. | 2171 // Step through invocation of a with step out. |
| 2086 step_action = StepOut; | 2172 step_action = StepOut; |
| 2087 break_point_hit_count = 0; | 2173 break_point_hit_count = 0; |
| 2088 expected_step_sequence = "a"; | 2174 expected_step_sequence = "a"; |
| 2089 a->Call(env->Global(), 0, NULL); | 2175 a->Call(env->Global(), 0, NULL); |
| 2090 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2176 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2091 | 2177 |
| 2092 // Get rid of the debug event listener. | 2178 // Get rid of the debug event listener. |
| 2093 v8::Debug::SetDebugEventListener(NULL); | 2179 v8::Debug::SetDebugEventListener(NULL); |
| 2180 CheckDebuggerUnloaded(); |
| 2094 } | 2181 } |
| 2095 | 2182 |
| 2096 | 2183 |
| 2097 TEST(StepInOutTree) { | 2184 TEST(StepInOutTree) { |
| 2098 v8::HandleScope scope; | 2185 v8::HandleScope scope; |
| 2099 DebugLocalContext env; | 2186 DebugLocalContext env; |
| 2100 | 2187 |
| 2101 // Create a function for checking the function when hitting a break point. | 2188 // Create a function for checking the function when hitting a break point. |
| 2102 frame_function_name = CompileFunction(&env, | 2189 frame_function_name = CompileFunction(&env, |
| 2103 frame_function_name_source, | 2190 frame_function_name_source, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2130 | 2217 |
| 2131 // Step through invocation of a with step out. | 2218 // Step through invocation of a with step out. |
| 2132 step_action = StepOut; | 2219 step_action = StepOut; |
| 2133 break_point_hit_count = 0; | 2220 break_point_hit_count = 0; |
| 2134 expected_step_sequence = "a"; | 2221 expected_step_sequence = "a"; |
| 2135 a->Call(env->Global(), 0, NULL); | 2222 a->Call(env->Global(), 0, NULL); |
| 2136 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2223 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2137 | 2224 |
| 2138 // Get rid of the debug event listener. | 2225 // Get rid of the debug event listener. |
| 2139 v8::Debug::SetDebugEventListener(NULL); | 2226 v8::Debug::SetDebugEventListener(NULL); |
| 2227 CheckDebuggerUnloaded(true); |
| 2140 } | 2228 } |
| 2141 | 2229 |
| 2142 | 2230 |
| 2143 TEST(StepInOutBranch) { | 2231 TEST(StepInOutBranch) { |
| 2144 v8::HandleScope scope; | 2232 v8::HandleScope scope; |
| 2145 DebugLocalContext env; | 2233 DebugLocalContext env; |
| 2146 | 2234 |
| 2147 // Create a function for checking the function when hitting a break point. | 2235 // Create a function for checking the function when hitting a break point. |
| 2148 frame_function_name = CompileFunction(&env, | 2236 frame_function_name = CompileFunction(&env, |
| 2149 frame_function_name_source, | 2237 frame_function_name_source, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2161 | 2249 |
| 2162 // Step through invocation of a. | 2250 // Step through invocation of a. |
| 2163 step_action = StepIn; | 2251 step_action = StepIn; |
| 2164 break_point_hit_count = 0; | 2252 break_point_hit_count = 0; |
| 2165 expected_step_sequence = "abaca"; | 2253 expected_step_sequence = "abaca"; |
| 2166 a->Call(env->Global(), 0, NULL); | 2254 a->Call(env->Global(), 0, NULL); |
| 2167 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2255 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2168 | 2256 |
| 2169 // Get rid of the debug event listener. | 2257 // Get rid of the debug event listener. |
| 2170 v8::Debug::SetDebugEventListener(NULL); | 2258 v8::Debug::SetDebugEventListener(NULL); |
| 2259 CheckDebuggerUnloaded(); |
| 2171 } | 2260 } |
| 2172 | 2261 |
| 2173 | 2262 |
| 2174 // Test that step in does not step into native functions. | 2263 // Test that step in does not step into native functions. |
| 2175 TEST(DebugStepNatives) { | 2264 TEST(DebugStepNatives) { |
| 2176 v8::HandleScope scope; | 2265 v8::HandleScope scope; |
| 2177 DebugLocalContext env; | 2266 DebugLocalContext env; |
| 2178 | 2267 |
| 2179 // Create a function for testing stepping. | 2268 // Create a function for testing stepping. |
| 2180 v8::Local<v8::Function> foo = CompileFunction( | 2269 v8::Local<v8::Function> foo = CompileFunction( |
| 2181 &env, | 2270 &env, |
| 2182 "function foo(){debugger;Math.sin(1);}", | 2271 "function foo(){debugger;Math.sin(1);}", |
| 2183 "foo"); | 2272 "foo"); |
| 2184 | 2273 |
| 2185 // Register a debug event listener which steps and counts. | 2274 // Register a debug event listener which steps and counts. |
| 2186 v8::Debug::SetDebugEventListener(DebugEventStep); | 2275 v8::Debug::SetDebugEventListener(DebugEventStep); |
| 2187 | 2276 |
| 2188 step_action = StepIn; | 2277 step_action = StepIn; |
| 2189 break_point_hit_count = 0; | 2278 break_point_hit_count = 0; |
| 2190 foo->Call(env->Global(), 0, NULL); | 2279 foo->Call(env->Global(), 0, NULL); |
| 2191 | 2280 |
| 2192 // With stepping all break locations are hit. | 2281 // With stepping all break locations are hit. |
| 2193 CHECK_EQ(3, break_point_hit_count); | 2282 CHECK_EQ(3, break_point_hit_count); |
| 2194 | 2283 |
| 2195 v8::Debug::SetDebugEventListener(NULL); | 2284 v8::Debug::SetDebugEventListener(NULL); |
| 2285 CheckDebuggerUnloaded(); |
| 2196 | 2286 |
| 2197 // Register a debug event listener which just counts. | 2287 // Register a debug event listener which just counts. |
| 2198 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); | 2288 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount); |
| 2199 | 2289 |
| 2200 break_point_hit_count = 0; | 2290 break_point_hit_count = 0; |
| 2201 foo->Call(env->Global(), 0, NULL); | 2291 foo->Call(env->Global(), 0, NULL); |
| 2202 | 2292 |
| 2203 // Without stepping only active break points are hit. | 2293 // Without stepping only active break points are hit. |
| 2204 CHECK_EQ(1, break_point_hit_count); | 2294 CHECK_EQ(1, break_point_hit_count); |
| 2205 | 2295 |
| 2206 v8::Debug::SetDebugEventListener(NULL); | 2296 v8::Debug::SetDebugEventListener(NULL); |
| 2297 CheckDebuggerUnloaded(); |
| 2207 } | 2298 } |
| 2208 | 2299 |
| 2209 | 2300 |
| 2210 // Test break on exceptions. For each exception break combination the number | 2301 // Test break on exceptions. For each exception break combination the number |
| 2211 // of debug event exception callbacks and message callbacks are collected. The | 2302 // of debug event exception callbacks and message callbacks are collected. The |
| 2212 // number of debug event exception callbacks are used to check that the | 2303 // number of debug event exception callbacks are used to check that the |
| 2213 // debugger is called correctly and the number of message callbacks is used to | 2304 // debugger is called correctly and the number of message callbacks is used to |
| 2214 // check that uncaught exceptions are still returned even if there is a break | 2305 // check that uncaught exceptions are still returned even if there is a break |
| 2215 // for them. | 2306 // for them. |
| 2216 TEST(BreakOnException) { | 2307 TEST(BreakOnException) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2343 caught->Call(env->Global(), 0, NULL); | 2434 caught->Call(env->Global(), 0, NULL); |
| 2344 CHECK_EQ(1, exception_hit_count); | 2435 CHECK_EQ(1, exception_hit_count); |
| 2345 CHECK_EQ(0, uncaught_exception_hit_count); | 2436 CHECK_EQ(0, uncaught_exception_hit_count); |
| 2346 CHECK_EQ(0, message_callback_count); | 2437 CHECK_EQ(0, message_callback_count); |
| 2347 notCaught->Call(env->Global(), 0, NULL); | 2438 notCaught->Call(env->Global(), 0, NULL); |
| 2348 CHECK_EQ(2, exception_hit_count); | 2439 CHECK_EQ(2, exception_hit_count); |
| 2349 CHECK_EQ(1, uncaught_exception_hit_count); | 2440 CHECK_EQ(1, uncaught_exception_hit_count); |
| 2350 CHECK_EQ(1, message_callback_count); | 2441 CHECK_EQ(1, message_callback_count); |
| 2351 | 2442 |
| 2352 v8::Debug::SetDebugEventListener(NULL); | 2443 v8::Debug::SetDebugEventListener(NULL); |
| 2444 CheckDebuggerUnloaded(); |
| 2353 v8::V8::RemoveMessageListeners(MessageCallbackCount); | 2445 v8::V8::RemoveMessageListeners(MessageCallbackCount); |
| 2354 } | 2446 } |
| 2355 | 2447 |
| 2356 | 2448 |
| 2357 // Test break on exception from compiler errors. When compiling using | 2449 // Test break on exception from compiler errors. When compiling using |
| 2358 // v8::Script::Compile there is no JavaScript stack whereas when compiling using | 2450 // v8::Script::Compile there is no JavaScript stack whereas when compiling using |
| 2359 // eval there are JavaScript frames. | 2451 // eval there are JavaScript frames. |
| 2360 TEST(BreakOnCompileException) { | 2452 TEST(BreakOnCompileException) { |
| 2361 v8::HandleScope scope; | 2453 v8::HandleScope scope; |
| 2362 DebugLocalContext env; | 2454 DebugLocalContext env; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2479 // Step through invocation of f + g + h now with break on caught exceptions. | 2571 // Step through invocation of f + g + h now with break on caught exceptions. |
| 2480 ChangeBreakOnException(true, true); | 2572 ChangeBreakOnException(true, true); |
| 2481 step_action = StepIn; | 2573 step_action = StepIn; |
| 2482 break_point_hit_count = 0; | 2574 break_point_hit_count = 0; |
| 2483 expected_step_sequence = "ffghhf"; | 2575 expected_step_sequence = "ffghhf"; |
| 2484 f->Call(env->Global(), 0, NULL); | 2576 f->Call(env->Global(), 0, NULL); |
| 2485 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); | 2577 CHECK_EQ(strlen(expected_step_sequence), break_point_hit_count); |
| 2486 | 2578 |
| 2487 // Get rid of the debug event listener. | 2579 // Get rid of the debug event listener. |
| 2488 v8::Debug::SetDebugEventListener(NULL); | 2580 v8::Debug::SetDebugEventListener(NULL); |
| 2581 CheckDebuggerUnloaded(); |
| 2489 } | 2582 } |
| 2490 | 2583 |
| 2491 | 2584 |
| 2492 TEST(DebugBreak) { | 2585 TEST(DebugBreak) { |
| 2493 v8::HandleScope scope; | 2586 v8::HandleScope scope; |
| 2494 DebugLocalContext env; | 2587 DebugLocalContext env; |
| 2495 | 2588 |
| 2496 // This test should be run with option --verify-heap. This is an ASSERT and | 2589 // This test should be run with option --verify-heap. This is an ASSERT and |
| 2497 // not a CHECK as --verify-heap is only available in debug mode. | 2590 // not a CHECK as --verify-heap is only available in debug mode. |
| 2498 ASSERT(v8::internal::FLAG_verify_heap); | 2591 ASSERT(v8::internal::FLAG_verify_heap); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2532 f1->Call(env->Global(), i, argv); | 2625 f1->Call(env->Global(), i, argv); |
| 2533 f2->Call(env->Global(), i, argv); | 2626 f2->Call(env->Global(), i, argv); |
| 2534 f3->Call(env->Global(), i, argv); | 2627 f3->Call(env->Global(), i, argv); |
| 2535 } | 2628 } |
| 2536 | 2629 |
| 2537 // One break for each function called. | 2630 // One break for each function called. |
| 2538 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); | 2631 CHECK_EQ(4 * ARRAY_SIZE(argv), break_point_hit_count); |
| 2539 | 2632 |
| 2540 // Get rid of the debug event listener. | 2633 // Get rid of the debug event listener. |
| 2541 v8::Debug::SetDebugEventListener(NULL); | 2634 v8::Debug::SetDebugEventListener(NULL); |
| 2635 CheckDebuggerUnloaded(); |
| 2542 } | 2636 } |
| 2543 | 2637 |
| 2544 | 2638 |
| 2545 // Test to ensure that JavaScript code keeps running while the debug break | 2639 // Test to ensure that JavaScript code keeps running while the debug break |
| 2546 // through the stack limit flag is set but breaks are disabled. | 2640 // through the stack limit flag is set but breaks are disabled. |
| 2547 TEST(DisableBreak) { | 2641 TEST(DisableBreak) { |
| 2548 v8::HandleScope scope; | 2642 v8::HandleScope scope; |
| 2549 DebugLocalContext env; | 2643 DebugLocalContext env; |
| 2550 | 2644 |
| 2551 // Register a debug event listener which sets the break flag and counts. | 2645 // Register a debug event listener which sets the break flag and counts. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2568 v8::internal::DisableBreak disable_break(true); | 2662 v8::internal::DisableBreak disable_break(true); |
| 2569 f->Call(env->Global(), 0, NULL); | 2663 f->Call(env->Global(), 0, NULL); |
| 2570 CHECK_EQ(1, break_point_hit_count); | 2664 CHECK_EQ(1, break_point_hit_count); |
| 2571 } | 2665 } |
| 2572 | 2666 |
| 2573 f->Call(env->Global(), 0, NULL); | 2667 f->Call(env->Global(), 0, NULL); |
| 2574 CHECK_EQ(2, break_point_hit_count); | 2668 CHECK_EQ(2, break_point_hit_count); |
| 2575 | 2669 |
| 2576 // Get rid of the debug event listener. | 2670 // Get rid of the debug event listener. |
| 2577 v8::Debug::SetDebugEventListener(NULL); | 2671 v8::Debug::SetDebugEventListener(NULL); |
| 2672 CheckDebuggerUnloaded(); |
| 2578 } | 2673 } |
| 2579 | 2674 |
| 2580 | 2675 |
| 2581 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) { | 2676 static v8::Handle<v8::Array> NamedEnum(const v8::AccessorInfo&) { |
| 2582 v8::Handle<v8::Array> result = v8::Array::New(3); | 2677 v8::Handle<v8::Array> result = v8::Array::New(3); |
| 2583 result->Set(v8::Integer::New(0), v8::String::New("a")); | 2678 result->Set(v8::Integer::New(0), v8::String::New("a")); |
| 2584 result->Set(v8::Integer::New(1), v8::String::New("b")); | 2679 result->Set(v8::Integer::New(1), v8::String::New("b")); |
| 2585 result->Set(v8::Integer::New(2), v8::String::New("c")); | 2680 result->Set(v8::Integer::New(2), v8::String::New("c")); |
| 2586 return result; | 2681 return result; |
| 2587 } | 2682 } |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3499 " CheckSourceLine(2)\n" | 3594 " CheckSourceLine(2)\n" |
| 3500 " CheckSourceLine(3)\n" | 3595 " CheckSourceLine(3)\n" |
| 3501 "}; f()"))->Run(); | 3596 "}; f()"))->Run(); |
| 3502 | 3597 |
| 3503 // Test that a parameter can be passed to a function called in the debugger. | 3598 // Test that a parameter can be passed to a function called in the debugger. |
| 3504 v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run(); | 3599 v8::Script::Compile(v8::String::New("CheckDataParameter()"))->Run(); |
| 3505 | 3600 |
| 3506 // Test that a function with closure can be run in the debugger. | 3601 // Test that a function with closure can be run in the debugger. |
| 3507 v8::Script::Compile(v8::String::New("CheckClosure()"))->Run(); | 3602 v8::Script::Compile(v8::String::New("CheckClosure()"))->Run(); |
| 3508 } | 3603 } |
| 3604 |
| 3605 |
| 3606 // Test that clearing the debug event listener actually clears all break points |
| 3607 // and related information. |
| 3608 TEST(DebuggerUnload) { |
| 3609 v8::HandleScope scope; |
| 3610 DebugLocalContext env; |
| 3611 |
| 3612 // Check debugger is unloaded before it is used. |
| 3613 CheckDebuggerUnloaded(); |
| 3614 |
| 3615 // Add debug event listener. |
| 3616 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 3617 v8::Undefined()); |
| 3618 CheckDebuggerLoaded(); |
| 3619 |
| 3620 // Create a couple of functions for the test. |
| 3621 v8::Local<v8::Function> foo = |
| 3622 CompileFunction(&env, "function foo(){x=1}", "foo"); |
| 3623 v8::Local<v8::Function> bar = |
| 3624 CompileFunction(&env, "function bar(){y=2}", "bar"); |
| 3625 |
| 3626 // Set some break points. |
| 3627 SetBreakPoint(foo, 0); |
| 3628 SetBreakPoint(foo, 4); |
| 3629 SetBreakPoint(bar, 0); |
| 3630 SetBreakPoint(bar, 4); |
| 3631 |
| 3632 // Make sure that the break points are there. |
| 3633 break_point_hit_count = 0; |
| 3634 foo->Call(env->Global(), 0, NULL); |
| 3635 CHECK_EQ(2, break_point_hit_count); |
| 3636 bar->Call(env->Global(), 0, NULL); |
| 3637 CHECK_EQ(4, break_point_hit_count); |
| 3638 |
| 3639 // Remove the debug event listener without clearing breakpoints. |
| 3640 v8::Debug::SetDebugEventListener(NULL); |
| 3641 CheckDebuggerUnloaded(true); |
| 3642 |
| 3643 // Set a new debug event listener. |
| 3644 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 3645 v8::Undefined()); |
| 3646 CheckDebuggerLoaded(); |
| 3647 |
| 3648 // Check that the break points was actually cleared. |
| 3649 break_point_hit_count = 0; |
| 3650 foo->Call(env->Global(), 0, NULL); |
| 3651 CHECK_EQ(0, break_point_hit_count); |
| 3652 |
| 3653 // Set break points and run again. |
| 3654 SetBreakPoint(foo, 0); |
| 3655 SetBreakPoint(foo, 4); |
| 3656 foo->Call(env->Global(), 0, NULL); |
| 3657 CHECK_EQ(2, break_point_hit_count); |
| 3658 |
| 3659 // Remove the debug event listener without clearing breakpoints again. |
| 3660 v8::Debug::SetDebugEventListener(NULL); |
| 3661 CheckDebuggerUnloaded(true); |
| 3662 } |
| OLD | NEW |