Public bug reported: On Noble 24.04, with default build-essential and gdb, printing the value of a std::basic_string with a custom allocator class (std::basic_string::<char, char_traits<char>, CUSTOM_ALLOCATOR_CLASS>) causes a floating point exception in GDB.
Compile this program with debugging information, break on the main function's line that does the console output to cout, and issue the command 'p obj' to witness the crash. This happens on a clean ubuntu:noble docker image: ============================== #include <iostream> #include <string> template <class T> class Allocator { public: typedef T value_type; typedef value_type * pointer; typedef value_type & reference; typedef const value_type * const_pointer; typedef const value_type & const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; template <class T1> class rebind { public: typedef Allocator<T1> other; }; pointer address(reference i_Val) const { return (&i_Val); } const_pointer address(const_reference i_Val) const { return (&i_Val); } Allocator() { } Allocator(const Allocator<T>&) { } template<class T1> Allocator(const Allocator<T1>&) { } template<class T1> Allocator<T>& operator=(const Allocator<T1>&) { return (*this); } void deallocate(pointer i_Ptr, size_type) { ::free(i_Ptr); } void deallocate(pointer i_Ptr, const std::nothrow_t &/*nothrow*/) { ::free(i_Ptr); } pointer allocate(size_type i_Count) { pointer retVal; retVal = static_cast<pointer>(malloc(i_Count * sizeof(T))); if (retVal == nullptr) throw std::bad_alloc(); return retVal; } pointer allocate(size_type i_Count, const void *) { return allocate(i_Count); } template<typename _Up, typename... _Args> void construct(_Up* i_Ptr, _Args&&... i_Arguments) { ::new(const_cast<void *>(reinterpret_cast<const void *>(i_Ptr))) _Up(std::forward<_Args>(i_Arguments)...); } template<typename _Up> void destroy(_Up* i_Ptr) { i_Ptr->~_Up(); } size_t max_size() const { size_t count = static_cast<size_t>(-1) / sizeof (T); return (0 < count ? count : 1); } }; // GDB crashes when trying to print 'str' in the main function on the cout line // when using Allocator. using String=std::basic_string<char, std::char_traits<char>, Allocator<char>>; int main(int argc, char *argv[]) { String str("Hello, World!"); std::cout << str << std::endl; return 0; } ================================== This message appears in gdb: 198 std::cout << str << std::endl; (gdb) p str Fatal signal: Floating point exception ----- Backtrace ----- 0x55f68d755bc6 ??? 0x55f68d878ecd ??? 0x7f9a6ce0631f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 0x55f68dae8ca8 ??? 0x55f68db86029 ??? 0x55f68d9eda57 ??? 0x55f68d87fea1 ??? 0x55f68db82d5f ??? 0x55f68d9b407e ??? 0x55f68d9b4379 ??? 0x55f68d78e464 ??? 0x55f68daf8727 ??? 0x55f68d879967 ??? 0x55f68d87b143 ??? 0x55f68d87a332 ??? 0x7f9a6e0779e4 ??? 0x55f68d87a495 ??? 0x55f68d87a663 ??? 0x55f68db3ba5c ??? 0x55f68dd06975 ??? 0x55f68dd074f7 ??? 0x55f68d955ea9 ??? 0x55f68d958f04 ??? 0x55f68d69fdab ??? 0x7f9a6cdeb1c9 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 0x7f9a6cdeb28a __libc_start_main_impl ../csu/libc-start.c:360 0x55f68d6ae1f4 ??? 0xffffffffffffffff ??? --------------------- A fatal error internal to GDB has been detected, further debugging is not possible. GDB will now terminate. This is a bug, please report it. For instructions, see: <https://www.gnu.org/software/gdb/bugs/>. Floating point exception (core dumped) ProblemType: Bug DistroRelease: Ubuntu 24.04 Package: gdb 15.0.50.20240403-0ubuntu1 ProcVersionSignature: Ubuntu 5.15.0-126.136-generic 5.15.167 Uname: Linux 5.15.0-126-generic x86_64 ApportVersion: 2.28.1-0ubuntu3.1 Architecture: amd64 CasperMD5CheckResult: unknown CloudBuildName: ubuntu-oci:minimized CloudSerial: 20241015 Date: Wed Nov 27 12:58:44 2024 ProcEnviron: PATH=(custom, no user) TERM=xterm SourcePackage: gdb UpgradeStatus: No upgrade log present (probably fresh install) mtime.conffile..etc.apport.crashdb.conf: 2024-11-27T12:53:43.637016 ** Affects: gdb (Ubuntu) Importance: Undecided Status: New ** Tags: amd64 apport-bug cloud-image gdb noble -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2089788 Title: GDB crash on simple C++ program debugging To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/2089788/+subscriptions -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs