News for hackers. Stuff that matters.
Re:Two handy GDB breakpoint tricks by thrtythreeforty on Sunday January 28, 2024 @09:53PM (#39172206)
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?
Re:Two handy GDB breakpoint tricks by dooglius on Sunday January 28, 2024 @10:07PM (#39172273)
TFA 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

Re:Two handy GDB breakpoint tricks by zyedidia on Sunday January 28, 2024 @10:40PM (#39172450)
The 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.
Re:Two handy GDB breakpoint tricks by zootboy on Monday January 29, 2024 @02:07AM (#39173574)
I'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.

Re:Two handy GDB breakpoint tricks by zyedidia on Monday January 29, 2024 @03:24AM (#39174028)
I 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`).
Re:Two handy GDB breakpoint tricks by thrtythreeforty on Tuesday January 30, 2024 @10:16PM (#39199385)
Followup: I found such a header! https://github.com/scottt/debugbreak