|
| 1 | +""" Check that registers written to memory for expression evaluation are |
| 2 | + written using the target's endian not the host's. |
| 3 | +""" |
| 4 | + |
| 5 | +from enum import Enum |
| 6 | +from textwrap import dedent |
| 7 | +import lldb |
| 8 | +from lldbsuite.test.lldbtest import * |
| 9 | +from lldbsuite.test.decorators import * |
| 10 | +from lldbsuite.test.gdbclientutils import * |
| 11 | +from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase |
| 12 | + |
| 13 | + |
| 14 | +class Endian(Enum): |
| 15 | + BIG = 0 |
| 16 | + LITTLE = 1 |
| 17 | + |
| 18 | + |
| 19 | +class Responder(MockGDBServerResponder): |
| 20 | + def __init__(self, doc, endian): |
| 21 | + super().__init__() |
| 22 | + self.target_xml = doc |
| 23 | + self.endian = endian |
| 24 | + |
| 25 | + def qXferRead(self, obj, annex, offset, length): |
| 26 | + if annex == "target.xml": |
| 27 | + return self.target_xml, False |
| 28 | + return (None,) |
| 29 | + |
| 30 | + def readRegister(self, regnum): |
| 31 | + return "E01" |
| 32 | + |
| 33 | + def readRegisters(self): |
| 34 | + # 64 bit pc value. |
| 35 | + data = ["00", "00", "00", "00", "00", "00", "12", "34"] |
| 36 | + if self.endian == Endian.LITTLE: |
| 37 | + data.reverse() |
| 38 | + return "".join(data) |
| 39 | + |
| 40 | + |
| 41 | +class TestXMLRegisterFlags(GDBRemoteTestBase): |
| 42 | + def do_endian_test(self, endian): |
| 43 | + architecture, pc_reg_name = { |
| 44 | + Endian.BIG: ("s390x", "pswa"), |
| 45 | + Endian.LITTLE: ("aarch64", "pc"), |
| 46 | + }[endian] |
| 47 | + |
| 48 | + self.server.responder = Responder( |
| 49 | + dedent( |
| 50 | + f"""\ |
| 51 | + <?xml version="1.0"?> |
| 52 | + <target version="1.0"> |
| 53 | + <architecture>{architecture}</architecture> |
| 54 | + <feature> |
| 55 | + <reg name="{pc_reg_name}" bitsize="64"/> |
| 56 | + </feature> |
| 57 | + </target>""" |
| 58 | + ), |
| 59 | + endian, |
| 60 | + ) |
| 61 | + target = self.dbg.CreateTarget("") |
| 62 | + process = self.connect(target) |
| 63 | + lldbutil.expect_state_changes( |
| 64 | + self, self.dbg.GetListener(), process, [lldb.eStateStopped] |
| 65 | + ) |
| 66 | + |
| 67 | + # If expressions convert register values into target endian, the |
| 68 | + # result of register read and expr should be the same. |
| 69 | + pc_value = "0x0000000000001234" |
| 70 | + self.expect( |
| 71 | + "register read pc", |
| 72 | + substrs=[pc_value], |
| 73 | + ) |
| 74 | + self.expect("expr --format hex -- $pc", substrs=[pc_value]) |
| 75 | + |
| 76 | + @skipIfXmlSupportMissing |
| 77 | + @skipIfRemote |
| 78 | + def test_little_endian_target(self): |
| 79 | + self.do_endian_test(Endian.LITTLE) |
| 80 | + |
| 81 | + @skipIfXmlSupportMissing |
| 82 | + @skipIfRemote |
| 83 | + # Unlike AArch64, we do need the backend present for this test to work. |
| 84 | + @skipIfLLVMTargetMissing("SystemZ") |
| 85 | + def test_big_endian_target(self): |
| 86 | + self.do_endian_test(Endian.BIG) |
0 commit comments