我试图在非常简单的项目中运行valgrind 3.13和3.14(在macOs 10.12.6上),但我得到了一个奇怪的错误,我之前从未进入过linux。
非常简单的C程序"selector-class-pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
:
main.c
使用int main() {
return (0);
}
进行编译:
cc
使用$> cc main.c
运行我的简单程序:
valgrind
valgrind的输出:
$> valgrind ./a.out
我不明白这一部分的痕迹:
==12768== Memcheck, a memory error detector
==12768== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==12768== Using Valgrind-3.14.0.SVN and LibVEX; rerun with -h for copyright info
==12768== Command: ./a.out
==12768==
==12768== Syscall param msg->desc.port.name points to uninitialised byte(s)
==12768== at 0x10049434A: mach_msg_trap (in /usr/lib/system/libsystem_kernel.dylib)
==12768== by 0x100493796: mach_msg (in /usr/lib/system/libsystem_kernel.dylib)
==12768== by 0x10048D485: task_set_special_port (in /usr/lib/system/libsystem_kernel.dylib)
==12768== by 0x10062910E: _os_trace_create_debug_control_port (in /usr/lib/system/libsystem_trace.dylib)
==12768== by 0x100629458: _libtrace_init (in /usr/lib/system/libsystem_trace.dylib)
==12768== by 0x1001599DF: libSystem_initializer (in /usr/lib/libSystem.B.dylib)
==12768== by 0x100017A1A: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==12768== by 0x100017C1D: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld)
==12768== by 0x1000134A9: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==12768== by 0x100013440: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==12768== by 0x100012523: ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (in /usr/lib/dyld)
==12768== by 0x1000125B8: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld)
==12768== Address 0x10488ac6c is on thread 1's stack
==12768== in frame #2, created by task_set_special_port (???:)
==12768== Uninitialised value was created by a stack allocation
==12768== at 0x1006290A6: _os_trace_create_debug_control_port (in /usr/lib/system/libsystem_trace.dylib)
==12768==
==12768==
==12768== HEAP SUMMARY:
==12768== in use at exit: 18,144 bytes in 162 blocks
==12768== total heap usage: 178 allocs, 16 frees, 24,288 bytes allocated
==12768==
==12768== LEAK SUMMARY:
==12768== definitely lost: 3,456 bytes in 54 blocks
==12768== indirectly lost: 0 bytes in 0 blocks
==12768== possibly lost: 72 bytes in 3 blocks
==12768== still reachable: 200 bytes in 6 blocks
==12768== suppressed: 14,416 bytes in 99 blocks
==12768== Rerun with --leak-check=full to see details of leaked memory
==12768==
==12768== For counts of detected and suppressed errors, rerun with: -v
==12768== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
我不明白为什么堆简要是如此之大(178个分配,16个释放,分配24,288个字节)我的简单返回(0);程序
答案 0 :(得分:3)
Valgrind有一个抑制错误的系统。抑制规则在特殊文件中指定,例如$PREFIX/lib/valgrind/default.supp
。用户可以使用--gen-suppressions=full
辅助工具创建自己的规则,这将为遇到的每个错误打印抑制规则。然后,用户可以根据自己的需要对其进行自定义。
我是针对有问题的错误做的,而且效果很好!无需安装不稳定版本。如果您遇到其他报告的错误,这也是一个很好的工具。
我将此文件保存为~/.valgrind.supp
。
# false positive for any executable (it seems)
# macOS 10.12.6
# valgrind 3.13.0
{
libtrace initialization false positive
Memcheck:Param
msg->desc.port.name
fun:mach_msg_trap
fun:mach_msg
fun:task_set_special_port
fun:_os_trace_create_debug_control_port
fun:_libtrace_init
}
#
发表评论,{}
表示规则。第一行是规则的名称。第二个说明要抑制哪个工具和错误类型。 Param
表示无效的系统调用参数,下一行给出了用于抑制错误的参数。以fun:
开头的以下行表示此抑制规则仅适用于由mach_msg_trap
调用的mach_msg
调用的task_set_special_port
,依此类推。这样我们只在这种非常特殊的情况下抑制错误,其中Valgrind错误地将libtrace初始化为错误。
如果您在命令行中提供参数--suppressions=$HOME/.valgrind.supp
,或者将其放在$VALGRIND_OPTS
或~/.valgrindrc
中,Valgrind将使用此规则。
答案 1 :(得分:1)