| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/event.h> | 9 #include <sys/event.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| 11 | 11 |
| 12 #include "bin/dartutils.h" | 12 #include "bin/dartutils.h" |
| 13 #include "bin/dbg_connection.h" | 13 #include "bin/dbg_connection.h" |
| 14 #include "bin/fdutils.h" | 14 #include "bin/fdutils.h" |
| 15 #include "bin/log.h" |
| 15 #include "bin/socket.h" | 16 #include "bin/socket.h" |
| 16 #include "platform/thread.h" | 17 #include "platform/thread.h" |
| 17 #include "platform/utils.h" | 18 #include "platform/utils.h" |
| 18 | 19 |
| 19 | 20 |
| 20 #define INVALID_FD -1 | 21 #define INVALID_FD -1 |
| 21 | 22 |
| 22 int DebuggerConnectionImpl::kqueue_fd_ = INVALID_FD; | 23 int DebuggerConnectionImpl::kqueue_fd_ = INVALID_FD; |
| 23 int DebuggerConnectionImpl::wakeup_fds_[2] = {INVALID_FD, INVALID_FD}; | 24 int DebuggerConnectionImpl::wakeup_fds_[2] = {INVALID_FD, INVALID_FD}; |
| 24 | 25 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 EV_SET(&ev_add, fd, EVFILT_READ, EV_ADD, 0, 0, NULL); | 81 EV_SET(&ev_add, fd, EVFILT_READ, EV_ADD, 0, 0, NULL); |
| 81 int status = | 82 int status = |
| 82 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &ev_add, 1, NULL, 0, NULL)); | 83 TEMP_FAILURE_RETRY(kevent(kqueue_fd_, &ev_add, 1, NULL, 0, NULL)); |
| 83 if (status == -1) { | 84 if (status == -1) { |
| 84 FATAL1("Failed adding debugger socket to kqueue: %s\n", strerror(errno)); | 85 FATAL1("Failed adding debugger socket to kqueue: %s\n", strerror(errno)); |
| 85 } | 86 } |
| 86 */ | 87 */ |
| 87 } else if (ident == wakeup_fds_[0]) { | 88 } else if (ident == wakeup_fds_[0]) { |
| 88 Message msg; | 89 Message msg; |
| 89 if (ReceiveMessage(&msg)) { | 90 if (ReceiveMessage(&msg)) { |
| 90 printf("Received sync message id %d.\n", msg.msg_id); | 91 Log::Print("Received sync message id %d.\n", msg.msg_id); |
| 91 } | 92 } |
| 92 } else { | 93 } else { |
| 93 printf("unexpected: receiving debugger connection event.\n"); | 94 Log::Print("unexpected: receiving debugger connection event.\n"); |
| 94 UNIMPLEMENTED(); | 95 UNIMPLEMENTED(); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 | 98 |
| 98 | 99 |
| 99 void DebuggerConnectionImpl::Handler(uword args) { | 100 void DebuggerConnectionImpl::Handler(uword args) { |
| 100 static const intptr_t kMaxEvents = 4; | 101 static const intptr_t kMaxEvents = 4; |
| 101 struct kevent events[kMaxEvents]; | 102 struct kevent events[kMaxEvents]; |
| 102 | 103 |
| 103 while (1) { | 104 while (1) { |
| 104 // Wait indefinitely for an event. | 105 // Wait indefinitely for an event. |
| 105 int result = TEMP_FAILURE_RETRY( | 106 int result = TEMP_FAILURE_RETRY( |
| 106 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL)); | 107 kevent(kqueue_fd_, NULL, 0, events, kMaxEvents, NULL)); |
| 107 if (result == -1) { | 108 if (result == -1) { |
| 108 FATAL1("kevent failed %s\n", strerror(errno)); | 109 FATAL1("kevent failed %s\n", strerror(errno)); |
| 109 } else { | 110 } else { |
| 110 ASSERT(result <= kMaxEvents); | 111 ASSERT(result <= kMaxEvents); |
| 111 for (int i = 0; i < result; i++) { | 112 for (int i = 0; i < result; i++) { |
| 112 HandleEvent(&events[i]); | 113 HandleEvent(&events[i]); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 printf("shutting down debugger thread\n"); | 117 Log::Print("shutting down debugger thread\n"); |
| 117 } | 118 } |
| 118 | 119 |
| 119 | 120 |
| 120 void DebuggerConnectionImpl::SetupPollQueue() { | 121 void DebuggerConnectionImpl::SetupPollQueue() { |
| 121 int result; | 122 int result; |
| 122 result = TEMP_FAILURE_RETRY(pipe(wakeup_fds_)); | 123 result = TEMP_FAILURE_RETRY(pipe(wakeup_fds_)); |
| 123 if (result != 0) { | 124 if (result != 0) { |
| 124 FATAL1("Pipe creation failed with error %d\n", result); | 125 FATAL1("Pipe creation failed with error %d\n", result); |
| 125 } | 126 } |
| 126 FDUtils::SetNonBlocking(wakeup_fds_[0]); | 127 FDUtils::SetNonBlocking(wakeup_fds_[0]); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 149 | 150 |
| 150 void DebuggerConnectionImpl::StartHandler(int port_number) { | 151 void DebuggerConnectionImpl::StartHandler(int port_number) { |
| 151 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1); | 152 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1); |
| 152 SetupPollQueue(); | 153 SetupPollQueue(); |
| 153 int result = | 154 int result = |
| 154 dart::Thread::Start(&DebuggerConnectionImpl::Handler, 0); | 155 dart::Thread::Start(&DebuggerConnectionImpl::Handler, 0); |
| 155 if (result != 0) { | 156 if (result != 0) { |
| 156 FATAL1("Failed to start debugger connection handler thread: %d\n", result); | 157 FATAL1("Failed to start debugger connection handler thread: %d\n", result); |
| 157 } | 158 } |
| 158 } | 159 } |
| OLD | NEW |