Пример #1
0
// Capture "golden" stack trace with default-configured Symbolizer
void ElfCacheTest::SetUp() {
  bar();
  Symbolizer symbolizer;
  symbolizer.symbolize(goldenFrames);
  // At least 3 stack frames from us + getStackTrace()
  ASSERT_LE(4, goldenFrames.frameCount);
}
Пример #2
0
std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
  out << "Exception type: ";
  if (info.type) {
    out << folly::demangle(*info.type);
  } else {
    out << "(unknown type)";
  }
  out << " (" << info.frames.size()
      << (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;

    if (frameCount > skip) {
      auto addresses = info.frames.data() + skip;
      frameCount -= skip;

      std::vector<SymbolizedFrame> frames;
      frames.resize(frameCount);

      Symbolizer symbolizer;
      symbolizer.symbolize(addresses, frames.data(), frameCount);

      OStreamSymbolizePrinter osp(out);
      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;
}
Пример #3
0
std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
  out << "Exception type: ";
  if (info.type) {
    out << folly::demangle(*info.type);
  } else {
    out << "(unknown type)";
  }
  out << " (" << info.frames.size()
      << (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);
    }
  } catch (const std::exception& e) {
    out << "\n !! caught " << folly::exceptionStr(e) << "\n";
  } catch (...) {
    out << "\n !!! caught unexpected exception\n";
  }
  return out;
}
Пример #4
0
int main(int argc, char *argv[]) {
    google::InitGoogleLogging(argv[0]);
    Symbolizer s;
    StringPiece name;
    Dwarf::LocationInfo location;
    CHECK(s.symbolize(reinterpret_cast<uintptr_t>(main), name, location));
    LOG(INFO) << name << " " << location.file << " " << location.line << " ("
              << location.mainFile << ")";
    return 0;
}
Пример #5
0
TEST(Symbolizer, Single) {
  Symbolizer symbolizer;
  SymbolizedFrame a;
  ASSERT_TRUE(symbolizer.symbolize(reinterpret_cast<uintptr_t>(foo), a));
  EXPECT_EQ("folly::symbolizer::test::foo()", a.demangledName());

  auto path = a.location.file.toString();
  folly::StringPiece basename(path);
  auto pos = basename.rfind('/');
  if (pos != folly::StringPiece::npos) {
    basename.advance(pos + 1);
  }
  EXPECT_EQ("SymbolizerTest.cpp", basename.str());
}
Пример #6
0
void runElfCacheTest(Symbolizer& symbolizer) {
    FrameArray<100> frames = goldenFrames;
    for (size_t i = 0; i < frames.frameCount; ++i) {
        frames.frames[i].clear();
    }
    symbolizer.symbolize(frames);
    ASSERT_LE(4, frames.frameCount);
    for (size_t i = 1; i < 4; ++i) {
        EXPECT_STREQ(goldenFrames.frames[i].name, frames.frames[i].name);
    }
}
Пример #7
0
void MemoryManager::refreshStatsHelperExceeded() {
#ifdef FACEBOOK
  if (RuntimeOption::LogNativeStackOnOOM) {
    using namespace folly::symbolizer;
    constexpr size_t kMaxFrames = 128;

    uintptr_t addresses[kMaxFrames];
    auto nframes = getStackTrace(addresses, kMaxFrames);
    std::vector<SymbolizedFrame> frames(nframes);
    Symbolizer symbolizer;
    symbolizer.symbolize(addresses, frames.data(), nframes);
    StringSymbolizePrinter printer;
    printer.println(addresses, frames.data(), nframes);
    Logger::Error("Exceeded memory limit\n\nC++ stack:\n%s",
                  printer.str().c_str());
  }
#endif
  ThreadInfo* info = ThreadInfo::s_threadInfo.getNoCheck();
  info->m_reqInjectionData.setMemExceededFlag();
  m_couldOOM = false;
}
Пример #8
0
TEST(Symbolizer, Single) {
    Symbolizer symbolizer;
    SymbolizedFrame a;
    ASSERT_TRUE(symbolizer.symbolize(reinterpret_cast<uintptr_t>(foo), a));
    EXPECT_EQ("folly::symbolizer::test::foo()", a.demangledName());

    // The version of clang we use doesn't generate a `.debug_aranges` section,
    // which the symbolizer needs to lookup the filename.
    constexpr bool built_with_clang =
#ifdef __clang__
        true;
#else
        false;
#endif
    if (!built_with_clang) {
        auto path = a.location.file.toString();
        folly::StringPiece basename(path);
        auto pos = basename.rfind('/');
        if (pos != folly::StringPiece::npos) {
            basename.advance(pos + 1);
        }
        EXPECT_EQ("SymbolizerTest.cpp", basename.str());
    }
}