aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2024-07-31 13:24:20 +0200
committerTom de Vries <tdevries@suse.de>2024-07-31 13:24:20 +0200
commit61ed16ee6341535924e5e601964afc6c256258e6 (patch)
treea1ff4f63677ba2de6ea7d2a87a1e34109d3d33f3
parent50fb268a6ff81c5a88119474ffe61cd4df1a8248 (diff)
downloadbinutils-61ed16ee6341535924e5e601964afc6c256258e6.zip
binutils-61ed16ee6341535924e5e601964afc6c256258e6.tar.gz
binutils-61ed16ee6341535924e5e601964afc6c256258e6.tar.bz2
[gdb/testsuite] Add gdb.python/py-disasm-{exec,obj}.exp
I tried to reproduce a problem in test-case gdb.python/py-disasm.exp on a s390x machine, but when running with target board unix/-m31 I saw that the required libraries were missing, so I couldn't generate an executable. However, I realized that I did have an object file, and the test-case should mostly also work with an object file. I've renamed gdb.python/py-disasm.exp to gdb.python/py-disasm.exp.tcl and included it from two new minimal test-case wrappers: - gdb.python/py-disasm-exec.exp, and - gdb.python/py-disasm-obj.exp where the former uses an executable as before, and the latter uses an object file. Using an object file required changing the info.read_memory calls in gdb.python/py-disasm.py: ... - info.read_memory(1, -info.address + 2) + info.read_memory(1, -info.address - 1) ... because reading from address 2 succeeds. Using address -1 instead does generate the expected gdb.MemoryError. Tested on x86_64-linux.
-rw-r--r--gdb/testsuite/gdb.python/py-disasm-exec.exp21
-rw-r--r--gdb/testsuite/gdb.python/py-disasm-obj.exp21
-rw-r--r--gdb/testsuite/gdb.python/py-disasm.exp.tcl (renamed from gdb/testsuite/gdb.python/py-disasm.exp)56
-rw-r--r--gdb/testsuite/gdb.python/py-disasm.py8
4 files changed, 90 insertions, 16 deletions
diff --git a/gdb/testsuite/gdb.python/py-disasm-exec.exp b/gdb/testsuite/gdb.python/py-disasm-exec.exp
new file mode 100644
index 0000000..546c4b8
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-disasm-exec.exp
@@ -0,0 +1,21 @@
+# Copyright (C) 2024 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/>.
+
+# This file is part of the GDB testsuite. It validates the Python
+# disassembler API.
+
+set kind exec
+
+source $srcdir/$subdir/py-disasm.exp.tcl
diff --git a/gdb/testsuite/gdb.python/py-disasm-obj.exp b/gdb/testsuite/gdb.python/py-disasm-obj.exp
new file mode 100644
index 0000000..37ff965
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-disasm-obj.exp
@@ -0,0 +1,21 @@
+# Copyright (C) 2024 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/>.
+
+# This file is part of the GDB testsuite. It validates the Python
+# disassembler API.
+
+set kind obj
+
+source $srcdir/$subdir/py-disasm.exp.tcl
diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp.tcl
index 5d7d922..8ed634e 100644
--- a/gdb/testsuite/gdb.python/py-disasm.exp
+++ b/gdb/testsuite/gdb.python/py-disasm.exp.tcl
@@ -20,26 +20,54 @@ load_lib gdb-python.exp
require allow_python_tests
-standard_testfile
+standard_testfile py-disasm.c
-if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} "debug"] } {
- return -1
-}
+if { $kind == "obj" } {
+
+ set obj [standard_output_file ${gdb_test_file_name}.o]
+
+ if { [gdb_compile "$srcdir/$subdir/$srcfile" $obj object "debug"] != "" } {
+ untested "failed to compile object file [file tail $obj]"
+ return -1
+ }
+
+ clean_restart $obj
+
+} else {
+
+ if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return -1
+ }
+
+ if { ![runto_main] } {
+ fail "can't run to main"
+ return 0
+ }
-if {![runto_main]} {
- fail "can't run to main"
- return 0
}
-set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
+set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-disasm.py]
gdb_test "source ${pyfile}" "Python script imported" \
"import python scripts"
-gdb_breakpoint [gdb_get_line_number "Break here."]
-gdb_continue_to_breakpoint "Break here."
+set line [gdb_get_line_number "Break here."]
-set curr_pc [get_valueof "/x" "\$pc" "*unknown*"]
+if { $kind == "obj" } {
+ set curr_pc "*unknown*"
+ set line [gdb_get_line_number "Break here."]
+ gdb_test_multiple "info line $line" "" {
+ -re -wrap "starts at address ($hex) \[^\r\n\]*" {
+ set curr_pc $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ }
+} else {
+ gdb_breakpoint $line
+ gdb_continue_to_breakpoint "Break here."
+
+ set curr_pc [get_valueof "/x" "\$pc" "*unknown*"]
+}
gdb_test_no_output "python current_pc = ${curr_pc}"
@@ -67,7 +95,11 @@ proc py_remove_all_disassemblers {} {
# Python disassembler API.
set nop "(nop|nop\t0|[string_to_regexp nop\t{0}])"
set unknown_error_pattern "unknown disassembler error \\(error = -1\\)"
-set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+"
+if { $kind == "obj" } {
+ set addr_pattern "\r\n ${curr_pc_pattern} <\[^>\]+>:\\s+"
+} else {
+ set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+"
+}
set base_pattern "${addr_pattern}${nop}"
# Helper proc to format a Python exception of TYPE with MSG.
diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py
index 2741fdb..f105657 100644
--- a/gdb/testsuite/gdb.python/py-disasm.py
+++ b/gdb/testsuite/gdb.python/py-disasm.py
@@ -252,7 +252,7 @@ class MemoryErrorEarlyDisassembler(TestDisassembler):
def disassemble(self, info):
tag = "## FAIL"
try:
- info.read_memory(1, -info.address + 2)
+ info.read_memory(1, -info.address - 1)
except gdb.MemoryError:
tag = "## AFTER ERROR"
result = builtin_disassemble_wrapper(info)
@@ -267,7 +267,7 @@ class MemoryErrorLateDisassembler(TestDisassembler):
def disassemble(self, info):
result = builtin_disassemble_wrapper(info)
# The following read will throw an error.
- info.read_memory(1, -info.address + 2)
+ info.read_memory(1, -info.address - 1)
return DisassemblerResult(1, "BAD")
@@ -276,9 +276,9 @@ class RethrowMemoryErrorDisassembler(TestDisassembler):
def disassemble(self, info):
try:
- info.read_memory(1, -info.address + 2)
+ info.read_memory(1, -info.address - 1)
except gdb.MemoryError as e:
- raise gdb.MemoryError("cannot read code at address 0x2")
+ raise gdb.MemoryError("cannot read code at address -1")
return DisassemblerResult(1, "BAD")