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

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
« no previous file with comments | « runtime/bin/dbg_connection.h ('k') | runtime/include/dart_debugger_api.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 "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 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", GetStringChars(script_url));
271 char const* chars;
272 Dart_StringToCString(lib_url, &chars);
273 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", chars);
274 } 284 }
275 msg.Printf("] }}"); 285 msg.Printf("] }}");
276 SendMsg(&msg); 286 SendMsg(&msg);
277 } 287 }
278 288
279 289
280 void DebuggerConnectionHandler::HandleGetLibraryURLsCmd(const char* json_msg) { 290 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) {
281 int msg_id = msgbuf_->MessageId(); 291 int msg_id = msgbuf_->MessageId();
282 dart::TextBuffer msg(64); 292 dart::TextBuffer msg(64);
283 msg.Printf("{ \"id\": %d, \"result\": { \"urls\": [", msg_id); 293 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id);
284 Dart_Handle urls = Dart_GetLibraryURLs(); 294 Dart_Handle lib_ids = Dart_GetLibraryIds();
285 ASSERT_NOT_ERROR(urls); 295 ASSERT_NOT_ERROR(lib_ids);
286 intptr_t num_libs; 296 intptr_t num_libs;
287 Dart_ListLength(urls, &num_libs); 297 Dart_Handle res = Dart_ListLength(lib_ids, &num_libs);
298 ASSERT_NOT_ERROR(res);
288 for (int i = 0; i < num_libs; i++) { 299 for (int i = 0; i < num_libs; i++) {
289 Dart_Handle lib_url = Dart_ListGetAt(urls, i); 300 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i);
301 ASSERT(Dart_IsInteger(lib_id_handle));
302 int lib_id = GetIntValue(lib_id_handle);
303 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id);
304 ASSERT_NOT_ERROR(lib_url);
305 ASSERT(!Dart_IsNull(lib_url));
290 ASSERT(Dart_IsString(lib_url)); 306 ASSERT(Dart_IsString(lib_url));
291 char const* chars; 307 char const* chars = NULL;
292 Dart_StringToCString(lib_url, &chars); 308 Dart_StringToCString(lib_url, &chars);
293 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", chars); 309 msg.Printf("%s{\"id\":%d,\"url\":\"%s\"}",
310 (i == 0) ? "" : ", ", lib_id, chars);
294 } 311 }
295 msg.Printf("] }}"); 312 msg.Printf("]}}");
296 SendMsg(&msg); 313 SendMsg(&msg);
297 } 314 }
298 315
299 316
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, 317 static void FormatField(dart::TextBuffer* buf,
310 Dart_Handle object_name, 318 Dart_Handle object_name,
311 Dart_Handle object) { 319 Dart_Handle object) {
312 ASSERT(Dart_IsString(object_name)); 320 ASSERT(Dart_IsString(object_name));
313 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); 321 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name));
314 intptr_t obj_id = Dart_CacheObject(object); 322 intptr_t obj_id = Dart_CacheObject(object);
315 ASSERT(obj_id >= 0); 323 ASSERT(obj_id >= 0);
316 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); 324 buf->Printf("\"value\":{\"objectId\":%d,", obj_id);
317 const char* kind = "object"; 325 const char* kind = "object";
318 if (Dart_IsInteger(object)) { 326 if (Dart_IsInteger(object)) {
(...skipping 26 matching lines...) Expand all
345 buf->Printf(","); 353 buf->Printf(",");
346 } 354 }
347 FormatField(buf, name_handle, value_handle); 355 FormatField(buf, name_handle, value_handle);
348 } 356 }
349 buf->Printf("]"); 357 buf->Printf("]");
350 } 358 }
351 359
352 360
353 static const char* FormatClassProps(dart::TextBuffer* buf, 361 static const char* FormatClassProps(dart::TextBuffer* buf,
354 intptr_t cls_id) { 362 intptr_t cls_id) {
355 Dart_Handle name, library, static_fields; 363 Dart_Handle name, static_fields;
356 intptr_t super_id; 364 intptr_t super_id = -1;
365 intptr_t library_id = -1;
357 Dart_Handle res = 366 Dart_Handle res =
358 Dart_GetClassInfo(cls_id, &name, &library, &super_id, &static_fields); 367 Dart_GetClassInfo(cls_id, &name, &library_id, &super_id, &static_fields);
359 RETURN_IF_ERROR(res); 368 RETURN_IF_ERROR(res);
360 RETURN_IF_ERROR(name); 369 RETURN_IF_ERROR(name);
361 buf->Printf("{\"name\":\"%s\",", GetStringChars(name)); 370 buf->Printf("{\"name\":\"%s\",", GetStringChars(name));
362 if (super_id > 0) { 371 if (super_id > 0) {
363 buf->Printf("\"superclassId\":%d,", super_id); 372 buf->Printf("\"superclassId\":%d,", super_id);
364 } 373 }
365 RETURN_IF_ERROR(library); 374 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); 375 RETURN_IF_ERROR(static_fields);
371 buf->Printf("\"fields\":"); 376 buf->Printf("\"fields\":");
372 FormatFieldList(buf, static_fields); 377 FormatFieldList(buf, static_fields);
373 buf->Printf("}"); 378 buf->Printf("}");
374 return NULL; 379 return NULL;
375 } 380 }
376 381
377 382
383 static const char* FormatLibraryProps(dart::TextBuffer* buf,
384 intptr_t lib_id) {
385 Dart_Handle url = Dart_GetLibraryURL(lib_id);
386 RETURN_IF_ERROR(url);
387 buf->Printf("{\"url\":\"%s\",", GetStringChars(url));
388
389 // Imports and prefixes.
390 Dart_Handle import_list = Dart_GetLibraryImports(lib_id);
391 RETURN_IF_ERROR(import_list);
392 ASSERT(Dart_IsList(import_list));
393 intptr_t list_length = 0;
394 Dart_Handle res = Dart_ListLength(import_list, &list_length);
395 RETURN_IF_ERROR(res);
396 buf->Printf("\"imports\":[");
397 for (int i = 0; i + 1 < list_length; i += 2) {
398 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1);
399 ASSERT_NOT_ERROR(lib_id);
400 buf->Printf("%s{\"libraryId\":%d,",
401 (i > 0) ? ",": "",
402 GetIntValue(lib_id));
403
404 Dart_Handle name = Dart_ListGetAt(import_list, i);
405 ASSERT_NOT_ERROR(name);
406 buf->Printf("\"prefix\":\"%s\"}",
407 Dart_IsNull(name) ? "" : GetStringChars(name));
408 }
409 buf->Printf("],");
410
411 // Global variables in the library.
412 Dart_Handle global_vars = Dart_GetLibraryFields(lib_id);
413 RETURN_IF_ERROR(global_vars);
414 buf->Printf("\"globals\":");
415 FormatFieldList(buf, global_vars);
416 buf->Printf("}");
417 return NULL;
418 }
419
420
378 static const char* FormatObjProps(dart::TextBuffer* buf, 421 static const char* FormatObjProps(dart::TextBuffer* buf,
379 Dart_Handle object) { 422 Dart_Handle object) {
380 intptr_t class_id; 423 intptr_t class_id;
424 if (Dart_IsNull(object)) {
425 buf->Printf("{\"classId\":-1,\"fields\":[]}");
426 return NULL;
427 }
381 Dart_Handle res = Dart_GetObjClassId(object, &class_id); 428 Dart_Handle res = Dart_GetObjClassId(object, &class_id);
382 RETURN_IF_ERROR(res); 429 RETURN_IF_ERROR(res);
383 buf->Printf("{\"classId\": %d, \"fields\":", class_id); 430 buf->Printf("{\"classId\": %d, \"fields\":", class_id);
384 Dart_Handle fields = Dart_GetInstanceFields(object); 431 Dart_Handle fields = Dart_GetInstanceFields(object);
385 RETURN_IF_ERROR(fields); 432 RETURN_IF_ERROR(fields);
386 FormatFieldList(buf, fields); 433 FormatFieldList(buf, fields);
387 buf->Printf("}"); 434 buf->Printf("}");
388 return NULL; 435 return NULL;
389 } 436 }
390 437
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 uint64_t bp_id_value; 508 uint64_t bp_id_value;
462 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value); 509 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value);
463 ASSERT_NOT_ERROR(res); 510 ASSERT_NOT_ERROR(res);
464 dart::TextBuffer msg(64); 511 dart::TextBuffer msg(64);
465 msg.Printf("{ \"id\": %d, \"result\": { \"breakpointId\": %d }}", 512 msg.Printf("{ \"id\": %d, \"result\": { \"breakpointId\": %d }}",
466 msg_id, bp_id_value); 513 msg_id, bp_id_value);
467 SendMsg(&msg); 514 SendMsg(&msg);
468 } 515 }
469 516
470 517
518 void DebuggerConnectionHandler::HandleRemBpCmd(const char* json_msg) {
519 int msg_id = msgbuf_->MessageId();
520 int bpt_id = msgbuf_->GetIntParam("breakpointId");
521 Dart_Handle res = Dart_RemoveBreakpoint(bpt_id);
522 if (Dart_IsError(res)) {
523 SendError(msg_id, Dart_GetError(res));
524 return;
525 }
526 dart::TextBuffer msg(32);
527 msg.Printf("{ \"id\": %d }", msg_id);
528 SendMsg(&msg);
529 }
530
531
471 void DebuggerConnectionHandler::HandleGetObjPropsCmd(const char* json_msg) { 532 void DebuggerConnectionHandler::HandleGetObjPropsCmd(const char* json_msg) {
472 int msg_id = msgbuf_->MessageId(); 533 int msg_id = msgbuf_->MessageId();
473 intptr_t obj_id = msgbuf_->GetIntParam("objectId"); 534 intptr_t obj_id = msgbuf_->GetIntParam("objectId");
474 Dart_Handle obj = Dart_GetCachedObject(obj_id); 535 Dart_Handle obj = Dart_GetCachedObject(obj_id);
475 if (Dart_IsError(obj)) { 536 if (Dart_IsError(obj)) {
476 SendError(msg_id, Dart_GetError(obj)); 537 SendError(msg_id, Dart_GetError(obj));
477 return; 538 return;
478 } 539 }
479 dart::TextBuffer msg(64); 540 dart::TextBuffer msg(64);
480 msg.Printf("{\"id\":%d, \"result\":", msg_id); 541 msg.Printf("{\"id\":%d, \"result\":", msg_id);
(...skipping 15 matching lines...) Expand all
496 const char* err = FormatClassProps(&msg, cls_id); 557 const char* err = FormatClassProps(&msg, cls_id);
497 if (err != NULL) { 558 if (err != NULL) {
498 SendError(msg_id, err); 559 SendError(msg_id, err);
499 return; 560 return;
500 } 561 }
501 msg.Printf("}"); 562 msg.Printf("}");
502 SendMsg(&msg); 563 SendMsg(&msg);
503 } 564 }
504 565
505 566
567 void DebuggerConnectionHandler::HandleGetLibPropsCmd(const char* json_msg) {
568 int msg_id = msgbuf_->MessageId();
569 intptr_t cls_id = msgbuf_->GetIntParam("libraryId");
570 dart::TextBuffer msg(64);
571 msg.Printf("{\"id\":%d, \"result\":", msg_id);
572 const char* err = FormatLibraryProps(&msg, cls_id);
573 if (err != NULL) {
574 SendError(msg_id, err);
575 return;
576 }
577 msg.Printf("}");
578 SendMsg(&msg);
579 }
580
581
506 void DebuggerConnectionHandler::HandleUnknownMsg(const char* json_msg) { 582 void DebuggerConnectionHandler::HandleUnknownMsg(const char* json_msg) {
507 int msg_id = msgbuf_->MessageId(); 583 int msg_id = msgbuf_->MessageId();
508 ASSERT(msg_id >= 0); 584 ASSERT(msg_id >= 0);
509 SendError(msg_id, "unknown debugger command"); 585 SendError(msg_id, "unknown debugger command");
510 } 586 }
511 587
512 588
513 void DebuggerConnectionHandler::HandleMessages() { 589 void DebuggerConnectionHandler::HandleMessages() {
514 static JSONDebuggerCommand debugger_commands[] = { 590 static JSONDebuggerCommand debugger_commands[] = {
515 { "resume", HandleResumeCmd }, 591 { "resume", HandleResumeCmd },
516 { "getLibraryURLs", HandleGetLibraryURLsCmd }, 592 { "getLibraries", HandleGetLibrariesCmd },
517 { "getClassProperties", HandleGetClassPropsCmd }, 593 { "getClassProperties", HandleGetClassPropsCmd },
594 { "getLibraryProperties", HandleGetLibPropsCmd },
518 { "getObjectProperties", HandleGetObjPropsCmd }, 595 { "getObjectProperties", HandleGetObjPropsCmd },
519 { "getScriptURLs", HandleGetScriptURLsCmd }, 596 { "getScriptURLs", HandleGetScriptURLsCmd },
520 { "getStackTrace", HandleGetStackTraceCmd }, 597 { "getStackTrace", HandleGetStackTraceCmd },
521 { "setBreakpoint", HandleSetBpCmd }, 598 { "setBreakpoint", HandleSetBpCmd },
599 { "removeBreakpoint", HandleRemBpCmd },
522 { "stepInto", HandleStepIntoCmd }, 600 { "stepInto", HandleStepIntoCmd },
523 { "stepOut", HandleStepOutCmd }, 601 { "stepOut", HandleStepOutCmd },
524 { "stepOver", HandleStepOverCmd }, 602 { "stepOver", HandleStepOverCmd },
525 { NULL, NULL } 603 { NULL, NULL }
526 }; 604 };
527 605
528 for (;;) { 606 for (;;) {
529 SendQueuedMsgs(); 607 SendQueuedMsgs();
530 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) { 608 while (!msgbuf_->IsValidMessage() && msgbuf_->Alive()) {
531 msgbuf_->ReadData(); 609 msgbuf_->ReadData();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 handler_started_ = true; 727 handler_started_ = true;
650 DebuggerConnectionImpl::StartHandler(port_number); 728 DebuggerConnectionImpl::StartHandler(port_number);
651 Dart_SetBreakpointHandler(BreakpointHandler); 729 Dart_SetBreakpointHandler(BreakpointHandler);
652 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); 730 Dart_SetBreakpointResolvedHandler(BptResolvedHandler);
653 } 731 }
654 732
655 733
656 DebuggerConnectionHandler::~DebuggerConnectionHandler() { 734 DebuggerConnectionHandler::~DebuggerConnectionHandler() {
657 CloseDbgConnection(); 735 CloseDbgConnection();
658 } 736 }
OLDNEW
« no previous file with comments | « runtime/bin/dbg_connection.h ('k') | runtime/include/dart_debugger_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698