Avoid using hardcoded line number to break on. Use the line_number() utility

function to get the line number to break on during setUp().

llvm-svn: 116275
This commit is contained in:
Johnny Chen 2010-10-12 00:09:25 +00:00
parent c56f5b93c5
commit cd9b7779f3
3 changed files with 12 additions and 5 deletions

View File

@ -31,14 +31,21 @@ class BitfieldsTestCase(TestBase):
self.buildDwarf()
self.bitfields_variable_python()
def setUp(self):
super(BitfieldsTestCase, self).setUp()
# Find the line number to break inside main().
self.line = line_number('main.c', '// Set break point at this line.')
def bitfields_variable(self):
"""Test 'frame variable ...' on a variable with bitfields."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
# Break inside the main.
self.expect("breakpoint set -f main.c -l 42", BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.c', line = 42, locations = 1")
self.expect("breakpoint set -f main.c -l %d" % self.line,
BREAKPOINT_CREATED,
startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" %
self.line)
self.runCmd("run", RUN_SUCCEEDED)
@ -81,7 +88,7 @@ class BitfieldsTestCase(TestBase):
target = self.dbg.CreateTarget(exe)
self.assertTrue(target.IsValid(), VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation("main.c", 42)
breakpoint = target.BreakpointCreateByLocation("main.c", self.line)
self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
self.runCmd("run", RUN_SUCCEEDED, setCookie=False)

View File

@ -39,6 +39,6 @@ int main (int argc, char const *argv[])
bits.b7 = i; //// break $source:$line
for (i=0; i<(1<<4); i++)
bits.four = i; //// break $source:$line
return 0; //// continue
return 0; //// Set break point at this line.
}

View File

@ -232,7 +232,7 @@ def line_number(filename, string_to_match):
for i, line in enumerate(f):
if line.find(string_to_match) != -1:
# Found our match.
return i
return i+1
return -1
def pointer_size():