Summary:
The error message from the construct `assertTrue(a == b, "msg") ` are nearly always completely useless for actually debugging the issue.
This patch is just replacing this construct (and similar ones like `assertTrue(a != b, ...)` with the proper call to assertEqual or assertNotEquals.
This patch was mostly written by a shell script with some manual verification afterwards:
```
lang=python
import sys
def sanitize_line(line):
if line.strip().startswith("self.assertTrue(") and " == " in line:
line = line.replace("self.assertTrue(", "self.assertEquals(")
line = line.replace(" == ", ", ", 1)
if line.strip().startswith("self.assertTrue(") and " != " in line:
line = line.replace("self.assertTrue(", "self.assertNotEqual(")
line = line.replace(" != ", ", ", 1)
return line
for a in sys.argv[1:]:
with open(a, "r") as f:
lines = f.readlines()
with open(a, "w") as f:
for line in lines:
f.write(sanitize_line(line))
```
Reviewers: labath, JDevlieghere
Reviewed By: labath
Subscribers: abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74475
104 lines
3.7 KiB
Python
104 lines
3.7 KiB
Python
"""
|
|
Test lldb breakpoint setting by source regular expression.
|
|
This test just tests the source file & function restrictions.
|
|
"""
|
|
|
|
|
|
import lldb
|
|
from lldbsuite.test.decorators import *
|
|
from lldbsuite.test.lldbtest import *
|
|
from lldbsuite.test import lldbutil
|
|
|
|
|
|
class TestSourceRegexBreakpoints(TestBase):
|
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
def test_location(self):
|
|
self.build()
|
|
self.source_regex_locations()
|
|
|
|
def test_restrictions(self):
|
|
self.build()
|
|
self.source_regex_restrictions()
|
|
|
|
def source_regex_locations(self):
|
|
""" Test that restricting source expressions to files & to functions. """
|
|
# Create a target by the debugger.
|
|
exe = self.getBuildArtifact("a.out")
|
|
target = self.dbg.CreateTarget(exe)
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
# First look just in main:
|
|
target_files = lldb.SBFileSpecList()
|
|
target_files.Append(lldb.SBFileSpec("a.c"))
|
|
|
|
func_names = lldb.SBStringList()
|
|
func_names.AppendString("a_func")
|
|
|
|
source_regex = "Set . breakpoint here"
|
|
main_break = target.BreakpointCreateBySourceRegex(
|
|
source_regex, lldb.SBFileSpecList(), target_files, func_names)
|
|
num_locations = main_break.GetNumLocations()
|
|
self.assertTrue(
|
|
num_locations == 1,
|
|
"a.c in a_func should give one breakpoint, got %d." %
|
|
(num_locations))
|
|
|
|
loc = main_break.GetLocationAtIndex(0)
|
|
self.assertTrue(loc.IsValid(), "Got a valid location.")
|
|
address = loc.GetAddress()
|
|
self.assertTrue(
|
|
address.IsValid(),
|
|
"Got a valid address from the location.")
|
|
|
|
a_func_line = line_number("a.c", "Set A breakpoint here")
|
|
line_entry = address.GetLineEntry()
|
|
self.assertTrue(line_entry.IsValid(), "Got a valid line entry.")
|
|
self.assertEquals(line_entry.line, a_func_line,
|
|
"Our line number matches the one lldbtest found.")
|
|
|
|
def source_regex_restrictions(self):
|
|
""" Test that restricting source expressions to files & to functions. """
|
|
# Create a target by the debugger.
|
|
exe = self.getBuildArtifact("a.out")
|
|
target = self.dbg.CreateTarget(exe)
|
|
self.assertTrue(target, VALID_TARGET)
|
|
|
|
# First look just in main:
|
|
target_files = lldb.SBFileSpecList()
|
|
target_files.Append(lldb.SBFileSpec("main.c"))
|
|
source_regex = "Set . breakpoint here"
|
|
main_break = target.BreakpointCreateBySourceRegex(
|
|
source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList())
|
|
|
|
num_locations = main_break.GetNumLocations()
|
|
self.assertTrue(
|
|
num_locations == 2,
|
|
"main.c should have 2 matches, got %d." %
|
|
(num_locations))
|
|
|
|
# Now look in both files:
|
|
target_files.Append(lldb.SBFileSpec("a.c"))
|
|
|
|
main_break = target.BreakpointCreateBySourceRegex(
|
|
source_regex, lldb.SBFileSpecList(), target_files, lldb.SBStringList())
|
|
|
|
num_locations = main_break.GetNumLocations()
|
|
self.assertTrue(
|
|
num_locations == 4,
|
|
"main.c and a.c should have 4 matches, got %d." %
|
|
(num_locations))
|
|
|
|
# Now restrict it to functions:
|
|
func_names = lldb.SBStringList()
|
|
func_names.AppendString("main_func")
|
|
main_break = target.BreakpointCreateBySourceRegex(
|
|
source_regex, lldb.SBFileSpecList(), target_files, func_names)
|
|
|
|
num_locations = main_break.GetNumLocations()
|
|
self.assertTrue(
|
|
num_locations == 2,
|
|
"main_func in main.c and a.c should have 2 matches, got %d." %
|
|
(num_locations))
|