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