OLD | NEW |
---|---|
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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 65 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
66 va_list args2; | 66 va_list args2; |
67 va_start(args2, fmt); | 67 va_start(args2, fmt); |
68 OS::VSNPrint(buffer, (len + 1), fmt, args2); | 68 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
69 va_end(args2); | 69 va_end(args2); |
70 | 70 |
71 return Eval(lib, buffer); | 71 return Eval(lib, buffer); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 /* | |
76 static RawFunction* GetFunction(const Class& cls, const char* name) { | 75 static RawFunction* GetFunction(const Class& cls, const char* name) { |
77 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 76 const Function& result = Function::Handle(cls.LookupDynamicFunction( |
78 String::Handle(String::New(name)))); | 77 String::Handle(String::New(name)))); |
79 EXPECT(!result.IsNull()); | 78 EXPECT(!result.IsNull()); |
80 return result.raw(); | 79 return result.raw(); |
81 } | 80 } |
82 | 81 |
83 | 82 /* |
84 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { | 83 static RawFunction* GetStaticFunction(const Class& cls, const char* name) { |
85 const Function& result = Function::Handle(cls.LookupStaticFunction( | 84 const Function& result = Function::Handle(cls.LookupStaticFunction( |
86 String::Handle(String::New(name)))); | 85 String::Handle(String::New(name)))); |
87 EXPECT(!result.IsNull()); | 86 EXPECT(!result.IsNull()); |
88 return result.raw(); | 87 return result.raw(); |
89 } | 88 } |
90 | 89 |
91 | 90 |
92 static RawField* GetField(const Class& cls, const char* name) { | 91 static RawField* GetField(const Class& cls, const char* name) { |
93 const Field& field = | 92 const Field& field = |
94 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | 93 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); |
95 EXPECT(!field.IsNull()); | 94 EXPECT(!field.IsNull()); |
96 return field.raw(); | 95 return field.raw(); |
97 } | 96 } |
98 */ | 97 */ |
srdjan
2013/12/30 17:54:46
Remove dead code above.
Cutch
2013/12/30 21:32:40
Done.
| |
99 | 98 |
100 | 99 |
101 static RawClass* GetClass(const Library& lib, const char* name) { | 100 static RawClass* GetClass(const Library& lib, const char* name) { |
102 const Class& cls = Class::Handle( | 101 const Class& cls = Class::Handle( |
103 lib.LookupClass(String::Handle(Symbols::New(name)))); | 102 lib.LookupClass(String::Handle(Symbols::New(name)))); |
104 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 103 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
105 return cls.raw(); | 104 return cls.raw(); |
106 } | 105 } |
107 | 106 |
108 | 107 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 "'x'], [], []]", cid); | 350 "'x'], [], []]", cid); |
352 Service::HandleServiceMessage(isolate, service_msg); | 351 Service::HandleServiceMessage(isolate, service_msg); |
353 handler.HandleNextMessage(); | 352 handler.HandleNextMessage(); |
354 EXPECT_STREQ( | 353 EXPECT_STREQ( |
355 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" | 354 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" |
356 "{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\",\"x\"]," | 355 "{\"arguments\":[\"classes\",\"1009\",\"functions\",\"9\",\"x\"]," |
357 "\"option_keys\":[],\"option_values\":[]}}", | 356 "\"option_keys\":[],\"option_values\":[]}}", |
358 handler.msg()); | 357 handler.msg()); |
359 } | 358 } |
360 | 359 |
360 | |
361 TEST_CASE(Service_Code) { | |
362 const char* kScript = | |
363 "var port;\n" // Set to our mock port by C++. | |
364 "\n" | |
365 "class A {\n" | |
366 " var a;\n" | |
367 " dynamic b() {}\n" | |
368 " dynamic c() {\n" | |
369 " var d = () { b(); };\n" | |
370 " return d;\n" | |
371 " }\n" | |
372 "}\n" | |
373 "main() {\n" | |
374 " var z = new A();\n" | |
375 " var x = z.c();\n" | |
376 " x();\n" | |
377 "}"; | |
378 | |
379 Isolate* isolate = Isolate::Current(); | |
380 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | |
381 EXPECT_VALID(h_lib); | |
382 Library& lib = Library::Handle(); | |
383 lib ^= Api::UnwrapHandle(h_lib); | |
384 EXPECT(!lib.IsNull()); | |
385 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
386 EXPECT_VALID(result); | |
387 const Class& class_a = Class::Handle(GetClass(lib, "A")); | |
388 EXPECT(!class_a.IsNull()); | |
389 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); | |
390 EXPECT(!function_c.IsNull()); | |
391 const Code& code_c = Code::Handle(function_c.CurrentCode()); | |
392 EXPECT(!code_c.IsNull()); | |
393 // Use the entry of the code object as it's reference. | |
394 uword entry = code_c.EntryPoint(); | |
395 EXPECT_GT(code_c.Size(), 16); | |
396 uword last = entry + code_c.Size(); | |
397 | |
398 // Build a mock message handler and wrap it in a dart port. | |
399 ServiceTestMessageHandler handler; | |
400 Dart_Port port_id = PortMap::CreatePort(&handler); | |
401 Dart_Handle port = | |
402 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | |
403 EXPECT_VALID(port); | |
404 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | |
405 | |
406 Instance& service_msg = Instance::Handle(); | |
407 | |
408 // Request an invalid code object. | |
409 service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]"); | |
410 Service::HandleServiceMessage(isolate, service_msg); | |
411 handler.HandleNextMessage(); | |
412 EXPECT_STREQ( | |
413 "{\"type\":\"Error\",\"text\":\"Could not find code at 0\",\"message\":" | |
414 "{\"arguments\":[\"code\",\"0\"]," | |
415 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | |
416 | |
417 // The following four tests check that a code object can be found | |
418 // inside the range: [code.EntryPoint(), code.EntryPoint() + code.Size()). | |
419 // Request code object at code.EntryPoint() | |
420 // Expect this to succeed as it is inside [entry, entry + size). | |
421 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", entry); | |
422 Service::HandleServiceMessage(isolate, service_msg); | |
423 handler.HandleNextMessage(); | |
424 { | |
425 // Only perform a partial match. | |
426 const intptr_t kBufferSize = 512; | |
427 char buffer[kBufferSize]; | |
428 OS::SNPrint(buffer, kBufferSize-1, | |
429 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | |
430 EXPECT_SUBSTRING(buffer, handler.msg()); | |
431 } | |
432 | |
433 // Request code object at code.EntryPoint() + 16. | |
434 // Expect this to succeed as it is inside [entry, entry + size). | |
435 uintptr_t address = entry + 16; | |
436 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | |
437 Service::HandleServiceMessage(isolate, service_msg); | |
438 handler.HandleNextMessage(); | |
439 { | |
440 // Only perform a partial match. | |
441 const intptr_t kBufferSize = 512; | |
442 char buffer[kBufferSize]; | |
443 OS::SNPrint(buffer, kBufferSize-1, | |
444 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | |
445 EXPECT_SUBSTRING(buffer, handler.msg()); | |
446 } | |
447 | |
448 // Request code object at code.EntryPoint() + code.Size() - 1. | |
449 // Expect this to succeed as it is inside [entry, entry + size). | |
450 address = last - 1; | |
451 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | |
452 Service::HandleServiceMessage(isolate, service_msg); | |
453 handler.HandleNextMessage(); | |
454 { | |
455 // Only perform a partial match. | |
456 const intptr_t kBufferSize = 512; | |
457 char buffer[kBufferSize]; | |
458 OS::SNPrint(buffer, kBufferSize-1, | |
459 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | |
460 EXPECT_SUBSTRING(buffer, handler.msg()); | |
461 } | |
462 | |
463 // Request code object at code.EntryPoint() + code.Size(). Expect this | |
464 // to fail as it's outside of [entry, entry + size). | |
465 address = last; | |
466 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | |
467 Service::HandleServiceMessage(isolate, service_msg); | |
468 handler.HandleNextMessage(); | |
469 { | |
470 const intptr_t kBufferSize = 1024; | |
471 char buffer[kBufferSize]; | |
472 OS::SNPrint(buffer, kBufferSize-1, | |
473 "{\"type\":\"Error\",\"text\":\"Could not find code at %" Px "\"," | |
474 "\"message\":{\"arguments\":[\"code\",\"%" Px "\"]," | |
475 "\"option_keys\":[],\"option_values\":[]}}", address, address); | |
476 EXPECT_STREQ(buffer, handler.msg()); | |
477 } | |
478 } | |
479 | |
361 } // namespace dart | 480 } // namespace dart |
OLD | NEW |