我在linux上編寫了一個C程序來處理大量的數據,大部分時間運行正常。但是,當處理一組特定的數據時,它總是告訴我'分段錯誤'錯誤,我試圖使用gdb而沒有運氣(請參閱我的另一個問題How to deal segmentation fault with GDB under particular circumstance?),所以我嘗試使用valgrind。它沒有告訴我用valgrind運行時的'分段錯誤'錯誤。那麼如何根據這些valgrind輸出來找到bug呢?有人可以幫助我分析這些valgrind輸出嗎?
==2441== Invalid write of size 4
==2441== at 0x404893: nodes_term32_flush (tyn_indexer.c:227)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid write of size 4
==2441== at 0x4048D8: nodes_term32_flush (tyn_indexer.c:254)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x40450D: nodes_term32_flush (tyn_indexer.c:260)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x404878: nodes_term32_flush (tyn_indexer.c:224)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid write of size 4
==2441== at 0x40487F: nodes_term32_flush (tyn_indexer.c:224)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x4048BD: nodes_term32_flush (tyn_indexer.c:251)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c094 is not stack'd, malloc'd or (recently) free'd
==2441==
==2441== Invalid write of size 4
==2441== at 0x4048C4: nodes_term32_flush (tyn_indexer.c:251)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c094 is not stack'd, malloc'd or (recently) free'd
==2441==
==2441== Invalid read of size 4
==2441== at 0x4093A0: tyn_p4d_encode32 (tyn_coder.c:645)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x409490: tyn_p4d_encode32 (tyn_coder.c:669)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x4094A7: tyn_p4d_encode32 (tyn_coder.c:667)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c088 is 8 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x409574: tyn_p4d_encode32 (tyn_coder.c:694)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c080 is 0 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x4095A6: tyn_p4d_encode32 (tyn_coder.c:708)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c088 is 8 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x409524: tyn_p4d_encode32 (tyn_coder.c:697)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c08c is 12 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x40953A: tyn_p4d_encode32 (tyn_coder.c:700)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1233c08c is 12 bytes after a block of size 1,048,576 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x406BEB: tyn_build_index (tyn_indexer.c:663)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x409552: tyn_p4d_encode32 (tyn_coder.c:702)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1243c2fc is 12 bytes after a block of size 16 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x40785B: tyn_exsorter_sort (tyn_exsorter.c:106)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x407CB7: tyn_iS16_encode32 (tyn_coder.c:96)
==2441== by 0x409621: tyn_p4d_encode32 (tyn_coder.c:725)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1243d880 is 0 bytes after a block of size 16 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x40785B: tyn_exsorter_sort (tyn_exsorter.c:106)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x407D20: tyn_iS16_encode32 (tyn_coder.c:109)
==2441== by 0x409621: tyn_p4d_encode32 (tyn_coder.c:725)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1243d880 is 0 bytes after a block of size 16 alloc'd
==2441== at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==2441== by 0x40785B: tyn_exsorter_sort (tyn_exsorter.c:106)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Invalid read of size 4
==2441== at 0x407D37: tyn_iS16_encode32 (tyn_coder.c:108)
==2441== by 0x409621: tyn_p4d_encode32 (tyn_coder.c:725)
==2441== by 0x4045F0: nodes_term32_flush (tyn_indexer.c:132)
==2441== by 0x407B77: tyn_exsorter_sort (tyn_exsorter.c:131)
==2441== by 0x406DDE: tyn_build_index (tyn_indexer.c:731)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441== Address 0x1243d8a8 is not stack'd, malloc'd or (recently) free'd
==2441==
==2441== Use of uninitialised value of size 8
==2441== at 0x3AE9C4726B: _itoa_word (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C49852: vfprintf (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C51FE8: printf (in /lib64/libc-2.14.90.so)
==2441== by 0x4071EF: tyn_build_index (tyn_indexer.c:888)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Conditional jump or move depends on uninitialised value(s)
==2441== at 0x3AE9C47275: _itoa_word (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C49852: vfprintf (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C51FE8: printf (in /lib64/libc-2.14.90.so)
==2441== by 0x4071EF: tyn_build_index (tyn_indexer.c:888)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
document id: 0
==2441== Conditional jump or move depends on uninitialised value(s)
==2441== at 0x3AE9C4774E: vfprintf (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C51FE8: printf (in /lib64/libc-2.14.90.so)
==2441== by 0x4073AD: tyn_build_index (tyn_indexer.c:900)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Use of uninitialised value of size 8
==2441== at 0x3AE9C4726B: _itoa_word (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C49852: vfprintf (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C51FE8: printf (in /lib64/libc-2.14.90.so)
==2441== by 0x4073AD: tyn_build_index (tyn_indexer.c:900)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
==2441== Conditional jump or move depends on uninitialised value(s)
==2441== at 0x3AE9C47275: _itoa_word (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C49852: vfprintf (in /lib64/libc-2.14.90.so)
==2441== by 0x3AE9C51FE8: printf (in /lib64/libc-2.14.90.so)
==2441== by 0x4073AD: tyn_build_index (tyn_indexer.c:900)
==2441== by 0x40384F: main (tyn_indexer.c:943)
==2441==
int32_t category: 0
bytes_collected: 972467429
196220 bytes/s
tyn_config->indexer->dl_directory: /dragon/tyan
tyn_config->indexer->memory_limit: 10240000
==2441==
==2441== HEAP SUMMARY:
==2441== in use at exit: 214,695,668 bytes in 399,272 blocks
==2441== total heap usage: 401,095 allocs, 1,823 frees, 219,225,806 bytes allocated
==2441==
==2441== LEAK SUMMARY:
==2441== definitely lost: 9,442,580 bytes in 27 blocks
==2441== indirectly lost: 34,682,771 bytes in 81 blocks
==2441== possibly lost: 170,557,809 bytes in 399,140 blocks
==2441== still reachable: 12,508 bytes in 24 blocks
==2441== suppressed: 0 bytes in 0 blocks
==2441== Rerun with --leak-check=full to see details of leaked memory
==2441==
==2441== For counts of detected and suppressed errors, rerun with: -v
==2441== Use --track-origins=yes to see where uninitialised values come from
==2441== ERROR SUMMARY: 32680 errors from 23 contexts (suppressed: 2 from 2)
和+1後面的時間來深入瞭解數據。我真的想要一般的方法,因爲那裏有很多信息,而且我在很長一段時間內沒有使用過valgrind。隨着時間的推移調試segfaults,我發現未初始化的變量往往會導致這個方向,當然,覆蓋緩衝區可以做各種有趣的事情。 – pstrjds 2012-03-23 04:39:41