1#!/usr/local/bin/bash
2# Copyright (C) 2015, 2018 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
20testfiles debug-ranges-no-lowpc.o
21
22testrun_compare ${abs_builddir}/dwarf-ranges debug-ranges-no-lowpc.o 0xb <<\EOF
231..2 (base 0)
243..4 (base 0)
25EOF
26
27# - hello.c
28# int say (const char *prefix);
29#
30# char *
31# subject (char *word, int count)
32# {
33#    return count > 0 ? word : (word + count);
34# }
35#
36# int
37# main (int argc, char **argv)
38# {
39#    return say (subject (argv[0], argc));
40# }
41#
42# int
43# no_say (const char *prefix)
44# {
45#   const char *world = subject ("World", 42);
46#   return prefix ? say (prefix) : say (world);
47# }
48#
49# - world.c
50# char * subject (char *word, int count);
51# int no_say (const char *prefix);
52#
53# static int
54# sad (char c)
55# {
56#   return c > 0 ? c : c + 1;
57# }
58#
59# static int
60# happy (const char *w)
61# {
62#   return sad (w[1]);
63# }
64#
65# int
66# say (const char *prefix)
67# {
68#   const char *world = subject ("World", 42);;
69#   return prefix ? sad (prefix[0]) : happy (world);
70# }
71#
72# char *
73# no_subject (char *word, int count)
74# {
75#    return count > 0 ? word : (word + count);
76# }
77#
78# int
79# no_main (int argc, char **argv)
80# {
81#    return no_say (no_subject (argv[0], argc));
82# }
83#
84# - gcc -c -O2 -gdwarf-4 hello.c
85# - gcc -c -O2 -gdwarf-4 world.c
86# - gcc -o testfileranges4 -O2 -gdwarf-4 hello.o world.o
87# - eu-strip -f testfileranges4.debug testfileranges4
88
89testfiles testfileranges4.debug
90testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0xb <<\EOF
91400500..40053a (base 0)
92400400..400415 (base 0)
93EOF
94
95testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0xcd <<\EOF
96400400..400402 (base 0)
97400405..40040d (base 0)
98EOF
99
100testrun_compare ${abs_builddir}/dwarf-ranges testfileranges4.debug 0x374 <<\EOF
1014005a0..4005a2 (base 400540)
1024005a5..4005ad (base 400540)
103EOF
104
105# Like above, but with -gdwarf-5.
106testfiles testfileranges5.debug
107testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0xc <<\EOF
108401150..40117a (base 0)
109401050..401067 (base 0)
110EOF
111
112testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0x2ce <<\EOF
11340119b..40119b (base 401180)
11440119c..4011a6 (base 401180)
1154011b0..4011b4 (base 401180)
1164011b5..4011bf (base 401180)
117EOF
118
119testrun_compare ${abs_builddir}/dwarf-ranges testfileranges5.debug 0x2ef <<\EOF
12040119b..40119b (base 401180)
12140119c..4011a6 (base 401180)
1224011b4..4011b4 (base 401180)
1234011b5..4011bf (base 401180)
124EOF
125
126exit 0
127