1# Copyright 2013-2016 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 3 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, see <http://www.gnu.org/licenses/>. 15 16load_lib dwarf.exp 17 18# This test can only be run on targets which support DWARF-2. 19if {![dwarf2_support]} { 20 return 0 21} 22 23standard_testfile main.c 24 25if { [prepare_for_testing "${testfile}.exp" "${testfile}" \ 26 [list ${srcfile}]] } { 27 return -1 28} 29 30# Add a .gdb_index section to PROGRAM. 31# PROGRAM is assumed to be the output of standard_output_file. 32# Returns the path of the program or "" if there is a failure. 33# If there is a failure it will have already been logged. 34 35proc add_gdb_index { program } { 36 set index_file ${program}.gdb-index 37 verbose -log "index_file: ${index_file}" 38 remote_file host delete ${index_file} 39 gdb_test_no_output "save gdb-index [file dirname ${index_file}]" \ 40 "save gdb-index for file [file tail ${program}]" 41 42 # No point in continuing if generating the index failed. 43 # N.B.: There are times when gdb won't create an index, and it's not a 44 # failure. However, in our case we need an index. So if you find one 45 # not being generated, you'll either have to tweak the .c file or maybe 46 # add a flag to force an index to be generated. 47 if { [remote_file host exists ${index_file}] } { 48 pass "gdb-index file created" 49 } else { 50 fail "gdb-index file created" 51 return "" 52 } 53 54 set program_with_index ${program}.with-index 55 if {[run_on_host "objcopy" [gdb_find_objcopy] "--remove-section .gdb_index --add-section .gdb_index=$index_file --set-section-flags .gdb_index=readonly ${program} ${program_with_index}"]} { 56 return "" 57 } 58 return ${program_with_index} 59} 60 61# Build a copy of the program with .gdb_index. 62# But only if the toolchain didn't already create one: gdb doesn't support 63# building an index from a program already using one. 64 65set test "check if index present" 66gdb_test_multiple "mt print objfiles ${testfile}" $test { 67 -re "gdb_index.*${gdb_prompt} $" { 68 set binfile_with_index $binfile 69 } 70 -re "Psymtabs.*${gdb_prompt} $" { 71 set binfile_with_index [add_gdb_index $binfile] 72 if { ${binfile_with_index} == "" } { 73 return -1 74 } 75 } 76} 77 78# Ok, we have a copy of $binfile with .gdb_index. 79# Restart gdb and verify the index was used. 80 81clean_restart ${binfile_with_index} 82gdb_test "mt print objfiles ${testfile}" \ 83 "gdb_index.*" \ 84 ".gdb_index used" 85 86# Make gdb re-read symbols and see if .gdb_index still gets used. 87# symtab/15885 88 89# There is gdb_touch_execfile, but it doesn't handle remote hosts. 90# Is touch portable enough? 91# First make sure enough time has passed, file mtime resolution is seconds. 92gdb_test_no_output "shell sleep 1" 93if {[run_on_host "touch binary" touch ${binfile_with_index}]} { 94 return -1 95} 96 97if ![runto_main] { 98 return -1 99} 100gdb_test "mt print objfiles ${testfile}" \ 101 "gdb_index.*" \ 102 ".gdb_index used after symbol reloading" 103