]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/python_api/disassemble-raw-data/TestDisassembleRawData.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / python_api / disassemble-raw-data / TestDisassembleRawData.py
1 """
2 Use lldb Python API to disassemble raw machine code bytes
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import re
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16
17 class DisassembleRawDataTestCase(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20
21     @add_test_categories(['pyapi'])
22     @no_debug_info_test
23     @skipIfRemote
24     def test_disassemble_raw_data(self):
25         """Test disassembling raw bytes with the API."""
26         # Create a target from the debugger.
27         arch = self.getArchitecture()
28         if re.match("mips*el", arch):
29             target = self.dbg.CreateTargetWithFileAndTargetTriple("", "mipsel")
30             raw_bytes = bytearray([0x21, 0xf0, 0xa0, 0x03])
31         elif re.match("mips", arch):
32             target = self.dbg.CreateTargetWithFileAndTargetTriple("", "mips")
33             raw_bytes = bytearray([0x03, 0xa0, 0xf0, 0x21])
34         else:
35             target = self.dbg.CreateTargetWithFileAndTargetTriple("", "x86_64")
36             raw_bytes = bytearray([0x48, 0x89, 0xe5])
37
38         self.assertTrue(target, VALID_TARGET)
39         insts = target.GetInstructions(lldb.SBAddress(0, target), raw_bytes)
40
41         inst = insts.GetInstructionAtIndex(0)
42
43         if self.TraceOn():
44             print()
45             print("Raw bytes:    ", [hex(x) for x in raw_bytes])
46             print("Disassembled%s" % str(inst))
47         if re.match("mips", arch):
48             self.assertTrue(inst.GetMnemonic(target) == "move")
49             self.assertTrue(inst.GetOperands(target) ==
50                             '$' + "fp, " + '$' + "sp")
51         else:
52             self.assertTrue(inst.GetMnemonic(target) == "movq")
53             self.assertTrue(inst.GetOperands(target) ==
54                             '%' + "rsp, " + '%' + "rbp")