5
5
import os , time
6
6
import re
7
7
import unittest2
8
- import lldb
8
+ import lldb , lldbutil
9
9
from lldbtest import *
10
10
11
11
class ConditionalBreakTestCase (TestBase ):
@@ -37,17 +37,22 @@ def test_with_dwarf_command(self):
37
37
def do_conditional_break (self ):
38
38
"""Exercise some thread and frame APIs to break if c() is called by a()."""
39
39
exe = os .path .join (os .getcwd (), "a.out" )
40
- self .runCmd ("file " + exe , CURRENT_EXECUTABLE_SET )
41
40
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 )
45
43
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 )
47
52
48
53
# 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 )
51
56
52
57
# Suppose we are only interested in the call scenario where c()'s
53
58
# immediate caller is a() and we want to find out the value passed from
@@ -56,31 +61,29 @@ def do_conditional_break(self):
56
61
# The 10 in range(10) is just an arbitrary number, which means we would
57
62
# like to try for at most 10 times.
58
63
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 )
62
65
63
66
if thread .GetNumFrames () >= 2 :
64
67
frame0 = thread .GetFrameAtIndex (0 )
65
68
name0 = frame0 .GetFunction ().GetName ()
66
69
frame1 = thread .GetFrameAtIndex (1 )
67
70
name1 = frame1 .GetFunction ().GetName ()
71
+ #lldbutil.PrintStackTrace(thread)
68
72
self .assertTrue (name0 == "c" , "Break on function c()" )
69
73
if (name1 == "a" ):
70
74
line = frame1 .GetLineEntry ().GetLine ()
71
75
# By design, we know that a() calls c() only from main.c:27.
72
76
# In reality, similar logic can be used to find out the call
73
77
# site.
74
78
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" )
79
84
break
80
85
81
- # This doesn't work?
82
- #process.Continue()
83
- self .runCmd ("process continue" )
86
+ self .process .Continue ()
84
87
85
88
def simulate_conditional_break_by_user (self ):
86
89
"""Simulate a user using lldb commands to break on c() if called from a()."""
0 commit comments