Henrique Bucher
Henrique Bucher

Reputation: 4474

Can asan issue trap upon violation like ubsan does?

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.

Upvotes: 1

Views: 559

Answers (1)

yugr
yugr

Reputation: 21916

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.

Upvotes: 2

Related Questions