-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix x0 register write bug in r_reg_next_diff ##debug #24694
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
Conversation
|
Much cleaner now! If you can provide a test it will be great, otherwise im happy to merge it as is |
ok sure, working on it |
|
run r2r -i on the broken tests. i think new output is better, because [sp+0] is the return address |
|
please git rebase and update the tests |
6928c7d to
c6a3b8a
Compare
|
oops. please rebase again |
'add x29, sp, 0x20' which sets up frame pointers. Variable substitution should only occur in memory access operations (with brackets). This aligns behavior with IDA and improves disassembly readability. Fix radareorg#17637
…##debug The r_reg_next_diff() function was skipping registers at offset 0 because it used 'offset > prev_offset' instead of 'offset >= prev_offset'. When prev_ri is NULL (first iteration), prev_offset is 0. Since x0 is at offset 0, the condition '0 > 0' was false, causing x0 to be skipped. This bug prevented x0 from being written during debugging sessions via GDB remote protocol, as the register was never detected as changed. The fix changes the condition to '>=' to include registers at offset 0. Fixes radareorg#18975
Address review feedback by extracting strstr conditionals into is_frame_pointer_setup() helper function for better readability. Use r_str_casestr() for case-insensitive matching.
Tests that frame pointer setup instructions (add x29, sp, 0) are properly pseudoized to mov x29, sp without variable substitution.
- Remove duplicate xref in cmd_zignature (better precision) - Remove ARM64 frame pointer test from feat_variables (moved to dedicated test)
c6a3b8a to
659454b
Compare
|
the tests hasnt been updated :? run 'r2r -i ' on the failing ones |
The x0 register fix causes more accurate disassembly: - 'add r7, sp, 0' instead of 'add r7, var_10h' - 'add.w r0, sp, 0x690' instead of 'add.w r0, config' These are the correct outputs after fixing the offset >= prev_offset comparison in r_reg_next_diff.
|
Just one left: "r2r -i db/formats/elf/thumb " |
|
Updated test expectations to match actual output spacing and removed BROKEN=1 flag as the test now passes correctly.
|
r2r -i db/formats/elf/thumb |
After fixing variable substitution to not apply to frame pointer setup instructions, the test now correctly shows 'add r7, sp, 0' instead of 'add r7, var_0h'.
|
r2r -i db/formats/elf/random |
|
this pr is fixing two issues. it will be good that when you get all tests pass, to squash all the changes in two separate commits. if you like i can do that. otherwise i can wait. but the changes look good to me |
please can you do it for me, everything looks good on my PC, all test |
|
fixed the tests , squashed changes and merged into master by hand |
Fix #18975, Fix #17637
This PR fixes two related issues:
Problem 1: x0 register write bug (#18975)
When debugging ARM64 binaries via GDB remote protocol, setting the x0 register with
dr x0=1would not work, while other registers (x1, x2, etc.) worked fine.Root Cause
The
r_reg_next_diff()function inlibr/reg/reg.cwas usingoffset > prev_offsetto iterate through registers. Whenprev_riis NULL (first iteration),prev_offsetis 0. Since x0 is also at offset 0, the condition0 > 0would evaluate to false, causing x0 to be skipped.Solution
Changed the condition from
>to>=to include registers at offset 0.Problem 2: ARM64 variable substitution (#17637)
Instructions like
add x29, sp, 0x20(frame pointer setup) were incorrectly having variables substituted, showingadd x29, var_0h_2instead of keeping the original instruction.Root Cause
The pseudo disassembly code in
libr/arch/p/arm/pseudo.cwas substituting variables in all address calculation instructions, including frame pointer setup which should be left unchanged.Solution
is_frame_pointer_setup()helper function usingr_str_casestr()for case-insensitive detectionadd/subinstructions that setup frame pointersadd x29, sp, 0tomov x29, spfor cleaner outputtest/db/cmd/feat_variablesTesting