| 44 | { |
| 45 | |
| 46 | PDAL_EXPORT std::vector<std::string> Utils::backtrace() |
| 47 | { |
| 48 | std::vector<std::string> lines; |
| 49 | BacktraceEntries entries = backtraceImpl(); |
| 50 | |
| 51 | // Remove the frame for the unwinding itself. |
| 52 | if (entries.size()) |
| 53 | entries.pop_front(); |
| 54 | |
| 55 | size_t maxLibnameLen(0); |
| 56 | for (auto& be : entries) |
| 57 | { |
| 58 | if (be.libname.empty()) |
| 59 | be.libname = "???"; |
| 60 | maxLibnameLen = std::max(maxLibnameLen, be.libname.size()); |
| 61 | } |
| 62 | |
| 63 | // Replace the simple symbol with a better representation if possible. |
| 64 | for (size_t i = 0; i < entries.size(); ++i) |
| 65 | { |
| 66 | BacktraceEntry& be = entries[i]; |
| 67 | std::string line; |
| 68 | |
| 69 | line = std::to_string(i); |
| 70 | line += std::string(4 - line.size(), ' '); |
| 71 | // Should the directory info be stripped from the libname? |
| 72 | line += be.libname; |
| 73 | line += std::string(maxLibnameLen + 2 - be.libname.size(), ' '); |
| 74 | if (be.symname.size()) |
| 75 | line += demangle(be.symname); |
| 76 | else |
| 77 | { |
| 78 | std::ostringstream oss; |
| 79 | intptr_t ip(reinterpret_cast<intptr_t>(be.addr)); |
| 80 | oss << "0x" << std::hex << std::setw(sizeof(ip) * 2) << |
| 81 | std::setfill('0') << ip; |
| 82 | line += oss.str(); |
| 83 | } |
| 84 | line += " + " + std::to_string(be.offset); |
| 85 | lines.push_back(line); |
| 86 | } |
| 87 | return lines; |
| 88 | } |
| 89 | |
| 90 | } // namespace pdal |
nothing calls this directly
no test coverage detected