1 #pragma once 2 #include <c10/macros/Export.h> 3 #include <cstdint> 4 #include <optional> 5 #include <string> 6 #include <vector> 7 8 namespace torch::unwind { 9 // gather current stack, relatively fast. 10 // gets faster once the cache of program counter locations is warm. 11 TORCH_API std::vector<void*> unwind(); 12 13 struct Frame { 14 std::string filename; 15 std::string funcname; 16 uint64_t lineno; 17 }; 18 19 enum class Mode { addr2line, fast, dladdr }; 20 21 // note: symbolize is really slow 22 // it will launch an addr2line process that has to parse dwarf 23 // information from the libraries that frames point into. 24 // Callers should first batch up all the unique void* pointers 25 // across a number of unwind states and make a single call to 26 // symbolize. 27 TORCH_API std::vector<Frame> symbolize( 28 const std::vector<void*>& frames, 29 Mode mode); 30 31 // returns path to the library, and the offset of the addr inside the library 32 TORCH_API std::optional<std::pair<std::string, uint64_t>> libraryFor( 33 void* addr); 34 35 struct Stats { 36 size_t hits = 0; 37 size_t misses = 0; 38 size_t unsupported = 0; 39 size_t resets = 0; 40 }; 41 Stats stats(); 42 43 } // namespace torch::unwind 44