return true;
}), allocations.end());
}
+
+void AccumulatedTraceData::printIndent(ostream& out, size_t indent, const char* indentString) const
+{
+ while (indent--) {
+ out << indentString;
+ }
+}
+
+void AccumulatedTraceData::printIp(const IpIndex ip, ostream &out, const size_t indent) const
+{
+ printIp(findIp(ip), out, indent);
+}
+
+void AccumulatedTraceData::printIp(const InstructionPointer& ip, ostream& out, const size_t indent) const
+{
+ printIndent(out, indent);
+
+ if (ip.functionIndex) {
+ out << prettyFunction(stringify(ip.functionIndex));
+ } else {
+ out << "0x" << hex << ip.instructionPointer << dec;
+ }
+
+ out << '\n';
+ printIndent(out, indent + 1);
+
+ if (ip.fileIndex) {
+ out << "at " << stringify(ip.fileIndex) << ':' << ip.line << '\n';
+ printIndent(out, indent + 1);
+ }
+
+ if (ip.moduleIndex) {
+ out << "in " << stringify(ip.moduleIndex);
+ } else {
+ out << "in ??";
+ }
+ out << '\n';
+}
+
+void AccumulatedTraceData::printBacktrace(const TraceIndex traceIndex, ostream& out,
+ const size_t indent, bool skipFirst) const
+{
+ if (!traceIndex) {
+ out << " ??";
+ return;
+ }
+ printBacktrace(findTrace(traceIndex), out, indent, skipFirst);
+}
+
+void AccumulatedTraceData::printBacktrace(TraceNode node, ostream& out, const size_t indent,
+ bool skipFirst) const
+{
+ while (node.ipIndex) {
+ const auto& ip = findIp(node.ipIndex);
+ if (!skipFirst) {
+ printIp(ip, out, indent);
+ }
+ skipFirst = false;
+
+ if (isStopIndex(ip.functionIndex)) {
+ break;
+ }
+
+ node = findTrace(node.parentIndex);
+ };
+}
void filterAllocations();
+ void printIndent(std::ostream& out, size_t indent, const char* indentString = " ") const;
+ void printIp(const IpIndex ip, std::ostream &out, const size_t indent = 0) const;
+ void printIp(const InstructionPointer& ip, std::ostream& out, const size_t indent = 0) const;
+ void printBacktrace(const TraceIndex traceIndex, std::ostream& out,
+ const size_t indent = 0, bool skipFirst = false) const;
+ void printBacktrace(TraceNode node, std::ostream& out, const size_t indent = 0,
+ bool skipFirst = false) const;
+
// indices of functions that should stop the backtrace, e.g. main or static initialization
std::vector<StringIndex> stopIndices;
std::unordered_map<uintptr_t, AllocationInfo> activeAllocations;
struct Printer final : public AccumulatedTraceData
{
- void printIp(const IpIndex ip, ostream &out, const size_t indent = 0) const
- {
- printIp(findIp(ip), out, indent);
- }
-
- void printIndent(ostream& out, size_t indent, const char* indentString = " ") const
- {
- while (indent--) {
- out << indentString;
- }
- }
-
- void printIp(const InstructionPointer& ip, ostream& out, const size_t indent = 0) const
- {
- printIndent(out, indent);
-
- if (ip.functionIndex) {
- out << prettyFunction(stringify(ip.functionIndex));
- } else {
- out << "0x" << hex << ip.instructionPointer << dec;
- }
-
- out << '\n';
- printIndent(out, indent + 1);
-
- if (ip.fileIndex) {
- out << "at " << stringify(ip.fileIndex) << ':' << ip.line << '\n';
- printIndent(out, indent + 1);
- }
-
- if (ip.moduleIndex) {
- out << "in " << stringify(ip.moduleIndex);
- } else {
- out << "in ??";
- }
- out << '\n';
- }
-
- void printBacktrace(const TraceIndex traceIndex, ostream& out,
- const size_t indent = 0, bool skipFirst = false) const
- {
- if (!traceIndex) {
- out << " ??";
- return;
- }
- printBacktrace(findTrace(traceIndex), out, indent, skipFirst);
- }
-
- void printBacktrace(TraceNode node, ostream& out, const size_t indent = 0,
- bool skipFirst = false) const
- {
- while (node.ipIndex) {
- const auto& ip = findIp(node.ipIndex);
- if (!skipFirst) {
- printIp(ip, out, indent);
- }
- skipFirst = false;
-
- if (isStopIndex(ip.functionIndex)) {
- break;
- }
-
- node = findTrace(node.parentIndex);
- };
- }
-
template<typename T, typename LabelPrinter, typename SubLabelPrinter>
void printAllocations(T AllocationData::* member, LabelPrinter label, SubLabelPrinter sublabel)
{