1
+ using LLVM,Test
2
+
1
3
@testset " debuginfo" begin
2
4
3
5
DEBUG_METADATA_VERSION ()
4
6
5
7
@dispose ctx= Context () begin
6
8
mod = parse (LLVM. Module, """
7
- define void @foo() !dbg !5 {
8
- top:
9
- ret void, !dbg !7
9
+ define void @foo() !dbg !15 {
10
+ %1 = alloca i32, align 4
11
+ call void @llvm.dbg.declare(metadata i32* %1, metadata !19, metadata !DIExpression()), !dbg !21
12
+ store i32 0, i32* %1, align 4, !dbg !21
13
+ ret void, !dbg !22
10
14
}
11
15
12
16
define void @bar() {
13
- top:
14
- ret void
17
+ ret void;
15
18
}
16
19
17
- !llvm.module.flags = !{!0, !1}
18
- !llvm.dbg.cu = !{!2}
20
+ declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
21
+
22
+ !llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10}
23
+ !llvm.dbg.cu = !{!11}
24
+ !llvm.ident = !{!14}
19
25
20
- !0 = !{i32 2, !"Dwarf Version", i32 4}
21
- !1 = !{i32 1, !"Debug Info Version", i32 3}
22
- !2 = distinct !DICompileUnit(language: DW_LANG_C89, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
23
- !3 = !DIFile(filename: "REPL[1]", directory: ".")
24
- !4 = !{}
25
- !5 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2)
26
- !6 = !DISubroutineType(types: !4)
27
- !7 = !DILocation(line: 1, scope: !5)""" ; ctx)
26
+ !0 = !{i32 2, !"SDK Version", [2 x i32] [i32 12, i32 3]}
27
+ !1 = !{i32 7, !"Dwarf Version", i32 4}
28
+ !2 = !{i32 2, !"Debug Info Version", i32 3}
29
+ !3 = !{i32 1, !"wchar_size", i32 4}
30
+ !4 = !{i32 1, !"branch-target-enforcement", i32 0}
31
+ !5 = !{i32 1, !"sign-return-address", i32 0}
32
+ !6 = !{i32 1, !"sign-return-address-all", i32 0}
33
+ !7 = !{i32 1, !"sign-return-address-with-bkey", i32 0}
34
+ !8 = !{i32 7, !"PIC Level", i32 2}
35
+ !9 = !{i32 7, !"uwtable", i32 1}
36
+ !10 = !{i32 7, !"frame-pointer", i32 1}
37
+ !11 = distinct !DICompileUnit(language: DW_LANG_C99, file: !12, producer: "Apple clang version 13.1.6 (clang-1316.0.21.2.5)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !13, splitDebugInlining: false, nameTableKind: None, sysroot: "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk", sdk: "MacOSX.sdk")
38
+ !12 = !DIFile(filename: "/tmp/test.c", directory: "/Users/tim/Julia/pkg/LLVM")
39
+ !13 = !{}
40
+ !14 = !{!"Apple clang version 13.1.6 (clang-1316.0.21.2.5)"}
41
+ !15 = distinct !DISubprogram(name: "foo", scope: !16, file: !16, line: 1, type: !17, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !11, retainedNodes: !13)
42
+ !16 = !DIFile(filename: "test.c", directory: "/tmp")
43
+ !17 = !DISubroutineType(types: !18)
44
+ !18 = !{null}
45
+ !19 = !DILocalVariable(name: "foobar", scope: !15, file: !16, line: 2, type: !20)
46
+ !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
47
+ !21 = !DILocation(line: 2, column: 9, scope: !15)
48
+ !22 = !DILocation(line: 3, column: 5, scope: !15)""" ; ctx)
28
49
29
50
foo = functions (mod)[" foo" ]
30
51
31
52
if LLVM. version () >= v " 8.0"
32
53
sp = LLVM. get_subprogram (foo)
33
54
@test sp != = nothing
55
+ @test LLVM. line (sp) == 1
34
56
35
57
bar = functions (mod)[" bar" ]
36
58
@test LLVM. get_subprogram (bar) === nothing
@@ -39,11 +61,33 @@ DEBUG_METADATA_VERSION()
39
61
end
40
62
41
63
bb = entry (foo)
42
- inst = first (instructions (bb))
43
64
44
- @test ! isempty (metadata (inst))
45
- strip_debuginfo! (mod)
46
- @test isempty (metadata (inst))
65
+ let inst = collect (instructions (bb))[2 ]
66
+ diloc = metadata (inst)[LLVM. MD_dbg]:: LLVM.DILocation
67
+ @test LLVM. line (diloc) == 2
68
+ @test LLVM. column (diloc) == 9
69
+ @test LLVM. inlined_at (diloc) === nothing
70
+
71
+ discope = LLVM. scope (diloc):: LLVM.DIScope
72
+ @test LLVM. name (discope) == " foo"
73
+
74
+ difile = LLVM. file (discope):: LLVM.DIFile
75
+ @test LLVM. directory (difile) == " /tmp"
76
+ @test LLVM. filename (difile) == " test.c"
77
+ @test LLVM. source (difile) == " "
78
+
79
+ divar = Metadata (operands (inst)[2 ]):: LLVM.DILocalVariable
80
+ @test LLVM. line (divar) == 2
81
+ @test LLVM. file (divar) == difile
82
+ @test LLVM. scope (divar) == discope
83
+ # TODO : get type and test DIType
84
+ end
85
+
86
+ let inst = collect (instructions (bb))[3 ]
87
+ @test ! isempty (metadata (inst))
88
+ strip_debuginfo! (mod)
89
+ @test isempty (metadata (inst))
90
+ end
47
91
end
48
92
49
93
end
0 commit comments