Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS += -std=c99
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,99 @@
"""
Test address breakpoints set with shared library of SBAddress work correctly.
"""
from __future__ import print_function
import os
import time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class AddressBreakpointTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def test_address_breakpoints(self):
"""Test address breakpoints set with shared library of SBAddress work correctly."""
self.build()
self.address_breakpoints()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def address_breakpoints(self):
"""Test address breakpoints set with shared library of SBAddress work correctly."""
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateBySourceRegex(
"Set a breakpoint here", lldb.SBFileSpec("main.c"))
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() >= 1,
VALID_BREAKPOINT)
# Get the breakpoint location from breakpoint after we verified that,
# indeed, it has one location.
location = breakpoint.GetLocationAtIndex(0)
self.assertTrue(location and
location.IsEnabled(),
VALID_BREAKPOINT_LOCATION)
# Next get the address from the location, and create an address breakpoint using
# that address:
address = location.GetAddress()
target.BreakpointDelete(breakpoint.GetID())
breakpoint = target.BreakpointCreateBySBAddress(address)
# Disable ASLR. This will allow us to actually test (on platforms that support this flag)
# that the breakpoint was able to track the module.
launch_info = lldb.SBLaunchInfo(None)
flags = launch_info.GetLaunchFlags()
flags &= ~lldb.eLaunchFlagDisableASLR
launch_info.SetLaunchFlags(flags)
error = lldb.SBError()
process = target.Launch(launch_info, error)
self.assertTrue(process, PROCESS_IS_VALID)
# Did we hit our breakpoint?
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
self.assertTrue(
len(threads) == 1,
"There should be a thread stopped at our breakpoint")
# The hit count for the breakpoint should be 1.
self.assertTrue(breakpoint.GetHitCount() == 1)
process.Kill()
# Now re-launch and see that we hit the breakpoint again:
launch_info.Clear()
launch_info.SetLaunchFlags(flags)
process = target.Launch(launch_info, error)
self.assertTrue(process, PROCESS_IS_VALID)
thread = get_threads_stopped_at_breakpoint(process, breakpoint)
self.assertTrue(
len(threads) == 1,
"There should be a thread stopped at our breakpoint")
# The hit count for the breakpoint should now be 2.
self.assertTrue(breakpoint.GetHitCount() == 2)

View File

@ -0,0 +1,49 @@
"""
Test that breakpoints set on a bad address say they are bad.
"""
from __future__ import print_function
import os
import time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class BadAddressBreakpointTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def test_bad_address_breakpoints(self):
"""Test that breakpoints set on a bad address say they are bad."""
self.build()
self.address_breakpoints()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def address_breakpoints(self):
"""Test that breakpoints set on a bad address say they are bad."""
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
"Set a breakpoint here", lldb.SBFileSpec("main.c"))
# Now see if we can read from 0. If I can't do that, I don't have a good way to know
# what an illegal address is...
error = lldb.SBError()
ptr = process.ReadPointerFromMemory(0x0, error)
if not error.Success():
bkpt = target.BreakpointCreateByAddress(0x0)
for bp_loc in bkpt:
self.assertTrue(bp_loc.IsResolved() == False)
else:
self.fail(
"Could not find an illegal address at which to set a bad breakpoint.")

View File

