Skip to content

Commit bc2d57b

Browse files
youngd007sivan-shani
authored andcommitted
Modify dwarfdump verification to allow sub-category counts (llvm#125062)
It was discovered that BOLT had several distinct issues of missing debug information by various tags for debug names (119493 & 119023 as examples), but the verification of a DWARF with llvm-dwarfdump prior to those fixes only gave one 'missing name' category. ``` {"error-categories":{"Name Index DIE entry missing name":{"count":36355210}},"error-count":36355210} ``` To more easily leverage dwarf verification for debug health, the JSON output will be improved to allow having detailed counts by a sub-category when it makes sense. For now, this is only implemented on the missing tags, but can be extended to more. ``` {"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} ``` This diff also modifies the tests created in pull request 124936 (not yet landed) to ensure the JSON switches. Ideally this lands after that but it did not correctly create a stack of pull requests.
1 parent 8f541bc commit bc2d57b

File tree

3 files changed

+222
-11
lines changed

3 files changed

+222
-11
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
@@ -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 (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+
auto Agg = Aggregation.find(std::string(category));
2198+
if (Agg != Aggregation.end()) {
2199+
for (auto &&[name, count] : Agg->second.DetailedCounts) {
2200+
handleCounts(name, count);
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
});
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# RUN: llvm-mc -triple x86_64-pc-linux %s -filetype=obj -o - | not llvm-dwarfdump -verify --verify-json=%t.json -
2+
# RUN: FileCheck %s --input-file %t.json
3+
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}
5+
# CHECK-NOT: error: Name Index @ 0x0: Entry for DIE @ {{.*}} (DW_TAG_variable) with name var_block_addr missing.
6+
7+
.section .debug_loc,"",@progbits
8+
.Ldebug_loc0:
9+
.quad 0
10+
.quad 1
11+
.short .Lloc0_end-.Lloc0_start # Loc expr size
12+
.Lloc0_start:
13+
.byte 3 # DW_OP_addr
14+
.quad 0x47
15+
.Lloc0_end:
16+
.quad 0
17+
.quad 0
18+
19+
.section .debug_abbrev,"",@progbits
20+
.byte 1 # Abbreviation Code
21+
.byte 17 # DW_TAG_compile_unit
22+
.byte 1 # DW_CHILDREN_yes
23+
.byte 37 # DW_AT_producer
24+
.byte 8 # DW_FORM_string
25+
.byte 17 # DW_AT_low_pc
26+
.byte 1 # DW_FORM_addr
27+
.byte 18 # DW_AT_high_pc
28+
.byte 6 # DW_FORM_data4
29+
.byte 0 # EOM(1)
30+
.byte 0 # EOM(2)
31+
32+
.byte 2 # Abbreviation Code
33+
.byte 52 # DW_TAG_variable
34+
.byte 0 # DW_CHILDREN_no
35+
.byte 3 # DW_AT_name
36+
.byte 8 # DW_FORM_string
37+
.byte 2 # DW_AT_location
38+
.byte 24 # DW_FORM_exprloc
39+
.byte 0 # EOM(1)
40+
.byte 0 # EOM(2)
41+
42+
.byte 3 # Abbreviation Code
43+
.byte 46 # DW_TAG_subprogram
44+
.byte 1 # DW_CHILDREN_yes
45+
.byte 3 # DW_AT_name
46+
.byte 8 # DW_FORM_string
47+
.byte 110 # DW_AT_linkage_name
48+
.byte 8 # DW_FORM_string
49+
.byte 82 # DW_AT_entry_pc
50+
.byte 1 # DW_FORM_addr
51+
.byte 0 # EOM(1)
52+
.byte 0 # EOM(2)
53+
54+
.byte 4 # Abbreviation Code
55+
.byte 57 # DW_TAG_namespace
56+
.byte 1 # DW_CHILDREN_yes
57+
.byte 3 # DW_AT_name
58+
.byte 8 # DW_FORM_string
59+
.byte 0 # EOM(1)
60+
.byte 0 # EOM(2)
61+
62+
.byte 5 # Abbreviation Code
63+
.byte 52 # DW_TAG_variable
64+
.byte 0 # DW_CHILDREN_no
65+
.byte 3 # DW_AT_name
66+
.byte 8 # DW_FORM_string
67+
.byte 2 # DW_AT_location
68+
.byte 23 # DW_FORM_sec_offset
69+
.byte 0 # EOM(1)
70+
.byte 0 # EOM(2)
71+
72+
.byte 6 # Abbreviation Code
73+
.byte 57 # DW_TAG_namespace
74+
.byte 1 # DW_CHILDREN_yes
75+
.byte 0 # EOM(1)
76+
.byte 0 # EOM(2)
77+
78+
.byte 7 # Abbreviation Code
79+
.byte 29 # DW_TAG_inlined_subroutine
80+
.byte 0 # DW_CHILDREN_no
81+
.byte 3 # DW_AT_name
82+
.byte 8 # DW_FORM_string
83+
.byte 17 # DW_AT_low_pc
84+
.byte 1 # DW_FORM_addr
85+
.byte 18 # DW_AT_high_pc
86+
.byte 1 # DW_FORM_addr
87+
.byte 0 # EOM(1)
88+
.byte 0 # EOM(2)
89+
90+
.byte 8 # Abbreviation Code
91+
.byte 10 # DW_TAG_label
92+
.byte 0 # DW_CHILDREN_no
93+
.byte 3 # DW_AT_name
94+
.byte 8 # DW_FORM_string
95+
.byte 82 # DW_AT_entry_pc
96+
.byte 1 # DW_FORM_addr
97+
.byte 0 # EOM(1)
98+
.byte 0 # EOM(2)
99+
100+
.byte 0 # EOM(3)
101+
.section .debug_info,"",@progbits
102+
103+
.Lcu_begin0:
104+
.long .Lcu_end0-.Lcu_start0 # Length of Unit
105+
.Lcu_start0:
106+
.short 4 # DWARF version number
107+
.long .debug_abbrev # Offset Into Abbrev. Section
108+
.byte 8 # Address Size (in bytes)
109+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
110+
.asciz "hand-written DWARF" # DW_AT_producer
111+
.quad 0x0 # DW_AT_low_pc
112+
.long 0x100 # DW_AT_high_pc
113+
114+
.byte 4 # Abbrev [4] DW_TAG_namespace
115+
.asciz "namesp" # DW_AT_name
116+
.byte 2 # Abbrev [2] DW_TAG_variable
117+
.asciz "var_block_addr" # DW_AT_name
118+
.byte 9 # DW_AT_location
119+
.byte 3 # DW_OP_addr
120+
.quad 0x47
121+
.byte 0 # End Of Children Mark
122+
123+
.byte 6 # Abbrev [6] DW_TAG_namespace
124+
.byte 5 # Abbrev [5] DW_TAG_variable
125+
.asciz "var_loc_addr" # DW_AT_name
126+
.long .Ldebug_loc0 # DW_AT_location
127+
.byte 0 # End Of Children Mark
128+
129+
.byte 2 # Abbrev [2] DW_TAG_variable
130+
.asciz "var_loc_tls" # DW_AT_name
131+
.byte 1 # DW_AT_location
132+
.byte 0x9b # DW_OP_form_tls_address
133+
134+
.byte 2 # Abbrev [2] DW_TAG_variable
135+
.asciz "var_loc_gnu_tls" # DW_AT_name
136+
.byte 1 # DW_AT_location
137+
.byte 0xe0 # DW_OP_GNU_push_tls_address
138+
139+
.byte 3 # Abbrev [3] DW_TAG_subprogram
140+
.asciz "fun_name" # DW_AT_name
141+
.asciz "_Z8fun_name" # DW_AT_linkage_name
142+
.quad 0x47 # DW_AT_entry_pc
143+
.byte 7 # Abbrev [7] DW_TAG_inlined_subroutine
144+
.asciz "fun_inline" # DW_AT_name
145+
.quad 0x48 # DW_AT_low_pc
146+
.quad 0x49 # DW_AT_high_pc
147+
.byte 8 # Abbrev [8] DW_TAG_label
148+
.asciz "label" # DW_AT_name
149+
.quad 0x4a # DW_AT_entry_pc
150+
.byte 0 # End Of Children Mark
151+
152+
.byte 0 # End Of Children Mark
153+
.Lcu_end0:
154+
155+
.section .debug_names,"",@progbits
156+
.long .Lnames_end0-.Lnames_start0 # Header: contribution length
157+
.Lnames_start0:
158+
.short 5 # Header: version
159+
.short 0 # Header: padding
160+
.long 1 # Header: compilation unit count
161+
.long 0 # Header: local type unit count
162+
.long 0 # Header: foreign type unit count
163+
.long 0 # Header: bucket count
164+
.long 0 # Header: name count
165+
.long .Lnames_abbrev_end0-.Lnames_abbrev_start0 # Header: abbreviation table size
166+
.long 0 # Header: augmentation length
167+
.long .Lcu_begin0 # Compilation unit 0
168+
.Lnames_abbrev_start0:
169+
.byte 0 # End of abbrev list
170+
.Lnames_abbrev_end0:
171+
.Lnames_entries0:
172+
.Lnames_end0:

0 commit comments

Comments
 (0)