Skip to content

Commit e058c73

Browse files
authored
Add test for dwarf verification JSON output (#124936)
Summary: 6244dfe LLVM commit added the ability for llvm-dwarfdump to specify --verify-json and get a JSON aggregation of the DWARF errors in a file. This diff improves the testing by ensuring we validate the expected JSON shape. A follow up diff will modify the JSON and this ensures we can verify. Test Plan: ninja check-llvm-tools-llvm-dwarfdump
1 parent 0e62c74 commit e058c73

File tree

2 files changed

+204
-0
lines changed

2 files changed

+204
-0
lines changed
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}},"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:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RUN: llvm-mc %s -filetype obj -triple x86_64-apple-darwin -o - | llvm-dwarfdump -verify --verify-json=%t.json -
2+
# RUN: FileCheck %s --input-file %t.json
3+
4+
# CHECK: {"error-categories":{},"error-count":0}
5+
6+
# This test is meant to verify that the -verify option
7+
# in llvm-dwarfdump doesn't produce any .apple_names related
8+
# output when there's no such section in the object.
9+
# The test was manually modified to exclude the
10+
# .apple_names section from the apple_names_verify_num_atoms.s
11+
# test file in the same directory.
12+
13+
.section __TEXT,__text,regular,pure_instructions
14+
.file 1 "basic.c"
15+
.comm _i,4,2 ## @i
16+
.comm _j,4,2 ## @j
17+
.section __DWARF,__debug_str,regular,debug
18+
Linfo_string:
19+
.asciz "Apple LLVM version 8.1.0 (clang-802.0.35)" ## string offset=0
20+
.asciz "basic.c" ## string offset=42
21+
.asciz "/Users/sgravani/Development/tests" ## string offset=50
22+
.asciz "i" ## string offset=84
23+
.asciz "int" ## string offset=86
24+
.asciz "j" ## string offset=90
25+
26+
.section __DWARF,__debug_info,regular,debug
27+
Lsection_info:
28+
29+
.subsections_via_symbols
30+
.section __DWARF,__debug_line,regular,debug
31+
Lsection_line:
32+
Lline_table_start0:

0 commit comments

Comments
 (0)