c – Valgrind不显示行号

前端之家收集整理的这篇文章主要介绍了c – Valgrind不显示行号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图找出使用Valgrind对一块内存进行无效写入的位置.它告诉我们存在这样一个问题,也就是说什么功能,但不是在哪一行.虽然功能非常小,但我想在Valgrind中显示行号.我在Valgrind的一些输出上看过这个,但目前它们没有显示,我想知道为什么.

输出如下:

  1. niklas@emerald:~/Arbeitsfläche/spyr/bin/Debug$valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./spyr
  2. [...]
  3. ==4404== Invalid write of size 4
  4. ==4404== at 0x8048849: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  5. ==4404== by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  6. ==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  7. ==4404== Address 0x422a0a0 is 4 bytes after a block of size 4 alloc'd
  8. ==4404== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  9. ==4404== by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  10. ==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  11. ==4404==
  12. ==4404== Invalid write of size 4
  13. ==4404== at 0x8048865: sp_ParticleBuffer_init (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  14. ==4404== by 0x8048BFC: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  15. ==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  16. ==4404== Address 0x422a09c is 0 bytes after a block of size 4 alloc'd
  17. ==4404== at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  18. ==4404== by 0x8048BC1: sp_ParticleSystem_createParticle (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  19. ==4404== by 0x8048691: main (in /home/niklas/Arbeitsfläche/spyr/bin/Debug/spyr)
  20. [...]

我看到了输出,其中行号在文件名后面的双冒号后显示.即/ home / niklas /Arbeitsfläche/ spyr / bin / Debug / spyr:23或类似.

我怎样才能启用它?

仅供参考,这是sp_ParticleBuffer_init函数.

  1. int sp_ParticleBuffer_init(sp_ParticleBuffer* buffer,sp_Uint32 buffer_size,int init_zero) {
  2. size_t size = sizeof(sp_Particle) * buffer_size;
  3. buffer->next = null;
  4. buffer->array = (sp_Particle*) malloc(size);
  5. buffer->alive_count = 0;
  6.  
  7. if (!buffer->array) return SPYR_ALLOCFailed;
  8. if (init_zero) memset((void*) buffer->array,size);
  9. return SPYR_NOERR;
  10. }

解决方法

您需要在二进制文件中包含调试信息.如果您正在使用gcc,请传递-g标志.

猜你在找的C&C++相关文章