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/py-disasm.py | |
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/py-disasm.py')
-rw-r--r-- | gdb/testsuite/gdb.python/py-disasm.py | 49 |
1 files changed, 49 insertions, 0 deletions
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.""" |