Skip to content

[Bug]: break_on_failure should use __builtin_debugtrap rather than __builtin_trap #4786

@RedBeard0531

Description

@RedBeard0531

Describe the issue

__builtin_trap() is considered a noreturn function and therefore you are not able to continue debugging after the first failure. Clang has __builtin_debugtrap with the desired semantics. GCC currently lacks such an extension, but the fallback behavior of raise(SIGTRAP); works correctly and is better than __builtin_trap(). GCC will need to add such an extension eventually to support C++26's std::breakpoint().

Steps to reproduce the problem

Run a test with multiple failures with --gtest_break_on_failure in gdb. Try to continue. Repeatedly. Note that it stays in the same place because the trap loops.

Now replace __builtin_trap with __builtin_debugtrap in

#elif GTEST_HAS_BUILTIN(__builtin_trap)
__builtin_trap();

When you try again, you can now continue to the next failure!

What version of GoogleTest are you using?

> git rev-parse HEAD
09ffd0015395354774c059a17d9f5bee36177ff9

What operating system and version are you using?

Linux arm64

What compiler and version are you using?

> gcc -v       
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/11/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) 

What build system are you using?

> bazel version  
Bazelisk version: development
Build label: 8.3.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Mon Jun 30 16:25:49 2025 (1751300749)
Build timestamp: 1751300749
Build timestamp as int: 1751300749

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions