blob: 65da3012934dc21ffb2dbcca8f49ce2f5785009d [file] [log] [blame]
Johnny Chen843f6892010-07-07 21:10:55 +00001"""
2Test that breakpoint by symbol name works correctly dlopen'ing a dynamic lib.
3"""
4
5import os, time
Johnny Chen75e28f92010-08-05 23:42:46 +00006import unittest2
Johnny Chen843f6892010-07-07 21:10:55 +00007import lldb
Johnny Chend85dae52010-08-09 23:44:24 +00008from lldbtest import *
Johnny Chen843f6892010-07-07 21:10:55 +00009
Johnny Chend85dae52010-08-09 23:44:24 +000010class TestLoadUnload(TestBase):
Johnny Chen843f6892010-07-07 21:10:55 +000011
12 mydir = "load_unload"
13
Johnny Chen30974392010-07-27 20:59:06 +000014 def test_load_unload(self):
Johnny Chen843f6892010-07-07 21:10:55 +000015 """Test breakpoint by name works correctly with dlopen'ing."""
16 res = self.res
17 exe = os.path.join(os.getcwd(), "a.out")
18 self.ci.HandleCommand("file " + exe, res)
Johnny Chend85dae52010-08-09 23:44:24 +000019 self.assertTrue(res.Succeeded(), CURRENT_EXECUTABLE_SET)
Johnny Chen843f6892010-07-07 21:10:55 +000020
21 # Break by function name a_function (not yet loaded).
22 self.ci.HandleCommand("breakpoint set -n a_function", res)
23 self.assertTrue(res.Succeeded())
24 self.assertTrue(res.GetOutput().startswith(
25 "Breakpoint created: 1: name = 'a_function', locations = 0 "
26 "(pending)"
Johnny Chend85dae52010-08-09 23:44:24 +000027 ),
28 BREAKPOINT_CREATED)
Johnny Chen843f6892010-07-07 21:10:55 +000029
30 self.ci.HandleCommand("run", res)
Johnny Chend85dae52010-08-09 23:44:24 +000031 #time.sleep(0.1)
32 self.assertTrue(res.Succeeded(), RUN_STOPPED)
Johnny Chen843f6892010-07-07 21:10:55 +000033
34 # The stop reason of the thread should be breakpoint and at a_function.
35 self.ci.HandleCommand("thread list", res)
36 output = res.GetOutput()
Johnny Chend85dae52010-08-09 23:44:24 +000037 self.assertTrue(res.Succeeded(), CMD_MSG('thread list'))
Johnny Chen843f6892010-07-07 21:10:55 +000038 self.assertTrue(output.find('state is Stopped') > 0 and
39 output.find('a_function') > 0 and
40 output.find('a.c:14') > 0 and
Johnny Chend85dae52010-08-09 23:44:24 +000041 output.find('stop reason = breakpoint') > 0,
42 STOPPED_DUE_TO_BREAKPOINT)
Johnny Chen843f6892010-07-07 21:10:55 +000043
44 # The breakpoint should have a hit count of 1.
45 self.ci.HandleCommand("breakpoint list", res)
46 self.assertTrue(res.Succeeded())
Johnny Chend85dae52010-08-09 23:44:24 +000047 self.assertTrue(res.GetOutput().find(' resolved, hit count = 1') > 0,
48 BREAKPOINT_HIT_ONCE)
Johnny Chen843f6892010-07-07 21:10:55 +000049
50 self.ci.HandleCommand("continue", res)
51 self.assertTrue(res.Succeeded())
52
53# # We should stop agaian at a_function.
54# # The stop reason of the thread should be breakpoint and at a_function.
55# self.ci.HandleCommand("thread list", res)
56# output = res.GetOutput()
57# self.assertTrue(res.Succeeded())
58# self.assertTrue(output.find('state is Stopped') > 0 and
59# output.find('a_function') > 0 and
60# output.find('a.c:14') > 0 and
61# output.find('stop reason = breakpoint') > 0)
62
63# # The breakpoint should have a hit count of 2.
64# self.ci.HandleCommand("breakpoint list", res)
65# self.assertTrue(res.Succeeded())
66# self.assertTrue(res.GetOutput().find(' resolved, hit count = 2') > 0)
67
68# self.ci.HandleCommand("continue", res)
69# self.assertTrue(res.Succeeded())
70
71
72if __name__ == '__main__':
Johnny Chen88f83042010-08-05 21:23:45 +000073 import atexit
Johnny Chen843f6892010-07-07 21:10:55 +000074 lldb.SBDebugger.Initialize()
Johnny Chen88f83042010-08-05 21:23:45 +000075 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen75e28f92010-08-05 23:42:46 +000076 unittest2.main()