OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 EXPECT_NOT_ERROR(res); | 168 EXPECT_NOT_ERROR(res); |
169 for (int i = 0; i < trace_len; i++) { | 169 for (int i = 0; i < trace_len; i++) { |
170 Dart_ActivationFrame frame; | 170 Dart_ActivationFrame frame; |
171 res = Dart_GetActivationFrame(trace, i, &frame); | 171 res = Dart_GetActivationFrame(trace, i, &frame); |
172 EXPECT_NOT_ERROR(res); | 172 EXPECT_NOT_ERROR(res); |
173 PrintActivationFrame(frame); | 173 PrintActivationFrame(frame); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 static void VerifyListEquals(Dart_Handle expected, Dart_Handle got) { | |
179 EXPECT(Dart_IsList(expected)); | |
180 EXPECT(Dart_IsList(got)); | |
181 Dart_Handle res; | |
182 intptr_t expected_length; | |
183 res = Dart_ListLength(expected, &expected_length); | |
184 EXPECT_NOT_ERROR(res); | |
185 intptr_t got_length; | |
186 res = Dart_ListLength(expected, &got_length); | |
187 EXPECT_NOT_ERROR(res); | |
188 EXPECT_EQ(expected_length, got_length); | |
189 for (intptr_t i = 0; i < expected_length; i++) { | |
190 Dart_Handle expected_elem = Dart_ListGetAt(expected, i); | |
191 EXPECT_NOT_ERROR(expected_elem); | |
192 Dart_Handle got_elem = Dart_ListGetAt(got, i); | |
193 EXPECT_NOT_ERROR(got_elem); | |
194 bool equals; | |
195 res = Dart_ObjectEquals(expected_elem, got_elem, &equals); | |
196 EXPECT_NOT_ERROR(res); | |
197 EXPECT(equals); | |
198 } | |
199 } | |
200 | |
201 | |
202 static void VerifyStackFrame(Dart_ActivationFrame frame, | |
203 const char* expected_name, | |
204 Dart_Handle expected_locals) { | |
205 Dart_Handle func_name; | |
206 Dart_Handle res; | |
207 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | |
208 EXPECT_NOT_ERROR(res); | |
209 EXPECT(Dart_IsString(func_name)); | |
210 const char* func_name_chars; | |
211 Dart_StringToCString(func_name, &func_name_chars); | |
212 if (expected_name != NULL) { | |
213 EXPECT_STREQ(func_name_chars, expected_name); | |
214 } | |
215 | |
216 if (!Dart_IsNull(expected_locals)) { | |
217 Dart_Handle locals = Dart_GetLocalVariables(frame); | |
218 EXPECT_NOT_ERROR(locals); | |
219 VerifyListEquals(expected_locals, locals); | |
220 } | |
221 } | |
222 | |
223 | |
178 static void VerifyStackTrace(Dart_StackTrace trace, | 224 static void VerifyStackTrace(Dart_StackTrace trace, |
179 const char* func_names[], | 225 const char* func_names[], |
180 int names_len) { | 226 Dart_Handle local_vars[], |
227 int expected_frames) { | |
181 intptr_t trace_len; | 228 intptr_t trace_len; |
182 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 229 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
183 Dart_Handle func_name; | |
184 EXPECT_NOT_ERROR(res); | 230 EXPECT_NOT_ERROR(res); |
185 for (int i = 0; i < trace_len; i++) { | 231 for (int i = 0; i < trace_len; i++) { |
186 Dart_ActivationFrame frame; | 232 Dart_ActivationFrame frame; |
187 res = Dart_GetActivationFrame(trace, i, &frame); | 233 res = Dart_GetActivationFrame(trace, i, &frame); |
188 EXPECT_NOT_ERROR(res); | 234 EXPECT_NOT_ERROR(res); |
189 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 235 if (i < expected_frames) { |
190 EXPECT_NOT_ERROR(res); | 236 VerifyStackFrame(frame, func_names[i], local_vars[i]); |
191 EXPECT(Dart_IsString(func_name)); | 237 } else { |
192 const char* func_name_chars; | 238 VerifyStackFrame(frame, NULL, Dart_Null()); |
193 Dart_StringToCString(func_name, &func_name_chars); | |
194 if (i < names_len) { | |
195 EXPECT_STREQ(func_name_chars, func_names[i]); | |
196 if (strcmp(func_name_chars, func_names[i]) != 0) { | |
197 OS::Print("Stack frame %d: expected function %s, but found %s\n", | |
198 i, func_names[i], func_name_chars); | |
199 } | |
200 } | 239 } |
201 } | 240 } |
202 } | 241 } |
203 | 242 |
204 | 243 |
205 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 244 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
206 const char* expected_trace[] = {"A.foo", "main"}; | 245 const char* expected_trace[] = {"A.foo", "main"}; |
207 const intptr_t expected_trace_length = 2; | 246 const intptr_t expected_trace_length = 2; |
208 breakpoint_hit = true; | 247 breakpoint_hit = true; |
209 breakpoint_hit_counter++; | 248 breakpoint_hit_counter++; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 EXPECT_NOT_ERROR(retval); | 617 EXPECT_NOT_ERROR(retval); |
579 int64_t int_value = 0; | 618 int64_t int_value = 0; |
580 Dart_IntegerToInt64(retval, &int_value); | 619 Dart_IntegerToInt64(retval, &int_value); |
581 EXPECT_EQ(442, int_value); | 620 EXPECT_EQ(442, int_value); |
582 EXPECT_EQ(2, breakpoint_hit_counter); | 621 EXPECT_EQ(2, breakpoint_hit_counter); |
583 } | 622 } |
584 | 623 |
585 | 624 |
586 static void ExprClosureBreakpointHandler(Dart_Breakpoint bpt, | 625 static void ExprClosureBreakpointHandler(Dart_Breakpoint bpt, |
587 Dart_StackTrace trace) { | 626 Dart_StackTrace trace) { |
588 static const char* expected_trace[] = {"add", "main", ""}; | 627 static const char* expected_trace[] = {"add", "main"}; |
628 Dart_Handle add_locals = Dart_NewList(4); | |
629 Dart_ListSetAt(add_locals, 0, Dart_NewString("a")); | |
630 Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10)); | |
631 Dart_ListSetAt(add_locals, 2, Dart_NewString("b")); | |
632 Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20)); | |
633 Dart_Handle expected_locals[] = {add_locals, Dart_Null()}; | |
589 breakpoint_hit_counter++; | 634 breakpoint_hit_counter++; |
590 PrintStackTrace(trace); | 635 PrintStackTrace(trace); |
591 VerifyStackTrace(trace, expected_trace, 2); | 636 VerifyStackTrace(trace, expected_trace, expected_locals, 2); |
592 } | 637 } |
593 | 638 |
594 | 639 |
595 TEST_CASE(Debug_ExprClosureBreakpoint) { | 640 TEST_CASE(Debug_ExprClosureBreakpoint) { |
596 const char* kScriptChars = | 641 const char* kScriptChars = |
597 "var c; \n" | 642 "var c; \n" |
598 " \n" | 643 " \n" |
599 "main() { \n" | 644 "main() { \n" |
600 " c = add(a, b) { \n" | 645 " c = add(a, b) { \n" |
601 " return a + b; \n" | 646 " return a + b; \n" |
(...skipping 11 matching lines...) Expand all Loading... | |
613 EXPECT(Dart_IsInteger(res)); | 658 EXPECT(Dart_IsInteger(res)); |
614 | 659 |
615 breakpoint_hit_counter = 0; | 660 breakpoint_hit_counter = 0; |
616 Dart_Handle retval = Invoke("main"); | 661 Dart_Handle retval = Invoke("main"); |
617 EXPECT_NOT_ERROR(retval); | 662 EXPECT_NOT_ERROR(retval); |
618 int64_t int_value = 0; | 663 int64_t int_value = 0; |
619 Dart_IntegerToInt64(retval, &int_value); | 664 Dart_IntegerToInt64(retval, &int_value); |
620 EXPECT_EQ(30, int_value); | 665 EXPECT_EQ(30, int_value); |
621 EXPECT_EQ(1, breakpoint_hit_counter); | 666 EXPECT_EQ(1, breakpoint_hit_counter); |
622 } | 667 } |
623 | 668 |
Ivan Posva
2012/07/02 21:10:38
?
| |
624 | |
625 static intptr_t bp_id_to_be_deleted; | 669 static intptr_t bp_id_to_be_deleted; |
626 | 670 |
627 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, | 671 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, |
628 Dart_StackTrace trace) { | 672 Dart_StackTrace trace) { |
629 const char* expected_trace[] = {"foo", "main"}; | 673 const char* expected_trace[] = {"foo", "main"}; |
630 const intptr_t expected_trace_length = 2; | 674 const intptr_t expected_trace_length = 2; |
631 breakpoint_hit_counter++; | 675 breakpoint_hit_counter++; |
632 intptr_t trace_len; | 676 intptr_t trace_len; |
633 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 677 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
634 EXPECT_NOT_ERROR(res); | 678 EXPECT_NOT_ERROR(res); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
997 list_as_string = Dart_ToString(lib_list); | 1041 list_as_string = Dart_ToString(lib_list); |
998 list_cstr = ""; | 1042 list_cstr = ""; |
999 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | 1043 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); |
1000 EXPECT_SUBSTRING(TestCase::url(), list_cstr); | 1044 EXPECT_SUBSTRING(TestCase::url(), list_cstr); |
1001 } | 1045 } |
1002 | 1046 |
1003 | 1047 |
1004 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1048 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1005 | 1049 |
1006 } // namespace dart | 1050 } // namespace dart |
OLD | NEW |