valgrind and iOS SDK 4.2?

2019-03-21 15:13发布

问题:

Having problems running iOS 4.2 apps with valgrind.

I installed valgrind 3.6.0-SVN from Macports. XCode 3.2.5.

When I modify my main() to run valgrind I get the following output:


Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
open$UNIX2003 called from function _vgrZU_libSystemZdZaZddylib_arc4random in image vgpreload_core-x86-darwin.so.
If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first.

==99640== 
==99640== Process terminating with default action of signal 6 (SIGABRT)
==99640==    at 0x8B5DEF6: __kill (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8BF062C: raise (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8C066E3: abort (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x33F2547: __springboard_unimplemented (in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libSystem.dylib)
==99640==    by 0x33FC208: open$UNIX2003 (in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libSystem.dylib)
==99640==    by 0x1AAD6F3: arc4random (vg_preloaded.c:163)
==99640==    by 0x8AFFB7E: create_scalable_zone (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8AFF7EA: _malloc_initialize (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8B23449: malloc_create_zone (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8B233F8: _dispatch_ccache_init (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8B21E0D: dispatch_once_f (in /usr/lib/libSystem.B.dylib)
==99640==    by 0x8B233D3: _dispatch_continuation_alloc_from_heap (in /usr/lib/libSystem.B.dylib)

The error seems to be pretty clear. How can I fix this? I've heard of successful attempts running valgrind on SDK 3.x. What has changed?

Any other advice?

回答1:

This is a hideous hack, and I have no idea what the implications are... but it did solve the problem:

In your valgrind source, open up vg_preloaded.c and find line 163 (referenced in your stack trace there). Change the code that is there to:

/*    if (rnd < 0) rnd = open("/dev/random", O_RDONLY);                     
      read(rnd, &result, sizeof(result)); */
result = random();

This appears to be the only thing that keeps valgrind from working... Your mileage may vary.



回答2:

Add the following to the top of one of your Objective-C files:

#import "stdio.h"
#import "fcntl.h"

int open$UNIX2003(const char *pathname, int flags, mode_t mode) {
    return open(pathname, flags, mode);
}

int read$UNIX2003(int fildes, void *buf, size_t nbyte) {
    return read(fildes, buf, nbyte);
}

int close$UNIX2003(int fildes) {
    return close(fildes);
}