Skip to content

Commit b5d28f3

Browse files
Nikola TesicDjordje Todorovic
Nikola Tesic
authored and
Djordje Todorovic
committed
[Debugify][OriginalDIMode] Make HTML reporting infrastructure more resilient
Debugify in OriginalDebugInfo mode (verify-each-debuginfo-preserve), when used in parallel builds of large projects, can produce incorrect report. More precisely, simultaneous writes to JSON report file, could form incorrect JSON objects, which describe found Debug Info bugs. This patch uses the lock/unlock mechanism to protect JSON report file and also makes script llvm/utils/llvm-original-di-preservation.py resilient to corrupted lines in the report file. So, it ensures the creation of HTML report. Differential Revision: https://reviews.llvm.org/D115616
1 parent 02bfe2d commit b5d28f3

File tree

5 files changed

+258
-28
lines changed

5 files changed

+258
-28
lines changed

llvm/lib/Transforms/Utils/Debugify.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,19 @@ static void writeJSON(StringRef OrigDIVerifyBugsReportFilePath,
513513
return;
514514
}
515515

516-
OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", ";
516+
if (auto L = OS_FILE.lock()) {
517+
OS_FILE << "{\"file\":\"" << FileNameFromCU << "\", ";
517518

518-
StringRef PassName = NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name";
519-
OS_FILE << "\"pass\":\"" << PassName << "\", ";
519+
StringRef PassName =
520+
NameOfWrappedPass != "" ? NameOfWrappedPass : "no-name";
521+
OS_FILE << "\"pass\":\"" << PassName << "\", ";
520522

521-
llvm::json::Value BugsToPrint{std::move(Bugs)};
522-
OS_FILE << "\"bugs\": " << BugsToPrint;
523+
llvm::json::Value BugsToPrint{std::move(Bugs)};
524+
OS_FILE << "\"bugs\": " << BugsToPrint;
523525

524-
OS_FILE << "}\n";
526+
OS_FILE << "}\n";
527+
}
528+
OS_FILE.close();
525529
}
526530

