This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 21_strings/insert.cc on the mainline


Surprisingly, on my system, gcc version 3.1 20010416 and gdb 20010325,
I encounter a different behaviour of the executable. If I set a
breakpoint in line 58, I can single step with the next command, the
flow continues in line 60, which is correct. But somewhere after the
line number 80 a segmentation fault occurs. The line
std::string str04(csz01, 'b') causes the segmentation fault. I cannot
tell what happens exactly since gdb is doing strange things, but single
stepping through the function
std::__malloc_alloc_template<0>::_S_oom_malloc(unsigned) shows that
bad_alloc is thrown, this exception is digested in the exception
handling code, resulting in a segmentation fault in
../include/bits/atomicity.h:40, which reads:
  
__asm__ __volatile__ ("lock; xaddl %0,%2"
			: "=r" (__result) 
                        : "0" (__val), "m" (*__mem) 
                        : "memory"); 

Transcript of the gdb session:
Breakpoint 12, test01() () at insert.cc:82 //std::string str04(csz01, 'b')
(gdb) s
std::allocator<char>::allocator() (this=0x401eead8)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:542
(gdb) s
std::string::string(unsigned, char, std::allocator<char> const&) (
    this=0xbffff75c, __n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:225
(gdb) s
std::string::_S_construct(unsigned, char, std::allocator<char> const&) (
    __n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:162
(gdb) s
(gdb) s
std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (
    __capacity=1073741820, __alloc=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:364
(gdb) s
(gdb) s
(gdb) s
std::allocator<char>::allocator(std::allocator<char> const&) (this=0x804a590)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:543
(gdb) s
std::allocator<char>::allocate(unsigned, void const*) (this=0xbffff74c, 
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:553
(gdb) s
std::__malloc_alloc_template<0>::allocate(unsigned) (__n=1073741833)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:86
(gdb) s
(gdb) s
std::__malloc_alloc_template<0>::_S_oom_malloc(unsigned) (__n=1073741833)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:124
(gdb) s
(gdb) s
(gdb) s
std::__throw_bad_alloc() () at ../../../../gcc/libstdc++-v3/libsupc++/new:44
(gdb) s
(gdb) s
__cxa_allocate_exception (thrown_size=4)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_alloc.cc:100
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
std::__throw_bad_alloc() ()
    at ../../../../gcc/libstdc++-v3/src/functexcept.cc:46
(gdb) s
(gdb) s
__cxa_throw (obj=0x40200490, tinfo=0x804e738, 
    dest=0x400671b0 <std::bad_alloc::~bad_alloc()>)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:59
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
__cxa_get_globals ()
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_globals.cc:118
(gdb) s
(gdb) s
__cxa_throw (obj=0x40200490, tinfo=0x804e738, 
    dest=0x400671b0 <std::bad_alloc::~bad_alloc()>)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:67
(gdb) s
(gdb) s
0x400de158 in _Unwind_RaiseException (exc=0x40200470)
    at ../../gcc/gcc/unwind-dw2.c:1076
Current language:  auto; currently c
(gdb) s
0x400de602 in init_dwarf_reg_size_table () from /usr/local/lib/libgcc_s.so.0
(gdb) s
Single stepping until exit from function init_dwarf_reg_size_table, 
which has no line number information.
0x400ddef1 in uw_init_context_1 (context=0xbffff4bc, outer_cfa=0xbffff54c, 
    outer_ra=0x40067113) at ../../gcc/gcc/unwind-dw2.c:1076
(gdb) s
0x400ddaf6 in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
(gdb) s
0x400de602 in init_dwarf_reg_size_table () from /usr/local/lib/libgcc_s.so.0
(gdb) s
Single stepping until exit from function init_dwarf_reg_size_table, 
which has no line number information.
0x400ddafe in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
(gdb) s
0x400dcac6 in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
(gdb) s
0x400de602 in init_dwarf_reg_size_table () from /usr/local/lib/libgcc_s.so.0
(gdb) s
Single stepping until exit from function init_dwarf_reg_size_table, 
which has no line number information.
0x400dcace in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
(gdb) s
0x400dc8c4 in read_uleb128 (buf=0x400e0952 "\001|\b\f\004\004\210\001", 
    r=0xbffff234) at ../../gcc/gcc/unwind-dw2.c:205
(gdb) bt
#0  0x400dc8c4 in read_uleb128 (buf=0x400e0952 "\001|\b\f\004\004\210\001", 
    r=0xbffff234) at ../../gcc/gcc/unwind-dw2.c:205
#1  0x400dcafa in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
#2  0x400ddb7c in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
#3  0x400ddf19 in uw_init_context_1 (context=0xbffff4bc, outer_cfa=0xbffff54c, 
    outer_ra=0x40067113) at ../../gcc/gcc/unwind-dw2.c:1076
#4  0x400de180 in _Unwind_RaiseException (exc=0x40200470)
    at ../../gcc/gcc/unwind-dw2.c:1076
#5  0x40067113 in __cxa_throw (obj=0x40200490, tinfo=0x804e738, 
    dest=0x400671b0 <std::bad_alloc::~bad_alloc()>)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:72
#6  0x4005930f in std::__throw_bad_alloc() ()
    at ../../../../gcc/libstdc++-v3/src/functexcept.cc:46
#7  0x0804c133 in std::__malloc_alloc_template<0>::_S_oom_malloc(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:126
#8  0x0804c078 in std::__malloc_alloc_template<0>::allocate(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:87
#9  0x0804be67 in std::allocator<char>::allocate(unsigned, void const*) (
    this=0xbffff74c, __n=1073741833)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:553
