C檢查內存泄漏以及Segment fault

Valgrind檢查內存泄漏,例如test是可執行程序

[root@localhost cmake-build-debug]# valgrind --leak-check=full --show-reachable=yes  ./test

 

gdb檢查Segment fault

1、

[root@app184 ~]#  ulimit -c unlimited

2、

[root@localhost cmake-build-debug]# ./test 

3、執行完第二步,會在可執行程序所在的文件夾出現一個core.xxxx的文件,gdb test core.xxxx查看

[root@localhost cmake-build-debug]# ll
總用量 588
-rw-r--r--. 1 root root      8 3月  12 09:04 aa.log
-rw-r--r--. 1 root root  33345 3月  11 17:16 CMakeCache.txt
drwxr-xr-x. 6 root root   4096 3月  12 09:45 CMakeFiles
-rw-r--r--. 1 root root   1501 3月  11 09:29 cmake_install.cmake
-rw-------. 1 root root 528384 3月  12 09:45 core.104063
-rw-r--r--. 1 root root   5369 3月  12 09:03 Makefile
-rw-r--r--. 1 root root   5133 3月  11 09:29 radar.cbp
-rwxr-xr-x. 1 root root  11192 3月  12 09:45 test
-rw-r--r--. 1 root root   5287 3月  12 09:03 test.cbp
[root@localhost cmake-build-debug]# gdb test core.104063 
[root@localhost cmake-build-debug]# gdb test core.104063 
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/sd_bs/test/cmake-build-debug/test...done.
[New LWP 104063]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./test'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000400b33 in sub () at /root/sd_bs/test/main.c:47
47          printf("%d", *p);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.3.x86_64
(gdb) 

發現錯誤實在main.c的47 行

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