98 points jandeboevrie 16 hours ago 23 comments
amluto 14 hours ago | parent
> Implementations are expected to optimize the code generated to be as minimal as possible for the platform. For example, on X86 it’s expected that this produces a single INT3 instruction. The goal in this expectation is to place the debugger as close as possible in the caller of breakpoint() to improve the debugging experience for users.
This is the wrong design on x86 at least with many debuggers. x86’s int3 is a trap and reports the address of the next instruction in the saved register state [0]. Most debuggers are not very clever and just use the saved address to generate the offending line of code and the call stack. But if the trap sequence is just int3, then the saved address could be outside the offending basic block or even outside the function entirely. gdb is certainly in the class of debuggers that get this wrong.
The easy workaround is to generate int3; nop for the breakpoint instead of just int3. The saved address will point to the nop and the debugger will be happy.
[0] FRED also reports the instruction length, allowing one to deduce the trapping address.
dingaling911 12 hours ago | parent
Joker_vD 12 hours ago | parent
Maxatar 11 hours ago | parent
GDB already compensates for breakpoints it inserts itself because it knows their locations, so it subtracts 1 as you suggest. It could also recognize embedded INT3 instructions but that requires distinguishing their traps from other causes of SIGTRAP which is much more complicated. So instead GDB generally leaves the instruction pointer unchanged for embedded INT3 instructions.
Here's a discussion of precisely this issue from the GDB developers:
https://sourceware.org/pipermail/gdb/2009-February/034621.ht...
dwattttt 4 hours ago | parent
Agentlien 2 hours ago | parent
tux3 12 hours ago | parent
dwattttt 4 hours ago | parent
singron 10 hours ago | parent
> The separation of concerns is deliberate — breakpoint() and is_debugger_present() are orthogonal building blocks, and breakpoint_if_debugging() is the convenience composition.
It might be a false positive or just a few spots. Or maybe it's rage bait. I'm sorry if the author actually writes with this style.
Maxatar 10 hours ago | parent
jchw 6 hours ago | parent
locknitpicker 5 hours ago | parent
I don't think this is a fair assessment. Submissions from specific sources are more frequent in niche forums, as this helps them stand out. So once a blog is found to be spamming, it's easier to target the blog and not individual submissions.
This is much harder to do on generalist forums such as HN.
jchw 4 hours ago | parent
At this point, my only reason for still being around on here is because I simply don't know of any place that I find strictly better. Most of the popular alternatives to HN are annoying in ways that I find equally hard or even harder to tolerate.
fnord77 7 hours ago | parent
I bet that could be modeled with a markov chain
koito17 5 hours ago | parent
None are constexpr — debugging is a runtime concern.
I am not very experienced with C++, but runtime debug functions are one of the last things where I'd expect compile-time computations. Inlining? Sure. Doing anything else at compile-time? Not really.The sentence feels like a remark about something a human reader is very unlikely to be thinking about.
eklitzke 8 hours ago | parent
1over137 7 hours ago | parent
locknitpicker 5 hours ago | parent
The C and C++ standards people are you and me. The proposal to standardize debugging calls comes from a long time contributor to Boost.
pjmlp 1 hour ago | parent
Granted ISO processes are way more burecraty and secretive than discussing RFC pull requests on Github, however at the end of the day, the work is done by volunteers pushing their own agenda or the one from their employer.
Anyone can do it, if willing to deal with the process,
https://isocpp.org/std/meetings-and-participation
https://www.open-std.org/jtc1/sc22/wg14/www/contributing.htm...