Files
binutils-gdb/gdb/testsuite/gdb.python/py-send-packet.exp
Andrew Burgess 9da79058a7 gdb/testsuite: fix failure in gdb.python/py-send-packet.exp
While working on another patch I noticed that, when run on an AArch64
target, the test gdb.python/py-send-packet.exp was failing:

  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/build/gdb/testsuite/outputs/gdb.python/py-send-packet/py-send-packet.py",
  line 106, in run_auxv_send_packet_test
      assert string == expected_result
  AssertionError
  Error while executing Python code.
  (gdb) FAIL: gdb.python/py-send-packet.exp: call python run_auxv_send_packet_test function

The test uses 'maint packet ...' to send a packet to gdbserver, and
then captures the output in TCL.  This output is then passed through
to a Python function, which performs some actions using the Python
API, and compares the results from the Python API to the results
captured in TCL from 'maint packet ...'.

The problem is that the output captured in TCL contains lots of things
like '\x000', when this is passed through to Python the '\x' causes
this to be treated as an escape code, which isn't what we want - we
want the actual string "\x000".

So, in the TCL part of the test we were expanding '\x' to '\\x', this
seemed to work fine for my testing on x86-64.

However, on AArch64 what I see is that the results from 'maint packet
...' contain a literal '\' character followed by a literal 'x'
character.  When GDB prints this in the 'maint packet' output, GDB
escapes the '\' for us, thus we get '\\x' printed by 'maint packet'.

However, now our TCL test script kicks in and tries to "fix" the '\x',
this means we now have '\\\x', which isn't correct.

The problem is that in the TCL script we are too restrictive, we
expand '\x' to '\\x', but really, we should be expanding all '\'
characters, regardless of what follows them.  This is what this patch
does.

After this the gdb.python/py-send-packet.exp test passes on AArch64
for me.
2022-11-17 14:36:35 +00:00

101 lines
3.3 KiB
Plaintext

# Copyright (C) 2021-2022 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test the gdb.RemoteTargetConnection.send_packet API. This is done
# by connecting to a remote target and fetching the thread list in two
# ways, first, we manually send the packets required to read the
# thread list using gdb.TargetConnection.send_packet, then we compare
# the results to the thread list using the standard API calls.
load_lib gdb-python.exp
load_lib gdbserver-support.exp
standard_testfile
if {[skip_gdbserver_tests]} {
return 0
}
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
if { [skip_python_tests] } {
return 0
}
# Make sure we're disconnected, in case we're testing with an
# extended-remote board, therefore already connected.
gdb_test "disconnect" ".*"
gdbserver_run ""
gdb_breakpoint "breakpt"
gdb_continue_to_breakpoint "breakpt"
# Source the python script.
set remote_python_file [gdb_remote_download host \
${srcdir}/${subdir}/${testfile}.py]
gdb_test "source $remote_python_file" "Sourcing complete\\." \
"source ${testfile}.py script"
# The test is actually written in the Python script. Run it now.
gdb_test "python run_send_packet_test()" "Send packet test passed"
# Check the string representation of a remote target connection.
gdb_test "python print(gdb.selected_inferior().connection)" \
"<gdb.RemoteTargetConnection num=$decimal, what=\".*\">"
# Check to see if there's any auxv data for this target.
gdb_test_multiple "info auxv" "" {
-re -wrap "The program has no auxiliary information now\\. " {
set skip_auxv_test true
}
-re -wrap "0\\s+AT_NULL\\s+End of vector\\s+0x0" {
set skip_auxv_test false
}
}
if { ! $skip_auxv_test } {
# Use 'maint packet' to fetch the auxv data.
set reply_data ""
gdb_test_multiple "maint packet qXfer:auxv:read::0,1000" "" {
-re "sending: \"qXfer:auxv:read::0,1000\"\r\n" {
exp_continue
}
-re -wrap "received: \"(.*)\"" {
set reply_data $expect_out(1,string)
}
}
# Escape any backslash characters in the output, so we can safely
# pass a string through to Python.
set reply_data [string map {\\ \\\\} $reply_data]
gdb_assert { ![string equal "$reply_data" ""] }
# Run the test, fetches the auxv data in Python and confirm it
# matches the expected results.
gdb_test "python run_auxv_send_packet_test(\"$reply_data\")" \
"auxv send packet test passed" \
"call python run_auxv_send_packet_test function"
}
set sizeof_global_var [get_valueof "/d" "sizeof(global_var)" "UNKNOWN"]
if { $sizeof_global_var == 4 } {
gdb_test_no_output "set debug remote 1"
gdb_test "python run_set_global_var_test()" \
"set global_var test passed"
}