Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e7addb3b93b1b370a371dd1e1eece7bed2b78520 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# *******************************************************************************
# * Copyright (c) 2011 Wind River Systems, Inc. and others.
# * All rights reserved. This program and the accompanying materials
# * are made available under the terms of the Eclipse Public License v1.0
# * which accompanies this distribution, and is available at
# * http://www.eclipse.org/legal/epl-v10.html
# *
# * Contributors:
# *     Wind River Systems - initial API and implementation
# *******************************************************************************

"""
IProcesses service provides access to the target OS's process
information, allows to start and terminate a process, and allows
to attach and detach a process for debugging. Debug services,
like IMemory and IRunControl, require a process to be attached
before they can access it.

If a process is started by this service, its standard input/output streams are
available for client to read/write using Streams service. Stream type of such
streams is set to "Processes".
"""

from tcf import services

NAME = "Processes"

# Context property names.

# The TCF context ID
PROP_ID = "ID"

# The TCF parent context ID
PROP_PARENT_ID = "ParentID"

# Is the context attached
PROP_ATTACHED = "Attached"

# Can terminate the context
PROP_CAN_TERMINATE = "CanTerminate"

# Process name. Client UI can show this name to a user
PROP_NAME = "Name"

# Process standard input stream ID
PROP_STDIN_ID = "StdInID"

# Process standard output stream ID
PROP_STDOUT_ID = "StdOutID"

# Process standard error stream ID
PROP_STDERR_ID = "StdErrID"


# Signal property names used by "getSignalList" command.

# Number, bit position in the signal mask
SIG_INDEX = "Index"

#String, signal name, for example "SIGHUP"
SIG_NAME = "Name"

# Number, signal code, as defined by OS
SIG_CODE = "Code"

# String, human readable description of the signal
SIG_DESCRIPTION = "Description"


class ProcessesService(services.Service):
    def getName(self):
        return NAME

    def getContext(self, id, done):
        """
        Retrieve context info for given context ID.
        A context corresponds to an execution thread, process, address space, etc.
        Context IDs are valid across TCF services, so it is allowed to issue
        'IProcesses.getContext' command with a context that was obtained,
        for example, from Memory service.
        However, 'Processes.getContext' is supposed to return only process specific data,
        If the ID is not a process ID, 'IProcesses.getContext' may not return any
        useful information

        @param id - context ID.
        @param done - call back interface called when operation is completed.
        """
        raise NotImplementedError("Abstract method")

    def getChildren(self, parent_context_id, attached_only, done):
        """
        Retrieve children of given context.

        @param parent_context_id - parent context ID. Can be None -
        to retrieve top level of the hierarchy, or one of context IDs retrieved
        by previous getContext or getChildren commands.
        @param attached_only - if True return only attached process IDs.
        @param done - call back interface called when operation is completed.
        """
        raise NotImplementedError("Abstract method")

    def getSignalList(self, context_id, done):
        """
        Get list of signals that can be send to the process.
        @param context_id - process context ID or None.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def getSignalMask(self, context_id, done):
        """
        Get process or thread signal mask.
        Bits in the mask control how signals should be handled by debug agent.
        When new context is created it inherits the mask from its parent.
        If context is not attached the command will return an error.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def setSignalMask(self, context_id, dont_stop, dont_pass, done):
        """
        Set process or thread signal mask.
        Bits in the mask control how signals should be handled by debug agent.
        If context is not attached the command will return an error.
        @param dont_stop - bit-set of signals that should not suspend execution of the context.
        By default, debugger suspends a context before it receives a signal.
        @param dont_pass - bit-set of signals that should not be delivered to the context.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def signal(self, context_id, signal, done):
        """
        Send a signal to a process or thread.
        @param context_id - context ID.
        @param signal - signal code.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def getEnvironment(self, done):
        """
        Get default set of environment variables used to start a new process.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def start(self, directory, file, command_line, environment, attach, done):
        """
        Start a new process on remote machine.
        @param directory - initial value of working directory for the process.
        @param file - process image file.
        @param command_line - command line arguments for the process.
        Note: the service does NOT add image file name as first argument for the process.
        If a client wants first parameter to be the file name, it should add it itself.
        @param environment - map of environment variables for the process,
        if None then default set of environment variables will be used.
        @param attach - if True debugger should be attached to the process.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def addListener(self, listener):
        """
        Add processes service event listener.
        @param listener - event listener implementation.
        """
        raise NotImplementedError("Abstract method")

    def removeListener(self, listener):
        """
        Remove processes service event listener.
        @param listener - event listener implementation.
        """
        raise NotImplementedError("Abstract method")


