brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.5 KiB · 5fa939f Raw
101 lines · plain
1STRING_EXTENSION_OUTSIDE(SBProcess)2%extend lldb::SBProcess {3#ifdef SWIGPYTHON4    %pythoncode %{5        def WriteMemoryAsCString(self, addr, str, error):6            '''7              WriteMemoryAsCString(self, addr, str, error):8                This functions the same as `WriteMemory` except a null-terminator is appended9                to the end of the buffer if it is not there already.10            '''11            if not str or len(str) == 0:12                return 013            if not str[-1] == '\0':14                str += '\0'15            return self.WriteMemory(addr, str, error)16 17        def __get_is_alive__(self):18            '''Returns "True" if the process is currently alive, "False" otherwise'''19            s = self.GetState()20            if (s == eStateAttaching or21                s == eStateLaunching or22                s == eStateStopped or23                s == eStateRunning or24                s == eStateStepping or25                s == eStateCrashed or26                s == eStateSuspended):27                return True28            return False29 30        def __get_is_running__(self):31            '''Returns "True" if the process is currently running, "False" otherwise'''32            state = self.GetState()33            if state == eStateRunning or state == eStateStepping:34                return True35            return False36 37        def __get_is_stopped__(self):38            '''Returns "True" if the process is currently stopped, "False" otherwise'''39            state = self.GetState()40            if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:41                return True42            return False43 44        class threads_access(object):45            '''A helper object that will lazily hand out thread for a process when supplied an index.'''46            def __init__(self, sbprocess):47                self.sbprocess = sbprocess48 49            def __len__(self):50                if self.sbprocess:51                    return int(self.sbprocess.GetNumThreads())52                return 053 54            def __getitem__(self, key):55                if isinstance(key, int):56                    count = len(self)57                    if -count <= key < count:58                        key %= count59                        return self.sbprocess.GetThreadAtIndex(key)60                return None61 62        def get_threads_access_object(self):63            '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''64            return self.threads_access (self)65 66        def get_process_thread_list(self):67            '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''68            threads = []69            accessor = self.get_threads_access_object()70            for idx in range(len(accessor)):71                threads.append(accessor[idx])72            return threads73 74        def __iter__(self):75            '''Iterate over all threads in a lldb.SBProcess object.'''76            return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex')77 78        def __len__(self):79            '''Return the number of threads in a lldb.SBProcess object.'''80            return self.GetNumThreads()81 82        def __int__(self):83            return self.GetProcessID()84 85        threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''')86        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]).''')87        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.''')88        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.''')89        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.''')90        id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''')91        target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''')92        num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''')93        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.''')94        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.).''')95        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.''')96        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.''')97        broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''')98    %}99#endif100}101