Valgrind的不显示行号码 [英] Valgrind does not show line-numbers

查看:1160
本文介绍了Valgrind的不显示行号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出我做无效写入使用Valgrind的一块内存。它告诉有这样的问题,也是在什么功能,但不是在哪一行。虽然功能是相当小的,我想在Valgrind的显示的行数。我已经看到了这个在Valgrind的一些产出,但目前他们没有显示,我不知道为什么。

的输出是下面的:

 尼克拉斯·@翡翠:〜/Arbeitsfläche/ spyr /斌/调试$的valgrind --tool = MEMCHECK --leak检查=全--show-可达= YES ./spyr
[...]
== == 4404大小为4的写入无效
== == 4404在0x8048849:sp_ParticleBuffer_init(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048BFC:sp_ParticleSystem_createParticle(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048691:主(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404地址0x422a0a0是大小为4 alloc'd块后4个字节
== == 4404在0x402BE68:的malloc(以/usr/lib/valgrind/vg$p$pload_memcheck-x86-linux.so)
== == 4404通过0x8048BC1:sp_ParticleSystem_createParticle(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048691:主(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404
== == 4404大小为4的写入无效
== == 4404在0x8048865:sp_ParticleBuffer_init(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048BFC:sp_ParticleSystem_createParticle(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048691:主(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404地址0x422a09c是大小为4 alloc'd块后0字节
== == 4404在0x402BE68:的malloc(以/usr/lib/valgrind/vg$p$pload_memcheck-x86-linux.so)
== == 4404通过0x8048BC1:sp_ParticleSystem_createParticle(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
== == 4404通过0x8048691:主(在/ home /尼古拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr)
[...]

我看到那里的文件名后面的双冒号后显示的行数输出。即 /主页/尼克拉斯/Arbeitsfläche/ spyr /斌/调试/ spyr:23 或类似

如何启用这个?

仅供参考,这是 sp_ParticleBuffer_init 功能。

  INT sp_ParticleBuffer_init(sp_ParticleBuffer *缓冲区,sp_Uint32 BUFFER_SIZE,诠释init_zero){
    为size_t大小= sizeof的(sp_Particle)* BUFFER_SIZE;
    buffer->接着=无效;
    buffer->数组=(sp_Particle *)malloc的(大小);
    buffer-> alive_count = 0;    如果(buffer->!数组)返回SPYR_ALLOCFAILED;
    如果(init_zero)memset的((无效*)buffer->阵,0,大小);
    返回SPYR_NOERR;
}


解决方案

您需要在您的二进制文件调试信息。如果你使用 GCC 传递 -g 标记。

I'm trying to find out where I made invalid writes to a piece of memory using Valgrind. It tells there is such an issue, also in what function, but not in what line. Although the function is quite small, I'd like to have the line-number shown in Valgrind. I've seen this on some outputs of Valgrind, but currently they are not shown, and I wonder why.

The output is the following:

niklas@emerald:~/Arbeitsfläche/spyr/bin/Debug$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./spyr
[...]
==4404== Invalid write of size 4
==4404==    at 0x8048849: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==  Address 0x422a0a0 is 4 bytes after a block of size 4 alloc'd
==4404==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==4404==    by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404== 
==4404== Invalid write of size 4
==4404==    at 0x8048865: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==  Address 0x422a09c is 0 bytes after a block of size 4 alloc'd
==4404==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==4404==    by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
==4404==    by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
[...]

I saw outputs where the line number is shown after a double-colon behind the file-name. I.e. /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr:23 or similar.

How can I enable this?

FYI, this is the sp_ParticleBuffer_init function.

int sp_ParticleBuffer_init(sp_ParticleBuffer* buffer, sp_Uint32 buffer_size, int init_zero) {
    size_t size   = sizeof(sp_Particle) * buffer_size;
    buffer->next  = null;
    buffer->array = (sp_Particle*) malloc(size);
    buffer->alive_count = 0;

    if (!buffer->array) return SPYR_ALLOCFAILED;
    if (init_zero) memset((void*) buffer->array, 0, size);
    return SPYR_NOERR;
}

解决方案

You need to include debug information in your binaries. Pass the -g flag if you're using gcc.

这篇关于Valgrind的不显示行号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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