struct __cxa_exception {
std::type_info* exceptionType;
- void (*exceptionDestructor) (void*);
+ void (*exceptionDestructor)(void*);
std::unexpected_handler unexpectedHandler;
std::terminate_handler terminateHandler;
__cxa_exception* nextException;
result.push_back(std::move(item.second));
}
- std::sort(result.begin(),
- result.end(),
- [](const ExceptionStats& lhs, const ExceptionStats& rhs) {
- return lhs.count > rhs.count;
- });
+ std::sort(
+ result.begin(),
+ result.end(),
+ [](const ExceptionStats& lhs, const ExceptionStats& rhs) {
+ return lhs.count > rhs.count;
+ });
return result;
}
}
struct Initializer {
- Initializer() { registerCxaThrowCallback(throwHandler); }
+ Initializer() {
+ registerCxaThrowCallback(throwHandler);
+ }
};
Initializer initializer;
out << "(unknown type)";
}
out << " (" << info.frames.size()
- << (info.frames.size() == 1 ? " frame" : " frames")
- << ")\n";
+ << (info.frames.size() == 1 ? " frame" : " frames") << ")\n";
try {
size_t frameCount = info.frames.size();
bool isAbiCppException(const __cxa_exception* exc) {
// The least significant four bytes must be "C++\0"
static const uint64_t cppClass =
- ((uint64_t)'C' << 24) |
- ((uint64_t)'+' << 16) |
- ((uint64_t)'+' << 8);
+ ((uint64_t)'C' << 24) | ((uint64_t)'+' << 16) | ((uint64_t)'+' << 8);
return (exc->unwindHeader.exception_class & 0xffffffff) == cppClass;
}
if (!getExceptionStackTraceStackFn) {
// Nope, see if it's in a shared library
- getExceptionStackTraceStackFn =
- (GetExceptionStackTraceStackType)dlsym(
- RTLD_NEXT, "getExceptionStackTraceStack");
+ getExceptionStackTraceStackFn = (GetExceptionStackTraceStackType)dlsym(
+ RTLD_NEXT, "getExceptionStackTraceStack");
}
}
};
static bool logged = false;
if (!logged) {
LOG(WARNING)
- << "Exception tracer library not linked, stack traces not available";
+ << "Exception tracer library not linked, stack traces not available";
logged = true;
}
} else if ((traceStack = getExceptionStackTraceStackFn()) == nullptr) {
static bool logged = false;
if (!logged) {
LOG(WARNING)
- << "Exception stack trace invalid, stack traces not available";
+ << "Exception stack trace invalid, stack traces not available";
logged = true;
}
}
// standard ABI __cxa_exception objects, and are correctly labeled as
// such in the exception_class field. We could try to extract the
// primary exception type in horribly hacky ways, but, for now, nullptr.
- info.type =
- isAbiCppException(currentException) ?
- currentException->exceptionType :
- nullptr;
+ info.type = isAbiCppException(currentException)
+ ? currentException->exceptionType
+ : nullptr;
if (traceStack) {
LOG_IF(DFATAL, !trace)
// The values in frames are IP (instruction pointer) addresses.
// They are only filled if the low-level exception tracer library is
// linked in or LD_PRELOADed.
- std::vector<uintptr_t> frames; // front() is top of stack
+ std::vector<uintptr_t> frames; // front() is top of stack
};
void printExceptionInfo(
class CallbackHolder {
public:
void registerCallback(Function f) {
- SYNCHRONIZED(callbacks_) { callbacks_.push_back(std::move(f)); }
+ SYNCHRONIZED(callbacks_) {
+ callbacks_.push_back(std::move(f));
+ }
}
// always inline to enforce kInternalFramesNumber
// calls need to go away. Everything else is messy though, so just
// #define it to an empty macro under Clang and be done with it.
#ifdef __clang__
-# define __builtin_unreachable()
+#define __builtin_unreachable()
#endif
namespace __cxxabiv1 {
-void __cxa_throw(void* thrownException,
- std::type_info* type,
- void (*destructor)(void*)) {
+void __cxa_throw(
+ void* thrownException,
+ std::type_info* type,
+ void (*destructor)(void*)) {
static auto orig_cxa_throw =
reinterpret_cast<decltype(&__cxa_throw)>(dlsym(RTLD_NEXT, "__cxa_throw"));
getCxaThrowCallbacks().invoke(thrownException, type, destructor);
// TODO(tudorb): Dicey, as it relies on the fact that std::exception_ptr
// is typedef'ed to a type in namespace __exception_ptr
static auto orig_rethrow_exception =
- reinterpret_cast<decltype(&rethrow_exception)>(
- dlsym(RTLD_NEXT,
- "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE"));
+ reinterpret_cast<decltype(&rethrow_exception)>(dlsym(
+ RTLD_NEXT,
+ "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE"));
getRethrowExceptionCallbacks().invoke(ep);
orig_rethrow_exception(ep);
__builtin_unreachable(); // orig_rethrow_exception never returns
#include <folly/experimental/symbolizer/StackTrace.h>
-namespace folly { namespace exception_tracer {
+namespace folly {
+namespace exception_tracer {
class StackTraceStack::Node : public StackTrace {
public:
Node* next;
private:
- Node() : next(nullptr) { }
- ~Node() { }
+ Node() : next(nullptr) {}
+ ~Node() {}
};
auto StackTraceStack::Node::allocate() -> Node* {
assert(p);
return static_cast<Node*>(p)->next;
}
-
-}} // namespaces
+} // namespace exception_tracer
+} // namespace folly
#include <cstddef>
#include <cstdint>
-namespace folly { namespace exception_tracer {
+namespace folly {
+namespace exception_tracer {
constexpr size_t kMaxFrames = 500;
struct StackTrace {
- StackTrace() : frameCount(0) { }
+ StackTrace() : frameCount(0) {}
size_t frameCount;
uintptr_t addresses[kMaxFrames];
// A StackTraceStack MUST be placed in zero-initialized memory.
class StackTraceStack {
class Node;
+
public:
/**
* Push the current stack trace onto the stack.
/**
* Is the stack empty?
*/
- bool empty() const { return !top_; }
+ bool empty() const {
+ return !top_;
+ }
/**
* Return the top stack trace, or nullptr if the stack is empty.
uintptr_t guard2_;
#endif
};
-
-}} // namespaces
+} // namespace exception_tracer
+} // namespace folly
{
std::unique_lock<std::mutex> lock(preparedMutex);
- preparedBarrier.wait(lock,
- [&]() { return preparedThreads == kNumThreads; });
+ preparedBarrier.wait(
+ lock, [&]() { return preparedThreads == kNumThreads; });
}
auto stats = getExceptionStatistics();
throw std::runtime_error("");
}
recurse(level - 1);
- folly::doNotOptimizeAway(0); // prevent tail recursion
+ folly::doNotOptimizeAway(0); // prevent tail recursion
}
void loop(int iters) {
constexpr size_t kNumThreads = 10;
threads.resize(10);
for (auto& t : threads) {
- t = std::thread([iters] () { loop(iters); });
+ t = std::thread([iters]() { loop(iters); });
}
for (auto& t : threads) {
t.join();