From 6a667807390b7091b5ec088d979c779f65d3dfa5 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 24 Jan 2023 15:12:34 +0000 Subject: gdb/python: implement DisassemblerResult.__str__ method Add the DisassemblerResult.__str__ method. This gives the same result as the DisassemblerResult.string attribute, but can be useful sometimes depending on how the user is trying to print the object. There's a test for the new functionality. --- gdb/testsuite/gdb.python/py-disasm.exp | 1 + gdb/testsuite/gdb.python/py-disasm.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'gdb/testsuite/gdb.python') diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp index 854cdbb..2550e60 100644 --- a/gdb/testsuite/gdb.python/py-disasm.exp +++ b/gdb/testsuite/gdb.python/py-disasm.exp @@ -76,6 +76,7 @@ set test_plans \ [list "ShowInfoRepr" "${base_pattern}\\s+## \]+>\r\n.*"] \ [list "ShowInfoSubClassRepr" "${base_pattern}\\s+## \]+>\r\n.*"] \ [list "ShowResultRepr" "${base_pattern}\\s+## \r\n.*"] \ + [list "ShowResultStr" "${base_pattern}\\s+## ${nop}\r\n.*"] \ [list "GlobalPreInfoDisassembler" "${base_pattern}\\s+## ad = $hex, ar = ${curr_arch}\r\n.*"] \ [list "GlobalPostInfoDisassembler" "${base_pattern}\\s+## ad = $hex, ar = ${curr_arch}\r\n.*"] \ [list "GlobalReadDisassembler" "${base_pattern}\\s+## bytes =( $hex)+\r\n.*"] \ diff --git a/gdb/testsuite/gdb.python/py-disasm.py b/gdb/testsuite/gdb.python/py-disasm.py index 977cdbf..435a3bf 100644 --- a/gdb/testsuite/gdb.python/py-disasm.py +++ b/gdb/testsuite/gdb.python/py-disasm.py @@ -113,6 +113,18 @@ class ShowResultRepr(TestDisassembler): return DisassemblerResult(length=length, string=string) +class ShowResultStr(TestDisassembler): + """Call the __str__ method on a DisassemblerResult object, incude the + resulting string in a comment within the disassembler output.""" + + def disassemble(self, info): + result = gdb.disassembler.builtin_disassemble(info) + comment = "\t## " + str(result) + string = result.string + comment + length = result.length + return DisassemblerResult(length=length, string=string) + + class GlobalPreInfoDisassembler(TestDisassembler): """Check the attributes of DisassembleInfo before disassembly has occurred.""" -- cgit v1.1