Skip to content

Commit ebf1cab

Browse files
committed
Modify dwarf verification JSON to include detailed counts by sub-category
1 parent 63113cf commit ebf1cab

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,29 @@ class DWARFDebugAbbrev;
3030
class DataExtractor;
3131
struct DWARFSection;
3232

33+
struct AggregationData {
34+
unsigned OverallCount;
35+
std::map<std::string, unsigned> DetailedCounts;
36+
AggregationData() = default;
37+
};
38+
3339
class OutputCategoryAggregator {
3440
private:
35-
std::map<std::string, unsigned> Aggregation;
41+
std::map<std::string, AggregationData> Aggregation;
3642
bool IncludeDetail;
3743

3844
public:
3945
OutputCategoryAggregator(bool includeDetail = false)
4046
: IncludeDetail(includeDetail) {}
4147
void ShowDetail(bool showDetail) { IncludeDetail = showDetail; }
4248
size_t GetNumCategories() const { return Aggregation.size(); }
43-
void Report(StringRef s, std::function<void()> detailCallback);
49+
void Report(StringRef category, std::function<void()> detailCallback);
50+
void Report(StringRef category, StringRef sub_category,
51+
std::function<void()> detailCallback);
4452
void EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
53+
void EnumerateDetailedResultsFor(
54+
StringRef category,
55+
std::function<void(StringRef, unsigned)> handleCounts);
4556
};
4657

4758
/// A class that verifies DWARF debug information given a DWARF Context.

llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,12 +1942,14 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
19421942
if (none_of(NI.equal_range(Name), [&](const DWARFDebugNames::Entry &E) {
19431943
return E.getDIEUnitOffset() == DieUnitOffset;
19441944
})) {
1945-
ErrorCategory.Report("Name Index DIE entry missing name", [&]() {
1946-
error() << formatv(
1947-
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1948-
"name {3} missing.\n",
1949-
NI.getUnitOffset(), Die.getOffset(), Die.getTag(), Name);
1950-
});
1945+
ErrorCategory.Report(
1946+
"Name Index DIE entry missing name",
1947+
llvm::dwarf::TagString(Die.getTag()), [&]() {
1948+
error() << formatv(
1949+
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1950+
"name {3} missing.\n",
1951+
NI.getUnitOffset(), Die.getOffset(), Die.getTag(), Name);
1952+
});
19511953
++NumErrors;
19521954
}
19531955
}
@@ -2169,15 +2171,35 @@ bool DWARFVerifier::verifyDebugStrOffsets(
21692171

21702172
void OutputCategoryAggregator::Report(
21712173
StringRef s, std::function<void(void)> detailCallback) {
2172-
Aggregation[std::string(s)]++;
2174+
this->Report(s, "", detailCallback);
2175+
}
2176+
2177+
void OutputCategoryAggregator::Report(
2178+
StringRef category, StringRef sub_category,
2179+
std::function<void(void)> detailCallback) {
2180+
std::string category_str = std::string(category);
2181+
AggregationData *Agg = &Aggregation[category_str];
2182+
Agg->OverallCount++;
2183+
if (!sub_category.empty()) {
2184+
Agg->DetailedCounts[std::string(sub_category)]++;
2185+
}
21732186
if (IncludeDetail)
21742187
detailCallback();
21752188
}
21762189

21772190
void OutputCategoryAggregator::EnumerateResults(
21782191
std::function<void(StringRef, unsigned)> handleCounts) {
2179-
for (auto &&[name, count] : Aggregation) {
2180-
handleCounts(name, count);
2192+
for (auto &&[name, aggData] : Aggregation) {
2193+
handleCounts(name, aggData.OverallCount);
2194+
}
2195+
}
2196+
void OutputCategoryAggregator::EnumerateDetailedResultsFor(
2197+
StringRef category, std::function<void(StringRef, unsigned)> handleCounts) {
2198+
auto Agg = Aggregation.find(std::string(category));
2199+
if (Agg != Aggregation.end()) {
2200+
for (auto &&[name, count] : Agg->second.DetailedCounts) {
2201+
handleCounts(name, count);
2202+
}
21812203
}
21822204
}
21832205

@@ -2204,6 +2226,12 @@ void DWARFVerifier::summarize() {
22042226
ErrorCategory.EnumerateResults([&](StringRef Category, unsigned Count) {
22052227
llvm::json::Object Val;
22062228
Val.try_emplace("count", Count);
2229+
llvm::json::Object Details;
2230+
ErrorCategory.EnumerateDetailedResultsFor(
2231+
Category, [&](StringRef SubCategory, unsigned SubCount) {
2232+
Details.try_emplace(SubCategory, SubCount);
2233+
});
2234+
Val.try_emplace("details", std::move(Details));
22072235
Categories.try_emplace(Category, std::move(Val));
22082236
ErrorCount += Count;
22092237
});

llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify--completeness-json-output.s renamed to llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-completeness-json-output.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj -o - | not llvm-dwarfdump -verify --verify-json=%t.json -
22
# RUN: FileCheck %s --input-file %t.json
33

4-
# CHECK: {"error-categories":{"Name Index DIE entry missing name":{"count":10}},"error-count":10}
4+
# CHECK: {"error-categories":{"Name Index DIE entry missing name":{"count":10,"details":{"DW_TAG_inlined_subroutine":1,"DW_TAG_label":1,"DW_TAG_namespace":2,"DW_TAG_subprogram":2,"DW_TAG_variable":4}}},"error-count":10}
55
# CHECK-NOT: error: Name Index @ 0x0: Entry for DIE @ {{.*}} (DW_TAG_variable) with name var_block_addr missing.
66

77
.section .debug_loc,"",@progbits

0 commit comments

Comments
 (0)