diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-12-18 09:57:34 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-12-18 09:57:34 +0000 |
commit | f37c45c20d82aead845bebe52abf68024ed48286 (patch) | |
tree | 21576380216e8e7e8506b97b7f8b40ab3d6c47a2 | |
parent | 7e45562ad038040418774e830deb7210f78a4426 (diff) | |
download | bcm5719-llvm-f37c45c20d82aead845bebe52abf68024ed48286.tar.gz bcm5719-llvm-f37c45c20d82aead845bebe52abf68024ed48286.zip |
[Sanitizer] Expose StackTrace::GetPreviousInstructionPc() to get PC of call instruction from return address
llvm-svn: 170424
4 files changed, 10 insertions, 12 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc index 7525895ab83..109a674e45b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -25,10 +25,7 @@ static const char *StripPathPrefix(const char *filepath, } // ----------------------- StackTrace ----------------------------- {{{1 -// PCs in stack traces are actually the return addresses, that is, -// addresses of the next instructions after the call. That's why we -// decrement them. -static uptr patch_pc(uptr pc) { +uptr StackTrace::GetPreviousInstructionPc(uptr pc) { #ifdef __arm__ // Cancel Thumb bit. pc = pc & (~1); @@ -71,7 +68,9 @@ void StackTrace::PrintStack(const uptr *addr, uptr size, InternalScopedBuffer<AddressInfo> addr_frames(64); uptr frame_num = 0; for (uptr i = 0; i < size && addr[i]; i++) { - uptr pc = patch_pc(addr[i]); + // PCs in stack traces are actually the return addresses, that is, + // addresses of the next instructions after the call. + uptr pc = GetPreviousInstructionPc(addr[i]); uptr addr_frames_num = 0; // The number of stack frames for current // instruction address. if (symbolize_callback) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h index 90ad31f1f66..597d24fd067 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -49,6 +49,7 @@ struct StackTrace { void PopStackFrames(uptr count); static uptr GetCurrentPc(); + static uptr GetPreviousInstructionPc(uptr pc); static uptr CompressStack(StackTrace *stack, u32 *compressed, uptr size); diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index 239aa27c748..b0dedda6afe 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -177,8 +177,8 @@ ScopedInterceptor::~ScopedInterceptor() { StatInc(thr, StatInt_##func); \ const uptr caller_pc = GET_CALLER_PC(); \ ScopedInterceptor si(thr, #func, caller_pc); \ - /* Subtract one from pc as we need current instruction address */ \ - const uptr pc = __sanitizer::StackTrace::GetCurrentPc() - 1; \ + const uptr pc = __sanitizer::StackTrace::GetPreviousInstructionPc( \ + __sanitizer::StackTrace::GetCurrentPc()); \ (void)pc; \ /**/ diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cc b/compiler-rt/lib/ubsan/ubsan_diag.cc index 517ce6b68b3..a726f4b55d9 100644 --- a/compiler-rt/lib/ubsan/ubsan_diag.cc +++ b/compiler-rt/lib/ubsan/ubsan_diag.cc @@ -24,13 +24,11 @@ Location __ubsan::getCallerLocation(uptr CallerLoc) { if (!CallerLoc) return Location(); - // Adjust to find the call instruction. - // FIXME: This is not portable. - --CallerLoc; + uptr Loc = StackTrace::GetPreviousInstructionPc(CallerLoc); AddressInfo Info; - if (!SymbolizeCode(CallerLoc, &Info, 1) || !Info.module || !*Info.module) - return Location(CallerLoc); + if (!SymbolizeCode(Loc, &Info, 1) || !Info.module || !*Info.module) + return Location(Loc); if (!Info.function) return ModuleLocation(Info.module, Info.module_offset); |