#
# 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.*"] \
[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.*"] \
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():
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)
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
):
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
# 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):