|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-clang -x c -Wno-unused-command-line-argument -Wl,--build-id -g %S/Inputs/fib.c -o %t/fib |
| 3 | +// RUN: %target-clang -x c -Wno-unused-command-line-argument -g %S/Inputs/fib.c -o %t/fib-no-uuid |
| 4 | +// RUN: %target-clang -x c -Wno-unused-command-line-argument -Wl,--build-id -Wl,--compress-debug-sections=zlib-gnu -g %S/Inputs/fib.c -o %t/fib-compress-gnu |
| 5 | +// RUN: %target-clang -x c -Wno-unused-command-line-argument -Wl,--build-id -Wl,--compress-debug-sections=zlib -g %S/Inputs/fib.c -o %t/fib-compress-zlib |
| 6 | +// RUN: %target-build-swift %s -parse-as-library -g -o %t/ElfReader |
| 7 | +// RUN: %target-run %t/ElfReader %t/fib | %FileCheck %s |
| 8 | +// RUN: %target-run %t/ElfReader %t/fib-no-uuid | %FileCheck %s --check-prefix NOUUID |
| 9 | +// RUN: %target-run %t/ElfReader %t/fib-compress-gnu | %FileCheck %s --check-prefix CMPGNU |
| 10 | +// RUN: %target-run %t/ElfReader %t/fib-compress-zlib | %FileCheck %s --check-prefix CMPZLIB |
| 11 | +// RUN: if %S/Inputs/make-minidebug %t/fib %t/fib-minidebug; then ( %target-run %t/ElfReader %t/fib-minidebug | %FileCheck %s --check-prefix MINIDEBUG ); else echo "warning: skipping minidebug test as we couldn't generate minidebug data"; fi |
| 12 | +// RUN: libc=$(ldd %t/fib | awk '/libc\.so\.6/ { print $3 }'); if %S/Inputs/has-uuid-syms "$libc" >/dev/null; then %target-run %t/ElfReader "$libc" | %FileCheck %s --check-prefix LIBC; else echo "warning: skipping /usr/lib/debug test as libc symbols are not installed"; fi |
| 13 | +// RUN: %S/Inputs/make-debuglink %t/fib %t/fib-stripped %t/fib.dbg && %target-run %t/ElfReader %t/fib-stripped | %FileCheck %s --check-prefix DBGLINK |
| 14 | + |
| 15 | +// REQUIRES: OS=linux-gnu |
| 16 | + |
| 17 | +@_spi(ElfTest) import _Backtracing |
| 18 | + |
| 19 | +@main |
| 20 | +struct ElfReader { |
| 21 | + |
| 22 | + static func main() { |
| 23 | + if CommandLine.argc != 2 { |
| 24 | + print("usage: ElfReader <path-to-binary>") |
| 25 | + return |
| 26 | + } |
| 27 | + |
| 28 | + // CHECK: {{.*}}/fib is a {{(32|64)}}-bit ELF image |
| 29 | + // CHECK-NEXT: uuid: {{[0-9a-f]+}} |
| 30 | + // CHECK-NEXT: debug image: <none> |
| 31 | + // CHECK-NEXT: .debug_info: found |
| 32 | + // CHECK-NEXT: .debug_line: found |
| 33 | + // CHECK-NEXT: .debug_abbrev: found |
| 34 | + // CHECK-NEXT: .debug_ranges: not found |
| 35 | + // CHECK-NEXT: .debug_str: found |
| 36 | + // CHECK-NEXT: .debug_addr: found |
| 37 | + // CHECK-NEXT: .debug_str_offsets: found |
| 38 | + // CHECK-NEXT: .debug_line_str: found |
| 39 | + // CHECK-NEXT: .debug_rnglists: not found |
| 40 | + |
| 41 | + // NOUUID: {{.*}}/fib-no-uuid is a {{(32|64)}}-bit ELF image |
| 42 | + // NOUUID-NEXT: uuid: <no uuid> |
| 43 | + // NOUUID-NEXT: debug image: <none> |
| 44 | + // NOUUID-NEXT: .debug_info: found |
| 45 | + // NOUUID-NEXT: .debug_line: found |
| 46 | + // NOUUID-NEXT: .debug_abbrev: found |
| 47 | + // NOUUID-NEXT: .debug_ranges: not found |
| 48 | + // NOUUID-NEXT: .debug_str: found |
| 49 | + // NOUUID-NEXT: .debug_addr: found |
| 50 | + // NOUUID-NEXT: .debug_str_offsets: found |
| 51 | + // NOUUID-NEXT: .debug_line_str: found |
| 52 | + // NOUUID-NEXT: .debug_rnglists: not found |
| 53 | + |
| 54 | + // CMPGNU: {{.*}}/fib-compress-gnu is a {{(32|64)}}-bit ELF image |
| 55 | + // CMPGNU-NEXT: uuid: {{[0-9a-f]+}} |
| 56 | + // CMPGNU-NEXT: debug image: <none> |
| 57 | + // CMPGNU-NEXT: .debug_info: found |
| 58 | + // CMPGNU-NEXT: .debug_line: found |
| 59 | + // CMPGNU-NEXT: .debug_abbrev: found |
| 60 | + // CMPGNU-NEXT: .debug_ranges: not found |
| 61 | + // CMPGNU-NEXT: .debug_str: found |
| 62 | + // CMPGNU-NEXT: .debug_addr: found |
| 63 | + // CMPGNU-NEXT: .debug_str_offsets: found |
| 64 | + // CMPGNU-NEXT: .debug_line_str: found |
| 65 | + // CMPGNU-NEXT: .debug_rnglists: not found |
| 66 | + |
| 67 | + // CMPZLIB: {{.*}}/fib-compress-zlib is a {{(32|64)}}-bit ELF image |
| 68 | + // CMPZLIB-NEXT: uuid: {{[0-9a-f]+}} |
| 69 | + // CMPZLIB-NEXT: debug image: <none> |
| 70 | + // CMPZLIB-NEXT: .debug_info: found |
| 71 | + // CMPZLIB-NEXT: .debug_line: found |
| 72 | + // CMPZLIB-NEXT: .debug_abbrev: found |
| 73 | + // CMPZLIB-NEXT: .debug_ranges: not found |
| 74 | + // CMPZLIB-NEXT: .debug_str: found |
| 75 | + // CMPZLIB-NEXT: .debug_addr: found |
| 76 | + // CMPZLIB-NEXT: .debug_str_offsets: found |
| 77 | + // CMPZLIB-NEXT: .debug_line_str: found |
| 78 | + // CMPZLIB-NEXT: .debug_rnglists: not found |
| 79 | + |
| 80 | + // MINIDEBUG: {{.*}}/fib-minidebug is a {{(32|64)}}-bit ELF image |
| 81 | + // MINIDEBUG-NEXT: uuid: {{[0-9a-f]+}} |
| 82 | + // MINIDEBUG-NEXT: debug image: image {{[0-9a-f]+}} |
| 83 | + // MINIDEBUG-NEXT: .debug_info: found |
| 84 | + // MINIDEBUG-NEXT: .debug_line: found |
| 85 | + // MINIDEBUG-NEXT: .debug_abbrev: found |
| 86 | + // MINIDEBUG-NEXT: .debug_ranges: not found |
| 87 | + // MINIDEBUG-NEXT: .debug_str: found |
| 88 | + // MINIDEBUG-NEXT: .debug_addr: found |
| 89 | + // MINIDEBUG-NEXT: .debug_str_offsets: found |
| 90 | + // MINIDEBUG-NEXT: .debug_line_str: found |
| 91 | + // MINIDEBUG-NEXT: .debug_rnglists: not found |
| 92 | + |
| 93 | + // LIBC: {{.*}}/libc.so.6 is a {{32|64}}-bit ELF image |
| 94 | + // LIBC-NEXT: uuid: [[PREFIX:[0-9a-f]{2}]][[SUFFIX:[0-9a-f]+]] |
| 95 | + // LIBC-NEXT: debug image: /usr/lib/debug/.build-id/[[PREFIX]]/[[SUFFIX]].debug |
| 96 | + // LIBC-NEXT: .debug_info: found |
| 97 | + // LIBC-NEXT: .debug_line: found |
| 98 | + // LIBC-NEXT: .debug_abbrev: found |
| 99 | + // LIBC-NEXT: .debug_ranges: |
| 100 | + // LIBC-NEXT: .debug_str: found |
| 101 | + // LIBC-NEXT: .debug_addr: |
| 102 | + // LIBC-NEXT: .debug_str_offsets: |
| 103 | + // LIBC-NEXT: .debug_line_str: |
| 104 | + // LIBC-NEXT: .debug_rnglists: |
| 105 | + |
| 106 | + // DBGLINK: {{.*}}/fib-stripped is a {{(32|64)}}-bit ELF image |
| 107 | + // DBGLINK-NEXT: uuid: {{[0-9a-f]+}} |
| 108 | + // DBGLINK-NEXT: debug image: {{.*}}/fib.dbg |
| 109 | + // DBGLINK-NEXT: .debug_info: found |
| 110 | + // DBGLINK-NEXT: .debug_line: found |
| 111 | + // DBGLINK-NEXT: .debug_abbrev: found |
| 112 | + // DBGLINK-NEXT: .debug_ranges: not found |
| 113 | + // DBGLINK-NEXT: .debug_str: found |
| 114 | + // DBGLINK-NEXT: .debug_addr: found |
| 115 | + // DBGLINK-NEXT: .debug_str_offsets: found |
| 116 | + // DBGLINK-NEXT: .debug_line_str: found |
| 117 | + // DBGLINK-NEXT: .debug_rnglists: not found |
| 118 | + |
| 119 | + if !testElfImageAt(path: CommandLine.arguments[1]) { |
| 120 | + exit(1) |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | +} |
| 125 | + |
0 commit comments