summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorDavid Pursell <dpursell@google.com>2015-10-05 14:22:10 -0700
committerDavid Pursell <dpursell@google.com>2015-10-06 09:18:36 -0700
commit320f881efeeabe670eabf26c120abc94f901ef9b (patch)
treeb8e0c0942505d4ec86b011c572d778841ad9c268 /scripts
parentf1b53b587871a16d2f444a77ea7256e6f8778c7e (diff)
downloadandroid_development-320f881efeeabe670eabf26c120abc94f901ef9b.tar.gz
android_development-320f881efeeabe670eabf26c120abc94f901ef9b.tar.bz2
android_development-320f881efeeabe670eabf26c120abc94f901ef9b.zip
gdbclient.py: add gdb connect retry.
gdbclient.py can sometimes attempt to connect to the server before it's ready, especially when debugging on an emulator. This CL adds functionality to retry the connection for up to 5 seconds. Bug: http://b/24671386 Change-Id: I65e77f918c3ea8433f992e67122cd48e3647c67b
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gdbclient.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py
index df924eb39..811d564e7 100755
--- a/scripts/gdbclient.py
+++ b/scripts/gdbclient.py
@@ -140,7 +140,7 @@ def handle_switches(args):
return (binary_file, pid, run_cmd)
-def generate_gdb_script(sysroot, binary_file, is64bit, port):
+def generate_gdb_script(sysroot, binary_file, is64bit, port, connect_timeout=5):
# Generate a gdb script.
# TODO: Detect the zygote and run 'art-on' automatically.
root = os.environ["ANDROID_BUILD_TOP"]
@@ -167,7 +167,31 @@ def generate_gdb_script(sysroot, binary_file, is64bit, port):
else:
gdb_commands += "source {}\n".format(dalvik_gdb_script)
- gdb_commands += "target remote :{}\n".format(port)
+ # Try to connect for a few seconds, sometimes the device gdbserver takes
+ # a little bit to come up, especially on emulators.
+ gdb_commands += """
+python
+
+def target_remote_with_retry(target, timeout_seconds):
+ import time
+ end_time = time.time() + timeout_seconds
+ while True:
+ try:
+ gdb.execute("target remote " + target)
+ return True
+ except gdb.error as e:
+ time_left = end_time - time.time()
+ if time_left < 0 or time_left > timeout_seconds:
+ print("Error: unable to connect to device.")
+ print(e)
+ return False
+ time.sleep(min(0.25, time_left))
+
+target_remote_with_retry(':{}', {})
+
+end
+""".format(port, connect_timeout)
+
return gdb_commands