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

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

Issue 10496006: Add string encoding to 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 class MessageBuffer { 48 class MessageBuffer {
49 public: 49 public:
50 explicit MessageBuffer(int fd); 50 explicit MessageBuffer(int fd);
51 ~MessageBuffer(); 51 ~MessageBuffer();
52 void ReadData(); 52 void ReadData();
53 bool IsValidMessage() const; 53 bool IsValidMessage() const;
54 void PopMessage(); 54 void PopMessage();
55 int MessageId() const; 55 int MessageId() const;
56 const char* Params() const; 56 const char* Params() const;
57 intptr_t GetIntParam(const char* name) const; 57 intptr_t GetIntParam(const char* name) const;
58 // GetStringParam mallocs the buffer that it returns. Caller must free.
59 char* GetStringParam(const char* name) const;
58 char* buf() const { return buf_; } 60 char* buf() const { return buf_; }
59 bool Alive() const { return connection_is_alive_; } 61 bool Alive() const { return connection_is_alive_; }
60 62
61 private: 63 private:
62 static const int kInitialBufferSize = 256; 64 static const int kInitialBufferSize = 256;
63 char* buf_; 65 char* buf_;
64 int buf_length_; 66 int buf_length_;
65 int fd_; 67 int fd_;
66 int data_length_; 68 int data_length_;
67 bool connection_is_alive_; 69 bool connection_is_alive_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 128
127 intptr_t MessageBuffer::GetIntParam(const char* name) const { 129 intptr_t MessageBuffer::GetIntParam(const char* name) const {
128 const char* params = Params(); 130 const char* params = Params();
129 ASSERT(params != NULL); 131 ASSERT(params != NULL);
130 dart::JSONReader r(params); 132 dart::JSONReader r(params);
131 r.Seek(name); 133 r.Seek(name);
132 ASSERT(r.Type() == dart::JSONReader::kInteger); 134 ASSERT(r.Type() == dart::JSONReader::kInteger);
133 return strtol(r.ValueChars(), NULL, 10); 135 return strtol(r.ValueChars(), NULL, 10);
134 } 136 }
135 137
138 char* MessageBuffer::GetStringParam(const char* name) const {
139 const char* params = Params();
140 ASSERT(params != NULL);
141 dart::JSONReader pr(params);
142 pr.Seek(name);
143 if (pr.Type() != dart::JSONReader::kString) {
144 return NULL;
145 }
146 intptr_t buflen = pr.ValueLen() + 1;
147 char* param_chars = reinterpret_cast<char*>(malloc(buflen));
148 pr.GetValueChars(param_chars, buflen);
149 // TODO(hausner): Decode escape sequences.
150 return param_chars;
151 }
136 152
137 void MessageBuffer::ReadData() { 153 void MessageBuffer::ReadData() {
138 ASSERT(data_length_ >= 0); 154 ASSERT(data_length_ >= 0);
139 ASSERT(data_length_ < buf_length_); 155 ASSERT(data_length_ < buf_length_);
140 int max_read = buf_length_ - data_length_ - 1; 156 int max_read = buf_length_ - data_length_ - 1;
141 if (max_read == 0) { 157 if (max_read == 0) {
142 // TODO(hausner): 158 // TODO(hausner):
143 // Buffer is full. What should we do if there is no valid message 159 // Buffer is full. What should we do if there is no valid message
144 // in the buffer? This might be possible if the client sends a message 160 // in the buffer? This might be possible if the client sends a message
145 // that's larger than the buffer, of if the client sends malformed 161 // that's larger than the buffer, of if the client sends malformed
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 Dart_Handle res = Dart_StringToCString(str, &chars); 235 Dart_Handle res = Dart_StringToCString(str, &chars);
220 ASSERT(!Dart_IsError(res)); 236 ASSERT(!Dart_IsError(res));
221 return chars; 237 return chars;
222 } 238 }
223 239
224 240
225 static int GetIntValue(Dart_Handle int_handle) { 241 static int GetIntValue(Dart_Handle int_handle) {
226 int64_t int64_val = -1; 242 int64_t int64_val = -1;
227 ASSERT(Dart_IsInteger(int_handle)); 243 ASSERT(Dart_IsInteger(int_handle));
228 Dart_Handle res = Dart_IntegerToInt64(int_handle, &int64_val); 244 Dart_Handle res = Dart_IntegerToInt64(int_handle, &int64_val);
229 ASSERT(!Dart_IsError(res)); 245 ASSERT_NOT_ERROR(res);
230 // TODO(hausner): Range check. 246 // TODO(hausner): Range check.
231 return int64_val; 247 return int64_val;
232 } 248 }
233 249
234 250
235 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) { 251 void DebuggerConnectionHandler::HandleResumeCmd(const char* json_msg) {
236 int msg_id = msgbuf_->MessageId(); 252 int msg_id = msgbuf_->MessageId();
237 dart::TextBuffer msg(64); 253 dart::TextBuffer msg(64);
238 msg.Printf("{ \"id\": %d }", msg_id); 254 msg.Printf("{ \"id\": %d }", msg_id);
239 SendMsg(&msg); 255 SendMsg(&msg);
(...skipping 15 matching lines...) Expand all
255 } 271 }
256 272
257 273
258 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) { 274 void DebuggerConnectionHandler::HandleStepOverCmd(const char* json_msg) {
259 Dart_Handle res = Dart_SetStepOver(); 275 Dart_Handle res = Dart_SetStepOver();
260 ASSERT_NOT_ERROR(res); 276 ASSERT_NOT_ERROR(res);
261 HandleResumeCmd(json_msg); 277 HandleResumeCmd(json_msg);
262 } 278 }
263 279
264 280
281 static void FormatEncodedString(dart::TextBuffer* buf, Dart_Handle str) {
282 ASSERT(Dart_IsString8(str));
283 intptr_t str_len = 0;
284 Dart_Handle res = Dart_StringLength(str, &str_len);
285 ASSERT_NOT_ERROR(res);
286 uint8_t* codepoints = reinterpret_cast<uint8_t*>(malloc(str_len));
287 ASSERT(codepoints != NULL);
288 intptr_t actual_len = str_len;
289 res = Dart_StringGet8(str, codepoints, &actual_len);
290 ASSERT(str_len == actual_len);
291 buf->Printf("\"");
292 buf->PrintJsonString8(codepoints, str_len);
293 buf->Printf("\"");
294 free(codepoints);
295 }
296
297
298 static void FormatErrorMsg(dart::TextBuffer* buf, Dart_Handle err) {
299 // TODO(hausner): Turn message into Dart string and
300 // properly encode the message.
301 ASSERT(Dart_IsError(err));
302 const char* msg = Dart_GetError(err);
303 buf->Printf("\"%s\"", msg);
304 }
305
306
265 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) { 307 void DebuggerConnectionHandler::HandleGetScriptURLsCmd(const char* json_msg) {
266 int msg_id = msgbuf_->MessageId(); 308 int msg_id = msgbuf_->MessageId();
267 dart::TextBuffer msg(64); 309 dart::TextBuffer msg(64);
268 intptr_t lib_id = msgbuf_->GetIntParam("libraryId"); 310 intptr_t lib_id = msgbuf_->GetIntParam("libraryId");
269 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); 311 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id);
270 ASSERT_NOT_ERROR(lib_url); 312 ASSERT_NOT_ERROR(lib_url);
271 Dart_Handle urls = Dart_GetScriptURLs(lib_url); 313 Dart_Handle urls = Dart_GetScriptURLs(lib_url);
272 if (Dart_IsError(urls)) { 314 if (Dart_IsError(urls)) {
273 SendError(msg_id, Dart_GetError(urls)); 315 SendError(msg_id, Dart_GetError(urls));
274 return; 316 return;
275 } 317 }
276 ASSERT(Dart_IsList(urls)); 318 ASSERT(Dart_IsList(urls));
277 intptr_t num_urls = 0; 319 intptr_t num_urls = 0;
278 Dart_ListLength(urls, &num_urls); 320 Dart_ListLength(urls, &num_urls);
279 msg.Printf("{ \"id\": %d, ", msg_id); 321 msg.Printf("{ \"id\": %d, ", msg_id);
280 msg.Printf("\"result\": { \"urls\": ["); 322 msg.Printf("\"result\": { \"urls\": [");
281 for (int i = 0; i < num_urls; i++) { 323 for (int i = 0; i < num_urls; i++) {
282 Dart_Handle script_url = Dart_ListGetAt(urls, i); 324 Dart_Handle script_url = Dart_ListGetAt(urls, i);
283 msg.Printf("%s\"%s\"", (i == 0) ? "" : ", ", GetStringChars(script_url)); 325 if (i > 0) {
326 msg.Printf(",");
327 }
328 FormatEncodedString(&msg, script_url);
284 } 329 }
285 msg.Printf("] }}"); 330 msg.Printf("]}}");
331 SendMsg(&msg);
332 }
333
334
335 void DebuggerConnectionHandler::HandleGetSourceCmd(const char* json_msg) {
336 int msg_id = msgbuf_->MessageId();
337 dart::TextBuffer msg(64);
338 intptr_t lib_id = msgbuf_->GetIntParam("libraryId");
339 char* url_chars = msgbuf_->GetStringParam("url");
340 ASSERT(url_chars != NULL);
341 Dart_Handle url = Dart_NewString(url_chars);
342 ASSERT_NOT_ERROR(url);
343 free(url_chars);
344 url_chars = NULL;
345 Dart_Handle source = Dart_ScriptGetSource(lib_id, url);
346 if (Dart_IsError(source)) {
347 SendError(msg_id, Dart_GetError(source));
348 return;
349 }
350 msg.Printf("{ \"id\": %d, ", msg_id);
351 msg.Printf("\"result\": { \"text\": ");
352 FormatEncodedString(&msg, source);
353 msg.Printf("}}");
286 SendMsg(&msg); 354 SendMsg(&msg);
287 } 355 }
288 356
289 357
290 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) { 358 void DebuggerConnectionHandler::HandleGetLibrariesCmd(const char* json_msg) {
291 int msg_id = msgbuf_->MessageId(); 359 int msg_id = msgbuf_->MessageId();
292 dart::TextBuffer msg(64); 360 dart::TextBuffer msg(64);
293 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id); 361 msg.Printf("{ \"id\": %d, \"result\": { \"libraries\": [", msg_id);
294 Dart_Handle lib_ids = Dart_GetLibraryIds(); 362 Dart_Handle lib_ids = Dart_GetLibraryIds();
295 ASSERT_NOT_ERROR(lib_ids); 363 ASSERT_NOT_ERROR(lib_ids);
296 intptr_t num_libs; 364 intptr_t num_libs;
297 Dart_Handle res = Dart_ListLength(lib_ids, &num_libs); 365 Dart_Handle res = Dart_ListLength(lib_ids, &num_libs);
298 ASSERT_NOT_ERROR(res); 366 ASSERT_NOT_ERROR(res);
299 for (int i = 0; i < num_libs; i++) { 367 for (int i = 0; i < num_libs; i++) {
300 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i); 368 Dart_Handle lib_id_handle = Dart_ListGetAt(lib_ids, i);
301 ASSERT(Dart_IsInteger(lib_id_handle)); 369 ASSERT(Dart_IsInteger(lib_id_handle));
302 int lib_id = GetIntValue(lib_id_handle); 370 int lib_id = GetIntValue(lib_id_handle);
303 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id); 371 Dart_Handle lib_url = Dart_GetLibraryURL(lib_id);
304 ASSERT_NOT_ERROR(lib_url); 372 ASSERT_NOT_ERROR(lib_url);
305 ASSERT(!Dart_IsNull(lib_url));
306 ASSERT(Dart_IsString(lib_url)); 373 ASSERT(Dart_IsString(lib_url));
307 char const* chars = NULL; 374 msg.Printf("%s{\"id\":%d,\"url\":", (i == 0) ? "" : ", ", lib_id);
308 Dart_StringToCString(lib_url, &chars); 375 FormatEncodedString(&msg, lib_url);
309 msg.Printf("%s{\"id\":%d,\"url\":\"%s\"}", 376 msg.Printf("}");
310 (i == 0) ? "" : ", ", lib_id, chars);
311 } 377 }
312 msg.Printf("]}}"); 378 msg.Printf("]}}");
313 SendMsg(&msg); 379 SendMsg(&msg);
314 } 380 }
315 381
316 382
317 static void FormatField(dart::TextBuffer* buf, 383 static void FormatField(dart::TextBuffer* buf,
318 Dart_Handle object_name, 384 Dart_Handle object_name,
319 Dart_Handle object) { 385 Dart_Handle object) {
320 ASSERT(Dart_IsString(object_name)); 386 ASSERT(Dart_IsString(object_name));
321 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); 387 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name));
322 intptr_t obj_id = Dart_CacheObject(object); 388 intptr_t obj_id = Dart_CacheObject(object);
323 ASSERT(obj_id >= 0); 389 ASSERT(obj_id >= 0);
324 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); 390 buf->Printf("\"value\":{\"objectId\":%d,", obj_id);
325 const char* kind = "object"; 391 const char* kind = "object";
326 if (Dart_IsInteger(object)) { 392 if (Dart_IsInteger(object)) {
327 kind = "integer"; 393 kind = "integer";
328 } else if (Dart_IsString(object)) { 394 } else if (Dart_IsString(object)) {
329 kind = "string"; 395 kind = "string";
330 } else if (Dart_IsBoolean(object)) { 396 } else if (Dart_IsBoolean(object)) {
331 kind = "boolean"; 397 kind = "boolean";
332 } 398 }
333 buf->Printf("\"kind\":\"%s\",", kind); 399 buf->Printf("\"kind\":\"%s\",", kind);
334 Dart_Handle text = Dart_ToString(object); 400 buf->Printf("\"text\":");
335 buf->Printf("\"text\":\"%s\"}}", GetStringChars(text)); 401 Dart_Handle text;
402 if (Dart_IsNull(object)) {
403 text = Dart_Null();
404 } else {
405 text = Dart_ToString(object);
406 }
407 if (Dart_IsNull(text)) {
408 buf->Printf("null");
409 } else if (Dart_IsError(text)) {
410 FormatErrorMsg(buf, text);
411 } else {
412 FormatEncodedString(buf, text);
413 }
414 buf->Printf("}}");
336 } 415 }
337 416
338 417
339 static void FormatFieldList(dart::TextBuffer* buf, 418 static void FormatFieldList(dart::TextBuffer* buf,
340 Dart_Handle obj_list) { 419 Dart_Handle obj_list) {
341 ASSERT(Dart_IsList(obj_list)); 420 ASSERT(Dart_IsList(obj_list));
342 intptr_t list_length = 0; 421 intptr_t list_length = 0;
343 Dart_Handle res = Dart_ListLength(obj_list, &list_length); 422 Dart_Handle res = Dart_ListLength(obj_list, &list_length);
344 ASSERT_NOT_ERROR(res); 423 ASSERT_NOT_ERROR(res);
345 ASSERT(list_length % 2 == 0); 424 ASSERT(list_length % 2 == 0);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 FormatFieldList(buf, static_fields); 456 FormatFieldList(buf, static_fields);
378 buf->Printf("}"); 457 buf->Printf("}");
379 return NULL; 458 return NULL;
380 } 459 }
381 460
382 461
383 static const char* FormatLibraryProps(dart::TextBuffer* buf, 462 static const char* FormatLibraryProps(dart::TextBuffer* buf,
384 intptr_t lib_id) { 463 intptr_t lib_id) {
385 Dart_Handle url = Dart_GetLibraryURL(lib_id); 464 Dart_Handle url = Dart_GetLibraryURL(lib_id);
386 RETURN_IF_ERROR(url); 465 RETURN_IF_ERROR(url);
387 buf->Printf("{\"url\":\"%s\",", GetStringChars(url)); 466 buf->Printf("{\"url\":");
467 FormatEncodedString(buf, url);
388 468
389 // Imports and prefixes. 469 // Imports and prefixes.
390 Dart_Handle import_list = Dart_GetLibraryImports(lib_id); 470 Dart_Handle import_list = Dart_GetLibraryImports(lib_id);
391 RETURN_IF_ERROR(import_list); 471 RETURN_IF_ERROR(import_list);
392 ASSERT(Dart_IsList(import_list)); 472 ASSERT(Dart_IsList(import_list));
393 intptr_t list_length = 0; 473 intptr_t list_length = 0;
394 Dart_Handle res = Dart_ListLength(import_list, &list_length); 474 Dart_Handle res = Dart_ListLength(import_list, &list_length);
395 RETURN_IF_ERROR(res); 475 RETURN_IF_ERROR(res);
396 buf->Printf("\"imports\":["); 476 buf->Printf(",\"imports\":[");
397 for (int i = 0; i + 1 < list_length; i += 2) { 477 for (int i = 0; i + 1 < list_length; i += 2) {
398 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1); 478 Dart_Handle lib_id = Dart_ListGetAt(import_list, i + 1);
399 ASSERT_NOT_ERROR(lib_id); 479 ASSERT_NOT_ERROR(lib_id);
400 buf->Printf("%s{\"libraryId\":%d,", 480 buf->Printf("%s{\"libraryId\":%d,",
401 (i > 0) ? ",": "", 481 (i > 0) ? ",": "",
402 GetIntValue(lib_id)); 482 GetIntValue(lib_id));
403 483
404 Dart_Handle name = Dart_ListGetAt(import_list, i); 484 Dart_Handle name = Dart_ListGetAt(import_list, i);
405 ASSERT_NOT_ERROR(name); 485 ASSERT_NOT_ERROR(name);
406 buf->Printf("\"prefix\":\"%s\"}", 486 buf->Printf("\"prefix\":\"%s\"}",
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 msg->Printf("\"callFrames\" : [ "); 523 msg->Printf("\"callFrames\" : [ ");
444 for (int i = 0; i < trace_len; i++) { 524 for (int i = 0; i < trace_len; i++) {
445 Dart_ActivationFrame frame; 525 Dart_ActivationFrame frame;
446 res = Dart_GetActivationFrame(trace, i, &frame); 526 res = Dart_GetActivationFrame(trace, i, &frame);
447 ASSERT_NOT_ERROR(res); 527 ASSERT_NOT_ERROR(res);
448 Dart_Handle func_name; 528 Dart_Handle func_name;
449 Dart_Handle script_url; 529 Dart_Handle script_url;
450 intptr_t line_number = 0; 530 intptr_t line_number = 0;
451 res = Dart_ActivationFrameInfo( 531 res = Dart_ActivationFrameInfo(
452 frame, &func_name, &script_url, &line_number); 532 frame, &func_name, &script_url, &line_number);
533
453 ASSERT_NOT_ERROR(res); 534 ASSERT_NOT_ERROR(res);
454 ASSERT(Dart_IsString(func_name)); 535 ASSERT(Dart_IsString(func_name));
455 const char* func_name_chars; 536 msg->Printf("%s{\"functionName\":", (i > 0) ? "," : "");
456 Dart_StringToCString(func_name, &func_name_chars); 537 FormatEncodedString(msg, func_name);
457 msg->Printf("%s { \"functionName\": \"%s\" , ", 538
458 i > 0 ? "," : "",
459 func_name_chars);
460 ASSERT(Dart_IsString(script_url)); 539 ASSERT(Dart_IsString(script_url));
461 const char* script_url_chars; 540 msg->Printf(",\"location\": { \"url\":");
462 Dart_StringToCString(script_url, &script_url_chars); 541 FormatEncodedString(msg, script_url);
463 msg->Printf("\"location\": { \"url\": \"%s\", \"lineNumber\":%d},", 542 msg->Printf(",\"lineNumber\":%d},", line_number);
464 script_url_chars, line_number); 543
465 Dart_Handle locals = Dart_GetLocalVariables(frame); 544 Dart_Handle locals = Dart_GetLocalVariables(frame);
466 ASSERT_NOT_ERROR(locals); 545 ASSERT_NOT_ERROR(locals);
467 msg->Printf("\"locals\":"); 546 msg->Printf("\"locals\":");
468 FormatFieldList(msg, locals); 547 FormatFieldList(msg, locals);
469 msg->Printf("}"); 548 msg->Printf("}");
470 } 549 }
471 msg->Printf("]"); 550 msg->Printf("]");
472 } 551 }
473 552
474 553
475 void DebuggerConnectionHandler::HandleGetStackTraceCmd(const char* json_msg) { 554 void DebuggerConnectionHandler::HandleGetStackTraceCmd(const char* json_msg) {
476 int msg_id = msgbuf_->MessageId(); 555 int msg_id = msgbuf_->MessageId();
477 Dart_StackTrace trace; 556 Dart_StackTrace trace;
478 Dart_Handle res = Dart_GetStackTrace(&trace); 557 Dart_Handle res = Dart_GetStackTrace(&trace);
479 ASSERT_NOT_ERROR(res); 558 ASSERT_NOT_ERROR(res);
480 dart::TextBuffer msg(128); 559 dart::TextBuffer msg(128);
481 msg.Printf("{ \"id\": %d, \"result\": {", msg_id); 560 msg.Printf("{ \"id\": %d, \"result\": {", msg_id);
482 FormatCallFrames(&msg, trace); 561 FormatCallFrames(&msg, trace);
483 msg.Printf("}}"); 562 msg.Printf("}}");
484 SendMsg(&msg); 563 SendMsg(&msg);
485 } 564 }
486 565
487 566
488 void DebuggerConnectionHandler::HandleSetBpCmd(const char* json_msg) { 567 void DebuggerConnectionHandler::HandleSetBpCmd(const char* json_msg) {
489 int msg_id = msgbuf_->MessageId(); 568 int msg_id = msgbuf_->MessageId();
490 const char* params = msgbuf_->Params(); 569 char* url_chars = msgbuf_->GetStringParam("url");
491 ASSERT(params != NULL); 570 ASSERT(url_chars != NULL);
492 dart::JSONReader pr(params);
493 pr.Seek("url");
494 ASSERT(pr.Type() == dart::JSONReader::kString);
495 char url_chars[128];
496 pr.GetValueChars(url_chars, sizeof(url_chars));
497 Dart_Handle url = Dart_NewString(url_chars); 571 Dart_Handle url = Dart_NewString(url_chars);
498 ASSERT_NOT_ERROR(url); 572 ASSERT_NOT_ERROR(url);
499 pr.Seek("line"); 573 free(url_chars);
500 ASSERT(pr.Type() == dart::JSONReader::kInteger); 574 url_chars = NULL;
501 intptr_t line_number = atoi(pr.ValueChars()); 575 intptr_t line_number = msgbuf_->GetIntParam("line");
502 Dart_Handle bp_id = Dart_SetBreakpoint(url, line_number); 576 Dart_Handle bp_id = Dart_SetBreakpoint(url, line_number);
503 if (Dart_IsError(bp_id)) { 577 if (Dart_IsError(bp_id)) {
504 SendError(msg_id, Dart_GetError(bp_id)); 578 SendError(msg_id, Dart_GetError(bp_id));
505 return; 579 return;
506 } 580 }
507 ASSERT(Dart_IsInteger(bp_id)); 581 ASSERT(Dart_IsInteger(bp_id));
508 uint64_t bp_id_value; 582 uint64_t bp_id_value;
509 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value); 583 Dart_Handle res = Dart_IntegerToUint64(bp_id, &bp_id_value);
510 ASSERT_NOT_ERROR(res); 584 ASSERT_NOT_ERROR(res);
511 dart::TextBuffer msg(64); 585 dart::TextBuffer msg(64);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 661
588 662
589 void DebuggerConnectionHandler::HandleMessages() { 663 void DebuggerConnectionHandler::HandleMessages() {
590 static JSONDebuggerCommand debugger_commands[] = { 664 static JSONDebuggerCommand debugger_commands[] = {
591 { "resume", HandleResumeCmd }, 665 { "resume", HandleResumeCmd },
592 { "getLibraries", HandleGetLibrariesCmd }, 666 { "getLibraries", HandleGetLibrariesCmd },
593 { "getClassProperties", HandleGetClassPropsCmd }, 667 { "getClassProperties", HandleGetClassPropsCmd },
594 { "getLibraryProperties", HandleGetLibPropsCmd }, 668 { "getLibraryProperties", HandleGetLibPropsCmd },
595 { "getObjectProperties", HandleGetObjPropsCmd }, 669 { "getObjectProperties", HandleGetObjPropsCmd },
596 { "getScriptURLs", HandleGetScriptURLsCmd }, 670 { "getScriptURLs", HandleGetScriptURLsCmd },
671 { "getScriptSource", HandleGetSourceCmd },
597 { "getStackTrace", HandleGetStackTraceCmd }, 672 { "getStackTrace", HandleGetStackTraceCmd },
598 { "setBreakpoint", HandleSetBpCmd }, 673 { "setBreakpoint", HandleSetBpCmd },
599 { "removeBreakpoint", HandleRemBpCmd }, 674 { "removeBreakpoint", HandleRemBpCmd },
600 { "stepInto", HandleStepIntoCmd }, 675 { "stepInto", HandleStepIntoCmd },
601 { "stepOut", HandleStepOutCmd }, 676 { "stepOut", HandleStepOutCmd },
602 { "stepOver", HandleStepOverCmd }, 677 { "stepOver", HandleStepOverCmd },
603 { NULL, NULL } 678 { NULL, NULL }
604 }; 679 };
605 680
606 for (;;) { 681 for (;;) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 Dart_ExitScope(); 750 Dart_ExitScope();
676 } 751 }
677 752
678 753
679 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id, 754 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id,
680 Dart_Handle url, 755 Dart_Handle url,
681 intptr_t line_number) { 756 intptr_t line_number) {
682 Dart_EnterScope(); 757 Dart_EnterScope();
683 dart::TextBuffer msg(128); 758 dart::TextBuffer msg(128);
684 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {"); 759 msg.Printf("{ \"event\": \"breakpointResolved\", \"params\": {");
685 msg.Printf("\"breakpointId\": %d, ", bp_id); 760 msg.Printf("\"breakpointId\": %d, \"url\":", bp_id);
686 char const* url_chars; 761 FormatEncodedString(&msg, url);
687 Dart_StringToCString(url, &url_chars); 762 msg.Printf(",\"line\": %d }}", line_number);
688 msg.Printf("\"url\": \"%s\", ", url_chars);
689 msg.Printf("\"line\": %d }}", line_number);
690 QueueMsg(&msg); 763 QueueMsg(&msg);
691 Dart_ExitScope(); 764 Dart_ExitScope();
692 } 765 }
693 766
694 767
695 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) { 768 void DebuggerConnectionHandler::AcceptDbgConnection(int debugger_fd) {
696 debugger_fd_ = debugger_fd; 769 debugger_fd_ = debugger_fd;
697 ASSERT(msgbuf_ == NULL); 770 ASSERT(msgbuf_ == NULL);
698 msgbuf_ = new MessageBuffer(debugger_fd_); 771 msgbuf_ = new MessageBuffer(debugger_fd_);
699 { 772 {
(...skipping 27 matching lines...) Expand all
727 handler_started_ = true; 800 handler_started_ = true;
728 DebuggerConnectionImpl::StartHandler(port_number); 801 DebuggerConnectionImpl::StartHandler(port_number);
729 Dart_SetBreakpointHandler(BreakpointHandler); 802 Dart_SetBreakpointHandler(BreakpointHandler);
730 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); 803 Dart_SetBreakpointResolvedHandler(BptResolvedHandler);
731 } 804 }
732 805
733 806
734 DebuggerConnectionHandler::~DebuggerConnectionHandler() { 807 DebuggerConnectionHandler::~DebuggerConnectionHandler() {
735 CloseDbgConnection(); 808 CloseDbgConnection();
736 } 809 }
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