1 STRING_EXTENSION_OUTSIDE(SBThread) 2 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) 10 11 def __iter__(self): 12 '''Iterate over all frames in a lldb.SBThread object.''' 13 return lldb_iter(self, 'GetNumFrames', 'GetFrameAtIndex') 14 15 def __len__(self): 16 '''Return the number of frames in a lldb.SBThread object.''' 17 return self.GetNumFrames() 18 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 23 24 def __len__(self): 25 if self.sbthread: 26 return int(self.sbthread.GetNumFrames()) 27 return 0 28 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 36 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) 40 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 47 48 def get_stop_reason_data(self): 49 return [ 50 self.GetStopReasonDataAtIndex(idx) 51 for idx in range(self.GetStopReasonDataCount()) 52 ] 53 54 def set_selected_frame(self, frame): 55 if isinstance(frame, SBFrame): 56 if frame.thread != self: 57 raise ValueError("cannot select frame from different thread") 58 self.SetSelectedFrame(frame.idx) 59 else: 60 self.SetSelectedFrame(frame) 61 62 id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''') 63 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.''') 64 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.''') 65 process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''') 66 num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''') 67 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.''') 68 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]").''') 69 name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''') 70 queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''') 71 queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''') 72 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.''') 73 stop_reason_data = property(get_stop_reason_data, None, doc='''A read only property that returns the stop reason data as a list.''') 74 is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''') 75 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.''') 76 selected_frame = property(GetSelectedFrame, set_selected_frame, doc='''A read/write property that gets and sets the selected frame of this SBThread.''') 77 %} 78 #endif 79 } 80