英文:
valgrind ends without printing summary
问题
我想使用Valgrind来查看我的程序是否存在内存错误。
我想在Alpine Linux上运行这个程序,它使用了不同的标准C库(musl与glibc)。
以下是在Alpine Linux上使用Valgrind对“echo”命令的示例输出:
/ # valgrind echo "hi"
==480== Memcheck, a memory error detector
==480== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==480== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==480== Command: echo hi
==480==
hi
==480==
==480== HEAP SUMMARY:
==480== in use at exit: 0 bytes in 0 blocks
==480== total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==480==
==480== All heap blocks were freed -- no leaks are possible
==480==
==480== For lists of detected and suppressed errors, rerun with: -s
==480== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
如预期,“echo”程序没有问题。
当我在Alpine上使用Valgrind运行我的程序(传递--track-origins=yes,--leak-check=full不会引起任何变化)时:
/ # valgrind work/test_lib
==481== Memcheck, a memory error detector
==481== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==481== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==481== Command: work/test_lib
==481==
Please pass path to lib + config + (optional data_json) (optional output path)
/ #
摘要信息缺失。我看不到任何错误。程序本身非常简单 - 只是在检查程序未接收到2个输入参数后打印行。此外,当我使用参数运行程序时,它能够正确运行并打印正确的输出结果。在这两种情况下,程序结束后都没有Valgrind摘要输出。
在另一台机器上(Centos),Valgrind确实在最后打印了Valgrind摘要报告(没有问题)。
该程序使用gcc-4.8和glibc编译,但没有任何特殊依赖项:
g++ -Wall --std=c++11 -ldl -march=x86-64 -msse2 -msse3 -msse4 test_lib.cpp -o test_lib
/ # ldd work/test_lib
/lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fc52c0cd000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc52c0af000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
我期望在Alpine Linux上使用Valgrind运行我的程序后能看到Valgrind摘要报告。
英文:
I want to use valgrind to see if my program has memory errors.
I want to run the program on Alpine linux which has different standard c library (musl vs glibc).
Here is and example output on "echo" command with valgrind on the Alpine linux:
/ # valgrind echo "hi"
==480== Memcheck, a memory error detector
==480== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==480== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==480== Command: echo hi
==480==
hi
==480==
==480== HEAP SUMMARY:
==480== in use at exit: 0 bytes in 0 blocks
==480== total heap usage: 1 allocs, 1 frees, 4 bytes allocated
==480==
==480== All heap blocks were freed -- no leaks are possible
==480==
==480== For lists of detected and suppressed errors, rerun with: -s
==480== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
As expected there are no problems in "echo" program.
When I run my program with valgrind on Alpine (passing--track-origins=yes, --leak-check=full doesn't cause any change):
/ # valgrind work/test_lib
==481== Memcheck, a memory error detector
==481== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==481== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==481== Command: work/test_lib
==481==
Please pass path to lib + config + (optional data_json) (optional output path)
/ #
The summary is missing. I don't see any errors. The program itself is very simple - just prints the lines after checking the program didn't receive 2 input parameters. Also when I run the program with arguments, it runs correctly and prints the right output result. There is no valgrind summary output after program ends in both cases.
In the other machine (Centos) valgrind indeed print valgrind summary output in the end (which is clean of problems).
The program was complied with gcc-4.8 and glibc, but without any special dependencies:
g++ -Wall --std=c++11 -ldl -march=x86-64 -msse2 -msse3 -msse4 test_lib.cpp -o test_lib
/ # ldd work/test_lib
/lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fc52c0cd000)
libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fc52c0af000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7fc52c31b000)
I was expecting to see valgrind summary report after running my program with valgrind on Alpine linux.
答案1
得分: 1
OK,
正在执行的代码是:
if (argc <= 2) { printf("请传递库的路径 + ...\n"); return -1; }
我看不出需要添加"--trace-children=yes" 以使 valgrind 在这种情况下工作。
但是 Alpine(因为它是使用 glibc 编译的)会导致创建一个子进程。为使用 glibc 编译的程序在 Alpine 中添加"--trace-children=yes" 可以解决此问题。
我尝试使用 ps -ef | more
跟踪"child" 进程
> valgrind --trace-children=yes /lib/ld-musl-x86_64.so.1 --argv0
> ./test_lib --preload /lib/libgcompat.so.0
> /usr/libexec/valgrind/vgpreload_core-amd64-linux.so:/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so
> -- /work/test_lib
当运行"valgrind echo hi" 时,我看不到所有这些"--preload"。
英文:
OK,
The code that is being executed is:
if (argc <= 2) { printf("Please pass path to lib + ...\n"); return -1; }
I don't see a reason to add "--trace-children=yes" to cause valgrind to work in this case.
But Alpine (since it was compiled with glibc) causes this to create a child process. Adding "--trace-children=yes" solves the problem in Alpine for programs that were compiled with glibc.
I tried to track the "child" process using ps -ef | more
> valgrind --trace-children=yes /lib/ld-musl-x86_64.so.1 --argv0
> ./test_lib --preload /lib/libgcompat.so.0
> /usr/libexec/valgrind/vgpreload_core-amd64-linux.so:/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so
> -- /work/test_lib
when running "valgrind echo hi", I don't see all those "--preload"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论