set_format_backtrace.cpp 781 B

123456789101112131415161718
  1. #include <library/cpp/dwarf_backtrace/backtrace.h>
  2. #include <util/stream/format.h>
  3. #include <util/system/backtrace.h>
  4. namespace {
  5. void PrintDwarfBacktrace(IOutputStream* out, void* const* backtrace, size_t size) {
  6. auto error = NDwarf::ResolveBacktrace({backtrace, size}, [out](const NDwarf::TLineInfo& info) {
  7. *out << info.FileName << ":" << info.Line << ":" << info.Col
  8. << " in " << info.FunctionName << " (" << Hex(info.Address, HF_ADDX) << ')' << Endl;
  9. return NDwarf::EResolving::Continue;
  10. });
  11. if (error) {
  12. *out << "***Cannot get backtrace: " << error->Message << " (" << error->Code << ")***" << Endl;
  13. }
  14. }
  15. [[maybe_unused]] auto _ = SetFormatBackTraceFn(&PrintDwarfBacktrace);
  16. }