Valgrind and iOS SDK 4.2?

Problems launching iOS 4.2 applications with valgrind.

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

When I change 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 pretty clear. How can i fix this? I heard about successful attempts to run valgrind on SDK 3.x. What changed?

Any other tips?

+4
source share
2 answers

This is a disgusting hack, and I don’t know what the consequences are ... but he solved the problem:

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

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

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

+4
source

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);
 }
+2
source

Source: https://habr.com/ru/post/1334280/