Valgrind的报告对空的C程序未初始化值 [英] Valgrind reports unitialized values on empty C program

查看:112
本文介绍了Valgrind的报告对空的C程序未初始化值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有任何海合会test.c以编译这个C程序铛test.c以

  INT主要(无效){
    返回0;
}

的valgrind ./a.out 给我这样的:

  == == 9232 MEMCHECK,内存错误检测
== == 9232版权所有(C)2002-2011,和GNU GPL的,Julian Seward写等。
== == 9232 Valgrind的使用,3.7.0和LibVEX;与-h版权信息重新运行
== == 9232命令:./a.out
== == 9232
== == 9232条件跳转或移动依赖于未初始化值(S)
== == 9232在0x4017876:指数(以/usr/lib/ld-2.16.so)
== == 9232通过0x4007902:expand_dynamic_string_token(以/usr/lib/ld-2.16.so)
== == 9232通过0x4008204:_dl_map_object(以/usr/lib/ld-2.16.so)
== == 9232通过0x400180D:map_doit(以/usr/lib/ld-2.16.so)
== == 9232通过0x400E785:_dl_catch_error(以/usr/lib/ld-2.16.so)
== == 9232通过0x40010DB:DO_ preLOAD(以/usr/lib/ld-2.16.so)
== == 9232通过0x4004546:dl_main(以/usr/lib/ld-2.16.so)
== == 9232通过0x4014B5D:_dl_sysdep_start(以/usr/lib/ld-2.16.so)
== == 9232通过0x4004DFD:_dl_start(以/usr/lib/ld-2.16.so)
== == 9232通过0x4001627:??? (在/usr/lib/ld-2.16.so)
== == 9232
== == 9232条件跳转或移动依赖于未初始化值(S)
== == 9232在0x401787B:指数(以/usr/lib/ld-2.16.so)
== == 9232通过0x4007902:expand_dynamic_string_token(以/usr/lib/ld-2.16.so)
== == 9232通过0x4008204:_dl_map_object(以/usr/lib/ld-2.16.so)
== == 9232通过0x400180D:map_doit(以/usr/lib/ld-2.16.so)
== == 9232通过0x400E785:_dl_catch_error(以/usr/lib/ld-2.16.so)
== == 9232通过0x40010DB:DO_ preLOAD(以/usr/lib/ld-2.16.so)
== == 9232通过0x4004546:dl_main(以/usr/lib/ld-2.16.so)
== == 9232通过0x4014B5D:_dl_sysdep_start(以/usr/lib/ld-2.16.so)
== == 9232通过0x4004DFD:_dl_start(以/usr/lib/ld-2.16.so)
== == 9232通过0x4001627:??? (在/usr/lib/ld-2.16.so)
== == 9232
== == 9232
== == 9232 HEAP摘要:
== == 9232使用在退出:0块0字节
== == 9232总堆的使用:0 allocs,0的FreeS,0字节分配
== == 9232
== == 9232的所有堆块被释放 - 无泄漏是可能的
== == 9232
== == 9232对于检测燮pressed错误计数,重新运行:-v
== == 9232使用--track-起源= yes来看到未初始化值来自
== == 9232错误摘要:从2上下文2个错误(SUP pressed:0 0)

GCC 4.7.1版本锵和3.1版。用什么这是吗?是不是有什么毛病我的记忆?还有,因为我最后一次使用的valgrind一段时间,但这个我觉得是不正常的行为。 Yelp的?


解决方案
这是可能从我从@Shawn学会燮preSS使用的valgrind .supp 文件中的这些链接器错误。我所做的就是使用在我的程序运行的valgrind - 根燮pressions =所有选项:

 的valgrind --gen燮pressions =所有./a.out

然后我提取括号中的新块,并把它们直接进入文件 my.supp

  {
   &所述连接体GT;
   MEMCHECK:电导率
   好玩的:指数
   好玩:expand_dynamic_string_token
   好玩:_dl_map_object
   好玩:map_doit
   好玩:_dl_catch_error
   乐趣:DO_ preLOAD
   好玩:dl_main
   好玩:_dl_sysdep_start
   好玩:_dl_start
   OBJ:/usr/lib/ld-2.16.so
}

