[ubsan] Simplify ubsan_GetStackTrace

Suggested by Vitaly Buka
This commit is contained in:
Fangrui Song 2022-04-13 00:32:10 -07:00
parent b0343a38a5
commit 63f2d1f4d4
2 changed files with 8 additions and 13 deletions

View File

@ -32,13 +32,9 @@ using namespace __ubsan;
// Windows.
// TODO(yln): This is a temporary workaround. GetStackTrace functions will be
// removed in the future.
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth, uptr pc,
uptr bp, void *context, bool request_fast) {
uptr top = 0;
uptr bottom = 0;
GetThreadStackTopAndBottom(false, &top, &bottom);
bool fast = StackTrace::WillUseFastUnwind(request_fast);
stack->Unwind(max_depth, pc, bp, context, top, bottom, fast);
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr pc, uptr bp,
void *context, bool request_fast) {
stack->Unwind(pc, bp, context, request_fast);
}
static void MaybePrintStackTrace(uptr pc, uptr bp) {
@ -48,8 +44,8 @@ static void MaybePrintStackTrace(uptr pc, uptr bp) {
return;
BufferedStackTrace stack;
ubsan_GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr,
common_flags()->fast_unwind_on_fatal);
ubsan_GetStackTrace(&stack, pc, bp, nullptr,
common_flags()->fast_unwind_on_fatal);
stack.Print();
}

View File

@ -38,15 +38,14 @@ void InitializeDeadlySignals() {}
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
// TODO(yln): Temporary workaround. Will be removed.
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
uptr pc, uptr bp, void *context, bool fast);
void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr pc, uptr bp,
void *context, bool fast);
namespace __ubsan {
static void OnStackUnwind(const SignalContext &sig, const void *,
BufferedStackTrace *stack) {
ubsan_GetStackTrace(stack, kStackTraceMax,
StackTrace::GetNextInstructionPc(sig.pc), sig.bp,
ubsan_GetStackTrace(stack, StackTrace::GetNextInstructionPc(sig.pc), sig.bp,
sig.context, common_flags()->fast_unwind_on_fatal);
}