• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
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# // 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# Disable valgrind while dumping because of a bug unmapping libc.so.
72# https://bugs.kde.org/show_bug.cgi?id=327427
73SAVED_VALGRIND_CMD="$VALGRIND_CMD"
74unset VALGRIND_CMD
75
76# Without -d the top function comes out as fu. Use --raw to not demangle.
77testrun_compare ${abs_top_builddir}/src/stack -r -n 2 -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
78PID 13654 - core
79TID 13654:
80#0  0x00000000004006c8 _Z2fui
81#1  0x00000000004004c5 main
82$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
83EOF
84
85# But when asking for source we see it is actually on line 6.
86# (Which is in function fubar, not fu). Use --raw to not demangle.
87testrun_compare ${abs_top_builddir}/src/stack -r -n 2 -s -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
88PID 13654 - core
89TID 13654:
90#0  0x00000000004006c8 _Z2fui
91    /home/mark/src/tests/dwarfinlines.cpp:6
92#1  0x00000000004004c5 main
93    /home/mark/src/tests/dwarfinlines.cpp:39
94$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
95EOF
96
97# So with --debugname we get the function correct as fubar.
98testrun_compare ${abs_top_builddir}/src/stack -n 2 -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
99PID 13654 - core
100TID 13654:
101#0  0x00000000004006c8 fubar
102#1  0x00000000004004c5 main
103$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
104EOF
105
106# Which now matches the source line (again 6 of course).
107testrun_compare ${abs_top_builddir}/src/stack -n 2 -s -d -e testfiledwarfinlines --core testfiledwarfinlines.core<<EOF
108PID 13654 - core
109TID 13654:
110#0  0x00000000004006c8 fubar
111    /home/mark/src/tests/dwarfinlines.cpp:6
112#1  0x00000000004004c5 main
113    /home/mark/src/tests/dwarfinlines.cpp:39
114$STACKCMD: tid 13654: shown max number of frames (2, use -n 0 for unlimited)
115EOF
116
117if [ "x$SAVED_VALGRIND_CMD" != "x" ]; then
118  VALGRIND_CMD="$SAVED_VALGRIND_CMD"
119  export VALGRIND_CMD
120fi
121
122exit 0
123