12 #define ACTIVATE_TRACE_LIB_TERMINATE_ON_INTERNAL_ERROR
13 #ifdef ACTIVATE_TRACE_LIB_TERMINATE_ON_INTERNAL_ERROR
14 #define TerminateIf(...) \
18 std::cerr << "TERMINATING!:\n (" << #__VA_ARGS__ << ") == true\n " \
19 << "'" << BOOST_CURRENT_FUNCTION << "' @ " << __LINE__ << " in '" \
20 << __FILE__ << "'\n " \
21 << "Stack Trace:\n"; \
22 Trace::PrintStackTrace(std::cerr, " "); \
23 std::cerr << std::flush; \
31 #define TerminateIf(...) \
47 static thread_local std::deque<ExceptionBacktraceTree>
All;
68 entries.emplace_back(t->location);
72 void print(std::ostream& out,
const std::string& prefix =
"", std::size_t levelOffset = 0);
81 thread_local
const Trace* Trace::Top =
nullptr;
82 thread_local std::uintmax_t Trace::Size = 0;
166 return out << l.
file <<
":" << l.
line <<
" : " << l.
func;
186 const auto numW = Size ? std::log10(Size) + 1 : 1;
190 out << pre << std::setw(numW) << cnt << std::setw(0) <<
": " << *
trace <<
"\n";
204 out <<
"--------------------------" << std::string(numW,
'-') <<
"\n";
208 out <<
"Exception Backtrace Tree " << std::setw(numW) << i << std::setw(0) <<
":\n";
223 const std::string& prefix,
224 std::size_t levelOffset)
227 const auto numW = std::log10(
entries.size()) + 1;
231 std::size_t nextChildIndex = 0;
232 auto updateNextChildEntryOffset = [&]
235 if (nextChildIndex <
children.size())
237 nextChildParentEntryOffset =
children.at(nextChildIndex).parentEntryOffset;
240 updateNextChildEntryOffset();
242 for (std::size_t entryIdx = 0; entryIdx <
entries.size(); ++entryIdx)
244 const std::size_t level =
245 levelOffset +
entries.size() - entryIdx;
246 while (entryIdx >= nextChildParentEntryOffset && nextChildIndex <
children.size())
248 children.at(nextChildIndex).print(out, prefix +
"| ", level);
249 out << prefix <<
"|/\n";
251 updateNextChildEntryOffset();
253 out << prefix <<
"* -" << std::setw(numW) << level << std::setw(0) <<
": "
254 <<
entries.at(entryIdx) <<
"\n";
257 for (; nextChildIndex <
children.size(); ++nextChildIndex)
259 children.at(nextChildIndex).print(out, prefix +
"| ");
260 out << prefix <<
"|/\n";