xref: /aosp_15_r20/external/elfutils/tests/run-stack-d-test.sh (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker#! /bin/sh
2*7304104dSAndroid Build Coastguard Worker# Copyright (C) 2014, 2015 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/test-subr.sh
19*7304104dSAndroid Build Coastguard Worker
20*7304104dSAndroid Build Coastguard Worker# // g++ dwarfinlines.cpp -g -o testfiledwarfinlines -O2
21*7304104dSAndroid Build Coastguard Worker# int
22*7304104dSAndroid Build Coastguard Worker# fubar (int x)
23*7304104dSAndroid Build Coastguard Worker# {
24*7304104dSAndroid Build Coastguard Worker#   __asm__ ( "nop" ::: );
25*7304104dSAndroid Build Coastguard Worker#   return 42 / x - 2;
26*7304104dSAndroid Build Coastguard Worker# }
27*7304104dSAndroid Build Coastguard Worker#
28*7304104dSAndroid Build Coastguard Worker# void foobar (int z1, int z2)
29*7304104dSAndroid Build Coastguard Worker# {
30*7304104dSAndroid Build Coastguard Worker#   __asm__ ( "nop" ::: );
31*7304104dSAndroid Build Coastguard Worker#   int x = z1 + z2;
32*7304104dSAndroid Build Coastguard Worker#   while (z1 + x + 1 != 42)
33*7304104dSAndroid Build Coastguard Worker#     x = fubar (z1 + z2 + x);
34*7304104dSAndroid Build Coastguard Worker# }
35*7304104dSAndroid Build Coastguard Worker#
36*7304104dSAndroid Build Coastguard Worker# void bar (int z)
37*7304104dSAndroid Build Coastguard Worker# {
38*7304104dSAndroid Build Coastguard Worker#   int a, b;
39*7304104dSAndroid Build Coastguard Worker#   a = b = z / 2;
40*7304104dSAndroid Build Coastguard Worker#   foobar(a, b);
41*7304104dSAndroid Build Coastguard Worker# }
42*7304104dSAndroid Build Coastguard Worker#
43*7304104dSAndroid Build Coastguard Worker# void foo (int x)
44*7304104dSAndroid Build Coastguard Worker# {
45*7304104dSAndroid Build Coastguard Worker#   if (x > 0)
46*7304104dSAndroid Build Coastguard Worker#     bar(x - 2);
47*7304104dSAndroid Build Coastguard Worker# }
48*7304104dSAndroid Build Coastguard Worker#
49*7304104dSAndroid Build Coastguard Worker# void fu (int y)
50*7304104dSAndroid Build Coastguard Worker# {
51*7304104dSAndroid Build Coastguard Worker#   __asm__ ( "nop" ::: );
52*7304104dSAndroid Build Coastguard Worker#   foo (y + 1);
53*7304104dSAndroid Build Coastguard Worker# }
54*7304104dSAndroid Build Coastguard Worker#
55*7304104dSAndroid Build Coastguard Worker# int
56*7304104dSAndroid Build Coastguard Worker# main (int argc, char **argv)
57*7304104dSAndroid Build Coastguard Worker# {
58*7304104dSAndroid Build Coastguard Worker#   fu (argc);
59*7304104dSAndroid Build Coastguard Worker# }
60*7304104dSAndroid Build Coastguard Workertestfiles testfiledwarfinlines testfiledwarfinlines.core
61*7304104dSAndroid Build Coastguard Worker
62*7304104dSAndroid Build Coastguard Worker# Depending on whether we are running make check or make installcheck
63*7304104dSAndroid Build Coastguard Worker# the actual binary name under test might be different. It is used in
64*7304104dSAndroid Build Coastguard Worker# the error message, which we also try to match.
65*7304104dSAndroid Build Coastguard Workerif test "$elfutils_testrun" = "installed"; then
66*7304104dSAndroid Build Coastguard WorkerSTACKCMD=${bindir}/`program_transform stack`
67*7304104dSAndroid Build Coastguard Workerelse
68*7304104dSAndroid Build Coastguard WorkerSTACKCMD=${abs_top_builddir}/src/stack
69*7304104dSAndroid Build Coastguard Workerfi
70*7304104dSAndroid Build Coastguard Worker
71*7304104dSAndroid Build Coastguard Worker# Disable valgrind while dumping because of a bug unmapping libc.so.
72*7304104dSAndroid Build Coastguard Worker# https://bugs.kde.org/show_bug.cgi?id=327427
73*7304104dSAndroid Build Coastguard WorkerSAVED_VALGRIND_CMD="$VALGRIND_CMD"
74*7304104dSAndroid Build Coastguard Workerunset VALGRIND_CMD
75*7304104dSAndroid Build Coastguard Worker
76*7304104dSAndroid Build Coastguard Worker# Without -d the top function comes out as fu. Use --raw to not demangle.
77*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/stack -r -n 2 -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
78*7304104dSAndroid Build Coastguard WorkerPID 13654 - core
79*7304104dSAndroid Build Coastguard WorkerTID 13654:
80*7304104dSAndroid Build Coastguard Worker#0  0x00000000004006c8 _Z2fui
81*7304104dSAndroid Build Coastguard Worker#1  0x00000000004004c5 main
82*7304104dSAndroid Build Coastguard Worker$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
83*7304104dSAndroid Build Coastguard WorkerEOF
84*7304104dSAndroid Build Coastguard Worker
85*7304104dSAndroid Build Coastguard Worker# But when asking for source we see it is actually on line 6.
86*7304104dSAndroid Build Coastguard Worker# (Which is in function fubar, not fu). Use --raw to not demangle.
87*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/stack -r -n 2 -s -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
88*7304104dSAndroid Build Coastguard WorkerPID 13654 - core
89*7304104dSAndroid Build Coastguard WorkerTID 13654:
90*7304104dSAndroid Build Coastguard Worker#0  0x00000000004006c8 _Z2fui
91*7304104dSAndroid Build Coastguard Worker    /home/mark/src/tests/dwarfinlines.cpp:6
92*7304104dSAndroid Build Coastguard Worker#1  0x00000000004004c5 main
93*7304104dSAndroid Build Coastguard Worker    /home/mark/src/tests/dwarfinlines.cpp:39
94*7304104dSAndroid Build Coastguard Worker$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
95*7304104dSAndroid Build Coastguard WorkerEOF
96*7304104dSAndroid Build Coastguard Worker
97*7304104dSAndroid Build Coastguard Worker# So with --debugname we get the function correct as fubar.
98*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/stack -n 2 -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
99*7304104dSAndroid Build Coastguard WorkerPID 13654 - core
100*7304104dSAndroid Build Coastguard WorkerTID 13654:
101*7304104dSAndroid Build Coastguard Worker#0  0x00000000004006c8 fubar
102*7304104dSAndroid Build Coastguard Worker#1  0x00000000004004c5 main
103*7304104dSAndroid Build Coastguard Worker$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
104*7304104dSAndroid Build Coastguard WorkerEOF
105*7304104dSAndroid Build Coastguard Worker
106*7304104dSAndroid Build Coastguard Worker# Which now matches the source line (again 6 of course).
107*7304104dSAndroid Build Coastguard Workertestrun_compare ${abs_top_builddir}/src/stack -n 2 -s -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
108*7304104dSAndroid Build Coastguard WorkerPID 13654 - core
109*7304104dSAndroid Build Coastguard WorkerTID 13654:
110*7304104dSAndroid Build Coastguard Worker#0  0x00000000004006c8 fubar
111*7304104dSAndroid Build Coastguard Worker    /home/mark/src/tests/dwarfinlines.cpp:6
112*7304104dSAndroid Build Coastguard Worker#1  0x00000000004004c5 main
113*7304104dSAndroid Build Coastguard Worker    /home/mark/src/tests/dwarfinlines.cpp:39
114*7304104dSAndroid Build Coastguard Worker$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
115*7304104dSAndroid Build Coastguard WorkerEOF
116*7304104dSAndroid Build Coastguard Worker
117*7304104dSAndroid Build Coastguard Workerif [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
118*7304104dSAndroid Build Coastguard Worker  VALGRIND_CMD="$SAVED_VALGRIND_CMD"
119*7304104dSAndroid Build Coastguard Worker  export VALGRIND_CMD
120*7304104dSAndroid Build Coastguard Workerfi
121*7304104dSAndroid Build Coastguard Worker
122*7304104dSAndroid Build Coastguard Workerexit 0
123