AddressSanitizer使用教程

如果遇到了segmentation fault,可以试试AddressSanitizer (aka ASan)。官方文档:https://github.com/google/sanitizers/wiki/AddressSanitizer

一般只需要在编译选项中加入-fsanitize=address即可。注意,仅在Debug模式下有效。

如果报这个错:

==1803867==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

需要在运行的命令前加上(具体的路径可能不一样):

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.8

如果想要在ASan error的时候dump core,需要在运行命令前:

# https://stackoverflow.com/questions/42851670/how-to-generate-core-dump-on-addresssanitizer-error
export ASAN_OPTIONS=abort_on_error=1
posted @ 2024-11-18 16:55  寻找繁星  阅读(16)  评论(0编辑  收藏  举报