public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed] [gdb/testsuite] Fix gdb.python/py-disasm.exp on s390x
Date: Tue, 13 Dec 2022 13:06:34 +0100	[thread overview]
Message-ID: <20221213120634.32016-1-tdevries@suse.de> (raw)

On s390x-linux, I run into:
...
(gdb) disassemble test^M
Dump of assembler code for function test:^M
   0x0000000001000638 <+0>:     stg     %r11,88(%r15)^M
   0x000000000100063e <+6>:     lgr     %r11,%r15^M
   0x0000000001000642 <+10>:    nop     0^M
=> 0x0000000001000646 <+14>:    nop     0^M
   0x000000000100064a <+18>:    nop     0^M
   0x000000000100064e <+22>:    lhi     %r1,0^M
   0x0000000001000652 <+26>:    lgfr    %r1,%r1^M
   0x0000000001000656 <+30>:    lgr     %r2,%r1^M
   0x000000000100065a <+34>:    lg      %r11,88(%r11)^M
   0x0000000001000660 <+40>:    br      %r14^M
End of assembler dump.^M
(gdb) FAIL: gdb.python/py-disasm.exp: global_disassembler=: disassemble test
...

The problem is that the test-case expects "nop" but on s390x we have instead
"nop\t0".

Fix this by allowing the insn.

Tested on s390x-linux and x86_64-linux.
---
 gdb/testsuite/gdb.python/py-disasm.exp |  9 +++++----
 gdb/testsuite/gdb.python/py-disasm.py  | 13 +++++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp
index 2fe20c39d83..a83c670bea2 100644
--- a/gdb/testsuite/gdb.python/py-disasm.exp
+++ b/gdb/testsuite/gdb.python/py-disasm.exp
@@ -66,9 +66,10 @@ proc py_remove_all_disassemblers {} {
 #
 # Each different disassembler tests some different feature of the
 # Python disassembler API.
+set nop "(nop|nop\t0)"
 set unknown_error_pattern "unknown disassembler error \\(error = -1\\)"
 set addr_pattern "\r\n=> ${curr_pc_pattern} <\[^>\]+>:\\s+"
-set base_pattern "${addr_pattern}nop"
+set base_pattern "${addr_pattern}${nop}"
 set test_plans \
     [list \
 	 [list "" "${base_pattern}\r\n.*"] \
@@ -87,9 +88,9 @@ set test_plans \
 	 [list "ReadMemoryMemoryErrorDisassembler" "${addr_pattern}Cannot access memory at address ${curr_pc_pattern}"] \
 	 [list "ReadMemoryGdbErrorDisassembler" "${addr_pattern}read_memory raised GdbError\r\n${unknown_error_pattern}"] \
 	 [list "ReadMemoryRuntimeErrorDisassembler" "${addr_pattern}Python Exception <class 'RuntimeError'>: read_memory raised RuntimeError\r\n\r\n${unknown_error_pattern}"] \
-	 [list "ReadMemoryCaughtMemoryErrorDisassembler" "${addr_pattern}nop\r\n.*"] \
-	 [list "ReadMemoryCaughtGdbErrorDisassembler" "${addr_pattern}nop\r\n.*"] \
-	 [list "ReadMemoryCaughtRuntimeErrorDisassembler" "${addr_pattern}nop\r\n.*"] \
+	 [list "ReadMemoryCaughtMemoryErrorDisassembler" "${addr_pattern}${nop}\r\n.*"] \
+	 [list "ReadMemoryCaughtGdbErrorDisassembler" "${addr_pattern}${nop}\r\n.*"] \
+	 [list "ReadMemoryCaughtRuntimeErrorDisassembler" "${addr_pattern}${nop}\r\n.*"] \
 	 [list "MemorySourceNotABufferDisassembler" "${addr_pattern}Python Exception <class 'TypeError'>: Result from read_memory is not a buffer\r\n\r\n${unknown_error_pattern}"] \
 	 [list "MemorySourceBufferTooLongDisassembler" "${addr_pattern}Python Exception <class 'ValueError'>: Buffer returned from read_memory is sized $decimal instead of the expected $decimal\r\n\r\n${unknown_error_pattern}"] \
 	 [list "ResultOfWrongType" "${addr_pattern}Python Exception <class 'TypeError'>: Result is not a DisassemblerResult.\r\n.*"] \
diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py
index 3b9008b1c54..ed9901e7866 100644
--- a/gdb/testsuite/gdb.python/py-disasm.py
+++ b/gdb/testsuite/gdb.python/py-disasm.py
@@ -25,6 +25,10 @@ from gdb.disassembler import Disassembler, DisassemblerResult
 current_pc = None
 
 
+def is_nop(s):
+    return s == "nop" or s == "nop\t0"
+
+
 # Remove all currently registered disassemblers.
 def remove_all_python_disassemblers():
     for a in gdb.architecture_names():
@@ -581,7 +585,7 @@ class AnalyzingDisassembler(Disassembler):
         result = gdb.disassembler.builtin_disassemble(info)
 
         # Record some informaiton about the first 'nop' instruction we find.
-        if self._nop_index is None and result.string == "nop":
+        if self._nop_index is None and is_nop(result.string):
             self._nop_index = len(self._pass_1_length)
             # The offset in the following read_memory call defaults to 0.
             self._nop_bytes = info.read_memory(result.length)
@@ -616,7 +620,7 @@ class AnalyzingDisassembler(Disassembler):
             if (
                 idx > 0
                 and idx != nop_idx
-                and self._pass_1_insn[idx] != "nop"
+                and not is_nop(self._pass_1_insn[idx])
                 and self._pass_1_length[idx] > self._pass_1_length[nop_idx]
                 and self._pass_1_length[idx] % self._pass_1_length[nop_idx] == 0
             ):
@@ -631,7 +635,7 @@ class AnalyzingDisassembler(Disassembler):
                 if (
                     idx > 0
                     and idx != nop_idx
-                    and self._pass_1_insn[idx] != "nop"
+                    and not is_nop(self._pass_1_insn[idx])
                     and self._pass_1_length[idx] == self._pass_1_length[nop_idx]
                 ):
                     replace_idx = idx
@@ -654,7 +658,8 @@ class AnalyzingDisassembler(Disassembler):
         # identified above with a series of 'nop' instructions.
         self._check = list(self._pass_1_insn)
         nop_count = int(self._pass_1_length[replace_idx] / self._pass_1_length[nop_idx])
-        nops = ["nop"] * nop_count
+        nop_insn = self._pass_1_insn[nop_idx]
+        nops = [nop_insn] * nop_count
         self._check[replace_idx : (replace_idx + 1)] = nops
 
     def check(self):

base-commit: 969b9a36506bfb386f8ce30f88f1a6a6ebbaca6e
-- 
2.35.3


                 reply	other threads:[~2022-12-13 12:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221213120634.32016-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).