1# Copyright (C) 2021-2023 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 the gdb.RemoteTargetConnection.send_packet API. This is done 17# by connecting to a remote target and fetching the thread list in two 18# ways, first, we manually send the packets required to read the 19# thread list using gdb.TargetConnection.send_packet, then we compare 20# the results to the thread list using the standard API calls. 21 22load_lib gdb-python.exp 23load_lib gdbserver-support.exp 24 25standard_testfile 26 27if {[skip_gdbserver_tests]} { 28 return 0 29} 30 31if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { 32 return -1 33} 34 35if { [skip_python_tests] } { 36 return 0 37} 38 39# Make sure we're disconnected, in case we're testing with an 40# extended-remote board, therefore already connected. 41gdb_test "disconnect" ".*" 42 43gdbserver_run "" 44 45gdb_breakpoint "breakpt" 46gdb_continue_to_breakpoint "breakpt" 47 48# Source the python script. 49set remote_python_file [gdb_remote_download host \ 50 ${srcdir}/${subdir}/${testfile}.py] 51gdb_test "source $remote_python_file" "Sourcing complete\\." \ 52 "source ${testfile}.py script" 53 54# The test is actually written in the Python script. Run it now. 55gdb_test "python run_send_packet_test()" "Send packet test passed" 56 57# Check the string representation of a remote target connection. 58gdb_test "python print(gdb.selected_inferior().connection)" \ 59 "<gdb.RemoteTargetConnection num=$decimal, what=\".*\">" 60 61# Check to see if there's any auxv data for this target. 62gdb_test_multiple "info auxv" "" { 63 -re -wrap "The program has no auxiliary information now\\. " { 64 set skip_auxv_test true 65 } 66 -re -wrap "0\\s+AT_NULL\\s+End of vector\\s+0x0" { 67 set skip_auxv_test false 68 } 69} 70 71if { ! $skip_auxv_test } { 72 # Use 'maint packet' to fetch the auxv data. 73 set reply_data "" 74 gdb_test_multiple "maint packet qXfer:auxv:read::0,1000" "" { 75 -re "sending: \"qXfer:auxv:read::0,1000\"\r\n" { 76 exp_continue 77 } 78 -re -wrap "received: \"(.*)\"" { 79 set reply_data $expect_out(1,string) 80 } 81 } 82 83 # Escape any backslash characters in the output, so we can safely 84 # pass a string through to Python. 85 set reply_data [string map {\\ \\\\} $reply_data] 86 gdb_assert { ![string equal "$reply_data" ""] } 87 88 # Run the test, fetches the auxv data in Python and confirm it 89 # matches the expected results. 90 gdb_test "python run_auxv_send_packet_test(\"$reply_data\")" \ 91 "auxv send packet test passed" \ 92 "call python run_auxv_send_packet_test function" 93} 94 95set sizeof_global_var [get_valueof "/d" "sizeof(global_var)" "UNKNOWN"] 96if { $sizeof_global_var == 4 } { 97 gdb_test_no_output "set debug remote 1" 98 gdb_test "python run_set_global_var_test()" \ 99 "set global_var test passed" 100} 101