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

Debugger: Avoid unaligned reads in expressions #17269

Merged
merged 2 commits into from
Apr 12, 2023

Conversation

unknownbrackets
Copy link
Collaborator

To prevent crashes, this makes all reads from conditions memcpy()s. The issue is that a 32 bit read straddling a VRAM mirror will crash.

Also fix a long standing bug that makes the disasm confused when you return to an idle thread.

-[Unknown]

@unknownbrackets unknownbrackets added this to the v1.15.0 milestone Apr 12, 2023
@@ -396,7 +396,7 @@ u32 DisassemblyManager::getNthNextAddress(u32 address, int n)
analyze(address);
Copy link
Owner

Choose a reason for hiding this comment

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

should we avoid analyzing if the address has gotten unaligned? It feels like there are some early checks possible, rather than just aligning the return value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, that actually aligns the address, and I didn't want to change that logic.

-[Unknown]


switch (size) {
case 1:
dest = valid ? Memory::Read_U8(address) : 0;
dest = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
Copy link
Owner

Choose a reason for hiding this comment

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

Hm, how does this do the same as the old code? previously it returned maximum an 8-bit value. I think this case is swapped with "case 4".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, thanks. I guess I only tried something where the lowest byte mattered anyway...

-[Unknown]


switch (size) {
case 1:
dest = valid ? Memory::Read_U8(address) : 0;
dest = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
Copy link
Owner

Choose a reason for hiding this comment

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

same here

Potentially, a watch or break condition could crash if it was unaligned
between mirrors.  This might happen if it's not the condition you wanted,
especially.  Play it safe.
We ended up with an unaligned start address for our window.
@hrydgard hrydgard merged commit 178fe27 into hrydgard:master Apr 12, 2023
@unknownbrackets unknownbrackets deleted the debugger-minor branch April 12, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants