diff --git a/tests/gdb-tests/tests/test_command_flags.py b/tests/gdb-tests/tests/test_command_flags.py new file mode 100644 index 000000000..ddf919e1d --- /dev/null +++ b/tests/gdb-tests/tests/test_command_flags.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +import gdb + +import pwndbg.gdblib.regs +import tests + +REFERENCE_BINARY = tests.binaries.get("reference-binary.out") + + +def test_flags_command(start_binary): + start_binary(REFERENCE_BINARY) + + old_eflags = pwndbg.gdblib.regs.eflags + + # Verify CF is not set + assert old_eflags & 0x1 == 0 + + gdb.execute("setflag cf 1") + + # Verify CF is set and no other flags have changed + assert (old_eflags | 1) == pwndbg.gdblib.regs.eflags + + gdb.execute("setflag cf 0") + + # Verify CF is not set and no other flags have changed + assert old_eflags == pwndbg.gdblib.regs.eflags + + # Test setting an invalid value + gdb.execute("setflag cf 2") + + # Verify no flags have changed + assert old_eflags == pwndbg.gdblib.regs.eflags