Home > OS >  Can asan issue trap upon violation like ubsan does?
Can asan issue trap upon violation like ubsan does?

Time:07-31

Minimum reproducible example: https://godbolt.org/z/4hje5h1js

A great feature of ubsan (undefined behavior sanitizer) is to issue a trap that breaks into gdb when an issue occurs. This is turned on with -fsanitize-undefined-trap-on-error. However asan (address sanitizer) does not seem to have such option.

Is that correct or I'm missing the proper documentation? If not, is there anything intrinsic about address sanitizer that prevents it doing a trap?

Compiling with clang 10.0 on Ubuntu 20.04 LTS.

CodePudding user response:

For historical reasons Asan simply exits the application on error but you can ask it to abort (which will be intercepted by gdb) by setting environment variable:

export ASAN_OPTIONS=abort_on_error=1

Or you could simply set a breakpoint at __asan_report_error in gdb.

CodePudding user response:

AddressSanitizer does it by default. If it does not stop in the debugger, make sure neither -fsanitize-recover=address is set in the compiler flags nor halt_on_error=0 is set in ASAN_OPTIONS environment variable.

  • Related