#10 0x0804b71c in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (__capacity=1073741820, __alloc=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:376
#11 0x0804b0c4 in std::string::_S_construct(unsigned, char, std::allocator<char> const&) (__n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:166
#12 0x0804a885 in std::string::string(unsigned, char, std::allocator<char> const&) (this=0xbffff75c, __n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:225
#13 0x08049d3d in test01() () at insert.cc:82
#14 0x0804a59b in main () at insert.cc:192
#15 0x400fdbaf in __libc_start_main () from /lib/libc.so.6
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) finish
Run till exit from #0  0x400dc8d2 in read_uleb128 (
    buf=0x400e0952 "\001|\b\f\004\004\210\001", r=0xbffff234)
    at ../../gcc/gcc/unwind-dw2.c:205
0x400dcafa in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
Value returned is $6 = (unsigned char *) 0x400e0953 "|\b\f\004\004\210\001"
(gdb) bt
#0  0x400dcafa in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
#1  0x400ddb7c in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
#2  0x400ddf19 in uw_init_context_1 (context=0xbffff4bc, outer_cfa=0xbffff54c, 
    outer_ra=0x40067113) at ../../gcc/gcc/unwind-dw2.c:1076
#3  0x400de180 in _Unwind_RaiseException (exc=0x40200470)
    at ../../gcc/gcc/unwind-dw2.c:1076
#4  0x40067113 in __cxa_throw (obj=0x40200490, tinfo=0x804e738, 
    dest=0x400671b0 <std::bad_alloc::~bad_alloc()>)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:72
#5  0x4005930f in std::__throw_bad_alloc() ()
    at ../../../../gcc/libstdc++-v3/src/functexcept.cc:46
#6  0x0804c133 in std::__malloc_alloc_template<0>::_S_oom_malloc(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:126
#7  0x0804c078 in std::__malloc_alloc_template<0>::allocate(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:87
#8  0x0804be67 in std::allocator<char>::allocate(unsigned, void const*) (
    this=0xbffff74c, __n=1073741833)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:553
#9  0x0804b71c in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (__capacity=1073741820, __alloc=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:376
#10 0x0804b0c4 in std::string::_S_construct(unsigned, char, std::allocator<char> const&) (__n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:166
#11 0x0804a885 in std::string::string(unsigned, char, std::allocator<char> const&) (this=0xbffff75c, __n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:225
#12 0x08049d3d in test01() () at insert.cc:82
#13 0x0804a59b in main () at insert.cc:192
#14 0x400fdbaf in __libc_start_main () from /lib/libc.so.6
(gdb) s
0x400dc914 in read_sleb128 (buf=0x400e0953 "|\b\f\004\004\210\001", 
    r=0xbffff230) at ../../gcc/gcc/unwind-dw2.c:205
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) s
(gdb) finish
Run till exit from #0  0x400dc923 in read_sleb128 (
    buf=0x400e0953 "|\b\f\004\004\210\001", r=0xbffff230)
    at ../../gcc/gcc/unwind-dw2.c:205
