C Valgrind不显示行号

C Valgrind不显示行号,c,linux,ubuntu,valgrind,C,Linux,Ubuntu,Valgrind,我试图找出我在哪里使用Valgrind对一段内存进行了无效写入。它告诉我们有这样一个问题,也在什么功能中,但不是在什么行中。虽然函数很小,但我希望在Valgrind中显示行号。我在Valgrind的一些输出中看到了这一点,但目前它们没有显示,我想知道为什么 输出如下: niklas@emerald:~/Arbeitsfläche/spyr/bin/Debug$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./sp

我试图找出我在哪里使用Valgrind对一段内存进行了无效写入。它告诉我们有这样一个问题,也在什么功能中,但不是在什么行中。虽然函数很小,但我希望在Valgrind中显示行号。我在Valgrind的一些输出中看到了这一点,但目前它们没有显示,我想知道为什么

输出如下:

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)
[...]
我看到输出,行号显示在文件名后面的双冒号后面。即
/home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr:23
或类似文件

如何启用此功能

仅供参考,这是sp_ParticleBuffer_init函数

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;
}

您需要在二进制文件中包含调试信息。如果使用的是
gcc

OMG,请传递
-g
标志。谢谢你,伙计o我使用Code::Blocks IDE进行编译,并在调试模式下运行编译。本以为它会使用
-g
,但它没有。也许有一天我会让它失效。。我还认为它们已启用,因为我不知道valgrind只显示可执行的名称,而不是文件名。xD但是valgrind在没有调试符号的情况下是如何知道函数名称的呢?是的,在设置中启用了
-g
选项就知道了。:)@NiklasR很高兴知道。对于第二个问题,二进制文件仍然保留一些信息,除非它们被剥离。这些信息足以展开堆栈。谢谢。(;[一些填充字符…]