Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 6c3634b

Browse files
committed
[lsan] Prettify LSan reports and add a summary.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182646 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 969b529 commit 6c3634b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/lsan/lsan_common.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ void PrintLeakedCb::operator()(void *p) const {
267267
}
268268

269269
static void PrintLeaked() {
270-
Printf("\nReporting individual blocks:\n");
270+
Printf("Reporting individual blocks:\n");
271+
Printf("============================\n");
271272
ForEachChunk(PrintLeakedCb());
273+
Printf("\n");
272274
}
273275

274276
enum LeakCheckResult {
@@ -290,9 +292,14 @@ static void DoLeakCheckCallback(const SuspendedThreadsList &suspended_threads,
290292
*result = kNoLeaks;
291293
return;
292294
}
295+
Printf("\n");
296+
Printf("=================================================================\n");
297+
Report("ERROR: LeakSanitizer: detected leaks.\n");
293298
leak_report.PrintLargest(flags()->max_leaks);
294299
if (flags()->report_blocks)
295300
PrintLeaked();
301+
leak_report.PrintSummary();
302+
Printf("\n");
296303
ForEachChunk(ClearTagCb());
297304
*result = kLeaksFound;
298305
}
@@ -387,17 +394,27 @@ void LeakReport::PrintLargest(uptr max_leaks) {
387394
InternalSort(&leaks_, leaks_.size(), IsLarger);
388395
max_leaks = max_leaks > 0 ? Min(max_leaks, leaks_.size()) : leaks_.size();
389396
for (uptr i = 0; i < max_leaks; i++) {
390-
Printf("\n%s leak of %llu bytes in %llu objects allocated from:\n",
397+
Printf("%s leak of %llu bytes in %llu object%s allocated from:\n",
391398
leaks_[i].is_directly_leaked ? "Direct" : "Indirect",
392-
leaks_[i].total_size, leaks_[i].hit_count);
399+
leaks_[i].total_size, leaks_[i].hit_count,
400+
leaks_[i].hit_count == 1 ? "" : "s");
393401
PrintStackTraceById(leaks_[i].stack_trace_id);
402+
Printf("\n");
394403
}
395404
if (max_leaks < leaks_.size()) {
396405
uptr remaining = leaks_.size() - max_leaks;
397-
Printf("\nOmitting %llu more leak%s.\n", remaining,
406+
Printf("Omitting %llu more leak%s.\n", remaining,
398407
remaining > 1 ? "s" : "");
399408
}
400409
}
401410

411+
void LeakReport::PrintSummary() {
412+
CHECK(leaks_.size() <= kMaxLeaksConsidered);
413+
uptr bytes_leaked = 0;
414+
for (uptr i = 0; i < leaks_.size(); i++) {
415+
bytes_leaked += leaks_[i].total_size;
416+
}
417+
Printf("SUMMARY: LeakSanitizer: %llu bytes leaked.\n", bytes_leaked);
418+
}
402419
} // namespace __lsan
403420
#endif // CAN_SANITIZE_LEAKS

lib/lsan/lsan_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class LeakReport {
9898
LeakReport() : leaks_(1) {}
9999
void Add(u32 stack_trace_id, uptr leaked_size, ChunkTag tag);
100100
void PrintLargest(uptr max_leaks);
101+
void PrintSummary();
101102
bool IsEmpty() { return leaks_.size() == 0; }
102103
private:
103104
InternalVector<Leak> leaks_;

0 commit comments

Comments
 (0)