<目次>
(1) Valgrindで行番号を表示させる方法
(1-1) 行番号を表示させる方法
(1-2) (参考)「-g」オプションについて
(1) Valgrindで行番号を表示させる方法
本記事ではValgrindのメモリチェックにおいて、結果に行番号を表示させる方法をご紹介します。メモリリークがどこで発生したか?を特定するのに役立ちます。
==XXXXX== by 0x40059E: main (in /tmp_rainbow/memorytest)
(After)
==XXXXX== by 0x40059E: main (memorytest.cpp:5)
(1-1) 行番号を表示させる方法
valgrind --tool=memcheck --leak-check=yes ../memorytest
==21696== HEAP SUMMARY: ==21696== in use at exit: 100 bytes in 1 blocks ==21696== total heap usage: 1 allocs, 0 frees, 100 bytes allocated ==21696== ==21696== 100 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==21696== at 0x4C2C866: operator new[](unsigned long) (vg_replace_malloc.c:579) ==21696== by 0x40059E: main (in /tmp_rainbow/memorytest) ==21696== ==21696== LEAK SUMMARY: ==21696== definitely lost: 100 bytes in 1 blocks ==21696== indirectly lost: 0 bytes in 0 blocks ==21696== possibly lost: 0 bytes in 0 blocks ==21696== still reachable: 0 bytes in 0 blocks ==21696== suppressed: 0 bytes in 0 blocks
$ g++ -g -o memorytest memorytest.cpp
valgrind --tool=memcheck --leak-check=yes ../memorytest
==11651== HEAP SUMMARY: ==11651== in use at exit: 100 bytes in 1 blocks ==11651== total heap usage: 1 allocs, 0 frees, 100 bytes allocated ==11651== ==11651== 100 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==11651== at 0x4C2C866: operator new[](unsigned long) (vg_replace_malloc.c:579) ==11651== by 0x40059E: main (memorytest.cpp:5) ==11651== ==11651== LEAK SUMMARY: ==11651== definitely lost: 100 bytes in 1 blocks ==11651== indirectly lost: 0 bytes in 0 blocks ==11651== possibly lost: 0 bytes in 0 blocks ==11651== still reachable: 0 bytes in 0 blocks ==11651== suppressed: 0 bytes in 0 blocks