C++ Logo

sg15

Advanced search

Re: [SG15] breakpoint and is_debugger_present proposals.

From: Timur Doumler <cpp_at_[hidden]>
Date: Wed, 5 Jan 2022 11:37:07 +0000
I am strongly in favour of this feature. It has been implemented cross-platform in the JUCE framework <https://github.com/juce-framework/JUCE>, where it has proven to be very useful in practice. It is used in JUCE’s jassert macro, which triggers a breakpoint whenever an assertion fails, if (and only if) we are running a debug build and a debugger is attached:
https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/system/juce_PlatformDefs.h#L152 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/system/juce_PlatformDefs.h#L152>

This has always worked well for me on all the relevant platforms.

juce_isRunningUnderDebugger() (equivalent of std::is_debugger_present) is implemented as follows:
Android: https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_android_Threads.cpp#L378 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_android_Threads.cpp#L378>
Linux: https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_linux_SystemStats.cpp#L348 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_linux_SystemStats.cpp#L348>
macOS: https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_mac_Threads.mm#L74 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_mac_Threads.mm#L74>
Windows: https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_win32_Threads.cpp#L230 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/native/juce_win32_Threads.cpp#L230>

and JUCE_BREAK_IN_DEBUGGER (equivalent of std::breakpoint) is implemented as follows: https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/system/juce_PlatformDefs.h#L62 <https://github.com/juce-framework/JUCE/blob/ddaa09110392a4419fecbb6d3022bede89b7e841/modules/juce_core/system/juce_PlatformDefs.h#L62>

I hope this is useful.

Cheers,
Timur

> On 5 Jan 2022, at 11:03, Daniel Ruoso via SG15 <sg15_at_[hidden]> wrote:
>
> On Tue, Jan 4, 2022, 21:20 Jonathan Wakely via SG15 <sg15_at_[hidden] <mailto:sg15_at_[hidden]>> wrote:
> It looks like the only implementation experience for linux is Unreal Engine 4, assuming that does actually work for linux. https://github.com/scottt/debugbreak <https://github.com/scottt/debugbreak> is a much better reference implementation
>
> I think this is a crucial point.
>
> It's not clear to me what a breakpoint outside of a debugger would do. Would it send itself a sigstop?
>
> Having a fully fleshed out implementation for the major compilers and operating systems would probably be a requirement for this to be evaluated in a more informed way.
>
> Daniel
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15


Received on 2022-01-05 05:37:17