Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor update to unittest of print-format after #843 #852

Merged
merged 1 commit into from
Jun 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)