解决被Valgrind检测到的内存问题

3

我有一个问题,涉及到valgrind;当我用valgrind检查我用C语言开发的程序时,它无法显示函数名称(只显示“???”),即使在检测到错误时也是如此,但并非所有错误都会出现这种情况。

==9803== ERROR SUMMARY: 24 errors from 6 contexts (suppressed: 0 from 0)
==9803== 
==9803== 1 errors in context 1 of 6:
==9803== Conditional jump or move depends on uninitialised value(s)
==9803==    at 0x40F7EC6: ???
==9803== 
==9803== 1 errors in context 2 of 6:
==9803== Conditional jump or move depends on uninitialised value(s)
==9803==    at 0x40F86F8: ???
==9803== 
==9803== 1 errors in context 3 of 6:
==9803== Conditional jump or move depends on uninitialised value(s)
==9803==    at 0x40F8166: ???
==9803== 
==9803== 1 errors in context 4 of 6:
==9803== Conditional jump or move depends on uninitialised value(s)
==9803==    at 0x40F805E: ???
==9803==

你是否有一种解决方案能够在valgrind中展示函数名称?
提前致谢。

这段代码会对你有所帮助。 - Ed Heal
3
你是否使用 -ggdb3 编译选项进行编译?它会将代码编译为带有调试信息的版本。 - Eregrith
我使用“-g3 -O0”标志编译了我的程序。 - developer
1
你正在使用共享对象吗?请参阅Valgrind FAQ - ks1322
使用-ggdb3标志具有相同的行为 - developer
显示剩余4条评论
1个回答

1

可能这些错误发生在您没有调试符号的库中。 很容易确认:只需在应用程序运行时查看/proc/pidof my-binary/maps。

08048000-08052000 r-xp 00000000 fe:00 42546         /bin/cat
08052000-08053000 rw-p 0000a000 fe:00 42546         /bin/cat
097fb000-0981c000 rw-p 00000000 00:00 0             [heap]
f73bc000-f75ac000 r--p 00000000 fe:02 281727        /usr/lib/locale/locale-archive
f75ac000-f75ad000 rw-p 00000000 00:00 0 
f75ad000-f76ed000 r-xp 00000000 fe:00 18416         /lib/i686/cmov/libc-2.11.2.so
f76ed000-f76ef000 r--p 0013f000 fe:00 18416         /lib/i686/cmov/libc-2.11.2.so
f76ef000-f76f0000 rw-p 00141000 fe:00 18416         /lib/i686/cmov/libc-2.11.2.so
f76f0000-f76f3000 rw-p 00000000 00:00 0 
f7705000-f7707000 rw-p 00000000 00:00 0 
f7707000-f7708000 r-xp 00000000 00:00 0             [vdso]
f7708000-f7723000 r-xp 00000000 fe:00 19087         /lib/ld-2.11.2.so
f7723000-f7724000 r--p 0001a000 fe:00 19087         /lib/ld-2.11.2.so
f7724000-f7725000 rw-p 0001b000 fe:00 19087         /lib/ld-2.11.2.so
ffb6e000-ffb83000 rw-p 00000000 00:00 0             

这清楚地显示了每个共享库代码段的地址(标记为r-xp)。只需找到与您看到的地址匹配的范围,您至少就会知道哪个库是负责的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接