转储valgrind数据 [英] dump valgrind data

查看:87
本文介绍了转储valgrind数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行无限循环的程序上使用valgrind.

I am using valgrind on a program which runs an infinite loop.

由于memcheck在程序结束后显示内存泄漏,但是由于我的程序具有无限循环,因此它将永远不会结束.

As memcheck displays the memory leaks after the end of the program, but as my program has infinite loop it will never end.

那么我有什么办法可以不时地强制从valgrind中转储数据.

So is there any way i can forcefully dump the data from valgrind time to time.

谢谢

推荐答案

看看客户端请求功能.您可能可以使用VALGRIND_DO_LEAK_CHECK或类似名称.

Have a look at the client requests feature of memcheck. You can probably use VALGRIND_DO_LEAK_CHECK or similar.

编辑:

针对上述说法,这是行不通的.这是一个永远循环的示例程序:

In response to the statement above that this doesn't work. Here is an example program which loops forever:

#include <valgrind/memcheck.h>
#include <unistd.h>
#include <cstdlib>

int main(int argc, char* argv[])
{

  while(true) {
    char* leaked = new char[1];
    VALGRIND_DO_LEAK_CHECK;
    sleep(1);
  }

  return EXIT_SUCCESS;
}

当我在valgrind中运行此命令时,我会得到无尽的新泄漏输出:

When I run this in valgrind, I get an endless output of new leaks:

$ valgrind ./a.out
==16082== Memcheck, a memory error detector
==16082== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==16082== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==16082== Command: ./a.out
==16082== 
==16082== LEAK SUMMARY:
==16082==    definitely lost: 0 bytes in 0 blocks
==16082==    indirectly lost: 0 bytes in 0 blocks
==16082==      possibly lost: 0 bytes in 0 blocks
==16082==    still reachable: 1 bytes in 1 blocks
==16082==         suppressed: 0 bytes in 0 blocks
==16082== Reachable blocks (those to which a pointer was found) are not shown.
==16082== To see them, rerun with: --leak-check=full --show-reachable=yes
==16082== 
==16082== 1 bytes in 1 blocks are definitely lost in loss record 2 of 2
==16082==    at 0x4C2BF77: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16082==    by 0x4007EE: main (testme.cc:9)
==16082== 
==16082== LEAK SUMMARY:
==16082==    definitely lost: 1 bytes in 1 blocks
==16082==    indirectly lost: 0 bytes in 0 blocks
==16082==      possibly lost: 0 bytes in 0 blocks
==16082==    still reachable: 1 bytes in 1 blocks
==16082==         suppressed: 0 bytes in 0 blocks
==16082== Reachable blocks (those to which a pointer was found) are not shown.
==16082== To see them, rerun with: --leak-check=full --show-reachable=yes
==16082== 
==16082== 2 bytes in 2 blocks are definitely lost in loss record 2 of 2
==16082==    at 0x4C2BF77: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==16082==    by 0x4007EE: main (testme.cc:9)
==16082== 
==16082== LEAK SUMMARY:
==16082==    definitely lost: 2 bytes in 2 blocks
==16082==    indirectly lost: 0 bytes in 0 blocks
==16082==      possibly lost: 0 bytes in 0 blocks
==16082==    still reachable: 1 bytes in 1 blocks
==16082==         suppressed: 0 bytes in 0 blocks
==16082== Reachable blocks (those to which a pointer was found) are not shown.
==16082== To see them, rerun with: --leak-check=full --show-reachable=yes

程序不会终止.

这篇关于转储valgrind数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