Skip to content

Commit 0c439cc

Browse files
committed
wasm: repair invalid DWARF scope ranges after transforms
Preserve nonzero tombstones, reject lost or reversed low/high pairs, normalize range lists, and repair parent scope ranges from surviving children. Ambiguous sibling scopes are made unavailable instead of being assigned incorrect code ranges.
1 parent 33abc59 commit 0c439cc

9 files changed

Lines changed: 441 additions & 60 deletions

‎src/wasm/wasm-debug.cpp‎

Lines changed: 405 additions & 27 deletions
Large diffs are not rendered by default.

‎test/passes/class_with_dwarf_noprint.bin.txt‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ DWARF debug info
33

44
Contains section .debug_info (429 bytes)
55
Contains section .debug_loc (199 bytes)
6-
Contains section .debug_ranges (24 bytes)
6+
Contains section .debug_ranges (32 bytes)
77
Contains section .debug_abbrev (337 bytes)
88
Contains section .debug_line (438 bytes)
99
Contains section .debug_str (364 bytes)
@@ -335,8 +335,8 @@ Abbrev table for offset: 0x00000000
335335
DW_AT_type [DW_FORM_ref4] (cu + 0x01a5 => {0x000001a5} "int")
336336

337337
0x0000011f: DW_TAG_lexical_block [22] *
338-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000030)
339-
DW_AT_high_pc [DW_FORM_data4] (0xffffffd0)
338+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
339+
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
340340

341341
0x00000128: DW_TAG_variable [21]
342342
DW_AT_location [DW_FORM_sec_offset] (0x00000046:
@@ -348,8 +348,8 @@ Abbrev table for offset: 0x00000000
348348
DW_AT_type [DW_FORM_ref4] (cu + 0x01a5 => {0x000001a5} "int")
349349

350350
0x00000137: DW_TAG_lexical_block [22] *
351-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000030)
352-
DW_AT_high_pc [DW_FORM_data4] (0x0000005f)
351+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
352+
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
353353

354354
0x00000140: DW_TAG_variable [21]
355355
DW_AT_location [DW_FORM_sec_offset] (0x0000009b:
@@ -369,9 +369,7 @@ Abbrev table for offset: 0x00000000
369369

370370
0x0000015e: DW_TAG_inlined_subroutine [23] *
371371
DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x00c5 => {0x000000c5} "_ZN6Random3getEf")
372-
DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
373-
[0x00000006, 0x00000007)
374-
[0x0000006b, 0x00000074))
372+
DW_AT_ranges [DW_FORM_sec_offset] (0x00000018)
375373
DW_AT_call_file [DW_FORM_data1] ("/tmp/emscripten_test_wasm3_2u9tontv/src.cpp")
376374
DW_AT_call_line [DW_FORM_data1] (28)
377375
DW_AT_call_column [DW_FORM_data1] (0x15)
@@ -388,8 +386,8 @@ Abbrev table for offset: 0x00000000
388386

389387
0x00000179: DW_TAG_inlined_subroutine [26] *
390388
DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x00c5 => {0x000000c5} "_ZN6Random3getEf")
391-
DW_AT_low_pc [DW_FORM_addr] (0x000000000000004a)
392-
DW_AT_high_pc [DW_FORM_data4] (0x00000019)
389+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
390+
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
393391
DW_AT_call_file [DW_FORM_data1] ("/tmp/emscripten_test_wasm3_2u9tontv/src.cpp")
394392
DW_AT_call_line [DW_FORM_data1] (29)
395393
DW_AT_call_column [DW_FORM_data1] (0x15)
@@ -703,6 +701,7 @@ file_names[ 3]:
703701
0x00000169: "x1"
704702

705703
.debug_ranges contents:
706-
00000000 00000000 00000001
704+
00000000 00000001 00000001
707705
00000000 00000065 0000006e
708706
00000000 <End of list>
707+
00000018 <End of list>

‎test/passes/dwarfdump_roundtrip_dwarfdump.bin.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Abbrev table for offset: 0x00000000
141141
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
142142

