1#! /bin/sh 2# Copyright (C) 2012 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# common.h 21# struct foo 22# { 23# const char *bar; 24# }; 25# 26# extern char *global; 27# int say (struct foo *prefix); 28 29# hello.c 30# #include "common.h" 31# 32# static char *hello = "Hello"; 33# 34# int 35# main (int argc, char **argv) 36# { 37# struct foo baz; 38# global = hello; 39# baz.bar = global; 40# return say(&baz); 41# } 42 43# world.c 44# #include "common.h" 45# 46# char *global; 47# 48# static int hello (const char *bar) 49# { 50# return bar == global; 51# } 52# 53# int 54# say (struct foo *prefix) 55# { 56# return hello (prefix->bar); 57# } 58 59# gcc -g -fdebug-types-section -c hello.c 60# gcc -g -fdebug-types-section -c world.c 61# gcc -g -fdebug-types-section -o testfilegdbindex7 hello.o world.o 62# gdb testfilegdbindex7 63# (gdb) save gdb-index . 64# objcopy --add-section .gdb_index=testfilegdbindex7.gdb-index --set-section-flags .gdb_index=readonly testfilegdbindex7 testfilegdbindex7 65 66testfiles testfilegdbindex5 testfilegdbindex7 testfilegdbindex9 testfilegdbindex9-no-maininfo 67 68testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex5 <<\EOF 69 70GDB section [33] '.gdb_index' at offset 0xe76 contains 8383 bytes : 71 Version: 5 72 CU offset: 0x18 73 TU offset: 0x38 74 address offset: 0x50 75 symbol offset: 0x78 76 constant offset: 0x2078 77 78 CU list at offset 0x18 contains 2 entries: 79 [ 0] start: 00000000, length: 184 80 [ 1] start: 0x0000b8, length: 204 81 82 TU list at offset 0x38 contains 1 entries: 83 [ 0] CU offset: 0, type offset: 29, signature: 0x87e03f92cc37cdf0 84 85 Address list at offset 0x50 contains 2 entries: 86 [ 0] 0x000000000040049c <main>..0x00000000004004d1 <main+0x35>, CU index: 0 87 [ 1] 0x00000000004004d4 <hello>..0x000000000040050b <say+0x1c>, CU index: 1 88 89 Symbol table at offset 0x50 contains 1024 slots: 90 [ 123] symbol: global, CUs: 1 91 [ 489] symbol: main, CUs: 0 92 [ 518] symbol: char, CUs: 0 93 [ 661] symbol: foo, CUs: 0T 94 [ 741] symbol: hello, CUs: 0, 1 95 [ 746] symbol: say, CUs: 1 96 [ 754] symbol: int, CUs: 0 97EOF 98 99testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex7 <<\EOF 100 101GDB section [33] '.gdb_index' at offset 0xe76 contains 8399 bytes : 102 Version: 7 103 CU offset: 0x18 104 TU offset: 0x38 105 address offset: 0x50 106 symbol offset: 0x78 107 constant offset: 0x2078 108 109 CU list at offset 0x18 contains 2 entries: 110 [ 0] start: 00000000, length: 184 111 [ 1] start: 0x0000b8, length: 204 112 113 TU list at offset 0x38 contains 1 entries: 114 [ 0] CU offset: 0, type offset: 29, signature: 0x87e03f92cc37cdf0 115 116 Address list at offset 0x50 contains 2 entries: 117 [ 0] 0x000000000040049c <main>..0x00000000004004d1 <main+0x35>, CU index: 0 118 [ 1] 0x00000000004004d4 <hello>..0x000000000040050b <say+0x1c>, CU index: 1 119 120 Symbol table at offset 0x50 contains 1024 slots: 121 [ 123] symbol: global, CUs: 1 (var:G) 122 [ 489] symbol: main, CUs: 0 (func:G) 123 [ 518] symbol: char, CUs: 0 (type:S) 124 [ 661] symbol: foo, CUs: 0T (type:S) 125 [ 741] symbol: hello, CUs: 0 (var:S), 1 (func:S) 126 [ 746] symbol: say, CUs: 1 (func:G) 127 [ 754] symbol: int, CUs: 0 (type:S) 128EOF 129 130# testfilegdbindex9-no-maininfo is built the same way as testfilegdbindex7. 131testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex9-no-maininfo <<\EOF 132 133GDB section [33] '.gdb_index' at offset 0x38e1 contains 8415 bytes : 134 Version: 9 135 CU offset: 0x1c 136 TU offset: 0x3c 137 address offset: 0x54 138 symbol offset: 0x7c 139 shortcut offset: 0x207c 140 constant offset: 0x2084 141 142 CU list at offset 0x1c contains 2 entries: 143 [ 0] start: 0x00004c, length: 220 144 [ 1] start: 0x000128, length: 214 145 146 TU list at offset 0x3c contains 1 entries: 147 [ 0] CU offset: 0, type offset: 30, signature: 0x87e03f92cc37cdf0 148 149 Address list at offset 0x54 contains 2 entries: 150 [ 0] 0x0000000000401106 <main>..0x000000000040113b <main+0x35>, CU index: 1 151 [ 1] 0x000000000040113c <hello>..0x0000000000401173 <say+0x1c>, CU index: 2 152 153 Symbol table at offset 0x54 contains 1024 slots: 154 [ 123] symbol: global, CUs: 1 (var:G), 0T (var:G) 155 [ 489] symbol: main, CUs: 1 (func:G) 156 [ 518] symbol: char, CUs: 0 (type:S) 157 [ 661] symbol: foo, CUs: 0 (type:S) 158 [ 741] symbol: hello, CUs: 1 (var:S), 0T (func:S) 159 [ 746] symbol: say, CUs: 0T (func:G) 160 [ 754] symbol: int, CUs: 1 (type:S) 161 162Shortcut table at offset 0x207c contains 2 slots: 163Language of main: ??? (0) 164Name of main: <unknown> 165EOF 166 167# testfilegdbindex9.f90 168# 169# program repro 170# type small_stride 171# character*40 long_string 172# integer small_pad 173# end type small_stride 174# type(small_stride), dimension (20), target :: unpleasant 175# character*40, pointer, dimension(:):: c40pt 176# integer i 177# do i = 0,19 178# unpleasant(i+1)%small_pad = i+1 179# unpleasant(i+1)%long_string = char (ichar('0') + i) 180# end do 181# c40pt => unpleasant%long_string 182# print *, c40pt 183#end program repro 184 185# gfortran -g -o testfilegdbindex9 testfilegdbindex9.f90 186# gdb-add-index testfilegdbindex9 187 188testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex9 <<\EOF 189 190GDB section [35] '.gdb_index' at offset 0x37d9 contains 8395 bytes : 191 Version: 9 192 CU offset: 0x1c 193 TU offset: 0x2c 194 address offset: 0x2c 195 symbol offset: 0x40 196 shortcut offset: 0x2040 197 constant offset: 0x2048 198 199 CU list at offset 0x1c contains 1 entries: 200 [ 0] start: 00000000, length: 307 201 202 TU list at offset 0x2c contains 0 entries: 203 204 Address list at offset 0x2c contains 1 entries: 205 [ 0] 0x0000000000401166 <MAIN__>..0x00000000004013f0 <main+0x3a>, CU index: 0 206 207 Symbol table at offset 0x2c contains 1024 slots: 208 [ 61] symbol: small_stride, CUs: 0 (type:S) 209 [ 71] symbol: integer(kind=8), CUs: 0 (type:S) 210 [ 161] symbol: character(kind=1), CUs: 0 (type:S) 211 [ 397] symbol: unpleasant, CUs: 0 (var:S) 212 [ 489] symbol: main, CUs: 0 (func:G) 213 [ 827] symbol: integer(kind=4), CUs: 0 (type:S) 214 [ 858] symbol: c40pt, CUs: 0 (var:S) 215 [ 965] symbol: repro, CUs: 0 (func:S) 216 [1016] symbol: i, CUs: 0 (var:S) 217 218Shortcut table at offset 0x2040 contains 2 slots: 219Language of main: Fortran08 220Name of main: repro 221EOF 222 223exit 0 224