linux 調試

ulimit -c unlimited 崩潰生成core文件

gdb -c corefile ./excute.


記一個bug:一個線程通過malloc分配內存,將該內存放入到list中,另一個線程讀取這個list,總是在特定的次數後發生free崩潰,提示:invalid pointer.

解決思路:跟蹤 malloc 和 free.使用了__malloc_hook.__free_hook.https://github.com/GisKook/codeset/blob/master/civilmanager_access/test/mallochook_test.c

同事使用了backtrace。打印調用堆棧。沒有發現有價值的東西,想到一般malloc時都在生成的pointer之前放置一些大小信息,跟蹤過程中發現出問題時malloc那個cookie都成爲了0.所以推斷是被其他線程覆蓋了,gdb使用awatch命令找到了源頭。


如何尋找類型的定義:如 time_t gcc -E xxx.c | grep time_t (Stop after the preprocessing stage; do not run the compiler proper.  The output is in the form of preprocessed source code, which is sent to the standard output. Input files which don’t require preprocessing are ignored.)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章