4Feb/110
gcc, colorgcc, lcov, valgrind
At home I usually don't create makefiles when my program is so small that it fits into one file.
However compilation errors are more readable with colorgcc, and having as much warnings/errors at compilation time as possible is even better.
.bashrc
:
GCC_ARGS="-Wall -Werror -pedantic -Weffc++ -Wshadow -ggdb --coverage" alias g++="/usr/lib/colorgcc/bin/g++ $GCC_ARGS" alias gcc="/usr/lib/colorgcc/bin/gcc $GCC_ARGS"
The -ggdb
puts debug symbols to the binary and --coverage
will make the binary create .gcda
and .gcno
files at runtime.
To create a nice coverage-html lcov needs more steps (3) than I'm willing to type everytime so the following line in the .bashrc
do the work. Note that the lcov_all
is function, because argument passing is not possible with aliases.
alias lcov_reset="lcov --directory . -z ; rm -f ./lcov.info" alias lcov_capture="lcov --directory . --capture -o lcov.info" alias lcov_html="rm -rf ./cov ; mkdir cov ; genhtml -o ./cov lcov.info" function lcov_all() { lcov_reset ; $1 ; lcov_capture ; lcov_html ; }
The best way to alter valgrind's behavior modifying the .valgrindrc
:
--leak-check=full --show-reachable=yes --malloc-fill=0xaa --free-fill=0xbb
So when I program follow the following steps:
- Edit the source.
g++ <sourcefile>
- run
<binary>
- Check leaks:
valgrind <binary>
- If coverage is needed,
lcov_all <binary>
Leave a comment