blob: 875e0b68a442121b25de563bce08692fe87fb18e [file] [log] [blame]
Jan Kratochvil8ae9bc92013-12-02 20:54:28 +01001# Copyright (C) 2013 Red Hat, Inc.
2# This file is part of elfutils.
3#
4# This file is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# elfutils is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17. $srcdir/test-subr.sh
18
19# Verify one of the backtraced threads contains function 'main'.
20check_main()
21{
22 if grep -w main $1; then
23 return
24 fi
25 echo >&2 $2: no main
26 false
27}
28
29# Without proper ELF symbols resolution we could get inappropriate weak
30# symbol "gsignal" with the same address as the correct symbol "raise".
31# It was fixed by GIT commit 78dec228b3cfb2f9300cd0b682ebf416c9674c91 .
32# [patch] Improve ELF symbols preference (global > weak)
33# https://lists.fedorahosted.org/pipermail/elfutils-devel/2012-October/002624.html
34check_gsignal()
35{
36 if ! grep -w gsignal $1; then
37 return
38 fi
39 echo >&2 $2: found gsignal
40 false
41}
42
43# Verify the STDERR output does not contain unexpected errors.
44# In some cases we cannot reliably find out we got behind _start as some
45# operating system do not properly terminate CFI by undefined PC.
46# Ignore it here as it is a bug of OS, not a bug of elfutils.
47check_err()
48{
49 if [ $(egrep -v <$1 'dwfl_thread_getframes: (No DWARF information found|no matching address range)$' \
50 | wc -c) \
51 -eq 0 ]
52 then
53 return
54 fi
55 echo >&2 $2: neither empty nor just out of DWARF
56 false
57}
58
59check_all()
60{
61 bt=$1
62 err=$2
63 testname=$3
64 check_main $bt $testname
65 check_gsignal $bt $testname
66 check_err $err $testname
67}
68
69check_unsupported()
70{
71 err=$1
72 testname=$2
73 if grep -q ': Unwinding not supported for this architecture$' $err; then
74 echo >&2 $testname: arch not supported
75 exit 77
76 fi
Mark Wielaard225dddf2014-01-26 20:16:48 +010077
78 # ARM is special. It is supported, but it doesn't use .eh_frame by default
79 # making the native tests fail unless debuginfo (for glibc) is installed
80 # and we can fall back on .debug_frame for the CFI.
81 case "`uname -m`" in
82 arm* )
83 if grep 'dwfl_thread_getframes: No DWARF information found' $1; then
84 echo >&2 $testname: arm needs debuginfo installed for all libraries
85 exit 77
86 fi
87 ;;
88 esac
Jan Kratochvil8ae9bc92013-12-02 20:54:28 +010089}
90
91check_core()
92{
93 arch=$1
94 testfiles backtrace.$arch.{exec,core}
95 tempfiles backtrace.$arch.{bt,err}
96 echo ./backtrace ./backtrace.$arch.{exec,core}
97 testrun ${abs_builddir}/backtrace -e ./backtrace.$arch.exec --core=./backtrace.$arch.core 1>backtrace.$arch.bt 2>backtrace.$arch.err || true
98 cat backtrace.$arch.{bt,err}
Kurt Roeckx02cefda2014-04-22 21:46:22 +020099 check_unsupported backtrace.$arch.err backtrace.$arch.core
Jan Kratochvil8ae9bc92013-12-02 20:54:28 +0100100 check_all backtrace.$arch.{bt,err} backtrace.$arch.core
101}
102
103# Backtrace live process.
104# Do not abort on non-zero exit code due to some warnings of ./backtrace
105# - see function check_err.
106check_native()
107{
108 child=$1
109 tempfiles $child.{bt,err}
110 (set +ex; testrun ${abs_builddir}/backtrace --backtrace-exec=${abs_builddir}/$child 1>$child.bt 2>$child.err; true)
111 cat $child.{bt,err}
112 check_unsupported $child.err $child
113 check_all $child.{bt,err} $child
114}
115
116# Backtrace core file.
117check_native_core()
118{
119 child=$1
Mark Wielaard7fc49292013-12-13 22:42:46 +0100120
121 # Disable valgrind while dumping core.
122 SAVED_VALGRIND_CMD="$VALGRIND_CMD"
123 unset VALGRIND_CMD
124
Mark Wielaard1051a0c2014-01-04 15:41:04 +0100125 # Skip the test if we cannot adjust core ulimit.
126 core="core.`ulimit -c unlimited || exit 77; set +ex; testrun ${abs_builddir}/$child --gencore; true`"
Matthias Klosee922ec42014-01-07 10:25:29 +0100127 # see if /proc/sys/kernel/core_uses_pid is set to 0
128 if [ -f core ]; then
129 mv core "$core"
130 fi
131 if [ ! -f "$core" ]; then exit 77; fi
Mark Wielaard7fc49292013-12-13 22:42:46 +0100132
133 if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
134 VALGRIND_CMD="$SAVED_VALGRIND_CMD"
135 export VALGRIND_CMD
136 fi
137
Jan Kratochvil8ae9bc92013-12-02 20:54:28 +0100138 # Do not abort on non-zero exit code due to some warnings of ./backtrace
139 # - see function check_err.
140 tempfiles $core{,.{bt,err}}
141 (set +ex; testrun ${abs_builddir}/backtrace -e ${abs_builddir}/$child --core=$core 1>$core.bt 2>$core.err; true)
142 cat $core.{bt,err}
143 check_unsupported $core.err $child-$core
144 check_all $core.{bt,err} $child-$core
145}