@ -0,0 +1,8 @@
#include <stdio.h>
int
main()
{
printf ("Set a breakpoint here.\n");
return 0;
}

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS += -std=c99
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,104 @@
"""
Test that the breakpoint auto-continue flag works correctly.
"""
from __future__ import print_function
import os
import time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class BreakpointAutoContinue(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def test_breakpoint_auto_continue(self):
"""Make sure the auto continue continues with no other complications"""
self.build()
self.simple_auto_continue()
def test_auto_continue_with_command(self):
"""Add a command, make sure the command gets run"""
self.build()
self.auto_continue_with_command()
def test_auto_continue_on_location(self):
"""Set auto-continue on a location and make sure only that location continues"""
self.build()
self.auto_continue_location()
def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
pattern="Set a breakpoint here"):
exe = os.path.join(os.getcwd(), "a.out")
self.target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target.IsValid(), "Target is not valid")
extra_options_txt = "--auto-continue 1 "
if additional_options:
extra_options_txt += additional_options
bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
extra_options = extra_options_txt,
num_expected_locations = num_expected_loc)
return bpno
def launch_it (self, expected_state):
error = lldb.SBError()
launch_info = lldb.SBLaunchInfo(None)
launch_info.SetWorkingDirectory(self.get_process_working_directory())
process = self.target.Launch(launch_info, error)
self.assertTrue(error.Success(), "Launch failed.")
state = process.GetState()
self.assertEqual(state, expected_state, "Didn't get expected state")
return process
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def simple_auto_continue(self):
bpno = self.make_target_and_bkpt()
process = self.launch_it(lldb.eStateExited)
bkpt = self.target.FindBreakpointByID(bpno)
self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
def auto_continue_with_command(self):
bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
process = self.launch_it(lldb.eStateStopped)
state = process.GetState()
self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
bkpt = self.target.FindBreakpointByID(bpno)
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
def auto_continue_location(self):
bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
bkpt = self.target.FindBreakpointByID(bpno)
bkpt.SetAutoContinue(False)
loc = lldb.SBBreakpointLocation()
for i in range(0,2):
func_name = bkpt.location[i].GetAddress().function.name
if func_name == "main":
loc = bkpt.location[i]
self.assertTrue(loc.IsValid(), "Didn't find a location in main")
loc.SetAutoContinue(True)
process = self.launch_it(lldb.eStateStopped)
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
func_name = threads[0].frame[0].function.name
self.assertEqual(func_name, "call_me")

View File

@ -0,0 +1,19 @@
#include <stdio.h>
void
call_me()
{
printf("Set another breakpoint here.\n");
}
int
main()
{
int change_me = 0;
for (int i = 0; i < 2; i++)
{
printf ("Set a breakpoint here: %d with: %d.\n", i, change_me);
}
call_me();
return 0;
}

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS += -std=c99
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,129 @@
"""
Test case sensitivity of paths on Windows / POSIX
llvm.org/pr22667
"""
import os
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
from lldbsuite.test import lldbplatform, lldbplatformutil
class BreakpointCaseSensitivityTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
BREAKPOINT_TEXT = 'Set a breakpoint here'
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
self.line = line_number('main.c', self.BREAKPOINT_TEXT)
@skipIf(hostoslist=no_match(['windows'])) # Skip for non-windows platforms
def test_breakpoint_matches_file_with_different_case(self):
"""Set breakpoint on file, should match files with different case on Windows"""
self.build()
self.case_sensitivity_breakpoint(True)
@skipIf(hostoslist=['windows']) # Skip for windows platforms
def test_breakpoint_doesnt_match_file_with_different_case(self):
"""Set breakpoint on file, shouldn't match files with different case on POSIX systems"""
self.build()
self.case_sensitivity_breakpoint(False)
def case_sensitivity_breakpoint(self, case_insensitive):
"""Set breakpoint on file, should match files with different case if case_insensitive is True"""
# use different case to check CreateTarget
exe = 'a.out'
if case_insensitive:
exe = exe.upper()
exe = os.path.join(os.getcwd(), exe)
# Create a target by the debugger.
self.target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target, VALID_TARGET)
cwd = os.getcwd()
# try both BreakpointCreateByLocation and BreakpointCreateBySourceRegex
for regex in [False, True]:
# should always hit
self.check_breakpoint('main.c', regex, True)
# should always hit
self.check_breakpoint(os.path.join(cwd, 'main.c'), regex, True)
# different case for directory
self.check_breakpoint(os.path.join(cwd.upper(), 'main.c'),
regex,
case_insensitive)
# different case for file
self.check_breakpoint('Main.c',
regex,
case_insensitive)
# different case for both
self.check_breakpoint(os.path.join(cwd.upper(), 'Main.c'),
regex,
case_insensitive)
def check_breakpoint(self, file, source_regex, should_hit):
"""
Check breakpoint hit at given file set by given method
file:
File where insert the breakpoint
source_regex:
True for testing using BreakpointCreateBySourceRegex,
False for BreakpointCreateByLocation
should_hit:
True if the breakpoint should hit, False otherwise
"""
desc = ' file %s set by %s' % (
file, 'regex' if source_regex else 'location')
if source_regex:
breakpoint = self.target.BreakpointCreateBySourceRegex(
self.BREAKPOINT_TEXT, lldb.SBFileSpec(file))
else:
breakpoint = self.target.BreakpointCreateByLocation(
file, self.line)
self.assertEqual(breakpoint and breakpoint.GetNumLocations() == 1,
should_hit,
VALID_BREAKPOINT + desc)
# Get the breakpoint location from breakpoint after we verified that,
# indeed, it has one location.
location = breakpoint.GetLocationAtIndex(0)
self.assertEqual(location.IsValid(),
should_hit,
VALID_BREAKPOINT_LOCATION + desc)
process = self.target.LaunchSimple(
None, None, self.get_process_working_directory())
self.assertTrue(process, PROCESS_IS_VALID + desc)
if should_hit:
# Did we hit our breakpoint?
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
self.assertEqual(
len(threads),
1,
"There should be a thread stopped at breakpoint" +
desc)
# The hit count for the breakpoint should be 1.
self.assertEqual(breakpoint.GetHitCount(), 1)
else:
# check the breakpoint was not hit
self.assertEqual(lldb.eStateExited, process.GetState())
self.assertEqual(breakpoint.GetHitCount(), 0)
# let process finish
process.Continue()
# cleanup
self.target.BreakpointDelete(breakpoint.GetID())

