1#!/usr/local/bin/bash
2# Copyright (C) 2014, 2015 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/test-subr.sh
19
20# See run-stack-d-test.sh for dwarfinlines.cpp source.
21testfiles testfiledwarfinlines testfiledwarfinlines.core
22
23# Depending on whether we are running make check or make installcheck
24# the actual binary name under test might be different. It is used in
25# the error message, which we also try to match.
26if test "$elfutils_testrun" = "installed"; then
27STACKCMD=${bindir}/`program_transform stack`
28else
29STACKCMD=${abs_top_builddir}/src/stack
30fi
31
32# Disable valgrind while dumping because of a bug unmapping libc.so.
33# https://bugs.kde.org/show_bug.cgi?id=327427
34SAVED_VALGRIND_CMD="$VALGRIND_CMD"
35unset VALGRIND_CMD
36
37# Compare with run-stack-d-test.sh to see the output without --inlines.
38# Only two call frames are visible (there is a jump from main to fu or
39# fubar). Explicitly use --raw so demangler support being configured in
40# doesn't change the results.
41
42# With --inlines we get all inlined calls. Note they share the same
43# address.
44testrun_compare ${abs_top_builddir}/src/stack -r -n 6 -i -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
45PID 13654 - core
46TID 13654:
47#0  0x00000000004006c8 fubar
48#1  0x00000000004006c8 foobar
49#2  0x00000000004006c8 bar
50#3  0x00000000004006c8 foo
51#4  0x00000000004006c8 _Z2fui
52#5  0x00000000004004c5 main
53$STACKCMD: tid 13654: shown max number of frames (6, use -n 0 for unlimited)
54EOF
55
56# With --source we can also see where in the source the inlined frames
57# where originally called from.
58testrun_compare ${abs_top_builddir}/src/stack -r -n 6 -s -i -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
59PID 13654 - core
60TID 13654:
61#0  0x00000000004006c8 fubar
62    /home/mark/src/tests/dwarfinlines.cpp:6
63#1  0x00000000004006c8 foobar
64    /home/mark/src/tests/dwarfinlines.cpp:14
65#2  0x00000000004006c8 bar
66    /home/mark/src/tests/dwarfinlines.cpp:21
67#3  0x00000000004006c8 foo
68    /home/mark/src/tests/dwarfinlines.cpp:27
69#4  0x00000000004006c8 _Z2fui
70    /home/mark/src/tests/dwarfinlines.cpp:33
71#5  0x00000000004004c5 main
72    /home/mark/src/tests/dwarfinlines.cpp:39
73$STACKCMD: tid 13654: shown max number of frames (6, use -n 0 for unlimited)
74EOF
75
76if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
77  VALGRIND_CMD="$SAVED_VALGRIND_CMD"
78  export VALGRIND_CMD
79fi
80
81exit 0
82