1""" 2Use lldb Python API to disassemble raw machine code bytes 3""" 4 5import os, time 6import re 7import unittest2 8import lldb, lldbutil 9from lldbtest import * 10 11class Disassemble_VST1_64(TestBase): 12 13 mydir = os.path.join("python_api", "disassemble-raw-data") 14 15 @python_api_test 16 def test_disassemble_invalid_vst_1_64_raw_data(self): 17 """Test disassembling invalid vst1.64 raw bytes with the API.""" 18 self.disassemble_invalid_vst_1_64_raw_data() 19 20 def disassemble_invalid_vst_1_64_raw_data(self): 21 """Test disassembling invalid vst1.64 raw bytes with the API.""" 22 # Create a target from the debugger. 23 24 target = self.dbg.CreateTargetWithFileAndTargetTriple ("", "thumbv7") 25 self.assertTrue(target, VALID_TARGET) 26 27 raw_bytes = bytearray([0xf0, 0xb5, 0x03, 0xaf, 28 0x2d, 0xe9, 0x00, 0x0d, 29 0xad, 0xf1, 0x40, 0x04, 30 0x24, 0xf0, 0x0f, 0x04, 31 0xa5, 0x46]) 32 33 insts = target.GetInstructions(lldb.SBAddress(), raw_bytes) 34 35 if self.TraceOn(): 36 print 37 for i in insts: 38 print "Disassembled%s" % str(i) 39 40 # Remove the following return statement when the radar is fixed. 41 return 42 43 # rdar://problem/11034702 44 # VST1 (multiple single elements) encoding? 45 # The disassembler should not crash! 46 raw_bytes = bytearray([0x04, 0xf9, 0xed, 0x82]) 47 48 insts = target.GetInstructions(lldb.SBAddress(), raw_bytes) 49 50 inst = insts.GetInstructionAtIndex(0) 51 52 if self.TraceOn(): 53 print 54 print "Raw bytes: ", [hex(x) for x in raw_bytes] 55 print "Disassembled%s" % str(inst) 56 57 self.assertTrue (inst.GetMnemonic(target) == "vst1.64") 58 59 60if __name__ == '__main__': 61 import atexit 62 lldb.SBDebugger.Initialize() 63 atexit.register(lambda: lldb.SBDebugger.Terminate()) 64 unittest2.main() 65