From b6b58a4d820c377c2c95ee71cfcb863c4737c0d3 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 15 Mar 2023 14:11:00 -0700 Subject: [PATCH] gdbclient.py: Fix gdb-remote command for non-local $ANDROID_SERIAL. As it turns out, gdbclient.py is broken when connecting to a host:port $ANDROID_SERIAL where the host is something other than localhost, because it will try to connect to a TCP socket on the host named in $ANDROID_SERIAL, while lldb-server is not even set up to listen on a TCP socket on the device (it listens on a Unix socket which gets forwarded by adb forward to localhost). Fix it by entirely removing the code that tries to connect directly to the host if the $ANDROID_SERIAL is of the form host:port. Change-Id: I91a04aa811b246c9cac82ef3b0779dc284364edf --- scripts/gdbclient.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py index 1c864beef..3ba057314 100755 --- a/scripts/gdbclient.py +++ b/scripts/gdbclient.py @@ -242,12 +242,7 @@ def handle_switches(args, sysroot): return (binary_file, pid, run_cmd) -def format_hostport(host, port): - if host is not None: - return "{}:{}".format(host, port) - return str(port) - -def generate_vscode_lldb_script(root, sysroot, binary_name, host, port, solib_search_path): +def generate_vscode_lldb_script(root, sysroot, binary_name, port, solib_search_path): # TODO It would be nice if we didn't need to copy this or run the # lldbclient.py program manually. Doing this would probably require # writing a vscode extension or modifying an existing one. @@ -263,11 +258,11 @@ def generate_vscode_lldb_script(root, sysroot, binary_name, host, port, solib_se "initCommands": ['settings append target.exec-search-paths {}'.format(' '.join(solib_search_path))], "targetCreateCommands": ["target create {}".format(binary_name), "target modules search-paths add / {}/".format(sysroot)], - "processCreateCommands": ["gdb-remote {}".format(format_hostport(host, port))] + "processCreateCommands": ["gdb-remote {}".format(str(port))] } return json.dumps(res, indent=4) -def generate_lldb_script(root, sysroot, binary_name, host, port, solib_search_path): +def generate_lldb_script(root, sysroot, binary_name, port, solib_search_path): commands = [] commands.append( 'settings append target.exec-search-paths {}'.format(' '.join(solib_search_path))) @@ -277,11 +272,11 @@ def generate_lldb_script(root, sysroot, binary_name, host, port, solib_search_pa commands.append("settings append target.source-map '/b/f/w' '{}'".format(root)) commands.append("settings append target.source-map '' '{}'".format(root)) commands.append('target modules search-paths add / {}/'.format(sysroot)) - commands.append('gdb-remote {}'.format(format_hostport(host, port))) + commands.append('gdb-remote {}'.format(str(port))) return '\n'.join(commands) -def generate_setup_script(debugger_path, sysroot, linker_search_dir, binary_file, is64bit, host, port, debugger, connect_timeout=5): +def generate_setup_script(debugger_path, sysroot, linker_search_dir, binary_file, is64bit, port, debugger, connect_timeout=5): # Generate a setup script. root = os.environ["ANDROID_BUILD_TOP"] symbols_dir = os.path.join(sysroot, "system", "lib64" if is64bit else "lib") @@ -297,10 +292,10 @@ def generate_setup_script(debugger_path, sysroot, linker_search_dir, binary_file if debugger == "vscode-lldb": return generate_vscode_lldb_script( - root, sysroot, binary_file.name, host, port, solib_search_path) + root, sysroot, binary_file.name, port, solib_search_path) elif debugger == 'lldb': return generate_lldb_script( - root, sysroot, binary_file.name, host, port, solib_search_path) + root, sysroot, binary_file.name, port, solib_search_path) else: raise Exception("Unknown debugger type " + debugger) @@ -319,11 +314,6 @@ def do_main(): if device is None: sys.exit("ERROR: Failed to find device.") - if ":" in device.serial: - host = device.serial.split(":")[0] - else: - host = None - root = os.environ["ANDROID_BUILD_TOP"] sysroot = os.path.join(os.environ["ANDROID_PRODUCT_OUT"], "symbols") @@ -389,7 +379,6 @@ def do_main(): linker_search_dir=linker_search_dir, binary_file=binary_file, is64bit=is64bit, - host=host, port=args.port, debugger=debugger)