| OLD | NEW |
| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 ASSERT(Dart_IsString(lib_url)); | 402 ASSERT(Dart_IsString(lib_url)); |
| 403 msg.Printf("%s{\"id\":%d,\"url\":", (i == 0) ? "" : ", ", lib_id); | 403 msg.Printf("%s{\"id\":%d,\"url\":", (i == 0) ? "" : ", ", lib_id); |
| 404 FormatEncodedString(&msg, lib_url); | 404 FormatEncodedString(&msg, lib_url); |
| 405 msg.Printf("}"); | 405 msg.Printf("}"); |
| 406 } | 406 } |
| 407 msg.Printf("]}}"); | 407 msg.Printf("]}}"); |
| 408 SendMsg(&msg); | 408 SendMsg(&msg); |
| 409 } | 409 } |
| 410 | 410 |
| 411 | 411 |
| 412 static void FormatField(dart::TextBuffer* buf, | 412 static void FormatRemoteObj(dart::TextBuffer* buf, Dart_Handle object) { |
| 413 Dart_Handle object_name, | |
| 414 Dart_Handle object) { | |
| 415 ASSERT(Dart_IsString(object_name)); | |
| 416 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); | |
| 417 intptr_t obj_id = Dart_CacheObject(object); | 413 intptr_t obj_id = Dart_CacheObject(object); |
| 418 ASSERT(obj_id >= 0); | 414 ASSERT(obj_id >= 0); |
| 419 buf->Printf("\"value\":{\"objectId\":%d,", obj_id); | 415 buf->Printf("{\"objectId\":%d,", obj_id); |
| 420 const char* kind = "object"; | 416 const char* kind = "object"; |
| 421 if (Dart_IsInteger(object)) { | 417 if (Dart_IsInteger(object)) { |
| 422 kind = "integer"; | 418 kind = "integer"; |
| 423 } else if (Dart_IsString(object)) { | 419 } else if (Dart_IsString(object)) { |
| 424 kind = "string"; | 420 kind = "string"; |
| 425 } else if (Dart_IsBoolean(object)) { | 421 } else if (Dart_IsBoolean(object)) { |
| 426 kind = "boolean"; | 422 kind = "boolean"; |
| 427 } | 423 } |
| 428 buf->Printf("\"kind\":\"%s\",", kind); | 424 buf->Printf("\"kind\":\"%s\",", kind); |
| 429 buf->Printf("\"text\":"); | 425 buf->Printf("\"text\":"); |
| 430 Dart_Handle text; | 426 Dart_Handle text; |
| 431 if (Dart_IsNull(object)) { | 427 if (Dart_IsNull(object)) { |
| 432 text = Dart_Null(); | 428 text = Dart_Null(); |
| 433 } else { | 429 } else { |
| 434 text = Dart_ToString(object); | 430 text = Dart_ToString(object); |
| 435 } | 431 } |
| 436 if (Dart_IsNull(text)) { | 432 if (Dart_IsNull(text)) { |
| 437 buf->Printf("null"); | 433 buf->Printf("null"); |
| 438 } else if (Dart_IsError(text)) { | 434 } else if (Dart_IsError(text)) { |
| 439 FormatErrorMsg(buf, text); | 435 FormatErrorMsg(buf, text); |
| 440 } else { | 436 } else { |
| 441 FormatEncodedString(buf, text); | 437 FormatEncodedString(buf, text); |
| 442 } | 438 } |
| 443 buf->Printf("}}"); | 439 buf->Printf("}"); |
| 440 } |
| 441 |
| 442 |
| 443 static void FormatField(dart::TextBuffer* buf, |
| 444 Dart_Handle object_name, |
| 445 Dart_Handle object) { |
| 446 ASSERT(Dart_IsString(object_name)); |
| 447 buf->Printf("{\"name\":\"%s\",", GetStringChars(object_name)); |
| 448 buf->Printf("\"value\":"); |
| 449 FormatRemoteObj(buf, object); |
| 450 buf->Printf("}"); |
| 444 } | 451 } |
| 445 | 452 |
| 446 | 453 |
| 447 static void FormatFieldList(dart::TextBuffer* buf, | 454 static void FormatFieldList(dart::TextBuffer* buf, |
| 448 Dart_Handle obj_list) { | 455 Dart_Handle obj_list) { |
| 449 ASSERT(Dart_IsList(obj_list)); | 456 ASSERT(Dart_IsList(obj_list)); |
| 450 intptr_t list_length = 0; | 457 intptr_t list_length = 0; |
| 451 Dart_Handle res = Dart_ListLength(obj_list, &list_length); | 458 Dart_Handle res = Dart_ListLength(obj_list, &list_length); |
| 452 ASSERT_NOT_ERROR(res); | 459 ASSERT_NOT_ERROR(res); |
| 453 ASSERT(list_length % 2 == 0); | 460 ASSERT(list_length % 2 == 0); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 } | 748 } |
| 742 if (!is_handled) { | 749 if (!is_handled) { |
| 743 printf("unrecognized command received: '%s'\n", msgbuf_->buf()); | 750 printf("unrecognized command received: '%s'\n", msgbuf_->buf()); |
| 744 HandleUnknownMsg(msgbuf_->buf()); | 751 HandleUnknownMsg(msgbuf_->buf()); |
| 745 msgbuf_->PopMessage(); | 752 msgbuf_->PopMessage(); |
| 746 } | 753 } |
| 747 } | 754 } |
| 748 } | 755 } |
| 749 | 756 |
| 750 | 757 |
| 751 void DebuggerConnectionHandler::SendBreakpointEvent(Dart_Breakpoint bpt, | 758 void DebuggerConnectionHandler::WaitForConnection() { |
| 752 Dart_StackTrace trace) { | 759 MonitorLocker ml(&is_connected_); |
| 760 while (!IsConnected()) { |
| 761 printf("Waiting for debugger connection...\n"); |
| 762 dart::Monitor::WaitResult res = ml.Wait(dart::Monitor::kNoTimeout); |
| 763 ASSERT(res == dart::Monitor::kNotified); |
| 764 } |
| 765 } |
| 766 |
| 767 |
| 768 void DebuggerConnectionHandler::SendBreakpointEvent(Dart_StackTrace trace) { |
| 753 dart::TextBuffer msg(128); | 769 dart::TextBuffer msg(128); |
| 754 msg.Printf("{ \"event\": \"paused\", \"params\": { "); | 770 msg.Printf("{ \"event\": \"paused\", \"params\": { "); |
| 771 msg.Printf("\"reason\": \"breakpoint\", "); |
| 755 FormatCallFrames(&msg, trace); | 772 FormatCallFrames(&msg, trace); |
| 756 msg.Printf("}}"); | 773 msg.Printf("}}"); |
| 757 SendMsg(&msg); | 774 SendMsg(&msg); |
| 758 } | 775 } |
| 759 | 776 |
| 760 | 777 |
| 761 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt, | 778 void DebuggerConnectionHandler::BreakpointHandler(Dart_Breakpoint bpt, |
| 762 Dart_StackTrace trace) { | 779 Dart_StackTrace trace) { |
| 763 { | 780 WaitForConnection(); |
| 764 MonitorLocker ml(&is_connected_); | |
| 765 while (!IsConnected()) { | |
| 766 printf("Waiting for debugger connection...\n"); | |
| 767 dart::Monitor::WaitResult res = ml.Wait(dart::Monitor::kNoTimeout); | |
| 768 ASSERT(res == dart::Monitor::kNotified); | |
| 769 } | |
| 770 } | |
| 771 Dart_EnterScope(); | 781 Dart_EnterScope(); |
| 772 SendQueuedMsgs(); | 782 SendQueuedMsgs(); |
| 773 SendBreakpointEvent(bpt, trace); | 783 SendBreakpointEvent(trace); |
| 774 HandleMessages(); | 784 HandleMessages(); |
| 775 if (!msgbuf_->Alive()) { | 785 if (!msgbuf_->Alive()) { |
| 776 CloseDbgConnection(); | 786 CloseDbgConnection(); |
| 787 } |
| 788 Dart_ExitScope(); |
| 789 } |
| 790 |
| 791 |
| 792 void DebuggerConnectionHandler::SendExceptionEvent( |
| 793 Dart_Handle exception, |
| 794 Dart_StackTrace stack_trace) { |
| 795 intptr_t exception_id = Dart_CacheObject(exception); |
| 796 ASSERT(exception_id >= 0); |
| 797 dart::TextBuffer msg(128); |
| 798 msg.Printf("{ \"event\": \"paused\", \"params\": {"); |
| 799 msg.Printf("\"reason\": \"exception\", "); |
| 800 msg.Printf("\"exception\":"); |
| 801 FormatRemoteObj(&msg, exception); |
| 802 msg.Printf(", "); |
| 803 FormatCallFrames(&msg, stack_trace); |
| 804 msg.Printf("}}"); |
| 805 SendMsg(&msg); |
| 806 } |
| 807 |
| 808 |
| 809 void DebuggerConnectionHandler::ExceptionThrownHandler( |
| 810 Dart_Handle exception, |
| 811 Dart_StackTrace stack_trace) { |
| 812 WaitForConnection(); |
| 813 Dart_EnterScope(); |
| 814 SendQueuedMsgs(); |
| 815 SendExceptionEvent(exception, stack_trace); |
| 816 HandleMessages(); |
| 817 if (!msgbuf_->Alive()) { |
| 818 CloseDbgConnection(); |
| 777 } | 819 } |
| 778 Dart_ExitScope(); | 820 Dart_ExitScope(); |
| 779 } | 821 } |
| 780 | 822 |
| 781 | 823 |
| 782 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id, | 824 void DebuggerConnectionHandler::BptResolvedHandler(intptr_t bp_id, |
| 783 Dart_Handle url, | 825 Dart_Handle url, |
| 784 intptr_t line_number) { | 826 intptr_t line_number) { |
| 785 Dart_EnterScope(); | 827 Dart_EnterScope(); |
| 786 dart::TextBuffer msg(128); | 828 dart::TextBuffer msg(128); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 if (handler_started_) { | 864 if (handler_started_) { |
| 823 return; | 865 return; |
| 824 } | 866 } |
| 825 ASSERT(listener_fd_ == -1); | 867 ASSERT(listener_fd_ == -1); |
| 826 listener_fd_ = ServerSocket::CreateBindListen(address, port_number, 1); | 868 listener_fd_ = ServerSocket::CreateBindListen(address, port_number, 1); |
| 827 | 869 |
| 828 handler_started_ = true; | 870 handler_started_ = true; |
| 829 DebuggerConnectionImpl::StartHandler(port_number); | 871 DebuggerConnectionImpl::StartHandler(port_number); |
| 830 Dart_SetBreakpointHandler(BreakpointHandler); | 872 Dart_SetBreakpointHandler(BreakpointHandler); |
| 831 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); | 873 Dart_SetBreakpointResolvedHandler(BptResolvedHandler); |
| 874 Dart_SetExceptionThrownHandler(ExceptionThrownHandler); |
| 832 } | 875 } |
| 833 | 876 |
| 834 | 877 |
| 835 DebuggerConnectionHandler::~DebuggerConnectionHandler() { | 878 DebuggerConnectionHandler::~DebuggerConnectionHandler() { |
| 836 CloseDbgConnection(); | 879 CloseDbgConnection(); |
| 837 } | 880 } |
| OLD | NEW |