[Lldb-commits] [lldb] r127173 - in /lldb/trunk: scripts/lldb.swig test/python_api/thread/ test/python_api/thread/Makefile test/python_api/thread/TestThreadAPI.py test/python_api/thread/main.cpp
Johnny Chen
johnny.chen at apple.com
Mon Mar 7 13:28:58 PST 2011
Author: johnny
Date: Mon Mar 7 15:28:57 2011
New Revision: 127173
URL: http://llvm.org/viewvc/llvm-project?rev=127173&view=rev
Log:
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)
Added:
lldb/trunk/test/python_api/thread/
lldb/trunk/test/python_api/thread/Makefile
lldb/trunk/test/python_api/thread/TestThreadAPI.py
lldb/trunk/test/python_api/thread/main.cpp
Modified:
lldb/trunk/scripts/lldb.swig
Modified: lldb/trunk/scripts/lldb.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/lldb.swig?rev=127173&r1=127172&r2=127173&view=diff
==============================================================================
--- lldb/trunk/scripts/lldb.swig (original)
+++ lldb/trunk/scripts/lldb.swig Mon Mar 7 15:28:57 2011
@@ -53,9 +53,34 @@
}
}
+/* Typemap definitions to allow SWIG to properly handle char buffer. */
+
+// typemap for a char buffer
+// See also SBThread::GetStopDescription.
+%typemap(in) (char *dst, size_t dst_len) {
+ if (!PyInt_Check($input)) {
+ PyErr_SetString(PyExc_ValueError, "Expecting an integer");
+ return NULL;
+ }
+ $2 = PyInt_AsLong($input);
+ if ($2 < 0) {
+ PyErr_SetString(PyExc_ValueError, "Positive integer expected");
+ return NULL;
+ }
+ $1 = (char *) malloc($2);
+}
+
+// Return the char buffer. Discarding any previous return result
+// See also SBThread::GetStopDescription.
+%typemap(argout) (char *dst, size_t dst_len) {
+ Py_XDECREF($result); /* Blow away any previous result */
+ $result = PyString_FromStringAndSize(($1),result);
+ free($1);
+}
// typemap for an outgoing buffer
+// See also SBProcess::WriteMemory.
%typemap(in) (const void *buf, size_t size) {
if (!PyString_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting a string");
@@ -66,6 +91,7 @@
}
// typemap for an incoming buffer
+// See also SBProcess::ReadMemory.
%typemap(in) (void *buf, size_t size) {
if (!PyInt_Check($input)) {
PyErr_SetString(PyExc_ValueError, "Expecting an integer");
@@ -80,6 +106,7 @@
}
// Return the buffer. Discarding any previous return result
+// See also SBProcess::ReadMemory.
%typemap(argout) (void *buf, size_t size) {
Py_XDECREF($result); /* Blow away any previous result */
if (result < 0) { /* Check for I/O error */
Added: lldb/trunk/test/python_api/thread/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/Makefile?rev=127173&view=auto
==============================================================================
--- lldb/trunk/test/python_api/thread/Makefile (added)
+++ lldb/trunk/test/python_api/thread/Makefile Mon Mar 7 15:28:57 2011
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/python_api/thread/TestThreadAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/TestThreadAPI.py?rev=127173&view=auto
==============================================================================
--- lldb/trunk/test/python_api/thread/TestThreadAPI.py (added)
+++ lldb/trunk/test/python_api/thread/TestThreadAPI.py Mon Mar 7 15:28:57 2011
@@ -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()
Added: lldb/trunk/test/python_api/thread/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/thread/main.cpp?rev=127173&view=auto
==============================================================================
--- lldb/trunk/test/python_api/thread/main.cpp (added)
+++ lldb/trunk/test/python_api/thread/main.cpp Mon Mar 7 15:28:57 2011
@@ -0,0 +1,26 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+
+// This simple program is to test the lldb Python API related to thread.
+
+char my_char = 'u';
+int my_int = 0;
+
+int main (int argc, char const *argv[])
+{
+ for (int i = 0; i < 3; ++i) {
+ printf("my_char='%c'\n", my_char);
+ ++my_char;
+ }
+
+ printf("after the loop: my_char='%c'\n", my_char); // 'my_char' should print out as 'x'.
+
+ return 0; // Set break point at this line and check variable 'my_char'.
+}
More information about the lldb-commits
mailing list