From a developer point of view, we highly recommend clang over other compilers.
The toolset provided is very convenient and the errors are easier to track.
Here is a non-exhaustive list of the debugging tips
Use the address sanitizer from clang by adding the -fsanitize=address to the compilation and linker flags.
To get a decent stack trace you should compile with -O1 and -fno-omit-frame-pointer. To further improve the trace, use -fno-optimize-sibling-calls.
For more information, refer to the clang documentation
Use the undefined behavior sanitizer from clang by adding the -fsanitize=undefined to the compilation and linker flags.
To get a decent stack trace you should compile with -O1 and -fno-omit-frame-pointer. Also, run with UBSAN_OPTIONS=print_stacktrace=1.
For more information, refer to the clang documentation
Please, use the fsanitize instead! It's much more powerfull and robust.
The classical vagrind is useful but sometimes not enough (see the sanitize). To run it:
mpirun -n X valgrind ./murphy...You can also add some options like --show-leak-kinds=all --leak-check=full --track-origins=yes --error-limit=no to help detect the leaks.
To run (and view the optimization) analysis, add the flags -fsave-optimization-record to the compilation.
Then, simply use the tool from llvm to create html webpages (run the command directly in the Docker):
python3 /usr/lib/llvm-11/share/opt-viewer/opt-viewer.py --output-dir opt_reports build/*.opt.yaml
- install the Intelisens extension
- create a new configuration profile (either open
c_cpp_properties.jsonor use the UI:cmd+P+ type ">C/C++: Edit configurations (UI)") - my configuration is something like:
{
"name": "murphy-container-clang",
"includePath": [
"src",
"src/clients",
"src/core",
"src/grid",
"src/operator",
"src/poisson",
"src/time",
"src/tools",
"src/wavelet",
"test/src",
"/soft/flups/include",
"/soft/p4est-github/include",
"/usr/local/hdf5/include",
"/usr/local/openmpi/include",
"/usr/local/fftw/include",
"/soft/googletest/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"browse": {
"path": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/test/src/**"
],
"limitSymbolsToIncludedHeaders": true,
// "databaseFilename": ""
}
}- choose the configuration:
cmd+P+ type ">C/C++: Select a configuration")
Now the IntelliSense of VSCode is using clang to guide you and generate error/warnings
Clang-Tidy is helpfull to track and detect all the c++ errors (like objects declaration etc).
VSCode has an extension that allows you to visualize the output directly in the editor.
- install the extension if not already done (should be done automatically as part of the
.devcontainer.jsonfile) - you need to generate a compilation database for clang (a file
compile_commands.json). As we now have clang in the docker the easiest is by far to use clang directly - we implemented a rule in the makefile to do so:
make compdb(ormake compdb_fullto include the tests)
Other useful resources