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

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, 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 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..1e8a9a93e6902549b4f2f15e10df4798a5889aa9
--- /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 os.path
ppi 2015/06/24 15:14:07 This seems not to be used.
etiennej 2015/06/29 15:41:42 Done.
+import socket
+import struct
+
+
+class RemoteFileConnectionException(Exception):
+ def __init__(self, *args, **kwargs):
+ Exception.__init__(self, *args, **kwargs)
+
ppi 2015/06/24 15:14:07 Two blank lines please.
etiennej 2015/06/29 15:41:42 Done.
+class RemoteFileConnection(object):
+ """Client for remote_file_reader server, allowing to read files on an
+ remote device."""
ppi 2015/06/24 15:14:07 The closing triple quote should be on the next lin
etiennej 2015/06/29 15:41:42 Done.
+ 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")
+
+ def connect(self):
+ self.socket.connect((self.host, self.port))
+
+ def close(self):
+ self.socket.close()
+
+ def open(self, filename):
+ 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):
ppi 2015/06/24 15:14:07 Remove spaces around "=".
etiennej 2015/06/29 15:41:42 Done.
+ self._send("S %d %d\n" % (pos, mode))
+ result = self._receive(1)
+ if result != 'O':
+ raise RemoteFileConnectionException("Unable to open file.")
+
+ 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")
+ 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)
+
ppi 2015/06/24 15:14:07 Remove the blank line.
etiennej 2015/06/29 15:41:42 Done.

Powered by Google App Engine
This is Rietveld 408576698