运行 NVIDIA Jetson 上的 valgrind 没有给出泄漏源信息
Running valgrind on NVIDIA Jetson gives no leak source information
tl;博士
valgrind 未显示可访问的内存泄漏源
详情
C++ 应用程序是使用带有以下额外选项的 cmake 构建的:
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3 -O0")
set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -O0")
已通过 make VERBOSE=1
命令。
运行 /usr/bin/valgrind --num-callers=500 --trace-children=yes --leak-check=full --show-reachable=yes -v --track-origins=yes --show-leak-kinds=all ./aplication --application params
的输出表明已加载相关符号。
为了检查内存泄漏,valgrind 与 gdb 结合使用,可以在任意时间间隔后检查 valgrind 报告。这些报告表明可访问内存逐渐增加 - 表明泄漏。
问题是 valgrind 没有提供任何可能导致内存泄漏的有用见解。输出结果如下:
==21466== Searching for pointers to 10,678 not-freed blocks
==21466== Checked 71,211,640 bytes
==21466==
==21466== 984 bytes in 42 blocks are still reachable in loss record 1 of 6
==21466== at 0x4845494: operator new(unsigned long, std::nothrow_t const&) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 2,560 bytes in 8 blocks are possibly lost in loss record 2 of 6
==21466== at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 17,512 bytes in 3 blocks are still reachable in loss record 3 of 6
==21466== at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 405,564 bytes in 977 blocks are still reachable in loss record 4 of 6
==21466== at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 468,429 bytes in 3,965 blocks are still reachable in loss record 5 of 6
==21466== at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 2,166,764 bytes in 5,683 blocks are still reachable in loss record 6 of 6
==21466== at 0x484522C: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== LEAK SUMMARY:
==21466== definitely lost: 0 bytes in 0 blocks
==21466== indirectly lost: 0 bytes in 0 blocks
==21466== possibly lost: 2,560 bytes in 8 blocks
==21466== still reachable: 3,059,253 bytes in 10,670 blocks
==21466== suppressed: 0 bytes in 0 blocks
是否还有其他方法可以让 valgrind 提供更多关于泄漏源的信息?
环境
- 硬件包:NVIDIA Jetson
- nv_tegra_release:R32(发布),修订版:5.1,GCID:27362550,董事会:t186ref,EABI:aarch64,日期:5 月 19 日,星期三 18:16:00 世界协调时间 2021
- linux 发行版:Ubuntu 18.04.5 LTS
- cpu型号:AMD锐龙5 3600X 6核处理器
- cpu 建筑: x86_64
- valgrind: 3.13.0
参考资料
- How to Run Valgrind
- Still Reachable Leak detected by Valgrind
- 使用 valgrind
使用 gdb
更新
卸载之前通过 apt 安装的 valgrind (v3.13) 并通过 snap 安装 valgrind (v3.17) 解决了这个问题。
如果 valgrind 出现问题,始终建议尝试使用最新版本,最新版本或 git 版本。
请注意,从源代码重新编译 valgrind 非常容易,因为它几乎没有依赖项。
如果堆栈跟踪出现特定问题,使用 valgrind + gdb + vgdb 比较 valgrind 和 gdb 生成的堆栈跟踪总是有用的。
在gdb的相关地方打断点,然后就可以对比gdb backtrace命令产生的gdb stacktrace和monitoring命令产生的valgrind stacktrace:
(gdb) monitor v.info scheduler
tl;博士
valgrind 未显示可访问的内存泄漏源
详情
C++ 应用程序是使用带有以下额外选项的 cmake 构建的:
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3 -O0")
set(CMAKE_C_FLAGS_DEBUG "-ggdb3 -O0")
已通过 make VERBOSE=1
命令。
运行 /usr/bin/valgrind --num-callers=500 --trace-children=yes --leak-check=full --show-reachable=yes -v --track-origins=yes --show-leak-kinds=all ./aplication --application params
的输出表明已加载相关符号。
为了检查内存泄漏,valgrind 与 gdb 结合使用,可以在任意时间间隔后检查 valgrind 报告。这些报告表明可访问内存逐渐增加 - 表明泄漏。
问题是 valgrind 没有提供任何可能导致内存泄漏的有用见解。输出结果如下:
==21466== Searching for pointers to 10,678 not-freed blocks
==21466== Checked 71,211,640 bytes
==21466==
==21466== 984 bytes in 42 blocks are still reachable in loss record 1 of 6
==21466== at 0x4845494: operator new(unsigned long, std::nothrow_t const&) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 2,560 bytes in 8 blocks are possibly lost in loss record 2 of 6
==21466== at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 17,512 bytes in 3 blocks are still reachable in loss record 3 of 6
==21466== at 0x4846D10: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 405,564 bytes in 977 blocks are still reachable in loss record 4 of 6
==21466== at 0x4846B0C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 468,429 bytes in 3,965 blocks are still reachable in loss record 5 of 6
==21466== at 0x4844BFC: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== 2,166,764 bytes in 5,683 blocks are still reachable in loss record 6 of 6
==21466== at 0x484522C: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==21466==
==21466== LEAK SUMMARY:
==21466== definitely lost: 0 bytes in 0 blocks
==21466== indirectly lost: 0 bytes in 0 blocks
==21466== possibly lost: 2,560 bytes in 8 blocks
==21466== still reachable: 3,059,253 bytes in 10,670 blocks
==21466== suppressed: 0 bytes in 0 blocks
是否还有其他方法可以让 valgrind 提供更多关于泄漏源的信息?
环境
- 硬件包:NVIDIA Jetson
- nv_tegra_release:R32(发布),修订版:5.1,GCID:27362550,董事会:t186ref,EABI:aarch64,日期:5 月 19 日,星期三 18:16:00 世界协调时间 2021
- linux 发行版:Ubuntu 18.04.5 LTS
- cpu型号:AMD锐龙5 3600X 6核处理器
- cpu 建筑: x86_64
- valgrind: 3.13.0
参考资料
- How to Run Valgrind
- Still Reachable Leak detected by Valgrind
- 使用 valgrind 使用 gdb
更新
卸载之前通过 apt 安装的 valgrind (v3.13) 并通过 snap 安装 valgrind (v3.17) 解决了这个问题。
如果 valgrind 出现问题,始终建议尝试使用最新版本,最新版本或 git 版本。
请注意,从源代码重新编译 valgrind 非常容易,因为它几乎没有依赖项。
如果堆栈跟踪出现特定问题,使用 valgrind + gdb + vgdb 比较 valgrind 和 gdb 生成的堆栈跟踪总是有用的。
在gdb的相关地方打断点,然后就可以对比gdb backtrace命令产生的gdb stacktrace和monitoring命令产生的valgrind stacktrace:
(gdb) monitor v.info scheduler