Mark Wielaard | 6c4b207 | 2013-01-30 11:04:38 +0100 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # Copyright (C) 2013 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 | # - hello.c |
| 21 | # int say (const char *prefix); |
| 22 | # |
| 23 | # static char * |
| 24 | # subject (char *word, int count) |
| 25 | # { |
| 26 | # return count > 0 ? word : (word + count); |
| 27 | # } |
| 28 | # |
| 29 | # int |
| 30 | # main (int argc, char **argv) |
| 31 | # { |
| 32 | # return say (subject (argv[0], argc)); |
| 33 | # } |
| 34 | # |
| 35 | # - world.c |
| 36 | # static int |
| 37 | # sad (char c) |
| 38 | # { |
| 39 | # return c > 0 ? c : c + 1; |
| 40 | # } |
| 41 | # |
| 42 | # static int |
| 43 | # happy (const char *w) |
| 44 | # { |
| 45 | # return sad (w[1]); |
| 46 | # } |
| 47 | # |
| 48 | # int |
| 49 | # say (const char *prefix) |
| 50 | # { |
| 51 | # const char *world = "World"; |
| 52 | # return prefix ? sad (prefix[0]) : happy (world); |
| 53 | # } |
| 54 | # |
| 55 | # gcc -g -O2 -c hello.c |
| 56 | # gcc -g -O2 -c world.c |
| 57 | # gcc -g -o testfileloc hello.o world.o |
| 58 | |
| 59 | testfiles testfileloc |
| 60 | |
| 61 | # Process values as offsets from base addresses and resolve to symbols. |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 62 | testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ranges \ |
Mark Wielaard | 6c4b207 | 2013-01-30 11:04:38 +0100 | [diff] [blame] | 63 | testfileloc<<\EOF |
| 64 | |
| 65 | DWARF section [33] '.debug_loc' at offset 0xd2a: |
| 66 | [ 0] 0x0000000000400480 <main>..0x000000000040048d <main+0xd> [ 0] reg5 |
| 67 | [ 23] 0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [ 0] reg5 |
| 68 | [ 46] 0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0 |
| 69 | |
| 70 | DWARF section [34] '.debug_ranges' at offset 0xd94: |
| 71 | [ 0] 0x0000000000400480 <main>..0x0000000000400482 <main+0x2> |
| 72 | 0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> |
| 73 | [ 30] 0x00000000004004ad <say+0xd>..0x00000000004004af <say+0xf> |
| 74 | 0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> |
| 75 | EOF |
| 76 | |
| 77 | # Don't resolve addresses to symbols. |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 78 | testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump=ranges \ |
Mark Wielaard | 6c4b207 | 2013-01-30 11:04:38 +0100 | [diff] [blame] | 79 | testfileloc<<\EOF |
| 80 | |
| 81 | DWARF section [33] '.debug_loc' at offset 0xd2a: |
| 82 | [ 0] 0x0000000000400480..0x000000000040048d [ 0] reg5 |
| 83 | [ 23] 0x0000000000400485..0x000000000040048d [ 0] reg5 |
| 84 | [ 46] 0x00000000004004b2..0x00000000004004ba [ 0] breg5 0 |
| 85 | |
| 86 | DWARF section [34] '.debug_ranges' at offset 0xd94: |
| 87 | [ 0] 0x0000000000400480..0x0000000000400482 |
| 88 | 0x0000000000400485..0x000000000040048d |
| 89 | [ 30] 0x00000000004004ad..0x00000000004004af |
| 90 | 0x00000000004004b2..0x00000000004004ba |
| 91 | EOF |
| 92 | |
| 93 | # Produce "raw" unprocessed content. |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 94 | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump=ranges \ |
Mark Wielaard | 6c4b207 | 2013-01-30 11:04:38 +0100 | [diff] [blame] | 95 | testfileloc<<\EOF |
| 96 | |
| 97 | DWARF section [33] '.debug_loc' at offset 0xd2a: |
| 98 | [ 0] 000000000000000000..0x000000000000000d [ 0] reg5 |
| 99 | [ 23] 0x0000000000000005..0x000000000000000d [ 0] reg5 |
| 100 | [ 46] 0x0000000000000012..0x000000000000001a [ 0] breg5 0 |
| 101 | |
| 102 | DWARF section [34] '.debug_ranges' at offset 0xd94: |
| 103 | [ 0] 000000000000000000..0x0000000000000002 |
| 104 | 0x0000000000000005..0x000000000000000d |
| 105 | [ 30] 0x000000000000000d..0x000000000000000f |
| 106 | 0x0000000000000012..0x000000000000001a |
| 107 | EOF |
| 108 | |
| 109 | exit 0 |