From fa59ab98685e4b5431d2be423f449df5069a454e Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 13 Dec 2022 13:06:15 +0100 Subject: [PATCH] [gdb/testsuite] Fix gdb.python/py-disasm.exp on s390x 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 : 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 : Result from read_memory is not a buffer\r\n\r\n${unknown_error_pattern}"] \ [list "MemorySourceBufferTooLongDisassembler" "${addr_pattern}Python Exception : 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 : 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): -- 2.30.2