Hello.
I have a trouble using valgrind: it finds an illegal instructions in places
where I use some sorts of input streams in C++ (std::ifstream, YAML-C++
streams).
Here is a small example of that trouble. Could you please answer on how to
fix it?
Thank you in advance.
-------------------------------------------------------------------------------------------------
$ cat test.cpp
#include <fstream>
int main(int argc, char **argv) {
std::ifstream s(argv[1]);
double x = 0;
while (s >> x) {
x *= x;
}
return 0;
}
$ g++ -O0 -g test.cpp
$ cat test.txt
1 2 3 4 5
$ valgrind ./a.out test.txt
==17934== Memcheck, a memory error detector
==17934== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==17934== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==17934== Command: ./a.out test.txt
==17934==
vex amd64->IR: unhandled instruction bytes: 0xC5 0xFB 0x10 0x44 0x24 0xF8
0xC3 0x90
==17934== valgrind: Unrecognised instruction at address 0x560cf43.
==17934== at 0x560CF43: __mpn_construct_double (in /lib64/libc-2.14.1.so)
==17934== by 0x56056D3: ____strtod_l_internal (in /lib64/libc-2.14.1.so)
==17934== by 0x4EE7E48: void std::__convert_to_v<double>(char const*,
double&, std::_Ios_Iostate&, __locale_struct* const&) (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4EBBFB5: std::num_get<char,
std::istreambuf_iterator<char, std::char_traits<char> >
>::do_get(std::istreambuf_iterator<char, std::char_traits<char> >,
std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&,
std::_Ios_Iostate&, double&) const (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4EAADF7: std::istream&
std::istream::_M_extract<double>(double&) (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4008A5: main (test.cpp:6)
==17934== Your program just tried to execute an instruction that Valgrind
==17934== did not recognise. There are two possible reasons for this.
==17934== 1. Your program has a bug and erroneously jumped to a non-code
==17934== location. If you are running Memcheck and you just saw a
==17934== warning about a bad jump, it's probably your program's fault.
==17934== 2. The instruction is legitimate but Valgrind doesn't handle it,
==17934== i.e. it's Valgrind's fault. If you think this is the case or
==17934== you are not sure, please let us know and we'll try to fix it.
==17934== Either way, Valgrind will now raise a SIGILL signal which will
==17934== probably kill your program.
==17934==
==17934== Process terminating with default action of signal 4 (SIGILL)
==17934== Illegal opcode at address 0x560CF43
==17934== at 0x560CF43: __mpn_construct_double (in /lib64/libc-2.14.1.so)
==17934== by 0x56056D3: ____strtod_l_internal (in /lib64/libc-2.14.1.so)
==17934== by 0x4EE7E48: void std::__convert_to_v<double>(char const*,
double&, std::_Ios_Iostate&, __locale_struct* const&) (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4EBBFB5: std::num_get<char,
std::istreambuf_iterator<char, std::char_traits<char> >
>::do_get(std::istreambuf_iterator<char, std::char_traits<char> >,
std::istreambuf_iterator<char, std::char_traits<char> >, std::ios_base&,
std::_Ios_Iostate&, double&) const (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4EAADF7: std::istream&
std::istream::_M_extract<double>(double&) (in
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6.0.14)
==17934== by 0x4008A5: main (test.cpp:6)
==17934==
==17934== HEAP SUMMARY:
==17934== in use at exit: 8,817 bytes in 3 blocks
==17934== total heap usage: 3 allocs, 0 frees, 8,817 bytes allocated
==17934==
==17934== LEAK SUMMARY:
==17934== definitely lost: 0 bytes in 0 blocks
==17934== indirectly lost: 0 bytes in 0 blocks
==17934== possibly lost: 57 bytes in 1 blocks
==17934== still reachable: 8,760 bytes in 2 blocks
==17934== suppressed: 0 bytes in 0 blocks
==17934== Rerun with --leak-check=full to see details of leaked memory
==17934==
==17934== For counts of detected and suppressed errors, rerun with: -v
==17934== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
Illegal instruction
-------------------------------------------------------------------------------------------------
System information:
$ valgrind --version
valgrind-3.7.0
$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-4.5.3-r2/work/gcc-4.5.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check
--with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls
--without-included-gettext --with-system-zlib --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
--enable-checking=release --enable-languages=c,c++,java,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-targets=all --with-bugurl=
http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r2 p1.1, pie-0.4.7'
Thread model: posix
gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.1, pie-0.4.7)
--
Best regards,
Valeriy Sokolov.
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users