2 Test the lldb disassemble command on each call frame when stopped on C's ctor.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class IterateFrameAndDisassembleTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 def test_and_run_command(self):
21 """Disassemble each call frame when stopped on C's constructor."""
25 raw_output = self.res.GetOutput()
26 frameRE = re.compile(r"""
27 ^\s\sframe # heading for the frame info,
29 0x[0-9a-f]{16} # the frame pc, and
30 \sa.out`(.+) # module`function, and
31 \s\+\s # the rest ' + ....'
33 for line in raw_output.split(os.linesep):
34 match = frameRE.search(line)
36 function = match.group(1)
38 #print("function:", function)
39 self.runCmd("disassemble -n '%s'" % function)
41 @add_test_categories(['pyapi'])
42 def test_and_python_api(self):
43 """Disassemble each call frame when stopped on C's constructor."""
47 # Now use the Python API to get at each function on the call stack and
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.
63 # Get all instructions for this function and print them out.
64 insts = function.GetInstructions(target)
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
74 # Call super's setUp().
76 # Find the line number to break for main.cpp.
77 self.line = line_number('main.cpp', '// Set break point at this line.')
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)
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)
88 self.runCmd("run", RUN_SUCCEEDED)
90 # The stop reason of the thread should be breakpoint.
91 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
93 'stop reason = breakpoint %d.' % (bpno)])
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'])