Skip to content

Commit d9442af

Browse files
committed
[lldb] Readd missing functionalities/breakpoint tests
It seems when I restructured the test folders the functionalities/breakpoint was deleted. This just reverts this change and re-adds the tests. llvm-svn: 371512
1 parent 3729b17 commit d9442af

File tree

108 files changed

+5369
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+5369
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LEVEL = ../../../make
2+
3+
C_SOURCES := main.c
4+
CFLAGS_EXTRAS += -std=c99
5+
6+
include $(LEVEL)/Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""
2+
Test address breakpoints set with shared library of SBAddress work correctly.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import lldb
9+
import lldbsuite.test.lldbutil as lldbutil
10+
from lldbsuite.test.lldbtest import *
11+
12+
13+
class AddressBreakpointTestCase(TestBase):
14+
15+
mydir = TestBase.compute_mydir(__file__)
16+
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
def test_address_breakpoints(self):
20+
"""Test address breakpoints set with shared library of SBAddress work correctly."""
21+
self.build()
22+
self.address_breakpoints()
23+
24+
def setUp(self):
25+
# Call super's setUp().
26+
TestBase.setUp(self)
27+
28+
def address_breakpoints(self):
29+
"""Test address breakpoints set with shared library of SBAddress work correctly."""
30+
exe = self.getBuildArtifact("a.out")
31+
32+
# Create a target by the debugger.
33+
target = self.dbg.CreateTarget(exe)
34+
self.assertTrue(target, VALID_TARGET)
35+
36+
# Now create a breakpoint on main.c by name 'c'.
37+
breakpoint = target.BreakpointCreateBySourceRegex(
38+
"Set a breakpoint here", lldb.SBFileSpec("main.c"))
39+
self.assertTrue(breakpoint and
40+
breakpoint.GetNumLocations() >= 1,
41+
VALID_BREAKPOINT)
42+
43+
# Get the breakpoint location from breakpoint after we verified that,
44+
# indeed, it has one location.
45+
location = breakpoint.GetLocationAtIndex(0)
46+
self.assertTrue(location and
47+
location.IsEnabled(),
48+
VALID_BREAKPOINT_LOCATION)
49+
50+
# Next get the address from the location, and create an address breakpoint using
51+
# that address:
52+
53+
address = location.GetAddress()
54+
target.BreakpointDelete(breakpoint.GetID())
55+
56+
breakpoint = target.BreakpointCreateBySBAddress(address)
57+
58+
# Disable ASLR. This will allow us to actually test (on platforms that support this flag)
59+
# that the breakpoint was able to track the module.
60+
61+
launch_info = lldb.SBLaunchInfo(None)
62+
flags = launch_info.GetLaunchFlags()
63+
flags &= ~lldb.eLaunchFlagDisableASLR
64+
launch_info.SetLaunchFlags(flags)
65+
66+
error = lldb.SBError()
67+
68+
process = target.Launch(launch_info, error)
69+
self.assertTrue(process, PROCESS_IS_VALID)
70+
71+
# Did we hit our breakpoint?
72+
from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
73+
threads = get_threads_stopped_at_breakpoint(process, breakpoint)
74+
self.assertTrue(
75+
len(threads) == 1,
76+
"There should be a thread stopped at our breakpoint")
77+
78+
# The hit count for the breakpoint should be 1.
79+
self.assertTrue(breakpoint.GetHitCount() == 1)
80+
81+
process.Kill()
82+
83+
# Now re-launch and see that we hit the breakpoint again:
84+
launch_info.Clear()
85+
launch_info.SetLaunchFlags(flags)
86+
87+
process = target.Launch(launch_info, error)
88+
self.assertTrue(process, PROCESS_IS_VALID)
89+
90+
thread = get_threads_stopped_at_breakpoint(process, breakpoint)
91+
self.assertTrue(
92+
len(threads) == 1,
93+
"There should be a thread stopped at our breakpoint")
94+
95+
# The hit count for the breakpoint should now be 2.
96+
self.assertTrue(breakpoint.GetHitCount() == 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Test that breakpoints set on a bad address say they are bad.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import lldb
9+
import lldbsuite.test.lldbutil as lldbutil
10+
from lldbsuite.test.lldbtest import *
11+
12+
13+
class BadAddressBreakpointTestCase(TestBase):
14+
15+
mydir = TestBase.compute_mydir(__file__)
16+
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
def test_bad_address_breakpoints(self):
20+
"""Test that breakpoints set on a bad address say they are bad."""
21+
self.build()
22+
self.address_breakpoints()
23+
24+
def setUp(self):
25+
# Call super's setUp().
26+
TestBase.setUp(self)
27+
28+
def address_breakpoints(self):
29+
"""Test that breakpoints set on a bad address say they are bad."""
30+
target, process, thread, bkpt = \
31+
lldbutil.run_to_source_breakpoint(self,
32+
"Set a breakpoint here",
33+
lldb.SBFileSpec("main.c"))
34+
35+
# Now see if we can read from 0. If I can't do that, I don't
36+
# have a good way to know what an illegal address is...
37+
error = lldb.SBError()
38+
39+
ptr = process.ReadPointerFromMemory(0x0, error)
40+
41+
if not error.Success():
42+
bkpt = target.BreakpointCreateByAddress(0x0)
43+
for bp_loc in bkpt:
44+
self.assertTrue(bp_loc.IsResolved() == False)
45+
else:
46+
self.fail(
47+
"Could not find an illegal address at which to set a bad breakpoint.")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int
4+
main()
5+
{
6+
printf ("Set a breakpoint here.\n");
7+
return 0;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LEVEL = ../../../make
2+
3+
C_SOURCES := main.c
4+
CFLAGS_EXTRAS += -std=c99
5+
6+
include $(LEVEL)/Makefile.rules
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Test that the breakpoint auto-continue flag works correctly.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import lldb
9+
import lldbsuite.test.lldbutil as lldbutil
10+
from lldbsuite.test.lldbtest import *
11+
12+
13+
class BreakpointAutoContinue(TestBase):
14+
15+
mydir = TestBase.compute_mydir(__file__)
16+
17+
NO_DEBUG_INFO_TESTCASE = True
18+
19+
def test_breakpoint_auto_continue(self):
20+
"""Make sure the auto continue continues with no other complications"""
21+
self.build()
22+
self.simple_auto_continue()
23+
24+
def test_auto_continue_with_command(self):
25+
"""Add a command, make sure the command gets run"""
26+
self.build()
27+
self.auto_continue_with_command()
28+
29+
def test_auto_continue_on_location(self):
30+
"""Set auto-continue on a location and make sure only that location continues"""
31+
self.build()
32+
self.auto_continue_location()
33+
34+
def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
35+
pattern="Set a breakpoint here"):
36+
exe = self.getBuildArtifact("a.out")
37+
self.target = self.dbg.CreateTarget(exe)
38+
self.assertTrue(self.target.IsValid(), "Target is not valid")
39+
40+
extra_options_txt = "--auto-continue 1 "
41+
if additional_options:
42+
extra_options_txt += additional_options
43+
bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
44+
extra_options = extra_options_txt,
45+
num_expected_locations = num_expected_loc)
46+
return bpno
47+
48+
def launch_it (self, expected_state):
49+
error = lldb.SBError()
50+
launch_info = lldb.SBLaunchInfo(None)
51+
launch_info.SetWorkingDirectory(self.get_process_working_directory())
52+
53+
process = self.target.Launch(launch_info, error)
54+
self.assertTrue(error.Success(), "Launch failed.")
55+
56+
state = process.GetState()
57+
self.assertEqual(state, expected_state, "Didn't get expected state")
58+
59+
return process
60+
61+
def setUp(self):
62+
# Call super's setUp().
63+
TestBase.setUp(self)
64+
65+
def simple_auto_continue(self):
66+
bpno = self.make_target_and_bkpt()
67+
process = self.launch_it(lldb.eStateExited)
68+
69+
bkpt = self.target.FindBreakpointByID(bpno)
70+
self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
71+
72+
def auto_continue_with_command(self):
73+
bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
74+
process = self.launch_it(lldb.eStateStopped)
75+
state = process.GetState()
76+
self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
77+
bkpt = self.target.FindBreakpointByID(bpno)
78+
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
79+
self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
80+
self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
81+
82+
def auto_continue_location(self):
83+
bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
84+
bkpt = self.target.FindBreakpointByID(bpno)
85+
bkpt.SetAutoContinue(False)
86+
87+
loc = lldb.SBBreakpointLocation()
88+
for i in range(0,2):
89+
func_name = bkpt.location[i].GetAddress().function.name
90+
if func_name == "main":
91+
loc = bkpt.location[i]
92+
93+
self.assertTrue(loc.IsValid(), "Didn't find a location in main")
94+
loc.SetAutoContinue(True)
95+
96+
process = self.launch_it(lldb.eStateStopped)
97+
98+
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
99+
self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
100+
func_name = threads[0].frame[0].function.name
101+
self.assertEqual(func_name, "call_me")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
void
4+
call_me()
5+
{
6+
printf("Set another breakpoint here.\n");
7+
}
8+
9+
int
10+
main()
11+
{
12+
int change_me = 0;
13+
for (int i = 0; i < 2; i++)
14+
{
15+
printf ("Set a breakpoint here: %d with: %d.\n", i, change_me);
16+
}
17+
call_me();
18+
return 0;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LEVEL = ../../../make
2+
3+
C_SOURCES := main.c
4+
CFLAGS_EXTRAS += -std=c99 -gcolumn-info
5+
6+
include $(LEVEL)/Makefile.rules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Test setting a breakpoint by line and column.
3+
"""
4+
5+
from __future__ import print_function
6+
7+
8+
import lldb
9+
from lldbsuite.test.decorators import *
10+
from lldbsuite.test.lldbtest import *
11+
from lldbsuite.test import lldbutil
12+
13+
14+
class BreakpointByLineAndColumnTestCase(TestBase):
15+
16+
mydir = TestBase.compute_mydir(__file__)
17+
18+
## Skip gcc version less 7.1 since it doesn't support -gcolumn-info
19+
@skipIf(compiler="gcc", compiler_version=['<', '7.1'])
20+
def testBreakpointByLineAndColumn(self):
21+
self.build()
22+
main_c = lldb.SBFileSpec("main.c")
23+
_, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self,
24+
main_c, 19, 50)
25+
self.expect("fr v did_call", substrs='1')
26+
in_then = False
27+
for i in range(breakpoint.GetNumLocations()):
28+
b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry()
29+
self.assertEqual(b_loc.GetLine(), 19)
30+
in_then |= b_loc.GetColumn() == 50
31+
self.assertTrue(in_then)
32+
33+
## Skip gcc version less 7.1 since it doesn't support -gcolumn-info
34+
@skipIf(compiler="gcc", compiler_version=['<', '7.1'])
35+
def testBreakpointByLine(self):
36+
self.build()
37+
main_c = lldb.SBFileSpec("main.c")
38+
_, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, main_c, 19)
39+
self.expect("fr v did_call", substrs='0')
40+
in_condition = False
41+
for i in range(breakpoint.GetNumLocations()):
42+
b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry()
43+
self.assertEqual(b_loc.GetLine(), 19)
44+
in_condition |= b_loc.GetColumn() < 30
45+
self.assertTrue(in_condition)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- main.c --------------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
int square(int x)
10+
{
11+
return x * x;
12+
}
13+
14+
int main (int argc, char const *argv[])
15+
{
16+
int did_call = 0;
17+
18+
// Line 20. v Column 50.
19+
if(square(argc+1) != 0) { did_call = 1; return square(argc); }
20+
// ^
21+
return square(0);
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
LEVEL = ../../../make
2+
3+
C_SOURCES := main.c a.c b.c
4+
5+
include $(LEVEL)/Makefile.rules

0 commit comments

Comments
 (0)