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

Fix aglib reg_write to correctly handle writing to the "pc" register #2539

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

patryk4815
Copy link
Member

Fixes #2537

@mbrla0 please look :)

@@ -125,7 +125,8 @@ def __setattr__(self, attr: str, val: Any) -> None:
if attr in ("last", "previous"):
super().__setattr__(attr, val)
else:
pwndbg.dbg.selected_frame().reg_write(attr, int(val))
if not pwndbg.dbg.selected_frame().reg_write(attr, int(val)):
Copy link
Member Author

@patryk4815 patryk4815 Nov 16, 2024

Choose a reason for hiding this comment

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

Or inside here we should "remap" if attr == pc to correct real register?
Maybe reg_write should only accept real registers?

And not modify gdb.py / lldb/__init__.py

Copy link
Member Author

Choose a reason for hiding this comment

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

And what about sp register? Like we have in fix() method:

    def fix(self, expression: str) -> str:
        for regname in set(self.all + ["sp", "pc"]):
            expression = re.sub(rf"\$?\b{regname}\b", r"$" + regname, expression)
        return expression

Copy link
Contributor

@mbrla0 mbrla0 Nov 18, 2024

Choose a reason for hiding this comment

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

Maybe reg_write should only accept real registers?

Yeah, maybe, and have __setattr__ handle the register aliases.

Or inside here we should "remap" if attr == pc to correct real register?

Personally, I think mapping pc to regs_sets[...].pc and still doing the sanity check against the registers listed in the reg sets is a cleaner solution, because that means we only ever have to deal with real register names in the Debugger API. Buuuut, both GDB and LLDB accept pc as a register name just fine, so it's not like this won't work, if you think it's better this way.

And what about sp register?

Yeap, this will probably need an exception for sp, too..

@disconnect3d
Copy link
Member

@mbrla0 Thoughts? Shall we merge this or should we change sth here>?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Investigate regression in tests test_next_command_doesnt_freeze_crashed_binary[nextproginstr]
3 participants