I am trying to debug a memory error detected by clang
with asan
, but missed by valgrind
. But I cannot get my clang
built bina
For me, there is no llvm-symbolizer in /usr/bin, I need to first use
sudo ln -s /usr/bin/llvm-symbolizer-3.8 /usr/bin/llvm-symbolizer
to create the symbolizer and then add it to the PATH:
ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer ./test
Sometimes everything (path to the symboliser, environment variable etc) will be correct, but still you won't get file:line
formatted output.
So run
dsymutil path/to/your.app/Contents/MacOS/binary
and then run the app and you'll get nicely formatted output. This is also mentioned in the docs.
Note that on macOS you may need to run dsymutil on your binary to have the file:line info in the AddressSanitizer reports.
http://clang.llvm.org/docs/AddressSanitizer.html#symbolizing-the-reports
Is addr2line what you are looking for?
$ addr2line -e ./test 0x43e94f
some/file.c:1234
Sometimes using a symbolizer with a version number will give the error:
ERROR: External symbolizer path is set to '/usr/bin/llvm-symbolizer-5.0' which isn't a known symbolizer. Please set the path to the llvm-symbolizer binary or other known tool.
This can be fixed by pointing to an unadorned llvm-symbolizer
binary:
export ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-5.0/bin/llvm-symbolizer
Then ran your executable as you normally would.
If we look at the clang
AddressSanitizer documentation it says:
To make AddressSanitizer symbolize its output you need to set the ASAN_SYMBOLIZER_PATH environment variable to point to the llvm-symbolizer binary (or make sure llvm-symbolizer is in your $PATH):
and shows the the following example:
ASAN_SYMBOLIZER_PATH=/usr/local/bin/llvm-symbolizer ./a.out
As the OP noted, the install location may vary, but once you know where llvm-symbolizer
is located the steps are the same.