backtrace.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <util/generic/array_ref.h>
  3. #include <util/generic/maybe.h>
  4. #include <util/generic/string.h>
  5. #include <util/generic/vector.h>
  6. #include <functional>
  7. namespace NDwarf {
  8. struct TLineInfo {
  9. TString FileName;
  10. int Line;
  11. int Col;
  12. TString FunctionName;
  13. uintptr_t Address;
  14. int Index;
  15. };
  16. struct TError {
  17. int Code;
  18. TString Message;
  19. };
  20. enum class EResolving {
  21. Continue = 0,
  22. Break = 1,
  23. };
  24. using TCallback = std::function<EResolving(const TLineInfo&)>;
  25. // Resolves backtrace addresses and calls the callback for all line infos of inlined functions there.
  26. // Stops execution if the callback returns `EResolving::Break`.
  27. [[nodiscard]] TMaybe<TError> ResolveBacktrace(TArrayRef<const void* const> backtrace, TCallback callback);
  28. // Same as `ResolveBacktrace` but uses a separate single-threaded `backtrace_state` protected by a static mutex.
  29. //
  30. // libbacktrace may leak memory when used concurrently even with the `threaded` option set to 1,
  31. // which is explicitly stated in its source code (contrib/libs/backtrace/dwarf.c:dwarf_lookup_pc,
  32. // contrib/libs/backtrace/fileline.c:fileline_initialize) and confirmed in MAPSBKOFCT-1959.
  33. [[nodiscard]] TMaybe<TError> ResolveBacktraceLocked(TArrayRef<const void* const> backtrace, TCallback callback);
  34. }