背景

公司C++项目代码使用了cppcheck做静态代码检查,也使用valgrind检查是否有内存泄漏问题。我多次强调要做到0警告,虽然有了CICD的Jenkins自动检查,也将结果通过邮件发给项目人员,但有的人还是没去修正警告,由于不是自己管辖范围,不好多说什么。
最近使用valgrind测试,遇到了未识别指令的问题(运行的程序被认为是非法指令)。经查发现是valgrind版本太低造成的。

问题出现

运行命令如下:

valgrind  --leak-check=full --show-leak-kinds=all  ./a.out

错误提示如下:

vex amd64->IR: unhandled instruction bytes: 0xF 0xC7 0xF0 0x89 0x6 0xF 0x42 0xC1
vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=0F
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==3562== valgrind: Unrecognised instruction at address 0x4ef1b15.
==3562==    at 0x4EF1B15: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==3562==    by 0x4EF1CB1: std::random_device::_M_getval() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==3562==    by 0x400D8B: std::random_device::operator()() (in /home/latelee/test/mytest/warningtest/a.out)
==3562==    by 0x400FA1: Init() (in /home/latelee/test/mytest/warningtest/a.out)
==3562==    by 0x400DD7: GetRandomC11() (in /home/latelee/test/mytest/warningtest/a.out)
==3562==    by 0x400B55: GetRandomNum() (in /home/latelee/test/mytest/warningtest/a.out)
==3562==    by 0x400D0A: main (in /home/latelee/test/mytest/warningtest/a.out)

==26759== Process terminating with default action of signal 4 (SIGILL)
==26759==  Illegal opcode at address 0x4EF1B15
==26759==    at 0x4EF1B15: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==26759==    by 0x4EF1CB1: std::random_device::_M_getval() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==26759==    by 0x400D8B: std::random_device::operator()() (in /home/latelee/test/mytest/warningtest/a.out)
==26759==    by 0x400FA1: Init() (in /home/latelee/test/mytest/warningtest/a.out)
==26759==    by 0x400DD7: GetRandomC11() (in /home/latelee/test/mytest/warningtest/a.out)
==26759==    by 0x400B55: GetRandomNum() (in /home/latelee/test/mytest/warningtest/a.out)
==26759==    by 0x400D0A: main (in /home/latelee/test/mytest/warningtest/a.out)

同时,valgrind也进行了提醒:

==2636== Your program just tried to execute an instruction that Valgrind
==2636== did not recognise.  There are two possible reasons for this.
==2636== 1. Your program has a bug and erroneously jumped to a non-code
==2636==    location.  If you are running Memcheck and you just saw a
==2636==    warning about a bad jump, it's probably your program's fault.
==2636== 2. The instruction is legitimate but Valgrind doesn't handle it,
==2636==    i.e. it's Valgrind's fault.  If you think this is the case or
==2636==    you are not sure, please let us know and we'll try to fix it.
==2636== Either way, Valgrind will now raise a SIGILL signal which will
==2636== probably kill your program.

大概意思是说,要么是程序代码真的有bug,要么是valgrind本身有bug(顺便反馈给作者)。反复阅读代码,统计new和delete出现次数,都没问题。
后来在https://stackoverflow.com/questions/37032339/valgrind-unrecognised-instruction上看到有介绍,大概意思是不支持_M_getval(),帖子中还附带了补丁,也建议使用新版本。本文使用新版本valgrind进行测试。

新版本编译、测试

先查看当前版本,如下:

$ valgrind --version
valgrind-3.11.0

在官网上查看到最新版本是3.13,下载地址

tar jxf valgrind-3.13.0.tar.bz2 ./configure --prefix=/home/latelee/bin/valgrind
make -j
make install

使用新版本进行测试,命令如下:

$/home/latelee/bin/valgrind/bin/valgrind --leak-check=full --show-leak-kinds=all  ./a.out

这次的结果如下:

==30979== Memcheck, a memory error detector
==30979== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==30979== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==30979== Command: ./a.out
==30979==
==30979== Conditional jump or move depends on uninitialised value(s)
==30979==    at 0x400E36: Uninit() (in /home/latelee/test/mytest/warningtest/a.out)
==30979==    by 0x400B65: GetRandomNum() (in /home/latelee/test/mytest/warningtest/a.out)
==30979==    by 0x400D0A: main (in /home/latelee/test/mytest/warningtest/a.out)
==30979==
-316985884
==30979==
==30979== HEAP SUMMARY:
==30979==     in use at exit: 72,704 bytes in 1 blocks
==30979==   total heap usage: 7 allocs, 6 frees, 84,856 bytes allocated
==30979==
==30979== LEAK SUMMARY:
==30979==    definitely lost: 0 bytes in 0 blocks
==30979==    indirectly lost: 0 bytes in 0 blocks
==30979==      possibly lost: 0 bytes in 0 blocks
==30979==    still reachable: 72,704 bytes in 1 blocks
==30979==         suppressed: 0 bytes in 0 blocks
==30979== Rerun with --leak-check=full to see details of leaked memory
==30979==
==30979== For counts of detected and suppressed errors, rerun with: -v
==30979== Use --track-origins=yes to see where uninitialised values come from
==30979== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

