【问题标题】:Can valgrind report a memory address of a lost block (for debugging recursive function calls)?valgrind 可以报告丢失块的内存地址(用于调试递归函数调用)吗?
【发布时间】:2016-08-31 09:18:31
【问题描述】:

This 的问题和我的最相似,但它比较老,所以我想知道从那以后有什么变化。

我的 valgrind 输出是:

==29443== 109 (16 direct, 93 indirect) bytes in 2 blocks are definitely lost in loss record 270 of 309
==29443==    at 0x4C2B0E0: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==29443==    by 0x4F4E8DB: grl::Configuration::Configuration(grl::Configuration const&) (configuration.h:192)
==29443==    by 0x4F49973: grl::YAMLConfigurator::load(YAML::Node const&, grl::Configuration*, std::string const&) (configurable.cpp:74)
==29443==    by 0x4F499FC: grl::YAMLConfigurator::load(YAML::Node const&, grl::Configuration*, std::string const&) (configurable.cpp:75)
==29443==    by 0x4F499FC: grl::YAMLConfigurator::load(YAML::Node const&, grl::Configuration*, std::string const&) (configurable.cpp:75)
==29443==    by 0x4F499FC: grl::YAMLConfigurator::load(YAML::Node const&, grl::Configuration*, std::string const&) (configurable.cpp:75)
==29443==    by 0x40C78E: grl::YAMLConfigurator::load(std::string, grl::Configuration*, std::string const&) (configurable.h:321)
==29443==    by 0x40B897: main (deployer.cpp:180)

程序在开始时配置为递归调用从 yaml 文件中读取并将所有必需的参数作为一对 (name, allocated address) 存储在映射中。我可以打印这些对。因此,如果 valgrind 可以告诉我丢失值的地址,那么我可以获取参数的名称并检查为什么它没有被释放。

如果功能不可用,我还能用什么?

【问题讨论】:

    标签: c++ recursion valgrind


    【解决方案1】:

    您可以使用 vgdb 在 valgrind+gdb 下运行您的程序。 见http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver

    然后就可以使用各种valgrind memcheck monitor 命令来做 泄漏搜索并具有泄漏块的地址/大小。 见http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.monitor-commands

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多