| 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 #ifndef BIN_DBG_CONNECTION_H_ | 5 #ifndef BIN_DBG_CONNECTION_H_ |
| 6 #define BIN_DBG_CONNECTION_H_ | 6 #define BIN_DBG_CONNECTION_H_ |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/utils.h" | 9 #include "bin/utils.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "bin/dbg_connection_win.h" | 24 #include "bin/dbg_connection_win.h" |
| 25 #else | 25 #else |
| 26 #error Unknown target os. | 26 #error Unknown target os. |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 | 29 |
| 30 class MessageBuffer; | 30 class MessageBuffer; |
| 31 | 31 |
| 32 class DebuggerConnectionHandler { | 32 class DebuggerConnectionHandler { |
| 33 public: | 33 public: |
| 34 explicit DebuggerConnectionHandler(int debug_fd); |
| 34 ~DebuggerConnectionHandler(); | 35 ~DebuggerConnectionHandler(); |
| 36 |
| 37 // Accessors. |
| 38 int debug_fd() const { return debug_fd_; } |
| 39 |
| 40 // Return message id of current debug command message. |
| 41 int MessageId(); |
| 42 |
| 43 // Starts the native thread which listens for connections from |
| 44 // debugger clients, reads and dispatches debug command messages |
| 45 // from the client. |
| 35 static void StartHandler(const char* address, int port_number); | 46 static void StartHandler(const char* address, int port_number); |
| 36 | 47 |
| 37 static bool IsConnected() { | 48 // Called by Isolates when isolates need to wait for a connection |
| 38 return debugger_fd_ >= 0; | 49 // from debugger clients. |
| 39 } | 50 static void WaitForConnection(); |
| 51 |
| 52 // Sends a reply or an error message to a specific debugger client. |
| 53 static void SendMsg(int debug_fd, dart::TextBuffer* msg); |
| 54 static void SendError(int debug_fd, int msg_id, const char* err_msg); |
| 55 |
| 56 // Sends an event message to all debugger clients that are connected. |
| 57 static void BroadcastMsg(dart::TextBuffer* msg); |
| 40 | 58 |
| 41 private: | 59 private: |
| 42 static void SendMsg(dart::TextBuffer* msg); | 60 void HandleUnknownMsg(); |
| 43 static void QueueMsg(dart::TextBuffer* msg); | 61 void HandleMessages(); |
| 44 static void SendQueuedMsgs(); | |
| 45 | 62 |
| 46 static void SendBreakpointEvent(Dart_StackTrace trace); | 63 void CloseDbgConnection(); |
| 47 static void SendExceptionEvent(Dart_Handle exception, Dart_StackTrace trace); | |
| 48 static void BptResolvedHandler(intptr_t bp_id, | |
| 49 Dart_Handle url, | |
| 50 intptr_t line_number); | |
| 51 static void BreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace); | |
| 52 static void ExceptionThrownHandler(Dart_Handle exception, | |
| 53 Dart_StackTrace stack_trace); | |
| 54 | 64 |
| 65 // The socket that connects with the debugger client. |
| 66 // The descriptor is created and closed by the debugger connection thread. |
| 67 int debug_fd_; |
| 68 |
| 69 // Buffer holding the messages received over the wire from the debugger |
| 70 // front end.. |
| 71 MessageBuffer* msgbuf_; |
| 72 |
| 73 // Accepts connection requests from debugger client and sets up a |
| 74 // connection handler object to read and handle messages from the client. |
| 55 static void AcceptDbgConnection(int debug_fd); | 75 static void AcceptDbgConnection(int debug_fd); |
| 56 static void WaitForConnection(); | |
| 57 static void CloseDbgConnection(); | |
| 58 | 76 |
| 59 static void HandleMessages(); | 77 // Handlers for generic debug command messages which are not specific to |
| 60 static void HandleResumeCmd(const char* msg); | 78 // an isolate. |
| 61 static void HandleStepIntoCmd(const char* msg); | 79 static void HandleInterruptCmd(DebuggerConnectionHandler* handler); |
| 62 static void HandleStepOverCmd(const char* msg); | 80 static void HandleIsolatesListCmd(DebuggerConnectionHandler* handler); |
| 63 static void HandleStepOutCmd(const char* msg); | 81 static void HandleQuitCmd(DebuggerConnectionHandler* handler); |
| 64 static void HandleGetLibrariesCmd(const char* json_msg); | |
| 65 static void HandleGetClassPropsCmd(const char* json_msg); | |
| 66 static void HandleGetLibPropsCmd(const char* json_msg); | |
| 67 static void HandleSetLibPropsCmd(const char* json_msg); | |
| 68 static void HandleGetGlobalsCmd(const char* json_msg); | |
| 69 static void HandleGetObjPropsCmd(const char* json_msg); | |
| 70 static void HandleGetListCmd(const char* json_msg); | |
| 71 static void HandleGetScriptURLsCmd(const char* json_msg); | |
| 72 static void HandleGetSourceCmd(const char* json_msg); | |
| 73 static void HandleGetStackTraceCmd(const char* json_msg); | |
| 74 static void HandlePauseOnExcCmd(const char* json_msg); | |
| 75 static void HandleSetBpCmd(const char* json_msg); | |
| 76 static void HandleRemBpCmd(const char* json_msg); | |
| 77 static void HandleUnknownMsg(const char* json_msg); | |
| 78 | 82 |
| 79 static void SendError(int msg_id, const char* err_msg); | 83 // Helper methods to manage debugger client connections. |
| 84 static void AddNewDebuggerConnection(int debug_fd); |
| 85 static void RemoveDebuggerConnection(int debug_fd); |
| 86 static DebuggerConnectionHandler* GetDebuggerConnectionHandler(int debug_fd); |
| 87 static bool IsConnected(); |
| 80 | 88 |
| 81 // Text buffer that accumulates messages to be sent to front end. | 89 // Helper method for sending messages back to a debugger client. |
| 82 static dart::TextBuffer queued_messages_; | 90 static void SendMsgHelper(int debug_fd, dart::TextBuffer* msg); |
| 83 | 91 |
| 84 static bool handler_started_; | 92 // mutex/condition variable used by isolates when writing back to the |
| 85 | 93 // debugger. This is also used to ensure that the isolate waits for |
| 86 static bool request_resume_; | 94 // a debugger to be attached when that is requested on the command line. |
| 95 static dart::Monitor handler_lock_; |
| 87 | 96 |
| 88 // The socket that is listening for incoming debugger connections. | 97 // The socket that is listening for incoming debugger connections. |
| 89 // This descriptor is created and closed by a VM thread. | 98 // This descriptor is created and closed by a native thread. |
| 90 static int listener_fd_; | 99 static int listener_fd_; |
| 91 | 100 |
| 92 // The socket that connects with the debugger client. | |
| 93 // The descriptor is created by the debugger connection thread and | |
| 94 // closed by a VM thread. | |
| 95 static int debugger_fd_; | |
| 96 | |
| 97 // The VM thread waits on this condition variable when it reaches a | |
| 98 // breakpoint and the debugger client has not connected yet. | |
| 99 static dart::Monitor is_connected_; | |
| 100 | |
| 101 static MessageBuffer* msgbuf_; | |
| 102 | |
| 103 friend class DebuggerConnectionImpl; | 101 friend class DebuggerConnectionImpl; |
| 104 | 102 |
| 105 DISALLOW_ALLOCATION(); | |
| 106 DISALLOW_IMPLICIT_CONSTRUCTORS(DebuggerConnectionHandler); | 103 DISALLOW_IMPLICIT_CONSTRUCTORS(DebuggerConnectionHandler); |
| 107 }; | 104 }; |
| 108 | 105 |
| 109 #endif // BIN_DBG_CONNECTION_H_ | 106 #endif // BIN_DBG_CONNECTION_H_ |
| OLD | NEW |