Search code examples
windowsaddress-sanitizersanitizer

Address Sanitizer - How to set >1 ASAN_OPTIONS?


I'm on Windows using Visual Studio compiler.
I'm using /fsanitize=address to compile with AddressSanitizer.
I run my exe from command line.

I want my exe to

  1. continue on ASAN errors and
  2. write all ASAN errors to a logfile

The documentation of ASAN_OPTIONS suggests the following syntax:
set ASAN_OPTIONS=continue_on_error=1:log_path=log_file my.exe

However, I only can (partially) succeed, when I
a) omit the exe name AND b) use only 1 option

When specifying the executable name, I always get the error
Internal error duing continue on error: Fail on write()
(no matter
whether I use the full path name or the exe file name only,
or if I'm in the exe's directory or not)

And when using more than 1 option, only 1 option is working.
I tried the delimiter characters (space) and :.
Surrounding the whole option string with quotes (") is counterproductive: then no option is recognized at all.

Edit after @yugr's answer: I experimented a little further and experienced the following:

  • 2 options:
    >set ASAN_OPTIONS=log_path='D:\_tmp\log_file':continue_on_error=1
    continues, but does not writa a logfile
  • exchanged option order:
    >set ASAN_OPTIONS=continue_on_error=1:log_path='D:\_tmp\log_file'
    continues, but does not writa a logfile
  • logfile only:
    set ASAN_OPTIONS=log_path='D:\_tmp\log_file'
    works: does writa a logfile
  • different delimiter: space
    >set ASAN_OPTIONS=continue_on_error=1 log_path='D:\_tmp\log_file'
    continues, but does not writa a logfile
  • exchanged option order with delimiter space:
    >set ASAN_OPTIONS=log_path='D:\_tmp\log_file' continue_on_error=1
    continues, but does not writa a logfile
  • different delimiter: semicolon
    >set ASAN_OPTIONS=continue_on_error=1;log_path='D:\_tmp\log_file'
    >my.exe
    Internal error duing continue on error: Fail on write()

Edit end.


I tried the option log_path with

  1. stderr
    => AddressSanitizer output occurs on stderr instead of stdout (note: the doc states a default value of stderr, which is obviously not the case here)
  2. log_file
    => works (the file log_file.<pid> occurs in the current directory, not in the exe directory)
  3. D:\_tmp\log_file
    => gives AddressSanitizer: ERROR: expected '=' in ASAN_OPTIONS - don't know why:
    > echo %ASAN_OPTIONS%
    log_path=D:\_tmp\log_file

Any hint is highly appreciated on the 3 dubieties (exe name in options, >1 option, path in log_path option).


Solution

  • The documentation of ASAN_OPTIONS suggests the following syntax: set ASAN_OPTIONS=continue_on_error=1:log_path=log_file my.exe ... When specifying the executable name, I always get the error

    That syntax is Linux-specific. On Windows you should run it with two separate commands

    > set ASAN_OPTIONS=log_path=log_file
    > my.exe
    

    Multiple flags in ASAN_OPTIONS can be separated via : or (whitespace):

    > set ASAN_OPTIONS=verbosity=2:log_path=log_file
    > set ASAN_OPTIONS=verbosity=2 log_path=log_file
    

    D:\_tmp\log_file => gives AddressSanitizer: ERROR: expected '=' in ASAN_OPTIONS - don't know why:

    Yes, this is a (mis)feature of Asan - it treats any unescaped colon as option separator so when you do

    set ASAN_OPTIONS=log_path=D:\_tmp\log_file
    

    it treats "\_tmp\log_file" as second option and fails to parse it. You should escape filename to prevent Asan from doing this:

    set ASAN_OPTIONS=log_path='D:\_tmp\log_file'
    

    2 options: set ASAN_OPTIONS=log_path='D:_tmp\log_file':continue_on_error=1 continues, but does not writa a logfile

    exchanged option order: set ASAN_OPTIONS=continue_on_error=1:log_path='D:_tmp\log_file' continues, but does not writa a logfile

    This happens because continue_on_error=1 forces output to stdout and overrides the log_path setting.