class ProcessContext(object):
    def __init__(self, props):
        self._props = props or {}

    def __str__(self):
        return "[Processes Context %s]" % self._props

    def getProperties(self):
        """
        Get context properties. See PROP_* definitions for property names.
        Context properties are read only, clients should not try to modify them.
        @return Map of context properties.
        """
        return self._props

    def getID(self):
        """
        Retrieve context ID.
        Same as getProperties().get('ID')
        """
        return self._props.get(PROP_ID)

    def getParentID(self):
        """
        Retrieve parent context ID.
        Same as getProperties().get('ParentID')
        """
        return self._props.get(PROP_PARENT_ID)

    def getName(self):
        """
        Retrieve human readable context name.
        Same as getProperties().get('Name')
        """
        return self._props.get(PROP_NAME)

    def isAttached(self):
        """
        Utility method to read context property PROP_ATTACHED.
        Services like IRunControl, IMemory, IBreakpoints work only with attached processes.
        @return value of PROP_ATTACHED.
        """
        return self._props.get(PROP_ATTACHED)

    def canTerminate(self):
        """
        Utility method to read context property PROP_CAN_TERMINATE.
        @return value of PROP_CAN_TERMINATE.
        """
        return self._props.get(PROP_CAN_TERMINATE)

    def attach(self, done):
        """
        Attach debugger to a process.
        Services like IRunControl, IMemory, IBreakpoints work only with attached processes.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def detach(self, done):
        """
        Detach debugger from a process.
        Process execution will continue without debugger supervision.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def terminate(self, done):
        """
        Terminate a process.
        @param done - call back interface called when operation is completed.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

class DoneCommand(object):
    """
    Call-back interface to be called when command is complete.
    """
    def doneCommand(self, token, error):
        pass

class DoneGetContext(object):
    """
    Client call back interface for getContext().
    """
    def doneGetContext(self, token, error, context):
        """
        Called when context data retrieval is done.
        @param error - error description if operation failed, None if succeeded.
        @param context - context data.
        """
        pass

class DoneGetChildren(object):
    """
    Client call back interface for getChildren().
    """
    def doneGetChildren(self, token, error, context_ids):
        """
        Called when context list retrieval is done.
        @param error - error description if operation failed, None if succeeded.
        @param context_ids - array of available context IDs.
        """
        pass

class DoneGetSignalList(object):
    """
    Call-back interface to be called when "getSignalList" command is complete.
    """
    def doneGetSignalList(self, token, error, list):
        pass

class DoneGetSignalMask(object):
    """
    Call-back interface to be called when "getSignalMask" command is complete.
    """
    def doneGetSignalMask(self, token, error, dont_stop, dont_pass, pending):
        """
        @param token - command handle.
        @param dont_stop - bit-set of signals that should suspend execution of the context.
        @param dont_pass - bit-set of signals that should not be delivered to the context.
        @param pending - bit-set of signals that are generated but not delivered yet.
        Note: "pending" is meaningful only if the context is suspended.
        """
        pass

class DoneGetEnvironment(object):
    """
    Call-back interface to be called when "getEnvironment" command is complete.
    """
    def doneGetEnvironment(self, token, error, environment):
        pass

class DoneStart(object):
    """
    Call-back interface to be called when "start" command is complete.
    """
    def doneStart(self, token, error, process):
        pass

class ProcessesListener(object):
    """
    Process event listener is notified when a process exits.
    Event are reported only for processes that were started by 'start' command.
    """

    def exited(self, process_id, exit_code):
        """
        Called when a process exits.
        @param process_id - process context ID
        @param exit_code - if >= 0 - the process exit code,
        if < 0 - process was terminated by a signal, the signal code = -exit_code.
        """
        pass

Back to the top