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

Add backwards memory examination for the dereference command #942

Merged
merged 5 commits into from
Apr 5, 2023

Conversation

tramasys
Copy link
Contributor

@tramasys tramasys commented Apr 4, 2023

Description/Motivation/Screenshots

This commit extends the dereference command, allowing to examine memory backwards via a negative --length value, analogous to the behaviour of x.

Against which architecture was this tested ?

"Tested" indicates that the PR works and the unit test (see docs/testing.md) run passes without issue.

  • x86-32
  • x86-64
  • ARM
  • AARCH64
  • MIPS
  • POWERPC
  • SPARC
  • RISC-V

Checklist

  • My PR was done against the dev branch, not main.
  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

gef.py Outdated
to_insnum = self.repeat_count * nb - 1
insnum_step = -1
else:
from_insnum = 0 + self.repeat_count * nb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 0 +?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation had them, so I simply left them in place. I can't tell why they were placed, so I just left them there in case there's some obsure edge-case that I'm not aware of.

gef.py Outdated
if nb > 0:
from_insnum = nb * (self.repeat_count + 1) - 1
to_insnum = self.repeat_count * nb - 1
insnum_step = -1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have to repeat this line in both cases

gef.py Outdated
if nb > 0:
from_insnum = 0 + self.repeat_count * nb
to_insnum = nb * (self.repeat_count + 1)
insnum_step = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have to repeat this in both cases

gef.py Outdated
to_insnum = nb * (self.repeat_count + 1)
insnum_step = 1
if nb > 0:
from_insnum = 0 + self.repeat_count * nb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 0+

Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests in tests/commands/dereference.py, other than that and graz remarks, it looks good to me

docs/commands/dereference.md Show resolved Hide resolved
"set {char[9]} ($sp+0x8) = { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00 }",
"set {char[9]} ($sp-0x8) = { 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00 }"
]
res = gdb_start_silent_cmd(cmd=setup, after=cmd)
self.assertNoException(res)
print(res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

"set {char[9]} ($sp+0x8) = { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00 }",
"set {char[9]} ($sp-0x8) = { 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00 }"
]
res = gdb_start_silent_cmd(cmd=setup, after=cmd)
self.assertNoException(res)
print(res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

gef.py Outdated
to_insnum = nb * (self.repeat_count + 1)
else:
from_insnum = nb * (self.repeat_count + 1) + 1
to_insnum = (0 + self.repeat_count * nb) + 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 0+

"""
res = res.splitlines()[-2]
self.assertTrue("AAAAAAAA" not in res)
self.assertTrue("BBBBBBBB" in res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertIn

Hence, we want to look at the second last line of the output
"""
res = res.splitlines()[-1]
self.assertTrue("AAAAAAAA" in res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertIn

"""
res = res.splitlines()[-1]
self.assertTrue("AAAAAAAA" in res)
self.assertTrue("BBBBBBBB" not in res)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertNotIn

Copy link
Owner

@hugsy hugsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@hugsy hugsy merged commit 0f477e7 into hugsy:dev Apr 5, 2023
@tramasys tramasys deleted the deref-extended branch April 5, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants