How to generate core dump when use Address Sanitizer and gcc7.1.0

4.9k views Asked by At

I compiled my code with -fsanitize=address on centOS 7.2.1511. When I updated gcc to 7.1.0, it can't generate core dump file anymore. Can anybody help me?

gcc compile options:

-lm -g3 -Wall -Wno-unknown-pragmas --std=c++11 -Werror -ggdb -fsanitize=address -fno-omit-frame-pointer -D_GLIBCXX_USE_CXX11_ABI=0

link options:

-lxml2 -lpthread -lmysqlclient -L/usr/lib64/mysql/ -llog4cxx -lprotobuf -llua -lluabind -lhiredis -lcrypto -lcurl -ljsoncpp -Wl,-E -fsanitize=address -ldl

When I used gcc 4.8.5, core dump was normally generated with the option ASAN_OPTIONS set like this:

export ASAN_OPTIONS="disable_core=0:unmap_shadow_on_exit=1:abort_on_error=1"

When I updated gcc to 7.1.0, core dump can't generate anymore, even if the ASAN_OPTIONS is set like above.

2

There are 2 answers

0
WenJuan Wu On

Problem is solved.The new sanitizer option ASAN_OPTIONS should be set is "disable_coredump",I set it like this:

ASAN_OPTIONS="disable_coredump=0:unmap_shadow_on_exit=1:abort_on_error=1"
3
ulidtko On

Well, in theory it should've worked like this:

  1. ulimit -c unlimited of course (optionally adjust sysctl kernel.core_pattern)
  2. export ASAN_OPTIONS=disable_coredump=0,abort_on_error=1
  3. run, obtain the core (ideally, if all works).

However, I've tried quite a few more combinations of disable_coredump=0, halt_on_error=1, abort_on_error=1, handle_abort=0 -- all I got each time was just an annoying ASAN error (@ LLVM 8, commit 1473e85213404eccb4d018d41c24d2f5834f81b5):

nested bug in the same thread, aborting.

and exit code 1 (no core). From what little glimpses at the source that I've taken, it seems that asan handles that same SIGABRT that it emitted, but interpreting that as a crash-while-handling-a-crash. Not quite exactly what -help said; a thing to improve, perhaps.


Still, I was able to circumvent this itchy-bitchy error handling with one more option:

ASAN_OPTIONS+=:sleep_before_dying=150

and then, when it sleeped as instructed, hit ^\ in the terminal (Ctrl\, the equivalent of kill -QUIT).

That, finally, produced the core file I've been trying to get.