TestBreakpointIgnoreCount.py [plain text]
"""
Test breakpoint ignore count features.
"""
import os, time
import re
import unittest2
import lldb, lldbutil
from lldbtest import *
class BreakpointIgnoreCountTestCase(TestBase):
mydir = os.path.join("functionalities", "breakpoint", "breakpoint_ignore_count")
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
def test_with_dsym_and_run_command(self):
"""Exercise breakpoint ignore count with 'breakpoint set -i <count>'."""
self.buildDsym()
self.breakpoint_ignore_count()
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@python_api_test
def test_with_dsym_and_python_api(self):
"""Use Python APIs to set breakpoint ignore count."""
self.buildDsym()
self.breakpoint_ignore_count_python()
def test_with_dwarf_and_run_command(self):
"""Exercise breakpoint ignore count with 'breakpoint set -i <count>'."""
self.buildDwarf()
self.breakpoint_ignore_count()
@python_api_test
def test_with_dwarf_and_python_api(self):
"""Use Python APIs to set breakpoint ignore count."""
self.buildDwarf()
self.breakpoint_ignore_count_python()
def setUp(self):
TestBase.setUp(self)
self.line1 = line_number('main.c', '// Find the line number of function "c" here.')
self.line2 = line_number('main.c', '// b(2) -> c(2) Find the call site of b(2).')
self.line3 = line_number('main.c', '// a(3) -> c(3) Find the call site of c(3).')
self.line4 = line_number('main.c', '// a(3) -> c(3) Find the call site of a(3).')
def breakpoint_ignore_count(self):
"""Exercise breakpoint ignore count with 'breakpoint set -i <count>'."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
self.expect("breakpoint set -i 1 -f main.c -l %d" % self.line1, BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
self.line1)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("process status", PROCESS_STOPPED,
patterns = ['Process .* stopped'])
self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE,
substrs = ["resolved = 1",
"hit count = 2"])
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT,
patterns = ["frame #0.*main.c:%d" % self.line1,
"frame #2.*main.c:%d" % self.line2])
def breakpoint_ignore_count_python(self):
"""Use Python APIs to set breakpoint ignore count."""
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByName('c', 'a.out')
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() == 1,
VALID_BREAKPOINT)
location = breakpoint.GetLocationAtIndex(0)
self.assertTrue(location and
location.IsEnabled(),
VALID_BREAKPOINT_LOCATION)
location.SetIgnoreCount(2)
self.assertTrue(location.GetIgnoreCount() == 2,
"SetIgnoreCount() works correctly")
process = target.LaunchSimple(None, None, os.getcwd())
self.assertTrue(process, PROCESS_IS_VALID)
from lldbutil import get_stopped_thread
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint")
frame0 = thread.GetFrameAtIndex(0)
frame1 = thread.GetFrameAtIndex(1)
frame2 = thread.GetFrameAtIndex(2)
self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and
frame1.GetLineEntry().GetLine() == self.line3 and
frame2.GetLineEntry().GetLine() == self.line4,
STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT)
self.assertTrue(breakpoint.GetHitCount() == 3)
process.Continue()
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()