问题
We are trying to track down a Conditional jump or move depends on uninitialised value in a C++ project reported by Valgrind. The address provided in the finding is not really helpful because it points to the end of a GCC extended assembly block, and not the actual variable causing the trouble.
According to the Valgrind's Eliminating undefined values with Valgrind, the easy way, we can use VALGRIND_CHECK_MEM_IS_DEFINED
or VALGRIND_CHECK_VALUE_IS_DEFINED
after including <memcheck.h>
. Additionally, those macros or functions are apparently documented in the header file (there is definitely no man page for them).
However, when I include <memcheck.h>
or <valgrind/memcheck.h>
, it results in:
fatal error: memcheck.h: No such file or directory
Based on Stack Overflow's How do I find which rpm package supplies a file I'm looking for?, I performed a RPM file search, but its returning 0 hits for memcheck.h
.
QUESTIONS
The blog article is a bit dated. Does the information still apply?
If the information is accurate, then where do I find
memcheck.h
?
$ uname -a
Linux localhost.localdomain 4.1.4-200.fc22.x86_64 #1 SMP Tue Aug 4 03:22:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ g++ --version
g++ (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4)
...
$ valgrind --version
valgrind-3.10.1
回答1:
You have to install the RPM valgrind-devel
which contains memcheck.h
.
The *-devel
packages are typically located in the "optional" repositories (e.g. rhel-x86_64-server-optional-6
on RHEL 6). Also, you can find the RPM on Google, download it, and install it on its own. With either approach, memcheck.h
is typically placed in /usr/include/valgrind
once installed.
回答2:
Another way to dig into uninitialised value error with valgrind is to use the embedded gdbserver.
You can then put breakpoints in your program, and interactively check the definedness of various addresses/length using various memcheck monitor commands such as:
check_memory [addressable|defined] <addr> [<len>]
check that <len> (or 1) bytes at <addr> have the given accessibility
and outputs a description of <addr>
See e.g. http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.monitor-commands for more information
来源:https://stackoverflow.com/questions/32048354/valgrind-fatal-error-memcheck-h-no-such-file-or-directory