Bug 301281 - valgrind hangs on OS X when the process calls system()
Summary: valgrind hangs on OS X when the process calls system()
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources macOS
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
: 284004 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-06 13:27 UTC by Greg Hazel
Modified: 2012-08-20 12:43 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Valgrind test case demonstrating the problem (276.79 KB, text/plain)
2012-08-13 14:29 UTC, erikacule
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Hazel 2012-06-06 13:27:01 UTC
When running my application with valgrind, the process hangs and cannot be ctrl-C'd. Removing calls to system() from my application prevents the hang. Setting --trace-children=no does not help.

Reproducible: Always

Steps to Reproduce:
1. Run an app which calls system(), under valgrind

Actual Results:  
Hang

Expected Results:  
No hang

OS X 10.7.4, x86_64
Comment 1 erikacule 2012-08-13 14:29:05 UTC
Created attachment 73140 [details]
Valgrind test case demonstrating the problem

Log generated by 

R -d "valgrind --tool=none --smc-check=all --trace-syscalls=yes" --vanilla < test.R &> valgrind_R_log.dat

test.R contains
print(seq(10))
Comment 2 erikacule 2012-08-13 14:32:01 UTC
I also encounter this problem, encountered when I ran R 2.15.1 under valgrind 3.9.0.SVN or valgrind 3.8.0.

The running process can only be terminated using SIGKILL.

I am using OS X 10.6.8, x86_64

I attached the with output "--trace-syscalls=yes" above.
Comment 3 Julian Seward 2012-08-17 10:18:37 UTC
*** Bug 284004 has been marked as a duplicate of this bug. ***
Comment 4 Julian Seward 2012-08-17 10:26:18 UTC
Here's a slightly simpler test case :-)

  #include <stdlib.h>
  int main ( void ) { system("/bin/date"); return 0; }

It seems that system() on Darwin calls __posix_spawn, and we wind up
in PRE(posix_spawn) in coregrind/m_syswrap/syswrap-darwin.c, and the
call "VG_(gdbserver) (tid);" never returns.  Philippe, any idea why?

In the meantime a simple workaround is simply to disable that call, as
follows:


Index: coregrind/m_syswrap/syswrap-darwin.c
===================================================================
--- coregrind/m_syswrap/syswrap-darwin.c	(revision 12864)
+++ coregrind/m_syswrap/syswrap-darwin.c	(working copy)
@@ -2835,7 +2835,7 @@
    VG_(debugLog)(1, "syswrap", "Posix_spawn of %s\n", (Char*)ARG2);
 
    // Terminate gdbserver if it is active.
-   if (VG_(clo_vgdb)  != Vg_VgdbNo) {
+   if (0 && VG_(clo_vgdb)  != Vg_VgdbNo) {
       // If the child will not be traced, we need to terminate gdbserver
       // to cleanup the gdbserver resources (e.g. the FIFO files).
       // If child will be traced, we also terminate gdbserver: the new
Comment 5 Philippe Waroquiers 2012-08-18 09:51:18 UTC
Should be fixed by revision 12879.
Comment 6 Philippe Waroquiers 2012-08-20 09:27:50 UTC
After more in depth analysis, committed another fix (revision 12882).
Comment 7 Julian Seward 2012-08-20 12:43:27 UTC
There was also a small followup change in r12883.  Closing since this is now fixed.