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

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

Issue 2869573002: Use latent breakpoints list when looking up or removing breakpoints. (Closed)
Patch Set: Created 3 years, 7 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
« runtime/vm/debugger.cc ('K') | « runtime/vm/debugger.cc ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/dart_api_impl.h" 5 #include "vm/dart_api_impl.h"
6 #include "vm/dart_api_message.h" 6 #include "vm/dart_api_message.h"
7 #include "vm/debugger.h" 7 #include "vm/debugger.h"
8 #include "vm/message.h" 8 #include "vm/message.h"
9 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 32 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1);
33 va_list args2; 33 va_list args2;
34 va_start(args2, fmt); 34 va_start(args2, fmt);
35 OS::VSNPrint(buffer, (len + 1), fmt, args2); 35 OS::VSNPrint(buffer, (len + 1), fmt, args2);
36 va_end(args2); 36 va_end(args2);
37 37
38 EXPECT_SUBSTRING(buffer, buff); 38 EXPECT_SUBSTRING(buffer, buff);
39 } 39 }
40 40
41 TEST_CASE(Debugger_GetBreakpointsById) {
42 const char* kScriptChars =
43 "main() {\n"
44 " var x = new StringBuffer();\n"
45 " x.add('won');\n"
46 " x.add('too');\n"
47 " return x.toString();\n"
48 "}\n";
49 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true);
50 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
51 EXPECT_VALID(lib);
52
53 Isolate* isolate = Isolate::Current();
54 Debugger* debugger = isolate->debugger();
55
56 // Test with one loaded breakpoint, one latent breakpoint.
57 Dart_Handle url = NewString(TestCase::url());
58 Dart_Handle result = Dart_SetBreakpoint(url, 2);
59 EXPECT_VALID(result);
60 EXPECT(Dart_IsInteger(result));
61 int64_t bp_id1 = 0;
62 EXPECT_VALID(Dart_IntegerToInt64(result, &bp_id1));
63
64 result = Dart_SetBreakpoint(NewString("not_yet_loaded_script_uri"), 4);
65 EXPECT_VALID(result);
66 EXPECT(Dart_IsInteger(result));
67 int64_t bp_id2 = 0;
68 EXPECT_VALID(Dart_IntegerToInt64(result, &bp_id2));
69
70 EXPECT(debugger->GetBreakpointById(bp_id1) != NULL);
71 EXPECT(debugger->GetBreakpointById(bp_id2) != NULL);
72 }
73
74 TEST_CASE(Debugger_RemoveBreakpoint) {
75 const char* kScriptChars =
76 "main() {\n"
77 " var x = new StringBuffer();\n"
78 " x.add('won');\n"
79 " x.add('too');\n"
80 " return x.toString();\n"
81 "}\n";
82 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true);
83 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
84 EXPECT_VALID(lib);
85
86 Isolate* isolate = Isolate::Current();
87 Debugger* debugger = isolate->debugger();
88
89 // Test with one loaded breakpoint, one latent breakpoint.
90 Dart_Handle url = NewString(TestCase::url());
91 Dart_Handle result = Dart_SetBreakpoint(url, 2);
92 EXPECT_VALID(result);
93 EXPECT(Dart_IsInteger(result));
94 int64_t bp_id1 = 0;
95 EXPECT_VALID(Dart_IntegerToInt64(result, &bp_id1));
96
97 result = Dart_SetBreakpoint(NewString("not_yet_loaded_script_uri"), 4);
98 EXPECT_VALID(result);
99 EXPECT(Dart_IsInteger(result));
100 int64_t bp_id2 = 0;
101 EXPECT_VALID(Dart_IntegerToInt64(result, &bp_id2));
102
103 EXPECT(debugger->GetBreakpointById(bp_id1) != NULL);
104 EXPECT(debugger->GetBreakpointById(bp_id2) != NULL);
105
106 debugger->RemoveBreakpoint(bp_id1);
107 debugger->RemoveBreakpoint(bp_id2);
108
109 EXPECT(debugger->GetBreakpointById(bp_id1) == NULL);
110 EXPECT(debugger->GetBreakpointById(bp_id2) == NULL);
111 }
41 112
42 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { 113 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) {
43 const char* kScriptChars = 114 const char* kScriptChars =
44 "main() {\n" 115 "main() {\n"
45 " var x = new StringBuffer();\n" 116 " var x = new StringBuffer();\n"
46 " x.add('won');\n" 117 " x.add('won');\n"
47 " x.add('too');\n" 118 " x.add('too');\n"
48 " return x.toString();\n" 119 " return x.toString();\n"
49 "}\n"; 120 "}\n";
50 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true); 121 SetFlagScope<bool> sfs(&FLAG_remove_script_timestamps_for_test, true);
(...skipping 10 matching lines...) Expand all
61 // Empty case. 132 // Empty case.
62 { 133 {
63 JSONStream js; 134 JSONStream js;
64 { 135 {
65 JSONArray jsarr(&js); 136 JSONArray jsarr(&js);
66 debugger->PrintBreakpointsToJSONArray(&jsarr); 137 debugger->PrintBreakpointsToJSONArray(&jsarr);
67 } 138 }
68 EXPECT_STREQ("[]", js.ToCString()); 139 EXPECT_STREQ("[]", js.ToCString());
69 } 140 }
70 141
71 // Test with a couple of breakpoints. 142 // Test with a couple of loaded breakpoints, one latent breakpoint.
72 Dart_Handle url = NewString(TestCase::url()); 143 Dart_Handle url = NewString(TestCase::url());
73 EXPECT_VALID(Dart_SetBreakpoint(url, 2)); 144 EXPECT_VALID(Dart_SetBreakpoint(url, 2));
74 EXPECT_VALID(Dart_SetBreakpoint(url, 3)); 145 EXPECT_VALID(Dart_SetBreakpoint(url, 3));
146 EXPECT_VALID(Dart_SetBreakpoint(NewString("not_yet_loaded_script_uri"), 4));
75 { 147 {
76 JSONStream js; 148 JSONStream js;
77 { 149 {
78 JSONArray jsarr(&js); 150 JSONArray jsarr(&js);
79 debugger->PrintBreakpointsToJSONArray(&jsarr); 151 debugger->PrintBreakpointsToJSONArray(&jsarr);
80 } 152 }
81 ExpectSubstringF( 153 ExpectSubstringF(
82 js.ToCString(), 154 js.ToCString(),
83 "[{\"type\":\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/2\"," 155 "[{\"type\":\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/"
84 "\"breakpointNumber\":2,\"resolved\":false," 156 "2\",\"breakpointNumber\":2,\"resolved\":false,\"location\":{\"type\":"
85 "\"location\":{\"type\":\"UnresolvedSourceLocation\"," 157 "\"UnresolvedSourceLocation\",\"script\":{\"type\":\"@Script\","
86 "\"script\":{\"type\":\"@Script\",\"fixedId\":true," 158 "\"fixedId\":true,\"id\":\"libraries\\/@15247669\\/scripts\\/"
87 "\"id\":\"libraries\\/%s" 159 "test-lib\\/"
88 "\\/scripts\\/test-lib\\/0\"," 160 "0\",\"uri\":\"test-lib\",\"_kind\":\"script\"},\"line\":3}},{\"type\":"
89 "\"uri\":\"test-lib\"," 161 "\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/"
90 "\"_kind\":\"script\"},\"line\":3}}," 162 "1\",\"breakpointNumber\":1,\"resolved\":false,\"location\":{\"type\":"
91 "{\"type\":\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/1\"," 163 "\"UnresolvedSourceLocation\",\"script\":{\"type\":\"@Script\","
92 "\"breakpointNumber\":1,\"resolved\":false," 164 "\"fixedId\":true,\"id\":\"libraries\\/@15247669\\/scripts\\/"
93 "\"location\":{\"type\":\"UnresolvedSourceLocation\"," 165 "test-lib\\/"
94 "\"script\":{\"type\":\"@Script\",\"fixedId\":true," 166 "0\",\"uri\":\"test-lib\",\"_kind\":\"script\"},\"line\":2}},{\"type\":"
95 "\"id\":\"libraries\\/%s" 167 "\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/"
96 "\\/scripts\\/test-lib\\/0\"," 168 "3\",\"breakpointNumber\":3,\"resolved\":false,\"location\":{\"type\":"
97 "\"uri\":\"test-lib\"," 169 "\"UnresolvedSourceLocation\",\"scriptUri\":\"not_yet_loaded_script_"
98 "\"_kind\":\"script\"},\"line\":2}}]", 170 "uri\",\"line\":4}}]",
99 private_key.ToCString(), private_key.ToCString()); 171 private_key.ToCString(), private_key.ToCString());
100 } 172 }
101 } 173 }
102 174
103 175
104 static bool saw_paused_event = false; 176 static bool saw_paused_event = false;
105 177
106 static void InspectPausedEvent(Dart_IsolateId isolate_id, 178 static void InspectPausedEvent(Dart_IsolateId isolate_id,
107 intptr_t bp_id, 179 intptr_t bp_id,
108 const Dart_CodeLocation& loc) { 180 const Dart_CodeLocation& loc) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 "enter(bar1) enter(bar2) enter(bar3) enter(foo) " 504 "enter(bar1) enter(bar2) enter(bar3) enter(foo) "
433 "enter(bar3) enter(foo) " 505 "enter(bar3) enter(foo) "
434 "exit(foo) exit(bar3) exit(bar2) exit(bar1) ", 506 "exit(foo) exit(bar3) exit(bar2) exit(bar1) ",
435 result_cstr); 507 result_cstr);
436 EXPECT(saw_paused_event); 508 EXPECT(saw_paused_event);
437 } 509 }
438 510
439 #endif // !PRODUCT 511 #endif // !PRODUCT
440 512
441 } // namespace dart 513 } // namespace dart
OLDNEW
« runtime/vm/debugger.cc ('K') | « runtime/vm/debugger.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698