| 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 // Search for the formatted string in buff. |
| 76 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { |
| 77 Isolate* isolate = Isolate::Current(); |
| 78 |
| 79 va_list args; |
| 80 va_start(args, fmt); |
| 81 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
| 82 va_end(args); |
| 83 |
| 84 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 85 va_list args2; |
| 86 va_start(args2, fmt); |
| 87 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
| 88 va_end(args2); |
| 89 |
| 90 EXPECT_SUBSTRING(buffer, buff); |
| 91 } |
| 92 |
| 93 |
| 75 static RawFunction* GetFunction(const Class& cls, const char* name) { | 94 static RawFunction* GetFunction(const Class& cls, const char* name) { |
| 76 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 95 const Function& result = Function::Handle(cls.LookupDynamicFunction( |
| 77 String::Handle(String::New(name)))); | 96 String::Handle(String::New(name)))); |
| 78 EXPECT(!result.IsNull()); | 97 EXPECT(!result.IsNull()); |
| 79 return result.raw(); | 98 return result.raw(); |
| 80 } | 99 } |
| 81 | 100 |
| 82 | 101 |
| 83 static RawClass* GetClass(const Library& lib, const char* name) { | 102 static RawClass* GetClass(const Library& lib, const char* name) { |
| 84 const Class& cls = Class::Handle( | 103 const Class& cls = Class::Handle( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 handler.HandleNextMessage(); | 343 handler.HandleNextMessage(); |
| 325 EXPECT_STREQ( | 344 EXPECT_STREQ( |
| 326 "{\"type\":\"Error\",\"text\":\"999999 is not a valid class id.\"," | 345 "{\"type\":\"Error\",\"text\":\"999999 is not a valid class id.\"," |
| 327 "\"message\":{\"arguments\":[\"classes\",\"999999\"]," | 346 "\"message\":{\"arguments\":[\"classes\",\"999999\"]," |
| 328 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 347 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
| 329 | 348 |
| 330 // Request the class A over the service. | 349 // Request the class A over the service. |
| 331 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); | 350 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); |
| 332 Service::HandleIsolateMessage(isolate, service_msg); | 351 Service::HandleIsolateMessage(isolate, service_msg); |
| 333 handler.HandleNextMessage(); | 352 handler.HandleNextMessage(); |
| 334 EXPECT_STREQ( | |
| 335 "{\"type\":\"Class\",\"id\":\"classes\\/1010\",\"name\":\"A\"," | |
| 336 "\"user_name\":\"A\",\"implemented\":false,\"abstract\":false," | |
| 337 "\"patch\":false,\"finalized\":true,\"const\":false,\"super\":" | |
| 338 "{\"type\":\"@Class\",\"id\":\"classes\\/35\",\"name\":\"Object\"," | |
| 339 "\"user_name\":\"Object\"},\"library\":{\"type\":\"@Library\",\"id\":" | |
| 340 "\"libraries\\/12\",\"name\":\"\",\"user_name\":\"dart:test-lib\"}," | |
| 341 "\"fields\":[{\"type\":\"@Field\",\"id\":\"classes\\/1010\\/fields\\/0\"," | |
| 342 "\"name\":\"a\",\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\"," | |
| 343 "\"id\":\"classes\\/1010\",\"name\":\"A\",\"user_name\":\"A\"}," | |
| 344 "\"declared_type\":{\"type\":\"@Class\",\"id\":\"classes\\/106\"," | |
| 345 "\"name\":\"dynamic\",\"user_name\":\"dynamic\"},\"static\":false," | |
| 346 "\"final\":false,\"const\":false}],\"functions\":[" | |
| 347 "{\"type\":\"@Function\",\"id\":\"classes\\/1010\\/functions\\/0\"," | |
| 348 "\"name\":\"get:a\",\"user_name\":\"A.a\"},{\"type\":\"@Function\"," | |
| 349 "\"id\":\"classes\\/1010\\/functions\\/1\",\"name\":\"set:a\"," | |
| 350 "\"user_name\":\"A.a=\"},{\"type\":\"@Function\",\"id\":" | |
| 351 "\"classes\\/1010\\/functions\\/2\",\"name\":\"b\",\"user_name\":\"A.b\"}" | |
| 352 ",{\"type\":\"@Function\",\"id\":\"classes\\/1010\\/functions\\/3\"," | |
| 353 "\"name\":\"c\",\"user_name\":\"A.c\"},{\"type\":\"@Function\",\"id\":" | |
| 354 "\"classes\\/1010\\/functions\\/4\",\"name\":\"A.\",\"user_name\":" | |
| 355 "\"A.A\"}]}", | |
| 356 handler.msg()); | |
| 357 | 353 |
| 358 // Request function 0 from class A. | 354 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); |
| 355 ExpectSubstringF(handler.msg(), |
| 356 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid); |
| 357 |
| 359 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0']," | 358 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '0']," |
| 360 "[], []]", cid); | 359 "[], []]", cid); |
| 361 Service::HandleIsolateMessage(isolate, service_msg); | 360 Service::HandleIsolateMessage(isolate, service_msg); |
| 362 handler.HandleNextMessage(); | 361 handler.HandleNextMessage(); |
| 363 EXPECT_STREQ( | 362 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg()); |
| 364 "{\"type\":\"Function\",\"id\":\"classes\\/1010\\/functions\\/0\",\"name\":" | 363 ExpectSubstringF(handler.msg(), |
| 365 "\"get:a\",\"user_name\":\"A.a\",\"is_static\":false,\"is_const\":false," | 364 "\"id\":\"classes\\/%" Pd "\\/functions\\/0\"," |
| 366 "\"is_optimizable\":true,\"is_inlinable\":false,\"kind\":" | 365 "\"name\":\"get:a\",", cid); |
| 367 "\"kImplicitGetter\",\"unoptimized_code\":{\"type\":\"null\"}," | |
| 368 "\"usage_counter\":0,\"optimized_call_site_count\":0,\"code\":" | |
| 369 "{\"type\":\"null\"},\"deoptimizations\":0}", handler.msg()); | |
| 370 | 366 |
| 371 // Request field 0 from class A. | 367 // Request field 0 from class A. |
| 372 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '0']," | 368 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '0']," |
| 373 "[], []]", cid); | 369 "[], []]", cid); |
| 374 Service::HandleIsolateMessage(isolate, service_msg); | 370 Service::HandleIsolateMessage(isolate, service_msg); |
| 375 handler.HandleNextMessage(); | 371 handler.HandleNextMessage(); |
| 376 EXPECT_STREQ( | 372 EXPECT_SUBSTRING("\"type\":\"Field\"", handler.msg()); |
| 377 "{\"type\":\"Field\",\"id\":\"classes\\/1010\\/fields\\/0\",\"name\":\"a\"," | 373 ExpectSubstringF(handler.msg(), |
| 378 "\"user_name\":\"a\",\"owner\":{\"type\":\"@Class\",\"id\":" | 374 "\"id\":\"classes\\/%" Pd "\\/fields\\/0\"," |
| 379 "\"classes\\/1010\",\"name\":\"A\",\"user_name\":\"A\"},\"declared_type\":" | 375 "\"name\":\"a\",", cid); |
| 380 "{\"type\":\"@Class\",\"id\":\"classes\\/106\",\"name\":\"dynamic\"," | |
| 381 "\"user_name\":\"dynamic\"},\"static\":false,\"final\":false,\"const\":" | |
| 382 "false,\"guard_nullable\":true,\"guard_class\":{\"type\":\"@Class\"," | |
| 383 "\"id\":\"classes\\/105\",\"name\":\"Null\",\"user_name\":\"Null\"}," | |
| 384 "\"guard_length\":\"variable\"}", handler.msg()); | |
| 385 | 376 |
| 386 // Invalid sub command. | 377 // Invalid sub command. |
| 387 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'huh', '0']," | 378 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'huh', '0']," |
| 388 "[], []]", cid); | 379 "[], []]", cid); |
| 389 Service::HandleIsolateMessage(isolate, service_msg); | 380 Service::HandleIsolateMessage(isolate, service_msg); |
| 390 handler.HandleNextMessage(); | 381 handler.HandleNextMessage(); |
| 391 EXPECT_STREQ( | 382 ExpectSubstringF(handler.msg(), |
| 392 "{\"type\":\"Error\",\"text\":\"Invalid sub collection huh\",\"message\":" | 383 "{\"type\":\"Error\",\"text\":\"Invalid sub collection huh\",\"message\":" |
| 393 "{\"arguments\":[\"classes\",\"1010\",\"huh\",\"0\"],\"option_keys\":[]," | 384 "{\"arguments\":[\"classes\",\"%" Pd "\",\"huh\",\"0\"],\"option_keys\":[]," |
| 394 "\"option_values\":[]}}", handler.msg()); | 385 "\"option_values\":[]}}", cid); |
| 395 | 386 |
| 396 // Invalid field request. | 387 // Invalid field request. |
| 397 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9']," | 388 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9']," |
| 398 "[], []]", cid); | 389 "[], []]", cid); |
| 399 Service::HandleIsolateMessage(isolate, service_msg); | 390 Service::HandleIsolateMessage(isolate, service_msg); |
| 400 handler.HandleNextMessage(); | 391 handler.HandleNextMessage(); |
| 401 EXPECT_STREQ( | 392 ExpectSubstringF(handler.msg(), |
| 402 "{\"type\":\"Error\",\"text\":\"Field 9 not found\"," | 393 "{\"type\":\"Error\",\"text\":\"Field 9 not found\"," |
| 403 "\"message\":{\"arguments\":[\"classes\",\"1010\",\"fields\",\"9\"]," | 394 "\"message\":{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\"]," |
| 404 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 395 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 405 | 396 |
| 406 // Invalid function request. | 397 // Invalid function request. |
| 407 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9']," | 398 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9']," |
| 408 "[], []]", cid); | 399 "[], []]", cid); |
| 409 Service::HandleIsolateMessage(isolate, service_msg); | 400 Service::HandleIsolateMessage(isolate, service_msg); |
| 410 handler.HandleNextMessage(); | 401 handler.HandleNextMessage(); |
| 411 EXPECT_STREQ( | 402 ExpectSubstringF(handler.msg(), |
| 412 "{\"type\":\"Error\",\"text\":\"Function 9 not found\"," | 403 "{\"type\":\"Error\",\"text\":\"Function 9 not found\"," |
| 413 "\"message\":{\"arguments\":[\"classes\",\"1010\",\"functions\",\"9\"]," | 404 "\"message\":{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\"]," |
| 414 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 405 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 415 | 406 |
| 416 | 407 |
| 417 // Invalid field subcommand. | 408 // Invalid field subcommand. |
| 418 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9', 'x']" | 409 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'fields', '9', 'x']" |
| 419 ",[], []]", cid); | 410 ",[], []]", cid); |
| 420 Service::HandleIsolateMessage(isolate, service_msg); | 411 Service::HandleIsolateMessage(isolate, service_msg); |
| 421 handler.HandleNextMessage(); | 412 handler.HandleNextMessage(); |
| 422 EXPECT_STREQ( | 413 ExpectSubstringF(handler.msg(), |
| 423 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" | 414 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" |
| 424 "{\"arguments\":[\"classes\",\"1010\",\"fields\",\"9\",\"x\"]," | 415 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," |
| 425 "\"option_keys\":[],\"option_values\":[]}}", | 416 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 426 handler.msg()); | |
| 427 | 417 |
| 428 // Invalid function request. | 418 // Invalid function request. |
| 429 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9'," | 419 service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'functions', '9'," |
| 430 "'x'], [], []]", cid); | 420 "'x'], [], []]", cid); |
| 431 Service::HandleIsolateMessage(isolate, service_msg); | 421 Service::HandleIsolateMessage(isolate, service_msg); |
| 432 handler.HandleNextMessage(); | 422 handler.HandleNextMessage(); |
| 433 EXPECT_STREQ( | 423 ExpectSubstringF(handler.msg(), |
| 434 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" | 424 "{\"type\":\"Error\",\"text\":\"Command too long\",\"message\":" |
| 435 "{\"arguments\":[\"classes\",\"1010\",\"functions\",\"9\",\"x\"]," | 425 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\",\"x\"]," |
| 436 "\"option_keys\":[],\"option_values\":[]}}", | 426 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 437 handler.msg()); | |
| 438 } | 427 } |
| 439 | 428 |
| 440 | 429 |
| 441 TEST_CASE(Service_Code) { | 430 TEST_CASE(Service_Code) { |
| 442 const char* kScript = | 431 const char* kScript = |
| 443 "var port;\n" // Set to our mock port by C++. | 432 "var port;\n" // Set to our mock port by C++. |
| 444 "\n" | 433 "\n" |
| 445 "class A {\n" | 434 "class A {\n" |
| 446 " var a;\n" | 435 " var a;\n" |
| 447 " dynamic b() {}\n" | 436 " dynamic b() {}\n" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 handler.HandleNextMessage(); | 608 handler.HandleNextMessage(); |
| 620 EXPECT_SUBSTRING( | 609 EXPECT_SUBSTRING( |
| 621 "{\"source\":\"dart:test-lib\",\"script\":{" | 610 "{\"source\":\"dart:test-lib\",\"script\":{" |
| 622 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\"," | 611 "\"type\":\"@Script\",\"id\":\"scripts\\/dart%3Atest-lib\"," |
| 623 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\"," | 612 "\"name\":\"dart:test-lib\",\"user_name\":\"dart:test-lib\"," |
| 624 "\"kind\":\"script\"},\"hits\":" | 613 "\"kind\":\"script\"},\"hits\":" |
| 625 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg()); | 614 "[3,0,3,1,5,1,5,1,5,1,6,1,6,1]}", handler.msg()); |
| 626 } | 615 } |
| 627 | 616 |
| 628 } // namespace dart | 617 } // namespace dart |
| OLD | NEW |