Home | History | Annotate | Download | only in tests
      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 # Tests readelf --debug-dump=aranges and --debug-dump=decodedaranges
     21 #
     22 # - foobarbaz.h
     23 #
     24 # int bar ();
     25 # int baz (int i);
     26 #
     27 # - bar.c
     28 #
     29 # #include "foobarbaz.h"
     30 #
     31 # static int bi;
     32 #
     33 # static int
     34 # barbaz (int i)
     35 # {
     36 #   return i * 2 - 1;
     37 # }
     38 #
     39 # __attribute__ ((constructor)) void
     40 # nobar ()
     41 # {
     42 #   bi = 1;
     43 # }
     44 #
     45 # int
     46 # bar ()
     47 # {
     48 #   bi++;
     49 #   return barbaz (bi);
     50 # }
     51 #
     52 # - foo.c
     53 #
     54 # include "foobarbaz.h"
     55 #
     56 # static int fi = 0;
     57 #
     58 # static int
     59 # foo (int i, int j)
     60 # {
     61 #   if (i > j)
     62 #     return i - j + fi;
     63 #   else
     64 #     return (2 * j) - i + fi;
     65 # }
     66 #
     67 # int
     68 # main (int argc, char **argv)
     69 # {
     70 #   int a = bar ();
     71 #   int b = baz (a + argc);
     72 #   int r = foo (a, b) - 1;
     73 #
     74 #   return r - 48;
     75 # }
     76 #
     77 # - baz.c
     78 # include "foobarbaz.h"
     79 #
     80 # static int bj;
     81 #
     82 # static int
     83 # bazbaz (int j)
     84 # {
     85 #   return bj * j - bar ();
     86 # }
     87 #
     88 # __attribute__ ((constructor)) void
     89 # nobaz ()
     90 # {
     91 #   bj = 1;
     92 # }
     93 #
     94 # int
     95 # baz (int i)
     96 # {
     97 #   if (i < 0)
     98 #     return bazbaz (i);
     99 #   else
    100 #     {
    101 #       while (i-- > 0)
    102 #         bj += bar ();
    103 #     }
    104 #   return bazbaz (i);
    105 # }
    106 #
    107 # gcc -g -O2 -m32 -c baz.c
    108 # gcc -g -O2 -m32 -c bar.c
    109 # gcc -g -O2 -m32 -c foo.c
    110 # gcc -g -O2 -m32 -o testfilefoobarbaz foo.o bar.o baz.o
    111 
    112 testfiles testfilefoobarbaz
    113 
    114 testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=aranges testfilefoobarbaz <<EOF
    115 
    116 DWARF section [27] '.debug_aranges' at offset 0x1044:
    117 
    118 Table at offset 0:
    119 
    120  Length:            28
    121  DWARF version:      2
    122  CU offset:          0
    123  Address size:       4
    124  Segment size:       0
    125 
    126    0x080482f0 <main>..0x08048323 <main+0x33>
    127 
    128 Table at offset 32:
    129 
    130  Length:            36
    131  DWARF version:      2
    132  CU offset:        136
    133  Address size:       4
    134  Segment size:       0
    135 
    136    0x08048440 <bar>..0x08048451 <bar+0x11>
    137    0x08048330 <nobar>..0x0804833a <nobar+0xa>
    138 
    139 Table at offset 72:
    140 
    141  Length:            36
    142  DWARF version:      2
    143  CU offset:        1d1
    144  Address size:       4
    145  Segment size:       0
    146 
    147    0x08048460 <baz>..0x080484bb <baz+0x5b>
    148    0x08048340 <nobaz>..0x0804834a <nobaz+0xa>
    149 EOF
    150 
    151 testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedaranges testfilefoobarbaz <<\EOF
    152 
    153 DWARF section [27] '.debug_aranges' at offset 0x1044 contains 5 entries:
    154  [0] start: 0x080482f0, length:    52, CU DIE offset:     11
    155  [1] start: 0x08048330, length:    11, CU DIE offset:    321
    156  [2] start: 0x08048340, length:    11, CU DIE offset:    476
    157  [3] start: 0x08048440, length:    18, CU DIE offset:    321
    158  [4] start: 0x08048460, length:    92, CU DIE offset:    476
    159 EOF
    160 
    161 exit 0
    162