1#! /bin/sh
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/test-subr.sh
19
20# // g++ dwarfinlines.cpp -g -o testfiledwarfinlines -O2
21# int
22# fubar (int x)
23# {
24#   __asm__ ( "nop" ::: );
25#   return 42 / x - 2;
26# }
27#
28# void foobar (int z1, int z2)
29# {
30#   __asm__ ( "nop" ::: );
31#   int x = z1 + z2;
32#   while (z1 + x + 1 != 42)
33#     x = fubar (z1 + z2 + x);
34# }
35#
36# void bar (int z)
37# {
38#   int a, b;
39#   a = b = z / 2;
40#   foobar(a, b);
41# }
42#
43# void foo (int x)
44# {
45#   if (x > 0)
46#     bar(x - 2);
47# }
48#
49# void fu (int y)
50# {
51#   __asm__ ( "nop" ::: );
52#   foo (y + 1);
53# }
54#
55# int
56# main (int argc, char **argv)
57# {
58#   fu (argc);
59# }
60testfiles testfiledwarfinlines testfiledwarfinlines.core
61
62# Depending on whether we are running make check or make installcheck
63# the actual binary name under test might be different. It is used in
64# the error message, which we also try to match.
65if test "$elfutils_testrun" = "installed"; then
66STACKCMD=${bindir}/`program_transform stack`
67else
68STACKCMD=${abs_top_builddir}/src/stack
69fi
70
71# Without -d the top function comes out as fu.
72testrun_compare ${abs_top_builddir}/src/stack -n 2 -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
73PID 13654 - core
74TID 13654:
75#0  0x00000000004006c8 fu(int)
76#1  0x00000000004004c5 main
77$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
78EOF
79
80# But when asking for source we see it is actually on line 6.
81# (Which is in function fubar, not fu).
82testrun_compare ${abs_top_builddir}/src/stack -n 2 -s -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
83PID 13654 - core
84TID 13654:
85#0  0x00000000004006c8 fu(int)
86    /home/mark/src/tests/dwarfinlines.cpp:6
87#1  0x00000000004004c5 main
88    /home/mark/src/tests/dwarfinlines.cpp:39
89$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
90EOF
91
92# So with --debugname we get the function correct as fubar.
93testrun_compare ${abs_top_builddir}/src/stack -n 2 -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
94PID 13654 - core
95TID 13654:
96#0  0x00000000004006c8 fubar
97#1  0x00000000004004c5 main
98$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
99EOF
100
101# Which now matches the source line (again 6 of course).
102testrun_compare ${abs_top_builddir}/src/stack -n 2 -s -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
103PID 13654 - core
104TID 13654:
105#0  0x00000000004006c8 fubar
106    /home/mark/src/tests/dwarfinlines.cpp:6
107#1  0x00000000004004c5 main
108    /home/mark/src/tests/dwarfinlines.cpp:39
109$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
110EOF
111
112exit 0
113