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

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

Issue 10572028: Implement the linux debugger 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
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 <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 <sys/epoll.h>
9 #include <unistd.h>
10 9
11 #include "bin/dbg_connection.h" 10 #include "bin/dbg_connection.h"
12 #include "bin/fdutils.h" 11 #include "bin/fdutils.h"
13 #include "bin/socket.h" 12 #include "bin/socket.h"
14 13
14 int DebuggerConnectionImpl::epoll_fd_ = -1;
15 int DebuggerConnectionImpl::wakeup_fds_[2] = {-1, -1};
siva 2012/06/20 00:53:31 It is not clear when epoll_fd_, wakeup_fds_ and li
hausner 2012/06/20 16:05:58 They are currently never closed. The Socket class
16
17
18 void DebuggerConnectionImpl::HandleEvent(struct epoll_event* event) {
19 if (event->data.fd == DebuggerConnectionHandler::listener_fd_) {
20 if (DebuggerConnectionHandler::IsConnected()) {
21 FATAL("Cannot connect to more than one debugger.\n");
22 }
23 int fd = ServerSocket::Accept(event->data.fd);
24 if (fd < 0) {
25 FATAL("Accepting new debugger connection failed.\n");
26 }
27 FDUtils::SetBlocking(fd);
28 DebuggerConnectionHandler::AcceptDbgConnection(fd);
29 // TODO(hausner): add the debugger wire socket fd to the event poll queue
30 // once we poll the debugger connection.
31 } else if (event->data.fd == DebuggerConnectionHandler::debugger_fd_) {
32 printf("unexpected: receiving debugger connection event.\n");
33 UNIMPLEMENTED();
34 } else {
35 // Sync message. Not yet implemented.
36 UNIMPLEMENTED();
37 }
38 }
39
40
41 void DebuggerConnectionImpl::Handler(uword args) {
42 static const intptr_t kMaxEvents = 4;
43 struct epoll_event events[kMaxEvents];
44 while (1) {
45 const int no_timeout = -1;
46 intptr_t result = TEMP_FAILURE_RETRY(
47 epoll_wait(epoll_fd_, events, kMaxEvents, no_timeout));
48 ASSERT(EAGAIN == EWOULDBLOCK);
49 if (result == -1) {
50 if (errno != EWOULDBLOCK) {
51 perror("epoll_wait failed");
52 }
53 } else {
54 ASSERT(result <= kMaxEvents);
55 for (int i = 0; i < result; i++) {
56 HandleEvent(&events[i]);
57 }
58 }
59 }
60 }
61
62
63 void DebuggerConnectionImpl::SetupPollQueue() {
64 int result;
65 result = TEMP_FAILURE_RETRY(pipe(wakeup_fds_));
siva 2012/06/20 00:53:31 int result = TEMP.... instead of two lines.
hausner 2012/06/20 16:05:58 Done.
66 if (result != 0) {
67 FATAL1("Pipe creation failed with error %d\n", result);
68 }
69 FDUtils::SetNonBlocking(wakeup_fds_[0]);
70
71 static const int kEpollInitialSize = 16;
72 epoll_fd_ = TEMP_FAILURE_RETRY(epoll_create(kEpollInitialSize));
73 if (epoll_fd_ == -1) {
74 FATAL("Failed creating epoll file descriptor");
75 }
76
77 // Register the wakeup _fd with the epoll instance.
78 struct epoll_event event;
79 event.events = EPOLLIN;
80 event.data.fd = wakeup_fds_[0];
81 int status = TEMP_FAILURE_RETRY(epoll_ctl(
82 epoll_fd_, EPOLL_CTL_ADD, wakeup_fds_[0], &event));
83 if (status == -1) {
84 FATAL("Failed adding wakeup fd to epoll instance");
85 }
86
87 // Register the wakeup_fd with the epoll instance.
siva 2012/06/20 00:53:31 Register the listener_fd_ with the epoll instance.
hausner 2012/06/20 16:05:58 Done.
88 event.events = EPOLLIN;
89 event.data.fd = DebuggerConnectionHandler::listener_fd_;
90 status = TEMP_FAILURE_RETRY(epoll_ctl(epoll_fd_, EPOLL_CTL_ADD,
91 DebuggerConnectionHandler::listener_fd_, &event));
92 if (status == -1) {
93 FATAL("Failed adding listener fd to epoll instance");
94 }
95 }
96
15 97
16 void DebuggerConnectionImpl::StartHandler(int port_number) { 98 void DebuggerConnectionImpl::StartHandler(int port_number) {
17 FATAL("Debugger wire protocol not yet implemented on Linux\n"); 99 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1);
100 SetupPollQueue();
101 int result = dart::Thread::Start(&DebuggerConnectionImpl::Handler, 0);
102 if (result != 0) {
103 FATAL1("Failed to start debugger connection handler thread: %d\n", result);
104 }
18 } 105 }
106
siva 2012/06/20 00:53:31 wasted space.
hausner 2012/06/20 16:05:58 What, the empty line after the } ? I'll add a TO
OLDNEW
« runtime/bin/dbg_connection_linux.h ('K') | « runtime/bin/dbg_connection_linux.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698