0x805C19A:main(in /bin/bash)-->这是Valgrind的输出

xnifntxz  于 2023-05-28  发布在  其他
关注(0)|答案(2)|浏览(104)

***编译代码:***make BUILD = TARGET_ -->编译代码

使用Valgrind编译源代码的命令。你知道吗?

***为C/C++文件运行valgrind的命令***valgrind --tool=memcheck --leak-check=yes --show-reachable=yes。/<file_name>
输出如下:

==16702== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 14 from 1)
==16702== malloc/free: in use at exit: 13,165 bytes in 414 blocks.
==16702== malloc/free: 1,219 allocs, 805 frees, 176,926 bytes allocated.
==16702== For counts of detected errors, rerun with: -v
==16702== searching for pointers to 414 not-freed blocks.
==16702== checked 108,004 bytes.
==16702==
==16702== 80 bytes in 1 blocks are definitely lost in loss record 1 of 4
==16702==    at 0x4004405: malloc (vg_replace_malloc.c:149)
==16702==    by 0x8095A91: xmalloc (in /bin/bash)
==16702==    by 0x806AC84: execute_command_internal (in /bin/bash)
==16702==    by 0x806C72F: execute_command (in /bin/bash)
==16702==    by 0x805DE1A: reader_loop (in /bin/bash)
==16702==    by 0x805CEE1: main (in /bin/bash)
==16702==
==16702==
==16702== 128 bytes in 1 blocks are still reachable in loss record 2 of 4
==16702==    at 0x400579F: realloc (vg_replace_malloc.c:306)
==16702==    by 0x8095AFC: xrealloc (in /bin/bash)
==16702==    by 0x8067484: (within /bin/bash)
==16702==    by 0x8067525: (within /bin/bash)
==16702==    by 0x8066DD4: (within /bin/bash)
==16702==    by 0x806712D: (within /bin/bash)
==16702==    by 0x8067B92: print_simple_command (in /bin/bash)
==16702==    by 0x806A3D6: execute_command_internal (in /bin/bash)
==16702==    by 0x806C72F: execute_command (in /bin/bash)
==16702==    by 0x805DE1A: reader_loop (in /bin/bash)
==16702==    by 0x805CEE1: main (in /bin/bash)
==16702==
==16702==
==16702== 2,092 bytes in 4 blocks are still reachable in loss record 3 of 4
==16702==    at 0x4004405: malloc (vg_replace_malloc.c:149)
==16702==    by 0x8095B13: xrealloc (in /bin/bash)
==16702==    by 0x8085F7C: (within /bin/bash)
==16702==    by 0x8086146: fd_to_buffered_stream (in /bin/bash)
==16702==    by 0x8086613: with_input_from_buffered_stream (in /bin/bash)
==16702==    by 0x805CFC3: main (in /bin/bash)
==16702==
==16702==
==16702== 10,865 bytes in 408 blocks are still reachable in loss record 4 of 4
==16702==    at 0x4004405: malloc (vg_replace_malloc.c:149)
==16702==    by 0x8095A91: xmalloc (in /bin/bash)
==16702==    by 0x8090EE1: set_default_locale (in /bin/bash)
==16702==    by 0x805C19A: main (in /bin/bash)
==16702==
==16702== LEAK SUMMARY:
==16702==    definitely lost: 80 bytes in 1 blocks.
==16702==      possibly lost: 0 bytes in 0 blocks.
==16702==    still reachable: 13,085 bytes in 413 blocks.
==16702==         suppressed: 0 bytes in 0 blocks.

我怎样才能编译和使用命令,以这样的方式,我得到更多的文件和行号,而不是(/bin/bash)?

ojsjcaue

ojsjcaue1#

猜测您正在运行运行测试exe的shell脚本。
试试--trace-children=yes
如果可能的话,用调试信息构建你的测试exe。通常在makefile中添加-gCFLAGS和/或CXXFLAGS

hmae6n7t

hmae6n7t2#

“用Valgrind编译源代码”
以前从没做过...不知道你什么意思...
我以前用过的一些有用的设置
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --trace-children=yes --vgeb=true --log-file=log.txt程序
如果你用符号编译,它也会有帮助。含义
编译时使用-O -g或-Og -g而不是-O2
或者甚至是...
哦你也可以试试
--vgdb-error=0
和瓦尔金德一起跑我想它停下来,把gdb拉起来
$> man valgring

$> valgrind -h
希望能帮上忙

相关问题