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 行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值