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