143143
0x00000026: DW_TAG_subprogram [2]
144-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
144+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
145145
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
146146
DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000c8] = "_Z3foov")
147147
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000d0] = "foo")

‎test/passes/fannkuch3_manyopts_dwarf.bin.txt‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,7 +2301,7 @@ DWARF debug info
23012301

23022302
Contains section .debug_info (851 bytes)
23032303
Contains section .debug_loc (1073 bytes)
2304-
Contains section .debug_ranges (88 bytes)
2304+
Contains section .debug_ranges (96 bytes)
23052305
Contains section .debug_abbrev (333 bytes)
23062306
Contains section .debug_line (2642 bytes)
23072307
Contains section .debug_str (434 bytes)
@@ -2850,8 +2850,8 @@ Abbrev table for offset: 0x00000000
28502850

28512851
0x00000278: DW_TAG_inlined_subroutine [24] *
28522852
DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x01a8 => {0x000001a8} "_ZL8fannkuchi")
2853-
DW_AT_low_pc [DW_FORM_addr] (0x00000000000003c2)
2854-
DW_AT_high_pc [DW_FORM_data4] (0xfffffc3e)
2853+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
2854+
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
28552855
DW_AT_call_file [DW_FORM_data1] ("/usr/local/google/home/azakai/Dev/emscripten/tests/fannkuch.cpp")
28562856
DW_AT_call_line [DW_FORM_data1] (159)
28572857
DW_AT_call_column [DW_FORM_data1] (0x29)
@@ -2923,12 +2923,10 @@ Abbrev table for offset: 0x00000000
29232923

29242924
0x000002da: DW_TAG_label [28]
29252925
DW_AT_abstract_origin [DW_FORM_ref4] (cu + 0x0226 => {0x00000226} "cleanup")
2926-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000604)
2926+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
29272927

29282928
0x000002e3: DW_TAG_lexical_block [14] *
2929-
DW_AT_ranges [DW_FORM_sec_offset] (0x00000028
2930-
[0x000004cd, 0x00000512)
2931-
[0x00000585, 0x000005d0))
2929+
DW_AT_ranges [DW_FORM_sec_offset] (0x00000058)
29322930

29332931
0x000002e8: DW_TAG_variable [26]
29342932
DW_AT_location [DW_FORM_sec_offset] (0x000003bc:
@@ -4671,6 +4669,7 @@ file_names[ 4]:
46714669
00000040 00000006 00000381
46724670
00000040 00000383 00000662
46734671
00000040 <End of list>
4672+
00000058 <End of list>
46744673
(module
46754674
(type $0 (func (param i32) (result i32)))
46764675
(type $1 (func (param i32 i32) (result i32)))
@@ -6847,7 +6846,7 @@ file_names[ 4]:
68476846
)
68486847
;; custom section ".debug_info", size 851
68496848
;; custom section ".debug_loc", size 1073
6850-
;; custom section ".debug_ranges", size 88
6849+
;; custom section ".debug_ranges", size 96
68516850
;; custom section ".debug_abbrev", size 333
68526851
;; custom section ".debug_line", size 2642
68536852
;; custom section ".debug_str", size 434

‎test/passes/fib2_dwarf.bin.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Abbrev table for offset: 0x00000000
453453
DW_AT_external [DW_FORM_flag_present] (true)
454454

455455
0x0000009a: DW_TAG_GNU_call_site [7]
456-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
456+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
457457

458458
0x0000009f: NULL
459459

‎test/passes/fib2_emptylocspan_dwarf.bin.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Abbrev table for offset: 0x00000000
453453
DW_AT_external [DW_FORM_flag_present] (true)
454454

455455
0x0000009a: DW_TAG_GNU_call_site [7]
456-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
456+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
457457

458458
0x0000009f: NULL
459459

‎test/passes/ignore_missing_func_dwarf.bin.txt‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ DWARF debug info
549549
================
550550

551551
Contains section .debug_info (175 bytes)
552-
Contains section .debug_ranges (32 bytes)
552+
Contains section .debug_ranges (64 bytes)
553553
Contains section .debug_abbrev (117 bytes)
554554
Contains section .debug_line (169 bytes)
555555
Contains section .debug_str (235 bytes)
@@ -621,8 +621,9 @@ Abbrev table for offset: 0x00000000
621621
DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
622622
DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000009b] = "/home/alon/Dev/emscripten")
623623
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
624-
DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
625-
[0x00000005, 0x0000006d))
624+
DW_AT_ranges [DW_FORM_sec_offset] (0x00000020
625+
[0x00000005, 0x0000006d)
626+
[0x0000006e, 0x000000d3))
626627

