diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-01-24 15:03:25 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2023-05-12 18:24:24 +0100 |
commit | 15ccb5e393f7c4032a8ee005a8183830a9c6accb (patch) | |
tree | a24c69e9112e808c3bafa7d9bdf35b6829034fc3 /gdb/testsuite/gdb.python | |
parent | 773e2d29c3a3c0f068b188a2a93c269cdfb237ad (diff) | |
download | binutils-15ccb5e393f7c4032a8ee005a8183830a9c6accb.zip binutils-15ccb5e393f7c4032a8ee005a8183830a9c6accb.tar.gz binutils-15ccb5e393f7c4032a8ee005a8183830a9c6accb.tar.bz2 |
gdb/python: implement __repr__ methods for py-disasm.c types
Add a __repr__ method for the DisassembleInfo and DisassemblerResult
types, and add some tests for these new methods.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-disasm.exp | 3 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-disasm.py | 49 |
2 files changed, 52 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-disasm.exp b/gdb/testsuite/gdb.python/py-disasm.exp index 38a2b76..854cdbb 100644 --- a/gdb/testsuite/gdb.python/py-disasm.exp +++ b/gdb/testsuite/gdb.python/py-disasm.exp @@ -73,6 +73,9 @@ set test_plans \ [list \ [list "" "${base_pattern}\r\n.*"] \ [list "GlobalNullDisassembler" "${base_pattern}\r\n.*"] \ + [list "ShowInfoRepr" "${base_pattern}\\s+## <gdb.disassembler.DisassembleInfo address=$hex architecture=\[^>\]+>\r\n.*"] \ + [list "ShowInfoSubClassRepr" "${base_pattern}\\s+## <MyInfo address=$hex architecture=\[^>\]+>\r\n.*"] \ + [list "ShowResultRepr" "${base_pattern}\\s+## <gdb.disassembler.DisassemblerResult length=$decimal string=\"\[^\r\n\]+\">\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 0ee883a..977cdbf 100644 --- a/gdb/testsuite/gdb.python/py-disasm.py +++ b/gdb/testsuite/gdb.python/py-disasm.py @@ -64,6 +64,55 @@ class TestDisassembler(Disassembler): raise NotImplementedError("override the disassemble method") +class ShowInfoRepr(TestDisassembler): + """Call the __repr__ method on the DisassembleInfo, convert the result + to a string, and incude it in a comment in the disassembler output.""" + + def disassemble(self, info): + comment = "\t## " + repr(info) + result = gdb.disassembler.builtin_disassemble(info) + string = result.string + comment + length = result.length + return DisassemblerResult(length=length, string=string) + + +class ShowInfoSubClassRepr(TestDisassembler): + """Create a sub-class of DisassembleInfo. Create an instace of this + sub-class and call the __repr__ method on it. Convert the result + to a string, and incude it in a comment in the disassembler + output. The DisassembleInfo sub-class does not override __repr__ + so we are calling the implementation on the parent class.""" + + class MyInfo(gdb.disassembler.DisassembleInfo): + """A wrapper around DisassembleInfo, doesn't add any new + functionality, just gives a new name in order to check the + __repr__ functionality.""" + + def __init__(self, info): + super().__init__(info) + + def disassemble(self, info): + info = self.MyInfo(info) + comment = "\t## " + repr(info) + result = gdb.disassembler.builtin_disassemble(info) + string = result.string + comment + length = result.length + return DisassemblerResult(length=length, string=string) + + +class ShowResultRepr(TestDisassembler): + """Call the __repr__ method on the DisassemblerResult, convert the + result to a string, and incude it in a comment in the disassembler + output.""" + + def disassemble(self, info): + result = gdb.disassembler.builtin_disassemble(info) + comment = "\t## " + repr(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.""" |