blob: 1e548ef08a867979cff031ff26243fed86e7a683 [file] [log] [blame] [edit]
# Copyright 2025 The Fuchsia 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 asyncio
import sys
import package_server
async def main(args: list[str] = sys.argv[1:]) -> int:
async with package_server.ensure_running():
# TODO(https://fxbug.dev/464692993): Refactor `//scripts/fxtest/python/debugger.py` into a
# shared library and use it here.
ffx_cmd = await asyncio.subprocess.create_subprocess_exec(
"ffx", "debug", "connect", *args, stdin=sys.stdin
)
try:
return await ffx_cmd.wait()
except asyncio.CancelledError:
# This block triggers if the python script receives SIGINT (Ctrl+C)
# or SIGTERM, and zxdb hasn't already exited.
# Gracefully shutdown zxdb.
ffx_cmd.terminate()
# Give zxdb a few seconds to clean up internal state
await asyncio.wait_for(ffx_cmd.wait(), timeout=3.0)
# Forcefully kill zxdb if it hasn't stopped yet.
if ffx_cmd.returncode is None:
ffx_cmd.kill()
await ffx_cmd.wait()
return -9
return ffx_cmd.returncode
if __name__ == "__main__":
sys.exit(asyncio.run(main()))