85 lines · plain
1STRING_EXTENSION_OUTSIDE(SBThread)2 3%extend lldb::SBThread {4#ifdef SWIGPYTHON5 %pythoncode %{6 # operator== is a free function, which swig does not handle, so we inject7 # our own equality operator here8 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 = sbthread23 24 def __len__(self):25 if self.sbthread:26 return int(self.sbthread.GetNumFrames())27 return 028 29 def __getitem__(self, key):30 if isinstance(key, int):31 count = len(self)32 if -count <= key < count:33 key %= count34 return self.sbthread.GetFrameAtIndex(key)35 return None36 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 frame_list = self.GetFrames()45 for frame in frame_list:46 frames.append(frame)47 return frames48 49 def get_stop_description(self):50 return self.GetStopDescription(1024)51 52 def get_stop_reason_data(self):53 return [54 self.GetStopReasonDataAtIndex(idx)55 for idx in range(self.GetStopReasonDataCount())56 ]57 58 def set_selected_frame(self, frame):59 if isinstance(frame, SBFrame):60 if frame.thread != self:61 raise ValueError("cannot select frame from different thread")62 self.SetSelectedFrame(frame.idx)63 else:64 self.SetSelectedFrame(frame)65 66 id = property(GetThreadID, None, doc='''A read only property that returns the thread ID as an integer.''')67 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.''')68 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.''')69 process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that owns this thread.''')70 num_frames = property(GetNumFrames, None, doc='''A read only property that returns the number of stack frames in this thread as an integer.''')71 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.''')72 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]").''')73 name = property(GetName, None, doc='''A read only property that returns the name of this thread as a string.''')74 queue = property(GetQueueName, None, doc='''A read only property that returns the dispatch queue name of this thread as a string.''')75 queue_id = property(GetQueueID, None, doc='''A read only property that returns the dispatch queue id of this thread as an integer.''')76 stop_description = property(get_stop_description, None, doc='''A read only property that returns a string describing the reason this thread stopped.''')77 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.''')78 stop_reason_data = property(get_stop_reason_data, None, doc='''A read only property that returns the stop reason data as a list.''')79 is_suspended = property(IsSuspended, None, doc='''A read only property that returns a boolean value that indicates if this thread is suspended.''')80 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.''')81 selected_frame = property(GetSelectedFrame, set_selected_frame, doc='''A read/write property that gets and sets the selected frame of this SBThread.''')82 %}83#endif84}85