0x400dcb08 in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
Value returned is $7 = (unsigned char *) 0x400e0954 "\b\f\004\004\210\001"
(gdb) bt
#0  0x400dcb08 in extract_cie_info (cie=0x400e0948, context=0xbffff4bc, 
    fs=0xbffff29c) at ../../gcc/gcc/unwind-dw2.c:265
#1  0x400ddb7c in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
#2  0x400ddf19 in uw_init_context_1 (context=0xbffff4bc, outer_cfa=0xbffff54c, 
    outer_ra=0x40067113) at ../../gcc/gcc/unwind-dw2.c:1076
#3  0x400de180 in _Unwind_RaiseException (exc=0x40200470)
    at ../../gcc/gcc/unwind-dw2.c:1076
#4  0x40067113 in __cxa_throw (obj=0x40200490, tinfo=0x804e738, 
    dest=0x400671b0 <std::bad_alloc::~bad_alloc()>)
    at ../../../../gcc/libstdc++-v3/libsupc++/eh_throw.cc:72
#5  0x4005930f in std::__throw_bad_alloc() ()
    at ../../../../gcc/libstdc++-v3/src/functexcept.cc:46
#6  0x0804c133 in std::__malloc_alloc_template<0>::_S_oom_malloc(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:126
#7  0x0804c078 in std::__malloc_alloc_template<0>::allocate(unsigned) (
    __n=1073741833) at /usr/local/include/g++-v3/bits/stl_alloc.h:87
#8  0x0804be67 in std::allocator<char>::allocate(unsigned, void const*) (
    this=0xbffff74c, __n=1073741833)
    at /usr/local/include/g++-v3/bits/stl_alloc.h:553
#9  0x0804b71c in std::string::_Rep::_S_create(unsigned, std::allocator<char> const&) (__capacity=1073741820, __alloc=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:376
#10 0x0804b0c4 in std::string::_S_construct(unsigned, char, std::allocator<char> const&) (__n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:166
#11 0x0804a885 in std::string::string(unsigned, char, std::allocator<char> const&) (this=0xbffff75c, __n=1073741820, __c=98 'b', __a=@0xbffff74c)
    at /usr/local/include/g++-v3/bits/basic_string.tcc:225
#12 0x08049d3d in test01() () at insert.cc:82
#13 0x0804a59b in main () at insert.cc:192
#14 0x400fdbaf in __libc_start_main () from /lib/libc.so.6
(gdb) s
0x400ddb7c in uw_frame_state_for (context=0xbffff4bc, fs=0xbffff29c)
    at ../../gcc/gcc/unwind-dw2.c:966
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
std::logic_error::~logic_error() (this=0x40067113)
    at ../include/bits/atomicity.h:40
Current language:  auto; currently c++
(gdb) s

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
(gdb) l
35	static inline _Atomic_word 
36	__attribute__ ((__unused__))
37	__exchange_and_add (volatile _Atomic_word *__mem, int __val)
38	{
39	  register _Atomic_word __result;
40	  __asm__ __volatile__ ("lock; xaddl %0,%2"
41				: "=r" (__result) 
42	                        : "0" (__val), "m" (*__mem) 
43	                        : "memory");
44	  return __result;


If I examine the core file. The backtrace information printed by gdb
reads:
Program received signal SIGSEGV, Segmentation fault.
std::logic_error::~logic_error() (this=0x40067113)
    at ../include/bits/atomicity.h:40
Current language:  auto; currently c++
(gdb) bt
#0  std::logic_error::~logic_error() (this=0x40067113)
    at ../include/bits/atomicity.h:40
#1  0x40069086 in std::length_error::~length_error() (this=0x40067113)
    at ../../../../gcc/libstdc++-v3/src/functexcept.cc:70
#2  0xbffff5a4 in ?? ()
#3  0x474e5543 in ?? ()

Which means that the destruction of an object of type logic_error does
not work, whatever the reason may be.

Maybe this patch 
2001-04-12  Nathan Sidwell  <nathan@codesourcery.com>

	* libsupc++/eh_alloc.cc (__cxa_allocate_exception): Don't
	terminate holding the mutex. Make sure size fits in
	EMERGENCY_OBJ_SIZE.

causes the problem, but this is only guessing. I apologize if this 
assumption is false.

Hope this helps a bit,

Peter Schmid


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]