linux 调试

来源:互联网 发布:淘宝天猫类目采集器 编辑:程序博客网 时间:2024/05/24 22:43

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.)

0 0
原创粉丝点击