2 Use lldb Python API to disassemble raw machine code bytes
5 from io
import StringIO
9 from lldbsuite
.test
.decorators
import *
10 from lldbsuite
.test
.lldbtest
import *
11 from lldbsuite
.test
import lldbutil
14 class Disassemble_VST1_64(TestBase
):
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(
49 push {r4, r5, r6, r7, lr}
58 return [x
.strip() for x
in s
.strip().splitlines()]
60 insts
= target
.GetInstructions(lldb
.SBAddress(), raw_bytes
)
65 print("Disassembled %s" % str(i
))
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
)
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)
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")