I'm trying to use Callgrind to control cache usage in an SDL2 application, but it freezes when SDL_Init is called - EDIT: To clarify, Valgrind hangs, there is no way out in my program, Valgrind seems to be stuck in suspense waiting for the function call to complete, but this never will not be. Here is a minimal source that demonstrates the problem:
#include <SDL.h>
#include <iostream>
int main (int argc, char *argv[]) {
std::cout << "SDL Init" << std::endl;
if (SDL_Init(SDL_INIT_VIDEO) != 0 ) {
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
std::cout << "Done" << std::endl;
SDL_Quit();
return 0;
}
Output when it freezes: (Edited to include additional debugging information generated using the -v -d and -fair-sched = try flags)
SDL Init
--5591:1: aspacem allocated valgrind thread stack at 0x7000050db000 size 1064960
--5591:1:syswrap- run_a_thread_NORETURN(tid=2): pre-thread_wrapper
--5591:1:syswrap- thread_wrapper(tid=2): entry
--5591-- REDIR: 0x104be985a (libsystem_malloc.dylib:malloc_size) redirected to 0x10013fb50 (malloc_size)
--5591-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--5591:1:mallocfr newSuperblock at 0x700005262000 (pszB 294880) unsplittable owner VALGRIND/ttaux
--5591:1:mallocfr reclaimSuperblock at 0x7000050AB000 (pszB 196576) unsplittable owner VALGRIND/ttaux
--5591-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--5591-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--5591:1: aspacem allocated valgrind thread stack at 0x70000532d000 size 1064960
--5591:1:syswrap- run_a_thread_NORETURN(tid=3): pre-thread_wrapper
--5591:1:syswrap- thread_wrapper(tid=3): entry
--5591:1: aspacem allocated valgrind thread stack at 0x700005431000 size 1064960
--5591:1:syswrap- run_a_thread_NORETURN(tid=4): pre-thread_wrapper
--5591:1:syswrap- thread_wrapper(tid=4): entry
--5591:1: aspacem allocated valgrind thread stack at 0x7000055b8000 size 1064960
--5591:1:syswrap- run_a_thread_NORETURN(tid=5): pre-thread_wrapper
--5591:1:syswrap- thread_wrapper(tid=5): entry
--5591-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
--5591:1:execonte resizing htab from size 1543 to 3079 (idx 2) Total#ECs=1544
--5591-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 16 times)
--5591:1:hashtabl resizing table `MC_(malloc_list)' from 1543 to 3079 (total elems 1544)
--5591:1:syswrap- thread_wrapper(tid=3): done
--5591:1:syswrap- run_a_thread_NORETURN(tid=3): post-thread_wrapper
--5591:1:syswrap- run_a_thread_NORETURN(tid=3): not last one standing
--5591:1:syswrap- thread_wrapper(tid=5): done
--5591:1:syswrap- run_a_thread_NORETURN(tid=5): post-thread_wrapper
--5591:1:syswrap- run_a_thread_NORETURN(tid=5): not last one standing
Execution only valgrind ./Applicationalso gives errors (truncated):
Conditional jump or move depends on uninitialised value(s)
at 0x7FFF5FC24A87: bcmp (in /usr/lib/dyld)....
Use of uninitialised value of size 8
at 0x7FFF5FC24A9F: bcmp (in /usr/lib/dyld)....
Use of uninitialised value of size 8
at 0x7FFF5FC24A9F: bcmp (in /usr/lib/dyld)....
Use of uninitialised value of size 8
at 0x7FFF5FC24A9F: bcmp (in /usr/lib/dyld)....
EDIT: I tried running it through gdb, its completely pleased. Running through helgrind or drd gives segfault: 11 in the SDL_Init call.
Helgrind: hg_main.c:4470 (void instrument_mem_access(IRSB *, IRExpr *, Int, Bool, Int, Int, IRExpr *)): Assertion 'szB > 8 && szB <= 512' failed.
, gdb , , - SDL valgrind , , , .
helgrind:
Thread 1: status = VgTs_Runnable (lwpid 2567)
==30388== at 0x103BE5C3D: _dispatch_alloc_continuation_from_heap_slow (in /usr/lib/system/libdispatch.dylib)
==30388== by 0x103BE5C0E: _dispatch_alloc_continuation_alloc (in /usr/lib/system/libdispatch.dylib)
==30388== by 0x103BE59D6: dispatch_source_set_event_handler (in /usr/lib/system/libdispatch.dylib)
==30388== by 0x103F16D05: _notify_lib_init (in /usr/lib/system/libsystem_notify.dylib)
==30388== by 0x103F176C2: notify_register_dispatch (in /usr/lib/system/libsystem_notify.dylib)
==30388== by 0x1021D0096: __71+[CFPrefsSource withSourceForIdentifier:user:byHost:container:perform:]_block_invoke_2 (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x103BE333E: _dispatch_client_callout (in /usr/lib/system/libdispatch.dylib)
==30388== by 0x103BE3236: dispatch_once_f (in /usr/lib/system/libdispatch.dylib)
==30388== by 0x1020C6A7A: +[CFPrefsSource withSourceForIdentifier:user:byHost:container:perform:] (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x10221D1AF: -[CFPrefsSearchListSource addSourceForIdentifier:user:byHost:container:] (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x10221C9E9: __73+[CFPrefsSearchListSource withSearchListForIdentifier:container:perform:]_block_invoke (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x10221C732: +[CFPrefsSearchListSource withSearchListForIdentifier:container:perform:] (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x10224F5C6: _CFPreferencesCopyAppValueWithContainer (in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation)
==30388== by 0x10480B9C8: -[NSUserDefaults(NSUserDefaults) init] (in /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation)
==30388== by 0x10480B3B6: +[NSUserDefaults(NSUserDefaults) standardUserDefaults] (in /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation)
==30388== by 0x100BBE5C7: +[NSApplication initialize] (in /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit)
==30388== by 0x1003553C7: call_load_methods (in /usr/lib/libobjc.A.dylib)
==30388== by 0x100355155: class_createInstance (in /usr/lib/libobjc.A.dylib)
==30388== by 0x100354D07: NXMapRemove (in /usr/lib/libobjc.A.dylib)
==30388== by 0x10034F590: objc_msgSend (in /usr/lib/libobjc.A.dylib)
==30388== by 0x1000BDC8F: Cocoa_RegisterApp (in /usr/local/lib/libSDL2-2.0.0.dylib)
==30388== by 0x1000C229B: Cocoa_CreateDevice (in /usr/local/lib/libSDL2-2.0.0.dylib)
==30388== by 0x1000B655B: SDL_VideoInit_REAL (in /usr/local/lib/libSDL2-2.0.0.dylib)
==30388== by 0x100020C69: SDL_InitSubSystem_REAL (in /usr/local/lib/libSDL2-2.0.0.dylib)
==30388== by 0x100002E80: main (main.cpp:14)
El Capitan Macbook, Valgrind-3.12.0.SVN LibVEX SDL2-2.0.4.
SDL2, Valgrind fom ( brew), .
- , Valgrind SDL_Init segfault ?