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

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..9759cdb6ded75d5117a6981dccc0bbfedb1ceb45
--- /dev/null
+++ b/mojo/devtools/common/android_gdb/remote_file_connection.py
@@ -0,0 +1,69 @@
+# 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")
+
+ def __del__(self):
+ self.disconnect()
+
+ def connect(self):
+ self._socket.connect((self._host, self._port))
+
+ def disconnect(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):
+ self._send("S %d %d\n" % (pos, mode))
+ result = self._receive(1)
+ if result != 'O':
+ raise RemoteFileConnectionException("Unable to seek in 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 read 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)
« no previous file with comments | « mojo/devtools/common/android_gdb/install_remote_file_reader.py ('k') | mojo/devtools/common/android_gdb/session.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698