现在我可以用 Valgrind的运行 - 燮pressions 选项指向我的新文件和消息将成为燮pressed:

 的valgrind --sup pressions = /家庭/富/ my.supp ./a.out


解决方案

这是一个知道 问题,提供的valgrind这是典型的使用的valgrind燮pressions 解决。假设问题已经被报告为你的发行版中,SUP pressions列表应该很快更新,并会在下次更新中消失。

现在,可以安全地忽略该消息。

如果你烦恼,你可以保持自己燮pressions文件并使用它,直到你发行版更新的默认文件(通常 /var/lib/valgrind/default.supp )。

I have this C program compiled with either gcc test.c or clang test.c:

int main (void) {
    return 0;
}

valgrind ./a.out gives me this:

==9232== Memcheck, a memory error detector
==9232== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==9232== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==9232== Command: ./a.out
==9232== 
==9232== Conditional jump or move depends on uninitialised value(s)
==9232==    at 0x4017876: index (in /usr/lib/ld-2.16.so)
==9232==    by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so)
==9232==    by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so)
==9232==    by 0x400180D: map_doit (in /usr/lib/ld-2.16.so)
==9232==    by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so)
==9232==    by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so)
==9232==    by 0x4004546: dl_main (in /usr/lib/ld-2.16.so)
==9232==    by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so)
==9232==    by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so)
==9232==    by 0x4001627: ??? (in /usr/lib/ld-2.16.so)
==9232== 
==9232== Conditional jump or move depends on uninitialised value(s)
==9232==    at 0x401787B: index (in /usr/lib/ld-2.16.so)
==9232==    by 0x4007902: expand_dynamic_string_token (in /usr/lib/ld-2.16.so)
==9232==    by 0x4008204: _dl_map_object (in /usr/lib/ld-2.16.so)
==9232==    by 0x400180D: map_doit (in /usr/lib/ld-2.16.so)
==9232==    by 0x400E785: _dl_catch_error (in /usr/lib/ld-2.16.so)
==9232==    by 0x40010DB: do_preload (in /usr/lib/ld-2.16.so)
==9232==    by 0x4004546: dl_main (in /usr/lib/ld-2.16.so)
==9232==    by 0x4014B5D: _dl_sysdep_start (in /usr/lib/ld-2.16.so)
==9232==    by 0x4004DFD: _dl_start (in /usr/lib/ld-2.16.so)
==9232==    by 0x4001627: ??? (in /usr/lib/ld-2.16.so)
==9232== 
==9232== 
==9232== HEAP SUMMARY:
==9232==     in use at exit: 0 bytes in 0 blocks
==9232==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==9232== 
==9232== All heap blocks were freed -- no leaks are possible
==9232== 
==9232== For counts of detected and suppressed errors, rerun with: -v
==9232== Use --track-origins=yes to see where uninitialised values come from
==9232== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

GCC version 4.7.1 and Clang version 3.1. What is up with this? Is there something wrong with my memory? There's some time since I last used valgrind but this I think is not normal behaviour. Yelp?


Solution: It is possible from what I learned from @Shawn to suppress these linker errors using a valgrind .supp file. What I did was running valgrind on my program using the --gen-suppressions=all option:

valgrind --gen-suppressions=all ./a.out 

Then I extract the new chunks enclosed in brackets and put them directly into a file my.supp:

{  
   <linker>
   Memcheck:Cond
   fun:index
   fun:expand_dynamic_string_token
   fun:_dl_map_object
   fun:map_doit
   fun:_dl_catch_error
   fun:do_preload
   fun:dl_main
   fun:_dl_sysdep_start
   fun:_dl_start
   obj:/usr/lib/ld-2.16.so
}  

Now I can run valgrind with the --suppressions option to point to my new file and the messages will be suppressed:

valgrind --suppressions=/home/foo/my.supp ./a.out

解决方案

This is a know issue with valgrind which is typically addressed using valgrind suppressions. Assuming the issue has been reported for your distro, the suppressions list should be updated shortly and will disappear in the next update.

For now, it is safe to ignore the message.

If it bothers you, you can maintain your own suppressions file and use it until your distro updates the default file (usually /var/lib/valgrind/default.supp).

这篇关于Valgrind的报告对空的C程序未初始化值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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