Search code examples
c++debuggingwindows-10visual-studio-2022address-sanitizer

Turn VS Address-Sanitizer off and on or speed up while debugging?


I've instrumented my debug code, the .EXE and all .DLLs. I'm tracking down an allocation bug that corrupts memory after about 5 minutes. With the code instrumented, it runs at less than 1% of the normal speed, so after 8 hours, the code isn't close to where the bug might occur. When I removed Address-Sanitizer and then instrumented only one small .DLL, it slows down just as much. How can I start my code debugging with full instrumentation, then turn off Address-Sanitizer, then turn it back on 5 minutes later when approaching the code where I think the bug is?

I'm enabling Address-Sanitizer in the project properties, C/C++ General Enable Address Sanitizer Yes (/fsanitize=address). I'm running VS2022 Community on Windows 10 Pro.

According to Google and Microsoft docs, the performance hit should be less than 2X, so my bug should be detected in about 10 minutes. Am I using Address-Sanitizer incorrectly, or is there a better setup?

Any help is very much appreciated! Thanks.


Solution

  • A better solution that using ASAN might be to use gflags. This allocates memory in such a way that memory overwrites are usually caught straightaway without impacting performance unduly. The main downside is that a 32 bit program might run out of addressing space, but it would cost you nothing to try it.

    The magic sauce is:

    gflags -p /decommit /enable my_app.exe

    and:

    gflags -p /disable my_app.exe

    Worth a shot, anyway.

    Please note that:

    • after running gflags, you need to restart your app

    • You have to run gflags in a command shell running 'As Administrator'

    Best of luck.