xref: /freebsd/contrib/llvm-project/lldb/bindings/interface/SBThreadExtensions.i (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 STRING_EXTENSION_OUTSIDE(SBThread)
2 
3 %extend lldb::SBThread {
4 #ifdef SWIGPYTHON
5     %pythoncode %{
6         def __iter__(self):
7             '''Iterate over all frames in a lldb.SBThread object.'''
8             return lldb_iter(self, 'GetNumFrames', 'GetFrameAtIndex')
9 
10         def __len__(self):
11             '''Return the number of frames in a lldb.SBThread object.'''
12             return self.GetNumFrames()
13 
14         class frames_access(object):
15             '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
16             def __init__(self, sbthread):
17                 self.sbthread = sbthread
18 
19             def __len__(self):
20                 if self.sbthread:
21                     return int(self.sbthread.GetNumFrames())
22                 return 0
23 
24             def __getitem__(self, key):
25                 if isinstance(key, int):
26                     count = len(self)
27                     if -count <= key < count:
28                         key %= count
29                         return self.sbthread.GetFrameAtIndex(key)
30                 return None
31 
32         def get_frames_access_object(self):
33             '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
34             return self.frames_access (self)
35 
36         def get_thread_frames(self):
37             '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
38             frames = []
39             for frame in self:
40                 frames.append(frame)
41             return frames
42 
43         id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
44         idx = property(GetIndexID, None, doc='''A read only property that returns the thread index ID as an integer. Thread index ID values start at 1 and increment as threads come and go and can be used to uniquely identify threads.''')
45         return_value = property(GetStopReturnValue, None, doc='''A read only property that returns an lldb object that represents the return value from the last stop (lldb.SBValue) if we just stopped due to stepping out of a function.''')
46         process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''')
47         num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''')
48         frames = property(get_thread_frames, None, doc='''A read only property that returns a list() of lldb.SBFrame objects for all frames in this thread.''')
49         frame = property(get_frames_access_object, None, doc='''A read only property that returns an object that can be used to access frames as an array ("frame_12 = lldb.thread.frame[12]").''')
50         name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')
51         queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
52         queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
53         stop_reason = property(GetStopReason, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eStopReason") that represents the reason this thread stopped.''')
54         is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
55         is_stopped = property(IsStopped, None, doc='''A read only property that returns a boolean value that indicates if this thread is stopped but not exited.''')
56     %}
57 #endif
58 }
59