Currently most of the test files have a separate dwarf and a separate dsym test with almost identical content (only the build step is different). With adding dwo symbol file handling to the test suit it would increase this to a 3-way duplication. The purpose of this change is to eliminate this redundancy with generating 2 test case (one dwarf and one dsym) for each test function specified (dwo handling will be added at a later commit). Main design goals: * There should be no boilerplate code in each test file to support the multiple debug info in most of the tests (custom scenarios are acceptable in special cases) so adding a new test case is easier and we can't miss one of the debug info type. * In case of a test failure, the debug symbols used during the test run have to be cleanly visible from the output of dotest.py to make debugging easier both from build bot logs and from local test runs * Each test case should have a unique, fully qualified name so we can run exactly 1 test with "-f <test-case>.<test-function>" syntax * Test output should be grouped based on test files the same way as it happens now (displaying dwarf/dsym results separately isn't preferable) Proposed solution (main logic in lldbtest.py, rest of them are test cases fixed up for the new style): * Have only 1 test fuction in the test files what will run for all debug info separately and this test function should call just "self.build(...)" to build an inferior with the right debug info * When a class is created by python (the class object, not the class instance), we will generate a new test method for each debug info format in the test class with the name "<test-function>_<debug-info>" and remove the original test method. This way unittest2 see multiple test methods (1 for each debug info, pretty much as of now) and will handle the test selection and the failure reporting correctly (the debug info will be visible from the end of the test name) * Add new annotation @no_debug_info_test to disable the generation of multiple tests for each debug info format when the test don't have an inferior Differential revision: http://reviews.llvm.org/D13028 llvm-svn: 248883
139 lines
5.0 KiB
Python
139 lines
5.0 KiB
Python
"""
|
|
Test conditionally break on a function and inspect its variables.
|
|
"""
|
|
|
|
import os, time
|
|
import re
|
|
import unittest2
|
|
import lldb, lldbutil
|
|
from lldbtest import *
|
|
|
|
# rdar://problem/8532131
|
|
# lldb not able to digest the clang-generated debug info correctly with respect to function name
|
|
#
|
|
# This class currently fails for clang as well as llvm-gcc.
|
|
|
|
class ConditionalBreakTestCase(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
@expectedFailureWindows("llvm.org/pr24778")
|
|
@python_api_test
|
|
def test_with_python(self):
|
|
"""Exercise some thread and frame APIs to break if c() is called by a()."""
|
|
self.build()
|
|
self.do_conditional_break()
|
|
|
|
def test_with_command(self):
|
|
"""Simulate a user using lldb commands to break on c() if called from a()."""
|
|
self.build()
|
|
self.simulate_conditional_break_by_user()
|
|
|
|
def do_conditional_break(self):
|
|
"""Exercise some thread and frame APIs to break if c() is called by a()."""
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
target = self.dbg.CreateTarget(exe)
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
breakpoint = target.BreakpointCreateByName("c", exe)
|
|
self.assertTrue(breakpoint, VALID_BREAKPOINT)
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
|
process = target.LaunchSimple (None, None, self.get_process_working_directory())
|
|
|
|
self.assertTrue(process, PROCESS_IS_VALID)
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
self.assertTrue(process.GetState() == lldb.eStateStopped,
|
|
STOPPED_DUE_TO_BREAKPOINT)
|
|
|
|
# Find the line number where a's parent frame function is c.
|
|
line = line_number('main.c',
|
|
"// Find the line number where c's parent frame is a here.")
|
|
|
|
# Suppose we are only interested in the call scenario where c()'s
|
|
# immediate caller is a() and we want to find out the value passed from
|
|
# a().
|
|
#
|
|
# The 10 in range(10) is just an arbitrary number, which means we would
|
|
# like to try for at most 10 times.
|
|
for j in range(10):
|
|
if self.TraceOn():
|
|
print "j is: ", j
|
|
thread = process.GetThreadAtIndex(0)
|
|
|
|
if thread.GetNumFrames() >= 2:
|
|
frame0 = thread.GetFrameAtIndex(0)
|
|
name0 = frame0.GetFunction().GetName()
|
|
frame1 = thread.GetFrameAtIndex(1)
|
|
name1 = frame1.GetFunction().GetName()
|
|
#lldbutil.print_stacktrace(thread)
|
|
self.assertTrue(name0 == "c", "Break on function c()")
|
|
if (name1 == "a"):
|
|
# By design, we know that a() calls c() only from main.c:27.
|
|
# In reality, similar logic can be used to find out the call
|
|
# site.
|
|
self.assertTrue(frame1.GetLineEntry().GetLine() == line,
|
|
"Immediate caller a() at main.c:%d" % line)
|
|
|
|
# And the local variable 'val' should have a value of (int) 3.
|
|
val = frame1.FindVariable("val")
|
|
self.assertTrue(val.GetTypeName() == "int", "'val' has int type")
|
|
self.assertTrue(val.GetValue() == "3", "'val' has a value of 3")
|
|
break
|
|
|
|
process.Continue()
|
|
|
|
def simulate_conditional_break_by_user(self):
|
|
"""Simulate a user using lldb commands to break on c() if called from a()."""
|
|
|
|
# Sourcing .lldb in the current working directory, which sets the main
|
|
# executable, sets the breakpoint on c(), and adds the callback for the
|
|
# breakpoint such that lldb only stops when the caller of c() is a().
|
|
# the "my" package that defines the date() function.
|
|
if self.TraceOn():
|
|
print "About to source .lldb"
|
|
|
|
if not self.TraceOn():
|
|
self.HideStdout()
|
|
|
|
# Separate out the "file a.out" command from .lldb file, for the sake of
|
|
# remote testsuite.
|
|
self.runCmd("file a.out")
|
|
self.runCmd("command source .lldb")
|
|
|
|
self.runCmd ("break list")
|
|
|
|
if self.TraceOn():
|
|
print "About to run."
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
self.runCmd ("break list")
|
|
|
|
if self.TraceOn():
|
|
print "Done running"
|
|
|
|
# The stop reason of the thread should be breakpoint.
|
|
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
|
|
substrs = ['stopped', 'stop reason = breakpoint'])
|
|
|
|
# The frame info for frame #0 points to a.out`c and its immediate caller
|
|
# (frame #1) points to a.out`a.
|
|
|
|
self.expect("frame info", "We should stop at c()",
|
|
substrs = ["a.out`c"])
|
|
|
|
# Select our parent frame as the current frame.
|
|
self.runCmd("frame select 1")
|
|
self.expect("frame info", "The immediate caller should be a()",
|
|
substrs = ["a.out`a"])
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import atexit
|
|
lldb.SBDebugger.Initialize()
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
unittest2.main()
|