clang memory sanitizer; how to make it print source line numbers

谁说我不能喝 提交于 2019-12-12 07:33:00

问题


I'm compiling my program with clang++ -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -g -O0 and when I run it, the output is:

matiu@matiu-laptop:~/projects/json++11/build$ ./tests 
.......==10534== WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7fe7602d4a51 (/home/matiu/projects/json++11/build/tests+0x106a51)
    #1 0x7fe7602dfca6 (/home/matiu/projects/json++11/build/tests+0x111ca6)
    ...
    #31 0x7fe75edbaec4 (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
    #32 0x7fe7602808dc (/home/matiu/projects/json++11/build/tests+0xb28dc)

  Uninitialized value was created by a heap allocation
    #0 0x7fe76026e7b3 (/home/matiu/projects/json++11/build/tests+0xa07b3)
    #1 0x7fe7602ee7da (/home/matiu/projects/json++11/build/tests+0x1207da)
    ...
    #18 0x7fe7602c1c4c (/home/matiu/projects/json++11/build/tests+0xf3c4c)
    #19 0x7fe7602873fa (/home/matiu/projects/json++11/build/tests+0xb93fa)

SUMMARY: MemorySanitizer: use-of-uninitialized-value ??:0 ??
Exiting

How can I make it show line numbers like in the beautiful examples: http://clang.llvm.org/docs/MemorySanitizer.html

I'm suspecting it might not be possible, due to my pragram being one giant nested bunch of lambdas: https://github.com/matiu2/json--11/blob/master/tests.cpp


回答1:


With the address sanitizer I noticed that I needed to have these environment variables defined:

  • ASAN_OPTIONS=symbolize=1 (only needed when compiled with GCC > 4.8) and
  • ASAN_SYMBOLIZER_PATH=$(which llvm-symbolizer) I think the symbolizer is what you're looking for. It transforms symbols to file names with line numbers and columns.

On the memory sanitizer project website it reads:

Symbolization

Set MSAN_SYMBOLIZER_PATH environment variable to the path to llvm-symbolizer binary (normally built with LLVM). MemorySanitizer will use it to symbolize reports on-the-fly.

So you need MSAN_SYMBOLIZER_PATH to be set analogous to ASAN_SYMBOLIZER_PATH.



来源:https://stackoverflow.com/questions/24399485/clang-memory-sanitizer-how-to-make-it-print-source-line-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!