valgrind - aragorn/home GitHub Wiki
{toc}
h3. stack trace of threaded program using gdb
{noformat} (gdb) thread apply all backtrace full {noformat}
h3. valgrind
- usage {code}valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar{code}
- still reachable ** http://stackoverflow.com/questions/3840582/still-reachable-leak-detected-by-valgrind
h4. tools
-
valgrind-3.6.0.SVN-Debian ๊ธฐ์ค
-
memcheck (default) - [manual|http://aragorn1.dev.daum.net/doc/valgrind/html/mc-manual.html] {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar}}
-
cachegrind - [manual|http://aragorn1.dev.daum.net/doc/valgrind/html/cg-manual.html] {{valgrind --tool=cachegrind ./foobar}}
-
- [manual|] {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar}}
-
- [manual|] {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar}}
-
- [manual|] {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar}}
-
- [manual|] {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./foobar}} h4. suppressing errors
-
http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress
-
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles
-
writing suppression files *# ์ฐธ๊ณ : http://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto *# valgrind report์์ ๋ถํ์ํ ์ค๋ฅ ํ์ง๊ฐ ์๋์ง ํ์ธํ๋ค. {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./benchmark -g debug -c 10 *.c > /dev/null 3>>error.log}} *# {{--gen-suppressions=all}} ์ต์ ์ ์ฌ์ฉํ์ฌ suppression file์ ์์ฑํ๋ค. ์ด๋ ์ํ์ ํ๋ฉด์ ์ถ๋ ฅํ๋ ๊ฒ์ ํ์ผ์ ์ ์ฅํ๊ณ , ํ์ง๋ ์ค๋ฅ๋ฅผ ์ ํ์์ด ๋ชจ๋ ์ถ๋ ฅํ๊ธฐ ์ํ ์ต์ ์ ์ถ๊ฐํ๋ค. {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes --gen-suppressions=all --error-limit=no --log-file=valgrind.log ./benchmark -g debug -c 10 *.c > /dev/null 3>>error.log}} # {{--log-file=valgrind.log}} ์ถ๋ ฅ์ ๋ก๊ทธ์ ์ ์ฅ # {{--error-limit=no}} ํ์ง๋ ์ค๋ฅ์ ์ ์ ํ์ ์์ฐ *# valgrind.log ๋ฅผ ํธ์งํ์ฌ suppression ๊ท์น๋ง ๋จ๊ธด๋ค. ๊ท์นํ์ผ์ valgrind.supp ์ ๋์ ์ด๋ฆ์ผ๋ก ๋ณ๊ฒฝํ์ฌ ์ ์ฅํ๋ค. ==1234== ์ ๊ฐ์ PID๋ก ์์ํ๋ ๋ก๊ทธ ๋ฉ์์ง๋ฅผ ์ญ์ ํ๋ค. suppression ๊ท์น์ stack trace๋ฅผ ์ ์ ํ ํธ์งํ์ฌ ์ ์ฌํ ํจํด์ ๋งค์น๋ ์ ์๋๋ก ์์ ํ๋ค. stack trace ์ ์ฒด๊ฐ ์ผ์นํ์ฌ์ผ ํ๋ฉฐ, ํจ์๋ ๊ฐ์ฒด์ด๋ฆ์ ์ฐพ์ ๋ * ๋๋ ? ์์ผ๋์นด๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค. stack์ frame์ ๋ํ ์์ผ๋์นด๋ ๋งค์น๋ ... ๋ฅผ ์ฌ์ฉํ๋ค. {newcode}
comments start with
{ <_Unwind_ForcedUnwind/pthread_cancel_init> Memcheck:Leak ... fun:dl_open_worker fun:_dl_catch_error fun:_dl_open fun:do_dlopen fun:_dl_catch_error fun:__libc_dlopen_mode fun:pthread_cancel_init fun:_Unwind_ForcedUnwind ... } {newcode} *# suppression file์ ์ ์ฉํ์ฌ ์ค๋ฅ ํ์ง๋ฅผ ์ฌ์๋ํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ๋ค. {{valgrind --tool=memcheck --leak-check=full --show-reachable=yes --suppressions=valgrind.supp ./benchmark -g debug -c 10 *.c > /dev/null 3>>error.log}}
h4. Data Race Detection
h3. threaded programming
-
volatile ** http://stackoverflow.com/questions/78172/using-c-pthreads-do-shared-variables-need-to-be-volatile ** http://stackoverflow.com/questions/6837699/are-mutex-lock-functions-sufficient-without-volatile ** https://en.wikipedia.org/wiki/Memory_barrier ** http://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming ** http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2016.html
-
volatile์ 3๊ฐ์ง ์ฉ๋ ** marking a local variable in the scope of a setjmp so that the variable does not rollback after a longjmp. ** memory that is modified by an external agent or appears to be because of a screwy memory mapping ** signal handler mischief
-
pthreads and valgrind memory leak ** http://stackoverflow.com/questions/15207762/c-pthreads-valgrind-memory-leak-why ** http://stackoverflow.com/questions/3840582/still-reachable-leak-detected-by-valgrind
h3. signal
- man 7 signal ** Async-signal-safe functions A signal handling routine established by sigaction(2) or signal(2) must be very careful, since processing elsewhere may be interrupted at some arbitrary point in the execution of the program. POSIX has the concept of "safe function". If a signal interrupts the execution of an unsafe function, and handler calls an unsafe function, then the behavior of the program is undefined.