[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / bindings / interface / SBThreadExtensions.i
blobbfcc4d17e8f829e3e4a35f18f6a9d4c031fdd9cd
1 STRING_EXTENSION_OUTSIDE(SBThread)
3 %extend lldb::SBThread {
4 #ifdef SWIGPYTHON
5 %pythoncode %{
6 # operator== is a free function, which swig does not handle, so we inject
7 # our own equality operator here
8 def __eq__(self, other):
9 return not self.__ne__(other)
11 def __iter__(self):
12 '''Iterate over all frames in a lldb.SBThread object.'''
13 return lldb_iter(self, 'GetNumFrames', 'GetFrameAtIndex')
15 def __len__(self):
16 '''Return the number of frames in a lldb.SBThread object.'''
17 return self.GetNumFrames()
19 class frames_access(object):
20 '''A helper object that will lazily hand out frames for a thread when supplied an index.'''
21 def __init__(self, sbthread):
22 self.sbthread = sbthread
24 def __len__(self):
25 if self.sbthread:
26 return int(self.sbthread.GetNumFrames())
27 return 0
29 def __getitem__(self, key):
30 if isinstance(key, int):
31 count = len(self)
32 if -count <= key < count:
33 key %= count
34 return self.sbthread.GetFrameAtIndex(key)
35 return None
37 def get_frames_access_object(self):
38 '''An accessor function that returns a frames_access() object which allows lazy frame access from a lldb.SBThread object.'''
39 return self.frames_access (self)
41 def get_thread_frames(self):
42 '''An accessor function that returns a list() that contains all frames in a lldb.SBThread object.'''
43 frames = []
44 for frame in self:
45 frames.append(frame)
46 return frames
48 id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')
49 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.''')
50 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.''')
51 process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''')
52 num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''')
53 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.''')
54 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]").''')
55 name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')
56 queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')
57 queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')
58 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.''')
59 is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')
60 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.''')
62 #endif