How to generate core dump on AddressSanitizer error
Asked Answered
D

1

19

I compiled my code like this to enable Asan:

g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer

but it never generates a core dump so that I can later examine the details of the error. How can I generate it?

Denoting answered 17/3, 2017 at 7:31 Comment(0)
S
37

You need to set environment variable to request coredumps

export ASAN_OPTIONS=abort_on_error=1

This should really be default but due to historic reasons ASan just exits with non-zero error code instead.

On 64-bit systems you might need to add

export ASAN_OPTIONS=abort_on_error=1:disable_coredump=0:unmap_shadow_on_exit=1

(coredumps are disabled by default there, in fear that they will be too large).

Note that on some systems coredumps may be disabled by default so you'll also need to run

ulimit -c unlimited

For complete list of flags you can see Asan wiki.

Sizeable answered 17/3, 2017 at 20:27 Comment(5)
This is the only place on the net that I could find the correct answer for my 64-bit system. Thank you!Umbrageous
@Umbrageous Thank you. It's indeed sad to see that it's so hard to use Asan. Some complexity is justified (Asan has to do a lot of clever tricks) but IMO a larger chunk of it is due to inadequate/missing documentation.Sizeable
ERROR: expected '='Combustion
The export command worked as expected, thanks. Friendly reminder: some users may need to call "ulimit -c unlimited" as well.Shaeshaef
@SantiagoVillafuerte Oh, right, thanks for the tip. Added to answer.Sizeable

© 2022 - 2024 — McMap. All rights reserved.