Skip to content

Commit bfde8dc

Browse files
author
Johnny Chen
committed
Update do_conditional_break() method impl to use all lldb Python APIs.
llvm-svn: 116117
1 parent b1b0ef7 commit bfde8dc

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lldb/test/conditional_break/TestConditionalBreak.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os, time
66
import re
77
import unittest2
8-
import lldb
8+
import lldb, lldbutil
99
from lldbtest import *
1010

1111
class ConditionalBreakTestCase(TestBase):
@@ -37,17 +37,22 @@ def test_with_dwarf_command(self):
3737
def do_conditional_break(self):
3838
"""Exercise some thread and frame APIs to break if c() is called by a()."""
3939
exe = os.path.join(os.getcwd(), "a.out")
40-
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
4140

42-
# Break on c().
43-
self.expect("breakpoint set -n c", BREAKPOINT_CREATED,
44-
startstr = "Breakpoint created: 1: name = 'c', locations = 1")
41+
target = self.dbg.CreateTarget(exe)
42+
self.assertTrue(target.IsValid(), VALID_TARGET)
4543

46-
self.runCmd("run", RUN_SUCCEEDED)
44+
breakpoint = target.BreakpointCreateByName("c", exe)
45+
self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT)
46+
47+
# Now launch the process, and do not stop at entry point.
48+
rc = lldb.SBError()
49+
self.process = target.Launch([''], [''], os.ctermid(), 0, False, rc)
50+
51+
self.assertTrue(rc.Success() and self.process.IsValid(), PROCESS_IS_VALID)
4752

4853
# The stop reason of the thread should be breakpoint.
49-
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
50-
substrs = ['state is Stopped', 'stop reason = breakpoint'])
54+
self.assertTrue(self.process.GetState() == lldb.eStateStopped,
55+
STOPPED_DUE_TO_BREAKPOINT)
5156

5257
# Suppose we are only interested in the call scenario where c()'s
5358
# immediate caller is a() and we want to find out the value passed from
@@ -56,31 +61,29 @@ def do_conditional_break(self):
5661
# The 10 in range(10) is just an arbitrary number, which means we would
5762
# like to try for at most 10 times.
5863
for j in range(10):
59-
target = self.dbg.GetSelectedTarget()
60-
process = target.GetProcess()
61-
thread = process.GetThreadAtIndex(0)
64+
thread = self.process.GetThreadAtIndex(0)
6265

6366
if thread.GetNumFrames() >= 2:
6467
frame0 = thread.GetFrameAtIndex(0)
6568
name0 = frame0.GetFunction().GetName()
6669
frame1 = thread.GetFrameAtIndex(1)
6770
name1 = frame1.GetFunction().GetName()
71+
#lldbutil.PrintStackTrace(thread)
6872
self.assertTrue(name0 == "c", "Break on function c()")
6973
if (name1 == "a"):
7074
line = frame1.GetLineEntry().GetLine()
7175
# By design, we know that a() calls c() only from main.c:27.
7276
# In reality, similar logic can be used to find out the call
7377
# site.
7478
self.assertTrue(line == 27, "Immediate caller a() at main.c:27")
75-
self.expect("thread backtrace", "Call site at a()",
76-
substrs = ["main.c:27"])
77-
self.expect("frame variable", "Passed in arg (int) val of 3",
78-
startstr = "(int) val = 3")
79+
80+
# And the local variable 'val' should have a value of (int) 3.
81+
val = frame1.LookupVar("val")
82+
self.assertTrue(val.GetTypeName() == "int", "'val' has int type")
83+
self.assertTrue(val.GetValue(frame1) == "3", "'val' has a value of 3")
7984
break
8085

81-
# This doesn't work?
82-
#process.Continue()
83-
self.runCmd("process continue")
86+
self.process.Continue()
8487

8588
def simulate_conditional_break_by_user(self):
8689
"""Simulate a user using lldb commands to break on c() if called from a()."""

0 commit comments

Comments
 (0)