summaryrefslogtreecommitdiffstats
path: root/lldb/test/python_api
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-08-05 20:17:27 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-08-05 20:17:27 +0000
commit36c5eb132761de243825daac55192cabcc2c3a7e (patch)
tree46405cdcc18699cf2333a00562ed41feafa20bae /lldb/test/python_api
parentd633abebf687bdde36986213bd04c813e7d676f0 (diff)
downloadbcm5719-llvm-36c5eb132761de243825daac55192cabcc2c3a7e.tar.gz
bcm5719-llvm-36c5eb132761de243825daac55192cabcc2c3a7e.zip
o modify-python-lldb.py:
Add the rich comparison methods (__eq__, __ne__) to SBType, too. o lldbtest.py: Add debug utility method TestBase.DebugSBType(). o test/python_api/type: Add tests for exercising SBType/SBTypeList API, including the SBTarget.FindTypes(type_name) API which returns a SBTypeList matching the type_name. llvm-svn: 136975
Diffstat (limited to 'lldb/test/python_api')
-rw-r--r--lldb/test/python_api/type/Makefile5
-rw-r--r--lldb/test/python_api/type/TestTypeList.py108
-rw-r--r--lldb/test/python_api/type/main.cpp49
3 files changed, 162 insertions, 0 deletions
diff --git a/lldb/test/python_api/type/Makefile b/lldb/test/python_api/type/Makefile
new file mode 100644
index 00000000000..8a7102e347a
--- /dev/null
+++ b/lldb/test/python_api/type/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/python_api/type/TestTypeList.py b/lldb/test/python_api/type/TestTypeList.py
new file mode 100644
index 00000000000..842d401d667
--- /dev/null
+++ b/lldb/test/python_api/type/TestTypeList.py
@@ -0,0 +1,108 @@
+"""
+Test SBType and SBTypeList API.
+"""
+
+import os, time
+import re
+import unittest2
+import lldb, lldbutil
+from lldbtest import *
+
+class TypeAndTypeListTestCase(TestBase):
+
+ mydir = os.path.join("python_api", "type")
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @python_api_test
+ def test_with_dsym(self):
+ """Exercise SBType and SBTypeList API."""
+ d = {'EXE': self.exe_name}
+ self.buildDsym(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.type_and_typelist_api(self.exe_name)
+
+ @python_api_test
+ def test_with_dwarf(self):
+ """Exercise SBType and SBTypeList API."""
+ d = {'EXE': self.exe_name}
+ self.buildDwarf(dictionary=d)
+ self.setTearDownCleanup(dictionary=d)
+ self.type_and_typelist_api(self.exe_name)
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # We'll use the test method name as the exe_name.
+ self.exe_name = self.testMethodName
+ # Find the line number to break at.
+ self.source = 'main.cpp'
+ self.line = line_number(self.source, '// Break at this line')
+
+ def type_and_typelist_api(self, exe_name):
+ """Exercise SBType and SBTypeList API."""
+ exe = os.path.join(os.getcwd(), exe_name)
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create the breakpoint inside function 'main'.
+ breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
+ self.assertTrue(breakpoint, VALID_BREAKPOINT)
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(None, None, os.getcwd())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Get Frame #0.
+ self.assertTrue(process.GetState() == lldb.eStateStopped)
+ thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
+ frame0 = thread.GetFrameAtIndex(0)
+
+ # Get the type 'Task'.
+ type_list = target.FindTypes('Task')
+ if self.TraceOn():
+ print "Size of type_list from target.FindTypes('Task') query: %d" % type_list.GetSize()
+ self.assertTrue(len(type_list) == 1)
+ for type in type_list:
+ self.assertTrue(type)
+ self.DebugSBType(type)
+
+ # Now use the SBTarget.FindFirstType() API to find 'Task'.
+ task_type = target.FindFirstType('Task')
+ self.assertTrue(task_type)
+ self.DebugSBType(task_type)
+
+ # Get the reference type of 'Task', just for fun.
+ task_ref_type = task_type.GetReferenceType()
+ self.assertTrue(task_ref_type)
+ self.DebugSBType(task_ref_type)
+
+ # Get the pointer type of 'Task', which is the same as task_head's type.
+ task_pointer_type = task_type.GetPointerType()
+ self.assertTrue(task_pointer_type)
+ self.DebugSBType(task_pointer_type)
+
+ # Get variable 'task_head'.
+ task_head = frame0.FindVariable('task_head')
+ self.assertTrue(task_head, VALID_VARIABLE)
+ self.DebugSBValue(task_head)
+ task_head_type = task_head.GetType()
+ self.DebugSBType(task_head_type)
+ self.assertTrue(task_head_type.IsPointerType())
+
+ self.assertTrue(task_head_type == task_pointer_type)
+
+ # Get the pointee type of 'task_head'.
+ task_head_pointee_type = task_head_type.GetPointeeType()
+ self.DebugSBType(task_head_pointee_type)
+
+ self.assertTrue(task_type == task_head_pointee_type)
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/python_api/type/main.cpp b/lldb/test/python_api/type/main.cpp
new file mode 100644
index 00000000000..db0e249cc91
--- /dev/null
+++ b/lldb/test/python_api/type/main.cpp
@@ -0,0 +1,49 @@
+//===-- 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>
+
+class Task {
+public:
+ int id;
+ Task *next;
+ Task(int i, Task *n):
+ id(i),
+ next(n)
+ {}
+};
+
+
+int main (int argc, char const *argv[])
+{
+ Task *task_head = new Task(-1, NULL);
+ Task *task1 = new Task(1, NULL);
+ Task *task2 = new Task(2, NULL);
+ Task *task3 = new Task(3, NULL); // Orphaned.
+ Task *task4 = new Task(4, NULL);
+ Task *task5 = new Task(5, NULL);
+
+ task_head->next = task1;
+ task1->next = task2;
+ task2->next = task4;
+ task4->next = task5;
+
+ int total = 0;
+ Task *t = task_head;
+ while (t != NULL) {
+ if (t->id >= 0)
+ ++total;
+ t = t->next;
+ }
+ printf("We have a total number of %d tasks\n", total);
+
+ // This corresponds to an empty task list.
+ Task *empty_task_head = new Task(-1, NULL);
+
+ return 0; // Break at this line
+}
OpenPOWER on IntegriCloud