X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2Fexception_tracer%2FExceptionTracer.cpp;h=c4e3b8503d4b6c144fa86785f8a7ae345e13a774;hb=7ffe7766f032914384aa6e0b9598bab7d9a90602;hp=82e18639a7e338efd04c46cb22decc3de4b6b144;hpb=6b4082ec2603c63cde2e33fb2c94e5a2ef9a8aa8;p=folly.git diff --git a/folly/experimental/exception_tracer/ExceptionTracer.cpp b/folly/experimental/exception_tracer/ExceptionTracer.cpp index 82e18639..c4e3b850 100644 --- a/folly/experimental/exception_tracer/ExceptionTracer.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Facebook, Inc. + * Copyright 2014 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,31 +14,33 @@ * limitations under the License. */ - -#include "folly/experimental/exception_tracer/ExceptionTracer.h" +#include #include #include +#include #include -#include "folly/experimental/exception_tracer/ExceptionAbi.h" -#include "folly/experimental/exception_tracer/StackTrace.h" -#include "folly/experimental/symbolizer/Symbolizer.h" -#include "folly/String.h" +#include +#include +#include +#include namespace { +using namespace ::folly::exception_tracer; +using namespace ::folly::symbolizer; +using namespace __cxxabiv1; + extern "C" { -const StackTraceStack* getExceptionStackTraceStack(void) __attribute__((weak)); -typedef const StackTraceStack* (*GetExceptionStackTraceStackType)(void); +StackTraceStack* getExceptionStackTraceStack(void) __attribute__((__weak__)); +typedef StackTraceStack* (*GetExceptionStackTraceStackType)(void); GetExceptionStackTraceStackType getExceptionStackTraceStackFn; } } // namespace -using namespace ::facebook::symbolizer; -using namespace __cxxabiv1; - +namespace folly { namespace exception_tracer { std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) { @@ -52,14 +54,22 @@ std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) { << (info.frames.size() == 1 ? " frame" : " frames") << ")\n"; try { - Symbolizer symbolizer; - folly::StringPiece symbolName; - Dwarf::LocationInfo location; - for (auto ip : info.frames) { - // Symbolize the previous address because the IP might be in the - // next function, per glog/src/signalhandler.cc - symbolizer.symbolize(ip-1, symbolName, location); - Symbolizer::write(out, ip, symbolName, location); + size_t frameCount = info.frames.size(); + // Skip our own internal frames + static constexpr size_t skip = 3; + + if (frameCount > skip) { + auto addresses = info.frames.data() + skip; + frameCount -= skip; + + std::vector frames; + frames.resize(frameCount); + + Symbolizer symbolizer; + symbolizer.symbolize(addresses, frames.data(), frameCount); + + OStreamSymbolizePrinter osp(out, SymbolizePrinter::COLOR_IF_TTY); + osp.println(addresses, frames.data(), frameCount); } } catch (const std::exception& e) { out << "\n !! caught " << folly::exceptionStr(e) << "\n"; @@ -112,8 +122,7 @@ std::vector getCurrentExceptions() { return exceptions; } - bool hasTraceStack = false; - const StackTraceStack* traceStack = nullptr; + StackTraceStack* traceStack = nullptr; if (!getExceptionStackTraceStackFn) { static bool logged = false; if (!logged) { @@ -128,10 +137,9 @@ std::vector getCurrentExceptions() { << "Exception stack trace invalid, stack traces not available"; logged = true; } - } else { - hasTraceStack = true; } + StackTrace* trace = traceStack ? traceStack->top() : nullptr; while (currentException) { ExceptionInfo info; // Dependent exceptions (thrown via std::rethrow_exception) aren't @@ -142,18 +150,16 @@ std::vector getCurrentExceptions() { isAbiCppException(currentException) ? currentException->exceptionType : nullptr; - if (hasTraceStack) { - CHECK(traceStack) << "Invalid trace stack!"; - info.frames.assign( - traceStack->trace.frameIPs, - traceStack->trace.frameIPs + traceStack->trace.frameCount); - traceStack = traceStack->next; + if (traceStack) { + CHECK(trace) << "Invalid trace stack!"; + info.frames.assign(trace->addresses, + trace->addresses + trace->frameCount); + trace = traceStack->next(trace); } currentException = currentException->nextException; exceptions.push_back(std::move(info)); } - - CHECK(!traceStack) << "Invalid trace stack!"; + CHECK(!trace) << "Invalid trace stack!"; return exceptions; } @@ -198,4 +204,4 @@ void installHandlers() { } } // namespace exception_tracer - +} // namespace folly