[gdb/testsuite] Fix gdb.python/py-disasm.exp on s390x
authorTom de Vries <tdevries@suse.de>
Tue, 13 Dec 2022 12:06:15 +0000 (13:06 +0100)
committerTom de Vries <tdevries@suse.de>
Tue, 13 Dec 2022 12:06:15 +0000 (13:06 +0100)
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
gdb/testsuite/gdb.python/py-disasm.py

index 2fe20c39d83a46fcefdd641a56c583137c0fa5fe..a83c670bea2894b50641646106132f51a0f5d51b 100644 (file)
@@ -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.*"] \
index 3b9008b1c54aad9c8c357a1e35a8c0f04deca017..ed9901e78668588232cedc250def74413a543f8b 100644 (file)
@@ -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):