Skip to content

Commit f7b9514

Browse files
committed
Modify dwarf verification JSON to include detailed counts by sub-category
Details: To help make better use of dwarfdump verification for identifying and fixing issues with debug information, the JSON will now emit details (sub-categories) where relevant. First modification concerns missing tags as those were recently missing for BOLT debug names. Test: test files for JSON output were previously added, so modify here to expect the new JSON keys. One test has sub-categories and another is empty. ninja check-llvm-tools-llvm-dwarfdump Also build the tool and run with a local executable to verify. ninja llvm-dwarfdump
1 parent 9ffab56 commit f7b9514

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

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

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

33+
struct AggregationData {
34+
unsigned OverallCount;
35+
std::map<std::string, unsigned> DetailedCounts;
36+
};
37+
3338
class OutputCategoryAggregator {
3439
private:
35-
std::map<std::string, unsigned> Aggregation;
40+
std::map<std::string, AggregationData> Aggregation;
3641
bool IncludeDetail;
3742

3843
public:
3944
OutputCategoryAggregator(bool includeDetail = false)
4045
: IncludeDetail(includeDetail) {}
4146
void ShowDetail(bool showDetail) { IncludeDetail = showDetail; }
4247
size_t GetNumCategories() const { return Aggregation.size(); }
43-
void Report(StringRef s, std::function<void()> detailCallback);
48+
void Report(StringRef category, std::function<void()> detailCallback);
49+
void Report(StringRef category, StringRef sub_category,
50+
std::function<void()> detailCallback);
4451
void EnumerateResults(std::function<void(StringRef, unsigned)> handleCounts);
52+
void EnumerateDetailedResultsFor(
53+
StringRef category,
54+
std::function<void(StringRef, unsigned)> handleCounts);
4555
};
4656

4757
/// 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
@@ -1941,12 +1941,14 @@ unsigned DWARFVerifier::verifyNameIndexCompleteness(
19411941
if (none_of(NI.equal_range(Name), [&](const DWARFDebugNames::Entry &E) {
19421942
return E.getDIEUnitOffset() == DieUnitOffset;
19431943
})) {
1944-
ErrorCategory.Report("Name Index DIE entry missing name", [&]() {
1945-
error() << formatv(
1946-
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1947-
"name {3} missing.\n",
1948-
NI.getUnitOffset(), Die.getOffset(), Die.getTag(), Name);
1949-
});
1944+
ErrorCategory.Report(
1945+
"Name Index DIE entry missing name",
1946+
llvm::dwarf::TagString(Die.getTag()), [&]() {
1947+
error() << formatv(
1948+
"Name Index @ {0:x}: Entry for DIE @ {1:x} ({2}) with "
1949+
"name {3} missing.\n",
1950+
NI.getUnitOffset(), Die.getOffset(), Die.getTag(), Name);
1951+
});
19501952
++NumErrors;
19511953
}
19521954
}
@@ -2168,15 +2170,35 @@ bool DWARFVerifier::verifyDebugStrOffsets(
21682170

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

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

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

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

llvm/test/tools/llvm-dwarfdump/X86/debug-names-verify-cu-lists-json-output.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: not llvm-dwarfdump -verify -verify-json=%t.json -
33
# RUN: FileCheck %s --input-file %t.json
44

5-
# CHECK: {"error-categories":{"Duplicate Name Index":{"count":1},"Name Index doesn't index any CU":{"count":1},"Name Index references non-existing CU":{"count":1}},"error-count":3}
5+
# CHECK: {"error-categories":{"Duplicate Name Index":{"count":1,"details":{}},"Name Index doesn't index any CU":{"count":1,"details":{}},"Name Index references non-existing CU":{"count":1,"details":{}}},"error-count":3}
66
# CHECK-NOT : error: Name Index @ 0x58 references a CU @ 0x0, but this CU is already indexed by Name Index @ 0x28
77
# CHECK-NOT: warning: CU @ 0x13 not covered by any Name Index
88

0 commit comments

Comments
 (0)