pdb-relative-source-lines.test 4.31 KB
Test the linker line tables on roughly the following example:

==> foo.h <==
void bar(void);
inline void foo(void) {
  bar();
}
==> pdb_lines_1.c <==
#include "foo.h"
int main(void) {
  foo();
  return 42;
}
==> pdb_lines_2.c <==
void bar(void) {
}

$ clang-cl -Xclang -fdebug-compilation-dir -Xclang . -c -Z7 pdb_lines*.c

/pdbsourcepath: only sets the directory that relative paths are considered
relative to, so this test needs to pass relative paths to lld-link for:
1. The input obj files
2. The /pdb: switch
3. The lld-link invocation itself
To achieve this, put all inputs of the lld-link invocation (including lld-link
itself) in a temp directory that's cwd and then make sure to only use relative
arguments when calling ./lld-link below.
RUN: rm -rf %t
RUN: mkdir %t
RUN: cp lld-link %t/lld-link
RUN: cd %t

RUN: yaml2obj %S/Inputs/pdb_lines_1_relative.yaml -o %t/pdb_lines_1_relative.obj
RUN: yaml2obj %S/Inputs/pdb_lines_2_relative.yaml -o %t/pdb_lines_2_relative.obj
RUN: ./lld-link -debug "-pdbsourcepath:c:\src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck %s
RUN: ./lld-link -debug "-pdbsourcepath:/usr/src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=POSIX %s

CHECK-LABEL:  - Module:          'c:\src\pdb_lines_1_relative.obj'
CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_1_relative.obj'
CHECK:          SourceFiles:
CHECK-NEXT:       - 'c:\src\pdb_lines_1.c'
CHECK-NEXT:       - 'c:\src\foo.h'
CHECK:          Subsections:
CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
CHECK:                - FileName:        'c:\src\foo.h'
CHECK:            - !FileChecksums
CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
CHECK:                - FileName:        'c:\src\foo.h'

CHECK-LABEL:  - Module:          'c:\src\pdb_lines_2_relative.obj'
CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_2_relative.obj'
CHECK:          SourceFiles:
CHECK-NEXT:       - 'c:\src\pdb_lines_2.c'
CHECK:          Subsections:
CHECK:                - FileName:        'c:\src\pdb_lines_2.c'
CHECK:            - !FileChecksums
CHECK:                - FileName:        'c:\src\pdb_lines_2.c'

CHECK-LABEL:  - Kind:            S_ENVBLOCK
CHECK-NEXT:     EnvBlockSym:     
CHECK-NEXT:       Entries:     
CHECK-NEXT:         - cwd
CHECK-NEXT:         - 'c:\src'
CHECK-NEXT:         - exe
CHECK-NEXT:         - 'c:\src\lld-link'
CHECK-NEXT:         - pdb 
CHECK-NEXT:         - 'c:\src\out.pdb'
CHECK-NEXT:         - cmd
CHECK-NEXT:         - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'


POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_1_relative.obj'
POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_1_relative.obj'
POSIX:          SourceFiles:
POSIX-NEXT:       - '/usr/src/pdb_lines_1.c'
POSIX-NEXT:       - '/usr/src/foo.h'
POSIX:          Subsections:
POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
POSIX:                - FileName:        '/usr/src/foo.h'
POSIX:            - !FileChecksums
POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
POSIX:                - FileName:        '/usr/src/foo.h'

POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_2_relative.obj'
POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_2_relative.obj'
POSIX:          SourceFiles:
POSIX-NEXT:       - '/usr/src/pdb_lines_2.c'
POSIX:          Subsections:
POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'
POSIX:            - !FileChecksums
POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'

POSIX-LABEL:  - Kind:            S_ENVBLOCK
POSIX-NEXT:     EnvBlockSym:     
POSIX-NEXT:       Entries:     
POSIX-NEXT:         - cwd
POSIX-NEXT:         - '/usr/src'
POSIX-NEXT:         - exe
POSIX-NEXT:         - '/usr/src/lld-link'
POSIX-NEXT:         - pdb 
POSIX-NEXT:         - '/usr/src/out.pdb'
POSIX-NEXT:         - cmd
POSIX-NEXT:         - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'