This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix/workaround for OS X truncated stacktraces taken by external tools
ClosedPublic

Authored by kubamracek on Jan 21 2015, 11:17 AM.

Details

Reviewers
glider
Summary

This patch is a proposed solution for https://code.google.com/p/address-sanitizer/issues/detail?id=375:

When the stacktraces are captured and printed by ASan itself, they are fine, but when the program has already printed the report (or is just printing it), capturing a stacktrace via other means is broken. "Other means" include OS X CrashReporter, debuggers or calling backtrace() within the program. For example calling backtrace() from a sanitizer_set_death_callback function prints a very truncated stacktrace:

0   crashlog-stacktraces.c.tmp          0x000000010fb1c397 death_function + 471
1   libclang_rt.asan_osx_dynamic.dylib  0x000000010fb72c1f _ZN11__sanitizer3DieEv + 15

The same can happen even within lldb (I'm seeing this for 32-bit x86):

(lldb) bt
* thread #1: tid = 0x9ec2d, 0x0000209a crashlog-stacktraces.c.tmp`death_function + 42 at crashlog-stacktraces.c:10, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x0000209a crashlog-stacktraces.c.tmp`death_function + 42 at crashlog-stacktraces.c:10
    frame #1: 0x0005eaf6 libclang_rt.asan_osx_dynamic.dylib`__sanitizer::Die() + 22
    frame #2: 0x00058136 libclang_rt.asan_osx_dynamic.dylib`__asan::ScopedInErrorReport::~ScopedInErrorReport() + 102
    frame #3: 0x00057fcf libclang_rt.asan_osx_dynamic.dylib`__asan::ScopedInErrorReport::~ScopedInErrorReport() + 15
    frame #4: 0x00057acc libclang_rt.asan_osx_dynamic.dylib`__asan_report_error + 4204
(lldb)

This patch forces __asan_report_error to always have a stack frame by using the ENABLE_FRAME_POINTER macro, which we are already using elsewhere (asan_mac.cc).

Diff Detail

Event Timeline

kubamracek retitled this revision from to [compiler-rt] Fix/workaround for OS X truncated stacktraces taken by external tools.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added subscribers: Unknown Object (MLST), kcc, glider, samsonov.

Adding the testcase into the patch.

glider accepted this revision.Jan 22 2015, 5:53 AM
glider added a reviewer: glider.
This revision is now accepted and ready to land.Jan 22 2015, 5:53 AM
kubamracek closed this revision.Jan 22 2015, 3:38 PM

Landed in r226878.