[PATCH v4] libstdc++: Implement C++26 <debugging> features (P2546R5)
Tomasz Kaminski
tkaminsk@redhat.com
Mon May 5 08:57:10 GMT 2025
On Mon, May 5, 2025 at 10:55 AM Jonathan Wakely <jwakely.gcc@gmail.com>
wrote:
>
>
> On Mon, 5 May 2025, 09:23 Sam James, <sam@gentoo.org> wrote:
>
>> Jonathan Wakely <jwakely@redhat.com> writes:
>>
>> > [...]
>> > +void
>> > +std::breakpoint() noexcept
>> > +{
>> > + PROBE(std::breakpoint);
>> > +
>> > + if (__gnu_cxx::debugger_signal_for_breakpoint > 0)
>> > + std::raise(__gnu_cxx::debugger_signal_for_breakpoint);
>> > +
>>
>> glib's
>> https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/gbacktrace.h#L58 is
>> a useful reference. It has an entry for alpha and also MSVC (though I
>> can't imagine MSVC matters here).
>>
>
> I can't load that page, Anubis takes 10s then I get "invalid response".
>
Relevant content:
/** * G_BREAKPOINT: * * Inserts a breakpoint instruction into the
code. * * On architectures which support it, this is implemented as a
soft interrupt * and on other architectures it raises a `SIGTRAP`
signal. * * `SIGTRAP` is used rather than abort() to allow breakpoints
to be skipped past * in a debugger if they are not the desired target
of debugging. */#if (defined (__i386__) || defined (__x86_64__)) &&
defined (__GNUC__) && __GNUC__ >= 2# define G_BREAKPOINT()
G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END#elif
(defined (_MSC_VER) || defined (__DMC__)) && defined (_M_IX86)#
define G_BREAKPOINT() G_STMT_START{ __asm int 3h
}G_STMT_END#elif defined (_MSC_VER)# define G_BREAKPOINT()
G_STMT_START{ __debugbreak(); }G_STMT_END#elif defined (__alpha__) &&
!defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2# define
G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt");
}G_STMT_END#elif defined (__APPLE__) || (defined(_WIN32) &&
(defined(__clang__) || defined(__GNUC__)))# define G_BREAKPOINT()
G_STMT_START{ __builtin_trap(); }G_STMT_END#else /* !__i386__ &&
!__alpha__ */# define G_BREAKPOINT() G_STMT_START{ raise
(SIGTRAP); }G_STMT_END#endif /* __i386__ */G_END_DECLS
>
>
>> > +#if _GLIBCXX_HAVE_DEBUGAPI_H && defined(_WIN32) && !defined(__CYGWIN__)
>> > + DebugBreak();
>> > +#elif __has_builtin(__builtin_debugtrap)
>> > + __builtin_debugtrap(); // Clang
>> > +#elif defined(__i386__) || defined(__x86_64__)
>> > + __asm__ volatile ("int3; nop");
>> > +#elifdef __thumb__
>> > + __asm__ volatile (".inst 0xde01");
>> > +#elifdef __aarch64__
>> > + __asm__ volatile (".inst 0xd4200000");
>> > +#elifdef __arm__
>> > + __asm__ volatile (".inst 0xe7f001f0");
>> > +#elifdef __riscv
>> > + /* section 2.8 in the RISC-V unprivileged ISA manual says for
>> semi-hosted
>> > + * environments we want the sequence:
>> > + * slli x0, x0, 0x1f # Entry NOP
>> > + * ebreak # Break to debugger
>> > + * srai x0, x0, 7 # NOP encoding the semihosting call number 7
>> > + */
>> > + __asm__ volatile (".4byte 0x00100073");
>> > +#elifdef __powerpc__
>> > + __asm__ volatile(".4byte 0x7d821008");
>> > +#else
>> > + __builtin_trap();
>> > +#endif
>> > +} // If the debugger stops here, std::breakpoint() was called.
>> > +
>> > [...]
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250505/4c25cbb1/attachment-0001.htm>
More information about the Libstdc++
mailing list