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]
Other format: [Raw text]

Re: core dumped when adding to vector


I would indeed be deeply shocked if there is a bug in vectors of enums. However, if someone has a 5 line example which they believes shows a bug in libstdc++ or gcc, I would have thought that bugzilla would be the right place to post it (I'm happy to be told that that isn't the right place)

Chris

In my program the problem occurs always but can not reproduce it in a 10 line program. The problem should be in my code, not in the vector.

I run valgrind and gdb and have attached their output. I need some help
on this issue because I have limited experience on C++. I have programmed
mostly in Java where such problems do not occure.

I readed from the FAQ of the libstdc++ about memory management how
to install a custom handler for out-of-memory events. This is the code:

void mem_handler() {
  rusage* usg = new rusage;
  getrusage(RUSAGE_SELF, usg);
  cout << "ru_maxrss:" << usg->ru_maxrss << endl
	   << "ru_ixrss:" << usg->ru_ixrss << endl
	   << "ru_idrss:" << usg->ru_idrss << endl
	   << "ru_isrss:" << usg->ru_isrss
	   << endl;
  delete usg;
  cerr << "Running out of mem" << endl;
  set_new_handler(old_handler);
}

The output is:
ru_maxrss:0
ru_ixrss:0
ru_idrss:0
ru_isrss:0
Running out of mem
Aborted

