1662548c8SAlex Langford STRING_EXTENSION_OUTSIDE(SBProcess) 2662548c8SAlex Langford %extend lldb::SBProcess { 3662548c8SAlex Langford #ifdef SWIGPYTHON 4662548c8SAlex Langford %pythoncode %{ 5e6cac17bSMed Ismail Bennani def WriteMemoryAsCString(self, addr, str, error): 6e6cac17bSMed Ismail Bennani ''' 7e6cac17bSMed Ismail Bennani WriteMemoryAsCString(self, addr, str, error): 8e6cac17bSMed Ismail Bennani This functions the same as `WriteMemory` except a null-terminator is appended 9e6cac17bSMed Ismail Bennani to the end of the buffer if it is not there already. 10e6cac17bSMed Ismail Bennani ''' 11e6cac17bSMed Ismail Bennani if not str or len(str) == 0: 12e6cac17bSMed Ismail Bennani return 0 13e6cac17bSMed Ismail Bennani if not str[-1] == '\0': 14e6cac17bSMed Ismail Bennani str += '\0' 15e6cac17bSMed Ismail Bennani return self.WriteMemory(addr, str, error) 16e6cac17bSMed Ismail Bennani 17662548c8SAlex Langford def __get_is_alive__(self): 18662548c8SAlex Langford '''Returns "True" if the process is currently alive, "False" otherwise''' 19662548c8SAlex Langford s = self.GetState() 20662548c8SAlex Langford if (s == eStateAttaching or 21662548c8SAlex Langford s == eStateLaunching or 22662548c8SAlex Langford s == eStateStopped or 23662548c8SAlex Langford s == eStateRunning or 24662548c8SAlex Langford s == eStateStepping or 25662548c8SAlex Langford s == eStateCrashed or 26662548c8SAlex Langford s == eStateSuspended): 27662548c8SAlex Langford return True 28662548c8SAlex Langford return False 29662548c8SAlex Langford 30662548c8SAlex Langford def __get_is_running__(self): 31662548c8SAlex Langford '''Returns "True" if the process is currently running, "False" otherwise''' 32662548c8SAlex Langford state = self.GetState() 33662548c8SAlex Langford if state == eStateRunning or state == eStateStepping: 34662548c8SAlex Langford return True 35662548c8SAlex Langford return False 36662548c8SAlex Langford 37662548c8SAlex Langford def __get_is_stopped__(self): 38662548c8SAlex Langford '''Returns "True" if the process is currently stopped, "False" otherwise''' 39662548c8SAlex Langford state = self.GetState() 40662548c8SAlex Langford if state == eStateStopped or state == eStateCrashed or state == eStateSuspended: 41662548c8SAlex Langford return True 42662548c8SAlex Langford return False 43662548c8SAlex Langford 44662548c8SAlex Langford class threads_access(object): 45662548c8SAlex Langford '''A helper object that will lazily hand out thread for a process when supplied an index.''' 46662548c8SAlex Langford def __init__(self, sbprocess): 47662548c8SAlex Langford self.sbprocess = sbprocess 48662548c8SAlex Langford 49662548c8SAlex Langford def __len__(self): 50662548c8SAlex Langford if self.sbprocess: 51662548c8SAlex Langford return int(self.sbprocess.GetNumThreads()) 52662548c8SAlex Langford return 0 53662548c8SAlex Langford 54662548c8SAlex Langford def __getitem__(self, key): 55662548c8SAlex Langford if isinstance(key, int): 56662548c8SAlex Langford count = len(self) 57662548c8SAlex Langford if -count <= key < count: 58662548c8SAlex Langford key %= count 59662548c8SAlex Langford return self.sbprocess.GetThreadAtIndex(key) 60662548c8SAlex Langford return None 61662548c8SAlex Langford 62662548c8SAlex Langford def get_threads_access_object(self): 63662548c8SAlex Langford '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.''' 64662548c8SAlex Langford return self.threads_access (self) 65662548c8SAlex Langford 66662548c8SAlex Langford def get_process_thread_list(self): 67662548c8SAlex Langford '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.''' 68662548c8SAlex Langford threads = [] 69662548c8SAlex Langford accessor = self.get_threads_access_object() 70662548c8SAlex Langford for idx in range(len(accessor)): 71662548c8SAlex Langford threads.append(accessor[idx]) 72662548c8SAlex Langford return threads 73662548c8SAlex Langford 74662548c8SAlex Langford def __iter__(self): 75662548c8SAlex Langford '''Iterate over all threads in a lldb.SBProcess object.''' 76662548c8SAlex Langford return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex') 77662548c8SAlex Langford 78662548c8SAlex Langford def __len__(self): 79662548c8SAlex Langford '''Return the number of threads in a lldb.SBProcess object.''' 80662548c8SAlex Langford return self.GetNumThreads() 81662548c8SAlex Langford 82*6813ef37SMed Ismail Bennani def __int__(self): 83*6813ef37SMed Ismail Bennani return self.GetProcessID() 84662548c8SAlex Langford 85662548c8SAlex Langford threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''') 86662548c8SAlex Langford thread = property(get_threads_access_object, None, doc='''A read only property that returns an object that can access threads by thread index (thread = lldb.process.thread[12]).''') 87662548c8SAlex Langford is_alive = property(__get_is_alive__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently alive.''') 88662548c8SAlex Langford is_running = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently running.''') 89662548c8SAlex Langford is_stopped = property(__get_is_stopped__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently stopped.''') 90662548c8SAlex Langford id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''') 91662548c8SAlex Langford target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''') 92662548c8SAlex Langford num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''') 93662548c8SAlex Langford selected_thread = property(GetSelectedThread, SetSelectedThread, doc='''A read/write property that gets/sets the currently selected thread in this process. The getter returns a lldb.SBThread object and the setter takes an lldb.SBThread object.''') 94662548c8SAlex Langford state = property(GetState, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eState") that represents the current state of this process (running, stopped, exited, etc.).''') 95662548c8SAlex Langford exit_state = property(GetExitStatus, None, doc='''A read only property that returns an exit status as an integer of this process when the process state is lldb.eStateExited.''') 96662548c8SAlex Langford exit_description = property(GetExitDescription, None, doc='''A read only property that returns an exit description as a string of this process when the process state is lldb.eStateExited.''') 97662548c8SAlex Langford broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''') 98662548c8SAlex Langford %} 99662548c8SAlex Langford #endif 100662548c8SAlex Langford } 101