]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/class_types/TestClassTypesDisassembly.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / class_types / TestClassTypesDisassembly.py
1 """
2 Test the lldb disassemble command on each call frame when stopped on C's ctor.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class IterateFrameAndDisassembleTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def test_and_run_command(self):
21         """Disassemble each call frame when stopped on C's constructor."""
22         self.build()
23         self.breakOnCtor()
24
25         raw_output = self.res.GetOutput()
26         frameRE = re.compile(r"""
27                               ^\s\sframe        # heading for the frame info,
28                               .*                # wildcard, and
29                               0x[0-9a-f]{16}    # the frame pc, and
30                               \sa.out`(.+)      # module`function, and
31                               \s\+\s            # the rest ' + ....'
32                               """, re.VERBOSE)
33         for line in raw_output.split(os.linesep):
34             match = frameRE.search(line)
35             if match:
36                 function = match.group(1)
37                 #print("line:", line)
38                 #print("function:", function)
39                 self.runCmd("disassemble -n '%s'" % function)
40
41     @add_test_categories(['pyapi'])
42     def test_and_python_api(self):
43         """Disassemble each call frame when stopped on C's constructor."""
44         self.build()
45         self.breakOnCtor()
46
47         # Now use the Python API to get at each function on the call stack and
48         # disassemble it.
49         target = self.dbg.GetSelectedTarget()
50         process = target.GetProcess()
51         thread = lldbutil.get_stopped_thread(
52             process, lldb.eStopReasonBreakpoint)
53         self.assertIsNotNone(thread)
54         depth = thread.GetNumFrames()
55         for i in range(depth - 1):
56             frame = thread.GetFrameAtIndex(i)
57             function = frame.GetFunction()
58             # Print the function header.
59             if self.TraceOn():
60                 print()
61                 print(function)
62             if function:
63                 # Get all instructions for this function and print them out.
64                 insts = function.GetInstructions(target)
65                 for inst in insts:
66                     # We could simply do 'print inst' to print out the disassembly.
67                     # But we want to print to stdout only if self.TraceOn() is
68                     # True.
69                     disasm = str(inst)
70                     if self.TraceOn():
71                         print(disasm)
72
73     def setUp(self):
74         # Call super's setUp().
75         TestBase.setUp(self)
76         # Find the line number to break for main.cpp.
77         self.line = line_number('main.cpp', '// Set break point at this line.')
78
79     def breakOnCtor(self):
80         """Setup/run the program so it stops on C's constructor."""
81         exe = os.path.join(os.getcwd(), "a.out")
82         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
83
84         # Break on the ctor function of class C.
85         bpno = lldbutil.run_break_set_by_file_and_line(
86             self, "main.cpp", self.line, num_expected_locations=-1)
87
88         self.runCmd("run", RUN_SUCCEEDED)
89
90         # The stop reason of the thread should be breakpoint.
91         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
92                     substrs=['stopped',
93                              'stop reason = breakpoint %d.' % (bpno)])
94
95         # This test was failing because we fail to put the C:: in front of constructore.
96         # We should maybe make another testcase to cover that specifically, but we shouldn't
97         # fail this whole testcase for an inessential issue.
98         # We should be stopped on the ctor function of class C.
99         # self.expect("thread backtrace", BACKTRACE_DISPLAYED_CORRECTLY,
100         #  substrs = ['C::C'])