[ubsan] Extract GetStackTraceWithPcBpAndContext similar to asan version

llvm-svn: 313350
This commit is contained in:
Vitaly Buka 2017-09-15 08:11:53 +00:00
parent 6188f326eb
commit 5fbd91df56
2 changed files with 16 additions and 8 deletions

View File

@ -26,21 +26,25 @@
using namespace __ubsan;
void __ubsan::GetStackTraceWithPcBpAndContext(BufferedStackTrace *stack,
uptr max_depth, uptr pc, uptr bp,
void *context, bool fast) {
uptr top = 0;
uptr bottom = 0;
if (fast)
GetThreadStackTopAndBottom(false, &top, &bottom);
stack->Unwind(max_depth, pc, bp, context, top, bottom, fast);
}
static void MaybePrintStackTrace(uptr pc, uptr bp) {
// We assume that flags are already parsed, as UBSan runtime
// will definitely be called when we print the first diagnostics message.
if (!flags()->print_stacktrace)
return;
uptr top = 0;
uptr bottom = 0;
bool request_fast_unwind = common_flags()->fast_unwind_on_fatal;
if (request_fast_unwind)
__sanitizer::GetThreadStackTopAndBottom(false, &top, &bottom);
BufferedStackTrace stack;
stack.Unwind(kStackTraceMax, pc, bp, nullptr, top, bottom,
request_fast_unwind);
GetStackTraceWithPcBpAndContext(&stack, kStackTraceMax, pc, bp, nullptr,
common_flags()->fast_unwind_on_fatal);
stack.Print();
}

View File

@ -231,6 +231,10 @@ bool ignoreReport(SourceLocation SLoc, ReportOptions Opts, ErrorType ET);
GET_CALLER_PC_BP; \
ReportOptions Opts = {unrecoverable_handler, pc, bp}
void GetStackTraceWithPcBpAndContext(BufferedStackTrace *stack, uptr max_depth,
uptr pc, uptr bp, void *context,
bool fast);
/// \brief Instantiate this class before printing diagnostics in the error
/// report. This class ensures that reports from different threads and from
/// different sanitizers won't be mixed.