3 ms·
What's the equivalent of int3 on an ARM machine? Is there any attempt to provide a header that "does the right thing" on a wide variety of platforms?
by thrtythreeforty 3y ago
What's the equivalent of int3 on an ARM machine? Is there any attempt to provide a header that "does the right thing" on a wide variety of platforms?
- dooglius 3y agoTFA says > As far as I know there is no ARM equivalent compatible with GDB (or even LLDB). The closest instruction, brk #0x1, does not behave as needed. But doesn't elaborate on why
- zyedidia 3y agoThe reason is because the ARM `brk #0x1` instruction doesn't set the exception return address to the next instruction, so the debugger will just return to the breakpoint when it tries to resume, instead of running the next instruction. Recent versions of LLDB will recognize `brk #0xf000` and automatically step over it when returning, but I don't think GDB does this. With GDB you would have to run something manually like `jump *($pc + 4)` to resume at the next instruction. Clang's `__builtin_debugtrap()` will generate `brk #0xf000` automatically.
- zootboy 3y agoI've been using this macro with GCC / GDB for years without running into the issue you're describing: #define DEBUG_BREAK() do{__asm__("BKPT");} while(0) I can continue just fine with it. Granted, this is on the various Cortex M0/M3/M4 chips, so I can't say for sure if it works on any of the bigger, fancier ARMs.
- zyedidia 3y agoI think it's a difference between ARMv8 and ARMv6/7 (I believe BKPT on ARMv6/7 sets the exception return address to `addr(instruction)+4`).
- thrtythreeforty 3y agoFollowup: I found such a header! https://github.com/scottt/debugbreak https://github.com/scottt/debugbreak