标签: valgrind

Valgrind在c库中的错误?

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)

gcc valgrind

6
推荐指数
1
解决办法
2372
查看次数

在Mac OS X Snow Leopard上的iPhone模拟器上使用Valgrind

由于在我的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.

iphone valgrind ios-simulator

6
推荐指数
1
解决办法
2810
查看次数

如何找到缓冲区溢出和内存损坏的地方?

valgrind找不到任何有用的东西.我糊涂了.

Symptomes:

  1. 我的数据被malloc()调用破坏了
  2. 我的函数的返回地址被错误的替换

PS:代码不会出现段错误

目前我通过mmap()+ 替换所有malloc()取得了一些进展mprotect()

c valgrind buffer-overflow memory-corruption

6
推荐指数
2
解决办法
1万
查看次数

boost :: bind()是通过引用还是按值复制参数?

为什么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()是否按引用或值存储值?

c++ valgrind boost-bind

6
推荐指数
1
解决办法
5501
查看次数

在类构造函数的第一行中无效写入8号

我在让一个简单的类构造函数工作时遇到麻烦。

// 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)

c++ valgrind

6
推荐指数
1
解决办法
1345
查看次数

Valgrind:c_str和strtod的"无效读取"

我使用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)

c++ string valgrind g++ strtod

6
推荐指数
1
解决办法
1816
查看次数

Segfaulting只有没有valgrind

我用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)

c valgrind segmentation-fault

6
推荐指数
1
解决办法
3124
查看次数

在64位机器上运行valgrind 32位二进制文​​件

我试图在64位机器(linux)上运行valgrind 32位二进制文​​件,我收到此错误:

valgrind:未能为平台'x86-linux'启动工具'memcheck':没有这样的文件或目录

我需要做些什么来使它工作?

linux valgrind

6
推荐指数
1
解决办法
3744
查看次数

如何从命令行在OSX上的callgrind输出中获取有意义的函数名称?

目标:我希望能够分析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)

c++ macos valgrind callgrind clang++

6
推荐指数
1
解决办法
795
查看次数

诊断神秘的valgrind"无效写"

[这是冗长而充满细节的.我的具体问题由下面的粗体字问题引入.]

摘要

我们在valgrind下运行一些测试套件,遇到一个对我来说没什么意义的错误.我正在寻找有关更详细地弄清楚可能出错的建议.

  • Valgrind抱怨"写8号无效".
  • 从运行到运行,错误是一致的,但是应该是不相关的代码更改,不同的编译器/ stdlib版本等.
  • 写入的地址位于堆栈中,据我所知,这是我们编写代码的完全合理的地址.
  • 它的对齐与写入的大小一致.
  • 它发生的地方深入标准库内部.

所有这些都闻起来好像真正的问题在其他地方:某些东西正在变得腐败并导致后来的混乱.但这是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)

c++ stack-overflow valgrind memory-corruption eglibc

6
推荐指数
1
解决办法
263
查看次数