42 lines · python
1"""2Test SBTarget Read Instruction.3"""4 5from lldbsuite.test.decorators import *6from lldbsuite.test.lldbtest import *7 8 9class TargetReadInstructionsFlavor(TestBase):10 @skipIfDarwin11 @skipIfWindows12 @skipIf(archs=no_match(["x86_64", "x86", "i386"]))13 def test_read_instructions_with_flavor(self):14 self.build()15 executable = self.getBuildArtifact("a.out")16 17 # create a target18 target = self.dbg.CreateTarget(executable)19 self.assertTrue(target.IsValid(), "target is not valid")20 21 functions = target.FindFunctions("test_add")22 self.assertEqual(len(functions), 1)23 test_add = functions[0]24 25 test_add_symbols = test_add.GetSymbol()26 self.assertTrue(27 test_add_symbols.IsValid(), "test_add function symbols is not valid"28 )29 30 expected_instructions = (("mov", "eax, edi"), ("add", "eax, esi"), ("ret", ""))31 test_add_insts = test_add_symbols.GetInstructions(target, "intel")32 # clang adds an extra nop instruction but gcc does not. It makes more sense33 # to check if it is at least 334 self.assertLessEqual(len(expected_instructions), len(test_add_insts))35 36 # compares only the expected instructions37 for expected_instr, instr in zip(expected_instructions, test_add_insts):38 self.assertTrue(instr.IsValid(), "instruction is not valid")39 expected_mnemonic, expected_op_str = expected_instr40 self.assertEqual(instr.GetMnemonic(target), expected_mnemonic)41 self.assertEqual(instr.GetOperands(target), expected_op_str)42