This is an archive of the discontinued LLVM Phabricator instance.

LLDB tests modification for hardware breakpoints
ClosedPublic

Authored by georgiev on Oct 15 2021, 9:55 AM.

Details

Summary

LLDB now shows additional string 'hardware' when a hardware breakpoint is hit. Current test fail for those kind of breakpoints, as they match exact string, which doesn't include 'hardware'.
The proposed solution is a regex match with an optional include of 'hardware' string (zero or one).

Diff Detail

Event Timeline

georgiev requested review of this revision.Oct 15 2021, 9:55 AM
georgiev created this revision.

All these tests are testing the same sort of thing. It would be better to make an lldbutil function that does this test and convert all these tests over to that. This sort of change is exactly why we don't want code that's poking at command results to find info about things like breakpoints scattered all over the testsuite.

Actually, they aren't testing the same "sort" of thing, it's exactly the same test: "was the breakpoint hit once". But those tests are also really inaccurate as they just ask whether any breakpoint has a hit count of 1. It would be really easy to edit a test, add another breakpoint that gets hit before you get to this self.expect. In that case, this test would stop testing what it was intended to test.

I know you didn't add these expects, but if you have the time it would be great to add lldbutils.GetBreakpointCount(breakpoint_no) and then actually pass the right breakpoint to the test...

What about the case when we have a logical BP with more than one location? the locations may have different hit count.
In particular we have a test like:
patterns=[

"1\.1: .+ unresolved, hit count = 0 +Options: disabled",
"1\.2: .+ resolved,( hardware,)? hit count = 1",
"1\.3: .+ resolved,( hardware,)? hit count = 1"])

If you have the breakpoint ID, you can find the SB Breakpoint and just ask it directly what it's hit count or location hit count are, and you don't have to scrub text output.

Jim

georgiev updated this revision to Diff 380714.EditedOct 19 2021, 9:41 AM

A diff updated with a new lldbutil function to test the breakpoint - check_breakpoint().

labath added a subscriber: labath.Oct 19 2021, 9:46 AM
labath added inline comments.
lldb/packages/Python/lldbsuite/test/lldbutil.py
736

None would be more pythonic

753–754

If you replace assertTrue(foo == bar) with assertEquals(foo, bar) then you get the failure message for free.

It looks like you missed one conversion. I agree with Pavel that None is not only more pythonic but also more lldbutils-y. Other than those nits, LGTM.

lldb/packages/Python/lldbsuite/test/lldbutil.py
738

These could be two lists or a list of duples to allow matching against more than one location at a time, but we can do also that when we need it.

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
-1–1

Why didn't you change this one to use your new function?

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py
-1–1

check_breakpoint checks the correctness of a breakpoint and its locations, whereas this test seems to be checking that side_effect is correctly updated inside the breakpoint command script.

georgiev updated this revision to Diff 380919.Oct 20 2021, 5:52 AM

Added breakpoint resolved check.
Addressed some of the comments.

georgiev updated this revision to Diff 380922.Oct 20 2021, 6:01 AM

Diff update

tatyana-krasnukha accepted this revision.EditedOct 25 2021, 10:13 AM

LGTM, but I would wait for one more approval.

This revision is now accepted and ready to land.Oct 25 2021, 10:13 AM
jingham accepted this revision.Oct 26 2021, 11:35 AM

There's one comment typo, but you can fix that on submission. Otherwise, LGTM.

lldb/packages/Python/lldbsuite/test/lldbutil.py
744

location -> locations

georgiev updated this revision to Diff 383282.Oct 29 2021, 2:51 AM
georgiev updated this revision to Diff 383284.
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2021, 12:38 AM

FYI, this broke all the TestObjCNewSyntax* tests. I *think* I've fixed them.

This change causes many test suite errors due to inline comment. Please fix ASAP

lldb/packages/Python/lldbsuite/test/lldbutil.py
759

This line throws and exception when I run it on my system. It seems we have a function in lldbtest.py:

# utility methods that tests can use to access the current objects
def target(self):
    if not self.dbg:
        raise Exception('Invalid debugger instance')
    return self.dbg.GetSelectedTarget()

And many tests actually set "self.target" to be a lldb.SBTarget with lines like:

self.target = self.dbg.CreateTarget(exe)

So this test fails for many objective C tests now with an exception

The right fix IMHO is to rename the function in lldbtest.py from "def target(self):" to "def selected_target(self):" and then find all call sites and fix them.

FYI, this broke all the TestObjCNewSyntax* tests. I *think* I've fixed them.

I synced to top of tree, still having issues. What was the commit for your fix?

Never mind, it seems to be fixed. Although the problem I mentioned is still true where some test cases might set "self.target = debugger.CreateTarget(...)" and if those test cases try to use the check_breakpoint function. See suggested code edit for a potential fix.

lldb/packages/Python/lldbsuite/test/lldbutil.py
759

You can make this safer by doing the suggested code change