Valgrind不会将输出发送到文件

时间:2019-03-13 16:59:04

标签: linux valgrind

全部

igor@IgorReinCloud ~/dbhandler/Debug/dbhandler $ valgrind --demangle=yes dbhandler --log-file=memcheck.log --leak-check=full
==28275== Memcheck, a memory error detector
==28275== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==28275== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==28275== Command: dbhandler --log-file=memcheck.log --leak-check=full

// Some errors logged on screen

Unknown long option 'log-file'

// Some more errors logged on screen

Usage: dbhandler [-h] [--verbose]
  -h, --help    show this help message
  --verbose     generate verbose log messages
==28275==
==28275== HEAP SUMMARY:
==28275==     in use at exit: 1,549,966 bytes in 16,372 blocks
==28275==   total heap usage: 177,899 allocs, 161,527 frees,
10,849,729 bytes allocated
==28275==
==28275== LEAK SUMMARY:
==28275==    definitely lost: 0 bytes in 0 blocks
==28275==    indirectly lost: 0 bytes in 0 blocks
==28275==      possibly lost: 3,408 bytes in 32 blocks
==28275==    still reachable: 1,464,270 bytes in 15,670 blocks
==28275==                       of which reachable via heuristic:
==28275==                         length64           : 4,872 bytes in 81 blocks
==28275==                         newarray           : 2,096 bytes in 51 blocks
==28275==         suppressed: 0 bytes in 0 blocks
==28275== Rerun with --leak-check=full to see details of leaked memory
==28275==
==28275== For counts of detected and suppressed errors, rerun with: -v
==28275== Use --track-origins=yes to see where uninitialised values come from
==28275== ERROR SUMMARY: 28 errors from 8 contexts (suppressed: 0 from 0)

但是,

igor@IgorReinCloud ~/dbhandler/Debug/dbhandler $ valgrind --help | grep log
    --time-stamp=no|yes       add timestamps to log messages? [no]
    --log-fd=<number>         log messages to file descriptor [2=stderr]
    --log-file=<file>         log messages to <file>
    --log-socket=ipaddr:port  log messages to socket ipaddr:port
igor@IgorReinCloud ~/dbhandler/Debug/dbhandler $

那么问题是什么?为什么消息不按原样应发送到日志文件?我在这里缺少选项吗?

TIA!

1 个答案:

答案 0 :(得分:1)

在要检查的程序之前,将选项放入Valgrind。它假定程序名称后的选项是程序的选项,而不是Valgrind。

因此,您有:

valgrind --demangle=yes dbhandler --log-file=memcheck.log --leak-check=full

但您应该使用:

valgrind --demangle=yes --log-file=memcheck.log --leak-check=full dbhandler

或者甚至使用--声明您已经完成了Valgrind的选项:

valgrind --demangle=yes --log-file=memcheck.log --leak-check=full -- dbhandler

Unknown long option log-file消息可能来自dbhandler,而不是Valgrind。这也是为什么您从dbhandler收到“使用情况”消息的原因。