Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / python_api / disassemble-raw-data / TestDisassemble_VST1_64.py
blobeebba9c920e23deaf9843b5ae0dd102a6910fce1
1 """
2 Use lldb Python API to disassemble raw machine code bytes
3 """
5 from io import StringIO
6 import sys
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
14 class Disassemble_VST1_64(TestBase):
15 @no_debug_info_test
16 @skipIfLLVMTargetMissing("ARM")
17 def test_disassemble_invalid_vst_1_64_raw_data(self):
18 """Test disassembling invalid vst1.64 raw bytes with the API."""
19 # Create a target from the debugger.
20 target = self.dbg.CreateTargetWithFileAndTargetTriple(
21 "", "thumbv7-apple-macosx"
23 self.assertTrue(target, VALID_TARGET)
25 raw_bytes = bytearray(
27 0xF0,
28 0xB5,
29 0x03,
30 0xAF,
31 0x2D,
32 0xE9,
33 0x00,
34 0x0D,
35 0xAD,
36 0xF1,
37 0x40,
38 0x04,
39 0x24,
40 0xF0,
41 0x0F,
42 0x04,
43 0xA5,
44 0x46,
48 assembly = """
49 push {r4, r5, r6, r7, lr}
50 add r7, sp, #0xc
51 push.w {r8, r10, r11}
52 sub.w r4, sp, #0x40
53 bic r4, r4, #0xf
54 mov sp, r4
55 """
57 def split(s):
58 return [x.strip() for x in s.strip().splitlines()]
60 insts = target.GetInstructions(lldb.SBAddress(), raw_bytes)
62 if self.TraceOn():
63 print()
64 for i in insts:
65 print("Disassembled %s" % str(i))
67 sio = StringIO()
68 insts.Print(sio)
69 self.assertEqual(split(assembly), split(sio.getvalue()))
71 self.assertEqual(insts.GetSize(), len(split(assembly)))
73 for i, asm in enumerate(split(assembly)):
74 inst = insts.GetInstructionAtIndex(i)
75 sio = StringIO()
76 inst.Print(sio)
77 self.assertEqual(asm, sio.getvalue().strip())
79 raw_bytes = bytearray([0x04, 0xF9, 0xED, 0x82])
81 insts = target.GetInstructions(lldb.SBAddress(), raw_bytes)
83 inst = insts.GetInstructionAtIndex(0)
85 if self.TraceOn():
86 print()
87 print("Raw bytes: ", [hex(x) for x in raw_bytes])
88 print("Disassembled%s" % str(inst))
90 self.assertEqual(inst.GetMnemonic(target), "vst1.64")