View File

@ -0,0 +1,8 @@
#include <stdio.h>
int
main()
{
printf("Set a breakpoint here.\n");
return 0;
}

View File

@ -0,0 +1,5 @@
LEVEL = ../../../make
C_SOURCES := main.c a.c b.c
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,299 @@
"""
Test lldb breakpoint command add/list/delete.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class BreakpointCommandTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
@classmethod
def classCleanup(cls):
"""Cleanup the test byproduct of breakpoint_command_sequence(self)."""
cls.RemoveTempFile("output.txt")
cls.RemoveTempFile("output2.txt")
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
def test_breakpoint_command_sequence(self):
"""Test a sequence of breakpoint command add, list, and delete."""
self.build()
self.breakpoint_command_sequence()
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24528")
def test_script_parameters(self):
"""Test a sequence of breakpoint command add, list, and delete."""
self.build()
self.breakpoint_command_script_parameters()
def test_commands_on_creation(self):
self.build()
self.breakpoint_commands_on_creation()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.line = line_number('main.c', '// Set break point at this line.')
# disable "There is a running process, kill it and restart?" prompt
self.runCmd("settings set auto-confirm true")
self.addTearDownHook(
lambda: self.runCmd("settings clear auto-confirm"))
def breakpoint_command_sequence(self):
"""Test a sequence of breakpoint command add, list, and delete."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add three breakpoints on the same line. The first time we don't specify the file,
# since the default file is the one containing main:
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1, loc_exact=True)
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
# Breakpoint 4 - set at the same location as breakpoint 1 to test
# setting breakpoint commands on two breakpoints at a time
lldbutil.run_break_set_by_file_and_line(
self, None, self.line, num_expected_locations=1, loc_exact=True)
# Now add callbacks for the breakpoints just created.
self.runCmd(
"breakpoint command add -s command -o 'frame variable --show-types --scope' 1 4")
self.runCmd(
"breakpoint command add -s python -o 'here = open(\"output.txt\", \"w\"); here.write(\"lldb\\n\"); here.close()' 2")
self.runCmd(
"breakpoint command add --python-function bktptcmd.function 3")
# Check that the breakpoint commands are correctly set.
# The breakpoint list now only contains breakpoint 1.
self.expect(
"breakpoint list", "Breakpoints 1 & 2 created", substrs=[
"2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
self.line], patterns=[
"1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
self.line])
self.expect(
"breakpoint list -f",
"Breakpoints 1 & 2 created",
substrs=[
"2: file = 'main.c', line = %d, exact_match = 0, locations = 1" %
self.line],
patterns=[
"1: file = '.*main.c', line = %d, exact_match = 0, locations = 1" %
self.line,
"1.1: .+at main.c:%d, .+unresolved, hit count = 0" %
self.line,
"2.1: .+at main.c:%d, .+unresolved, hit count = 0" %
self.line])
self.expect("breakpoint command list 1", "Breakpoint 1 command ok",
substrs=["Breakpoint commands:",
"frame variable --show-types --scope"])
self.expect("breakpoint command list 2", "Breakpoint 2 command ok",
substrs=["Breakpoint commands (Python):",
"here = open",
"here.write",
"here.close()"])
self.expect("breakpoint command list 3", "Breakpoint 3 command ok",
substrs=["Breakpoint commands (Python):",
"bktptcmd.function(frame, bp_loc, internal_dict)"])
self.expect("breakpoint command list 4", "Breakpoint 4 command ok",
substrs=["Breakpoint commands:",
"frame variable --show-types --scope"])
self.runCmd("breakpoint delete 4")
self.runCmd("command script import --allow-reload ./bktptcmd.py")
# Next lets try some other breakpoint kinds. First break with a regular expression
# and then specify only one file. The first time we should get two locations,
# the second time only one:
lldbutil.run_break_set_by_regexp(
self, r"._MyFunction", num_expected_locations=2)
lldbutil.run_break_set_by_regexp(
self,
r"._MyFunction",
extra_options="-f a.c",
num_expected_locations=1)
lldbutil.run_break_set_by_regexp(
self,
r"._MyFunction",
extra_options="-f a.c -f b.c",
num_expected_locations=2)
# Now try a source regex breakpoint:
lldbutil.run_break_set_by_source_regexp(
self,
r"is about to return [12]0",
extra_options="-f a.c -f b.c",
num_expected_locations=2)
lldbutil.run_break_set_by_source_regexp(
self,
r"is about to return [12]0",
extra_options="-f a.c",
num_expected_locations=1)
# Run the program. Remove 'output.txt' if it exists.
self.RemoveTempFile("output.txt")
self.RemoveTempFile("output2.txt")
self.runCmd("run", RUN_SUCCEEDED)
# Check that the file 'output.txt' exists and contains the string
# "lldb".
# The 'output.txt' file should now exist.
self.assertTrue(
os.path.isfile("output.txt"),
"'output.txt' exists due to breakpoint command for breakpoint 2.")
self.assertTrue(
os.path.isfile("output2.txt"),
"'output2.txt' exists due to breakpoint command for breakpoint 3.")
# Read the output file produced by running the program.
with open('output.txt', 'r') as f:
output = f.read()
self.expect(
output,
"File 'output.txt' and the content matches",
exe=False,
startstr="lldb")
with open('output2.txt', 'r') as f:
output = f.read()
self.expect(
output,
"File 'output2.txt' and the content matches",
exe=False,
startstr="lldb")
# Finish the program.
self.runCmd("process continue")
# Remove the breakpoint command associated with breakpoint 1.
self.runCmd("breakpoint command delete 1")
# Remove breakpoint 2.
self.runCmd("breakpoint delete 2")
self.expect(
"breakpoint command list 1",
startstr="Breakpoint 1 does not have an associated command.")
self.expect(
"breakpoint command list 2",
error=True,
startstr="error: '2' is not a currently valid breakpoint ID.")
# The breakpoint list now only contains breakpoint 1.
self.expect(
"breakpoint list -f",
"Breakpoint 1 exists",
patterns=[
"1: file = '.*main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
self.line,
"hit count = 1"])
# Not breakpoint 2.
self.expect(
"breakpoint list -f",
"No more breakpoint 2",
matching=False,
substrs=[
"2: file = 'main.c', line = %d, exact_match = 0, locations = 1, resolved = 1" %
self.line])
# Run the program again, with breakpoint 1 remaining.
self.runCmd("run", RUN_SUCCEEDED)
# We should be stopped again due to breakpoint 1.
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])
# The breakpoint should have a hit count of 2.
self.expect("breakpoint list -f", BREAKPOINT_HIT_TWICE,
substrs=['resolved, hit count = 2'])
def breakpoint_command_script_parameters(self):
"""Test that the frame and breakpoint location are being properly passed to the script breakpoint command function."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Add a breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=1, loc_exact=True)
# Now add callbacks for the breakpoints just created.
self.runCmd("breakpoint command add -s python -o 'here = open(\"output-2.txt\", \"w\"); here.write(str(frame) + \"\\n\"); here.write(str(bp_loc) + \"\\n\"); here.close()' 1")
# Remove 'output-2.txt' if it already exists.
if (os.path.exists('output-2.txt')):
os.remove('output-2.txt')
# Run program, hit breakpoint, and hopefully write out new version of
# 'output-2.txt'
self.runCmd("run", RUN_SUCCEEDED)
# Check that the file 'output.txt' exists and contains the string
# "lldb".
# The 'output-2.txt' file should now exist.
self.assertTrue(
os.path.isfile("output-2.txt"),
"'output-2.txt' exists due to breakpoint command for breakpoint 1.")
# Read the output file produced by running the program.
with open('output-2.txt', 'r') as f:
output = f.read()
self.expect(
output,
"File 'output-2.txt' and the content matches",
exe=False,
startstr="frame #0:",
patterns=["1.* where = .*main .* resolved, hit count = 1"])
# Now remove 'output-2.txt'
os.remove('output-2.txt')
def breakpoint_commands_on_creation(self):
"""Test that setting breakpoint commands when creating the breakpoint works"""
exe = os.path.join(os.getcwd(), "a.out")
target = self.dbg.CreateTarget(exe)
self.assertTrue(target.IsValid(), "Created an invalid target.")
# Add a breakpoint.
lldbutil.run_break_set_by_file_and_line(
self, "main.c", self.line, num_expected_locations=1, loc_exact=True,
extra_options='-C bt -C "thread list" -C continue')
bkpt = target.FindBreakpointByID(1)
self.assertTrue(bkpt.IsValid(), "Couldn't find breakpoint 1")
com_list = lldb.SBStringList()
bkpt.GetCommandLineCommands(com_list)
self.assertEqual(com_list.GetSize(), 3, "Got the wrong number of commands")
self.assertEqual(com_list.GetStringAtIndex(0), "bt", "First bt")
self.assertEqual(com_list.GetStringAtIndex(1), "thread list", "Next thread list")
self.assertEqual(com_list.GetStringAtIndex(2), "continue", "Last continue")

View File

@ -0,0 +1,110 @@
"""
Test that you can set breakpoint commands successfully with the Python API's:
"""
from __future__ import print_function
import os
import re
import sys
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class PythonBreakpointCommandSettingTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
my_var = 10
@add_test_categories(['pyapi'])
def test_step_out_python(self):
"""Test stepping out using avoid-no-debug with dsyms."""
self.build()
self.do_set_python_command_from_python()
def setUp(self):
TestBase.setUp(self)
self.main_source = "main.c"
self.main_source_spec = lldb.SBFileSpec(self.main_source)
def do_set_python_command_from_python(self):
exe = os.path.join(os.getcwd(), "a.out")
error = lldb.SBError()
self.target = self.dbg.CreateTarget(exe)
self.assertTrue(self.target, VALID_TARGET)
body_bkpt = self.target.BreakpointCreateBySourceRegex(
"Set break point at this line.", self.main_source_spec)
self.assertTrue(body_bkpt, VALID_BREAKPOINT)
func_bkpt = self.target.BreakpointCreateBySourceRegex(
"Set break point at this line.", self.main_source_spec)
self.assertTrue(func_bkpt, VALID_BREAKPOINT)
# Also test that setting a source regex breakpoint with an empty file
# spec list sets it on all files:
no_files_bkpt = self.target.BreakpointCreateBySourceRegex(
"Set a breakpoint here", lldb.SBFileSpecList(), lldb.SBFileSpecList())
self.assertTrue(no_files_bkpt, VALID_BREAKPOINT)
num_locations = no_files_bkpt.GetNumLocations()
self.assertTrue(
num_locations >= 2,
"Got at least two breakpoint locations")
got_one_in_A = False
got_one_in_B = False
for idx in range(0, num_locations):
comp_unit = no_files_bkpt.GetLocationAtIndex(idx).GetAddress().GetSymbolContext(
lldb.eSymbolContextCompUnit).GetCompileUnit().GetFileSpec()
print("Got comp unit: ", comp_unit.GetFilename())
if comp_unit.GetFilename() == "a.c":
got_one_in_A = True
elif comp_unit.GetFilename() == "b.c":
got_one_in_B = True
self.assertTrue(got_one_in_A, "Failed to match the pattern in A")
self.assertTrue(got_one_in_B, "Failed to match the pattern in B")
self.target.BreakpointDelete(no_files_bkpt.GetID())
PythonBreakpointCommandSettingTestCase.my_var = 10
error = lldb.SBError()
error = body_bkpt.SetScriptCallbackBody("\
import TestBreakpointCommandsFromPython\n\
TestBreakpointCommandsFromPython.PythonBreakpointCommandSettingTestCase.my_var = 20\n\
print('Hit breakpoint')")
self.assertTrue(
error.Success(),
"Failed to set the script callback body: %s." %
(error.GetCString()))
self.dbg.HandleCommand(
"command script import --allow-reload ./bktptcmd.py")
func_bkpt.SetScriptCallbackFunction("bktptcmd.function")
# We will use the function that touches a text file, so remove it
# first:
self.RemoveTempFile("output2.txt")
# Now launch the process, and do not stop at entry point.
self.process = self.target.LaunchSimple(
None, None, self.get_process_working_directory())
self.assertTrue(self.process, PROCESS_IS_VALID)
# Now finish, and make sure the return value is correct.
threads = lldbutil.get_threads_stopped_at_breakpoint(
self.process, body_bkpt)
self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.")
self.thread = threads[0]
self.assertTrue(PythonBreakpointCommandSettingTestCase.my_var == 20)
# Check for the function version as well, which produced this file:
# Remember to clean up after ourselves...
self.assertTrue(
os.path.isfile("output2.txt"),
"'output2.txt' exists due to breakpoint command for breakpoint function.")
self.RemoveTempFile("output2.txt")

View File

@ -0,0 +1,72 @@
"""
Test _regexp-break command which uses regular expression matching to dispatch to other built in breakpoint commands.
"""
from __future__ import print_function
import os
import time
import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil
class RegexpBreakCommandTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
def test(self):
"""Test _regexp-break command."""
self.build()
self.regexp_break_command()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to break inside main().
self.source = 'main.c'
self.line = line_number(
self.source, '// Set break point at this line.')
def regexp_break_command(self):
"""Test the super consie "b" command, which is analias for _regexp-break."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
break_results = lldbutil.run_break_set_command(
self, "b %d" %
self.line)
lldbutil.check_breakpoint_result(
self,
break_results,
file_name='main.c',
line_number=self.line,
num_locations=1)
break_results = lldbutil.run_break_set_command(
self, "b %s:%d" % (self.source, self.line))
lldbutil.check_breakpoint_result(
self,
break_results,
file_name='main.c',
line_number=self.line,
num_locations=1)
# Check breakpoint with full file path.
full_path = os.path.join(os.getcwd(), self.source)
break_results = lldbutil.run_break_set_command(
self, "b %s:%d" % (full_path, self.line))
lldbutil.check_breakpoint_result(
self,
break_results,
file_name='main.c',
line_number=self.line,
num_locations=1)
self.runCmd("run", RUN_SUCCEEDED)
# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs=['stopped',
'stop reason = breakpoint'])

