valgrind - aragorn/home GitHub Wiki

{toc}

h3. stack trace of threaded program using gdb

{noformat} (gdb) thread apply all backtrace full {noformat}

h3. 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

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.