vld vld_vs2019 vld_doc download gui DR常用命令sudo apt-get install valgrindsudo apt-get install subversion svn co svn://svn.valgrind.org/valgrind/trunk valgrindgcc test.c -g -o test #运行后生成.outvalgrind --suppressionsvalgrind/runTest.sup --leak-checkfull ./bin/runTestvalgrind --leak-checkfull --show-reachableyes --trace-childrenyes ./bin/runTestkillall memcheck #守护进程泄漏检测killall callgrind #守护进程代码覆盖和性能瓶颈检测valgrind --toolMemcheck(默认),callgrind,Addrcheck,Cachegrind,Helgrind(多线程分析),Massif(堆分析),DHAT,BBV ./bin/runTest #生成callgrind.out.pidcallgrind_annotate --autoyes callgrind.out.23202 log #查看callgrind结果valgrind --toolmemcheck ls -l #命令内存检查–vgdbyes,full --vgdb-error0 --vgdb-stop-atstartup,exit,abexit,valgrindabexit #valgrind下gdb调试–log-file #输出日志–run-cxx-freeres #C检测gdb prog target remote | vgdb #开始gdb调试后另shell远程gdb调试示例代码#include stdio.h#include stdlib.h#include string.hvoid f(void){int* x malloc(10 * sizeof(int));x[10] 0; // problem 1: heap block overrun} // problem 2: memory leak – x not freedvoid func() {printf(“func call”);func();}int main(int, int**) {f();//func();printf(“hello\n”);char *ptr malloc(10);ptr[12] ‘a’;// 内存越界memcpy(ptr1, ptr, 5);// 踩内存char a[10];a[12] ‘i’;// 数组越界free(ptr);free(ptr);// 重复释放char *p1;*p1 ‘1’;// 非法指针}创作不易小小的支持一下吧
阅读完成 · 觉得有帮助?