From: Oto Šťáva Date: Wed, 4 Oct 2023 13:01:07 +0000 (+0200) Subject: kresctl: debug command help message X-Git-Tag: v6.0.10~9^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0c52a1c31a2b2bcef3cf90a171912942dce9461;p=thirdparty%2Fknot-resolver.git kresctl: debug command help message --- diff --git a/python/knot_resolver/client/commands/debug.py b/python/knot_resolver/client/commands/debug.py index 44ab33ebd..421e0edb7 100644 --- a/python/knot_resolver/client/commands/debug.py +++ b/python/knot_resolver/client/commands/debug.py @@ -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 ' command, where is an integer from 1 to " + f"{num_inferiors}.\\n\\n", + ] + ) exec_args.extend(self.gdb_args) print(f"exec_args = {exec_args}")