627628
0x00000026: DW_TAG_variable [2]
628629
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000b5] = "quine")
@@ -668,7 +669,7 @@ Abbrev table for offset: 0x00000000
668669
0x00000074: NULL
669670

670671
0x00000075: DW_TAG_subprogram [6] *
671-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
672+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
672673
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
673674
DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x000000d2] = "_Z6unusedi")
674675
DW_AT_name [DW_FORM_strp] ( .debug_str[0x000000dd] = "unused")
@@ -821,6 +822,10 @@ file_names[ 1]:
821822
00000000 <End of list>
822823
00000010 0000006e 000000d3
823824
00000010 <End of list>
825+
00000020 ffffffff 00000000
826+
00000020 00000005 0000006d
827+
00000020 0000006e 000000d3
828+
00000020 <End of list>
824829
(module
825830
(type $0 (func))
826831
(type $1 (func (param i32) (result i32)))
@@ -1074,7 +1079,7 @@ file_names[ 1]:
10741079
)
10751080
)
10761081
;; custom section ".debug_info", size 175
1077-
;; custom section ".debug_ranges", size 32
1082+
;; custom section ".debug_ranges", size 64
10781083
;; custom section ".debug_abbrev", size 117
10791084
;; custom section ".debug_line", size 169
10801085
;; custom section ".debug_str", size 235

‎test/passes/inlined_to_start_dwarf.bin.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ Abbrev table for offset: 0x00000000
115115
DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x0000006f] = "/home/azakai/Dev/emscripten")
116116
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
117117
DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
118-
[0x00000000, 0x00000007)
118+
[0x00000001, 0x00000001)
119119
[0x00000005, 0x00000012)
120120
[0x00000013, 0x0000001b))
121121

122122
0x00000026: DW_TAG_subprogram [2] *
123-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
123+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
124124
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
125125
DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_WASM_location 0x3 +0, <decoding error> 00 00 9f)
126126
DW_AT_GNU_all_call_sites [DW_FORM_flag_present] (true)
@@ -260,7 +260,7 @@ Abbrev table for offset: 0x00000000
260260
DW_AT_type [DW_FORM_ref4] (cu + 0x0071 => {0x00000071} "int")
261261

262262
0x00000129: DW_TAG_GNU_call_site [13]
263-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
263+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
264264

265265
0x0000012e: NULL
266266

@@ -404,7 +404,7 @@ file_names[ 1]:
404404
0x000000d4: "char"
405405

406406
.debug_ranges contents:
407-
00000000 00000000 00000007
407+
00000000 00000001 00000001
408408
00000000 00000005 00000012
409409
00000000 00000013 0000001b
410410
00000000 <End of list>

‎test/passes/reverse_dwarf_abbrevs.bin.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Abbrev table for offset: 0x00000000
5050
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
5151

5252
0x00000026: DW_TAG_subprogram [3] *
53-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
53+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
5454
DW_AT_high_pc [DW_FORM_data4] (0x00000000)
5555
DW_AT_frame_base [DW_FORM_exprloc] (DW_OP_WASM_location 0x3 +0, <decoding error> 00 00 9f)
5656
DW_AT_GNU_all_call_sites [DW_FORM_flag_present] (true)
@@ -61,7 +61,7 @@ Abbrev table for offset: 0x00000000
6161
DW_AT_external [DW_FORM_flag_present] (true)
6262

6363
0x00000041: DW_TAG_GNU_call_site [2]
64-
DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
64+
DW_AT_low_pc [DW_FORM_addr] (0x00000000ffffffff)
6565

6666
0x00000046: NULL
6767

0 commit comments

Comments
 (0)