5

我正在尝试使用 Callgrind 来监视 SDL2 应用程序中的缓存使用情况,但它挂在 SDL_Init 调用上 - 编辑:澄清一下,Valgrind 挂起,我的程序没有进一步的输出,Valgrind 似乎陷入了等待函数调用完成,但它永远不会。这是展示问题的最小来源:

#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;
}

挂起时的输出:(已编辑以包含额外的调试信息,使用标志 -v -d 和 --fair-sched=try 生成)

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

运行valgrind ./Application也会给出错误(截断):

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)....

编辑:我试过通过 gdb 运行它,它非常高兴。通过 helgrind 或 drd 运行它会在 SDL_Init 调用中产生 segfault:11 。

Helgrind: hg_main.c:4470 (void instrument_mem_access(IRSB *, IRExpr *, Int, Bool, Int, Int, IRExpr *)): Assertion 'szB > 8 && szB <= 512' failed.

鉴于 gdb 是干净的,我认为通过 valgrind 运行 SDL 应用程序会导致这个问题,但我不知道它可能是什么,或者如何解决这个问题,我找不到任何关于它的进一步讨论我自己的调查。

来自 hlgrind 的完整堆栈跟踪:

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(最初是通过 brew 获得的),但这没有任何影响。

有谁知道为什么 Valgrind 会导致 SDL_Init 出现段错误,以及是否有办法解决这个问题?

谢谢

4

0 回答 0