[Lldb-commits] [lldb] r136983 - in /lldb/trunk: scripts/Python/interface/SBType.i test/python_api/type/TestTypeList.py
Johnny Chen
johnny.chen at apple.com
Fri Aug 5 14:35:43 PDT 2011
Author: johnny
Date: Fri Aug 5 16:35:43 2011
New Revision: 136983
URL: http://llvm.org/viewvc/llvm-project?rev=136983&view=rev
Log:
Add SBType.GetBasicType() to the test scenario.
Add docstring for SBType, too.
Modified:
lldb/trunk/scripts/Python/interface/SBType.i
lldb/trunk/test/python_api/type/TestTypeList.py
Modified: lldb/trunk/scripts/Python/interface/SBType.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBType.i?rev=136983&r1=136982&r2=136983&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBType.i (original)
+++ lldb/trunk/scripts/Python/interface/SBType.i Fri Aug 5 16:35:43 2011
@@ -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:
Modified: lldb/trunk/test/python_api/type/TestTypeList.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/type/TestTypeList.py?rev=136983&r1=136982&r2=136983&view=diff
==============================================================================
--- lldb/trunk/test/python_api/type/TestTypeList.py (original)
+++ lldb/trunk/test/python_api/type/TestTypeList.py Fri Aug 5 16:35:43 2011
@@ -100,6 +100,15 @@
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
More information about the lldb-commits
mailing list