28 #ifdef ENABLE_DEBUGGER_SUPPORT
44 using ::v8::internal::EmbeddedVector;
46 using ::v8::internal::OS;
47 using ::v8::internal::Handle;
48 using ::v8::internal::Heap;
49 using ::v8::internal::JSGlobalProxy;
50 using ::v8::internal::Code;
51 using ::v8::internal::Debug;
52 using ::v8::internal::Debugger;
53 using ::v8::internal::CommandMessage;
54 using ::v8::internal::CommandMessageQueue;
55 using ::v8::internal::StepAction;
56 using ::v8::internal::StepIn;
57 using ::v8::internal::StepNext;
58 using ::v8::internal::StepOut;
59 using ::v8::internal::Vector;
63 #define SMALL_STRING_BUFFER_SIZE 80
71 const char* expected_source,
73 const char* value_source,
75 if (expected != value) {
76 V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# "
77 "Expected: %i\n# Found: %i",
78 expected_source, value_source, expected, value);
86 const char* unexpected_source,
88 const char* value_source,
90 if (unexpected == value) {
91 V8_Fatal(file, line,
"CHECK_NE(%s, %s) failed\n# Value: %i",
92 unexpected_source, value_source, value);
100 const char* expected_source,
101 const Code* expected,
102 const char* value_source,
104 if (expected != value) {
105 V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# "
106 "Expected: %p\n# Found: %p",
107 expected_source, value_source, expected, value);
113 const char* expected_source,
114 const Code* expected,
115 const char* value_source,
117 if (expected == value) {
118 V8_Fatal(file, line,
"CHECK_NE(%s, %s) failed\n# Value: %p",
119 expected_source, value_source, value);
128 class DebugLocalContext {
130 inline DebugLocalContext(
135 : context_(v8::Context::New(extensions, global_template, global_object)) {
138 inline ~DebugLocalContext() {
142 inline v8::Context* operator->() {
return *context_; }
143 inline v8::Context* operator*() {
return *context_; }
144 inline bool IsReady() {
return !context_.IsEmpty(); }
146 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
149 debug->debug_context()->set_security_token(
152 Handle<JSGlobalProxy> global(Handle<JSGlobalProxy>::cast(
154 Handle<v8::internal::String> debug_string =
155 FACTORY->LookupAsciiSymbol(
"debug");
157 Handle<Object>(debug->debug_context()->global_proxy()),
DONT_ENUM,
172 const char* function_name) {
181 const char* function_name) {
191 Handle<v8::internal::SharedFunctionInfo> shared(f->shared());
192 return Debug::HasDebugInfo(shared);
198 static int SetBreakPoint(Handle<v8::internal::JSFunction> fun,
int position) {
199 static int break_point = 0;
200 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
201 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
202 debug->SetBreakPoint(
219 static int SetBreakPointFromJS(
const char* function_name,
220 int line,
int position) {
221 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
223 "debug.Debug.setBreakPoint(%s,%d,%d)",
224 function_name, line, position);
232 static int SetScriptBreakPointByIdFromJS(
int script_id,
int line,
int column) {
233 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
237 "debug.Debug.setScriptBreakPointById(%d,%d,%d)",
238 script_id, line, column);
242 "debug.Debug.setScriptBreakPointById(%d,%d)",
251 return value->Int32Value();
258 static int SetScriptBreakPointByNameFromJS(
const char* script_name,
259 int line,
int column) {
260 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
264 "debug.Debug.setScriptBreakPointByName(\"%s\",%d,%d)",
265 script_name, line, column);
269 "debug.Debug.setScriptBreakPointByName(\"%s\",%d)",
278 return value->Int32Value();
284 static void ClearBreakPoint(
int break_point) {
285 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
286 debug->ClearBreakPoint(
292 static void ClearBreakPointFromJS(
int break_point_number) {
293 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
295 "debug.Debug.clearBreakPoint(%d)",
302 static void EnableScriptBreakPointFromJS(
int break_point_number) {
303 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
305 "debug.Debug.enableScriptBreakPoint(%d)",
312 static void DisableScriptBreakPointFromJS(
int break_point_number) {
313 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
315 "debug.Debug.disableScriptBreakPoint(%d)",
322 static void ChangeScriptBreakPointConditionFromJS(
int break_point_number,
323 const char* condition) {
324 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
326 "debug.Debug.changeScriptBreakPointCondition(%d, \"%s\")",
327 break_point_number, condition);
333 static void ChangeScriptBreakPointIgnoreCountFromJS(
int break_point_number,
335 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
337 "debug.Debug.changeScriptBreakPointIgnoreCount(%d, %d)",
338 break_point_number, ignoreCount);
345 static void ChangeBreakOnException(
bool caught,
bool uncaught) {
346 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
347 debug->ChangeBreakOnException(v8::internal::BreakException, caught);
348 debug->ChangeBreakOnException(v8::internal::BreakUncaughtException, uncaught);
353 static void ChangeBreakOnExceptionFromJS(
bool caught,
bool uncaught) {
366 v8::String::New(
"debug.Debug.clearBreakOnUncaughtException()"))->Run();
372 static void PrepareStep(StepAction step_action) {
373 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
374 debug->PrepareStep(step_action, 1);
384 Handle<FixedArray> GetDebuggedFunctions() {
385 Debug* debug = Isolate::Current()->debug();
387 v8::internal::DebugInfoListNode* node = debug->debug_info_list_;
397 Handle<FixedArray> debugged_functions =
403 debugged_functions->set(count++, *node->debug_info());
407 return debugged_functions;
411 static Handle<Code> ComputeCallDebugBreak(
int argc) {
412 return Isolate::Current()->stub_cache()->ComputeCallDebugBreak(argc,
418 void CheckDebuggerUnloaded(
bool check_functions) {
421 CHECK(Isolate::Current()->debug()->debug_context().is_null());
422 CHECK_EQ(
NULL, Isolate::Current()->debug()->debug_info_list_);
429 HeapIterator iterator;
430 for (HeapObject* obj = iterator.next(); obj !=
NULL; obj = iterator.next()) {
431 CHECK(!obj->IsDebugInfo());
432 CHECK(!obj->IsBreakPointInfo());
436 if (check_functions) {
437 if (obj->IsJSFunction()) {
439 for (RelocIterator it(fun->shared()->code()); !it.done(); it.next()) {
440 RelocInfo::Mode rmode = it.rinfo()->rmode();
441 if (RelocInfo::IsCodeTarget(rmode)) {
442 CHECK(!Debug::IsDebugBreak(it.rinfo()->target_address()));
443 }
else if (RelocInfo::IsJSReturn(rmode)) {
444 CHECK(!Debug::IsDebugBreakAtReturn(it.rinfo()));
453 void ForceUnloadDebugger() {
454 Isolate::Current()->debugger()->never_unload_debugger_ =
false;
455 Isolate::Current()->debugger()->UnloadDebugger();
463 static void CheckDebuggerUnloaded(
bool check_functions =
false) {
467 v8::internal::CheckDebuggerUnloaded(check_functions);
473 class TestBreakLocationIterator:
public v8::internal::BreakLocationIterator {
475 explicit TestBreakLocationIterator(Handle<v8::internal::DebugInfo> debug_info)
476 : BreakLocationIterator(debug_info, v8::internal::SOURCE_BREAK_LOCATIONS) {}
479 return reloc_iterator_original_;
486 void CheckDebugBreakFunction(DebugLocalContext* env,
487 const char* source,
const char*
name,
488 int position, v8::internal::RelocInfo::Mode mode,
490 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
494 *CompileFunction(env, source, name));
495 int bp = SetBreakPoint(fun, position);
498 Handle<v8::internal::SharedFunctionInfo> shared(fun->shared());
499 CHECK(Debug::HasDebugInfo(shared));
500 TestBreakLocationIterator it1(Debug::GetDebugInfo(shared));
501 it1.FindBreakLocationFromPosition(position);
502 v8::internal::RelocInfo::Mode actual_mode = it1.it()->rinfo()->rmode();
503 if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
504 actual_mode = v8::internal::RelocInfo::CODE_TARGET;
507 if (mode != v8::internal::RelocInfo::JS_RETURN) {
509 Code::GetCodeFromTargetAddress(it1.it()->rinfo()->target_address()));
511 CHECK(Debug::IsDebugBreakAtReturn(it1.it()->rinfo()));
517 CHECK(!debug->HasDebugInfo(shared));
518 CHECK(debug->EnsureDebugInfo(shared));
519 TestBreakLocationIterator it2(Debug::GetDebugInfo(shared));
520 it2.FindBreakLocationFromPosition(position);
521 actual_mode = it2.it()->rinfo()->rmode();
522 if (actual_mode == v8::internal::RelocInfo::CODE_TARGET_WITH_ID) {
523 actual_mode = v8::internal::RelocInfo::CODE_TARGET;
526 if (mode == v8::internal::RelocInfo::JS_RETURN) {
527 CHECK(!Debug::IsDebugBreakAtReturn(it2.it()->rinfo()));
540 const char* frame_function_name_source =
541 "function frame_function_name(exec_state, frame_number) {"
542 " return exec_state.frame(frame_number).func().name();"
549 const char* frame_argument_name_source =
550 "function frame_argument_name(exec_state, frame_number) {"
551 " return exec_state.frame(frame_number).argumentName(0);"
558 const char* frame_argument_value_source =
559 "function frame_argument_value(exec_state, frame_number) {"
560 " return exec_state.frame(frame_number).argumentValue(0).value_;"
567 const char* frame_local_name_source =
568 "function frame_local_name(exec_state, frame_number) {"
569 " return exec_state.frame(frame_number).localName(0);"
576 const char* frame_local_value_source =
577 "function frame_local_value(exec_state, frame_number) {"
578 " return exec_state.frame(frame_number).localValue(0).value_;"
585 const char* frame_source_line_source =
586 "function frame_source_line(exec_state) {"
587 " return exec_state.frame(0).sourceLine();"
594 const char* frame_source_column_source =
595 "function frame_source_column(exec_state) {"
596 " return exec_state.frame(0).sourceColumn();"
603 const char* frame_script_name_source =
604 "function frame_script_name(exec_state) {"
605 " return exec_state.frame(0).func().script().name();"
612 const char* frame_script_data_source =
613 "function frame_script_data(exec_state) {"
614 " return exec_state.frame(0).func().script().data();"
621 const char* compiled_script_data_source =
622 "function compiled_script_data(event_data) {"
623 " return event_data.script().data();"
629 static const char* frame_count_source =
630 "function frame_count(exec_state) {"
631 " return exec_state.frameCount();"
637 char last_function_hit[80];
641 char last_script_name_hit[80];
642 char last_script_data_hit[80];
645 int last_source_line = -1;
646 int last_source_column = -1;
649 int break_point_hit_count = 0;
650 int break_point_hit_count_deoptimize = 0;
655 Debug* debug = v8::internal::Isolate::Current()->debug();
661 break_point_hit_count++;
662 if (!frame_function_name.
IsEmpty()) {
669 last_function_hit[0] =
'\0';
673 function_name->WriteAscii(last_function_hit);
677 if (!frame_source_line.
IsEmpty()) {
687 if (!frame_source_column.
IsEmpty()) {
697 if (!frame_script_name.
IsEmpty()) {
704 last_script_name_hit[0] =
'\0';
708 script_name->WriteAscii(last_script_name_hit);
712 if (!frame_script_data.
IsEmpty()) {
719 last_script_data_hit[0] =
'\0';
724 script_data->WriteAscii(last_script_data_hit);
730 if (break_point_hit_count == break_point_hit_count_deoptimize) {
739 last_script_data_hit[0] =
'\0';
744 script_data->WriteAscii(last_script_data_hit);
752 int exception_hit_count = 0;
753 int uncaught_exception_hit_count = 0;
754 int last_js_stack_height = -1;
756 static void DebugEventCounterClear() {
757 break_point_hit_count = 0;
758 exception_hit_count = 0;
759 uncaught_exception_hit_count = 0;
766 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
773 break_point_hit_count++;
775 exception_hit_count++;
782 if (result->IsTrue()) {
783 uncaught_exception_hit_count++;
790 static const int kArgc = 1;
807 struct EvaluateCheck {
812 struct EvaluateCheck* checks =
NULL;
815 const char* evaluate_check_source =
816 "function evaluate_check(exec_state, expr, expected) {"
817 " return exec_state.frame(0).evaluate(expr).value() === expected;"
826 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
831 for (
int i = 0; checks[i].expr !=
NULL; i++) {
835 checks[i].expected };
837 evaluate_check_function->
Call(exec_state, argc, argv);
840 V8_Fatal(__FILE__, __LINE__,
"%s != %s", checks[i].expr, *ascii);
848 int debug_event_remove_break_point = 0;
853 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
858 break_point_hit_count++;
860 ClearBreakPoint(debug_event_remove_break_point);
867 StepAction step_action = StepIn;
872 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
877 break_point_hit_count++;
878 PrepareStep(step_action);
892 const char* expected_step_sequence =
NULL;
899 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
905 CHECK(break_point_hit_count <
915 expected_step_sequence[break_point_hit_count]);
918 break_point_hit_count++;
919 PrepareStep(step_action);
925 static void DebugEventBreakPointCollectGarbage(
930 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
938 break_point_hit_count++;
939 if (break_point_hit_count % 2 == 0) {
944 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
956 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
962 break_point_hit_count++;
976 int max_break_point_hit_count = 0;
977 bool terminate_after_max_break_point_hit =
false;
982 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
987 if (break_point_hit_count < max_break_point_hit_count) {
989 break_point_hit_count++;
994 static const int kArgc = 1;
998 frame_count->
Call(exec_state, kArgc, argv);
1005 }
else if (terminate_after_max_break_point_hit) {
1012 if (break_point_hit_count == break_point_hit_count_deoptimize) {
1023 int message_callback_count = 0;
1025 static void MessageCallbackCountClear() {
1026 message_callback_count = 0;
1031 message_callback_count++;
1041 using ::v8::internal::Builtins;
1042 using ::v8::internal::Isolate;
1044 DebugLocalContext env;
1046 CheckDebugBreakFunction(&env,
1047 "function f1(){}",
"f1",
1049 v8::internal::RelocInfo::JS_RETURN,
1051 CheckDebugBreakFunction(&env,
1052 "function f2(){x=1;}",
"f2",
1054 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1055 Isolate::Current()->builtins()->builtin(
1056 Builtins::kStoreIC_DebugBreak));
1057 CheckDebugBreakFunction(&env,
1058 "function f3(){var a=x;}",
"f3",
1060 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1061 Isolate::Current()->builtins()->builtin(
1062 Builtins::kLoadIC_DebugBreak));
1068 #if !defined (__arm__) && !defined(__thumb__)
1069 CheckDebugBreakFunction(
1071 "function f4(){var index='propertyName'; var a={}; a[index] = 'x';}",
1074 v8::internal::RelocInfo::CODE_TARGET,
1075 Isolate::Current()->builtins()->builtin(
1076 Builtins::kKeyedStoreIC_DebugBreak));
1077 CheckDebugBreakFunction(
1079 "function f5(){var index='propertyName'; var a={}; return a[index];}",
1082 v8::internal::RelocInfo::CODE_TARGET,
1083 Isolate::Current()->builtins()->builtin(
1084 Builtins::kKeyedLoadIC_DebugBreak));
1089 Handle<Code> debug_break_0 = v8::internal::ComputeCallDebugBreak(0);
1090 Handle<Code> debug_break_1 = v8::internal::ComputeCallDebugBreak(1);
1091 Handle<Code> debug_break_4 = v8::internal::ComputeCallDebugBreak(4);
1093 CheckDebugBreakFunction(&env,
1094 "function f4_0(){x();}",
"f4_0",
1096 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1099 CheckDebugBreakFunction(&env,
1100 "function f4_1(){x(1);}",
"f4_1",
1102 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1105 CheckDebugBreakFunction(&env,
1106 "function f4_4(){x(1,2,3,4);}",
"f4_4",
1108 v8::internal::RelocInfo::CODE_TARGET_CONTEXT,
1117 DebugLocalContext env;
1120 CompileFunction(&env,
"function foo(){}",
"foo");
1122 CompileFunction(&env,
"function bar(){}",
"bar");
1124 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1125 CHECK(!HasDebugInfo(foo));
1126 CHECK(!HasDebugInfo(bar));
1128 int bp1 = SetBreakPoint(foo, 0);
1129 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
1130 CHECK(HasDebugInfo(foo));
1131 CHECK(!HasDebugInfo(bar));
1133 int bp2 = SetBreakPoint(bar, 0);
1134 CHECK_EQ(2, v8::internal::GetDebuggedFunctions()->length());
1135 CHECK(HasDebugInfo(foo));
1136 CHECK(HasDebugInfo(bar));
1138 ClearBreakPoint(bp1);
1139 CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
1140 CHECK(!HasDebugInfo(foo));
1141 CHECK(HasDebugInfo(bar));
1143 ClearBreakPoint(bp2);
1144 CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
1145 CHECK(!HasDebugInfo(foo));
1146 CHECK(!HasDebugInfo(bar));
1151 TEST(BreakPointICStore) {
1152 break_point_hit_count = 0;
1154 DebugLocalContext env;
1164 CHECK_EQ(0, break_point_hit_count);
1167 int bp = SetBreakPoint(foo, 0);
1169 CHECK_EQ(1, break_point_hit_count);
1171 CHECK_EQ(2, break_point_hit_count);
1174 ClearBreakPoint(bp);
1176 CHECK_EQ(2, break_point_hit_count);
1179 CheckDebuggerUnloaded();
1184 TEST(BreakPointICLoad) {
1185 break_point_hit_count = 0;
1187 DebugLocalContext env;
1197 CHECK_EQ(0, break_point_hit_count);
1200 int bp = SetBreakPoint(foo, 0);
1202 CHECK_EQ(1, break_point_hit_count);
1204 CHECK_EQ(2, break_point_hit_count);
1207 ClearBreakPoint(bp);
1209 CHECK_EQ(2, break_point_hit_count);
1212 CheckDebuggerUnloaded();
1217 TEST(BreakPointICCall) {
1218 break_point_hit_count = 0;
1220 DebugLocalContext env;
1230 CHECK_EQ(0, break_point_hit_count);
1233 int bp = SetBreakPoint(foo, 0);
1235 CHECK_EQ(1, break_point_hit_count);
1237 CHECK_EQ(2, break_point_hit_count);
1240 ClearBreakPoint(bp);
1242 CHECK_EQ(2, break_point_hit_count);
1245 CheckDebuggerUnloaded();
1250 TEST(BreakPointICCallWithGC) {
1251 break_point_hit_count = 0;
1253 DebugLocalContext env;
1263 CHECK_EQ(0, break_point_hit_count);
1266 int bp = SetBreakPoint(foo, 0);
1268 CHECK_EQ(1, break_point_hit_count);
1270 CHECK_EQ(2, break_point_hit_count);
1273 ClearBreakPoint(bp);
1275 CHECK_EQ(2, break_point_hit_count);
1278 CheckDebuggerUnloaded();
1283 TEST(BreakPointConstructCallWithGC) {
1284 break_point_hit_count = 0;
1286 DebugLocalContext env;
1291 "function foo(){return new bar(1).x;}"))->Run();
1297 CHECK_EQ(0, break_point_hit_count);
1300 int bp = SetBreakPoint(foo, 0);
1302 CHECK_EQ(1, break_point_hit_count);
1304 CHECK_EQ(2, break_point_hit_count);
1307 ClearBreakPoint(bp);
1309 CHECK_EQ(2, break_point_hit_count);
1312 CheckDebuggerUnloaded();
1317 TEST(BreakPointReturn) {
1318 break_point_hit_count = 0;
1320 DebugLocalContext env;
1324 frame_source_line = CompileFunction(&env,
1325 frame_source_line_source,
1326 "frame_source_line");
1327 frame_source_column = CompileFunction(&env,
1328 frame_source_column_source,
1329 "frame_source_column");
1340 CHECK_EQ(0, break_point_hit_count);
1343 int bp = SetBreakPoint(foo, 0);
1345 CHECK_EQ(1, break_point_hit_count);
1349 CHECK_EQ(2, break_point_hit_count);
1354 ClearBreakPoint(bp);
1356 CHECK_EQ(2, break_point_hit_count);
1359 CheckDebuggerUnloaded();
1365 int break_point_count,
1367 break_point_hit_count = 0;
1370 CHECK_EQ((i + 1) * break_point_count, break_point_hit_count);
1375 TEST(GCDuringBreakPointProcessing) {
1376 break_point_hit_count = 0;
1378 DebugLocalContext env;
1385 foo = CompileFunction(&env,
"function foo(){bar=0;}",
"foo");
1386 SetBreakPoint(foo, 0);
1387 CallWithBreakPoints(env->Global(),
foo, 1, 10);
1390 foo = CompileFunction(&env,
"bar=1;function foo(){var x=bar;}",
"foo");
1391 SetBreakPoint(foo, 0);
1392 CallWithBreakPoints(env->Global(),
foo, 1, 10);
1395 foo = CompileFunction(&env,
"function bar(){};function foo(){bar();}",
"foo");
1396 SetBreakPoint(foo, 0);
1397 CallWithBreakPoints(env->Global(),
foo, 1, 10);
1400 foo = CompileFunction(&env,
"function foo(){}",
"foo");
1401 SetBreakPoint(foo, 0);
1402 CallWithBreakPoints(env->Global(),
foo, 1, 25);
1405 foo = CompileFunction(&env,
"function foo(){var a;}",
"foo");
1406 SetBreakPoint(foo, 0);
1407 CallWithBreakPoints(env->Global(),
foo, 1, 25);
1410 CheckDebuggerUnloaded();
1418 break_point_hit_count = 0;
1420 for (
int i = 0; i < 3; i++) {
1423 CHECK_EQ(1 + i * 3, break_point_hit_count);
1428 CHECK_EQ(2 + i * 3, break_point_hit_count);
1431 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
1433 CHECK_EQ(3 + i * 3, break_point_hit_count);
1439 TEST(BreakPointSurviveGC) {
1440 break_point_hit_count = 0;
1442 DebugLocalContext env;
1450 CompileFunction(&env,
"function foo(){}",
"foo");
1451 foo = CompileFunction(&env,
"function foo(){bar=0;}",
"foo");
1452 SetBreakPoint(foo, 0);
1454 CallAndGC(env->Global(),
foo);
1458 CompileFunction(&env,
"function foo(){}",
"foo");
1459 foo = CompileFunction(&env,
"bar=1;function foo(){var x=bar;}",
"foo");
1460 SetBreakPoint(foo, 0);
1462 CallAndGC(env->Global(),
foo);
1466 CompileFunction(&env,
"function foo(){}",
"foo");
1467 foo = CompileFunction(&env,
1468 "function bar(){};function foo(){bar();}",
1470 SetBreakPoint(foo, 0);
1472 CallAndGC(env->Global(),
foo);
1476 CompileFunction(&env,
"function foo(){}",
"foo");
1477 foo = CompileFunction(&env,
"function foo(){}",
"foo");
1478 SetBreakPoint(foo, 0);
1480 CallAndGC(env->Global(),
foo);
1484 CompileFunction(&env,
"function foo(){}",
"foo");
1485 foo = CompileFunction(&env,
"function foo(){var bar=0;}",
"foo");
1486 SetBreakPoint(foo, 0);
1488 CallAndGC(env->Global(),
foo);
1492 CheckDebuggerUnloaded();
1497 TEST(BreakPointThroughJavaScript) {
1498 break_point_hit_count = 0;
1500 DebugLocalContext env;
1514 CHECK_EQ(0, break_point_hit_count);
1517 int bp1 = SetBreakPointFromJS(
"foo", 0, 3);
1519 CHECK_EQ(1, break_point_hit_count);
1521 CHECK_EQ(2, break_point_hit_count);
1524 int bp2 = SetBreakPointFromJS(
"foo", 0, 9);
1526 CHECK_EQ(4, break_point_hit_count);
1528 CHECK_EQ(6, break_point_hit_count);
1531 ClearBreakPointFromJS(bp2);
1533 CHECK_EQ(7, break_point_hit_count);
1535 CHECK_EQ(8, break_point_hit_count);
1538 ClearBreakPointFromJS(bp1);
1540 CHECK_EQ(8, break_point_hit_count);
1543 CheckDebuggerUnloaded();
1553 TEST(ScriptBreakPointByNameThroughJavaScript) {
1554 break_point_hit_count = 0;
1556 DebugLocalContext env;
1565 " a = 0; // line 2\n"
1567 " b = 1; // line 4\n"
1575 " b = 2; // line 12\n"
1577 " b = 3; // line 14\n"
1578 " f(); // line 15\n"
1591 break_point_hit_count = 0;
1593 CHECK_EQ(0, break_point_hit_count);
1595 CHECK_EQ(0, break_point_hit_count);
1598 int sbp1 = SetScriptBreakPointByNameFromJS(
"test", 12, 0);
1599 break_point_hit_count = 0;
1601 CHECK_EQ(0, break_point_hit_count);
1603 CHECK_EQ(1, break_point_hit_count);
1606 break_point_hit_count = 0;
1607 ClearBreakPointFromJS(sbp1);
1609 CHECK_EQ(0, break_point_hit_count);
1611 CHECK_EQ(0, break_point_hit_count);
1614 int sbp2 = SetScriptBreakPointByNameFromJS(
"test", 2, 0);
1615 break_point_hit_count = 0;
1617 CHECK_EQ(1, break_point_hit_count);
1619 CHECK_EQ(2, break_point_hit_count);
1622 int sbp3 = SetScriptBreakPointByNameFromJS(
"test", 4, 0);
1623 int sbp4 = SetScriptBreakPointByNameFromJS(
"test", 12, 0);
1624 int sbp5 = SetScriptBreakPointByNameFromJS(
"test", 14, 0);
1625 int sbp6 = SetScriptBreakPointByNameFromJS(
"test", 15, 0);
1626 break_point_hit_count = 0;
1628 CHECK_EQ(2, break_point_hit_count);
1630 CHECK_EQ(7, break_point_hit_count);
1633 break_point_hit_count = 0;
1634 ClearBreakPointFromJS(sbp2);
1635 ClearBreakPointFromJS(sbp3);
1636 ClearBreakPointFromJS(sbp4);
1637 ClearBreakPointFromJS(sbp5);
1638 ClearBreakPointFromJS(sbp6);
1640 CHECK_EQ(0, break_point_hit_count);
1642 CHECK_EQ(0, break_point_hit_count);
1645 CheckDebuggerUnloaded();
1657 TEST(ScriptBreakPointByIdThroughJavaScript) {
1658 break_point_hit_count = 0;
1660 DebugLocalContext env;
1669 " a = 0; // line 2\n"
1671 " b = 1; // line 4\n"
1679 " b = 2; // line 12\n"
1681 " b = 3; // line 14\n"
1682 " f(); // line 15\n"
1696 uint32_t script_id = script->
Id()->Uint32Value();
1699 break_point_hit_count = 0;
1701 CHECK_EQ(0, break_point_hit_count);
1703 CHECK_EQ(0, break_point_hit_count);
1706 int sbp1 = SetScriptBreakPointByIdFromJS(script_id, 12, 0);
1707 break_point_hit_count = 0;
1709 CHECK_EQ(0, break_point_hit_count);
1711 CHECK_EQ(1, break_point_hit_count);
1714 break_point_hit_count = 0;
1715 ClearBreakPointFromJS(sbp1);
1717 CHECK_EQ(0, break_point_hit_count);
1719 CHECK_EQ(0, break_point_hit_count);
1722 int sbp2 = SetScriptBreakPointByIdFromJS(script_id, 2, 0);
1723 break_point_hit_count = 0;
1725 CHECK_EQ(1, break_point_hit_count);
1727 CHECK_EQ(2, break_point_hit_count);
1730 int sbp3 = SetScriptBreakPointByIdFromJS(script_id, 4, 0);
1731 int sbp4 = SetScriptBreakPointByIdFromJS(script_id, 12, 0);
1732 int sbp5 = SetScriptBreakPointByIdFromJS(script_id, 14, 0);
1733 int sbp6 = SetScriptBreakPointByIdFromJS(script_id, 15, 0);
1734 break_point_hit_count = 0;
1736 CHECK_EQ(2, break_point_hit_count);
1738 CHECK_EQ(7, break_point_hit_count);
1741 break_point_hit_count = 0;
1742 ClearBreakPointFromJS(sbp2);
1743 ClearBreakPointFromJS(sbp3);
1744 ClearBreakPointFromJS(sbp4);
1745 ClearBreakPointFromJS(sbp5);
1746 ClearBreakPointFromJS(sbp6);
1748 CHECK_EQ(0, break_point_hit_count);
1750 CHECK_EQ(0, break_point_hit_count);
1753 CheckDebuggerUnloaded();
1766 TEST(EnableDisableScriptBreakPoint) {
1767 break_point_hit_count = 0;
1769 DebugLocalContext env;
1777 " a = 0; // line 1\n"
1788 int sbp = SetScriptBreakPointByNameFromJS(
"test", 1, 0);
1791 break_point_hit_count = 0;
1793 CHECK_EQ(1, break_point_hit_count);
1795 DisableScriptBreakPointFromJS(sbp);
1797 CHECK_EQ(1, break_point_hit_count);
1799 EnableScriptBreakPointFromJS(sbp);
1801 CHECK_EQ(2, break_point_hit_count);
1803 DisableScriptBreakPointFromJS(sbp);
1805 CHECK_EQ(2, break_point_hit_count);
1811 CHECK_EQ(2, break_point_hit_count);
1813 EnableScriptBreakPointFromJS(sbp);
1815 CHECK_EQ(3, break_point_hit_count);
1818 CheckDebuggerUnloaded();
1823 TEST(ConditionalScriptBreakPoint) {
1824 break_point_hit_count = 0;
1826 DebugLocalContext env;
1835 " g(count++); // line 2\n"
1838 " var a=x; // line 5\n"
1849 int sbp1 = SetScriptBreakPointByNameFromJS(
"test", 5, 0);
1852 break_point_hit_count = 0;
1853 ChangeScriptBreakPointConditionFromJS(sbp1,
"false");
1855 CHECK_EQ(0, break_point_hit_count);
1857 ChangeScriptBreakPointConditionFromJS(sbp1,
"true");
1858 break_point_hit_count = 0;
1860 CHECK_EQ(1, break_point_hit_count);
1862 ChangeScriptBreakPointConditionFromJS(sbp1,
"x % 2 == 0");
1863 break_point_hit_count = 0;
1864 for (
int i = 0; i < 10; i++) {
1867 CHECK_EQ(5, break_point_hit_count);
1873 break_point_hit_count = 0;
1874 for (
int i = 0; i < 10; i++) {
1877 CHECK_EQ(5, break_point_hit_count);
1880 CheckDebuggerUnloaded();
1885 TEST(ScriptBreakPointIgnoreCount) {
1886 break_point_hit_count = 0;
1888 DebugLocalContext env;
1896 " a = 0; // line 1\n"
1907 int sbp = SetScriptBreakPointByNameFromJS(
"test", 1, 0);
1910 break_point_hit_count = 0;
1911 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 1);
1913 CHECK_EQ(0, break_point_hit_count);
1915 CHECK_EQ(1, break_point_hit_count);
1917 ChangeScriptBreakPointIgnoreCountFromJS(sbp, 5);
1918 break_point_hit_count = 0;
1919 for (
int i = 0; i < 10; i++) {
1922 CHECK_EQ(5, break_point_hit_count);
1928 break_point_hit_count = 0;
1929 for (
int i = 0; i < 10; i++) {
1932 CHECK_EQ(5, break_point_hit_count);
1935 CheckDebuggerUnloaded();
1940 TEST(ScriptBreakPointReload) {
1941 break_point_hit_count = 0;
1943 DebugLocalContext env;
1953 " a = 0; // line 2\n"
1955 " b = 1; // line 4\n"
1963 SetScriptBreakPointByNameFromJS(
"1", 2, 0);
1970 break_point_hit_count = 0;
1972 CHECK_EQ(1, break_point_hit_count);
1980 break_point_hit_count = 0;
1982 CHECK_EQ(0, break_point_hit_count);
1989 break_point_hit_count = 0;
1991 CHECK_EQ(1, break_point_hit_count);
1994 CheckDebuggerUnloaded();
1999 TEST(ScriptBreakPointMultiple) {
2000 break_point_hit_count = 0;
2002 DebugLocalContext env;
2011 " a = 0; // line 1\n"
2017 " b = 0; // line 1\n"
2024 int sbp = SetScriptBreakPointByNameFromJS(
"test", 1, 0);
2033 break_point_hit_count = 0;
2035 CHECK_EQ(1, break_point_hit_count);
2037 CHECK_EQ(2, break_point_hit_count);
2040 ClearBreakPointFromJS(sbp);
2043 break_point_hit_count = 0;
2045 CHECK_EQ(0, break_point_hit_count);
2047 CHECK_EQ(0, break_point_hit_count);
2050 sbp = SetScriptBreakPointByNameFromJS(
"test", 1, 0);
2053 break_point_hit_count = 0;
2055 CHECK_EQ(1, break_point_hit_count);
2057 CHECK_EQ(2, break_point_hit_count);
2060 CheckDebuggerUnloaded();
2065 TEST(ScriptBreakPointLineOffset) {
2066 break_point_hit_count = 0;
2068 DebugLocalContext env;
2077 " a = 0; // line 8 as this script has line offset 7\n"
2078 " b = 0; // line 9 as this script has line offset 7\n"
2086 int sbp1 = SetScriptBreakPointByNameFromJS(
"test.html", 8, 0);
2087 int sbp2 = SetScriptBreakPointByNameFromJS(
"test.html", 9, 0);
2094 break_point_hit_count = 0;
2096 CHECK_EQ(2, break_point_hit_count);
2099 ClearBreakPointFromJS(sbp1);
2100 ClearBreakPointFromJS(sbp2);
2103 break_point_hit_count = 0;
2105 CHECK_EQ(0, break_point_hit_count);
2108 sbp1 = SetScriptBreakPointByNameFromJS(
"test.html", 9, 0);
2111 break_point_hit_count = 0;
2113 CHECK_EQ(1, break_point_hit_count);
2116 CheckDebuggerUnloaded();
2121 TEST(ScriptBreakPointLine) {
2123 DebugLocalContext env;
2127 frame_function_name = CompileFunction(&env,
2128 frame_function_name_source,
2129 "frame_function_name");
2139 " a = 1; // line 2\n"
2141 " a = 2; // line 4\n"
2142 " /* xx */ function g() { // line 5\n"
2143 " function h() { // line 6\n"
2144 " a = 3; // line 7\n"
2147 " a = 4; // line 10\n"
2149 " a=5; // line 12");
2152 int sbp1 = SetScriptBreakPointByNameFromJS(
"test.html", 0, -1);
2153 int sbp2 = SetScriptBreakPointByNameFromJS(
"test.html", 1, -1);
2154 int sbp3 = SetScriptBreakPointByNameFromJS(
"test.html", 5, -1);
2157 break_point_hit_count = 0;
2164 CHECK_EQ(1, break_point_hit_count);
2169 CHECK_EQ(2, break_point_hit_count);
2174 CHECK_EQ(3, break_point_hit_count);
2178 ClearBreakPointFromJS(sbp3);
2179 int sbp4 = SetScriptBreakPointByNameFromJS(
"test.html", 6, -1);
2183 CHECK_EQ(4, break_point_hit_count);
2189 ClearBreakPointFromJS(sbp2);
2190 ClearBreakPointFromJS(sbp4);
2191 int sbp5 = SetScriptBreakPointByNameFromJS(
"test.html", 4, -1);
2192 break_point_hit_count = 0;
2195 CHECK_EQ(0, break_point_hit_count);
2198 break_point_hit_count = 0;
2200 CHECK_EQ(2, break_point_hit_count);
2204 int sbp6 = SetScriptBreakPointByNameFromJS(
"test.html", 12, -1);
2207 break_point_hit_count = 0;
2209 CHECK_EQ(3, break_point_hit_count);
2214 ClearBreakPointFromJS(sbp1);
2215 ClearBreakPointFromJS(sbp5);
2216 ClearBreakPointFromJS(sbp6);
2217 break_point_hit_count = 0;
2219 CHECK_EQ(0, break_point_hit_count);
2222 CheckDebuggerUnloaded();
2227 TEST(ScriptBreakPointLineTopLevel) {
2229 DebugLocalContext env;
2237 " a = 1; // line 1\n"
2239 "a = 2; // line 3\n");
2247 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
2249 SetScriptBreakPointByNameFromJS(
"test.html", 3, -1);
2252 break_point_hit_count = 0;
2254 CHECK_EQ(0, break_point_hit_count);
2257 break_point_hit_count = 0;
2259 CHECK_EQ(1, break_point_hit_count);
2262 break_point_hit_count = 0;
2264 CHECK_EQ(0, break_point_hit_count);
2267 CheckDebuggerUnloaded();
2273 TEST(ScriptBreakPointTopLevelCrash) {
2275 DebugLocalContext env;
2287 int sbp1 = SetScriptBreakPointByNameFromJS(
"test.html", 3, -1);
2290 break_point_hit_count = 0;
2292 CHECK_EQ(1, break_point_hit_count);
2295 int sbp2 = SetScriptBreakPointByNameFromJS(
"test.html", 3, -1);
2296 ClearBreakPointFromJS(sbp1);
2297 ClearBreakPointFromJS(sbp2);
2300 CheckDebuggerUnloaded();
2306 TEST(RemoveBreakPointInBreak) {
2308 DebugLocalContext env;
2311 CompileFunction(&env,
"function foo(){a=1;}",
"foo");
2312 debug_event_remove_break_point = SetBreakPoint(foo, 0);
2317 break_point_hit_count = 0;
2319 CHECK_EQ(1, break_point_hit_count);
2321 break_point_hit_count = 0;
2323 CHECK_EQ(0, break_point_hit_count);
2326 CheckDebuggerUnloaded();
2331 TEST(DebuggerStatement) {
2332 break_point_hit_count = 0;
2334 DebugLocalContext env;
2339 "function foo(){debugger;debugger;}"))->Run();
2347 CHECK_EQ(1, break_point_hit_count);
2351 CHECK_EQ(3, break_point_hit_count);
2354 CheckDebuggerUnloaded();
2359 TEST(DebuggerStatementBreakpoint) {
2360 break_point_hit_count = 0;
2362 DebugLocalContext env;
2371 CHECK_EQ(1, break_point_hit_count);
2373 int bp = SetBreakPoint(foo, 0);
2377 CHECK_EQ(2, break_point_hit_count);
2379 ClearBreakPoint(bp);
2381 CheckDebuggerUnloaded();
2387 TEST(DebugEvaluate) {
2389 DebugLocalContext env;
2393 evaluate_check_function = CompileFunction(&env,
2394 evaluate_check_source,
2401 struct EvaluateCheck checks_uu[] = {
2406 struct EvaluateCheck checks_hu[] = {
2411 struct EvaluateCheck checks_hh[] = {
2429 const int foo_break_position_1 = 15;
2430 const int foo_break_position_2 = 29;
2436 int bp = SetBreakPoint(foo, foo_break_position_1);
2438 foo->Call(env->Global(), 0,
NULL);
2442 foo->Call(env->Global(), 1, argv_foo);
2445 ClearBreakPoint(bp);
2446 SetBreakPoint(foo, foo_break_position_2);
2448 foo->Call(env->Global(), 1, argv_foo);
2456 "x = 'Goodbye, world!';"
2457 "function bar(x, b) {"
2459 " function barbar() {"
2460 " y=0; /* To ensure break location.*/"
2463 " debug.Debug.clearAllBreakPoints();"
2468 const int barbar_break_position = 8;
2477 bar->
Call(env->Global(), 2, argv_bar_1);
2486 bar->
Call(env->Global(), 2, argv_bar_2);
2495 bar->
Call(env->Global(), 2, argv_bar_3);
2498 CheckDebuggerUnloaded();
2504 int AsciiToUtf16(
const char* input_buffer,
uint16_t* output_buffer) {
2506 for (i = 0; input_buffer[i] !=
'\0'; ++i) {
2508 output_buffer[i] =
static_cast<unsigned char>(input_buffer[i]);
2510 output_buffer[i] = 0;
2517 int Utf16ToAscii(
const uint16_t* input_buffer,
int length,
2518 char* output_buffer,
int output_len = -1) {
2519 if (output_len >= 0) {
2520 if (length > output_len - 1) {
2521 length = output_len - 1;
2525 for (
int i = 0; i < length; ++i) {
2526 output_buffer[i] =
static_cast<char>(input_buffer[i]);
2528 output_buffer[length] =
'\0';
2534 bool GetEvaluateStringResult(
char *message,
char* buffer,
int buffer_size) {
2535 if (strstr(message,
"\"command\":\"evaluate\"") ==
NULL) {
2538 const char* prefix =
"\"text\":\"";
2539 char* pos1 = strstr(message, prefix);
2543 pos1 += strlen(prefix);
2544 char* pos2 = strchr(pos1,
'"');
2548 Vector<char> buf(buffer, buffer_size);
2549 int len =
static_cast<int>(pos2 - pos1);
2550 if (len > buffer_size - 1) {
2551 len = buffer_size - 1;
2553 OS::StrNCpy(buf, pos1, len);
2554 buffer[buffer_size - 1] =
'\0';
2559 struct EvaluateResult {
2560 static const int kBufferSize = 20;
2561 char buffer[kBufferSize];
2564 struct DebugProcessDebugMessagesData {
2565 static const int kArraySize = 5;
2567 EvaluateResult results[kArraySize];
2572 EvaluateResult* current() {
2573 return &results[counter % kArraySize];
2580 DebugProcessDebugMessagesData process_debug_messages_data;
2582 static void DebugProcessDebugMessagesHandler(
2587 const int kBufferSize = 100000;
2588 char print_buffer[kBufferSize];
2589 Utf16ToAscii(message, length, print_buffer, kBufferSize);
2591 EvaluateResult* array_item = process_debug_messages_data.current();
2593 bool res = GetEvaluateStringResult(print_buffer,
2595 EvaluateResult::kBufferSize);
2597 process_debug_messages_data.next();
2603 TEST(DebugEvaluateWithoutStack) {
2607 DebugLocalContext env;
2609 const char* source =
2610 "var v1 = 'Pinguin';\n function getAnimal() { return 'Capy' + 'bara'; }";
2616 const int kBufferSize = 1000;
2619 const char* command_111 =
"{\"seq\":111,"
2620 "\"type\":\"request\","
2621 "\"command\":\"evaluate\","
2624 " \"expression\":\"v1\",\"disable_break\":true"
2629 const char* command_112 =
"{\"seq\":112,"
2630 "\"type\":\"request\","
2631 "\"command\":\"evaluate\","
2634 " \"expression\":\"getAnimal()\",\"disable_break\":true"
2639 const char* command_113 =
"{\"seq\":113,"
2640 "\"type\":\"request\","
2641 "\"command\":\"evaluate\","
2644 " \"expression\":\"239 + 566\",\"disable_break\":true"
2651 CHECK_EQ(3, process_debug_messages_data.counter);
2653 CHECK_EQ(strcmp(
"Pinguin", process_debug_messages_data.results[0].buffer), 0);
2654 CHECK_EQ(strcmp(
"Capybara", process_debug_messages_data.results[1].buffer),
2656 CHECK_EQ(strcmp(
"805", process_debug_messages_data.results[2].buffer), 0);
2660 CheckDebuggerUnloaded();
2665 TEST(DebugStepLinear) {
2667 DebugLocalContext env;
2671 "function foo(){a=1;b=1;c=1;}",
2675 CompileRun(
"a=0; b=0; c=0; foo();");
2677 SetBreakPoint(foo, 3);
2682 step_action = StepIn;
2683 break_point_hit_count = 0;
2687 CHECK_EQ(4, break_point_hit_count);
2690 CheckDebuggerUnloaded();
2695 SetBreakPoint(foo, 3);
2696 break_point_hit_count = 0;
2700 CHECK_EQ(1, break_point_hit_count);
2703 CheckDebuggerUnloaded();
2708 TEST(DebugStepKeyedLoadLoop) {
2710 DebugLocalContext env;
2719 "function foo(a) {\n"
2721 " var len = a.length;\n"
2722 " for (var i = 0; i < len; i++) {\n"
2732 for (
int i = 0; i < 10; i++) {
2737 const int kArgc = 1;
2739 foo->
Call(env->Global(), kArgc, args);
2742 SetBreakPoint(foo, 3);
2743 step_action = StepNext;
2744 break_point_hit_count = 0;
2745 foo->
Call(env->Global(), kArgc, args);
2748 CHECK_EQ(34, break_point_hit_count);
2751 CheckDebuggerUnloaded();
2756 TEST(DebugStepKeyedStoreLoop) {
2758 DebugLocalContext env;
2767 "function foo(a) {\n"
2768 " var len = a.length;\n"
2769 " for (var i = 0; i < len; i++) {\n"
2779 for (
int i = 0; i < 10; i++) {
2784 const int kArgc = 1;
2786 foo->
Call(env->Global(), kArgc, args);
2789 SetBreakPoint(foo, 3);
2790 step_action = StepNext;
2791 break_point_hit_count = 0;
2792 foo->
Call(env->Global(), kArgc, args);
2795 CHECK_EQ(33, break_point_hit_count);
2798 CheckDebuggerUnloaded();
2803 TEST(DebugStepNamedLoadLoop) {
2805 DebugLocalContext env;
2813 "function foo() {\n"
2816 " for (var i = 0; i < 10; i++) {\n"
2817 " var v = new V(i, i + 1);\n"
2823 "function V(x, y) {\n"
2833 SetBreakPoint(foo, 4);
2834 step_action = StepNext;
2835 break_point_hit_count = 0;
2839 CHECK_EQ(54, break_point_hit_count);
2842 CheckDebuggerUnloaded();
2846 static void DoDebugStepNamedStoreLoop(
int expected) {
2848 DebugLocalContext env;
2856 "function foo() {\n"
2858 " for (var i = 0; i < 10; i++) {\n"
2868 SetBreakPoint(foo, 3);
2869 step_action = StepNext;
2870 break_point_hit_count = 0;
2874 CHECK_EQ(expected, break_point_hit_count);
2877 CheckDebuggerUnloaded();
2882 TEST(DebugStepNamedStoreLoop) {
2883 DoDebugStepNamedStoreLoop(23);
2888 TEST(DebugStepLinearMixedICs) {
2890 DebugLocalContext env;
2897 "function bar() {};"
2900 " var index='name';"
2902 " a=1;b=2;x=a;y[index]=3;x=y[index];bar();}",
"foo");
2905 CompileRun(
"a=0; b=0; bar(); foo();");
2907 SetBreakPoint(foo, 0);
2909 step_action = StepIn;
2910 break_point_hit_count = 0;
2914 CHECK_EQ(11, break_point_hit_count);
2917 CheckDebuggerUnloaded();
2922 SetBreakPoint(foo, 0);
2923 break_point_hit_count = 0;
2927 CHECK_EQ(1, break_point_hit_count);
2930 CheckDebuggerUnloaded();
2934 TEST(DebugStepDeclarations) {
2936 DebugLocalContext env;
2943 const char* src =
"function foo() { "
2947 " var d = Math.floor;"
2948 " var e = b + d(1.2);"
2953 SetBreakPoint(foo, 0);
2956 step_action = StepIn;
2957 break_point_hit_count = 0;
2959 CHECK_EQ(6, break_point_hit_count);
2963 CheckDebuggerUnloaded();
2967 TEST(DebugStepLocals) {
2969 DebugLocalContext env;
2976 const char* src =
"function foo() { "
2981 " a = Math.floor(b);"
2986 SetBreakPoint(foo, 0);
2989 step_action = StepIn;
2990 break_point_hit_count = 0;
2992 CHECK_EQ(6, break_point_hit_count);
2996 CheckDebuggerUnloaded();
3002 DebugLocalContext env;
3010 const char* src =
"function foo(x) { "
3019 "a=0; b=0; c=0; d=0; foo()";
3021 SetBreakPoint(foo, 0);
3024 step_action = StepIn;
3025 break_point_hit_count = 0;
3027 foo->
Call(env->Global(), argc, argv_true);
3028 CHECK_EQ(4, break_point_hit_count);
3031 step_action = StepIn;
3032 break_point_hit_count = 0;
3034 foo->
Call(env->Global(), argc, argv_false);
3035 CHECK_EQ(5, break_point_hit_count);
3039 CheckDebuggerUnloaded();
3043 TEST(DebugStepSwitch) {
3045 DebugLocalContext env;
3053 const char* src =
"function foo(x) { "
3068 "a=0; b=0; c=0; d=0; e=0; f=0; foo()";
3070 SetBreakPoint(foo, 0);
3073 step_action = StepIn;
3074 break_point_hit_count = 0;
3076 foo->
Call(env->Global(), argc, argv_1);
3077 CHECK_EQ(6, break_point_hit_count);
3080 step_action = StepIn;
3081 break_point_hit_count = 0;
3083 foo->
Call(env->Global(), argc, argv_2);
3084 CHECK_EQ(5, break_point_hit_count);
3087 step_action = StepIn;
3088 break_point_hit_count = 0;
3090 foo->
Call(env->Global(), argc, argv_3);
3091 CHECK_EQ(7, break_point_hit_count);
3095 CheckDebuggerUnloaded();
3099 TEST(DebugStepWhile) {
3101 DebugLocalContext env;
3109 const char* src =
"function foo(x) { "
3117 SetBreakPoint(foo, 8);
3120 step_action = StepIn;
3121 break_point_hit_count = 0;
3123 foo->
Call(env->Global(), argc, argv_10);
3124 CHECK_EQ(22, break_point_hit_count);
3127 step_action = StepIn;
3128 break_point_hit_count = 0;
3130 foo->
Call(env->Global(), argc, argv_100);
3131 CHECK_EQ(202, break_point_hit_count);
3135 CheckDebuggerUnloaded();
3139 TEST(DebugStepDoWhile) {
3141 DebugLocalContext env;
3149 const char* src =
"function foo(x) { "
3157 SetBreakPoint(foo, 8);
3160 step_action = StepIn;
3161 break_point_hit_count = 0;
3163 foo->
Call(env->Global(), argc, argv_10);
3164 CHECK_EQ(22, break_point_hit_count);
3167 step_action = StepIn;
3168 break_point_hit_count = 0;
3170 foo->
Call(env->Global(), argc, argv_100);
3171 CHECK_EQ(202, break_point_hit_count);
3175 CheckDebuggerUnloaded();
3179 TEST(DebugStepFor) {
3181 DebugLocalContext env;
3189 const char* src =
"function foo(x) { "
3191 " for (i = 0; i < x; i++) {"
3195 "a=0; b=0; i=0; foo()";
3198 SetBreakPoint(foo, 8);
3201 step_action = StepIn;
3202 break_point_hit_count = 0;
3204 foo->
Call(env->Global(), argc, argv_10);
3205 CHECK_EQ(23, break_point_hit_count);
3208 step_action = StepIn;
3209 break_point_hit_count = 0;
3211 foo->
Call(env->Global(), argc, argv_100);
3212 CHECK_EQ(203, break_point_hit_count);
3216 CheckDebuggerUnloaded();
3220 TEST(DebugStepForContinue) {
3222 DebugLocalContext env;
3230 const char* src =
"function foo(x) { "
3234 " for (var i = 0; i < x; i++) {"
3236 " if (a % 2 == 0) continue;"
3245 SetBreakPoint(foo, 8);
3250 step_action = StepIn;
3251 break_point_hit_count = 0;
3253 result = foo->
Call(env->Global(), argc, argv_10);
3255 CHECK_EQ(51, break_point_hit_count);
3258 step_action = StepIn;
3259 break_point_hit_count = 0;
3261 result = foo->
Call(env->Global(), argc, argv_100);
3263 CHECK_EQ(456, break_point_hit_count);
3267 CheckDebuggerUnloaded();
3271 TEST(DebugStepForBreak) {
3273 DebugLocalContext env;
3281 const char* src =
"function foo(x) { "
3285 " for (var i = 0; i < 1000; i++) {"
3287 " if (a == x) break;"
3296 SetBreakPoint(foo, 8);
3302 step_action = StepIn;
3303 break_point_hit_count = 0;
3305 result = foo->
Call(env->Global(), argc, argv_10);
3307 CHECK_EQ(54, break_point_hit_count);
3310 step_action = StepIn;
3311 break_point_hit_count = 0;
3313 result = foo->
Call(env->Global(), argc, argv_100);
3315 CHECK_EQ(504, break_point_hit_count);
3319 CheckDebuggerUnloaded();
3323 TEST(DebugStepForIn) {
3325 DebugLocalContext env;
3333 const char* src_1 =
"function foo() { "
3340 foo = CompileFunction(&env, src_1,
"foo");
3341 SetBreakPoint(foo, 0);
3343 step_action = StepIn;
3344 break_point_hit_count = 0;
3346 CHECK_EQ(6, break_point_hit_count);
3350 const char* src_2 =
"function foo() { "
3351 " var a = {a:[1, 2, 3]};"
3357 foo = CompileFunction(&env, src_2,
"foo");
3358 SetBreakPoint(foo, 0);
3360 step_action = StepIn;
3361 break_point_hit_count = 0;
3363 CHECK_EQ(8, break_point_hit_count);
3367 CheckDebuggerUnloaded();
3371 TEST(DebugStepWith) {
3373 DebugLocalContext env;
3380 const char* src =
"function foo(x) { "
3389 SetBreakPoint(foo, 8);
3391 step_action = StepIn;
3392 break_point_hit_count = 0;
3394 CHECK_EQ(4, break_point_hit_count);
3398 CheckDebuggerUnloaded();
3402 TEST(DebugConditional) {
3404 DebugLocalContext env;
3411 const char* src =
"function foo(x) { "
3418 SetBreakPoint(foo, 0);
3420 step_action = StepIn;
3421 break_point_hit_count = 0;
3423 CHECK_EQ(5, break_point_hit_count);
3425 step_action = StepIn;
3426 break_point_hit_count = 0;
3429 foo->
Call(env->Global(), argc, argv_true);
3430 CHECK_EQ(5, break_point_hit_count);
3434 CheckDebuggerUnloaded();
3438 TEST(StepInOutSimple) {
3440 DebugLocalContext env;
3443 frame_function_name = CompileFunction(&env,
3444 frame_function_name_source,
3445 "frame_function_name");
3452 const char* src =
"function a() {b();c();}; "
3453 "function b() {c();}; "
3457 SetBreakPoint(a, 0);
3460 step_action = StepIn;
3461 break_point_hit_count = 0;
3462 expected_step_sequence =
"abcbaca";
3465 break_point_hit_count);
3468 step_action = StepNext;
3469 break_point_hit_count = 0;
3470 expected_step_sequence =
"aaa";
3473 break_point_hit_count);
3476 step_action = StepOut;
3477 break_point_hit_count = 0;
3478 expected_step_sequence =
"a";
3481 break_point_hit_count);
3485 CheckDebuggerUnloaded();
3489 TEST(StepInOutTree) {
3491 DebugLocalContext env;
3494 frame_function_name = CompileFunction(&env,
3495 frame_function_name_source,
3496 "frame_function_name");
3503 const char* src =
"function a() {b(c(d()),d());c(d());d()}; "
3504 "function b(x,y) {c();}; "
3505 "function c(x) {}; "
3507 "a(); b(); c(); d()";
3509 SetBreakPoint(a, 0);
3512 step_action = StepIn;
3513 break_point_hit_count = 0;
3514 expected_step_sequence =
"adacadabcbadacada";
3517 break_point_hit_count);
3520 step_action = StepNext;
3521 break_point_hit_count = 0;
3522 expected_step_sequence =
"aaaa";
3525 break_point_hit_count);
3528 step_action = StepOut;
3529 break_point_hit_count = 0;
3530 expected_step_sequence =
"a";
3533 break_point_hit_count);
3537 CheckDebuggerUnloaded(
true);
3541 TEST(StepInOutBranch) {
3543 DebugLocalContext env;
3546 frame_function_name = CompileFunction(&env,
3547 frame_function_name_source,
3548 "frame_function_name");
3555 const char* src =
"function a() {b(false);c();}; "
3556 "function b(x) {if(x){c();};}; "
3560 SetBreakPoint(a, 0);
3563 step_action = StepIn;
3564 break_point_hit_count = 0;
3565 expected_step_sequence =
"abbaca";
3568 break_point_hit_count);
3572 CheckDebuggerUnloaded();
3577 TEST(DebugStepNatives) {
3579 DebugLocalContext env;
3584 "function foo(){debugger;Math.sin(1);}",
3590 step_action = StepIn;
3591 break_point_hit_count = 0;
3595 CHECK_EQ(3, break_point_hit_count);
3598 CheckDebuggerUnloaded();
3603 break_point_hit_count = 0;
3607 CHECK_EQ(1, break_point_hit_count);
3610 CheckDebuggerUnloaded();
3615 TEST(DebugStepFunctionApply) {
3617 DebugLocalContext env;
3622 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3623 "function foo(){ debugger; bar.apply(this, [1,2,3]); }",
3629 step_action = StepIn;
3630 break_point_hit_count = 0;
3634 CHECK_EQ(7, break_point_hit_count);
3637 CheckDebuggerUnloaded();
3642 break_point_hit_count = 0;
3646 CHECK_EQ(1, break_point_hit_count);
3649 CheckDebuggerUnloaded();
3654 TEST(DebugStepFunctionCall) {
3656 DebugLocalContext env;
3661 "function bar(x, y, z) { if (x == 1) { a = y; b = z; } }"
3662 "function foo(a){ debugger;"
3664 " bar.call(this, 1, 2, 3);"
3666 " bar.call(this, 0);"
3673 step_action = StepIn;
3676 break_point_hit_count = 0;
3678 CHECK_EQ(6, break_point_hit_count);
3681 break_point_hit_count = 0;
3684 foo->
Call(env->Global(), argc, argv);
3685 CHECK_EQ(8, break_point_hit_count);
3688 CheckDebuggerUnloaded();
3693 break_point_hit_count = 0;
3697 CHECK_EQ(1, break_point_hit_count);
3700 CheckDebuggerUnloaded();
3705 TEST(PauseInScript) {
3707 DebugLocalContext env;
3714 const char* src =
"(function (evt) {})";
3715 const char* script_name =
"StepInHandlerTest";
3718 SetScriptBreakPointByNameFromJS(script_name, 0, -1);
3719 break_point_hit_count = 0;
3727 CHECK_EQ(1, break_point_hit_count);
3731 CheckDebuggerUnloaded();
3741 TEST(BreakOnException) {
3743 DebugLocalContext env;
3746 v8::internal::Isolate::Current()->TraceException(
false);
3749 CompileFunction(&env,
"function throws(){throw 1;}",
"throws");
3751 CompileFunction(&env,
3752 "function caught(){try {throws();} catch(e) {};}",
3755 CompileFunction(&env,
"function notCaught(){throws();}",
"notCaught");
3761 DebugEventCounterClear();
3762 MessageCallbackCountClear();
3763 caught->
Call(env->Global(), 0,
NULL);
3765 CHECK_EQ(0, uncaught_exception_hit_count);
3766 CHECK_EQ(0, message_callback_count);
3767 notCaught->
Call(env->Global(), 0,
NULL);
3769 CHECK_EQ(0, uncaught_exception_hit_count);
3770 CHECK_EQ(1, message_callback_count);
3773 DebugEventCounterClear();
3774 MessageCallbackCountClear();
3775 ChangeBreakOnException(
false,
false);
3776 caught->
Call(env->Global(), 0,
NULL);
3778 CHECK_EQ(0, uncaught_exception_hit_count);
3779 CHECK_EQ(0, message_callback_count);
3780 notCaught->
Call(env->Global(), 0,
NULL);
3782 CHECK_EQ(0, uncaught_exception_hit_count);
3783 CHECK_EQ(1, message_callback_count);
3786 DebugEventCounterClear();
3787 MessageCallbackCountClear();
3788 ChangeBreakOnException(
false,
true);
3789 caught->
Call(env->Global(), 0,
NULL);
3791 CHECK_EQ(0, uncaught_exception_hit_count);
3792 CHECK_EQ(0, message_callback_count);
3793 notCaught->
Call(env->Global(), 0,
NULL);
3795 CHECK_EQ(1, uncaught_exception_hit_count);
3796 CHECK_EQ(1, message_callback_count);
3799 DebugEventCounterClear();
3800 MessageCallbackCountClear();
3801 ChangeBreakOnException(
true,
true);
3802 caught->
Call(env->Global(), 0,
NULL);
3804 CHECK_EQ(0, uncaught_exception_hit_count);
3805 CHECK_EQ(0, message_callback_count);
3806 notCaught->
Call(env->Global(), 0,
NULL);
3808 CHECK_EQ(1, uncaught_exception_hit_count);
3809 CHECK_EQ(1, message_callback_count);
3812 DebugEventCounterClear();
3813 MessageCallbackCountClear();
3814 ChangeBreakOnException(
true,
false);
3815 caught->
Call(env->Global(), 0,
NULL);
3817 CHECK_EQ(0, uncaught_exception_hit_count);
3818 CHECK_EQ(0, message_callback_count);
3819 notCaught->
Call(env->Global(), 0,
NULL);
3821 CHECK_EQ(1, uncaught_exception_hit_count);
3822 CHECK_EQ(1, message_callback_count);
3825 DebugEventCounterClear();
3826 MessageCallbackCountClear();
3827 ChangeBreakOnExceptionFromJS(
false,
false);
3828 caught->
Call(env->Global(), 0,
NULL);
3830 CHECK_EQ(0, uncaught_exception_hit_count);
3831 CHECK_EQ(0, message_callback_count);
3832 notCaught->
Call(env->Global(), 0,
NULL);
3834 CHECK_EQ(0, uncaught_exception_hit_count);
3835 CHECK_EQ(1, message_callback_count);
3838 DebugEventCounterClear();
3839 MessageCallbackCountClear();
3840 ChangeBreakOnExceptionFromJS(
false,
true);
3841 caught->
Call(env->Global(), 0,
NULL);
3843 CHECK_EQ(0, uncaught_exception_hit_count);
3844 CHECK_EQ(0, message_callback_count);
3845 notCaught->
Call(env->Global(), 0,
NULL);
3847 CHECK_EQ(1, uncaught_exception_hit_count);
3848 CHECK_EQ(1, message_callback_count);
3851 DebugEventCounterClear();
3852 MessageCallbackCountClear();
3853 ChangeBreakOnExceptionFromJS(
true,
true);
3854 caught->
Call(env->Global(), 0,
NULL);
3856 CHECK_EQ(0, message_callback_count);
3857 CHECK_EQ(0, uncaught_exception_hit_count);
3858 notCaught->
Call(env->Global(), 0,
NULL);
3860 CHECK_EQ(1, uncaught_exception_hit_count);
3861 CHECK_EQ(1, message_callback_count);
3864 DebugEventCounterClear();
3865 MessageCallbackCountClear();
3866 ChangeBreakOnExceptionFromJS(
true,
false);
3867 caught->
Call(env->Global(), 0,
NULL);
3869 CHECK_EQ(0, uncaught_exception_hit_count);
3870 CHECK_EQ(0, message_callback_count);
3871 notCaught->
Call(env->Global(), 0,
NULL);
3873 CHECK_EQ(1, uncaught_exception_hit_count);
3874 CHECK_EQ(1, message_callback_count);
3877 CheckDebuggerUnloaded();
3885 TEST(BreakOnCompileException) {
3887 DebugLocalContext env;
3890 ChangeBreakOnException(
false,
true);
3892 v8::internal::Isolate::Current()->TraceException(
false);
3895 frame_count = CompileFunction(&env, frame_count_source,
"frame_count");
3900 DebugEventCounterClear();
3901 MessageCallbackCountClear();
3905 CHECK_EQ(0, uncaught_exception_hit_count);
3906 CHECK_EQ(0, message_callback_count);
3907 CHECK_EQ(-1, last_js_stack_height);
3912 CHECK_EQ(1, uncaught_exception_hit_count);
3913 CHECK_EQ(1, message_callback_count);
3919 CHECK_EQ(2, uncaught_exception_hit_count);
3920 CHECK_EQ(2, message_callback_count);
3926 CHECK_EQ(3, uncaught_exception_hit_count);
3927 CHECK_EQ(3, message_callback_count);
3933 CHECK_EQ(4, uncaught_exception_hit_count);
3934 CHECK_EQ(4, message_callback_count);
3939 TEST(StepWithException) {
3941 DebugLocalContext env;
3944 ChangeBreakOnException(
false,
true);
3947 frame_function_name = CompileFunction(&env,
3948 frame_function_name_source,
3949 "frame_function_name");
3955 const char* src =
"function a() { n(); }; "
3956 "function b() { c(); }; "
3957 "function c() { n(); }; "
3958 "function d() { x = 1; try { e(); } catch(x) { x = 2; } }; "
3959 "function e() { n(); }; "
3960 "function f() { x = 1; try { g(); } catch(x) { x = 2; } }; "
3961 "function g() { h(); }; "
3962 "function h() { x = 1; throw 1; }; ";
3966 SetBreakPoint(a, 0);
3967 step_action = StepIn;
3968 break_point_hit_count = 0;
3969 expected_step_sequence =
"aa";
3972 break_point_hit_count);
3976 SetBreakPoint(b, 0);
3977 step_action = StepIn;
3978 break_point_hit_count = 0;
3979 expected_step_sequence =
"bcc";
3982 break_point_hit_count);
3985 SetBreakPoint(d, 0);
3986 ChangeBreakOnException(
false,
true);
3987 step_action = StepIn;
3988 break_point_hit_count = 0;
3989 expected_step_sequence =
"ddedd";
3992 break_point_hit_count);
3995 ChangeBreakOnException(
true,
true);
3996 step_action = StepIn;
3997 break_point_hit_count = 0;
3998 expected_step_sequence =
"ddeedd";
4001 break_point_hit_count);
4005 SetBreakPoint(f, 0);
4006 ChangeBreakOnException(
false,
true);
4007 step_action = StepIn;
4008 break_point_hit_count = 0;
4009 expected_step_sequence =
"ffghhff";
4012 break_point_hit_count);
4015 ChangeBreakOnException(
true,
true);
4016 step_action = StepIn;
4017 break_point_hit_count = 0;
4018 expected_step_sequence =
"ffghhhff";
4021 break_point_hit_count);
4025 CheckDebuggerUnloaded();
4031 DebugLocalContext env;
4036 CHECK(v8::internal::FLAG_verify_heap);
4043 const char* src =
"function f0() {}"
4044 "function f1(x1) {}"
4045 "function f2(x1,x2) {}"
4046 "function f3(x1,x2,x3) {}";
4068 break_point_hit_count = 0;
4069 for (
unsigned int i = 0; i <
ARRAY_SIZE(argv); i++) {
4070 f0->
Call(env->Global(), i, argv);
4071 f1->
Call(env->Global(), i, argv);
4072 f2->
Call(env->Global(), i, argv);
4073 f3->
Call(env->Global(), i, argv);
4081 CheckDebuggerUnloaded();
4087 TEST(DisableBreak) {
4089 DebugLocalContext env;
4095 const char* src =
"function f() {g()};function g(){i=0; while(i<10){i++}}";
4102 break_point_hit_count = 0;
4104 CHECK_EQ(1, break_point_hit_count);
4108 v8::internal::DisableBreak disable_break(
true);
4110 CHECK_EQ(1, break_point_hit_count);
4114 CHECK_EQ(2, break_point_hit_count);
4118 CheckDebuggerUnloaded();
4121 static const char* kSimpleExtensionSource =
4128 TEST(NoBreakWhenBootstrapping) {
4136 break_point_hit_count = 0;
4141 kSimpleExtensionSource));
4142 const char* extension_names[] = {
"simpletest" };
4148 CHECK_EQ(0, break_point_hit_count);
4152 CheckDebuggerUnloaded();
4175 if (strcmp(*n,
"a") == 0) {
4177 }
else if (strcmp(*n,
"b") == 0) {
4179 }
else if (strcmp(*n,
"c") == 0) {
4195 TEST(InterceptorPropertyMirror) {
4198 DebugLocalContext env;
4225 "var named_mirror = debug.MakeMirror(intercepted_named);"
4226 "var indexed_mirror = debug.MakeMirror(intercepted_indexed);"
4227 "var both_mirror = debug.MakeMirror(intercepted_both)");
4229 "named_mirror instanceof debug.ObjectMirror")->BooleanValue());
4231 "indexed_mirror instanceof debug.ObjectMirror")->BooleanValue());
4233 "both_mirror instanceof debug.ObjectMirror")->BooleanValue());
4237 "named_names = named_mirror.propertyNames();"
4238 "indexed_names = indexed_mirror.propertyNames();"
4239 "both_names = both_mirror.propertyNames()");
4240 CHECK_EQ(3, CompileRun(
"named_names.length")->Int32Value());
4241 CHECK_EQ(2, CompileRun(
"indexed_names.length")->Int32Value());
4242 CHECK_EQ(5, CompileRun(
"both_names.length")->Int32Value());
4246 source =
"named_mirror.properties().length";
4247 CHECK_EQ(3, CompileRun(source)->Int32Value());
4249 source =
"indexed_mirror.properties().length";
4250 CHECK_EQ(2, CompileRun(source)->Int32Value());
4252 source =
"both_mirror.properties().length";
4253 CHECK_EQ(5, CompileRun(source)->Int32Value());
4256 source =
"both_mirror.properties(1).length";
4257 CHECK_EQ(3, CompileRun(source)->Int32Value());
4260 source =
"both_mirror.properties(2).length";
4261 CHECK_EQ(2, CompileRun(source)->Int32Value());
4264 source =
"both_mirror.properties(3).length";
4265 CHECK_EQ(5, CompileRun(source)->Int32Value());
4268 CompileRun(
"var named_values = named_mirror.properties()");
4271 for (
int i = 0; i < 3; i++) {
4272 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
4273 OS::SNPrintF(buffer,
4274 "named_values[%d] instanceof debug.PropertyMirror", i);
4275 CHECK(CompileRun(buffer.start())->BooleanValue());
4278 OS::SNPrintF(buffer,
"named_values[%d].propertyType()", i);
4279 CHECK_EQ(5, CompileRun(buffer.start())->Int32Value());
4281 OS::SNPrintF(buffer,
"named_values[%d].isNative()", i);
4282 CHECK(CompileRun(buffer.start())->BooleanValue());
4287 CompileRun(
"var indexed_values = indexed_mirror.properties()");
4290 for (
int i = 0; i < 2; i++) {
4291 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
4292 OS::SNPrintF(buffer,
4293 "indexed_values[%d] instanceof debug.PropertyMirror", i);
4294 CHECK(CompileRun(buffer.start())->BooleanValue());
4299 CompileRun(
"var both_values = both_mirror.properties()");
4302 for (
int i = 0; i < 5; i++) {
4303 EmbeddedVector<char, SMALL_STRING_BUFFER_SIZE> buffer;
4304 OS::SNPrintF(buffer,
"both_values[%d] instanceof debug.PropertyMirror", i);
4305 CHECK(CompileRun(buffer.start())->BooleanValue());
4309 source =
"both_values[0].name() == 'a'";
4310 CHECK(CompileRun(source)->BooleanValue());
4312 source =
"both_values[1].name() == 'b'";
4313 CHECK(CompileRun(source)->BooleanValue());
4315 source =
"both_values[2].name() == 'c'";
4316 CHECK(CompileRun(source)->BooleanValue());
4318 source =
"both_values[3].name() == 1";
4319 CHECK(CompileRun(source)->BooleanValue());
4321 source =
"both_values[4].name() == 10";
4322 CHECK(CompileRun(source)->BooleanValue());
4326 TEST(HiddenPrototypePropertyMirror) {
4329 DebugLocalContext env;
4355 "var o0_mirror = debug.MakeMirror(o0);"
4356 "var o1_mirror = debug.MakeMirror(o1);"
4357 "var o2_mirror = debug.MakeMirror(o2);"
4358 "var o3_mirror = debug.MakeMirror(o3)");
4359 CHECK(CompileRun(
"o0_mirror instanceof debug.ObjectMirror")->BooleanValue());
4360 CHECK(CompileRun(
"o1_mirror instanceof debug.ObjectMirror")->BooleanValue());
4361 CHECK(CompileRun(
"o2_mirror instanceof debug.ObjectMirror")->BooleanValue());
4362 CHECK(CompileRun(
"o3_mirror instanceof debug.ObjectMirror")->BooleanValue());
4366 "o0_mirror.propertyNames().length")->Int32Value());
4368 "o1_mirror.propertyNames().length")->Int32Value());
4370 "o2_mirror.propertyNames().length")->Int32Value());
4372 "o3_mirror.propertyNames().length")->Int32Value());
4378 "o0_mirror.propertyNames().length")->Int32Value());
4380 "o0_mirror.property('x').value().value()")->Int32Value());
4382 "o0_mirror.property('y').value().value()")->Int32Value());
4389 "o0_mirror.propertyNames().length")->Int32Value());
4391 "o0_mirror.property('x').value().value()")->Int32Value());
4393 "o0_mirror.property('y').value().value()")->Int32Value());
4395 "o0_mirror.property('z').value().value()")->Int32Value());
4405 "o0_mirror.propertyNames().length")->Int32Value());
4407 "o3_mirror.propertyNames().length")->Int32Value());
4409 "o0_mirror.property('x').value().value()")->Int32Value());
4411 "o0_mirror.property('y').value().value()")->Int32Value());
4413 "o0_mirror.property('z').value().value()")->Int32Value());
4414 CHECK(CompileRun(
"o0_mirror.property('u').isUndefined()")->BooleanValue());
4417 CHECK(CompileRun(
"o0_mirror.protoObject() == o3_mirror")->BooleanValue());
4427 TEST(NativeGetterPropertyMirror) {
4430 DebugLocalContext env;
4441 CHECK_EQ(10, CompileRun(
"instance.x")->Int32Value());
4444 CompileRun(
"var instance_mirror = debug.MakeMirror(instance);");
4446 "instance_mirror instanceof debug.ObjectMirror")->BooleanValue());
4448 CompileRun(
"var named_names = instance_mirror.propertyNames();");
4449 CHECK_EQ(1, CompileRun(
"named_names.length")->Int32Value());
4450 CHECK(CompileRun(
"named_names[0] == 'x'")->BooleanValue());
4452 "instance_mirror.property('x').value().isNumber()")->BooleanValue());
4454 "instance_mirror.property('x').value().value() == 10")->BooleanValue());
4460 return CompileRun(
"throw new Error('Error message');");
4464 TEST(NativeGetterThrowingErrorPropertyMirror) {
4467 DebugLocalContext env;
4480 CompileRun(
"var instance_mirror = debug.MakeMirror(instance);");
4482 "instance_mirror instanceof debug.ObjectMirror")->BooleanValue());
4483 CompileRun(
"named_names = instance_mirror.propertyNames();");
4484 CHECK_EQ(1, CompileRun(
"named_names.length")->Int32Value());
4485 CHECK(CompileRun(
"named_names[0] == 'x'")->BooleanValue());
4487 "instance_mirror.property('x').value().isError()")->BooleanValue());
4491 "instance_mirror.property('x').value().message() == 'Error message'")->
4499 TEST(NoHiddenProperties) {
4502 DebugLocalContext env;
4506 const char* source =
"var obj = {a: 1};";
4515 CompileRun(
"var obj_mirror = debug.MakeMirror(obj);");
4517 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue());
4518 CompileRun(
"var named_names = obj_mirror.propertyNames();");
4522 CHECK_EQ(1, CompileRun(
"named_names.length")->Int32Value());
4523 CHECK(CompileRun(
"named_names[0] == 'a'")->BooleanValue());
4525 "obj_mirror.property('a').value().value() == 1")->BooleanValue());
4550 CompileRun(
"var obj_mirror = debug.MakeMirror(obj);");
4552 "obj_mirror instanceof debug.ObjectMirror")->BooleanValue());
4553 CompileRun(
"var named_names = obj_mirror.propertyNames();");
4556 CHECK_EQ(2, CompileRun(
"named_names.length")->Int32Value());
4557 CHECK(CompileRun(
"named_names.sort(); named_names[0] == 'a' &&"
4558 "named_names[1] == 'b'")->BooleanValue());
4560 "obj_mirror.property('a').value().value() == 1")->BooleanValue());
4562 "obj_mirror.property('b').value().value() == 2")->BooleanValue());
4574 class ThreadBarrier {
4576 explicit ThreadBarrier(
int num_threads);
4587 ThreadBarrier::ThreadBarrier(
int num_threads)
4588 : num_threads_(num_threads), num_blocked_(0) {
4589 lock_ = OS::CreateMutex();
4590 sem_ = OS::CreateSemaphore(0);
4596 ThreadBarrier::~ThreadBarrier() {
4602 void ThreadBarrier::Wait() {
4605 if (num_blocked_ == num_threads_ - 1) {
4607 for (
int i = 0; i < num_threads_ - 1; ++i) {
4611 printf(
"BARRIER\n\n");
4626 ThreadBarrier barrier_1;
4627 ThreadBarrier barrier_2;
4628 ThreadBarrier barrier_3;
4629 ThreadBarrier barrier_4;
4630 ThreadBarrier barrier_5;
4635 Barriers::Barriers() : barrier_1(2), barrier_2(2),
4636 barrier_3(2), barrier_4(2), barrier_5(2) {}
4638 void Barriers::Initialize() {
4639 semaphore_1 = OS::CreateSemaphore(0);
4640 semaphore_2 = OS::CreateSemaphore(0);
4645 bool IsBreakEventMessage(
char *message) {
4646 const char* type_event =
"\"type\":\"event\"";
4647 const char* event_break =
"\"event\":\"break\"";
4649 return strstr(message, type_event) !=
NULL &&
4650 strstr(message, event_break) !=
NULL;
4655 bool IsExceptionEventMessage(
char *message) {
4656 const char* type_event =
"\"type\":\"event\"";
4657 const char* event_exception =
"\"event\":\"exception\"";
4659 return strstr(message, type_event) !=
NULL &&
4660 strstr(message, event_exception) !=
NULL;
4665 bool IsEvaluateResponseMessage(
char* message) {
4666 const char* type_response =
"\"type\":\"response\"";
4667 const char* command_evaluate =
"\"command\":\"evaluate\"";
4669 return strstr(message, type_response) !=
NULL &&
4670 strstr(message, command_evaluate) !=
NULL;
4680 int GetEvaluateIntResult(
char *message) {
4681 const char* value =
"\"value\":";
4682 char* pos = strstr(message, value);
4693 int GetBreakpointIdFromBreakEventMessage(
char *message) {
4694 const char* breakpoints =
"\"breakpoints\":[";
4695 char* pos = strstr(message, breakpoints);
4706 int GetTotalFramesInt(
char *message) {
4707 const char* prefix =
"\"totalFrames\":";
4708 char* pos = strstr(message, prefix);
4712 pos += strlen(prefix);
4719 int GetSourceLineFromBreakEventMessage(
char *message) {
4720 const char* source_line =
"\"sourceLine\":";
4721 char* pos = strstr(message, source_line);
4735 Barriers message_queue_barriers;
4741 MessageQueueDebuggerThread()
4742 : Thread(
"MessageQueueDebuggerThread") { }
4746 static void MessageHandler(
const uint16_t* message,
int length,
4748 static char print_buffer[1000];
4749 Utf16ToAscii(message, length, print_buffer);
4750 if (IsBreakEventMessage(print_buffer)) {
4753 message_queue_barriers.semaphore_2->Signal();
4758 message_queue_barriers.semaphore_1->Wait();
4761 void MessageQueueDebuggerThread::Run() {
4762 const int kBufferSize = 1000;
4765 const char* command_1 =
4767 "\"type\":\"request\","
4768 "\"command\":\"evaluate\","
4769 "\"arguments\":{\"expression\":\"1+2\"}}";
4770 const char* command_2 =
4772 "\"type\":\"request\","
4773 "\"command\":\"evaluate\","
4774 "\"arguments\":{\"expression\":\"1+a\"}}";
4775 const char* command_3 =
4777 "\"type\":\"request\","
4778 "\"command\":\"evaluate\","
4779 "\"arguments\":{\"expression\":\"c.d * b\"}}";
4780 const char* command_continue =
4782 "\"type\":\"request\","
4783 "\"command\":\"continue\"}";
4784 const char* command_single_step =
4786 "\"type\":\"request\","
4787 "\"command\":\"continue\","
4788 "\"arguments\":{\"stepaction\":\"next\"}}";
4792 message_queue_barriers.semaphore_1->Signal();
4793 message_queue_barriers.barrier_1.Wait();
4804 message_queue_barriers.barrier_2.Wait();
4812 for (
int i = 0; i < 6 ; ++i) {
4813 message_queue_barriers.semaphore_1->Signal();
4815 message_queue_barriers.barrier_3.Wait();
4818 message_queue_barriers.semaphore_1->Signal();
4821 message_queue_barriers.semaphore_2->Wait();
4828 for (
int i = 0; i < 6 ; ++i) {
4829 message_queue_barriers.semaphore_1->Signal();
4832 message_queue_barriers.semaphore_2->Wait();
4836 for (
int i = 0; i < 2 ; ++i) {
4837 message_queue_barriers.semaphore_1->Signal();
4844 TEST(MessageQueues) {
4845 MessageQueueDebuggerThread message_queue_debugger_thread;
4849 DebugLocalContext env;
4850 message_queue_barriers.Initialize();
4852 message_queue_debugger_thread.Start();
4854 const char* source_1 =
"a = 3; b = 4; c = new Object(); c.d = 5;";
4855 const char* source_2 =
"e = 17;";
4856 const char* source_3 =
"a = 4; debugger; a = 5; a = 6; a = 7;";
4860 CompileRun(source_1);
4861 message_queue_barriers.barrier_1.Wait();
4862 message_queue_barriers.barrier_2.Wait();
4863 CompileRun(source_2);
4864 message_queue_barriers.barrier_3.Wait();
4865 CompileRun(source_3);
4866 message_queue_debugger_thread.Join();
4874 constructor_call_counter++;
4876 virtual ~TestClientData() {
4877 destructor_call_counter++;
4880 static void ResetCounters() {
4881 constructor_call_counter = 0;
4882 destructor_call_counter = 0;
4885 static int constructor_call_counter;
4886 static int destructor_call_counter;
4889 int TestClientData::constructor_call_counter = 0;
4890 int TestClientData::destructor_call_counter = 0;
4895 TEST(MessageQueueExpandAndDestroy) {
4896 TestClientData::ResetCounters();
4898 CommandMessageQueue queue(1);
4899 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4900 new TestClientData()));
4901 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4902 new TestClientData()));
4903 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4904 new TestClientData()));
4905 CHECK_EQ(0, TestClientData::destructor_call_counter);
4906 queue.Get().Dispose();
4907 CHECK_EQ(1, TestClientData::destructor_call_counter);
4908 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4909 new TestClientData()));
4910 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4911 new TestClientData()));
4912 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4913 new TestClientData()));
4914 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4915 new TestClientData()));
4916 queue.Put(CommandMessage::New(Vector<uint16_t>::empty(),
4917 new TestClientData()));
4918 CHECK_EQ(1, TestClientData::destructor_call_counter);
4919 queue.Get().Dispose();
4920 CHECK_EQ(2, TestClientData::destructor_call_counter);
4923 CHECK_EQ(TestClientData::destructor_call_counter,
4924 TestClientData::destructor_call_counter);
4928 static int handled_client_data_instances_count = 0;
4929 static void MessageHandlerCountingClientData(
4932 handled_client_data_instances_count++;
4938 TEST(SendClientDataToHandler) {
4941 DebugLocalContext env;
4942 TestClientData::ResetCounters();
4943 handled_client_data_instances_count = 0;
4945 const char* source_1 =
"a = 3; b = 4; c = new Object(); c.d = 5;";
4946 const int kBufferSize = 1000;
4948 const char* command_1 =
4950 "\"type\":\"request\","
4951 "\"command\":\"evaluate\","
4952 "\"arguments\":{\"expression\":\"1+2\"}}";
4953 const char* command_2 =
4955 "\"type\":\"request\","
4956 "\"command\":\"evaluate\","
4957 "\"arguments\":{\"expression\":\"1+a\"}}";
4958 const char* command_continue =
4960 "\"type\":\"request\","
4961 "\"command\":\"continue\"}";
4964 new TestClientData());
4967 new TestClientData());
4969 new TestClientData());
4971 CompileRun(source_1);
4973 CHECK_EQ(3, TestClientData::constructor_call_counter);
4974 CHECK_EQ(TestClientData::constructor_call_counter,
4975 handled_client_data_instances_count);
4976 CHECK_EQ(TestClientData::constructor_call_counter,
4977 TestClientData::destructor_call_counter);
4988 Barriers threaded_debugging_barriers;
4992 V8Thread() : Thread(
"V8Thread") { }
4998 DebuggerThread() : Thread(
"DebuggerThread") { }
5004 threaded_debugging_barriers.barrier_1.Wait();
5010 static char print_buffer[1000];
5012 Utf16ToAscii(*json, json.length(), print_buffer);
5013 if (IsBreakEventMessage(print_buffer)) {
5015 int source_line = GetSourceLineFromBreakEventMessage(print_buffer);
5019 CHECK(7 <= source_line && source_line <= 13);
5020 threaded_debugging_barriers.barrier_2.Wait();
5025 void V8Thread::Run() {
5026 const char* source =
5028 "function bar( new_value ) {\n"
5029 " flag = new_value;\n"
5030 " return \"Return from bar(\" + new_value + \")\";\n"
5033 "function foo() {\n"
5035 " while ( flag == true ) {\n"
5036 " if ( x == 1 ) {\n"
5037 " ThreadedAtBarrier1();\n"
5047 DebugLocalContext env;
5058 void DebuggerThread::Run() {
5059 const int kBufSize = 1000;
5062 const char* command_1 =
"{\"seq\":102,"
5063 "\"type\":\"request\","
5064 "\"command\":\"evaluate\","
5065 "\"arguments\":{\"expression\":\"bar(false)\"}}";
5066 const char* command_2 =
"{\"seq\":103,"
5067 "\"type\":\"request\","
5068 "\"command\":\"continue\"}";
5070 threaded_debugging_barriers.barrier_1.Wait();
5072 threaded_debugging_barriers.barrier_2.Wait();
5078 TEST(ThreadedDebugging) {
5079 DebuggerThread debugger_thread;
5083 threaded_debugging_barriers.Initialize();
5086 debugger_thread.Start();
5089 debugger_thread.Join();
5101 BreakpointsV8Thread() : Thread(
"BreakpointsV8Thread") { }
5107 explicit BreakpointsDebuggerThread(
bool global_evaluate)
5108 : Thread(
"BreakpointsDebuggerThread"),
5109 global_evaluate_(global_evaluate) {}
5113 bool global_evaluate_;
5117 Barriers* breakpoints_barriers;
5118 int break_event_breakpoint_id;
5119 int evaluate_int_result;
5122 static char print_buffer[1000];
5124 Utf16ToAscii(*json, json.length(), print_buffer);
5126 if (IsBreakEventMessage(print_buffer)) {
5127 break_event_breakpoint_id =
5128 GetBreakpointIdFromBreakEventMessage(print_buffer);
5129 breakpoints_barriers->semaphore_1->Signal();
5130 }
else if (IsEvaluateResponseMessage(print_buffer)) {
5131 evaluate_int_result = GetEvaluateIntResult(print_buffer);
5132 breakpoints_barriers->semaphore_1->Signal();
5137 void BreakpointsV8Thread::Run() {
5138 const char* source_1 =
"var y_global = 3;\n"
5139 "function cat( new_value ) {\n"
5140 " var x = new_value;\n"
5141 " y_global = y_global + 4;\n"
5143 " y_global = y_global + 5;\n"
5147 "function dog() {\n"
5155 const char* source_2 =
"cat(17);\n"
5160 DebugLocalContext env;
5163 CompileRun(source_1);
5164 breakpoints_barriers->barrier_1.Wait();
5165 breakpoints_barriers->barrier_2.Wait();
5166 CompileRun(source_2);
5170 void BreakpointsDebuggerThread::Run() {
5171 const int kBufSize = 1000;
5174 const char* command_1 =
"{\"seq\":101,"
5175 "\"type\":\"request\","
5176 "\"command\":\"setbreakpoint\","
5177 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
5178 const char* command_2 =
"{\"seq\":102,"
5179 "\"type\":\"request\","
5180 "\"command\":\"setbreakpoint\","
5181 "\"arguments\":{\"type\":\"function\",\"target\":\"dog\",\"line\":3}}";
5182 const char* command_3;
5183 if (this->global_evaluate_) {
5184 command_3 =
"{\"seq\":103,"
5185 "\"type\":\"request\","
5186 "\"command\":\"evaluate\","
5187 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false,"
5188 "\"global\":true}}";
5190 command_3 =
"{\"seq\":103,"
5191 "\"type\":\"request\","
5192 "\"command\":\"evaluate\","
5193 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":false}}";
5195 const char* command_4;
5196 if (this->global_evaluate_) {
5197 command_4 =
"{\"seq\":104,"
5198 "\"type\":\"request\","
5199 "\"command\":\"evaluate\","
5200 "\"arguments\":{\"expression\":\"100 + 8\",\"disable_break\":true,"
5201 "\"global\":true}}";
5203 command_4 =
"{\"seq\":104,"
5204 "\"type\":\"request\","
5205 "\"command\":\"evaluate\","
5206 "\"arguments\":{\"expression\":\"x + 1\",\"disable_break\":true}}";
5208 const char* command_5 =
"{\"seq\":105,"
5209 "\"type\":\"request\","
5210 "\"command\":\"continue\"}";
5211 const char* command_6 =
"{\"seq\":106,"
5212 "\"type\":\"request\","
5213 "\"command\":\"continue\"}";
5214 const char* command_7;
5215 if (this->global_evaluate_) {
5216 command_7 =
"{\"seq\":107,"
5217 "\"type\":\"request\","
5218 "\"command\":\"evaluate\","
5219 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true,"
5220 "\"global\":true}}";
5222 command_7 =
"{\"seq\":107,"
5223 "\"type\":\"request\","
5224 "\"command\":\"evaluate\","
5225 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}";
5227 const char* command_8 =
"{\"seq\":108,"
5228 "\"type\":\"request\","
5229 "\"command\":\"continue\"}";
5233 breakpoints_barriers->barrier_1.Wait();
5238 breakpoints_barriers->barrier_2.Wait();
5245 breakpoints_barriers->semaphore_1->Wait();
5247 CHECK_EQ(1, break_event_breakpoint_id);
5251 breakpoints_barriers->semaphore_1->Wait();
5253 CHECK_EQ(2, break_event_breakpoint_id);
5257 breakpoints_barriers->semaphore_1->Wait();
5259 CHECK_EQ(108, evaluate_int_result);
5263 breakpoints_barriers->semaphore_1->Wait();
5265 CHECK_EQ(107, evaluate_int_result);
5270 breakpoints_barriers->semaphore_1->Wait();
5272 CHECK_EQ(1, break_event_breakpoint_id);
5276 breakpoints_barriers->semaphore_1->Wait();
5278 CHECK_EQ(116, evaluate_int_result);
5283 void TestRecursiveBreakpointsGeneric(
bool global_evaluate) {
5284 i::FLAG_debugger_auto_break =
true;
5286 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
5287 BreakpointsV8Thread breakpoints_v8_thread;
5290 Barriers stack_allocated_breakpoints_barriers;
5291 stack_allocated_breakpoints_barriers.Initialize();
5292 breakpoints_barriers = &stack_allocated_breakpoints_barriers;
5294 breakpoints_v8_thread.Start();
5295 breakpoints_debugger_thread.Start();
5297 breakpoints_v8_thread.Join();
5298 breakpoints_debugger_thread.Join();
5301 TEST(RecursiveBreakpoints) {
5302 TestRecursiveBreakpointsGeneric(
false);
5305 TEST(RecursiveBreakpointsGlobal) {
5306 TestRecursiveBreakpointsGeneric(
true);
5317 TEST(SetDebugEventListenerOnUninitializedVM) {
5326 TEST(SetMessageHandlerOnUninitializedVM) {
5331 TEST(DebugBreakOnUninitializedVM) {
5336 TEST(SendCommandToUninitializedVM) {
5337 const char* dummy_command =
"{}";
5339 int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer);
5347 static const char* debugger_call_with_data_source =
5348 "function debugger_call_with_data(exec_state, data) {"
5349 " if (data) return data;"
5358 static const char* debugger_call_with_closure_source =
5360 "(function (exec_state) {"
5361 " if (exec_state.y) return x - 1;"
5362 " exec_state.y = x;"
5363 " return exec_state.y"
5415 TEST(CallFunctionInDebugger) {
5458 " CheckFrameCount(2);"
5464 " CheckSourceLine(1)\n"
5465 " CheckSourceLine(2)\n"
5466 " CheckSourceLine(3)\n"
5481 " CheckSourceLine(8)\n"
5482 " CheckSourceLine(9)\n"
5483 " CheckSourceLine(10)\n"
5484 "}; f()"), &origin)->Run();
5489 static void SendContinueCommand();
5490 static void MessageHandlerBreakPointHitCount(
5494 break_point_hit_count++;
5496 SendContinueCommand();
5503 TEST(DebuggerUnload) {
5504 DebugLocalContext env;
5507 CheckDebuggerUnloaded();
5510 break_point_hit_count = 0;
5517 CompileFunction(&env,
"function foo(){x=1}",
"foo");
5519 CompileFunction(&env,
"function bar(){y=2}",
"bar");
5522 SetBreakPoint(foo, 0);
5523 SetBreakPoint(foo, 4);
5524 SetBreakPoint(bar, 0);
5525 SetBreakPoint(bar, 4);
5528 break_point_hit_count = 0;
5530 CHECK_EQ(2, break_point_hit_count);
5532 CHECK_EQ(4, break_point_hit_count);
5538 CheckDebuggerUnloaded(
true);
5541 break_point_hit_count = 0;
5551 CHECK_EQ(0, break_point_hit_count);
5554 SetBreakPoint(foo, 0);
5555 SetBreakPoint(foo, 4);
5557 CHECK_EQ(2, break_point_hit_count);
5563 CheckDebuggerUnloaded(
true);
5568 static void SendContinueCommand() {
5569 const int kBufferSize = 1000;
5571 const char* command_continue =
5573 "\"type\":\"request\","
5574 "\"command\":\"continue\"}";
5581 static int message_handler_hit_count = 0;
5583 message_handler_hit_count++;
5585 static char print_buffer[1000];
5587 Utf16ToAscii(*json, json.length(), print_buffer);
5588 if (IsExceptionEventMessage(print_buffer)) {
5590 SendContinueCommand();
5596 TEST(DebuggerClearMessageHandler) {
5598 DebugLocalContext env;
5601 CheckDebuggerUnloaded();
5608 CompileRun(
"throw 1");
5611 CHECK_GT(message_handler_hit_count, 0);
5614 message_handler_hit_count = 0;
5619 CompileRun(
"throw 1");
5622 CHECK_EQ(0, message_handler_hit_count);
5624 CheckDebuggerUnloaded(
true);
5629 static void MessageHandlerClearingMessageHandler(
5631 message_handler_hit_count++;
5639 TEST(DebuggerClearMessageHandlerWhileActive) {
5641 DebugLocalContext env;
5644 CheckDebuggerUnloaded();
5651 CompileRun(
"throw 1");
5654 CHECK_EQ(1, message_handler_hit_count);
5656 CheckDebuggerUnloaded(
true);
5667 HostDispatchV8Thread() : Thread(
"HostDispatchV8Thread") { }
5673 HostDispatchDebuggerThread() : Thread(
"HostDispatchDebuggerThread") { }
5677 Barriers* host_dispatch_barriers;
5680 static char print_buffer[1000];
5682 Utf16ToAscii(*json, json.length(), print_buffer);
5686 static void HostDispatchDispatchHandler() {
5687 host_dispatch_barriers->semaphore_1->Signal();
5691 void HostDispatchV8Thread::Run() {
5692 const char* source_1 =
"var y_global = 3;\n"
5693 "function cat( new_value ) {\n"
5694 " var x = new_value;\n"
5701 const char* source_2 =
"cat(17);\n";
5705 DebugLocalContext env;
5711 CompileRun(source_1);
5712 host_dispatch_barriers->barrier_1.Wait();
5713 host_dispatch_barriers->barrier_2.Wait();
5714 CompileRun(source_2);
5718 void HostDispatchDebuggerThread::Run() {
5719 const int kBufSize = 1000;
5722 const char* command_1 =
"{\"seq\":101,"
5723 "\"type\":\"request\","
5724 "\"command\":\"setbreakpoint\","
5725 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
5726 const char* command_2 =
"{\"seq\":102,"
5727 "\"type\":\"request\","
5728 "\"command\":\"continue\"}";
5731 host_dispatch_barriers->barrier_1.Wait();
5735 host_dispatch_barriers->barrier_2.Wait();
5739 host_dispatch_barriers->semaphore_1->Wait();
5745 TEST(DebuggerHostDispatch) {
5746 HostDispatchDebuggerThread host_dispatch_debugger_thread;
5747 HostDispatchV8Thread host_dispatch_v8_thread;
5748 i::FLAG_debugger_auto_break =
true;
5751 Barriers stack_allocated_host_dispatch_barriers;
5752 stack_allocated_host_dispatch_barriers.Initialize();
5753 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
5755 host_dispatch_v8_thread.Start();
5756 host_dispatch_debugger_thread.Start();
5758 host_dispatch_v8_thread.Join();
5759 host_dispatch_debugger_thread.Join();
5771 DebugMessageDispatchV8Thread() : Thread(
"DebugMessageDispatchV8Thread") { }
5777 DebugMessageDispatchDebuggerThread()
5778 : Thread(
"DebugMessageDispatchDebuggerThread") { }
5782 Barriers* debug_message_dispatch_barriers;
5785 static void DebugMessageHandler() {
5786 debug_message_dispatch_barriers->semaphore_1->Signal();
5790 void DebugMessageDispatchV8Thread::Run() {
5793 DebugLocalContext env;
5798 CompileRun(
"var y = 1 + 2;\n");
5799 debug_message_dispatch_barriers->barrier_1.Wait();
5800 debug_message_dispatch_barriers->semaphore_1->Wait();
5801 debug_message_dispatch_barriers->barrier_2.Wait();
5805 void DebugMessageDispatchDebuggerThread::Run() {
5806 debug_message_dispatch_barriers->barrier_1.Wait();
5807 SendContinueCommand();
5808 debug_message_dispatch_barriers->barrier_2.Wait();
5812 TEST(DebuggerDebugMessageDispatch) {
5813 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
5814 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
5816 i::FLAG_debugger_auto_break =
true;
5819 Barriers stack_allocated_debug_message_dispatch_barriers;
5820 stack_allocated_debug_message_dispatch_barriers.Initialize();
5821 debug_message_dispatch_barriers =
5822 &stack_allocated_debug_message_dispatch_barriers;
5824 debug_message_dispatch_v8_thread.Start();
5825 debug_message_dispatch_debugger_thread.Start();
5827 debug_message_dispatch_v8_thread.Join();
5828 debug_message_dispatch_debugger_thread.Join();
5832 TEST(DebuggerAgent) {
5834 i::Debugger* debugger = i::Isolate::Current()->debugger();
5837 const int kPort1 = 5858;
5838 const int kPort2 = 5857;
5839 const int kPort3 = 5856;
5842 const int kPortBufferLen = 6;
5843 char port2_str[kPortBufferLen];
5844 OS::SNPrintF(
i::Vector<char>(port2_str, kPortBufferLen),
"%d", kPort2);
5852 debugger->StartAgent(
"test", kPort1);
5853 debugger->StopAgent();
5856 ok = debugger->StartAgent(
"test", kPort2);
5858 debugger->WaitForAgent();
5860 ok = client->
Connect(
"localhost", port2_str);
5866 ok = client->
Receive(&buf, 1) == 1;
5868 debugger->StopAgent();
5874 server->
Bind(kPort3);
5876 debugger->StartAgent(
"test", kPort3);
5877 debugger->StopAgent();
5883 class DebuggerAgentProtocolServerThread :
public i::Thread {
5885 explicit DebuggerAgentProtocolServerThread(
int port)
5886 : Thread(
"DebuggerAgentProtocolServerThread"),
5890 listening_(OS::CreateSemaphore(0)) {
5892 ~DebuggerAgentProtocolServerThread() {
5900 void WaitForListening() { listening_->Wait(); }
5901 char* body() {
return *body_; }
5912 void DebuggerAgentProtocolServerThread::Run() {
5918 ok = server_->Bind(port_);
5922 ok = server_->Listen(1);
5924 listening_->Signal();
5927 client_ = server_->Accept();
5931 i::DebuggerAgentUtil::ReceiveMessage(client_);
5935 TEST(DebuggerAgentProtocolOverflowHeader) {
5938 const int kPort = 5860;
5939 static const char* kLocalhost =
"localhost";
5942 const int kPortBufferLen = 6;
5943 char port_str[kPortBufferLen];
5950 DebuggerAgentProtocolServerThread* server =
5951 new DebuggerAgentProtocolServerThread(kPort);
5953 server->WaitForListening();
5958 bool ok = client->
Connect(kLocalhost, port_str);
5962 static const int kBufferSize = 1000;
5963 char buffer[kBufferSize];
5966 for (
int i = 0; i < kBufferSize - 4; i++) {
5969 buffer[kBufferSize - 4] =
':';
5970 buffer[kBufferSize - 3] =
'0';
5971 buffer[kBufferSize - 2] =
'\r';
5972 buffer[kBufferSize - 1] =
'\n';
5973 client->
Send(buffer, kBufferSize);
5978 for (
int i = 2; i < kBufferSize - 2; i++) {
5981 buffer[kBufferSize - 2] =
'\r';
5982 buffer[kBufferSize - 1] =
'\n';
5983 client->
Send(buffer, kBufferSize);
5986 const char* content_length_zero_header =
"Content-Length:0\r\n";
5987 client->
Send(content_length_zero_header,
5989 client->
Send(
"\r\n", 2);
6009 EmptyExternalStringResource() { empty_[0] = 0; }
6010 virtual ~EmptyExternalStringResource() {}
6011 virtual size_t length()
const {
return empty_.length(); }
6012 virtual const uint16_t*
data()
const {
return empty_.start(); }
6018 TEST(DebugGetLoadedScripts) {
6020 DebugLocalContext env;
6023 EmptyExternalStringResource source_ext_str;
6028 Handle<i::ExternalTwoByteString> i_source(
6032 i_source->set_resource(0);
6034 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
6035 i::FLAG_allow_natives_syntax =
true;
6037 "var scripts = %DebugGetLoadedScripts();"
6038 "var count = scripts.length;"
6039 "for (var i = 0; i < count; ++i) {"
6040 " scripts[i].line_ends;"
6043 i::FLAG_allow_natives_syntax = allow_natives_syntax;
6051 TEST(ScriptNameAndData) {
6053 DebugLocalContext env;
6058 frame_script_name = CompileFunction(&env,
6059 frame_script_name_source,
6060 "frame_script_name");
6061 frame_script_data = CompileFunction(&env,
6062 frame_script_data_source,
6063 "frame_script_data");
6064 compiled_script_data = CompileFunction(&env,
6065 compiled_script_data_source,
6066 "compiled_script_data");
6085 CHECK_EQ(1, break_point_hit_count);
6086 CHECK_EQ(
"name", last_script_name_hit);
6087 CHECK_EQ(
"data", last_script_data_hit);
6094 CHECK_EQ(2, break_point_hit_count);
6095 CHECK_EQ(
"name", last_script_name_hit);
6096 CHECK_EQ(
"", last_script_data_hit);
6101 " toString: function() { return this.a + ' ' + this.b; }\n"
6110 CHECK_EQ(3, break_point_hit_count);
6111 CHECK_EQ(
"new name", last_script_name_hit);
6112 CHECK_EQ(
"abc 123", last_script_data_hit);
6117 CHECK_EQ(
"in compile", last_script_data_hit);
6121 CHECK_EQ(4, break_point_hit_count);
6122 CHECK_EQ(
"in compile", last_script_data_hit);
6134 expected_context_data));
6135 message_handler_hit_count++;
6137 static char print_buffer[1000];
6139 Utf16ToAscii(*json, json.length(), print_buffer);
6142 if (IsBreakEventMessage(print_buffer)) {
6143 SendContinueCommand();
6167 CHECK(context_2->GetData()->IsUndefined());
6172 context_1->SetData(data_1);
6173 context_2->SetData(data_2);
6175 CHECK(context_2->GetData()->StrictEquals(data_2));
6178 const char* source =
"function f() { debugger; }";
6183 expected_context = context_1;
6184 expected_context_data = data_1;
6186 f->
Call(context_1->Global(), 0,
NULL);
6193 expected_context = context_2;
6194 expected_context_data = data_2;
6196 f->
Call(context_2->Global(), 0,
NULL);
6200 CHECK_GT(message_handler_hit_count, 4);
6203 CheckDebuggerUnloaded();
6208 static int message_handler_break_hit_count = 0;
6212 message_handler_break_hit_count++;
6213 if (message_handler_break_hit_count == 1) {
6221 SendContinueCommand();
6227 TEST(DebugBreakInMessageHandler) {
6229 DebugLocalContext env;
6234 const char* script =
"function f() { debugger; g(); } function g() { }";
6244 CHECK_EQ(2, message_handler_break_hit_count);
6247 CHECK_EQ(2, message_handler_break_hit_count);
6251 #ifndef V8_INTERPRETED_REGEXP
6254 static void DebugEventDebugBreak(
6261 break_point_hit_count++;
6264 if (!frame_function_name.
IsEmpty()) {
6271 last_function_hit[0] =
'\0';
6275 function_name->WriteAscii(last_function_hit);
6280 if (break_point_hit_count < 20) {
6287 TEST(RegExpDebugBreak) {
6290 DebugLocalContext env;
6293 frame_function_name = CompileFunction(&env,
6294 frame_function_name_source,
6295 "frame_function_name");
6299 const char* script =
6300 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n"
6301 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }";
6311 result = f->
Call(env->Global(), argc, argv);
6315 CHECK_EQ(1, break_point_hit_count);
6318 #endif // V8_INTERPRETED_REGEXP
6322 static void ExecuteScriptForContextCheck() {
6330 CHECK(context_1->GetData()->IsUndefined());
6334 context_1->SetData(data_1);
6335 CHECK(context_1->GetData()->StrictEquals(data_1));
6338 const char* source =
"function f() { eval('debugger;'); }";
6343 expected_context = context_1;
6344 expected_context_data = data_1;
6346 f->
Call(context_1->Global(), 0,
NULL);
6355 TEST(EvalContextData) {
6359 ExecuteScriptForContextCheck();
6362 CHECK_GT(message_handler_hit_count, 2);
6364 CheckDebuggerUnloaded();
6368 static bool sent_eval =
false;
6369 static int break_count = 0;
6370 static int continue_command_send_count = 0;
6373 static void DebugEvalContextCheckMessageHandler(
6377 expected_context_data));
6378 message_handler_hit_count++;
6380 static char print_buffer[1000];
6382 Utf16ToAscii(*json, json.length(), print_buffer);
6384 if (IsBreakEventMessage(print_buffer)) {
6389 const int kBufferSize = 1000;
6391 const char* eval_command =
6393 "\"type\":\"request\","
6394 "\"command\":\"evaluate\","
6395 "\"arguments\":{\"expression\":\"debugger;\","
6396 "\"global\":true,\"disable_break\":false}}";
6403 SendContinueCommand();
6404 continue_command_send_count++;
6406 }
else if (IsEvaluateResponseMessage(print_buffer) &&
6407 continue_command_send_count < 2) {
6410 SendContinueCommand();
6411 continue_command_send_count++;
6418 TEST(NestedBreakEventContextData) {
6421 message_handler_hit_count = 0;
6424 ExecuteScriptForContextCheck();
6427 CHECK_GT(message_handler_hit_count, 3);
6432 CheckDebuggerUnloaded();
6437 int script_collected_count = 0;
6444 script_collected_count++;
6450 TEST(ScriptCollectedEvent) {
6451 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6452 break_point_hit_count = 0;
6453 script_collected_count = 0;
6455 DebugLocalContext env;
6458 debug->GetLoadedScripts();
6462 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6464 script_collected_count = 0;
6474 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6476 CHECK_EQ(2, script_collected_count);
6479 CheckDebuggerUnloaded();
6484 int script_collected_message_count = 0;
6488 script_collected_message_count++;
6497 TEST(ScriptCollectedEventContext) {
6498 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6499 script_collected_message_count = 0;
6503 DebugLocalContext env;
6506 debug->GetLoadedScripts();
6510 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6521 HEAP->CollectAllGarbage(Heap::kNoGCFlags);
6523 CHECK_EQ(2, script_collected_message_count);
6530 int after_compile_message_count = 0;
6535 after_compile_message_count++;
6537 SendContinueCommand();
6545 TEST(AfterCompileMessageWhenMessageHandlerIsReset) {
6547 DebugLocalContext env;
6548 after_compile_message_count = 0;
6549 const char* script =
"var a=1";
6561 CheckDebuggerUnloaded();
6564 CHECK_EQ(2, after_compile_message_count);
6569 TEST(BreakMessageWhenMessageHandlerIsReset) {
6571 DebugLocalContext env;
6572 after_compile_message_count = 0;
6573 const char* script =
"function f() {};";
6587 CheckDebuggerUnloaded();
6590 CHECK_EQ(1, after_compile_message_count);
6594 static int exception_event_count = 0;
6597 exception_event_count++;
6598 SendContinueCommand();
6604 TEST(ExceptionMessageWhenMessageHandlerIsReset) {
6606 DebugLocalContext env;
6609 ChangeBreakOnException(
false,
true);
6611 exception_event_count = 0;
6612 const char* script =
"function f() {throw new Error()};";
6625 CheckDebuggerUnloaded();
6627 CHECK_EQ(1, exception_event_count);
6633 TEST(ProvisionalBreakpointOnLineOutOfRange) {
6635 DebugLocalContext env;
6637 const char* script =
"function f() {};";
6638 const char* resource_name =
"test_resource";
6642 int sbp1 = SetScriptBreakPointByNameFromJS(resource_name, 3,
6644 int sbp2 = SetScriptBreakPointByNameFromJS(resource_name, 5, 5);
6646 after_compile_message_count = 0;
6660 CHECK_EQ(1, after_compile_message_count);
6662 ClearBreakPointFromJS(sbp1);
6663 ClearBreakPointFromJS(sbp2);
6672 break_point_hit_count++;
6677 SendContinueCommand();
6681 bool is_debug_break = isolate->
stack_guard()->IsDebugBreak();
6689 if (is_debug_break) {
6700 TEST(NoDebugBreakInAfterCompileMessageHandler) {
6702 DebugLocalContext env;
6711 const char* src =
"function f() { eval('var x = 10;'); } ";
6715 CHECK_EQ(1, break_point_hit_count);
6721 CHECK_EQ(2, break_point_hit_count);
6725 CheckDebuggerUnloaded();
6729 static int counting_message_handler_counter;
6732 counting_message_handler_counter++;
6736 TEST(ProcessDebugMessages) {
6738 DebugLocalContext env;
6740 counting_message_handler_counter = 0;
6744 const int kBufferSize = 1000;
6746 const char* scripts_command =
6748 "\"type\":\"request\","
6749 "\"command\":\"scripts\"}";
6754 CHECK_EQ(0, counting_message_handler_counter);
6757 CHECK_GE(counting_message_handler_counter, 1);
6759 counting_message_handler_counter = 0;
6763 CHECK_EQ(0, counting_message_handler_counter);
6766 CHECK_GE(counting_message_handler_counter, 2);
6770 CheckDebuggerUnloaded();
6774 struct BacktraceData {
6775 static int frame_counter;
6777 char print_buffer[1000];
6779 Utf16ToAscii(*json, json.length(), print_buffer, 1000);
6781 if (strstr(print_buffer,
"backtrace") ==
NULL) {
6784 frame_counter = GetTotalFramesInt(print_buffer);
6788 int BacktraceData::frame_counter;
6794 DebugLocalContext env;
6798 const int kBufferSize = 1000;
6800 const char* scripts_command =
6802 "\"type\":\"request\","
6803 "\"command\":\"backtrace\"}";
6806 BacktraceData::frame_counter = -10;
6809 CHECK_EQ(BacktraceData::frame_counter, 0);
6815 BacktraceData::frame_counter = -10;
6818 CHECK_EQ(BacktraceData::frame_counter, 1);
6822 CheckDebuggerUnloaded();
6828 DebugLocalContext env;
6833 "function runTest(mirror) {"
6834 " return mirror.isString() && (mirror.length() == 5);"
6837 "runTest;"))->Run());
6844 TEST(DebugBreakFunctionApply) {
6846 DebugLocalContext env;
6851 "function baz(x) { }"
6852 "function bar(x) { baz(); }"
6853 "function foo(){ bar.apply(this, [1]); }",
6864 break_point_hit_count = 0;
6865 max_break_point_hit_count = 10000;
6869 CHECK_GT(break_point_hit_count, 1);
6872 CheckDebuggerUnloaded();
6887 CHECK(current == debugee_context);
6888 CHECK(current != debugger_context);
6890 CHECK(calling == debugee_context);
6891 CHECK(calling != debugger_context);
6899 static void DebugEventGetAtgumentPropertyValue(
6905 break_point_hit_count++;
6908 "(function(exec_state) {\n"
6909 " return (exec_state.frame(0).argumentValue(0).property('a').\n"
6910 " value().value() == 1);\n"
6920 TEST(CallingContextIsNotDebugContext) {
6921 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug();
6924 DebugLocalContext env;
6935 NamedGetterWithCallingContextCheck);
6937 named->NewInstance());
6945 "function bar(x) { debugger; }"
6946 "function foo(){ bar(obj); }",
6949 break_point_hit_count = 0;
6951 CHECK_EQ(1, break_point_hit_count);
6956 CheckDebuggerUnloaded();
6960 TEST(DebugContextIsPreservedBetweenAccesses) {
6975 TEST(DebugEventContext) {
6979 expected_callback_data);
6984 expected_context.
Clear();
6987 CheckDebuggerUnloaded();
6991 static void* expected_break_data;
6992 static bool was_debug_break_called;
6993 static bool was_debug_event_called;
6997 was_debug_event_called =
true;
6999 was_debug_break_called =
true;
7005 TEST(DebugEventBreakData) {
7007 DebugLocalContext env;
7010 TestClientData::constructor_call_counter = 0;
7011 TestClientData::destructor_call_counter = 0;
7013 expected_break_data =
NULL;
7014 was_debug_event_called =
false;
7015 was_debug_break_called =
false;
7018 CHECK(was_debug_event_called);
7019 CHECK(!was_debug_break_called);
7021 TestClientData* data1 =
new TestClientData();
7022 expected_break_data = data1;
7023 was_debug_event_called =
false;
7024 was_debug_break_called =
false;
7027 CHECK(was_debug_event_called);
7028 CHECK(!was_debug_break_called);
7030 expected_break_data =
NULL;
7031 was_debug_event_called =
false;
7032 was_debug_break_called =
false;
7035 CHECK(!was_debug_event_called);
7036 CHECK(was_debug_break_called);
7038 TestClientData* data2 =
new TestClientData();
7039 expected_break_data = data2;
7040 was_debug_event_called =
false;
7041 was_debug_break_called =
false;
7045 CHECK(was_debug_event_called);
7046 CHECK(was_debug_break_called);
7048 CHECK_EQ(2, TestClientData::constructor_call_counter);
7049 CHECK_EQ(TestClientData::constructor_call_counter,
7050 TestClientData::destructor_call_counter);
7053 CheckDebuggerUnloaded();
7056 static bool debug_event_break_deoptimize_done =
false;
7063 if (!frame_function_name.
IsEmpty()) {
7068 frame_function_name->
Call(exec_state, argc, argv);
7073 function_name->WriteAscii(fn);
7074 if (strcmp(fn,
"bar") == 0) {
7076 debug_event_break_deoptimize_done =
true;
7088 TEST(DeoptimizeDuringDebugBreak) {
7090 DebugLocalContext env;
7094 frame_function_name = CompileFunction(&env,
7095 frame_function_name_source,
7096 "frame_function_name");
7114 CHECK(debug_event_break_deoptimize_done);
7120 static void DebugEventBreakWithOptimizedStack(
v8::DebugEvent event,
7125 if (!frame_function_name.
IsEmpty()) {
7126 for (
int i = 0; i < 2; i++) {
7131 frame_function_name->
Call(exec_state, argc, argv);
7136 result = frame_argument_name->
Call(exec_state, argc, argv);
7137 CHECK(result->IsString());
7146 result = frame_argument_value->
Call(exec_state, argc, argv);
7147 CHECK(result->IsUndefined() || (result->Int32Value() == 1 - i));
7149 result = frame_local_name->
Call(exec_state, argc, argv);
7150 CHECK(result->IsString());
7159 result = frame_local_value->
Call(exec_state, argc, argv);
7160 CHECK(result->IsUndefined() || (result->Int32Value() == 42));
7175 TEST(DebugBreakStackInspection) {
7177 DebugLocalContext env;
7179 frame_function_name =
7180 CompileFunction(&env, frame_function_name_source,
"frame_function_name");
7181 frame_argument_name =
7182 CompileFunction(&env, frame_argument_name_source,
"frame_argument_name");
7183 frame_argument_value = CompileFunction(&env,
7184 frame_argument_value_source,
7185 "frame_argument_value");
7187 CompileFunction(&env, frame_local_name_source,
"frame_local_name");
7189 CompileFunction(&env, frame_local_value_source,
"frame_local_value");
7195 env->Global()->Set(v8_str(
"scheduleBreak"), schedule_break);
7198 "function loop(count) {"
7200 " if (count < 1) { scheduleBreak(); loop(count + 1); }"
7208 static void TestDebugBreakInLoop(
const char* loop_head,
7209 const char** loop_bodies,
7210 const char* loop_tail) {
7212 static const int kBreaksPerTest = 100;
7214 for (
int i = 0; loop_bodies[i] !=
NULL; i++) {
7217 for (
int j = 0; j < 11; j++) {
7218 break_point_hit_count_deoptimize = j;
7220 break_point_hit_count_deoptimize = kBreaksPerTest;
7223 break_point_hit_count = 0;
7224 max_break_point_hit_count = kBreaksPerTest;
7225 terminate_after_max_break_point_hit =
true;
7227 EmbeddedVector<char, 1024> buffer;
7228 OS::SNPrintF(buffer,
7229 "function f() {%s%s%s}",
7230 loop_head, loop_bodies[i], loop_tail);
7233 CompileRun(buffer.start());
7240 CHECK_EQ(kBreaksPerTest, break_point_hit_count);
7248 TEST(DebugBreakLoop) {
7250 DebugLocalContext env;
7256 frame_count = CompileFunction(&env, frame_count_source,
"frame_count");
7258 CompileRun(
"var a = 1;");
7259 CompileRun(
"function g() { }");
7260 CompileRun(
"function h() { }");
7262 const char* loop_bodies[] = {
7265 "if (a == 0) { g() }",
7266 "if (a == 1) { g() }",
7267 "if (a == 0) { g() } else { h() }",
7268 "if (a == 0) { continue }",
7269 "if (a == 1) { continue }",
7270 "switch (a) { case 1: g(); }",
7271 "switch (a) { case 1: continue; }",
7272 "switch (a) { case 1: g(); break; default: h() }",
7273 "switch (a) { case 1: continue; break; default: h() }",
7277 TestDebugBreakInLoop(
"while (true) {", loop_bodies,
"}");
7278 TestDebugBreakInLoop(
"while (a == 1) {", loop_bodies,
"}");
7280 TestDebugBreakInLoop(
"do {", loop_bodies,
"} while (true)");
7281 TestDebugBreakInLoop(
"do {", loop_bodies,
"} while (a == 1)");
7283 TestDebugBreakInLoop(
"for (;;) {", loop_bodies,
"}");
7284 TestDebugBreakInLoop(
"for (;a == 1;) {", loop_bodies,
"}");
7288 CheckDebuggerUnloaded();
7300 int expected_frame_count = 4;
7301 int expected_line_number[] = {1, 4, 7, 12};
7307 int break_id = v8::internal::Isolate::Current()->debug()->break_id();
7310 OS::SNPrintF(script_vector,
"%%GetFrameCount(%d)", break_id);
7314 CHECK_EQ(expected_frame_count, frame_count);
7316 for (
int i = 0; i < frame_count; i++) {
7319 OS::SNPrintF(script_vector,
"%%GetFrameDetails(%d, %d)[5]", break_id, i);
7329 TEST(DebugBreakInline) {
7330 i::FLAG_allow_natives_syntax =
true;
7332 DebugLocalContext env;
7333 const char* source =
7334 "function debug(b) { \n"
7335 " if (b) debugger; \n"
7337 "function f(b) { \n"
7340 "function g(b) { \n"
7345 "%OptimizeFunctionOnNextCall(g); \n"
7349 inline_script->
Run();
7353 #endif // ENABLE_DEBUGGER_SUPPORT
static Local< Context > GetCurrent()
virtual DebugEvent GetEvent() const =0
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
virtual bool WillStartRunning() const =0
#define CHECK_EQ(expected, value)
V8EXPORT bool IsTrue() const
static bool IsExecutionTerminating(Isolate *isolate=NULL)
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
Handle< Boolean > V8EXPORT True()
Local< Value > Exception() const
V8EXPORT bool StrictEquals(Handle< Value > that) const
V8EXPORT Local< Value > Get(Handle< Value > key)
static Smi * FromInt(int value)
void V8EXPORT RegisterExtension(Extension *extension)
Local< Object > NewInstance()
value format" "after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false, "print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false, "print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false, "report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true, "garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true, "flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true, "use incremental marking") DEFINE_bool(incremental_marking_steps, true, "do incremental marking steps") DEFINE_bool(trace_incremental_marking, false, "trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true, "Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false, "Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true, "use inline caching") DEFINE_bool(native_code_counters, false, "generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false, "Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true, "Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false, "Never perform compaction on full GC-testing only") DEFINE_bool(compact_code_space, true, "Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true, "Flush inline caches prior to mark compact collection and" "flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0, "Default seed for initializing random generator" "(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true, "allows verbose printing") DEFINE_bool(allow_natives_syntax, false, "allow natives syntax") DEFINE_bool(trace_sim, false, "Trace simulator execution") DEFINE_bool(check_icache, false, "Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0, "Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8, "Stack alingment in bytes in simulator(4 or 8, 8 is default)") DEFINE_bool(trace_exception, false, "print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false, "preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true, "randomize hashes to avoid predictable hash collisions" "(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0, "Fixed seed to use to hash property keys(0 means random)" "(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false, "activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true, "generate optimized regexp code") DEFINE_bool(testing_bool_flag, true, "testing_bool_flag") DEFINE_int(testing_int_flag, 13, "testing_int_flag") DEFINE_float(testing_float_flag, 2.5, "float-flag") DEFINE_string(testing_string_flag, "Hello, world!", "string-flag") DEFINE_int(testing_prng_seed, 42, "Seed used for threading test randomness") DEFINE_string(testing_serialization_file, "/tmp/serdes", "file in which to serialize heap") DEFINE_bool(help, false, "Print usage message, including flags, on console") DEFINE_bool(dump_counters, false, "Dump counters on exit") DEFINE_string(map_counters, "", "Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT, "Pass all remaining arguments to the script.Alias for\"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#43"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2#define FLAG_MODE_DEFINE_DEFAULTS#1"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flag-definitions.h"1#define FLAG_FULL(ftype, ctype, nam, def, cmt)#define FLAG_READONLY(ftype, ctype, nam, def, cmt)#define DEFINE_implication(whenflag, thenflag)#define DEFINE_bool(nam, def, cmt)#define DEFINE_int(nam, def, cmt)#define DEFINE_float(nam, def, cmt)#define DEFINE_string(nam, def, cmt)#define DEFINE_args(nam, def, cmt)#define FLAG DEFINE_bool(use_strict, false,"enforce strict mode") DEFINE_bool(es5_readonly, false,"activate correct semantics for inheriting readonliness") DEFINE_bool(es52_globals, false,"activate new semantics for global var declarations") DEFINE_bool(harmony_typeof, false,"enable harmony semantics for typeof") DEFINE_bool(harmony_scoping, false,"enable harmony block scoping") DEFINE_bool(harmony_modules, false,"enable harmony modules (implies block scoping)") DEFINE_bool(harmony_proxies, false,"enable harmony proxies") DEFINE_bool(harmony_collections, false,"enable harmony collections (sets, maps, and weak maps)") DEFINE_bool(harmony, false,"enable all harmony features (except typeof)") DEFINE_implication(harmony, harmony_scoping) DEFINE_implication(harmony, harmony_modules) DEFINE_implication(harmony, harmony_proxies) DEFINE_implication(harmony, harmony_collections) DEFINE_implication(harmony_modules, harmony_scoping) DEFINE_bool(packed_arrays, false,"optimizes arrays that have no holes") DEFINE_bool(smi_only_arrays, true,"tracks arrays with only smi values") DEFINE_bool(clever_optimizations, true,"Optimize object size, Array shift, DOM strings and string +") DEFINE_bool(unbox_double_arrays, true,"automatically unbox arrays of doubles") DEFINE_bool(string_slices, true,"use string slices") DEFINE_bool(crankshaft, true,"use crankshaft") DEFINE_string(hydrogen_filter,"","optimization filter") DEFINE_bool(use_range, true,"use hydrogen range analysis") DEFINE_bool(eliminate_dead_phis, true,"eliminate dead phis") DEFINE_bool(use_gvn, true,"use hydrogen global value numbering") DEFINE_bool(use_canonicalizing, true,"use hydrogen instruction canonicalizing") DEFINE_bool(use_inlining, true,"use function inlining") DEFINE_int(max_inlined_source_size, 600,"maximum source size in bytes considered for a single inlining") DEFINE_int(max_inlined_nodes, 196,"maximum number of AST nodes considered for a single inlining") DEFINE_int(max_inlined_nodes_cumulative, 196,"maximum cumulative number of AST nodes considered for inlining") DEFINE_bool(loop_invariant_code_motion, true,"loop invariant code motion") DEFINE_bool(collect_megamorphic_maps_from_stub_cache, true,"crankshaft harvests type feedback from stub cache") DEFINE_bool(hydrogen_stats, false,"print statistics for hydrogen") DEFINE_bool(trace_hydrogen, false,"trace generated hydrogen to file") DEFINE_string(trace_phase,"Z","trace generated IR for specified phases") DEFINE_bool(trace_inlining, false,"trace inlining decisions") DEFINE_bool(trace_alloc, false,"trace register allocator") DEFINE_bool(trace_all_uses, false,"trace all use positions") DEFINE_bool(trace_range, false,"trace range analysis") DEFINE_bool(trace_gvn, false,"trace global value numbering") DEFINE_bool(trace_representation, false,"trace representation types") DEFINE_bool(stress_pointer_maps, false,"pointer map for every instruction") DEFINE_bool(stress_environments, false,"environment for every instruction") DEFINE_int(deopt_every_n_times, 0,"deoptimize every n times a deopt point is passed") DEFINE_bool(trap_on_deopt, false,"put a break point before deoptimizing") DEFINE_bool(deoptimize_uncommon_cases, true,"deoptimize uncommon cases") DEFINE_bool(polymorphic_inlining, true,"polymorphic inlining") DEFINE_bool(use_osr, true,"use on-stack replacement") DEFINE_bool(array_bounds_checks_elimination, false,"perform array bounds checks elimination") DEFINE_bool(array_index_dehoisting, false,"perform array index dehoisting") DEFINE_bool(trace_osr, false,"trace on-stack replacement") DEFINE_int(stress_runs, 0,"number of stress runs") DEFINE_bool(optimize_closures, true,"optimize closures") DEFINE_bool(inline_construct, true,"inline constructor calls") DEFINE_bool(inline_arguments, true,"inline functions with arguments object") DEFINE_int(loop_weight, 1,"loop weight for representation inference") DEFINE_bool(optimize_for_in, true,"optimize functions containing for-in loops") DEFINE_bool(experimental_profiler, true,"enable all profiler experiments") DEFINE_bool(watch_ic_patching, false,"profiler considers IC stability") DEFINE_int(frame_count, 1,"number of stack frames inspected by the profiler") DEFINE_bool(self_optimization, false,"primitive functions trigger their own optimization") DEFINE_bool(direct_self_opt, false,"call recompile stub directly when self-optimizing") DEFINE_bool(retry_self_opt, false,"re-try self-optimization if it failed") DEFINE_bool(count_based_interrupts, false,"trigger profiler ticks based on counting instead of timing") DEFINE_bool(interrupt_at_exit, false,"insert an interrupt check at function exit") DEFINE_bool(weighted_back_edges, false,"weight back edges by jump distance for interrupt triggering") DEFINE_int(interrupt_budget, 5900,"execution budget before interrupt is triggered") DEFINE_int(type_info_threshold, 15,"percentage of ICs that must have type info to allow optimization") DEFINE_int(self_opt_count, 130,"call count before self-optimization") DEFINE_implication(experimental_profiler, watch_ic_patching) DEFINE_implication(experimental_profiler, self_optimization) DEFINE_implication(experimental_profiler, retry_self_opt) DEFINE_implication(experimental_profiler, count_based_interrupts) DEFINE_implication(experimental_profiler, interrupt_at_exit) DEFINE_implication(experimental_profiler, weighted_back_edges) DEFINE_bool(trace_opt_verbose, false,"extra verbose compilation tracing") DEFINE_implication(trace_opt_verbose, trace_opt) DEFINE_bool(debug_code, false,"generate extra code (assertions) for debugging") DEFINE_bool(code_comments, false,"emit comments in code disassembly") DEFINE_bool(enable_sse2, true,"enable use of SSE2 instructions if available") DEFINE_bool(enable_sse3, true,"enable use of SSE3 instructions if available") DEFINE_bool(enable_sse4_1, true,"enable use of SSE4.1 instructions if available") DEFINE_bool(enable_cmov, true,"enable use of CMOV instruction if available") DEFINE_bool(enable_rdtsc, true,"enable use of RDTSC instruction if available") DEFINE_bool(enable_sahf, true,"enable use of SAHF instruction if available (X64 only)") DEFINE_bool(enable_vfp3, true,"enable use of VFP3 instructions if available - this implies ""enabling ARMv7 instructions (ARM only)") DEFINE_bool(enable_armv7, true,"enable use of ARMv7 instructions if available (ARM only)") DEFINE_bool(enable_fpu, true,"enable use of MIPS FPU instructions if available (MIPS only)") DEFINE_string(expose_natives_as, NULL,"expose natives in global object") DEFINE_string(expose_debug_as, NULL,"expose debug in global object") DEFINE_bool(expose_gc, false,"expose gc extension") DEFINE_bool(expose_externalize_string, false,"expose externalize string extension") DEFINE_int(stack_trace_limit, 10,"number of stack frames to capture") DEFINE_bool(builtins_in_stack_traces, false,"show built-in functions in stack traces") DEFINE_bool(disable_native_files, false,"disable builtin natives files") DEFINE_bool(inline_new, true,"use fast inline allocation") DEFINE_bool(stack_trace_on_abort, true,"print a stack trace if an assertion failure occurs") DEFINE_bool(trace, false,"trace function calls") DEFINE_bool(mask_constants_with_cookie, true,"use random jit cookie to mask large constants") DEFINE_bool(lazy, true,"use lazy compilation") DEFINE_bool(trace_opt, false,"trace lazy optimization") DEFINE_bool(trace_opt_stats, false,"trace lazy optimization statistics") DEFINE_bool(opt, true,"use adaptive optimizations") DEFINE_bool(always_opt, false,"always try to optimize functions") DEFINE_bool(prepare_always_opt, false,"prepare for turning on always opt") DEFINE_bool(trace_deopt, false,"trace deoptimization") DEFINE_int(min_preparse_length, 1024,"minimum length for automatic enable preparsing") DEFINE_bool(always_full_compiler, false,"try to use the dedicated run-once backend for all code") DEFINE_bool(trace_bailout, false,"print reasons for falling back to using the classic V8 backend") DEFINE_bool(compilation_cache, true,"enable compilation cache") DEFINE_bool(cache_prototype_transitions, true,"cache prototype transitions") DEFINE_bool(trace_debug_json, false,"trace debugging JSON request/response") DEFINE_bool(debugger_auto_break, true,"automatically set the debug break flag when debugger commands are ""in the queue") DEFINE_bool(enable_liveedit, true,"enable liveedit experimental feature") DEFINE_bool(break_on_abort, true,"always cause a debug break before aborting") DEFINE_int(stack_size, kPointerSize *123,"default size of stack region v8 is allowed to use (in kBytes)") DEFINE_int(max_stack_trace_source_length, 300,"maximum length of function source code printed in a stack trace.") DEFINE_bool(always_inline_smi_code, false,"always inline smi code in non-opt code") DEFINE_int(max_new_space_size, 0,"max size of the new generation (in kBytes)") DEFINE_int(max_old_space_size, 0,"max size of the old generation (in Mbytes)") DEFINE_int(max_executable_size, 0,"max size of executable memory (in Mbytes)") DEFINE_bool(gc_global, false,"always perform global GCs") DEFINE_int(gc_interval,-1,"garbage collect after <n> allocations") DEFINE_bool(trace_gc, false,"print one trace line following each garbage collection") DEFINE_bool(trace_gc_nvp, false,"print one detailed trace line in name=value format ""after each garbage collection") DEFINE_bool(print_cumulative_gc_stat, false,"print cumulative GC statistics in name=value format on exit") DEFINE_bool(trace_gc_verbose, false,"print more details following each garbage collection") DEFINE_bool(trace_fragmentation, false,"report fragmentation for old pointer and data pages") DEFINE_bool(collect_maps, true,"garbage collect maps from which no objects can be reached") DEFINE_bool(flush_code, true,"flush code that we expect not to use again before full gc") DEFINE_bool(incremental_marking, true,"use incremental marking") DEFINE_bool(incremental_marking_steps, true,"do incremental marking steps") DEFINE_bool(trace_incremental_marking, false,"trace progress of the incremental marking") DEFINE_bool(use_idle_notification, true,"Use idle notification to reduce memory footprint.") DEFINE_bool(send_idle_notification, false,"Send idle notifcation between stress runs.") DEFINE_bool(use_ic, true,"use inline caching") DEFINE_bool(native_code_counters, false,"generate extra code for manipulating stats counters") DEFINE_bool(always_compact, false,"Perform compaction on every full GC") DEFINE_bool(lazy_sweeping, true,"Use lazy sweeping for old pointer and data spaces") DEFINE_bool(never_compact, false,"Never perform compaction on full GC - testing only") DEFINE_bool(compact_code_space, true,"Compact code space on full non-incremental collections") DEFINE_bool(cleanup_code_caches_at_gc, true,"Flush inline caches prior to mark compact collection and ""flush code caches in maps during mark compact cycle.") DEFINE_int(random_seed, 0,"Default seed for initializing random generator ""(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer, true,"allows verbose printing") DEFINE_bool(allow_natives_syntax, false,"allow natives syntax") DEFINE_bool(trace_sim, false,"Trace simulator execution") DEFINE_bool(check_icache, false,"Check icache flushes in ARM and MIPS simulator") DEFINE_int(stop_sim_at, 0,"Simulator stop after x number of instructions") DEFINE_int(sim_stack_alignment, 8,"Stack alingment in bytes in simulator (4 or 8, 8 is default)") DEFINE_bool(trace_exception, false,"print stack trace when throwing exceptions") DEFINE_bool(preallocate_message_memory, false,"preallocate some memory to build stack traces.") DEFINE_bool(randomize_hashes, true,"randomize hashes to avoid predictable hash collisions ""(with snapshots this option cannot override the baked-in seed)") DEFINE_int(hash_seed, 0,"Fixed seed to use to hash property keys (0 means random)""(with snapshots this option cannot override the baked-in seed)") DEFINE_bool(preemption, false,"activate a 100ms timer that switches between V8 threads") DEFINE_bool(regexp_optimization, true,"generate optimized regexp code") DEFINE_bool(testing_bool_flag, true,"testing_bool_flag") DEFINE_int(testing_int_flag, 13,"testing_int_flag") DEFINE_float(testing_float_flag, 2.5,"float-flag") DEFINE_string(testing_string_flag,"Hello, world!","string-flag") DEFINE_int(testing_prng_seed, 42,"Seed used for threading test randomness") DEFINE_string(testing_serialization_file,"/tmp/serdes","file in which to serialize heap") DEFINE_bool(help, false,"Print usage message, including flags, on console") DEFINE_bool(dump_counters, false,"Dump counters on exit") DEFINE_string(map_counters,"","Map counters to a file") DEFINE_args(js_arguments, JSARGUMENTS_INIT,"Pass all remaining arguments to the script. Alias for \"--\".") DEFINE_bool(debug_compile_events, true,"Enable debugger compile events") DEFINE_bool(debug_script_collected_events, true,"Enable debugger script collected events") DEFINE_bool(gdbjit, false,"enable GDBJIT interface (disables compacting GC)") DEFINE_bool(gdbjit_full, false,"enable GDBJIT interface for all code objects") DEFINE_bool(gdbjit_dump, false,"dump elf objects with debug info to disk") DEFINE_string(gdbjit_dump_filter,"","dump only objects containing this substring") DEFINE_bool(force_marking_deque_overflows, false,"force overflows of marking deque by reducing it's size ""to 64 words") DEFINE_bool(stress_compaction, false,"stress the GC compactor to flush out bugs (implies ""--force_marking_deque_overflows)")#define FLAG DEFINE_bool(enable_slow_asserts, false,"enable asserts that are slow to execute") DEFINE_bool(trace_codegen, false,"print name of functions for which code is generated") DEFINE_bool(print_source, false,"pretty print source code") DEFINE_bool(print_builtin_source, false,"pretty print source code for builtins") DEFINE_bool(print_ast, false,"print source AST") DEFINE_bool(print_builtin_ast, false,"print source AST for builtins") DEFINE_string(stop_at,"","function name where to insert a breakpoint") DEFINE_bool(print_builtin_scopes, false,"print scopes for builtins") DEFINE_bool(print_scopes, false,"print scopes") DEFINE_bool(trace_contexts, false,"trace contexts operations") DEFINE_bool(gc_greedy, false,"perform GC prior to some allocations") DEFINE_bool(gc_verbose, false,"print stuff during garbage collection") DEFINE_bool(heap_stats, false,"report heap statistics before and after GC") DEFINE_bool(code_stats, false,"report code statistics after GC") DEFINE_bool(verify_heap, false,"verify heap pointers before and after GC") DEFINE_bool(print_handles, false,"report handles after GC") DEFINE_bool(print_global_handles, false,"report global handles after GC") DEFINE_bool(trace_ic, false,"trace inline cache state transitions") DEFINE_bool(print_interfaces, false,"print interfaces") DEFINE_bool(print_interface_details, false,"print interface inference details") DEFINE_int(print_interface_depth, 5,"depth for printing interfaces") DEFINE_bool(trace_normalization, false,"prints when objects are turned into dictionaries.") DEFINE_bool(trace_lazy, false,"trace lazy compilation") DEFINE_bool(collect_heap_spill_statistics, false,"report heap spill statistics along with heap_stats ""(requires heap_stats)") DEFINE_bool(trace_isolates, false,"trace isolate state changes") DEFINE_bool(log_state_changes, false,"Log state changes.") DEFINE_bool(regexp_possessive_quantifier, false,"enable possessive quantifier syntax for testing") DEFINE_bool(trace_regexp_bytecodes, false,"trace regexp bytecode execution") DEFINE_bool(trace_regexp_assembler, false,"trace regexp macro assembler calls.")#define FLAG DEFINE_bool(log, false,"Minimal logging (no API, code, GC, suspect, or handles samples).") DEFINE_bool(log_all, false,"Log all events to the log file.") DEFINE_bool(log_runtime, false,"Activate runtime system %Log call.") DEFINE_bool(log_api, false,"Log API events to the log file.") DEFINE_bool(log_code, false,"Log code events to the log file without profiling.") DEFINE_bool(log_gc, false,"Log heap samples on garbage collection for the hp2ps tool.") DEFINE_bool(log_handles, false,"Log global handle events.") DEFINE_bool(log_snapshot_positions, false,"log positions of (de)serialized objects in the snapshot.") DEFINE_bool(log_suspect, false,"Log suspect operations.") DEFINE_bool(prof, false,"Log statistical profiling information (implies --log-code).") DEFINE_bool(prof_auto, true,"Used with --prof, starts profiling automatically") DEFINE_bool(prof_lazy, false,"Used with --prof, only does sampling and logging"" when profiler is active (implies --noprof_auto).") DEFINE_bool(prof_browser_mode, true,"Used with --prof, turns on browser-compatible mode for profiling.") DEFINE_bool(log_regexp, false,"Log regular expression execution.") DEFINE_bool(sliding_state_window, false,"Update sliding state window counters.") DEFINE_string(logfile,"v8.log","Specify the name of the log file.") DEFINE_bool(ll_prof, false,"Enable low-level linux profiler.")#define FLAG DEFINE_bool(trace_elements_transitions, false,"trace elements transitions") DEFINE_bool(print_code_stubs, false,"print code stubs") DEFINE_bool(test_secondary_stub_cache, false,"test secondary stub cache by disabling the primary one") DEFINE_bool(test_primary_stub_cache, false,"test primary stub cache by disabling the secondary one") DEFINE_bool(print_code, false,"print generated code") DEFINE_bool(print_opt_code, false,"print optimized code") DEFINE_bool(print_unopt_code, false,"print unoptimized code before ""printing optimized code based on it") DEFINE_bool(print_code_verbose, false,"print more information for code") DEFINE_bool(print_builtin_code, false,"print generated code for builtins")#47"/Users/thlorenz/dev/dx/v8-perf/build/v8/src/flags.cc"2 namespace{struct Flag{enum FlagType{TYPE_BOOL, TYPE_INT, TYPE_FLOAT, TYPE_STRING, TYPE_ARGS} name
static V8EXPORT Local< String > New(const char *data, int length=-1)
void SetData(Handle< String > data)
virtual bool Shutdown()=0
static ExternalTwoByteString * cast(Object *obj)
Local< ObjectTemplate > InstanceTemplate()
virtual Handle< Value > GetCallbackData() const =0
static Local< Context > GetDebugContext()
static Handle< T > Cast(Handle< S > that)
virtual int Receive(char *data, int len) const =0
void SetIndexedPropertyHandler(IndexedPropertyGetter getter, IndexedPropertySetter setter=0, IndexedPropertyQuery query=0, IndexedPropertyDeleter deleter=0, IndexedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
virtual DebugEvent GetEvent() const =0
V8EXPORT Local< Value > Call(Handle< Object > recv, int argc, Handle< Value > argv[])
static Script * cast(Object *obj)
static void DeoptimizeAll()
V8EXPORT Local< String > ToString() const
virtual bool IsEvent() const =0
virtual ClientData * GetClientData() const =0
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
static Function * Cast(Value *obj)
virtual int Send(const char *data, int len) const =0
virtual const uint16_t * data() const =0
StackGuard * stack_guard()
static void DebugBreakForCommand(ClientData *data=NULL, Isolate *isolate=NULL)
static Local< Script > New(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
void V8_Fatal(const char *file, int line, const char *format,...)
static bool SetDebugEventListener(EventCallback that, Handle< Value > data=Handle< Value >())
virtual size_t length() const =0
static bool AddMessageListener(MessageCallback that, Handle< Value > data=Handle< Value >())
double StringToInt(UnicodeCache *unicode_cache, String *str, int radix)
static Local< ObjectTemplate > New()
static void SetHostDispatchHandler(HostDispatchHandler handler, int period=100)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
static const int kNoGCFlags
void SetAccessor(Handle< String > name, AccessorGetter getter, AccessorSetter setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
Handle< Object > SetProperty(Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
static void TerminateExecution(int thread_id)
V8EXPORT int32_t Int32Value() const
static void RemoveMessageListeners(MessageCallback that)
V8EXPORT bool SetHiddenValue(Handle< String > key, Handle< Value > value)
static const int kMakeHeapIterableMask
virtual Handle< String > GetJSON() const =0
virtual bool Connect(const char *host, const char *port)=0
static Local< Context > GetCalling()
V8EXPORT bool IsFunction() const
#define CHECK_NE(unexpected, value)
static void SetMessageHandler(MessageHandler handler, bool message_handler_thread=false)
Handle< Boolean > V8EXPORT False()
void SetHiddenPrototype(bool value)
int StrLength(const char *string)
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
void SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter=0, NamedPropertyQuery query=0, NamedPropertyDeleter deleter=0, NamedPropertyEnumerator enumerator=0, Handle< Value > data=Handle< Value >())
static Local< T > Cast(Local< S > that)
static void SetMessageHandler2(MessageHandler2 handler)
int GetScriptLineNumber(Handle< Script > script, int code_pos)
static void SetDebugMessageDispatchHandler(DebugMessageDispatchHandler handler, bool provide_locker=false)
void Continue(InterruptFlag after_what)
V8EXPORT bool IsNumber() const
virtual ClientData * GetClientData() const =0
Local< Function > GetFunction()
static bool SetDebugEventListener2(EventCallback2 that, Handle< Value > data=Handle< Value >())
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
static V8EXPORT Local< Integer > New(int32_t value)
virtual bool Bind(const int port)=0
static Local< Value > Call(v8::Handle< v8::Function > fun, Handle< Value > data=Handle< Value >())
Handle< Primitive > V8EXPORT Undefined()
static V8EXPORT Local< Number > New(double value)
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
virtual Handle< Context > GetEventContext() const =0
virtual Handle< Context > GetEventContext() const =0
static void SendCommand(const uint16_t *command, int length, ClientData *client_data=NULL, Isolate *isolate=NULL)
static void DebugBreak(Isolate *isolate=NULL)
static V8EXPORT Local< String > NewExternal(ExternalStringResource *resource)
static Local< Value > GetMirror(v8::Handle< v8::Value > obj)
#define SMALL_STRING_BUFFER_SIZE
static void ProcessDebugMessages()
void CheckNonEqualsHelper(const char *file, int line, const char *unexpected_source, v8::Handle< v8::Value > unexpected, const char *value_source, v8::Handle< v8::Value > value)
void CheckEqualsHelper(const char *file, int line, const char *expected_source, v8::Handle< v8::Value > expected, const char *value_source, v8::Handle< v8::Value > value)
static V8EXPORT Local< Object > New()
static Socket * CreateSocket()
static v8::internal::Handle< v8::internal::TemplateInfo > OpenHandle(const Template *that)
V8EXPORT bool Set(Handle< Value > key, Handle< Value > value, PropertyAttribute attribs=None)
static JSFunction * cast(Object *obj)