llvm/llvm/test/tools/llvm-symbolizer/symbol-search.test

# This test checks the case when an address is specified by a symbol name rather
# than a number.
#
# It uses ELF shared object `Inputs/symbols.so` built for x86_64 using
# the instructions from `Inputs/symbols.h`.

# Show that the "CODE" command supports search by symbol name.
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so "CODE func_01" | FileCheck --check-prefix=CODE-CMD %s
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so "CODE func_01" | FileCheck --check-prefix=CODE-CMD %s
CODE-CMD: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12

# Check if a symbol name can be specified on the command-line.
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01 | FileCheck --check-prefix=SYMB %s
RUN: llvm-symbolizer -e %p/Inputs/symbols.so func_01 | FileCheck --check-prefix=SYMB %s
SYMB: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12

# Check that if a symbol has a space in its name, ignore everything from the space onwards.
RUN: llvm-addr2line -e %p/Inputs/symbols.so "func_01 ignored text" | FileCheck --check-prefix=SYMB %s
RUN: llvm-symbolizer -e %p/Inputs/symbols.so "func_01 ignored text" | FileCheck --check-prefix=SYMB %s

# Show that a symbol name may be resolved to more than one location.
RUN: llvm-addr2line -e %p/Inputs/symbols.so static_func | FileCheck --check-prefix=SYMB-MULTI %s
SYMB-MULTI:      /tmp/dbginfo{{[/\]+}}symbols.part3.c:4
SYMB-MULTI-NEXT: /tmp/dbginfo{{[/\]+}}symbols.part4.c:4

# Show that if a symbol is not found, a special mark is printed.
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_666 | FileCheck --check-prefix=NONEXISTENT %s
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_666 | FileCheck --check-prefix=NONEXISTENT %s
NONEXISTENT: ??

# Show that more than one symbol may be specified.
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01 func_02 | FileCheck --check-prefix=FUNCS %s
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01 func_02 | FileCheck --check-prefix=FUNCS %s
FUNCS:  /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12
FUNCS:  /tmp/dbginfo{{[/\]+}}symbols.part2.cpp:10

# Symbol may be combined with offset.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+0 | FileCheck --check-prefix=SYMLINE0 %s
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01+0 | FileCheck --check-prefix=SYMLINE0 %s
SYMLINE0: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12

RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+12 | FileCheck --check-prefix=SYMLINE1 %s
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01+12 | FileCheck --check-prefix=SYMLINE1 %s
SYMLINE1: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:13

RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+19 | FileCheck --check-prefix=SYMLINE2 %s
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01+19 | FileCheck --check-prefix=SYMLINE2 %s
SYMLINE2: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:14

# Offset can be specified with various bases.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+0x0C | FileCheck --check-prefix=SYMLINE1 %s
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01+0x0C | FileCheck --check-prefix=SYMLINE1 %s

RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+014 | FileCheck --check-prefix=SYMLINE1 %s
RUN: llvm-addr2line -e %p/Inputs/symbols.so func_01+014 | FileCheck --check-prefix=SYMLINE1 %s

# If '+' is not followed by a number, it is part of the symbol name, not an offset separator.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+ | FileCheck --check-prefix=NONEXISTENT %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+ | FileCheck --check-prefix=NONEXISTENT %s

RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+abc | FileCheck --check-prefix=NONEXISTENT %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+abc | FileCheck --check-prefix=NONEXISTENT %s

RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-prefix=NONEXISTENT %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so func_01+0A | FileCheck --check-prefix=NONEXISTENT %s

# If '+' is not preceded by a symbol, it is part of a symbol name, not an offset separator.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so +0x1138 | FileCheck --check-prefix=NONEXISTENT %s

# Show that C++ mangled names may be specified.
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so _ZL14static_func_01i | FileCheck --check-prefix=MULTI-CXX %s
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so _ZL14static_func_01i | FileCheck --check-prefix=MULTI-CXX %s
MULTI-CXX: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:7
MULTI-CXX: /tmp/dbginfo{{[/\]+}}symbols.part2.cpp:5

# Show that containing function name can be printed in mangled form.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so --no-demangle _Z7func_04i | FileCheck --check-prefix=MANGLED %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so -f _Z7func_04i | FileCheck --check-prefix=MANGLED %s
MANGLED: _Z7func_04i
MANGLED-NEXT: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:22

# Show that containing function name can be printed in demangled form.
RUN: llvm-symbolizer --obj=%p/Inputs/symbols.so _Z7func_04i | FileCheck --check-prefix=NOTMANGLED %s
RUN: llvm-addr2line --obj=%p/Inputs/symbols.so -f --demangle _Z7func_04i | FileCheck --check-prefix=NOTMANGLED %s
NOTMANGLED: func_04(int)
NOTMANGLED-NEXT: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:22

# Show that both the symbol and input file can be specified in the search string on the command-line.
RUN: llvm-addr2line "%p/Inputs/symbols.so func_01" | FileCheck --check-prefix=SYMBIN %s
RUN: llvm-symbolizer "%p/Inputs/symbols.so func_01" | FileCheck --check-prefix=SYMBIN %s
SYMBIN: /tmp/dbginfo{{[/\]+}}symbols.part1.cpp:12

# Show that the case of missing input file specified in the search string on the command-line is properly treated.
RUN: llvm-addr2line "%p/Inputs/666.so func_01" 2> %t.1.stderr | FileCheck --check-prefix=NONEXISTENT %s
RUN: FileCheck --input-file=%t.1.stderr --check-prefix=BINARY-NOT-FOUND -DMSG=%errc_ENOENT %s
RUN: llvm-symbolizer "%p/Inputs/666.so func_01" 2> %t.2.stderr | FileCheck --check-prefix=NONEXISTENT %s
RUN: FileCheck --input-file=%t.2.stderr --check-prefix=BINARY-NOT-FOUND -DMSG=%errc_ENOENT %s
BINARY-NOT-FOUND: error: '{{.*}}666.so': [[MSG]]