Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / bindings / interface / SBProcessExtensions.i
blob5fa939f6aacfc10f2a7258f13f8ff93811e97b2a
1 STRING_EXTENSION_OUTSIDE(SBProcess)
2 %extend lldb::SBProcess {
3 #ifdef SWIGPYTHON
4 %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 appended
9 to the end of the buffer if it is not there already.
10 '''
11 if not str or len(str) == 0:
12 return 0
13 if not str[-1] == '\0':
14 str += '\0'
15 return self.WriteMemory(addr, str, error)
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 or
21 s == eStateLaunching or
22 s == eStateStopped or
23 s == eStateRunning or
24 s == eStateStepping or
25 s == eStateCrashed or
26 s == eStateSuspended):
27 return True
28 return False
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 True
35 return False
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 True
42 return False
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 = sbprocess
49 def __len__(self):
50 if self.sbprocess:
51 return int(self.sbprocess.GetNumThreads())
52 return 0
54 def __getitem__(self, key):
55 if isinstance(key, int):
56 count = len(self)
57 if -count <= key < count:
58 key %= count
59 return self.sbprocess.GetThreadAtIndex(key)
60 return None
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)
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 threads
74 def __iter__(self):
75 '''Iterate over all threads in a lldb.SBProcess object.'''
76 return lldb_iter(self, 'GetNumThreads', 'GetThreadAtIndex')
78 def __len__(self):
79 '''Return the number of threads in a lldb.SBProcess object.'''
80 return self.GetNumThreads()
82 def __int__(self):
83 return self.GetProcessID()
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.''')
99 #endif