Test that gdb and argparse give the same help message (#2961)

* test that gdb and argparse give the same help message

* fix misc test

* rstrip outputs

* added comment explaining the down aliases

* Update pwndbg/commands/ida.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update tests/gdb-tests/tests/test_misc.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pull/2967/head
k4lizen 7 months ago committed by GitHub
parent eac203cf10
commit c8793b87d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -69,7 +69,11 @@ parser.add_argument(
)
@pwndbg.commands.Command(parser, category=CommandCategory.MISC)
# Since we are redefining a gdb command, we also redefine the original aliases.
# These aliases ("do", "dow") are necessary to ensure consistency in the help system
# and to pass the test_consistent_help test, which verifies that all commands and their
# aliases are documented correctly. See issue #2961 for more details.
@pwndbg.commands.Command(parser, category=CommandCategory.MISC, aliases=["do", "dow"])
@pwndbg.commands.OnlyWhenRunning
def down(n=1) -> None:
"""

@ -0,0 +1,20 @@
from __future__ import annotations
import gdb
import pwndbg
def test_consistent_help():
"""
Tests that the help printed by gdb (via `help cmd`) is
the exact same as the help printed by argparse (via `cmd -h`).
"""
for cmd in pwndbg.commands.commands:
name = cmd.command_name
gdb_out = gdb.execute(f"help {name}", to_string=True)
argparse_out = gdb.execute(f"{name} -h", to_string=True)
# I would rather not strip, but gdb is inconsistent between versions.
assert gdb_out.rstrip() == argparse_out.rstrip()

@ -11,7 +11,8 @@ STACK_COMMANDS = [
"Context",
"Print out the current register, instruction, and stack context.",
),
("down", [], "Misc", "Select and print stack frame called by this one."),
# The aliases 'do' and 'dow' were added to support the help consistency test.
("down", ["do", "dow"], "Misc", "Select and print stack frame called by this one."),
("retaddr", [], "Stack", "Print out the stack addresses that contain return addresses."),
("stack", [], "Stack", "Dereferences on stack data with specified count and offset."),
("up", [], "Misc", "Select and print stack frame that called this one."),

Loading…
Cancel
Save