13

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?

ks1322
  • 33,961
  • 14
  • 109
  • 164
wsy
  • 219
  • 4
  • 8

1 Answers1

30

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).

For complete list of flags you can see Asan wiki.

Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
yugr
  • 19,769
  • 3
  • 51
  • 96
  • 3
    This is the only place on the net that I could find the correct answer for my 64-bit system. Thank you! – the_endian May 12 '20 at 04:56
  • @the_endian 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. – yugr May 12 '20 at 15:07
  • `ERROR: expected '='` – ar2015 May 23 '20 at 03:59