Skip to content

Commit

Permalink
Minor update to unittest of print-format after #843 (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy authored Jun 26, 2022
1 parent 9834252 commit a2a4bfa
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/commands/print_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,27 @@ def test_cmd_print_format(self):
self.assertFailIfInactiveSession(gdb_run_cmd("print-format"))
res = gdb_start_silent_cmd("print-format $sp")
self.assertNoException(res)
self.assertTrue("buf = [" in res)
self.assertIn("buf = [" , res)
res = gdb_start_silent_cmd("print-format --lang js $sp")
self.assertNoException(res)
self.assertTrue("var buf = [" in res)
self.assertIn("var buf = [" , res)
res = gdb_start_silent_cmd("set *((int*)$sp) = 0x41414141",
after=["print-format --lang hex $sp"])
self.assertNoException(res)
self.assertTrue("41414141" in res, f"{res}")
self.assertIn("41414141", res, f"{res}")
res = gdb_start_silent_cmd("print-format --lang iDontExist $sp")
self.assertNoException(res)
self.assertTrue("Language must be in:" in res)
self.assertIn("Language must be in:" , res)


def test_cmd_print_format_bytearray(self):
res = gdb_start_silent_cmd("set *((int*)$sp) = 0x41414141",
after=["print-format --lang bytearray -l 4 $sp"])
self.assertNoException(res)
try:
gef_var = res.split('$_gef')[1].split("'")[0]
except:
self.assertTrue(False)
gef_var = res.split('$_gef')[1].split("'")[0]
self.assertTrue("\x41\x41\x41\x41" in res)
res = gdb_start_silent_cmd("set *((int*)$sp) = 0x41414141",
after=["print-format --lang bytearray -l 4 $sp", "p $_gef" + gef_var])
self.assertNoException(res)
self.assertTrue("0x41, 0x41, 0x41, 0x41" in res)
self.assertIn(
f"Saved data b'AAAA'... in '$_gef{gef_var}'", res)

0 comments on commit a2a4bfa

Please sign in to comment.