Skip to content

Commit b29cdd4

Browse files
authored
Print all debug annotations when BINARYEN_PRINT_FULL (#5904)
In general, full print mode should print out all the things to avoid confusion. It already did so for blocks (that the text format sometimes elides), types, etc. Doing it for debug info can avoid confusion when debugging (in fact, this was one of the main reasons I've been confused about how source maps work in Binaryen...). Also add a comment to the code just landed in #5903
1 parent 65eb421 commit b29cdd4

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/passes/Print.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ struct PrintSExpression : public UnifiedExpressionVisitor<PrintSExpression> {
170170

171171
std::vector<HeapType> heapTypes;
172172

173+
// Track the print indent so that we can see when it changes. That affects how
174+
// we print debug annotations. In particular, we don't want to print repeated
175+
// debug locations for children, like this:
176+
//
177+
// ;;@ file.cpp:20:4
178+
// (block
179+
// ;; no need to annotate here; children have the parent's location by
180+
// ;; default anyhow
181+
// (nop)
182+
//
183+
// But we do want to print an annotation even if it repeats if it is not a
184+
// child:
185+
//
186+
// ;;@ file.cpp:20:4
187+
// (block)
188+
// ;;@ file.cpp:20:4 - this is clearer to annotate, to avoid confusion with
189+
// the case where there is no debug info on the nop
190+
// (nop)
191+
//
173192
unsigned lastPrintIndent = 0;
174193

175194
// Print type names by saved name or index if we have a module, or otherwise
@@ -2377,7 +2396,9 @@ std::ostream& PrintSExpression::printPrefixedTypes(const char* prefix,
23772396

23782397
void PrintSExpression::printDebugLocation(
23792398
const Function::DebugLocation& location) {
2380-
if (lastPrintedLocation == location && indent > lastPrintIndent) {
2399+
// Do not skip repeated debug info in full mode, for less-confusing debugging:
2400+
// full mode prints out everything in the most verbose manner.
2401+
if (lastPrintedLocation == location && indent > lastPrintIndent && !full) {
23812402
return;
23822403
}
23832404
lastPrintedLocation = location;

test/lit/debug/full.wat

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
;; RUN: wasm-opt %s -S -o - | filecheck %s --check-prefix=NRML
3+
;; RUN: env BINARYEN_PRINT_FULL=1 wasm-opt %s -S -o - | filecheck %s --check-prefix=FULL
4+
5+
;;
6+
;; Compare normal text output with debug info to full mode.
7+
;;
8+
;; Full mode does not skip repeated debug info in some cases, see below. It also
9+
;; annotates the type of each node.
10+
;;
11+
12+
(module
13+
;; NRML: (func $a
14+
;; NRML-NEXT: ;;@ src.cpp:1:2
15+
;; NRML-NEXT: (block $block
16+
;; NRML-NEXT: (drop
17+
;; NRML-NEXT: (i32.const 0)
18+
;; NRML-NEXT: )
19+
;; NRML-NEXT: ;;@ src.cpp:3:4
20+
;; NRML-NEXT: (drop
21+
;; NRML-NEXT: (i32.const 1)
22+
;; NRML-NEXT: )
23+
;; NRML-NEXT: ;;@ src.cpp:3:4
24+
;; NRML-NEXT: (drop
25+
;; NRML-NEXT: (i32.const 2)
26+
;; NRML-NEXT: )
27+
;; NRML-NEXT: )
28+
;; NRML-NEXT: ;;@ src.cpp:1:2
29+
;; NRML-NEXT: )
30+
;; FULL: (func $a
31+
;; FULL-NEXT: [none] ;;@ src.cpp:1:2
32+
;; FULL-NEXT: [none](block $block
33+
;; FULL-NEXT: [none] ;;@ src.cpp:1:2
34+
;; FULL-NEXT: (drop
35+
;; FULL-NEXT: [i32] ;;@ src.cpp:1:2
36+
;; FULL-NEXT: (i32.const 0)
37+
;; FULL-NEXT: )
38+
;; FULL-NEXT: [none] ;;@ src.cpp:3:4
39+
;; FULL-NEXT: (drop
40+
;; FULL-NEXT: [i32] ;;@ src.cpp:3:4
41+
;; FULL-NEXT: (i32.const 1)
42+
;; FULL-NEXT: )
43+
;; FULL-NEXT: [none] ;;@ src.cpp:3:4
44+
;; FULL-NEXT: (drop
45+
;; FULL-NEXT: [i32] ;;@ src.cpp:3:4
46+
;; FULL-NEXT: (i32.const 2)
47+
;; FULL-NEXT: )
48+
;; FULL-NEXT: ) ;; end block block
49+
;; FULL-NEXT: ;;@ src.cpp:1:2
50+
;; FULL-NEXT: )
51+
(func $a
52+
;;@ src.cpp:1:2
53+
(block $block
54+
(drop (i32.const 0)) ;; this child has the same location as the parent
55+
;; block, and only in full mode will we print such
56+
;; repeating info, including on the const child of
57+
;; the drop
58+
;;@ src.cpp:3:4
59+
(drop (i32.const 1))
60+
(drop (i32.const 2)) ;; this child has the same location as the sibling
61+
;; before it, but we print it in normal mode as well
62+
;; as full mode (as that seems less confusing). in
63+
;; full mode, however, we also annotate the location
64+
;; of the const node children of the drops.
65+
)
66+
)
67+
)

0 commit comments

Comments
 (0)