/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-
-#include "folly/experimental/exception_tracer/ExceptionTracer.h"
+#include <folly/experimental/exception_tracer/ExceptionTracer.h>
#include <dlfcn.h>
#include <exception>
#include <iostream>
#include <glog/logging.h>
-#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 <folly/experimental/exception_tracer/ExceptionAbi.h>
+#include <folly/experimental/exception_tracer/StackTrace.h>
+#include <folly/experimental/symbolizer/Symbolizer.h>
+#include <folly/String.h>
namespace {
using namespace __cxxabiv1;
extern "C" {
-StackTraceStack* getExceptionStackTraceStack(void) __attribute__((weak));
+StackTraceStack* getExceptionStackTraceStack(void) __attribute__((__weak__));
typedef StackTraceStack* (*GetExceptionStackTraceStackType)(void);
GetExceptionStackTraceStackType getExceptionStackTraceStackFn;
}
namespace exception_tracer {
std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
+ printExceptionInfo(out, info, SymbolizePrinter::COLOR_IF_TTY);
+ return out;
+}
+
+void printExceptionInfo(
+ std::ostream& out,
+ const ExceptionInfo& info,
+ int options) {
out << "Exception type: ";
if (info.type) {
out << folly::demangle(*info.type);
<< (info.frames.size() == 1 ? " frame" : " frames")
<< ")\n";
try {
- ssize_t frameCount = info.frames.size();
- // Skip our own internal frames
- static constexpr size_t skip = 3;
+ size_t frameCount = info.frames.size();
- if (frameCount > skip) {
- auto addresses = info.frames.data() + skip;
- frameCount -= skip;
+ // Skip our own internal frames
+ static constexpr size_t kInternalFramesNumber = 3;
+ if (frameCount > kInternalFramesNumber) {
+ auto addresses = info.frames.data() + kInternalFramesNumber;
+ frameCount -= kInternalFramesNumber;
std::vector<SymbolizedFrame> frames;
frames.resize(frameCount);
- Symbolizer symbolizer;
+ Symbolizer symbolizer(
+ (options & SymbolizePrinter::NO_FILE_AND_LINE)
+ ? Dwarf::LocationInfoMode::DISABLED
+ : Symbolizer::kDefaultLocationInfoMode);
symbolizer.symbolize(addresses, frames.data(), frameCount);
- OStreamSymbolizePrinter osp(out);
- osp.print(addresses, frames.data(), frameCount);
+ OStreamSymbolizePrinter osp(out, options);
+ osp.println(addresses, frames.data(), frameCount);
}
} catch (const std::exception& e) {
out << "\n !! caught " << folly::exceptionStr(e) << "\n";
} catch (...) {
out << "\n !!! caught unexpected exception\n";
}
- return out;
}
namespace {
} // namespace exception_tracer
} // namespace folly
-