精确定位“条件跳转或移动取决于未初始化的值” valgrind消息 [英] pinpointing "conditional jump or move depends on uninitialized value(s)" valgrind message

查看:552
本文介绍了精确定位“条件跳转或移动取决于未初始化的值” valgrind消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从valgrind得到一些神秘的未初始化的值消息,这是一个很糟糕的价值起源于的地方。

So I've been getting some mysterious uninitialized values message from valgrind and it's been quite the mystery as of where the bad value originated from.

似乎valgrind显示

Seems that valgrind shows the place where the unitialised value ends up being used, but not the origin of the uninitialised value.

==11366== Conditional jump or move depends on uninitialised value(s)
==11366==    at 0x43CAE4F: __printf_fp (in /lib/tls/i686/cmov/libc-2.7.so)
==11366==    by 0x43C6563: vfprintf (in /lib/tls/i686/cmov/libc-2.7.so)
==11366==    by 0x43EAC03: vsnprintf (in /lib/tls/i686/cmov/libc-2.7.so)
==11366==    by 0x42D475B: (within /usr/lib/libstdc++.so.6.0.9)
==11366==    by 0x42E2C9B: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const (in /usr/lib/libstdc++.so.6.0.9)
==11366==    by 0x42E31B4: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const (in /usr/lib/libstdc++.so.6.0.9)
==11366==    by 0x42EE56F: std::ostream& std::ostream::_M_insert<double>(double) (in /usr/lib/libstdc++.so.6.0.9)
==11366==    by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221)
==11366==    by 0x810B9F1: Snake::Snake::update() (snake.cpp:257)
==11366==    by 0x81113C1: SnakeApp::updateState() (snakeapp.cpp:224)
==11366==    by 0x8120351: RoenGL::updateState() (roengl.cpp:1180)
==11366==    by 0x81E87D9: Roensachs::update() (rs.cpp:321)

可以看出,它变得相当神秘。它是通过Class :: MethodX,它有时指向直流ostream等也许这是由于优化?

As can be seen, it gets quite cryptic.. especially because when it's saying by Class::MethodX, it sometimes points straight to ostream etc. Perhaps this is due to optimization?

==11366==    by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221)

那。有什么我错过了吗?

Just like that. Is there something I'm missing? What is the best way to catch bad values without having to resort to super-long printf detective work?

更新: strong>

Update:

我发现有什么错误,但奇怪的是,valgrind没有报告错误的值首次使用时。它用于乘法函数:

I found out what was wrong, but the strange thing is, valgrind did not report it when the bad value was first used. It was used in a multiplication function:

movespeed = stat.speedfactor * speedfac * currentbendfactor.val;

其中speedfac是一个单位浮点数。但是,当时没有报告,直到值打印,我得到错误..有valgrind设置更改此行为吗?

Where speedfac was an unitialised float. However, at that time it was not reported and not until the value is to be printed that I get the error.. Is there a setting for valgrind to change this behavior?

推荐答案

使用valgrind选项 - track-origins = yes 让它跟踪未初始化值的来源。这将使它更慢,需要更多的内存,但如果你需要跟踪一个未初始化的值的来源,可能非常有用。

Use the valgrind option --track-origins=yes to have it track the origin of uninitialized values. This will make it slower and take more memory, but can be very helpful if you need to track down the origin of an uninitialized value.

更新:关于报告未初始化值的点, valgrind手册指出

Update: Regarding the point at which the uninitialized value is reported, the valgrind manual states:


重要的是要了解你的程序可以按照喜欢的方式复制垃圾(未初始化)数据。 Memcheck观察这一点并跟踪数据,但不抱怨。只有当您的计划尝试以可能影响程序外部可见行为的方式使用未初始化数据时,才会发出投诉。

It is important to understand that your program can copy around junk (uninitialised) data as much as it likes. Memcheck observes this and keeps track of the data, but does not complain. A complaint is issued only when your program attempts to make use of uninitialised data in a way that might affect your program's externally-visible behaviour.

Valgrind常见问题


对于未初始化内存值的副本的渴望报告,这已被建议多次。不幸的是,几乎所有的程序合法地复制未初始化的内存值(因为编译器pad结构以保持对齐),并且急切的检查导致数百个假阳性。因此,Memcheck目前不支持热切检查。

As for eager reporting of copies of uninitialised memory values, this has been suggested multiple times. Unfortunately, almost all programs legitimately copy uninitialised memory values around (because compilers pad structs to preserve alignment) and eager checking leads to hundreds of false positives. Therefore Memcheck does not support eager checking at this time.

这篇关于精确定位“条件跳转或移动取决于未初始化的值” valgrind消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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