1#! /bin/bash
2# Copyright (C) 2014 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/backtrace-subr.sh
19
20tempfiles deleted deleted-lib.so
21cp -p ${abs_builddir}/deleted ${abs_builddir}/deleted-lib.so .
22
23# We don't want to run the deleted process under valgrind then
24# stack will see the valgrind process backtrace.
25OLD_VALGRIND_CMD="$VALGRIND_CMD"
26unset VALGRIND_CMD
27
28pid=$(testrun ${abs_builddir}/deleted)
29sleep 1
30rm -f deleted deleted-lib.so
31tempfiles bt bt.err
32
33set VALGRIND_CMD="$OLD_VALGRIND_CMD"
34# It may have non-zero exit code with:
35# .../elfutils/src/stack: dwfl_thread_getframes tid 26376 at 0x4006c8 in .../elfutils/tests/deleted: no matching address range
36testrun ${abs_top_builddir}/src/stack -p $pid 1>bt 2>bt.err || true
37cat bt bt.err
38kill -9 $pid
39wait
40check_native_unsupported bt.err deleted
41if grep -q -E ': dwfl_linux_proc_attach pid ([[:digit:]]+): Function not implemented$' bt.err; then
42  echo >&2 deleted: OS not supported
43  exit 77
44fi
45# For PPC64 we need access to the OPD table which we get through the shdrs
46# (see backends/ppc64_init.c) but for the deleted-lib we only have phdrs.
47# So we don't have the name of the function. But since we should find
48# the EH_FRAME through phdrs just fine, we can unwind into main.
49if test "`uname -m`" != "ppc64"; then
50  grep -qw libfunc bt
51fi
52grep -qw main bt
53