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 (" \
19 << #__VA_ARGS__ << ") == true\n " \
20 << "'" << BOOST_CURRENT_FUNCTION \
21 << "' @ " << __LINE__ \
22 << " in '" << __FILE__ << "'\n " \
23 << "Stack Trace:\n"; \
24 Trace::PrintStackTrace(std::cerr, " "); \
25 std::cerr << std::flush; \
30 #define TerminateIf(...) do{}while(false)
43 static thread_local std::deque<ExceptionBacktraceTree>
All;
62 entries.emplace_back(t->location);
66 void print(std::ostream& out,
const std::string& prefix =
"", std::size_t levelOffset = 0);
74 thread_local
const Trace* Trace::Top =
nullptr;
75 thread_local std::uintmax_t Trace::Size = 0;
149 return out << l.
file <<
":" << l.
line <<
" : " << l.
func;
166 const auto numW = Size ? std::log10(Size) + 1 : 1;
171 << std::setw(numW) << cnt << std::setw(0)
172 <<
": " << *
trace <<
"\n";
183 out <<
"--------------------------" << std::string(numW,
'-') <<
"\n";
187 out <<
"Exception Backtrace Tree "
188 << std::setw(numW) << i << std::setw(0) <<
":\n";
203 const auto numW = std::log10(
entries.size()) + 1;
207 std::size_t nextChildIndex = 0;
208 auto updateNextChildEntryOffset = [&]
211 if (nextChildIndex <
children.size())
213 nextChildParentEntryOffset =
children.at(nextChildIndex).parentEntryOffset;
216 updateNextChildEntryOffset();
218 for (std::size_t entryIdx = 0; entryIdx <
entries.size(); ++entryIdx)
220 const std::size_t level = levelOffset +
entries.size() - entryIdx;
221 while (entryIdx >= nextChildParentEntryOffset && nextChildIndex <
children.size())
223 children.at(nextChildIndex).print(out, prefix +
"| ", level);
224 out << prefix <<
"|/\n";
226 updateNextChildEntryOffset();
228 out << prefix <<
"* -"
229 << std::setw(numW) << level << std::setw(0) <<
": "
230 <<
entries.at(entryIdx) <<
"\n";
233 for (; nextChildIndex <
children.size(); ++nextChildIndex)
235 children.at(nextChildIndex).print(out, prefix +
"| ");
236 out << prefix <<
"|/\n";