From: Oto Šťáva Date: Mon, 18 Mar 2024 11:21:28 +0000 (+0100) Subject: kresctl debug: add --print-only and be silent by default X-Git-Tag: v6.0.10~9^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=243b30c9dbdc1500706db029f88c6c1d3bed3e08;p=thirdparty%2Fknot-resolver.git kresctl debug: add --print-only and be silent by default --- diff --git a/doc/user/manager-client.rst b/doc/user/manager-client.rst index 03a2d9eb8..7d43a07f1 100644 --- a/doc/user/manager-client.rst +++ b/doc/user/manager-client.rst @@ -382,6 +382,11 @@ single ``kresctl`` command. Use a custom GDB executable. This may be a command on ``PATH``, or an absolute path to an executable. + .. option:: --print-only + + Prints the GDB command line into ``stderr`` as a Python array, does not + execute GDB. + .. _manager-client-subprocess-types: diff --git a/python/knot_resolver/client/commands/debug.py b/python/knot_resolver/client/commands/debug.py index cd12db50d..5d9a81df0 100644 --- a/python/knot_resolver/client/commands/debug.py +++ b/python/knot_resolver/client/commands/debug.py @@ -18,6 +18,7 @@ class DebugCommand(Command): self.proc_type: Optional[str] = namespace.proc_type self.sudo: bool = namespace.sudo self.gdb: str = namespace.gdb + self.print_only: bool = namespace.print_only self.gdb_args: List[str] = namespace.extra super().__init__(namespace) @@ -41,6 +42,7 @@ class DebugCommand(Command): dest="sudo", help="Run GDB with sudo", action="store_true", + default=False, ) debug.add_argument( "--gdb", @@ -48,6 +50,12 @@ class DebugCommand(Command): type=str, default=None, ) + debug.add_argument( + "--print-only", + help="Prints the GDB command line into stderr as a Python array, does not execute GDB", + action="store_true", + default=False, + ) return debug, DebugCommand @staticmethod @@ -105,7 +113,7 @@ class DebugCommand(Command): # Attach GDB to processes - the processes are attached using the `add-inferior` and `attach` GDB # commands. This way, we can debug multiple processes. - exec_args.extend([gdb_cmd]) + exec_args.extend([gdb_cmd, "--"]) exec_args.extend(["-init-eval-command", "set detach-on-fork off"]) exec_args.extend(["-init-eval-command", "set schedule-multiple on"]) exec_args.extend(["-init-eval-command", f'attach {procs[0]["pid"]}']) @@ -130,5 +138,7 @@ class DebugCommand(Command): ) exec_args.extend(self.gdb_args) - print(f"exec_args = {exec_args}") - os.execl(*exec_args) + if self.print_only: + print(f"{exec_args}") + else: + os.execl(*exec_args)