可以看到,虽然有error,但已经没有valgrind: Unrecognised instruction at address的错误信息了。

小结

建议使用源码编译安装valgrind,减少其自身bug带来的误判。

李迟 2018.8.30 周四 夜

遇到一个valgrind自身的bug相关推荐

  1. linux mysql 不稳定_linux,mysql:今天写出一个十分弱智的bug!

    今天写出一个十分弱智的bug,记录一下,提醒自己以后别这种犯错,不怕丢人哈~ 在写一个分页查询记录的sql时,要根据添加的时间逆序分页输出,之前的写法是酱紫: select record.a, y.c ...

  2. Delphi XE 10.4 FMX ListView 一个不易察觉的 BUG

    Delphi XE 10.4 FMX ListView 一个不易察觉的 BUG 在使用 ListView DynamicAppearance 时发现非常强大,可以加很多东西,但没有发现复选框(哪位大佬 ...

  3. 最近提交一个mysql5.7的bug,提醒自己以后注意写SQL要规范

    最近帮朋友提交一个mysql5.7的bug , oracle mysql 的大神还回复我 , 以后注意书写sql规范 , 潜台词是不是不要给他们增加工作量 https://bugs.mysql.com ...

  4. 编写代码、打印图4-2所示的图形python_Python之turtle库画各种有趣的图及源码(更新中)_一个超会写Bug的程序猿的博客-CSDN博客...

    原文作者:一个超会写Bug的安太狼 原文标题:Python之turtle库画各种有趣的图及源码(更新中) 发布时间:2021-02-09 03:35:11 Turtle库是Python语言中一个很流行 ...

  5. 在AutoCAD 2008发现了一个动态块的BUG

    前不久发现了一个AutoCAD 2008的BUG. 具体症状是这样的: 图形中存在动态块时,只要使用lisp函数: (entget (car (entsel "\nSelect Object ...

  6. 如何提交一个高质量的bug?

    在日常的软件测试工作中,测试人员发现bug之后,接下来就需要提交bug.关于如何提交一个高质量的bug,是一个很值得思考的问题,因为这关系到开发能不能接受bug,也决定了后续的工作流程是否能顺利进行. ...

  7. 今天写出一个十分弱智的 bug!

    来源:cnblogs.com/supercj/p/10333918.html 今天写出一个十分弱智的bug,记录一下,提醒自己以后别这种犯错,不怕丢人哈~ 在写一个分页查询记录的sql时,要根据添加的 ...

  8. Java中一个令人惊讶的bug

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 今天分享一个JDK中令人惊讶的BUG,这个BUG的神奇之处在于,复 ...

  9. 一个JDK线程池BUG引发的GC机制思考

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 作者:空无 来源:https://urlify.cn/63QrYv ...

最新文章

  1. Simulink仿真 第四节 总线及示波器模块
  2. Java 集合框架 : Collection、Map
  3. [WPF疑难] 继承自定义窗口
  4. 【JavaScript吉光片羽】--- 滑动条
  5. c++ ea 代码 生成_看EA如何生成代码框架
  6. Intel Sandy Bridge/Ivy Bridge架构/微架构/流水线 (16) - L1数据缓存/存储转发访存消歧存储体冲突
  7. Windows 7 任务栏开发 之 进度条(Progress Bar)
  8. window.event对象详尽解析
  9. 老李推荐:第6章2节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-获取命令字串...
  10. 计算机导入文件格式,电脑如何打开zip格式文件|电脑打开zip格式文件的方法
  11. apms阅卷系统服务器,APMS全通纸笔王网上阅卷系统网上操作指南.doc
  12. web聊天界面html,PC端Web聊天界面+代码分享(HTML+CSS)
  13. python离线安装whl文件.
  14. 树莓派-11-3又1/2位数字万用表使用说明书
  15. /usr/include/gnu/stubs.h:7:27: 致命错误:gnu/stubs-32.h:没有那个文件或目录
  16. 一元云购CMS微信分享打不开解决办法
  17. 何钦铭c语言第三版第3章答案,何钦铭版C语言第3章答案精选.pdf
  18. 2022 年十大最佳网络分析工具介绍
  19. C语言:ASCII字符文件与二进制字符文件的相互转换
  20. js生成token 七牛云_自己尝试生成七牛云的accessToken,但一直返回{error:bad token}...

热门文章

  1. Ajax 技术资源中心
  2. 苹果Mac Studio 3月18日发售 但法国一用户已提前收货
  3. 1天暴涨1300亿!中国移动最不争气的儿子,被王濛救活了?
  4. 疑似小米12 mini渲染图曝光:屏幕不到6英寸 真小屏旗舰
  5. 为什么川渝的超市要求顾客必须“要有妈”?
  6. 教育部成立校外教育培训监管司 K12迎最强监管 教育中概股再跳水
  7. 终于要来了!华为P50将提供两个版本:国内仅有鸿蒙
  8. 诺基亚9.3再曝光:后置1亿像素圆形五摄 价格或超6000元
  9. 618期间, “直播带货”翻车负面信息暴增
  10. iPhone 11系列低至4599元,40亿消费券开抢!618正式开启了