valgrind跟蹤調試動態庫*.so


遇到問題:

在使用valgrind跟蹤調試動態庫時,遇到如下問題,不知道問題發生在代碼哪里:

 

==11728== 1 errors in context 5 of 31:

==11728== Source and destination overlap in memcpy(0x4f35880, 0x4f35880, 163840)
==11728== at 0x4A08A9E: memcpy (mc_replace_strmem.c:878)
==11728== by 0x5885956: ???
==11728== by 0x5887CDC: ???
==11728== by 0x588DBEE: ???
==11728== by 0x5249391: ???
==11728== by 0x503E2D2: ???
==11728== by 0x405F5B: main (main.c:168)

 

一、在官方幫助中有:

If they're not long enough, use --num-callers to make them longer.

If they're not detailed enough, make sure you are compiling with -g to add debug information. And don't strip symbol tables (programs should be unstripped unless you run 'strip' on them; some libraries ship stripped).

Also, for leak reports involving shared objects, if the shared object is unloaded before the program terminates, Valgrind will discard the debug information and the error message will be full of ??? entries. The workaround here is to avoid calling dlclose on these shared objects.

從字面上看,主程序不要關閉(或卸載)動態庫,但怎么才算不不關閉動態庫呢?

看了半個下午,才搞懂這個是什么意思:

正常情況下,我們在程序中打開動態庫后,在程序結束后,都要關閉動態庫。這樣的話,就無法找到符號表。

二、解決方案:

把關閉動態庫的代碼注釋掉即可。

例如在glib中:

//g_module_close(mode_dispatch);

 

ps:兩年前遇到過同樣的問題,今天有遇到就忘了當時是怎么解決的。還是記錄一下吧。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM