1# Copyright 2018-2020 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 16# Test MIPS Floating Point General Register handling in core files. 17 18if { ![istarget "mips*-*-*"] } then { 19 verbose "Skipping MIPS Floating Point General Register tests." 20 return 21} 22 23standard_testfile 24 25if { [prepare_for_testing "failed to prepare" ${testfile}] } { 26 return 27} 28 29# Procedure to get current content of all floating-point registers. 30proc mips_fpregset_core_fetch_float_registers { test } { 31 global gdb_prompt 32 33 set all_registers_lines {} 34 set bad -1 35 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer 36 # corrupting the next matches. 37 if { [gdb_test_multiple "info registers float" $test { 38 -re "info registers float\r\n" { 39 exp_continue 40 } 41 -ex "The program has no registers now" { 42 set bad 1 43 exp_continue 44 } 45 -re "^\(?:fcsr\|fir\):\[ \t\]+\[^\r\n\]+\r\n" { 46 # Filter out control registers. They may or may not be a part 47 # of the float group depending on whether XML descriptions are 48 # used or not. 49 exp_continue 50 } 51 -re "^\[^ \t\]+\[ \t\]+\[^\r\n\]+\r\n" { 52 lappend all_registers_lines $expect_out(0,string) 53 exp_continue 54 } 55 -re "$gdb_prompt $" { 56 incr bad 57 } 58 -re "^\[^\r\n\]+\r\n" { 59 if { !$bad } { 60 warning "Unrecognized output: $expect_out(0,string)" 61 set bad 1 62 } 63 exp_continue 64 } 65 }] != 0 } { 66 return {} 67 } 68 69 if { $bad } { 70 fail $test 71 return {} 72 } 73 74 pass $test 75 return $all_registers_lines 76} 77 78# Generate a native core file. 79 80set corefile [core_find $binfile] 81set core_supported [expr {$corefile != ""}] 82 83# Generate a core file with "gcore". 84 85clean_restart ${binfile} 86 87runto break_here 88 89# Check if we have an FPU available. 90gdb_test_multiple "show mipsfpu" "check for MIPS floating-point coprocessor" { 91 -re "The MIPS floating-point coprocessor\ 92 .*\(absent\|unknown\).*$gdb_prompt $" { 93 unsupported "no MIPS floating-point coprocessor in the processor" 94 return 95 } 96 -re "The MIPS floating-point coprocessor .*$gdb_prompt $" { 97 verbose "MIPS floating-point coprocessor check successful." 98 } 99 default { 100 fail 101 return 102 } 103} 104 105# Save live FGR register contents. 106set live_fgr_contents [mips_fpregset_core_fetch_float_registers \ 107 "retrieve live FGR register contents"] 108 109set gcorefile [standard_output_file gcore.test] 110set gcore_supported [gdb_gcore_cmd "$gcorefile" "gcore"] 111 112# Restart gdb and load COREFILE as a core file. SUPPORTED is true iff 113# the core was generated successfully; otherwise, the tests are marked 114# unsupported. 115# 116proc mips_fpregset_core_test { supported corefile } { 117 upvar live_fgr_contents live_fgr_contents 118 upvar target_triplet target_triplet 119 upvar host_triplet host_triplet 120 upvar binfile binfile 121 122 clean_restart ${binfile} 123 124 set test "load core file" 125 if { $supported } { 126 set core_loaded [gdb_core_cmd $corefile $test] 127 } else { 128 set core_loaded 0 129 unsupported $test 130 } 131 132 if { $core_loaded == 1 } { 133 set test "core file FGR register contents" 134 set core_fgr_contents \ 135 [mips_fpregset_core_fetch_float_registers "retrieve $test"] 136 if { $core_fgr_contents == $live_fgr_contents } then { 137 pass $test 138 } else { 139 fail $test 140 } 141 } else { 142 unsupported $test 143 } 144} 145 146with_test_prefix "native" { 147 mips_fpregset_core_test $core_supported $corefile 148} 149 150with_test_prefix "gcore" { 151 mips_fpregset_core_test $gcore_supported $gcorefile 152} 153 154gdb_exit 155