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 66 testfiles testfilegdbindex5 testfilegdbindex7 67 68 testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex5 <<\EOF 69 70 GDB 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 97 EOF 98 99 testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=gdb_index testfilegdbindex7 <<\EOF 100 101 GDB 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) 128 EOF 129 130 exit 0 131