1# Copyright 2002, 2003 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 17# Please email any bugs, comments, and/or additions to this file to: 18# bug-gdb@prep.ai.mit.edu 19 20# relocate.exp -- Expect script to test loading symbols from unrelocated 21# object files. 22 23if $tracelevel then { 24 strace $tracelevel 25} 26 27set testfile relocate 28set srcfile ${testfile}.c 29set binfile ${objdir}/${subdir}/${testfile}.o 30 31remote_exec build "rm -f ${binfile}" 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } { 33 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 34} 35 36proc get_var_address { var } { 37 global gdb_prompt hex 38 39 send_gdb "print &${var}\n" 40 # Match output like: 41 # $1 = (int *) 0x0 42 # $5 = (int (*)()) 0 43 # $6 = (int (*)()) 0x24 <function_bar> 44 gdb_expect { 45 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" 46 { 47 pass "get address of ${var}" 48 if { $expect_out(1,string) == "0" } { 49 return "0x0" 50 } else { 51 return $expect_out(1,string) 52 } 53 } 54 -re "${gdb_prompt} $" 55 { fail "get address of ${var} (unknown output)" } 56 timeout 57 { fail "get address of ${var} (timeout)" } 58 } 59 return "" 60} 61 62 63 64gdb_exit 65gdb_start 66gdb_reinitialize_dir $srcdir/$subdir 67 68# Load the object file. 69gdb_test "add-symbol-file ${binfile} 0" \ 70 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ 71 "add-symbol-file ${testfile}.o 0" \ 72 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \ 73 "y" 74 75# Print the addresses of static variables. 76set static_foo_addr [get_var_address static_foo] 77set static_bar_addr [get_var_address static_bar] 78 79# Make sure they have different addresses. 80if { "${static_foo_addr}" == "${static_bar_addr}" } { 81 fail "static variables have different addresses" 82} else { 83 pass "static variables have different addresses" 84} 85 86# Print the addresses of global variables. 87set global_foo_addr [get_var_address global_foo] 88set global_bar_addr [get_var_address global_bar] 89 90# Make sure they have different addresses. 91if { "${global_foo_addr}" == "${global_bar_addr}" } { 92 fail "global variables have different addresses" 93} else { 94 pass "global variables have different addresses" 95} 96 97# Print the addresses of functions. 98set function_foo_addr [get_var_address function_foo] 99set function_bar_addr [get_var_address function_bar] 100 101# Make sure they have different addresses. 102if { "${function_foo_addr}" == "${function_bar_addr}" } { 103 fail "functions have different addresses" 104} else { 105 pass "functions have different addresses" 106} 107 108# Now use a variable as an offset to add-symbol-file, and check that 109# the functions' addresses change. 110 111gdb_exit 112gdb_start 113gdb_reinitialize_dir $srcdir/$subdir 114 115gdb_test "set \$offset = 0x10000" "" 116 117# Load the object file. 118gdb_test "add-symbol-file ${binfile} \$offset" \ 119 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ 120 "add-symbol-file ${testfile}.o \$offset" \ 121 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ 122 "y" 123 124# Print the addresses of functions. 125set new_function_foo_addr [get_var_address function_foo] 126 127# Make sure they have different addresses. 128if { "${function_foo_addr}" == "${new_function_foo_addr}" } { 129 fail "function foo has a different address" 130} else { 131 pass "function foo has a different address" 132} 133 134return 0 135