View File

@ -0,0 +1,9 @@
#include <stdio.h>
int
a_MyFunction ()
{
// Set a breakpoint here.
printf ("a is about to return 10.\n");
return 10;
}

View File

@ -0,0 +1,9 @@
#include <stdio.h>
int
b_MyFunction ()
{
// Set a breakpoint here.
printf ("b is about to return 20.\n");
return 20;
}

View File

@ -0,0 +1,7 @@
from __future__ import print_function
def function(frame, bp_loc, dict):
there = open("output2.txt", "w")
print("lldb", file=there)
there.close()

View File

@ -0,0 +1,13 @@
//===-- main.c --------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main (int argc, char const *argv[])
{
return 0; // Set break point at this line.
}

View File

@ -0,0 +1,6 @@
LEVEL = ../../../make
C_SOURCES := main.c
CFLAGS_EXTRAS += -std=c99
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,237 @@
"""
Test breakpoint conditions with 'breakpoint modify -c <expr> id'.
"""
from __future__ import print_function
import os
import time
import re
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class BreakpointConditionsTestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
# Requires EE to support COFF on Windows (http://llvm.org/pr22232)
@skipIfWindows
def test_breakpoint_condition_and_run_command(self):
"""Exercise breakpoint condition with 'breakpoint modify -c <expr> id'."""
self.build()
self.breakpoint_conditions()
# Requires EE to support COFF on Windows (http://llvm.org/pr22232)
@skipIfWindows
def test_breakpoint_condition_inline_and_run_command(self):
"""Exercise breakpoint condition inline with 'breakpoint set'."""
self.build()
self.breakpoint_conditions(inline=True)
# Requires EE to support COFF on Windows (http://llvm.org/pr22232)
@skipIfWindows
@add_test_categories(['pyapi'])
def test_breakpoint_condition_and_python_api(self):
"""Use Python APIs to set breakpoint conditions."""
self.build()
self.breakpoint_conditions_python()
# Requires EE to support COFF on Windows (http://llvm.org/pr22232)
@skipIfWindows
@add_test_categories(['pyapi'])
def test_breakpoint_invalid_condition_and_python_api(self):
"""Use Python APIs to set breakpoint conditions."""
self.build()
self.breakpoint_invalid_conditions_python()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number to of function 'c'.
self.line1 = line_number(
'main.c', '// Find the line number of function "c" here.')
self.line2 = line_number(
'main.c', "// Find the line number of c's parent call here.")
def breakpoint_conditions(self, inline=False):
"""Exercise breakpoint condition with 'breakpoint modify -c <expr> id'."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
if inline:
# Create a breakpoint by function name 'c' and set the condition.
lldbutil.run_break_set_by_symbol(
self,
"c",
extra_options="-c 'val == 3'",
num_expected_locations=1,
sym_exact=True)
else:
# Create a breakpoint by function name 'c'.
lldbutil.run_break_set_by_symbol(
self, "c", num_expected_locations=1, sym_exact=True)
# And set a condition on the breakpoint to stop on when 'val == 3'.
self.runCmd("breakpoint modify -c 'val == 3' 1")
# Now run the program.
self.runCmd("run", RUN_SUCCEEDED)
# The process should be stopped at this point.
self.expect("process status", PROCESS_STOPPED,
patterns=['Process .* stopped'])
# 'frame variable --show-types val' should return 3 due to breakpoint condition.
self.expect(
"frame variable --show-types val",
VARIABLES_DISPLAYED_CORRECTLY,
startstr='(int) val = 3')
# Also check the hit count, which should be 3, by design.
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs=["resolved = 1",
"Condition: val == 3",
"hit count = 1"])
# The frame #0 should correspond to main.c:36, the executable statement
# in function name 'c'. And the parent frame should point to
# main.c:24.
self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT_CONDITION,
#substrs = ["stop reason = breakpoint"],
patterns=["frame #0.*main.c:%d" % self.line1,
"frame #1.*main.c:%d" % self.line2])
# Test that "breakpoint modify -c ''" clears the condition for the last
# created breakpoint, so that when the breakpoint hits, val == 1.
self.runCmd("process kill")
self.runCmd("breakpoint modify -c ''")
self.expect(
"breakpoint list -f",
BREAKPOINT_STATE_CORRECT,
matching=False,
substrs=["Condition:"])
# Now run the program again.
self.runCmd("run", RUN_SUCCEEDED)
# The process should be stopped at this point.
self.expect("process status", PROCESS_STOPPED,
patterns=['Process .* stopped'])
# 'frame variable --show-types val' should return 1 since it is the first breakpoint hit.
self.expect(
"frame variable --show-types val",
VARIABLES_DISPLAYED_CORRECTLY,
startstr='(int) val = 1')
self.runCmd("process kill")
def breakpoint_conditions_python(self):
"""Use Python APIs to set breakpoint conditions."""
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateByName('c', 'a.out')
#print("breakpoint:", breakpoint)
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() == 1,
VALID_BREAKPOINT)
# We didn't associate a thread index with the breakpoint, so it should
# be invalid.
self.assertTrue(breakpoint.GetThreadIndex() == lldb.UINT32_MAX,
"The thread index should be invalid")
# The thread name should be invalid, too.
self.assertTrue(breakpoint.GetThreadName() is None,
"The thread name should be invalid")
# Let's set the thread index for this breakpoint and verify that it is,
# indeed, being set correctly.
# There's only one thread for the process.
breakpoint.SetThreadIndex(1)
self.assertTrue(breakpoint.GetThreadIndex() == 1,
"The thread index has been set correctly")
# Get the breakpoint location from breakpoint after we verified that,
# indeed, it has one location.
location = breakpoint.GetLocationAtIndex(0)
self.assertTrue(location and
location.IsEnabled(),
VALID_BREAKPOINT_LOCATION)
# Set the condition on the breakpoint location.
location.SetCondition('val == 3')
self.expect(location.GetCondition(), exe=False,
startstr='val == 3')
# 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)
# Frame #0 should be on self.line1 and the break condition should hold.
from lldbsuite.test.lldbutil import get_stopped_thread
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertTrue(
thread.IsValid(),
"There should be a thread stopped due to breakpoint condition")
frame0 = thread.GetFrameAtIndex(0)
var = frame0.FindValue('val', lldb.eValueTypeVariableArgument)
self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and
var.GetValue() == '3')
# The hit count for the breakpoint should be 1.
self.assertTrue(breakpoint.GetHitCount() == 1)
# Test that the condition expression didn't create a result variable:
options = lldb.SBExpressionOptions()
value = frame0.EvaluateExpression("$0", options)
self.assertTrue(value.GetError().Fail(),
"Conditions should not make result variables.")
process.Continue()
def breakpoint_invalid_conditions_python(self):
"""Use Python APIs to set breakpoint conditions."""
exe = os.path.join(os.getcwd(), "a.out")
# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
# Now create a breakpoint on main.c by name 'c'.
breakpoint = target.BreakpointCreateByName('c', 'a.out')
#print("breakpoint:", breakpoint)
self.assertTrue(breakpoint and
breakpoint.GetNumLocations() == 1,
VALID_BREAKPOINT)
# Set the condition on the breakpoint.
breakpoint.SetCondition('no_such_variable == not_this_one_either')
self.expect(breakpoint.GetCondition(), exe=False,
startstr='no_such_variable == not_this_one_either')
# 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)
# Frame #0 should be on self.line1 and the break condition should hold.
from lldbsuite.test.lldbutil import get_stopped_thread
thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertTrue(
thread.IsValid(),
"There should be a thread stopped due to breakpoint condition")
frame0 = thread.GetFrameAtIndex(0)
var = frame0.FindValue('val', lldb.eValueTypeVariableArgument)
self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1)
# The hit count for the breakpoint should be 1.
self.assertTrue(breakpoint.GetHitCount() == 1)

Some files were not shown because too many files have changed in this diff Show More