c - Valgrind 不显示行号

标签 c linux ubuntu valgrind

我正在尝试找出我使用 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)
[...]

我看到输出中行号显示在文件名后面的双冒号之后。 IE。 /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,请传递 -g 标志。

关于c - Valgrind 不显示行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12130246/

相关文章:

c - C语言中简单的凯撒密码,无需用户输入

linux - -f 、 -s 选项如何与 uniq 命令一起使用?

linux - python : Should I use shutil or subprocess to manipulate files and directories as a better approach?

ubuntu - 如何以编程方式从 MP3 中删除静音?

ubuntu - Sonarqube for Ubuntu 成功扫描 .NET 项目,但未分析任何问题

C strncpy 没有空终止的原因

c - 切片文件字符串

C 程序可以编译,但执行后立即终止

linux - 如何使用sed从文本文件中获取变量?

java - 为什么我的简单 springmvc Web 应用程序会关闭 Jetty?