summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/scripts/Python/interface/SBType.i73
-rw-r--r--lldb/test/python_api/type/TestTypeList.py9
2 files changed, 82 insertions, 0 deletions
diff --git a/lldb/scripts/Python/interface/SBType.i b/lldb/scripts/Python/interface/SBType.i
index 1936c04039f..48f20f1f2d6 100644
--- a/lldb/scripts/Python/interface/SBType.i
+++ b/lldb/scripts/Python/interface/SBType.i
@@ -9,6 +9,79 @@
namespace lldb {
+%feature("docstring",
+"Represents a data type in lldb. The FindFirstType() method of SBTarget/SBModule
+returns a SBType.
+
+SBType supports the eq/ne operator. For example,
+
+main.cpp:
+
+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
+}
+
+find_type.py:
+
+ # Get the type 'Task'.
+ task_type = target.FindFirstType('Task')
+ self.assertTrue(task_type)
+
+ # Get the variable 'task_head'.
+ frame0.FindVariable('task_head')
+ task_head_type = task_head.GetType()
+ self.assertTrue(task_head_type.IsPointerType())
+
+ # task_head_type is 'Task *'.
+ task_pointer_type = task_type.GetPointerType()
+ self.assertTrue(task_head_type == task_pointer_type)
+
+ # Get the child mmember 'id' from 'task_head'.
+ id = task_head.GetChildMemberWithName('id')
+ id_type = id.GetType()
+
+ # SBType.GetBasicType() takes an enum 'BasicType' (lldb-enumerations.h).
+ int_type = id_type.GetBasicType(lldb.eBasicTypeInt)
+ # id_type and int_type should be the same type!
+ self.assertTrue(id_type == int_type)
+
+...
+") SBType;
class SBType
{
public:
diff --git a/lldb/test/python_api/type/TestTypeList.py b/lldb/test/python_api/type/TestTypeList.py
index 842d401d667..c2dda911428 100644
--- a/lldb/test/python_api/type/TestTypeList.py
+++ b/lldb/test/python_api/type/TestTypeList.py
@@ -100,6 +100,15 @@ class TypeAndTypeListTestCase(TestBase):
self.assertTrue(task_type == task_head_pointee_type)
+ # We'll now get the child member 'id' from 'task_head'.
+ id = task_head.GetChildMemberWithName('id')
+ self.DebugSBValue(id)
+ id_type = id.GetType()
+ self.DebugSBType(id_type)
+
+ # SBType.GetBasicType() takes an enum 'BasicType' (lldb-enumerations.h).
+ int_type = id_type.GetBasicType(lldb.eBasicTypeInt)
+ self.assertTrue(id_type == int_type)
if __name__ == '__main__':
import atexit
OpenPOWER on IntegriCloud