xref: /freebsd/contrib/llvm-project/lldb/bindings/interface/SBThreadExtensions.i (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
106c3fb27SDimitry Andric STRING_EXTENSION_OUTSIDE(SBThread)
206c3fb27SDimitry Andric 
306c3fb27SDimitry Andric %extend lldb::SBThread {
406c3fb27SDimitry Andric #ifdef SWIGPYTHON
506c3fb27SDimitry Andric     %pythoncode %{
6*5f757f3fSDimitry Andric         # operator== is a free function, which swig does not handle, so we inject
7*5f757f3fSDimitry Andric         # our own equality operator here
8*5f757f3fSDimitry Andric         def __eq__(self, other):
9*5f757f3fSDimitry Andric             return not self.__ne__(other)
10*5f757f3fSDimitry Andric 
1106c3fb27SDimitry Andric         def __iter__(self):
1206c3fb27SDimitry Andric             '''Iterate over all frames in a lldb.SBThread object.'''
1306c3fb27SDimitry Andric             return lldb_iter(self, 'GetNumFrames', 'GetFrameAtIndex')
1406c3fb27SDimitry Andric 
1506c3fb27SDimitry Andric         def __len__(self):
1606c3fb27SDimitry Andric             '''Return the number of frames in a lldb.SBThread object.'''
1706c3fb27SDimitry Andric             return self.GetNumFrames()
1806c3fb27SDimitry Andric 
1906c3fb27SDimitry Andric         class frames_access(object):
2006c3fb27SDimitry Andric             '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
2106c3fb27SDimitry Andric             def __init__(self, sbthread):
2206c3fb27SDimitry Andric                 self.sbthread = sbthread
2306c3fb27SDimitry Andric 
2406c3fb27SDimitry Andric             def __len__(self):
2506c3fb27SDimitry Andric                 if self.sbthread:
2606c3fb27SDimitry Andric                     return int(self.sbthread.GetNumFrames())
2706c3fb27SDimitry Andric                 return 0
2806c3fb27SDimitry Andric 
2906c3fb27SDimitry Andric             def __getitem__(self, key):
3006c3fb27SDimitry Andric                 if isinstance(key, int):
3106c3fb27SDimitry Andric                     count = len(self)
3206c3fb27SDimitry Andric                     if -count <= key < count:
3306c3fb27SDimitry Andric                         key %= count
3406c3fb27SDimitry Andric                         return self.sbthread.GetFrameAtIndex(key)
3506c3fb27SDimitry Andric                 return None
3606c3fb27SDimitry Andric 
3706c3fb27SDimitry Andric         def get_frames_access_object(self):
3806c3fb27SDimitry Andric             '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
3906c3fb27SDimitry Andric             return self.frames_access (self)
4006c3fb27SDimitry Andric 
4106c3fb27SDimitry Andric         def get_thread_frames(self):
4206c3fb27SDimitry Andric             '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
4306c3fb27SDimitry Andric             frames = []
4406c3fb27SDimitry Andric             for frame in self:
4506c3fb27SDimitry Andric                 frames.append(frame)
4606c3fb27SDimitry Andric             return frames
4706c3fb27SDimitry Andric 
4806c3fb27SDimitry Andric         id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
4906c3fb27SDimitry Andric         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.''')
5006c3fb27SDimitry Andric         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.''')
5106c3fb27SDimitry Andric         process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''')
5206c3fb27SDimitry Andric         num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''')
5306c3fb27SDimitry Andric         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.''')
5406c3fb27SDimitry Andric         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]").''')
5506c3fb27SDimitry Andric         name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')
5606c3fb27SDimitry Andric         queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
5706c3fb27SDimitry Andric         queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
5806c3fb27SDimitry Andric         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.''')
5906c3fb27SDimitry Andric         is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
6006c3fb27SDimitry Andric         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.''')
6106c3fb27SDimitry Andric     %}
6206c3fb27SDimitry Andric #endif
6306c3fb27SDimitry Andric }
64