From 2f6f7ba87940f9aba90aa9bf356c363b2d8a98af Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Mon, 7 Mar 2011 21:28:57 +0000 Subject: Add TestThreadAPI.py file to house the Python SBThread API test cases. Currently it has only test cases for SBThread.GetStopDescription() API. Also modified lldb.swig to add typemap for (char *dst, size_t dst_len) which occurs for SBThread::GetStopDescription() C++ API. For Python scripting: # Due to the typemap magic (see lldb.swig), we pass in an (int)length to GetStopDescription # and expect to get a Python string as the result object! # The 100 is just an arbitrary number specifying the buffer size. stop_description = thread.GetStopDescription(100) llvm-svn: 127173 --- lldb/test/python_api/thread/TestThreadAPI.py | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lldb/test/python_api/thread/TestThreadAPI.py (limited to 'lldb/test/python_api/thread/TestThreadAPI.py') diff --git a/lldb/test/python_api/thread/TestThreadAPI.py b/lldb/test/python_api/thread/TestThreadAPI.py new file mode 100644 index 00000000000..fa1e8eab2af --- /dev/null +++ b/lldb/test/python_api/thread/TestThreadAPI.py @@ -0,0 +1,66 @@ +""" +Test SBThread APIs. +""" + +import os, time +import unittest2 +import lldb +from lldbutil import get_stopped_thread +from lldbtest import * + +class ThreadAPITestCase(TestBase): + + mydir = os.path.join("python_api", "thread") + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + def test_get_stop_description_with_dsym(self): + """Test Python SBThread.GetStopDescription() API.""" + self.buildDsym() + self.get_stop_description() + + @python_api_test + def test_get_stop_description_with_dwarf(self): + """Test Python SBThread.GetStopDescription() API.""" + self.buildDwarf() + self.get_stop_description() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number("main.cpp", "// Set break point at this line and check variable 'my_char'.") + + def get_stop_description(self): + """Test Python SBProcess.ReadMemory() API.""" + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target.IsValid(), VALID_TARGET) + + breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) + self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) + #self.runCmd("breakpoint list") + + # Launch the process, and do not stop at the entry point. + error = lldb.SBError() + self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) + + thread = get_stopped_thread(self.process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint") + #self.runCmd("process status") + + # Due to the typemap magic (see lldb.swig), we pass in an (int)length to GetStopDescription + # and expect to get a Python string as the result object! + # The 100 is just an arbitrary number specifying the buffer size. + stop_description = thread.GetStopDescription(100) + self.expect(stop_description, exe=False, + startstr = 'breakpoint') + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() -- cgit v1.2.3