Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e488715bbbaa5499dad92dbe5e6ccb533e824e17 (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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# *****************************************************************************
# * Copyright (c) 2011, 2013 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
# *****************************************************************************

from .. import services

NAME = "RunControl"

# Context property names.

# Run control context ID
PROP_ID = "ID"

# Context parent (owner) ID, for a thread it is same as process ID
PROP_PARENT_ID = "ParentID"

# Context process (memory space) ID
PROP_PROCESS_ID = "ProcessID"

# ID of a context that created this context
PROP_CREATOR_ID = "CreatorID"

# Human readable context name
PROP_NAME = "Name"

# true if the context is a container. Container can propagate run control
# commands to his children
PROP_IS_CONTAINER = "IsContainer"

# true if context has execution state - can be suspended/resumed
PROP_HAS_STATE = "HasState"

# Bit-set of RM_ values that are supported by the context
PROP_CAN_RESUME = "CanResume"

# Bit-set of RM_ values that can be used with count > 1
PROP_CAN_COUNT = "CanCount"

# true if suspend command is supported by the context
PROP_CAN_SUSPEND = "CanSuspend"

# true if terminate command is supported by the context
PROP_CAN_TERMINATE = "CanTerminate"

# Context ID of a run control group that contains the context.
# Members of same group are always suspended and resumed together:
# resuming/suspending a context resumes/suspends all members of the group
PROP_RC_GROUP = "RCGroup"

# Context ID of a breakpoints group that contains the context.
# Members of same group share same breakpoint instances:
# a breakpoint is planted once for the group, no need to plant
# the breakpoint for each member of the group
PROP_BP_GROUP = "BPGroup"

# true if detach command is supported by the context
PROP_CAN_DETACH = "CanDetach"

# Context ID of a symbols group that contains the context.
# Members of a symbols group share same symbol reader configuration settings,
# like user defined memory map entries and source lookup info
PROP_SYMBOLS_GROUP = "SymbolsGroup"


# Context resume modes.
RM_RESUME = 0

# Step over a single instruction.
# If the instruction is a function call then don't stop until the function
# returns.

RM_STEP_OVER = 1

# Step a single instruction.
# If the instruction is a function call then stop at first instruction of the
# function.
RM_STEP_INTO = 2

# Step over a single source code line.
# If the line contains a function call then don't stop until the function
# returns.
RM_STEP_OVER_LINE = 3

# Step a single source code line.
# If the line contains a function call then stop at first line of the function.
RM_STEP_INTO_LINE = 4

# Run until control returns from current function.
RM_STEP_OUT = 5

# Start running backwards.
# Execution will continue until suspended by command or breakpoint.
RM_REVERSE_RESUME = 6

# Reverse of RM_STEP_OVER - run backwards over a single instruction.
# If the instruction is a function call then don't stop until get out of the
# function.
RM_REVERSE_STEP_OVER = 7

# Reverse of RM_STEP_INTO.
# This effectively "un-executes" the previous instruction
RM_REVERSE_STEP_INTO = 8

# Reverse of RM_STEP_OVER_LINE.
# Resume backward execution of given context until control reaches an
# instruction that belongs to a different source line.
# If the line contains a function call then don't stop until get out of the
# function.
# Error is returned if line number information not available.
RM_REVERSE_STEP_OVER_LINE = 9

# Reverse of RM_STEP_INTO_LINE,
# Resume backward execution of given context until control reaches an
# instruction that belongs to a different line of source code.
# If a function is called, stop at the beginning of the last line of the
# function code.
# Error is returned if line number information not available.
RM_REVERSE_STEP_INTO_LINE = 10

# Reverse of RM_STEP_OUT.
# Resume backward execution of the given context until control reaches the
# point where the current function was called.
RM_REVERSE_STEP_OUT = 11

# Step over instructions until PC is outside the specified range.
# Any function call within the range is considered to be in range.
RM_STEP_OVER_RANGE = 12

# Step instruction until PC is outside the specified range for any reason.
RM_STEP_INTO_RANGE = 13

# Reverse of RM_STEP_OVER_RANGE
RM_REVERSE_STEP_OVER_RANGE = 14

# Reverse of RM_STEP_INTO_RANGE
RM_REVERSE_STEP_INTO_RANGE = 15

# Run until the context becomes active - scheduled to run on a target CPU
RM_UNTIL_ACTIVE = 16

# Run reverse until the context becomes active
RM_REVERSE_UNTIL_ACTIVE = 17

# State change reason of a context.
# Reason can be any text, but if it is one of predefined strings,
# a generic client might be able to handle it better.
REASON_USER_REQUEST = "Suspended"
REASON_STEP = "Step"
REASON_BREAKPOINT = "Breakpoint"
REASON_EXCEPTION = "Exception"
REASON_CONTAINER = "Container"
REASON_WATCHPOINT = "Watchpoint"
REASON_SIGNAL = "Signal"
REASON_SHAREDLIB = "Shared Library"
REASON_ERROR = "Error"

# Optional parameters of context state.
STATE_SIGNAL = "Signal"
STATE_SIGNAL_NAME = "SignalName"
STATE_SIGNAL_DESCRIPTION = "SignalDescription"
STATE_BREAKPOINT_IDS = "BPs"
STATE_PC_ERROR = "PCError"

# Boolean - true if the context is running in reverse
STATE_REVERSING = "Reversing"

# Optional parameters of resume command.
# Integer - starting address of step range, inclusive */
RP_RANGE_START = "RangeStart"

# Integer - ending address of step range, exclusive */
RP_RANGE_END = "RangeEnd"


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

    def getContext(self, contextID, done):
        """
        Retrieve context properties for given context ID.

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

    def getChildren(self, parent_context_id, 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 done - callback interface called when operation is completed.
        """
        raise NotImplementedError("Abstract method")

    def addListener(self, listener):
        """
        Add run control event listener.
        @param listener - run control event listener to add.
        """
        raise NotImplementedError("Abstract method")

    def removeListener(self, listener):
        """
        Remove run control event listener.
        @param listener - run control event listener to remove.
        """
        raise NotImplementedError("Abstract method")


class RunControlError(Exception):
    pass


class DoneGetState(object):
    def doneGetState(self, token, error, suspended, pc, reason, params):
        """
        Called when getState command execution is complete.
        @param token - pending command handle.
        @param error - command execution error or None.
        @param suspended - true if the context is suspended
        @param pc - program counter of the context (if suspended).
        @param reason - suspend reason (if suspended), see REASON_*.
        @param params - additional target specific data about context state,
                        see STATE_*.
        """
        pass


class DoneCommand(object):
    def doneCommand(self, token, error):
        """
        Called when run control command execution is complete.
        @param token - pending command handle.
        @param error - command execution error or None.
        """
        pass


class DoneGetContext(object):
    "Client callback 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 callback 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 RunControlContext(object):
    """
    A context corresponds to an execution thread, process, address space, etc.
    A context can belong to a parent context. Contexts hierarchy can be simple
    plain list or it can form a tree. It is up to target agent developers to
    choose layout that is most descriptive for a given target. Context IDs are
    valid across all services. In other words, all services access same
    hierarchy of contexts, with same IDs, however, each service accesses its
    own subset of context's attributes and functionality, which is relevant to
    that service.
    """
    def __init__(self, props):
        self._props = props or {}

    def __str__(self):
        return "[Run Control 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 getProcessID(self):
        """
        Retrieve context process ID.
        Same as getProperties().get('ProcessID')
        """
        return self._props.get(PROP_PROCESS_ID)

    def getCreatorID(self):
        """
        Retrieve context creator ID.
        Same as getProperties().get('CreatorID')
        """
        return self._props.get(PROP_CREATOR_ID)

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

    def isContainer(self):
        """
        Utility method to read context property PROP_IS_CONTAINER.
        Executing resume or suspend command on a container causes all its
        children to resume or suspend.
        @return value of PROP_IS_CONTAINER.
        """
        return self._props.get(PROP_IS_CONTAINER)

    def hasState(self):
        """
        Utility method to read context property PROP_HAS_STATE.
        Only context that has a state can be resumed or suspended.
        @return value of PROP_HAS_STATE.
        """
        return self._props.get(PROP_HAS_STATE)

    def canSuspend(self):
        """
        Utility method to read context property PROP_CAN_SUSPEND.
        Value 'true' means suspend command is supported by the context,
        however the method does not check that the command can be executed
        successfully in the current state of the context. For example, the
        command still can fail if context is already suspended.
        @return value of PROP_CAN_SUSPEND.
        """
        return self._props.get(PROP_CAN_SUSPEND)

    def canResume(self, mode):
        """
        Utility method to read a 'mode' bit in context property
        PROP_CAN_RESUME.
        Value 'true' means resume command is supported by the context, however
        the method does not check that the command can be executed successfully
        in the current state of the context. For example, the command still can
        fail if context is already resumed.
        @param mode - resume mode, see RM_*.
        @return value of requested bit of PROP_CAN_RESUME.
        """
        b = self._props.get(PROP_CAN_RESUME) or 0
        return (b & (1 << mode)) != 0

    def canCount(self, mode):
        """
        Utility method to read a 'mode' bit in context property PROP_CAN_COUNT.
        Value 'true' means resume command with count other then 1 is supported
        by the context, however the method does not check that the command can
        be executed successfully in the current state of the context. For
        example, the command still can fail if context is already resumed.
        @param mode - resume mode, see RM_*.
        @return value of requested bit of PROP_CAN_COUNT.
        """
        b = self._props.get(PROP_CAN_COUNT) or 0
        return (b & (1 << mode)) != 0

    def canTerminate(self):
        """
        Utility method to read context property PROP_CAN_TERMINATE.
        Value 'true' means terminate command is supported by the context,
        however the method does not check that the command can be executed
        successfully in the current state of the context. For example, the
        command still can fail if context is already exited.
        @return value of PROP_CAN_SUSPEND.
        """
        return self._props.get(PROP_CAN_TERMINATE)

    def getRCGroup(self):
        """
        Utility method to read context property PROP_RC_GROUP -
        context ID of a run control group that contains the context.
        Members of same group are always suspended and resumed together:
        resuming/suspending a context resumes/suspends all members of the
        group.
        @return value of PROP_RC_GROUP.
        """
        return self._props.get(PROP_RC_GROUP)

    def getBPGroup(self):
        """
        Utility method to read context property PROP_BP_GROUP - context ID of a
        breakpoints group that contains the context.

        Members of same group share same breakpoint instances:
        a breakpoint is planted once for the group, no need to plant the
        breakpoint for each member of the group

        @return value of PROP_BP_GROUP or @b None if the context does not
                support breakpoints.
        """
        return self._props.get(PROP_BP_GROUP)

    def getSymbolsGroup(self):
        """
        Utility method to read context property PROP_SYMBOLS_GROUP - context ID
        of a symbols group that contains the context.

        Members of a symbols group share same symbol reader configuration
        settings, like user defined memory map entries and source lookup info.

        @return value of PROP_SYMBOLS_GROUP or @b None if the context is not a
                member of a symbols group.
        """
        return self._props.get(PROP_SYMBOLS_GROUP)

    def canDetach(self):
        """
        Utility method to read context property PROP_CAN_DETACH.
        Value 'true' means detach command is supported by the context, however
        the method does not check that the command can be executed successfully
        in the current state of the context. For example, the command still can
        fail if the context already has exited.
        @return value of PROP_CAN_DETACH.
        """
        return self._props.get(PROP_CAN_DETACH)

    def detach(self, done):
        """
        Send a command to detach a context.

        @param done - command result call back object.

        @return pending command handle, can be used to cancel the command
        """
        raise NotImplementedError("Abstract method")

    def getState(self, done):
        """
        Send a command to retrieve current state of a context.
        @param done - command result call back object.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def suspend(self, done):
        """
        Send a command to suspend a context.
        Also suspends children if context is a container.
        @param done - command result call back object.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

#    def resume(self, mode, count, done):
#        """
#        Send a command to resume a context.
#        Also resumes children if context is a container.
#        @param mode - defines how to resume the context, see RM_*.
#        @param count - if mode implies stepping, defines how many steps to
#                       perform.
#        @param done - command result call back object.
#        @return pending command handle, can be used to cancel the command.
#        """
#        raise NotImplementedError("Abstract method")

    def resume(self, mode, count, params, done):
        """
        Send a command to resume a context.
        Also resumes children if context is a container.
        @param mode - defines how to resume the context, see RM_*.
        @param count - if mode implies stepping, defines how many steps to
                       perform.
        @param params - resume parameters, for example, step range definition,
                        see RP_*.
        @param done - command result call back object.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")

    def terminate(self, done):
        """
        Send a command to terminate a context.
        @param done - command result call back object.
        @return pending command handle, can be used to cancel the command.
        """
        raise NotImplementedError("Abstract method")


class RunControlListener(object):
    "Service events listener interface."

    def contextAdded(self, contexts):
        """
        Called when new contexts are created.
        @param contexts - array of new context properties.
        """
        pass

    def contextChanged(self, contexts):
        """
        Called when a context properties changed.
        @param contexts - array of new context properties.
        """
        pass

    def contextRemoved(self, context_ids):
        """
        Called when contexts are removed.
        @param context_ids - array of removed context IDs.
        """
        pass

    def contextSuspended(self, context, pc, reason, params):
        """
        Called when a thread is suspended.
        @param context - ID of a context that was suspended.
        @param pc - program counter of the context, can be None.
        @param reason - human readable description of suspend reason.
        @param params - additional, target specific data about suspended
                        context.
        """
        pass

    def contextResumed(self, context):
        """
        Called when a thread is resumed.
        @param context - ID of a context that was resumed.
        """
        pass

    def containerSuspended(self, context, pc, reason, params, suspended_ids):
        """
        Called when target simultaneously suspends multiple threads in a
        container (process, core, etc.).

        @param context - ID of a context responsible for the event. It can be
                         container ID or any one of container children, for
                         example, it can be thread that hit "suspend all"
                         breakpoint. Client expected to move focus (selection)
                         to this context.
        @param pc - program counter of the context.
        @param reason - suspend reason, see REASON_*.
        @param params - additional target specific data about context state,
                        see STATE_*.
        @param suspended_ids - full list of all contexts that were suspended.
        """
        pass

    def containerResumed(self, context_ids):
        """
        Called when target simultaneously resumes multiple threads in a
        container (process, core, etc.).

        @param context_ids - full list of all contexts that were resumed.
        """
        pass

    def contextException(self, context, msg):
        """
        Called when an exception is detected in a target thread.
        @param context - ID of a context that caused an exception.
        @param msg - human readable description of the exception.
        """
        pass

Back to the top