I need a way to determine how much memory the program
is using. getrusage was not the answer on this problem.
The `time' command did not the job either.

I used top in batch mode to figure out the amount of memory used.
This is the output from 3 runs:
1460 anakreon 16 0 640 640 548 R 12.5 0.3 0:00.01 simulator


1461 anakreon 16 0 1316 1312 1144 R 24.1 0.7 0:00.02 simulator

1462 anakreon 16 0 1284 1280 1112 R 25.0 0.7 0:00.02 simulator

where 0.3 and 0.7 are the percentage of memory used.

From top it seems that the amount of memory is neglible.

I do understand that the mail is lengthy and this is not the right
place for this question but I need to meet a deadline and the situation
is strange.
I'd really appreciate if someone can give a hint on what's going on
or how could i see the amount of memory used from inside the program.

Anakreon
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211616000 (LWP 7689)]
0x08063844 in std::vector<protocol_state, std::allocator<protocol_state> >::end() const (this=0x0)
    at stl_vector.h:378
378           end() const { return const_iterator (_M_finish); }
(gdb) backtrace 
#0  0x08063844 in std::vector<protocol_state, std::allocator<protocol_state> >::end() const (this=0x0)
    at stl_vector.h:378
#1  0x08062e4b in std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (this=0x0)
    at stl_vector.h:467
#2  0x08061bd7 in Log::addTransaction(int, double, int) (this=0x806da98, tid=0, size=4.8285078350454569, 
    maxId=2) at log.cpp:29
#3  0x08059a89 in Acp::jobFinished(Event*) (this=0x806da10, j=0x8075ff0) at acp.cpp:178
#4  0x0804ef17 in System::startSimulation(double) (this=0x806db28, maxTime=10000) at system.cpp:207
#5  0x080495b8 in main (argc=2, argv=0xbffff274) at main.cpp:106
==7621== Memcheck, a memory error detector for x86-linux.
==7621== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==7621== Using valgrind-2.1.0, a program supervision framework for x86-linux.
==7621== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==7621== 
==7621== My PID = 7621, parent PID = 6737.  Prog and args are:
==7621==    ./simulator
==7621==    config.xml
==7621== 
==7621== Command line
==7621==    ./simulator
==7621==    config.xml
==7621== Startup, with flags:
==7621==    --suppressions=/usr/lib/valgrind/default.supp
==7621==    -v
==7621==    --logfile=val
==7621==    --leak-check=yes
==7621== Reading syms from /home/e/code/cpp/transaction/simulator
==7621== Reading syms from /lib/i686/libc-2.3.3.so
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /lib/libgcc_s-3.3.2.so.1
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /usr/lib/libstdc++.so.5.0.5
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /lib/i686/libm-2.3.3.so
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /usr/lib/valgrind/libpthread.so
==7621== Reading syms from /lib/libz.so.1.2.1
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /usr/lib/libxml2.so.2.6.6
==7621==    object doesn't have a symbol table
==7621==    object doesn't have any debug info
==7621== Reading syms from /usr/lib/valgrind/valgrind.so
==7621== Reading syms from /usr/lib/valgrind/vgskin_memcheck.so
==7621== Reading syms from /lib/ld-2.3.3.so
==7621== Reading suppressions file: /usr/lib/valgrind/default.supp
==7621== Estimated CPU clock rate is 651 MHz
==7621== 
==7621== Use of uninitialised value of size 4
==7621==    at 0x8063844: std::vector<protocol_state, std::allocator<protocol_state> >::end() const (stl_vector.h:378)
==7621==    by 0x8062E4A: std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (stl_vector.h:467)
==7621==    by 0x8061BD6: Log::addTransaction(int, double, int) (log.cpp:29)
==7621==    by 0x8059A88: Acp::jobFinished(Event*) (acp.cpp:178)
==7621== 
==7621== Invalid read of size 4
==7621==    at 0x8063844: std::vector<protocol_state, std::allocator<protocol_state> >::end() const (stl_vector.h:378)
==7621==    by 0x8062E4A: std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (stl_vector.h:467)
==7621==    by 0x8061BD6: Log::addTransaction(int, double, int) (log.cpp:29)
==7621==    by 0x8059A88: Acp::jobFinished(Event*) (acp.cpp:178)
==7621==  Address 0x4 is not stack'd, malloc'd or free'd
==7621== 
==7621== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==7621==  Address not mapped to object at address 0x4
==7621==    at 0x8063844: std::vector<protocol_state, std::allocator<protocol_state> >::end() const (stl_vector.h:378)
==7621==    by 0x8062E4A: std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (stl_vector.h:467)
==7621==    by 0x8061BD6: Log::addTransaction(int, double, int) (log.cpp:29)
==7621==    by 0x8059A88: Acp::jobFinished(Event*) (acp.cpp:178)
==7621== 
==7621== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
==7621== 
==7621== 1 errors in context 1 of 2:
==7621== Invalid read of size 4
==7621==    at 0x8063844: std::vector<protocol_state, std::allocator<protocol_state> >::end() const (stl_vector.h:378)
==7621==    by 0x8062E4A: std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (stl_vector.h:467)
==7621==    by 0x8061BD6: Log::addTransaction(int, double, int) (log.cpp:29)
==7621==    by 0x8059A88: Acp::jobFinished(Event*) (acp.cpp:178)
==7621==  Address 0x4 is not stack'd, malloc'd or free'd
==7621== 
==7621== 1 errors in context 2 of 2:
==7621== Use of uninitialised value of size 4
==7621==    at 0x8063844: std::vector<protocol_state, std::allocator<protocol_state> >::end() const (stl_vector.h:378)
==7621==    by 0x8062E4A: std::vector<protocol_state, std::allocator<protocol_state> >::empty() const (stl_vector.h:467)
==7621==    by 0x8061BD6: Log::addTransaction(int, double, int) (log.cpp:29)
==7621==    by 0x8059A88: Acp::jobFinished(Event*) (acp.cpp:178)
==7621== IN SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
==7621== 
==7621== malloc/free: in use at exit: 9438 bytes in 111 blocks.
==7621== malloc/free: 550 allocs, 439 frees, 65588 bytes allocated.
==7621== 
==7621== searching for pointers to 111 not-freed blocks.
==7621== checked 6010484 bytes.
==7621== 
==7621== LEAK SUMMARY:
==7621==    definitely lost: 0 bytes in 0 blocks.
==7621==    possibly lost:   0 bytes in 0 blocks.
==7621==    still reachable: 9238 bytes in 110 blocks.
==7621==         suppressed: 200 bytes in 1 blocks.
==7621== Reachable blocks (those to which a pointer was found) are not shown.
==7621== To see them, rerun with: --show-reachable=yes
--7621--     TT/TC: 0 tc sectors discarded.
--7621--            4562 chainings, 0 unchainings.
--7621-- translate: new     8178 (131873 -> 1861981; ratio 141:10)
--7621--            discard 0 (0 -> 0; ratio 0:10).
--7621--  dispatch: 105478 jumps (bb entries), of which 63504 (60%) were unchained.
--7621--            13/12447 major/minor sched events.  8606 tt_fast misses.
--7621-- reg-alloc: 1478 t-req-spill, 352846+8177 orig+spill uis, 42904 total-reg-r.
--7621--    sanity: 14 cheap, 1 expensive checks.
--7621--    ccalls: 44705 C calls, 57% saves+restores avoided (150422 bytes)
--7621--            58771 args, avg 0.86 setup instrs each (15482 bytes)
--7621--            0% clear the stack (134115 bytes)
--7621--            13654 retvals, 32% of reg-reg movs avoided (8632 bytes)

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