forked from OSchip/llvm-project
Added TestHelloWorld.py which exercises the Python APIs for target, breakpoint,
and process. Added comment within the file about issues of using LaunchProcess of SBTarget to launch a process (rdar://problem/8364687). llvm-svn: 112276
This commit is contained in:
parent
96b7f55a03
commit
82d404c886
|
@ -68,7 +68,7 @@ class TestArrayTypes(TestBase):
|
|||
|
||||
# The stop reason of the thread should be breakpoint.
|
||||
thread = target.GetProcess().GetThreadAtIndex(0)
|
||||
self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"),
|
||||
self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
|
||||
STOPPED_DUE_TO_BREAKPOINT)
|
||||
|
||||
# The breakpoint should have a hit count of 1.
|
||||
|
|
|
@ -69,7 +69,7 @@ class TestBitfields(TestBase):
|
|||
|
||||
# The stop reason of the thread should be breakpoint.
|
||||
thread = target.GetProcess().GetThreadAtIndex(0)
|
||||
self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"),
|
||||
self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
|
||||
STOPPED_DUE_TO_BREAKPOINT)
|
||||
|
||||
# The breakpoint should have a hit count of 1.
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
LEVEL = ../make
|
||||
|
||||
C_SOURCES := main.c
|
||||
|
||||
include $(LEVEL)/Makefile.rules
|
|
@ -0,0 +1,86 @@
|
|||
"""Test Python APIs for target, breakpoint, and process."""
|
||||
|
||||
import os, time
|
||||
import unittest2
|
||||
import lldb
|
||||
from lldbtest import *
|
||||
|
||||
class TestHelloWorld(TestBase):
|
||||
|
||||
mydir = "hello_world"
|
||||
|
||||
@unittest2.expectedFailure
|
||||
def test_hellp_world_python(self):
|
||||
"""Create target, breakpoint, launch a process, and then kill it."""
|
||||
|
||||
exe = os.path.join(os.getcwd(), "a.out")
|
||||
|
||||
target = self.dbg.CreateTarget(exe)
|
||||
|
||||
breakpoint = target.BreakpointCreateByLocation("main.c", 4)
|
||||
|
||||
# The default state after breakpoint creation should be enabled.
|
||||
self.assertTrue(breakpoint.IsEnabled(),
|
||||
"Breakpoint should be enabled after creation")
|
||||
|
||||
breakpoint.SetEnabled(False)
|
||||
self.assertTrue(not breakpoint.IsEnabled(),
|
||||
"Breakpoint.SetEnabled(False) works")
|
||||
|
||||
breakpoint.SetEnabled(True)
|
||||
self.assertTrue(breakpoint.IsEnabled(),
|
||||
"Breakpoint.SetEnabled(True) works")
|
||||
|
||||
# rdar://problem/8364687
|
||||
# SBTarget.LaunchProcess() issue (or is there some race condition)?
|
||||
|
||||
# The following approach of launching a process looks untidy and only
|
||||
# works sometimes.
|
||||
process = target.LaunchProcess([''], [''], os.ctermid(), False)
|
||||
|
||||
SR = process.GetThreadAtIndex(0).GetStopReason()
|
||||
count = 0
|
||||
while SR == StopReasonEnum("Invalid") or SR == StopReasonEnum("Signal"):
|
||||
print >> sys.stderr, "StopReason =", StopReasonString(SR)
|
||||
|
||||
time.sleep(1.0)
|
||||
print >> sys.stderr, "Continuing the process:", process
|
||||
process.Continue()
|
||||
|
||||
count = count + 1
|
||||
if count == 10:
|
||||
print >> sys.stderr, "Reached 10 iterations, giving up..."
|
||||
break
|
||||
|
||||
SR = process.GetThreadAtIndex(0).GetStopReason()
|
||||
|
||||
# End of section of launching a process.
|
||||
|
||||
# On the other hand, the following two lines of code are more reliable.
|
||||
#self.runCmd("run")
|
||||
#process = target.GetProcess()
|
||||
|
||||
self.runCmd("thread backtrace")
|
||||
self.runCmd("breakpoint list")
|
||||
self.runCmd("thread list")
|
||||
|
||||
# The stop reason of the thread should be breakpoint.
|
||||
thread = process.GetThreadAtIndex(0)
|
||||
|
||||
print >> sys.stderr, "StopReason =", StopReasonString(thread.GetStopReason())
|
||||
self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
|
||||
STOPPED_DUE_TO_BREAKPOINT)
|
||||
|
||||
# The breakpoint should have a hit count of 1.
|
||||
self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
|
||||
|
||||
# Now kill the process, and we are done.
|
||||
rc = process.Kill()
|
||||
self.assertTrue(rc.Success())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import atexit
|
||||
lldb.SBDebugger.Initialize()
|
||||
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
||||
unittest2.main()
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
printf("Hello world.\n");
|
||||
return 0;
|
||||
}
|
|
@ -149,28 +149,51 @@ def CMD_MSG(command):
|
|||
return "Command '%s' returns successfully" % (command)
|
||||
|
||||
#
|
||||
# Returns the enum from the input string stopReason.
|
||||
# Returns the enum from the input string.
|
||||
#
|
||||
def Enum(stopReason):
|
||||
if stopReason == "Invalid":
|
||||
def StopReasonEnum(string):
|
||||
if string == "Invalid":
|
||||
return 0
|
||||
elif stopReason == "None":
|
||||
elif string == "None":
|
||||
return 1
|
||||
elif stopReason == "Trace":
|
||||
elif string == "Trace":
|
||||
return 2
|
||||
elif stopReason == "Breakpoint":
|
||||
elif string == "Breakpoint":
|
||||
return 3
|
||||
elif stopReason == "Watchpoint":
|
||||
elif string == "Watchpoint":
|
||||
return 4
|
||||
elif stopReason == "Signal":
|
||||
elif string == "Signal":
|
||||
return 5
|
||||
elif stopReason == "Exception":
|
||||
elif string == "Exception":
|
||||
return 6
|
||||
elif stopReason == "PlanComplete":
|
||||
elif string == "PlanComplete":
|
||||
return 7
|
||||
else:
|
||||
raise Exception("Unknown stopReason string")
|
||||
|
||||
#
|
||||
# Returns the stopReason string given an enum.
|
||||
#
|
||||
def StopReasonString(enum):
|
||||
if enum == 0:
|
||||
return "Invalid"
|
||||
elif enum == 1:
|
||||
return "None"
|
||||
elif enum == 2:
|
||||
return "Trace"
|
||||
elif enum == 3:
|
||||
return "Breakpoint"
|
||||
elif enum == 4:
|
||||
return "Watchpoint"
|
||||
elif enum == 5:
|
||||
return "Signal"
|
||||
elif enum == 6:
|
||||
return "Exception"
|
||||
elif enum == 7:
|
||||
return "PlanComplete"
|
||||
else:
|
||||
raise Exception("Unknown stopReason enum")
|
||||
|
||||
#
|
||||
# Returns an env variable array from the os.environ map object.
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue