감동, 마음이 움직이는 것

[c++] debugging using Valgrind 본문

Tips (Utility, Computer Language, and etc.)

[c++] debugging using Valgrind

Struggler J. 2017. 7. 9. 17:37

[출처]

http://blog.daum.net/basetechnology/6997968

http://valgrind.org/

http://stormaa.tistory.com/5


[1] 다운로드

나는 이게 설치되어 있어서 그냥 바로 사용가능했었는데 다운로드 받으려면 http://valgrind.org/ 로 들어가서 다운을 받으면 된다.


[2] 컴파일 옵션 -g

소스코드를 컴파일할 때 -g 옵션을 사용해서 컴파일을 해야한다.

(예) gcc test.cpp -o test -g 

[3] Memory leak check

valgrind --tool=memcheck   --log-file=memcheck.txt  ./test 

혹은

valgrind --leak-check=full --log-file=memcheck.txt -v --error-limit=no ./test

사실 두 개의 차이가 뭔지는 정확히 모르겟지만 leak-check=full이  훨씬 더 자세한 것들이 나오더라.

첫 번째의 경우는 정말 간단하게 한눈에 요약해서 눈에 들어온다.

두 번째 leak summary에서는  definitely lost부분만 자세히 보면 된다고 한다.

--tool=memcheck

--leak-check=full: 메모리에러가 난 경우 라인위치 출력

--log-file: 체크결과를 =이후의 파일이름으로 저장