106c3fb27SDimitry Andric STRING_EXTENSION_OUTSIDE(SBProcess) 206c3fb27SDimitry Andric %extend lldb::SBProcess { 306c3fb27SDimitry Andric #ifdef SWIGPYTHON 406c3fb27SDimitry Andric %pythoncode %{ 506c3fb27SDimitry Andric def WriteMemoryAsCString(self, addr, str, error): 606c3fb27SDimitry Andric ''' 706c3fb27SDimitry Andric WriteMemoryAsCString(self, addr, str, error): 806c3fb27SDimitry Andric This functions the same as `WriteMemory` except a null-terminator is appended 906c3fb27SDimitry Andric to the end of the buffer if it is not there already. 1006c3fb27SDimitry Andric ''' 1106c3fb27SDimitry Andric if not str or len(str) == 0: 1206c3fb27SDimitry Andric return 0 1306c3fb27SDimitry Andric if not str[-1] == '\0': 1406c3fb27SDimitry Andric str += '\0' 1506c3fb27SDimitry Andric return self.WriteMemory(addr, str, error) 1606c3fb27SDimitry Andric 1706c3fb27SDimitry Andric def __get_is_alive__(self): 1806c3fb27SDimitry Andric '''Returns "True" if the process is currently alive, "False" otherwise''' 1906c3fb27SDimitry Andric s = self.GetState() 2006c3fb27SDimitry Andric if (s == eStateAttaching or 2106c3fb27SDimitry Andric s == eStateLaunching or 2206c3fb27SDimitry Andric s == eStateStopped or 2306c3fb27SDimitry Andric s == eStateRunning or 2406c3fb27SDimitry Andric s == eStateStepping or 2506c3fb27SDimitry Andric s == eStateCrashed or 2606c3fb27SDimitry Andric s == eStateSuspended): 2706c3fb27SDimitry Andric return True 2806c3fb27SDimitry Andric return False 2906c3fb27SDimitry Andric 3006c3fb27SDimitry Andric def __get_is_running__(self): 3106c3fb27SDimitry Andric '''Returns "True" if the process is currently running, "False" otherwise''' 3206c3fb27SDimitry Andric state = self.GetState() 3306c3fb27SDimitry Andric if state == eStateRunning or state == eStateStepping: 3406c3fb27SDimitry Andric return True 3506c3fb27SDimitry Andric return False 3606c3fb27SDimitry Andric 3706c3fb27SDimitry Andric def __get_is_stopped__(self): 3806c3fb27SDimitry Andric '''Returns "True" if the process is currently stopped, "False" otherwise''' 3906c3fb27SDimitry Andric state = self.GetState() 4006c3fb27SDimitry Andric if state == eStateStopped or state == eStateCrashed or state == eStateSuspended: 4106c3fb27SDimitry Andric return True 4206c3fb27SDimitry Andric return False 4306c3fb27SDimitry Andric 4406c3fb27SDimitry Andric class threads_access(object): 4506c3fb27SDimitry Andric '''A helper object that will lazily hand out thread for a process when supplied an index.''' 4606c3fb27SDimitry Andric def __init__(self, sbprocess): 4706c3fb27SDimitry Andric self.sbprocess = sbprocess 4806c3fb27SDimitry Andric 4906c3fb27SDimitry Andric def __len__(self): 5006c3fb27SDimitry Andric if self.sbprocess: 5106c3fb27SDimitry Andric return int(self.sbprocess.GetNumThreads()) 5206c3fb27SDimitry Andric return 0 5306c3fb27SDimitry Andric 5406c3fb27SDimitry Andric def __getitem__(self, key): 5506c3fb27SDimitry Andric if isinstance(key, int): 5606c3fb27SDimitry Andric count = len(self) 5706c3fb27SDimitry Andric if -count <= key < count: 5806c3fb27SDimitry Andric key %= count 5906c3fb27SDimitry Andric return self.sbprocess.GetThreadAtIndex(key) 6006c3fb27SDimitry Andric return None 6106c3fb27SDimitry Andric 6206c3fb27SDimitry Andric def get_threads_access_object(self): 6306c3fb27SDimitry Andric '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.''' 6406c3fb27SDimitry Andric return self.threads_access (self) 6506c3fb27SDimitry Andric 6606c3fb27SDimitry Andric def get_process_thread_list(self): 6706c3fb27SDimitry Andric '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.''' 6806c3fb27SDimitry Andric threads = [] 6906c3fb27SDimitry Andric accessor = self.get_threads_access_object() 7006c3fb27SDimitry Andric for idx in range(len(accessor)): 7106c3fb27SDimitry Andric threads.append(accessor[idx]) 7206c3fb27SDimitry Andric return threads 7306c3fb27SDimitry Andric 7406c3fb27SDimitry Andric def __iter__(self): 7506c3fb27SDimitry Andric '''Iterate over all threads in a lldb.SBProcess object.''' 7606c3fb27SDimitry Andric return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex') 7706c3fb27SDimitry Andric 7806c3fb27SDimitry Andric def __len__(self): 7906c3fb27SDimitry Andric '''Return the number of threads in a lldb.SBProcess object.''' 8006c3fb27SDimitry Andric return self.GetNumThreads() 8106c3fb27SDimitry Andric 82*5f757f3fSDimitry Andric def __int__(self): 83*5f757f3fSDimitry Andric return self.GetProcessID() 8406c3fb27SDimitry Andric 8506c3fb27SDimitry Andric threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''') 8606c3fb27SDimitry Andric 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]).''') 8706c3fb27SDimitry Andric 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.''') 8806c3fb27SDimitry Andric 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.''') 8906c3fb27SDimitry Andric 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.''') 9006c3fb27SDimitry Andric id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''') 9106c3fb27SDimitry Andric target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''') 9206c3fb27SDimitry Andric num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''') 9306c3fb27SDimitry Andric 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.''') 9406c3fb27SDimitry Andric 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.).''') 9506c3fb27SDimitry Andric 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.''') 9606c3fb27SDimitry Andric 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.''') 9706c3fb27SDimitry Andric broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''') 9806c3fb27SDimitry Andric %} 9906c3fb27SDimitry Andric #endif 10006c3fb27SDimitry Andric } 101