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

Unified Diff: mojo/devtools/common/android_gdb/remote_file_connection.py

Issue 1209593002: GDB support for Android in devtools' debugger. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: mojo/devtools/common/android_gdb/remote_file_connection.py
diff --git a/mojo/devtools/common/android_gdb/remote_file_connection.py b/mojo/devtools/common/android_gdb/remote_file_connection.py
new file mode 100644
index 0000000000000000000000000000000000000000..95247d59d3e4e13f5554bb24b3db434887eaae7d
--- /dev/null
+++ b/mojo/devtools/common/android_gdb/remote_file_connection.py
@@ -0,0 +1,66 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import socket
+import struct
+
+
+class RemoteFileConnectionException(Exception):
+ def __init__(self, *args, **kwargs):
+ Exception.__init__(self, *args, **kwargs)
+
+
+class RemoteFileConnection(object):
+ """Client for remote_file_reader server, allowing to read files on an
+ remote device.
+ """
+ def __init__(self, host, port):
+ self.host = host
+ self.port = port
+ self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self._size_struct = struct.Struct("!i")
ppi 2015/07/09 13:12:39 is "size_struct" the only private member? Should a
etiennej 2015/07/15 07:13:20 Done.
+
+ def connect(self):
+ self.socket.connect((self.host, self.port))
+
+ def close(self):
ppi 2015/07/09 13:12:39 if this is a pair for "connect", let's call it "di
qsr 2015/07/09 13:54:18 It has to be called close (and is in fact a pair f
qsr 2015/07/09 14:06:16 Ok, I was mis-remembering, we do not ever close th
etiennej 2015/07/15 07:13:20 Done.
+ self.socket.close()
+
+ def open(self, filename):
ppi 2015/07/09 13:12:39 When the file will be closed on the remote side? I
qsr 2015/07/09 13:54:18 The file will be closed when you disconnect, or wh
etiennej 2015/07/15 07:13:20 Acknowledged.
+ self._send("O %s\n" % filename)
+ result = self._receive(1)
+ if result != 'O':
+ raise RemoteFileConnectionException("Unable to open file " + filename)
+
+ def seek(self, pos, mode=0):
+ self._send("S %d %d\n" % (pos, mode))
+ result = self._receive(1)
+ if result != 'O':
+ raise RemoteFileConnectionException("Unable to open file.")
ppi 2015/07/09 13:12:38 Update the exception message here and below.
etiennej 2015/07/15 07:13:20 Done.
+
+ def read(self, size=0):
+ assert size > 0
+ self._send("R %d\n" % size)
+ result = self._receive(1)
+ if result != 'O':
+ raise RemoteFileConnectionException("Unable to open file.")
+ read_size = self._size_struct.unpack(self._receive(4))[0]
+ return self._receive(read_size)
+
+ def _send(self, data):
+ while len(data) > 0:
+ sent = self.socket.send(data)
+ if sent == 0:
+ raise RemoteFileConnectionException("socket connection broken")
ppi 2015/07/09 13:12:39 Capitalize and end with a period to match the othe
etiennej 2015/07/15 07:13:20 Done.
+ data = data[sent:]
+
+ def _receive(self, length):
+ result = []
+ while length > 0:
+ chunk = self.socket.recv(length)
+ if chunk == '':
+ raise RemoteFileConnectionException("socket connection broken")
+ result.append(chunk)
+ length -= len(chunk)
+ return ''.join(result)

Powered by Google App Engine
This is Rietveld 408576698