]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kresctl: debug command help message
authorOto Šťáva <oto.stava@nic.cz>
Wed, 4 Oct 2023 13:01:07 +0000 (15:01 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 3 Dec 2024 10:49:05 +0000 (11:49 +0100)
python/knot_resolver/client/commands/debug.py

index 44ab33ebdce296e0977623941c19a1ed5d3a1f51..421e0edb76109d08f89c6ce4919e78fb8311728d 100644 (file)
@@ -77,11 +77,15 @@ class DebugCommand(Command):
 
         exec_args = []
 
+        # Put `sudo --` at the beginning of the command.
         if self.sudo:
             exec_args.extend([sudo_cmd, "--"])
 
-        # attach to PIDs
-        exec_args.extend([gdb_cmd, "--pid", str(procs[0]["pid"])])
+        # Attach GDB to processes - the first process gets passed as a regular `--pid` argument to GDB, the
+        # rest are attached using the `add-inferior` and `attach` GDB commands. This way, we are now debugging
+        # multiple processes.
+        exec_args.extend([gdb_cmd])
+        exec_args.extend(["-init-eval-command", f'attach {procs[0]["pid"]}'])
         inferior = 2
         for proc in procs[1:]:
             exec_args.extend(["-init-eval-command", "add-inferior"])
@@ -89,7 +93,18 @@ class DebugCommand(Command):
             exec_args.extend(["-init-eval-command", f'attach {proc["pid"]}'])
             inferior += 1
 
-        exec_args.extend(["-init-eval-command", "inferior 1"])
+        num_inferiors = inferior - 1
+        if num_inferiors > 1:
+            # Now we switch back to the first process and add additional provided GDB arguments.
+            exec_args.extend(["-init-eval-command", "inferior 1"])
+            exec_args.extend(
+                [
+                    "-init-eval-command",
+                    "echo \\n\\nYou are now debugging multiple Knot Resolver processes. To switch between "
+                    "them, use the 'inferior <n>' command, where <n> is an integer from 1 to "
+                    f"{num_inferiors}.\\n\\n",
+                ]
+            )
         exec_args.extend(self.gdb_args)
 
         print(f"exec_args = {exec_args}")