Is it possible to run valgrind on an iOS simulator and device?

I need to debug heap overflow in a very large project. After playing with valgrind a bit, it seems like the perfect tool to detect heap block overflows in C, so I would like to run an iOS application with it.

I built and installed valgrind from trunk on OS X Yosemite and wrote a test program with deliberate heap overflow and checked that valgrind catches and reports this.

Now I want to run a test application in a simulator. I read that it can be run in the iOS simulator using execl (), but when I do this, I see the following error in the console.

dyld: missing load command LC_DYLD_INFO

After that, the application crashes in dyldbootstrap :: rebaseDyld () with EXC_BAD_ACCESS. Is something else needed here? Valgrind apparently also supports arm64 now. Is it possible to pack the valgrind executable file with my application and run it on the device?

#define VALGRIND "/usr/local/bin/valgrind" int main(int argc, char * argv[]) { if ( argc >= 2 && strcmp(argv[1], "-valgrind") == 0 ) { if ( execl(VALGRIND, VALGRIND, argv[0], NULL) < 0 ) { NSLog(@"Failed to relaunch under valgrind"); exit(1); } NSLog(@"Running under valgrind!!"); } @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } 
+5
source share
1 answer

You can use xcrun simctl spawn to start an arbitrary process on the simulator, but you cannot run macOS executables in the simulator environment. It shares a kernel with macOS, but is otherwise different. You will need to build Valgrind for iOS and then drop it in the device data directory and try to propagate it.

0
source

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


All Articles