安装VS2019以支持ASAN地址消毒

一、安装VS2019 

   请移步至https://my.visualstudio.com/Downloads?q=visual%20studio%202019&wt.mc_id=o~msft~vscom~older-downloads选择 Visual Studio Professional 2019 (version 16.11.16)专业版下载

    key请自行Google获取,谢谢。

二、VS2019工程属性配置ASAN地址消毒

                                    Turn on AddressSanitizer &  Turn off edit and continue

                                             Turn off /INCREMENTAL (incremental linking)

三、配置ASAN_OPTIONS环境变量

 

log_path=asan.log:表示程序运行时asan若检测到内存操作问题,会记录在此,请打开该文件进行分析。

help=1:Print the flag descriptions

可在ASAN_OPTIONS环境变量中提供如下配置,仅供参考:halt_on_error=1:quarantine_size_mb=512:thread_local_quarantine_size_kb=128:log_path=asan.log:alloc_dealloc_mismatch=1:allocation_size_too_big=1:calloc_overflow=1:double_free=1:dynamic_stack_buffer_overflow=1:global_buffer_overflow=1:heap_buffer_overflow=1:heap_use_after_free=1:invalid_allocation_alignment=1:memcpy_param_overlap=1:new_delete_type_mismatch=1:stack_buffer_overflow=1:stack_buffer_underflow=1:stack_use_after_return=1:stack_use_after_scope=1:strncat_param_overlap=1:use_after_poison=1:detect_stack_use_after_return=1:allow_user_poisoning=1:check_initialization_order=1:report_globals=1:debug=1:sleep_before_dying=5:atexit=1:print_stats=1:strict_init_order=1:detect_invalid_pointer_pairs=2:detect_container_overflow=1:detect_odr_violation=2:verbosity=2:detect_deadlocks=1:color=always:help=1

以下选项是Windows所支持且常用的,亲测可用:

halt_on_error=0:quarantine_size_mb=1024:thread_local_quarantine_size_kb=512:log_path=asan.log:alloc_dealloc_mismatch=1:new_delete_type_mismatch=1:detect_stack_use_after_return=1:allow_user_poisoning=1:check_initialization_order=1:report_globals=1:debug=1:sleep_before_dying=5:atexit=1:print_stats=1:strict_init_order=1:detect_invalid_pointer_pairs=2:detect_container_overflow=1:detect_odr_violation=2:verbosity=2:detect_deadlocks=1:color=always:detect_stack_use_after_return=1:allocator_may_return_null=1:windows_hook_legacy_allocators=1

另外,请在项目属性==>C/C++==>Command Line==>Additional Options里添加/fsanitize-address-use-after-return或/fno-sanitize-address-vcasan-lib支持,ASAN_OPTIONS里增加detect_stack_use_after_return=1

友情提示:以上配置OK之后,尤其是ASAN_OPTIONS环境变量配置成功后,请重启VS2019或Windows生效。

四、遗留问题

1.halt_on_error=0选项亲测功能不生效,即未在asan工具检测到内存问题后继续运行程序,而是闪退。待研究。

五、参考文献

 1) 关于 ASAN - 知乎

 ​​​2) AddressSanitizer | Microsoft Docs

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老中医的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值