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

Side by Side Diff: runtime/vm/debugger_api_impl_test.cc

Issue 9716004: Properly recognize closures when setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/debugger.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 EXPECT_NOT_ERROR(res); 147 EXPECT_NOT_ERROR(res);
148 for (int i = 0; i < trace_len; i++) { 148 for (int i = 0; i < trace_len; i++) {
149 Dart_ActivationFrame frame; 149 Dart_ActivationFrame frame;
150 res = Dart_GetActivationFrame(trace, i, &frame); 150 res = Dart_GetActivationFrame(trace, i, &frame);
151 EXPECT_NOT_ERROR(res); 151 EXPECT_NOT_ERROR(res);
152 PrintActivationFrame(frame); 152 PrintActivationFrame(frame);
153 } 153 }
154 } 154 }
155 155
156 156
157 static void VerifyStackTrace(Dart_StackTrace trace,
158 const char* func_names[],
159 int names_len) {
160 intptr_t trace_len;
161 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
162 Dart_Handle func_name;
163 EXPECT_NOT_ERROR(res);
164 for (int i = 0; i < trace_len; i++) {
165 Dart_ActivationFrame frame;
166 res = Dart_GetActivationFrame(trace, i, &frame);
167 EXPECT_NOT_ERROR(res);
168 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL);
169 EXPECT_NOT_ERROR(res);
170 EXPECT(Dart_IsString(func_name));
171 const char* func_name_chars;
172 Dart_StringToCString(func_name, &func_name_chars);
173 if (i < names_len) {
174 EXPECT_STREQ(func_name_chars, func_names[i]);
175 if (strcmp(func_name_chars, func_names[i]) != 0) {
176 OS::Print("Stack frame %d: expected function %s, but found %s\n",
177 i, func_names[i], func_name_chars);
178 }
179 }
180 }
181 }
182
183
157 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { 184 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) {
158 const char* expected_trace[] = {"A.foo", "main"}; 185 const char* expected_trace[] = {"A.foo", "main"};
159 const intptr_t expected_trace_length = 2; 186 const intptr_t expected_trace_length = 2;
160 breakpoint_hit = true; 187 breakpoint_hit = true;
161 breakpoint_hit_counter++; 188 breakpoint_hit_counter++;
162 intptr_t trace_len; 189 intptr_t trace_len;
163 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 190 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
164 EXPECT_NOT_ERROR(res); 191 EXPECT_NOT_ERROR(res);
165 EXPECT_EQ(expected_trace_length, trace_len); 192 EXPECT_EQ(expected_trace_length, trace_len);
166 for (int i = 0; i < trace_len; i++) { 193 for (int i = 0; i < trace_len; i++) {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 breakpoint_hit_counter = 0; 603 breakpoint_hit_counter = 0;
577 Dart_Handle retval = Invoke(lib, "main"); 604 Dart_Handle retval = Invoke(lib, "main");
578 EXPECT_NOT_ERROR(retval); 605 EXPECT_NOT_ERROR(retval);
579 int64_t int_value = 0; 606 int64_t int_value = 0;
580 Dart_IntegerToInt64(retval, &int_value); 607 Dart_IntegerToInt64(retval, &int_value);
581 EXPECT_EQ(442, int_value); 608 EXPECT_EQ(442, int_value);
582 EXPECT_EQ(2, breakpoint_hit_counter); 609 EXPECT_EQ(2, breakpoint_hit_counter);
583 } 610 }
584 611
585 612
613 static void ExprClosureBreakpointHandler(Dart_Breakpoint bpt,
614 Dart_StackTrace trace) {
615 static const char* expected_trace[] = {"add", "main", ""};
616 breakpoint_hit_counter++;
617 PrintStackTrace(trace);
618 VerifyStackTrace(trace, expected_trace, 2);
619 }
620
621
622 TEST_CASE(Debug_ExprClosureBreakpoint) {
623 const char* kScriptChars =
624 "var c; \n"
625 " \n"
626 "main() { \n"
627 " c = add(a, b) { \n"
628 " return a + b; \n"
629 " }; \n"
630 " return c(10, 20); \n"
631 "} \n";
632
633 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
634 EXPECT(!Dart_IsError(lib));
635
636 Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler);
637
638 Dart_Handle script_url = Dart_NewString(TestCase::url());
639 Dart_Handle line_no = Dart_NewInteger(5); // In closure 'add'.
640 Dart_Breakpoint bpt;
641 Dart_Handle res = Dart_SetBreakpointAtLine(script_url, line_no, &bpt);
642 EXPECT_NOT_ERROR(res);
643
644 breakpoint_hit_counter = 0;
645 Dart_Handle retval = Invoke(lib, "main");
646 EXPECT_NOT_ERROR(retval);
647 int64_t int_value = 0;
648 Dart_IntegerToInt64(retval, &int_value);
649 EXPECT_EQ(30, int_value);
650 EXPECT_EQ(1, breakpoint_hit_counter);
651 }
652
653
586 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, 654 static void DeleteBreakpointHandler(Dart_Breakpoint bpt,
587 Dart_StackTrace trace) { 655 Dart_StackTrace trace) {
588 const char* expected_trace[] = {"foo", "main"}; 656 const char* expected_trace[] = {"foo", "main"};
589 const intptr_t expected_trace_length = 2; 657 const intptr_t expected_trace_length = 2;
590 breakpoint_hit_counter++; 658 breakpoint_hit_counter++;
591 intptr_t trace_len; 659 intptr_t trace_len;
592 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 660 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
593 EXPECT_NOT_ERROR(res); 661 EXPECT_NOT_ERROR(res);
594 EXPECT_EQ(expected_trace_length, trace_len); 662 EXPECT_EQ(expected_trace_length, trace_len);
595 for (int i = 0; i < trace_len; i++) { 663 for (int i = 0; i < trace_len; i++) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 EXPECT(Dart_IsString(source)); 911 EXPECT(Dart_IsString(source));
844 char const* source_chars; 912 char const* source_chars;
845 Dart_StringToCString(source, &source_chars); 913 Dart_StringToCString(source, &source_chars);
846 OS::Print("\n=== source: ===\n%s", source_chars); 914 OS::Print("\n=== source: ===\n%s", source_chars);
847 EXPECT_STREQ(kScriptChars, source_chars); 915 EXPECT_STREQ(kScriptChars, source_chars);
848 } 916 }
849 917
850 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 918 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
851 919
852 } // namespace dart 920 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698