527531
bool llvm::checkDebugInfoMetadata(Module &M,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{"file":"debug.c", "pass":"Simplify the CFG", "bugs": [[{"action":"drop","fn-name":"debug_class_type_samep","metadata":"dbg-var-intrinsic","name":"pf1"},{"action":"drop","fn-name":"debug_class_type_samep","metadata":"dbg-var-intrinsic","name":"pf2"},{"action":"drop","fn-name":"debug_class_type_samep","metadata":"dbg-var-intrinsic","name":"pv1"},{"action":"drop","fn-name":"debug_class_type_samep","metadata":"dbg-var-intrinsic","name":"pv2"}]]}
2+
{"file":"debug.c", "pass":"Combine redundant instructions", "bugs": [[{"action":"drop","fn-name":"debug_write_block","metadata":"dbg-var-intrinsic","name":"n"},{"action":"drop","fn-name":"debug_write_block","metadata":"dbg-var-intrinsic","name":"b"}]]}
3+
{"file":"ieee.c", "pass":"Interprocedural Sparse Conditional Constant Propagation", "bugs": [[{"action":"not-generate","bb-name":"land.lhs.true251","fn-name":"parse_ieee_bb","instr":"br","metadata":"DILocation"},{"action":"not-generate","bb-name":"cond.false70","fn-n{"file":"stabs.c", "pass":"Simplify the CFG", "bugs": [[{"action":"not-generate","bb-name":"land.lhs.true76","fn-name":"parse_stab","instr":"icmp","metadata":"DILocation"}]]}
4+
ame":"ieee_end_class_type","instr":"br","metadata":"DILocation"},{"action":"not-generate","bb-name":"lor.lhs.false79","fn-name":"ieee_end_class_type","instr":"br","metadata":"DILocation"}]]}
5+
{"file":"wrstabs.c", "pass":"Simplify the CFG", "bugs": [[{"action":"drop","fn-name":"stab_bool_type","metadata":"dbg-var-intrinsic","name":"tindex"}]]}
6+
{"file":"prdbg.c", "pass":"Simplify the CFG", "bugs": [[{"action":"drop","fn-name":"pr_tag_type","metadata":"dbg-var-intrinsic","name":"t"},{"action":"drop","fn-name":"pr_tag_type","metadata":"dbg-var-intrinsic","name":"tag"}]]}
7+
{"file":"objdump.c", "pass":"Simplify the CFG", "bugs": [[{"action":"drop","fn-name":"dump_section_header","metadata":"dbg-var-intrinsic","name":"comma"},{"action":"drop","fn-name":"dump_section_header","metadata":"dbg-var-intrinsic","name":"ls"}]]}
8+
{"file":"objdump.c", "bad-field": [[{"action":"drop","fn-name":"dump_section_header","metadata":"dbg-var-intrinsic","name":"comma"},{"action":"drop","fn-name":"dump_section_header","metadata":"dbg-var-intrinsic","name":"ls"}]]}
9+
{"file":"wrstabs.c", "pass":"Simplify the CFG", "bugs": [[{"bad-bug":"stab_function_type"}]]}
10+
{"file":"wrstabs.c", "pass":"Simplify the CFG", "bugs": [[{"action":"drop","bb-name":"if.end","fn-name":"stab_function_type","instr":"br","metadata":"DILocation"}]]}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<html>
2+
<head>
3+
<style>
4+
table, th, td {
5+
border: 1px solid black;
6+
}
7+
table.center {
8+
margin-left: auto;
9+
margin-right: auto;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<table>
15+
<caption><b>Location Bugs found by the Debugify</b></caption>
16+
<tr>
17+
<th>File</th>
18+
<th>LLVM Pass Name</th>
19+
<th>LLVM IR Instruction</th>
20+
<th>Function Name</th>
21+
<th>Basic Block Name</th>
22+
<th>Action</th>
23+
</tr>
24+
</tr>
25+
<tr>
26+
<td>wrstabs.c</td>
27+
<td>Simplify the CFG</td>
28+
<td>br</td>
29+
<td>stab_function_type</td>
30+
<td>if.end</td>
31+
<td>drop</td>
32+
</tr>
33+
<tr>
34+
</table>
35+
<br>
36+
<table>
37+
<caption><b>Summary of Location Bugs</b></caption>
38+
<tr>
39+
<th>LLVM Pass Name</th>
40+
<th>Number of bugs</th>
41+
</tr>
42+
<tr>
43+
<td>Simplify the CFG</td>
44+
<td>1</td>
45+
</tr>
46+
<tr>
47+
</table>
48+
<br>
49+
<br>
50+
<table>
51+
<caption><b>SP Bugs found by the Debugify</b></caption>
52+
<tr>
53+
<th>File</th>
54+
<th>LLVM Pass Name</th>
55+
<th>Function Name</th>
56+
<th>Action</th>
57+
</tr>
58+
<tr>
59+
<td colspan='4'> No bugs found </td>
60+
</tr>
61+
</table>
62+
<br>
63+
<table>
64+
<caption><b>Summary of SP Bugs</b></caption>
65+
<tr>
66+
<th>LLVM Pass Name</th>
67+
<th>Number of bugs</th>
68+
</tr>
69+
<tr>
70+
<tr>
71+
<td colspan='2'> No bugs found </td>
72+
</tr>
73+
</table>
74+
<br>
75+
<br>
76+
<table>
77+
<caption><b>Variable Location Bugs found by the Debugify</b></caption>
78+
<tr>
79+
<th>File</th>
80+
<th>LLVM Pass Name</th>
81+
<th>Variable</th>
82+
<th>Function</th>
83+
<th>Action</th>
84+
</tr>
85+
</tr>
86+
<tr>
87+
<td>debug.c</td>
88+
<td>Simplify the CFG</td>
89+
<td>pf1</td>
90+
<td>debug_class_type_samep</td>
91+
<td>drop</td>
92+
</tr>
93+
<tr>
94+
<td>debug.c</td>
95+
<td>Simplify the CFG</td>
96+
<td>pf2</td>
97+
<td>debug_class_type_samep</td>
98+
<td>drop</td>
99+
</tr>
100+
<tr>
101+
<td>debug.c</td>
102+
<td>Simplify the CFG</td>
103+
<td>pv1</td>
104+
<td>debug_class_type_samep</td>
105+
<td>drop</td>
106+
</tr>
107+
<tr>
108+
<td>debug.c</td>
109+
<td>Simplify the CFG</td>
110+
<td>pv2</td>
111+
<td>debug_class_type_samep</td>
112+
<td>drop</td>
113+
</tr>
114+
<tr>
115+
</tr>
116+
<tr>
117+
<td>debug.c</td>
118+
<td>Combine redundant instructions</td>
119+
<td>n</td>
120+
<td>debug_write_block</td>
121+
<td>drop</td>
122+
</tr>
123+
<tr>
124+
<td>debug.c</td>
125+
<td>Combine redundant instructions</td>
126+
<td>b</td>
127+
<td>debug_write_block</td>
128+
<td>drop</td>
129+
</tr>
130+
<tr>
131+
</tr>
132+
<tr>
133+
<td>prdbg.c</td>
134+
<td>Simplify the CFG</td>
135+
<td>t</td>
136+
<td>pr_tag_type</td>
137+
<td>drop</td>
138+
</tr>
139+
<tr>
140+
<td>prdbg.c</td>
141+
<td>Simplify the CFG</td>
142+
<td>tag</td>
143+
<td>pr_tag_type</td>
144+
<td>drop</td>
145+
</tr>
146+
<tr>
147+
</tr>
148+
<tr>
149+
<td>objdump.c</td>
150+
<td>Simplify the CFG</td>
151+
<td>comma</td>
152+
<td>dump_section_header</td>
153+
<td>drop</td>
154+
</tr>
155+
<tr>
156+
<td>objdump.c</td>
157+
<td>Simplify the CFG</td>
158+
<td>ls</td>
159+
<td>dump_section_header</td>
160+
<td>drop</td>
161+
</tr>
162+
<tr>
163+
</table>
164+
<br>
165+
<table>
166+
<caption><b>Summary of Variable Location Bugs</b></caption>
167+
<tr>
168+
<th>LLVM Pass Name</th>
169+
<th>Number of bugs</th>
170+
</tr>
171+
<tr>
172+
<td>Combine redundant instructions</td>
173+
<td>2</td>
174+
</tr>
175+
<tr>
176+
<td>Simplify the CFG</td>
177+
<td>9</td>
178+
</tr>
179+
<tr>
180+
</table>
181+
</body>
182+
</html>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
RUN: %llvm-original-di-preservation %p/Inputs/sample.json %t.html
1+
RUN: %llvm-original-di-preservation %p/Inputs/sample.json %t.html | FileCheck %s
22
RUN: diff -w %p/Inputs/expected-sample.html %t.html
3+
CHECK-NOT: Skipped lines:
4+
5+
RUN: %llvm-original-di-preservation %p/Inputs/corrupted.json %t2.html | FileCheck %s -check-prefix=CORRUPTED
6+
RUN: diff -w %p/Inputs/expected-skipped.html %t2.html
7+
CORRUPTED: Skipped lines: 3
8+
CORRUPTED: Skipped bugs: 1

llvm/utils/llvm-original-di-preservation.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def generate_html_report(di_location_bugs, di_subprogram_bugs, di_var_bugs, \
330330
def get_json(file):
331331
json_parsed = None
332332
di_checker_data = []
333+
skipped_lines = 0
333334

334335
# The file contains json object per line.
335336
# An example of the line (formatted json):
@@ -356,11 +357,11 @@ def get_json(file):
356357
try:
357358
json_object = loads(json_object_line)
358359
except:
359-
print ("error: No valid di-checker data found.")
360-
sys.exit(1)
361-
di_checker_data.append(json_object)
360+
skipped_lines += 1
361+
else:
362+
di_checker_data.append(json_object)
362363

363-
return di_checker_data
364+
return (di_checker_data, skipped_lines)
364365

365366
# Parse the program arguments.
366367
def parse_program_args(parser):
@@ -377,7 +378,7 @@ def Main():
377378
print ("error: The output file must be '.html'.")
378379
sys.exit(1)
379380

380-
debug_info_bugs = get_json(opts.file_name)
381+
(debug_info_bugs, skipped_lines) = get_json(opts.file_name)
381382

382383
# Use the defaultdict in order to make multidim dicts.
383384
di_location_bugs = defaultdict(lambda: defaultdict(dict))
@@ -389,24 +390,37 @@ def Main():
389390
di_sp_bugs_summary = OrderedDict()
390391
di_var_bugs_summary = OrderedDict()
391392

393+
skipped_bugs = 0
392394
# Map the bugs into the file-pass pairs.
393395
for bugs_per_pass in debug_info_bugs:
394-
bugs_file = bugs_per_pass["file"]
395-
bugs_pass = bugs_per_pass["pass"]
396-
397-
bugs = bugs_per_pass["bugs"][0]
396+
try:
397+
bugs_file = bugs_per_pass["file"]
398+
bugs_pass = bugs_per_pass["pass"]
399+
bugs = bugs_per_pass["bugs"][0]
400+
except:
401+
skipped_lines += 1
402+
continue
398403

399404
di_loc_bugs = []
400405
di_sp_bugs = []
401406
di_var_bugs = []
402407

403408
for bug in bugs:
404-
bugs_metadata = bug["metadata"]
409+
try:
410+
bugs_metadata = bug["metadata"]
411+
except:
412+
skipped_bugs += 1
413+
continue
414+
405415
if bugs_metadata == "DILocation":
406-
action = bug["action"]
407-
bb_name = bug["bb-name"]
408-
fn_name = bug["fn-name"]
409-
instr = bug["instr"]
416+
try:
417+
action = bug["action"]
418+
bb_name = bug["bb-name"]
419+
fn_name = bug["fn-name"]
420+
instr = bug["instr"]
421+
except:
422+
skipped_bugs += 1
423+
continue
410424
di_loc_bugs.append(DILocBug(action, bb_name, fn_name, instr))
411425

412426
# Fill the summary dict.
@@ -415,8 +429,12 @@ def Main():
415429
else:
416430
di_location_bugs_summary[bugs_pass] = 1
417431
elif bugs_metadata == "DISubprogram":
418-
action = bug["action"]
419-
name = bug["name"]
432+
try:
433+
action = bug["action"]
434+
name = bug["name"]
435+
except:
436+
skipped_bugs += 1
437+
continue
420438
di_sp_bugs.append(DISPBug(action, name))
421439

422440
# Fill the summary dict.
@@ -425,9 +443,13 @@ def Main():
425443
else:
426444
di_sp_bugs_summary[bugs_pass] = 1
427445
elif bugs_metadata == "dbg-var-intrinsic":
428-
action = bug["action"]
429-
fn_name = bug["fn-name"]
430-
name = bug["name"]
446+
try:
447+
action = bug["action"]
448+
fn_name = bug["fn-name"]
449+
name = bug["name"]
450+
except:
451+
skipped_bugs += 1
452+
continue
431453
di_var_bugs.append(DIVarBug(action, name, fn_name))
432454

433455
# Fill the summary dict.
@@ -436,8 +458,9 @@ def Main():
436458
else:
437459
di_var_bugs_summary[bugs_pass] = 1
438460
else:
439-
print ("error: Unsupported metadata.")
440-
sys.exit(1)
461+
# Unsupported metadata.
462+
skipped_bugs += 1
463+
continue
441464

442465
di_location_bugs[bugs_file][bugs_pass] = di_loc_bugs
443466
di_subprogram_bugs[bugs_file][bugs_pass] = di_sp_bugs
@@ -447,6 +470,11 @@ def Main():
447470
di_location_bugs_summary, di_sp_bugs_summary, \
448471
di_var_bugs_summary, opts.html_file)
449472

473+
if skipped_lines > 0:
474+
print ("Skipped lines: " + str(skipped_lines))
475+
if skipped_bugs > 0:
476+
print ("Skipped bugs: " + str(skipped_bugs))
477+
450478
if __name__ == "__main__":
451479
Main()
452480
sys.exit(0)

0 commit comments

Comments
 (0)