]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kresctl debug: add --print-only and be silent by default
authorOto Šťáva <oto.stava@nic.cz>
Mon, 18 Mar 2024 11:21:28 +0000 (12:21 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 3 Dec 2024 10:50:01 +0000 (11:50 +0100)
doc/user/manager-client.rst
python/knot_resolver/client/commands/debug.py

index 03a2d9eb84fe196bea5c463b868a5464387cc19d..7d43a07f150e14af36189765806ffa8f399599a1 100644 (file)
@@ -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:
 
index cd12db50ddc276c0c6b88b0777d5fec2d209421b..5d9a81df0b1f84dceabc050f7908623750ac2cea 100644 (file)
@@ -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)