diff --git a/python-packages/gdbrunner/__init__.py b/python-packages/gdbrunner/__init__.py index b01ef6b91..bd2b72dd1 100644 --- a/python-packages/gdbrunner/__init__.py +++ b/python-packages/gdbrunner/__init__.py @@ -63,14 +63,18 @@ class ArgumentParser(argparse.ArgumentParser): msg += "\n Try specifying its location with --adb." sys.exit(msg.format(adb_path)) - if result.device == "-a": - result.device = adb.get_device(adb_path=adb_path) - elif result.device == "-d": - result.device = adb.get_usb_device(adb_path=adb_path) - elif result.device == "-e": - result.device = adb.get_emulator_device(adb_path=adb_path) - else: - result.device = adb.get_device(result.serial, adb_path=adb_path) + try: + if result.device == "-a": + result.device = adb.get_device(adb_path=adb_path) + elif result.device == "-d": + result.device = adb.get_usb_device(adb_path=adb_path) + elif result.device == "-e": + result.device = adb.get_emulator_device(adb_path=adb_path) + else: + result.device = adb.get_device(result.serial, adb_path=adb_path) + except (adb.DeviceNotFoundError, adb.NoUniqueDeviceError, RuntimeError): + # Don't error out if we can't find a device. + result.device = None return result diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py index 4993ad590..4fb6c7e71 100755 --- a/scripts/gdbclient.py +++ b/scripts/gdbclient.py @@ -210,6 +210,10 @@ end def main(): args = parse_args() device = args.device + + if device is None: + sys.exit("ERROR: Failed to find device.") + props = device.get_props() root = os.environ["ANDROID_BUILD_TOP"]