diff --git a/llvm/test/Bitcode/metadata-source.ll b/llvm/test/Bitcode/metadata-source.ll new file mode 100644 index 000000000000..d52dc260d222 --- /dev/null +++ b/llvm/test/Bitcode/metadata-source.ll @@ -0,0 +1,13 @@ +; Test that DIFile representation upgrades with introduction of +; optional source field. +; +; RUN: llvm-dis < %s.bc | FileCheck %s +; RUN: verify-uselistorder < %s.bc + +!llvm.dbg.cu = !{!1} +!llvm.module.flags = !{!3} + +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 5.0.1 (tags/RELEASE_501/final)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug) +; CHECK-NOT: !DIFile({{.*}}source:{{.*}}) +!2 = !DIFile(filename: "a.c", directory: "/test") +!3 = !{i32 2, !"Debug Info Version", i32 3} diff --git a/llvm/test/Bitcode/metadata-source.ll.bc b/llvm/test/Bitcode/metadata-source.ll.bc new file mode 100644 index 000000000000..b7b0a9e4c33b Binary files /dev/null and b/llvm/test/Bitcode/metadata-source.ll.bc differ diff --git a/llvm/test/CodeGen/Generic/dwarf-source.ll b/llvm/test/CodeGen/Generic/dwarf-source.ll new file mode 100644 index 000000000000..9c34fc5285b7 --- /dev/null +++ b/llvm/test/CodeGen/Generic/dwarf-source.ll @@ -0,0 +1,61 @@ +; Source text provided by IR should be passed through to asm. +; It is emitted to an object file only for DWARF 5 or later. + +; Darwin clamps the line table at DWARF v2 so XFAIL this test. +; XFAIL: darwin + +; REQUIRES: object-emission +; RUN: %llc_dwarf -dwarf-version 4 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM +; RUN: %llc_dwarf -dwarf-version 5 -filetype=asm -o - %s | FileCheck %s --check-prefix=ASM +; RUN: %llc_dwarf -dwarf-version 4 -filetype=obj -o %t4.o %s +; RUN: llvm-dwarfdump -debug-line %t4.o | FileCheck %s --check-prefix=OBJ-4 +; RUN: %llc_dwarf -dwarf-version 5 -filetype=obj -o %t5.o %s +; RUN: llvm-dwarfdump -debug-line %t5.o | FileCheck %s --check-prefix=OBJ-5 + +; FIXME: Need to convey the source for the primary source file. +; ASM: .file 1 ".{{/|\\\\}}t1.h" source "11111111111111111111111111111111" +; ASM: .file 2 ".{{/|\\\\}}t2.h" source "22222222222222222222222222222222" + +; OBJ-4: file_names[ 1]: +; OBJ-4-NEXT: name: "t1.h" +; OBJ-4-NEXT: dir_index: 1 +; OBJ-4-NOT: 11111111111111111111111111111111 +; OBJ-4: file_names[ 2]: +; OBJ-4-NEXT: name: "t2.h" +; OBJ-4-NEXT: dir_index: 1 +; OBJ-4-NOT: 22222222222222222222222222222222 + +; OBJ-5: file_names[ 0]: +; OBJ-5-NEXT: name: "t1.h" +; OBJ-5-NEXT: dir_index: 1 +; OBJ-5-NEXT: source: "11111111111111111111111111111111" +; OBJ-5: file_names[ 1]: +; OBJ-5-NEXT: name: "t2.h" +; OBJ-5-NEXT: dir_index: 1 +; OBJ-5-NEXT: source: "22222222222222222222222222222222" + +; ModuleID = 't.c' +source_filename = "t.c" + +@t1 = global i32 1, align 4, !dbg !0 +@t2 = global i32 0, align 4, !dbg !6 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!11, !12, !13} +!llvm.ident = !{!14} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "t1", scope: !2, file: !10, line: 1, type: !9, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 322159)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) +!3 = !DIFile(filename: "t.c", directory: "/test", source: "00000000000000000000000000000000") +!4 = !{} +!5 = !{!0, !6} +!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!7 = distinct !DIGlobalVariable(name: "t2", scope: !2, file: !8, line: 1, type: !9, isLocal: false, isDefinition: true) +!8 = !DIFile(filename: "./t2.h", directory: "/test", source: "22222222222222222222222222222222") +!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!10 = !DIFile(filename: "./t1.h", directory: "/test", source: "11111111111111111111111111111111") +!11 = !{i32 2, !"Dwarf Version", i32 4} +!12 = !{i32 2, !"Debug Info Version", i32 3} +!13 = !{i32 1, !"wchar_size", i32 4} +!14 = !{!"clang version 7.0.0 (trunk 322159)"} diff --git a/llvm/test/Linker/Inputs/metadata-source-a.ll b/llvm/test/Linker/Inputs/metadata-source-a.ll new file mode 100644 index 000000000000..e828770e048a --- /dev/null +++ b/llvm/test/Linker/Inputs/metadata-source-a.ll @@ -0,0 +1,22 @@ +; ModuleID = 'a.c' +source_filename = "a.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@a = common global i32 0, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (https://git.llvm.org/git/clang.git/ c12b573f9ac61655cce52628b34235f58edaf984) (https://scott.linder@llvm.org/git/llvm.git 90c4822e8541eb07891cd03e614c530c30f8aa12)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) +!3 = !DIFile(filename: "a.c", directory: "/home/slinder1/test/link", source: "int a;\0A") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 7.0.0 (https://git.llvm.org/git/clang.git/ c12b573f9ac61655cce52628b34235f58edaf984) (https://scott.linder@llvm.org/git/llvm.git 90c4822e8541eb07891cd03e614c530c30f8aa12)"} diff --git a/llvm/test/Linker/Inputs/metadata-source-b.ll b/llvm/test/Linker/Inputs/metadata-source-b.ll new file mode 100644 index 000000000000..2bda92e71b26 --- /dev/null +++ b/llvm/test/Linker/Inputs/metadata-source-b.ll @@ -0,0 +1,22 @@ +; ModuleID = 'b.c' +source_filename = "b.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@b = common global i32 0, align 4, !dbg !0 + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} +!llvm.ident = !{!10} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (https://git.llvm.org/git/clang.git/ c12b573f9ac61655cce52628b34235f58edaf984) (https://scott.linder@llvm.org/git/llvm.git 90c4822e8541eb07891cd03e614c530c30f8aa12)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) +!3 = !DIFile(filename: "b.c", directory: "/home/slinder1/test/link", source: "int b;\0A") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!10 = !{!"clang version 7.0.0 (https://git.llvm.org/git/clang.git/ c12b573f9ac61655cce52628b34235f58edaf984) (https://scott.linder@llvm.org/git/llvm.git 90c4822e8541eb07891cd03e614c530c30f8aa12)"} diff --git a/llvm/test/Linker/metadata-source.ll b/llvm/test/Linker/metadata-source.ll new file mode 100644 index 000000000000..6e667434826b --- /dev/null +++ b/llvm/test/Linker/metadata-source.ll @@ -0,0 +1,4 @@ +; RUN: llvm-link %p/Inputs/metadata-source-a.ll %p/Inputs/metadata-source-b.ll -S | FileCheck %s + +; CHECK: !DIFile(filename: "a.c", directory: "/home/slinder1/test/link", source: "int a;\0A") +; CHECK: !DIFile(filename: "b.c", directory: "/home/slinder1/test/link", source: "int b;\0A") diff --git a/llvm/test/MC/AsmParser/debug-empty-source.s b/llvm/test/MC/AsmParser/debug-empty-source.s new file mode 100644 index 000000000000..2f2039cfdae3 --- /dev/null +++ b/llvm/test/MC/AsmParser/debug-empty-source.s @@ -0,0 +1,7 @@ +// RUN: llvm-mc %s -o -| FileCheck %s + +.file 1 "dir1" "foo" source "" +.loc 1 1 0 +nop + +# CHECK: .file {{.*}} source "" diff --git a/llvm/test/MC/AsmParser/debug-no-source.s b/llvm/test/MC/AsmParser/debug-no-source.s new file mode 100644 index 000000000000..590feba8c768 --- /dev/null +++ b/llvm/test/MC/AsmParser/debug-no-source.s @@ -0,0 +1,5 @@ +// RUN: llvm-mc %s | FileCheck %s + +.file 1 "dir1/foo" + +# CHECK-NOT: .file {{.*}} source diff --git a/llvm/test/MC/ELF/debug-file-options.s b/llvm/test/MC/ELF/debug-file-options.s new file mode 100644 index 000000000000..3bcd131cc38b --- /dev/null +++ b/llvm/test/MC/ELF/debug-file-options.s @@ -0,0 +1,36 @@ +// RUN: llvm-mc -triple x86_64-unknown-unknown -dwarf-version 5 -filetype=obj %s -o -| llvm-dwarfdump --debug-line --debug-line-str -v - | FileCheck %s + +// Test combinations of options to the .file directive. + + .file 1 "dir1/foo" md5 "ee87e05688663173cd6043a3a15bba6e" source "void foo() {}" + .file 2 "dir2/bar" source "void bar() {}" md5 "816225a0c90ca8948b70eb58be4d522f" + .loc 1 1 0 + nop + .loc 2 1 0 + nop + +# CHECK: debug_line[0x00000000] +# CHECK: version: 5 +# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "" +# CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1" +# CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2" +# CHECK-NOT: include_directories +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: md5_checksum: ee87e05688663173cd6043a3a15bba6e +# CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}" +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar" +# CHECK-NEXT: dir_index: 2 +# CHECK-NEXT: md5_checksum: 816225a0c90ca8948b70eb58be4d522f +# CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar() {}" + +# CHECK: .debug_line_str contents: +# CHECK-NEXT: 0x[[DIR0]]: "" +# CHECK-NEXT: 0x[[DIR1]]: "dir1" +# CHECK-NEXT: 0x[[DIR2]]: "dir2" +# CHECK-NEXT: 0x[[FILE1]]: "foo" +# CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}" +# CHECK-NEXT: 0x[[FILE2]]: "bar" +# CHECK-NEXT: 0x[[FILE2SRC]]: "void bar() {}" diff --git a/llvm/test/MC/ELF/debug-source.s b/llvm/test/MC/ELF/debug-source.s new file mode 100644 index 000000000000..0b919e15ddb5 --- /dev/null +++ b/llvm/test/MC/ELF/debug-source.s @@ -0,0 +1,32 @@ +// RUN: llvm-mc -triple x86_64-unknown-unknown -dwarf-version 5 -filetype=obj %s -o -| llvm-dwarfdump --debug-line --debug-line-str -v - | FileCheck %s + + .file 1 "dir1/foo" source "void foo() {}" + .file 2 "dir2" "bar" source "void bar()\n{\n}" + .loc 1 1 0 + nop + .loc 2 1 0 + nop + +# CHECK: debug_line[0x00000000] +# CHECK: version: 5 +# CHECK: include_directories[ 0] = .debug_line_str[0x[[DIR0:[0-9a-f]+]]] = "" +# CHECK: include_directories[ 1] = .debug_line_str[0x[[DIR1:[0-9a-f]+]]] = "dir1" +# CHECK: include_directories[ 2] = .debug_line_str[0x[[DIR2:[0-9a-f]+]]] = "dir2" +# CHECK-NOT: include_directories +# CHECK: file_names[ 0]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE1:[0-9a-f]+]]] = "foo" +# CHECK-NEXT: dir_index: 1 +# CHECK-NEXT: source: .debug_line_str[0x[[FILE1SRC:[0-9a-f]+]]] = "void foo() {}" +# CHECK: file_names[ 1]: +# CHECK-NEXT: name: .debug_line_str[0x[[FILE2:[0-9a-f]+]]] = "bar" +# CHECK-NEXT: dir_index: 2 +# CHECK-NEXT: source: .debug_line_str[0x[[FILE2SRC:[0-9a-f]+]]] = "void bar()\n{\n}" + +# CHECK: .debug_line_str contents: +# CHECK-NEXT: 0x[[DIR0]]: "" +# CHECK-NEXT: 0x[[DIR1]]: "dir1" +# CHECK-NEXT: 0x[[DIR2]]: "dir2" +# CHECK-NEXT: 0x[[FILE1]]: "foo" +# CHECK-NEXT: 0x[[FILE1SRC]]: "void foo() {}" +# CHECK-NEXT: 0x[[FILE2]]: "bar" +# CHECK-NEXT: 0x[[FILE2SRC]]: "void bar()\n{\n}" diff --git a/llvm/test/tools/llvm-objdump/Inputs/embedded-source b/llvm/test/tools/llvm-objdump/Inputs/embedded-source new file mode 100644 index 000000000000..072b5a90c5c8 Binary files /dev/null and b/llvm/test/tools/llvm-objdump/Inputs/embedded-source differ diff --git a/llvm/test/tools/llvm-objdump/embedded-source.test b/llvm/test/tools/llvm-objdump/embedded-source.test new file mode 100644 index 000000000000..464c9da5f118 --- /dev/null +++ b/llvm/test/tools/llvm-objdump/embedded-source.test @@ -0,0 +1,22 @@ +; RUN: llvm-objdump -disassemble -line-numbers %p/Inputs/embedded-source | FileCheck --check-prefix=LINE %s +; RUN: llvm-objdump -disassemble -source %p/Inputs/embedded-source | FileCheck --check-prefix=SOURCE %s + +; LINE: main: +; LINE-NEXT: ; {{.*}}embedded-source.c:1 +; LINE-NEXT: pushq %rbp +; LINE: ; {{.*}}embedded-source.c:2 +; LINE-NEXT: movl $2 +; LINE: ; {{.*}}embedded-source.c:3 +; LINE: addl $1 +; LINE: ; {{.*}}embedded-source.c:4 +; LINE: retq + +; SOURCE: main: +; SOURCE-NEXT: ; int main(int argc, char *argv[]) { +; SOURCE-NEXT: pushq %rbp +; SOURCE: ; int i = 2; +; SOURCE-NEXT: movl $2 +; SOURCE: ; i += 1; +; SOURCE: addl $1 +; SOURCE: ; return i; +; SOURCE: retq