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

Side by Side Diff: runtime/bin/dbg_connection.cc

Issue 10447045: Introduce library ids and info in the wire protocol (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
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 "bin/dbg_connection.h" 5 #include "bin/dbg_connection.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 #include "bin/socket.h" 7 #include "bin/socket.h"
8 #include "bin/thread.h" 8 #include "bin/thread.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 207
208 void DebuggerConnectionHandler::SendError(int msg_id, 208 void DebuggerConnectionHandler::SendError(int msg_id,
209 const char* err_msg) { 209 const char* err_msg) {
210 dart::TextBuffer msg(64); 210 dart::TextBuffer msg(64);
211 msg.Printf("{\"id\": %d, \"error\": \"Error: %s\"}", msg_id, err_msg); 211 msg.Printf("{\"id\": %d, \"error\": \"Error: %s\"}", msg_id, err_msg);
212 SendMsg(&msg); 212 SendMsg(&msg);
213 } 213 }
214 214
215 215
216 static const char* GetStringChars(Dart_Handle str) {
217 ASSERT(Dart_IsString(str));
218 const char* chars;
219 Dart_Handle res = Dart_StringToCString(str, &chars);
220 ASSERT(!Dart_IsError(res));
221 return chars;
222 }
223
224
225 static int GetIntValue(Dart_Handle int_handle) {
226 int64_t int64_val = -1;
227 ASSERT(Dart_IsInteger(int_handle));
228 Dart_Handle res = Dart_IntegerToInt64(int_handle, &int64_val);
229 ASSERT(!Dart_IsError(res));
230 // TODO(hausner): Range check.
231 return int64_val;
232 }
233
234
216 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { 235 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) {
217 int msg_id = msgbuf_->MessageId(); 236 int msg_id = msgbuf_->MessageId();
218 dart::TextBuffer msg(64); 237 dart::TextBuffer msg(64);
219 msg.Printf("{ \"id\": %d }", msg_id); 238 msg.Printf("{ \"id\": %d }", msg_id);
220 SendMsg(&msg); 239 SendMsg(&msg);
221 request_resume_ = true; 240 request_resume_ = true;
222 } 241 }
223 242
224 243
225 void DebuggerConnectionHandler::HandleStepIntoCmd(const char* json_msg) { 244 void DebuggerConnectionHandler::HandleStepIntoCmd(const char* json_msg) {
(...skipping 13 matching lines...) Expand all
239 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) { 258 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) {
240 Dart_Handle res = Dart_SetStepOver(); 259 Dart_Handle res = Dart_SetStepOver();
241 ASSERT_NOT_ERROR(res); 260 ASSERT_NOT_ERROR(res);
242 HandleResumeCmd(json_msg); 261 HandleResumeCmd(json_msg);
243 } 262 }
244 263
245 264
246 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) { 265 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) {
247 int msg_id = msgbuf_->MessageId(); 266 int msg_id = msgbuf_->MessageId();
248 dart::TextBuffer msg(64); 267 dart::TextBuffer msg(64);
249 const char* params = msgbuf_->Params(); 268 intptr_t lib_id = msgbuf_->GetIntParam("libraryId");
250 ASSERT(params != NULL); 269 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id);
251 dart::JSONReader pr(params);
252 pr.Seek("library");
253 ASSERT(pr.Type() == dart::JSONReader::kString);
254 char lib_url_chars[128];
255 pr.GetValueChars(lib_url_chars, sizeof(lib_url_chars));
256 Dart_Handle lib_url = Dart_NewString(lib_url_chars);
257 ASSERT_NOT_ERROR(lib_url); 270 ASSERT_NOT_ERROR(lib_url);
258 Dart_Handle urls = Dart_GetScriptURLs(lib_url); 271 Dart_Handle urls = Dart_GetScriptURLs(lib_url);
259 if (Dart_IsError(urls)) { 272 if (Dart_IsError(urls)) {
260 SendError(msg_id, Dart_GetError(urls)); 273 SendError(msg_id, Dart_GetError(urls));
261 return; 274 return;
262 } 275 }
263 ASSERT(Dart_IsList(urls)); 276 ASSERT(Dart_IsList(urls));
264 intptr_t num_urls = 0; 277 intptr_t num_urls = 0;
265 Dart_ListLength(urls, &num_urls); 278 Dart_ListLength(urls, &num_urls);
266 msg.Printf("{ \"id\": %d, ", msg_id); 279 msg.Printf("{ \"id\": %d, ", msg_id);
267 msg.Printf("\"result\": { \"urls\": ["); 280 msg.Printf("\"result\": { \"urls\": [");
268 for (int i = 0; i < num_urls; i++) { 281 for (int i = 0; i < num_urls; i++) {
269 Dart_Handle script_url = Dart_ListGetAt(urls, i); 282 Dart_Handle script_url = Dart_ListGetAt(urls, i);
270 ASSERT(Dart_IsString(script_url)); 283 ASSERT(Dart_IsString(script_url));
271 char const* chars; 284 char const* chars;
272 Dart_StringToCString(lib_url, &chars); 285 Dart_StringToCString(lib_url, &chars);
273 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", chars); 286 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", chars);
274 } 287 }
275 msg.Printf("] }}"); 288 msg.Printf("] }}");
276 SendMsg(&msg); 289 SendMsg(&msg);
277 } 290 }
278 291
279 292
280 void DebuggerConnectionHandler::HandleGetLibraryURLsCmd(const char* json_msg) { 293 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) {
281 int msg_id = msgbuf_->MessageId(); 294 int msg_id = msgbuf_->MessageId();
282 dart::TextBuffer msg(64); 295 dart::TextBuffer msg(64);
283 msg.Printf("{ \"id\": %d, \"result\": { \"urls\": [", msg_id); 296 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id);
284 Dart_Handle urls = Dart_GetLibraryURLs(); 297 Dart_Handle lib_ids = Dart_GetLibraryIds();
285 ASSERT_NOT_ERROR(urls); 298 ASSERT_NOT_ERROR(lib_ids);
286 intptr_t num_libs; 299 intptr_t num_libs;
287 Dart_ListLength(urls, &num_libs); 300 Dart_ListLength(lib_ids, &num_libs);
siva 2012/05/29 18:07:53 ASSERT return value is not an error?
hausner 2012/05/29 19:48:18 Done.
288 for (int i = 0; i < num_libs; i++) { 301 for (int i = 0; i < num_libs; i++) {
289 Dart_Handle lib_url = Dart_ListGetAt(urls, i); 302 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i);
303 ASSERT(Dart_IsInteger(lib_id_handle));
304 int lib_id = GetIntValue(lib_id_handle);
305 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id);
306 ASSERT_NOT_ERROR(lib_url);
307 ASSERT(!Dart_IsNull(lib_url));
290 ASSERT(Dart_IsString(lib_url)); 308 ASSERT(Dart_IsString(lib_url));
291 char const* chars; 309 char const* chars = NULL;
292 Dart_StringToCString(lib_url, &chars); 310 Dart_StringToCString(lib_url, &chars);
293 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", chars); 311 msg.Printf("%s{\"id\":%d,\"url\":\"%s\"}",
312 (i == 0) ? "" : ", ", lib_id, chars);
siva 2012/05/29 18:07:53 maybe use GetStringChars(lib_url) here instead of
hausner 2012/05/29 19:48:18 Yes. On 2012/05/29 18:07:53, asiva wrote:
294 } 313 }
295 msg.Printf("] }}"); 314 msg.Printf("]}}");
296 SendMsg(&msg); 315 SendMsg(&msg);
297 } 316 }
298 317
299 318
300 static const char* GetStringChars(Dart_Handle str) {
301 ASSERT(Dart_IsString(str));
302 const char* chars;
303 Dart_Handle res = Dart_StringToCString(str, &chars);
304 ASSERT(!Dart_IsError(res));
305 return chars;
306 }
307
308
309 static void FormatField(dart::TextBuffer* buf, 319 static void FormatField(dart::TextBuffer* buf,
310 Dart_Handle object_name, 320 Dart_Handle object_name,
311 Dart_Handle object) { 321 Dart_Handle object) {
312 ASSERT(Dart_IsString(object_name)); 322 ASSERT(Dart_IsString(object_name));
313 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); 323 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name));
314 intptr_t obj_id = Dart_CacheObject(object); 324 intptr_t obj_id = Dart_CacheObject(object);
315 ASSERT(obj_id >= 0); 325 ASSERT(obj_id >= 0);
316 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); 326 buf->Printf("\"value\":{\"objectId\":%d,", obj_id);
317 const char* kind = "object"; 327 const char* kind = "object";
318 if (Dart_IsInteger(object)) { 328 if (Dart_IsInteger(object)) {
(...skipping 26 matching lines...) Expand all
345 buf->Printf(","); 355 buf->Printf(",");
346 } 356 }
347 FormatField(buf, name_handle, value_handle); 357 FormatField(buf, name_handle, value_handle);
348 } 358 }
349 buf->Printf("]"); 359 buf->Printf("]");
350 } 360 }
351 361
352 362
353 static const char* FormatClassProps(dart::TextBuffer* buf, 363 static const char* FormatClassProps(dart::TextBuffer* buf,
354 intptr_t cls_id) { 364 intptr_t cls_id) {
355 Dart_Handle name, library, static_fields; 365 Dart_Handle name, static_fields;
356 intptr_t super_id; 366 intptr_t super_id = -1;
367 intptr_t library_id = -1;
357 Dart_Handle res = 368 Dart_Handle res =
358 Dart_GetClassInfo(cls_id, &name, &library, &super_id, &static_fields); 369 Dart_GetClassInfo(cls_id, &name, &library_id, &super_id, &static_fields);
359 RETURN_IF_ERROR(res); 370 RETURN_IF_ERROR(res);
360 RETURN_IF_ERROR(name); 371 RETURN_IF_ERROR(name);
361 buf->Printf("{\"name\":\"%s\",", GetStringChars(name)); 372 buf->Printf("{\"name\":\"%s\",", GetStringChars(name));
362 if (super_id > 0) { 373 if (super_id > 0) {
363 buf->Printf("\"superclassId\":%d,", super_id); 374 buf->Printf("\"superclassId\":%d,", super_id);
364 } 375 }
365 RETURN_IF_ERROR(library); 376 buf->Printf("\"libraryId\":%d,", library_id);
366 ASSERT(!Dart_IsNull(library));
367 // TODO(hausner): get proper library id.
368 intptr_t libId = 0;
369 buf->Printf("\"libraryId\":%d,", libId);
370 RETURN_IF_ERROR(static_fields); 377 RETURN_IF_ERROR(static_fields);
371 buf->Printf("\"fields\":"); 378 buf->Printf("\"fields\":");
372 FormatFieldList(buf, static_fields); 379 FormatFieldList(buf, static_fields);
373 buf->Printf("}"); 380 buf->Printf("}");
374 return NULL; 381 return NULL;
375 } 382 }
376 383
377 384
385 static const char* FormatLibraryProps(dart::TextBuffer* buf,
386 intptr_t lib_id) {
siva 2012/05/29 18:07:53 indentation?
hausner 2012/05/29 19:48:18 Done.
387 Dart_Handle url = Dart_GetLibraryURL(lib_id);
388 RETURN_IF_ERROR(url);
389 buf->Printf("{\"url\":\"%s\",", GetStringChars(url));
390
391 // Imports and prefixes.
392 Dart_Handle import_list = Dart_GetLibraryImports(lib_id);
393 RETURN_IF_ERROR(import_list);
394 ASSERT(Dart_IsList(import_list));
395 intptr_t list_length = 0;
396 Dart_Handle res = Dart_ListLength(import_list, &list_length);
397 RETURN_IF_ERROR(res);
398 buf->Printf("\"imports\":[");
399 for (int i = 0; i + 1 < list_length; i += 2) {
400 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1);
401 ASSERT_NOT_ERROR(lib_id);
402 buf->Printf("%s{\"libraryId\":%d,",
403 (i > 0) ? ",": "",
404 GetIntValue(lib_id));
405
406 Dart_Handle name = Dart_ListGetAt(import_list, i);
407 ASSERT_NOT_ERROR(name);
408 buf->Printf("\"prefix\":\"%s\"}",
409 Dart_IsNull(name) ? "" : GetStringChars(name));
410 }
411 buf->Printf("],");
412
413 // Global variables in the library.
414 Dart_Handle global_vars = Dart_GetLibraryFields(lib_id);
415 RETURN_IF_ERROR(global_vars);
416 buf->Printf("\"globals\":");
417 FormatFieldList(buf, global_vars);
418 buf->Printf("}");
419 return NULL;
420 }
421
422
378 static const char* FormatObjProps(dart::TextBuffer* buf, 423 static const char* FormatObjProps(dart::TextBuffer* buf,
379 Dart_Handle object) { 424 Dart_Handle object) {
380 intptr_t class_id; 425 intptr_t class_id;
426 if (Dart_IsNull(object)) {
427 buf->Printf("{\"classId\":-1,\"fields\":[]}");
428 return NULL;
429 }
381 Dart_Handle res = Dart_GetObjClassId(object, &class_id); 430 Dart_Handle res = Dart_GetObjClassId(object, &class_id);
382 RETURN_IF_ERROR(res); 431 RETURN_IF_ERROR(res);
383 buf->Printf("{\"classId\": %d, \"fields\":", class_id); 432 buf->Printf("{\"classId\": %d, \"fields\":", class_id);
384 Dart_Handle fields = Dart_GetInstanceFields(object); 433 Dart_Handle fields = Dart_GetInstanceFields(object);
385 RETURN_IF_ERROR(fields); 434 RETURN_IF_ERROR(fields);
386 FormatFieldList(buf, fields); 435 FormatFieldList(buf, fields);
387 buf->Printf("}"); 436 buf->Printf("}");
388 return NULL; 437 return NULL;
389 } 438 }
390 439
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 uint64_t bp_id_value; 510 uint64_t bp_id_value;
462 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value); 511 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value);
463 ASSERT_NOT_ERROR(res); 512 ASSERT_NOT_ERROR(res);
464 dart::TextBuffer msg(64); 513 dart::TextBuffer msg(64);
465 msg.Printf("{ \"id\": %d, \"result\": { \"breakpointId\": %d }}", 514 msg.Printf("{ \"id\": %d, \"result\": { \"breakpointId\": %d }}",
466 msg_id, bp_id_value); 515 msg_id, bp_id_value);
467 SendMsg(&msg); 516 SendMsg(&msg);
468 } 517 }
469 518
470 519
520 void DebuggerConnectionHandler::HandleRemBpCmd(const char* json_msg) {
521 int msg_id = msgbuf_->MessageId();
522 int bpt_id = msgbuf_->GetIntParam("breakpointId");
523 Dart_Handle res = Dart_RemoveBreakpoint(bpt_id);
524 ASSERT_NOT_ERROR(res);
525 dart::TextBuffer msg(32);
526 msg.Printf("{ \"id\": %d }", msg_id);
siva 2012/05/29 18:07:53 Shouldn't the reply have an Error reply so that th
hausner 2012/05/29 19:48:18 Done.
527 SendMsg(&msg);
528 }
529
530
471 void DebuggerConnectionHandler::HandleGetObjPropsCmd(const char* json_msg) { 531 void DebuggerConnectionHandler::HandleGetObjPropsCmd(const char* json_msg) {
472 int msg_id = msgbuf_->MessageId(); 532 int msg_id = msgbuf_->MessageId();
473 intptr_t obj_id = msgbuf_->GetIntParam("objectId"); 533 intptr_t obj_id = msgbuf_->GetIntParam("objectId");
474 Dart_Handle obj = Dart_GetCachedObject(obj_id); 534 Dart_Handle obj = Dart_GetCachedObject(obj_id);
475 if (Dart_IsError(obj)) { 535 if (Dart_IsError(obj)) {
476 SendError(msg_id, Dart_GetError(obj)); 536 SendError(msg_id, Dart_GetError(obj));
477 return; 537 return;
478 } 538 }
479 dart::TextBuffer msg(64); 539 dart::TextBuffer msg(64);
480 msg.Printf("{\"id\":%d, \"result\":", msg_id); 540 msg.Printf("{\"id\":%d, \"result\":", msg_id);
(...skipping 15 matching lines...) Expand all
496 const char* err = FormatClassProps(&msg, cls_id); 556 const char* err = FormatClassProps(&msg, cls_id);
497 if (err != NULL) { 557 if (err != NULL) {
498 SendError(msg_id, err); 558 SendError(msg_id, err);
499 return; 559 return;
500 } 560 }
501 msg.Printf("}"); 561 msg.Printf("}");
502 SendMsg(&msg); 562 SendMsg(&msg);
503 } 563 }
504 564
505 565
566 void DebuggerConnectionHandler::HandleGetLibPropsCmd(const char* json_msg) {
567 int msg_id = msgbuf_->MessageId();
568 intptr_t cls_id = msgbuf_->GetIntParam("libraryId");
569 dart::TextBuffer msg(64);
570 msg.Printf("{\"id\":%d, \"result\":", msg_id);
571 const char* err = FormatLibraryProps(&msg, cls_id);
572 if (err != NULL) {
573 SendError(msg_id, err);
574 return;
575 }
576 msg.Printf("}");
577 SendMsg(&msg);
578 }
579
580
506 void DebuggerConnectionHandler::HandleUnknownMsg(const char* json_msg) { 581 void DebuggerConnectionHandler::HandleUnknownMsg(const char* json_msg) {
507 int msg_id = msgbuf_->MessageId(); 582 int msg_id = msgbuf_->MessageId();
508 ASSERT(msg_id >= 0); 583 ASSERT(msg_id >= 0);
509 SendError(msg_id, "unknown debugger command"); 584 SendError(msg_id, "unknown debugger command");
510 } 585 }
511 586
512 587
513 void DebuggerConnectionHandler::HandleMessages() { 588 void DebuggerConnectionHandler::HandleMessages() {
514 static JSONDebuggerCommand debugger_commands[] = { 589 static JSONDebuggerCommand debugger_commands[] = {
515 { "resume", HandleResumeCmd }, 590 { "resume", HandleResumeCmd },
516 { "getLibraryURLs", HandleGetLibraryURLsCmd }, 591 { "getLibraries", HandleGetLibrariesCmd },
517 { "getClassProperties", HandleGetClassPropsCmd }, 592 { "getClassProperties", HandleGetClassPropsCmd },
593 { "getLibraryProperties", HandleGetLibPropsCmd },
518 { "getObjectProperties", HandleGetObjPropsCmd }, 594 { "getObjectProperties", HandleGetObjPropsCmd },
519 { "getScriptURLs", HandleGetScriptURLsCmd }, 595 { "getScriptURLs", HandleGetScriptURLsCmd },
520 { "getStackTrace", HandleGetStackTraceCmd }, 596 { "getStackTrace", HandleGetStackTraceCmd },
521 { "setBreakpoint", HandleSetBpCmd }, 597 { "setBreakpoint", HandleSetBpCmd },
598 { "removeBreakpoint", HandleRemBpCmd },
522 { "stepInto", HandleStepIntoCmd }, 599 { "stepInto", HandleStepIntoCmd },
523 { "stepOut", HandleStepOutCmd }, 600 { "stepOut", HandleStepOutCmd },
524 { "stepOver", HandleStepOverCmd }, 601 { "stepOver", HandleStepOverCmd },
525 { NULL, NULL } 602 { NULL, NULL }
526 }; 603 };
527 604
528 for (;;) { 605 for (;;) {
529 SendQueuedMsgs(); 606 SendQueuedMsgs();
530 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) { 607 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) {
531 msgbuf_->ReadData(); 608 msgbuf_->ReadData();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 handler_started_ = true; 726 handler_started_ = true;
650 DebuggerConnectionImpl::StartHandler(port_number); 727 DebuggerConnectionImpl::StartHandler(port_number);
651 Dart_SetBreakpointHandler(BreakpointHandler); 728 Dart_SetBreakpointHandler(BreakpointHandler);
652 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); 729 Dart_SetBreakpointResolvedHandler(BptResolvedHandler);
653 } 730 }
654 731
655 732
656 DebuggerConnectionHandler::~DebuggerConnectionHandler() { 733 DebuggerConnectionHandler::~DebuggerConnectionHandler() {
657 CloseDbgConnection(); 734 CloseDbgConnection();
658 } 735 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698