代码之家  ›  专栏  ›  技术社区  ›  Igor

Valgrind不将输出发送到文件

  •  0
  • Igor  · 技术社区  · 5 年前

    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 $
    

    那么问题是什么呢?为什么这些消息没有像它应该的那样进入日志文件?我是不是错过了一个选择?

    蒂亚!

    0 回复  |  直到 5 年前
        1
  •  1
  •   Jonathan Leffler    5 年前

    在你想检查的程序之前把选项放到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 --demangle=yes --log-file=memcheck.log --leak-check=full -- dbhandler
    

    Unknown long option log-file 消息可能来自 dbhandler 而不是瓦尔格林。这也是为什么你会从 数据库处理程序 .