Valgrind显示出8号错误的未初始化值.偶尔,下面的条件跳转未初始化的值错误.
我正在做的就是使用gcc附带的stdc ++库和内置的vsnprintf打印格式化的字符串.
这是一个名为format的方法,它是自定义字符串类的一部分.现在怎么办?一切看起来都正确 错误似乎在_itoa.c中.但是我所能想到的就是在外面做的不是使用这个功能,这是不太可能的!
==4229== Memcheck, a memory error detector
==4229== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==4229== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==4229== Command: ./test
==4229==
==4229== Use of uninitialised value of size 8
==4229== at 0x54A3DF1: _itoa_word (_itoa.c:196)
==4229== by 0x54A5138: vfprintf (vfprintf.c:1613)
==4229== by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65)
==4229== by 0x407E57: myString::format(char const*, ...) (stdio2.h:79)
==4229== by 0x419D14: ID::toString() (id.cpp:151)
==4229== by 0x41D03D: main (test.cpp:126)
==4229==
==4229== …
Run Code Online (Sandbox Code Playgroud) 由于在我的iOS程序中看到随机内存崩溃,我决定使用Valgrind帮助解决问题,因为他们有一个在32位mac OS X上运行的端口.我按照此网页中的说明进行设置Valgrind在iPhone模拟器上:
http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html
但是,虽然我可以让程序在iOS模拟器中编译,并且预处理程序标志设置,但我无法让Valgrind实际运行我的程序.它总是退出并出现以下错误:
valgrind: /Users/megahub/Library/Application Support/iPhone Simulator/4.2/Applications/6FD1FFF3-0EFB-4D81-A95A-F02E0AA9095E/QuamStockAdHoc.app/QuamStockAdHoc: cannot execute binary file
cannot execute binary file
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我已经验证了可执行文件存在于该路径中,因为我可以在模拟器中运行它而不使用Valgrind.
valgrind找不到任何有用的东西.我糊涂了.
Symptomes:
PS:代码不会出现段错误
目前我通过mmap()
+ 替换所有malloc()取得了一些进展mprotect()
为什么valgrind的DRD工具抱怨"线程加载冲突...大小为4":关于这样的代码:
void SomeFunction(const int& value)
{
boost::bind(..., value); /* <-- complaines on this line
with last backtrace function "new(int)" */
}
Run Code Online (Sandbox Code Playgroud)
boost :: bind()是否按引用或值存储值?
我在让一个简单的类构造函数工作时遇到麻烦。
// In XModule.h
class XModule
{
...
public:
TXMHeader header; // module header
TXMInstrument* instr; // all instruments (256 of them)
TXMSample* smp; // all samples (256 of them, only 255 can be used)
TXMPattern* phead; // all pattern headers (256 of them)
}
Run Code Online (Sandbox Code Playgroud)
Module.cpp
// In XModule.cpp
....
XModule::XModule()
{
// allocated necessary space for all possible patterns, instruments and samples
phead = new TXMPattern[256]; // Line # 1882
instr = new TXMInstrument[256];
smp = new TXMSample[MP_MAXSAMPLES];
memset(&header,0,sizeof(TXMHeader)); …
Run Code Online (Sandbox Code Playgroud) 我使用strtod()来转换一些输入字符串.在用valgrind检查我的代码时,我遇到了"无效读取大小为8".如果b以"i"或"n"开头,则显示消息,这就是我到目前为止所发现的.另外,如果我直接创建一个const char*(不调用c_str()),strtod似乎没问题.继承人代码:
#include <cstdlib>
#include <string>
int main(int argc, char** argv) {
char* a = 0;
std::string b = "i";
const char* c = b.c_str();
double d = strtod(c, &a);
}
Run Code Online (Sandbox Code Playgroud)
和(详细)valgrind输出:
==12638== Memcheck, a memory error detector
==12638== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==12638== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==12638== Command: ./leak
==12638==
--12638-- Valgrind options:
--12638-- --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
--12638-- --show-reachable=yes
--12638-- --leak-check=full
--12638-- -v
--12638-- Contents of /proc/version: …
Run Code Online (Sandbox Code Playgroud) 我用valgrind得到了最后的"完成"消息,并获得此退出报告:
==3434== HEAP SUMMARY:
==3434== in use at exit: 8,432 bytes in 4 blocks
==3434== total heap usage: 4,369 allocs, 8,037 frees, 377,356 bytes allocated
==3434==
==3434== LEAK SUMMARY:
==3434== definitely lost: 152 bytes in 1 blocks
==3434== indirectly lost: 0 bytes in 0 blocks
==3434== possibly lost: 0 bytes in 0 blocks
==3434== still reachable: 8,192 bytes in 2 blocks
==3434== suppressed: 88 bytes in 1 blocks
==3434== Rerun with --leak-check=full to see details of leaked memory
==3434==
==3434== …
Run Code Online (Sandbox Code Playgroud) 我试图在64位机器(linux)上运行valgrind 32位二进制文件,我收到此错误:
valgrind:未能为平台'x86-linux'启动工具'memcheck':没有这样的文件或目录
我需要做些什么来使它工作?
目标:我希望能够分析callgrind(以及后来的cachegrind)的输出,并希望在使用callgrind_annotate CLI时看到有意义的变量名称.
之前的研究:我知道Valgrind中的dsym标志(http://valgrind.org/docs/manual/manual-core.html)并且相信我已经了解调试符号如何在osx上工作(LLDB没有显示源代码).我在这个网站上看到的这个问题的少数提及要么没有得到答复,要么就是没有包含-g标志的情况.
理论(可能是错误的......):基于valgrind输出中的"dym ="行,我想知道valgrind是否正在努力寻找dsym目录的路径."
我可以给你什么数据?
给出以下源代码:
#include <iostream>
#include <cmath>
bool isPrime(int x)
{
int limit = std::sqrt(x);
for (int i = 2; i <= limit; ++i)
{
if (x % i == 0)
{
return false;
}
}
return true;
}
int main()
{
int primeCount = 0;
for (int i = 0; i < 1000000; ++i)
{
if (isPrime(i))
{
++primeCount;
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用了以下命令行指令:
g++ -g -c badprime.cpp
g++ …
Run Code Online (Sandbox Code Playgroud) [这是冗长而充满细节的.我的具体问题由下面的粗体字问题引入.]
摘要
我们在valgrind下运行一些测试套件,遇到一个对我来说没什么意义的错误.我正在寻找有关更详细地弄清楚可能出错的建议.
所有这些都闻起来好像真正的问题在其他地方:某些东西正在变得腐败并导致后来的混乱.但这是valgrind报告的第一个问题,所以如果在其他地方有内存踩踏,那么valgrind就无法抓住它.我怀疑要么我错过了一些明显的东西,要么有一个微妙的问题,那些具有比我更有专业知识的人可能能够指出我.
一些细节
以下是一些细节和一些具体问题.
这是在x64硬件上运行Ubuntu 14.04的Linux机器上.
这是valgrind在一个相当典型的例子中的抱怨:
==14259== Invalid write of size 8
==14259== at 0x662BBC9: __printf_fp (printf_fp.c:663)
==14259== by 0x6629792: vfprintf (vfprintf.c:1660)
==14259== by 0x664D578: vsnprintf (vsnprintf.c:119)
==14259== by 0x52DCE0F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==14259== by 0x52E3263: 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/x86_64-linux-gnu/libstdc++.so.6.0.19)
==14259== by 0x52E354F: 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 …
Run Code Online (Sandbox Code Playgroud)