Bug 188657

Summary: Massif: ms_main.c:1700 (update_stack_stats): Assertion 'stacks_szB >= -stack_szB_delta' failed
Product: [Developer tools] valgrind Reporter: Nuno Lopes <nunoplopes>
Component: massifAssignee: Nicholas Nethercote <njn>
Status: REPORTED ---    
Severity: crash CC: borntraeger
Priority: NOR    
Version First Reported In: 3.4.1   
Target Milestone: wanted3.6.0   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Nuno Lopes 2009-04-02 14:12:00 UTC
Version:           3.4.1 (using Devel)
Compiler:          gcc 4.1.2 
OS:                Linux
Installed from:    Compiled sources

running a server in prolog under massif with the following cmd:
./valgrind/bin/valgrind --tool=massif --stacks=yes --alloc-fn=SP_malloc --alloc-fn=SP_realloc ./code/server -ref1

it crashes with:

Massif: ms_main.c:1700 (update_stack_stats): Assertion 'stacks_szB >= -stack_szB_delta' failed.
==6932==    at 0x38005EFD: report_and_quit (m_libcassert.c:140)
==6932==    by 0x380061E5: vgPlain_assert_fail (m_libcassert.c:205)
==6932==    by 0x3800070C: update_stack_stats (ms_main.c:1700)
==6932==    by 0x38003F0B: die_mem_stack (ms_main.c:1723)
==6932==    by 0x380171FE: vgPlain_unknown_SP_update (m_stacks.c:322)
==6932==    by 0x531AAB1: ???
==6932==    by 0x3817DCC7: (within /home/nlopes/valgrind/lib/valgrind/x86-linux/massif)
==6932==    by 0x4: ???
==6932==    by 0x100C625: ???
==6932==    by 0x1E: ???
==6932==    by 0x1E: ???
==6932==    by 0x478CBE8: ???
==6932==    by 0x478CBE8: ???
==6932==    by 0x478CC1C: ???
==6932==    by 0x478CC1C: ???
==6932==    by 0x478CBE8: ???
==6932==    by 0x38017C2B: vgPlain_do_syscall (m_syscall.c:531)
==6932==    by 0x478CC1C: ???
==6932==    by 0x61: ???
==6932==    by 0x478CC6C: ???
==6932==    by 0x61: ???

sched status:
  running_tid=1

Thread 1: status = VgTs_Runnable
==6932==    at 0x80A401D: recv_data_callback (helpers.c:176)

Thread 2: status = VgTs_WaitSys
==6932==    at 0x819963A: poll (in /home/nlopes/server)
==6932==    by 0x816DBEC: __pthread_manager (manager.c:152)
==6932==    by 0x819B1C9: clone (in /home/nlopes/server)

Thread 3: status = VgTs_WaitSys
==6932==    at 0x8199BEA: select (in /home/nlopes/server)

Thread 4: status = VgTs_WaitSys
==6932==    at 0x816FD83: __pthread_sigsuspend (pt-sigsuspend.c:56)
==6932==    by 0x816EEA7: __pthread_wait_for_restart_signal (pthread.c:1224)
==6932==    by 0x816CC6A: pthread_cond_wait (restart.h:34)
==6932==    by 0x80FB942: spio_cond_var_wait_pthread (in /home/nlopes/server)
==6932==    by 0x61716CF: ???

please note that valgrind was compiled with '-mpreferred-stack-boundary=4' because of bug #188656.
Comment 1 Nicholas Nethercote 2009-04-02 14:19:21 UTC
It would be helpful if you could add VG_(printf) calls to determine the values of stacks_szB and stack_szB_delta when the assert happens.  Thanks.
Comment 2 Nuno Lopes 2009-04-02 17:46:40 UTC
So this is what I get:
stacks_szB=65320
stack_szB_delta=-65564

I couldn't get a full history of values because it takes too much time to trigger this bug (I had to cancel the full history as the log file was already 10 GB long..)
Comment 3 Christian Borntraeger 2011-01-17 22:09:45 UTC
Does the program use longjmp?

If yes, then you could try the patch from this bug:
http://bugs.kde.org/show_bug.cgi?id=256043
Comment 4 Christian Borntraeger 2011-01-18 07:32:40 UTC
Sorry, you cant use the patch from the other bugzilla, since it is not for x86.
Still, it might be the same problem. I will have a look, if I can come up with something for x86.
Comment 5 Christian Borntraeger 2011-01-18 09:34:37 UTC
I added a possible fix for x86 in
https://bugs.kde.org/show_bug.cgi?id=256043

(https://bugs.kde.org/attachment.cgi?id=56155)

If that fixes the problem on x86, we would need something similar for the other platforms as well.