Skip to content

Commit 4ce918e

Browse files
committedMar 5, 2019
[NFC][Sanitizer] Cleanup ASan's GetStackTrace implementation
Cleanup ASan's __sanitizer::BufferedStackTrace::UnwindImpl (formerly GetStackTrace) implementation. Start with ASan because it is the most complex implementation. GetStackTrace implementations seem to have started out as exact copies of the original implementation in ASan, but have diverged in subtle ways. My goal is to parameterize this algorithm (via templating or callbacks) so we can share the implementation and get rid of the inversed dependency (sanitizer_common depends on concrete implementations in asan, ubsan, etc.). This should also help us to avoid those pesky linker errors caused by undefined, duplicate, and weak symbols on Windows. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D58861 llvm-svn: 355355
1 parent c2b3f62 commit 4ce918e

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed
 

‎compiler-rt/lib/asan/asan_stack.cc

+14-19
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,23 @@ u32 GetMallocContextSize() {
3131
void __sanitizer::BufferedStackTrace::UnwindImpl(
3232
uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
3333
using namespace __asan;
34-
#if SANITIZER_WINDOWS
35-
Unwind(max_depth, pc, 0, context, 0, 0, false);
36-
#else
37-
AsanThread *t;
3834
size = 0;
39-
if (LIKELY(asan_inited)) {
40-
if ((t = GetCurrentThread()) && !t->isUnwinding()) {
41-
uptr stack_top = t->stack_top();
42-
uptr stack_bottom = t->stack_bottom();
43-
ScopedUnwinding unwind_scope(t);
44-
if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) {
45-
if (StackTrace::WillUseFastUnwind(request_fast))
46-
Unwind(max_depth, pc, bp, nullptr, stack_top, stack_bottom, true);
47-
else
48-
Unwind(max_depth, pc, 0, context, 0, 0, false);
49-
}
50-
} else if (!t && !request_fast) {
51-
/* If GetCurrentThread() has failed, try to do slow unwind anyways. */
52-
Unwind(max_depth, pc, bp, context, 0, 0, false);
35+
if (UNLIKELY(!asan_inited)) return;
36+
37+
AsanThread *t = GetCurrentThread();
38+
if (t && !t->isUnwinding() && WillUseFastUnwind(request_fast)) {
39+
uptr top = t->stack_top();
40+
uptr bottom = t->stack_bottom();
41+
ScopedUnwinding unwind_scope(t);
42+
if (!SANITIZER_MIPS || IsValidFrame(bp, top, bottom)) {
43+
UnwindFast(pc, bp, top, bottom, max_depth);
44+
return;
5345
}
5446
}
55-
#endif // SANITIZER_WINDOWS
47+
48+
#if SANITIZER_CAN_SLOW_UNWIND
49+
UnwindSlowWithOptionalContext(pc, context, max_depth);
50+
#endif
5651
}
5752

5853
// ------------------ Interface -------------- {{{1

‎compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ struct BufferedStackTrace : public StackTrace {
134134
void UnwindSlow(uptr pc, u32 max_depth);
135135
void UnwindSlow(uptr pc, void *context, u32 max_depth);
136136

137+
void UnwindSlowWithOptionalContext(uptr pc, void *context, u32 max_depth) {
138+
if (context) UnwindSlow(pc, context, max_depth);
139+
else UnwindSlow(pc, max_depth);
140+
}
141+
137142
void PopStackFrames(uptr count);
138143
uptr LocatePcInTrace(uptr pc);
139144

0 commit comments

Comments
 (0)
Please sign in to comment.