所有人,

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 $

那么问题是什么?为什么消息不会按原样进入日志文件?我是不是错过了一个选择?
蒂亚!

最佳答案

在你想检查的程序之前把选项放到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获得“用法”消息的原因。

关于linux - Valgrind不会将输出发送到文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55147436/

10-15 06:43