Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f09ba812ea9175455c7bd4954b011b3c048a77f (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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
# *****************************************************************************
# * Copyright (c) 2011, 2013-2014 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
# *****************************************************************************

"""Breakpoint is represented by unique identifier and set of properties.

.. |add| replace:: :meth:`BreakpointsService.add`
.. |addListener| replace:: :meth:`BreakpointsService.addListener`
.. |change| replace:: :meth:`BreakpointsService.change`
.. |contextAdded| replace:: :meth:`BreakpointsListener.contextAdded`
.. |contextChanged| replace:: :meth:`BreakpointsListener.contextChanges`
.. |contextRemoved| replace:: :meth:`BreakpointsListener.contextRemoved`
.. |disable| replace:: :meth:`BreakpointsService.disable`
.. |enable| replace:: :meth:`BreakpointsService.enable`
.. |getCapabilities| replace:: :meth:`BreakpointsService.getCapabilities`
.. |getIDs| replace:: :meth:`BreakpointsService.getIDs`
.. |getProperties| replace:: :meth:`BreakpointsService.getProperties`
.. |getStatus| replace:: :meth:`BreakpointsService.getStatus`
.. |remove| replace:: :meth:`BreakpointsService.remove`
.. |removeListener| replace:: :meth:`BreakpointsService.removeListener`
.. |set| replace:: :meth:`BreakpointsService.set`
.. |BreakpointInstance| replace:: :class:`BreakpointInstance`
.. |BreakpointsListener| replace:: :class:`BreakpointsListener`
.. |BreakpointStatus| replace:: :class:`BreakpointStatus`
.. |DoneCommand| replace:: :class:`DoneCommand`
.. |DoneGetCapabilities| replace:: :class:`DoneGetCapabilities`
.. |DoneGetIDs| replace:: :class:`DoneGetIDs`
.. |DoneGetProperties| replace:: :class:`DoneGetProperties`
.. |DoneGetStatus| replace:: :class:`DoneGetStatus`

A breakpoint identifier (String id) needs to be unique across all hosts and
targets.

Breakpoint properties (|dict|) is extendible dictionary of named attributes,
which define breakpoint location and behavior. This module defines some common
attribute names (see `Breakpoint Properties`_), host tools and target agents
may support additional attributes.

For each breakpoint a target agent maintains another extendible collection of
named attributes: breakpoint status (see `Status`_). While breakpoint
properties are persistent and represent user input, breakpoint status reflects
dynamic target agent reports about breakpoint current state, like actual
addresses where breakpoint is planted or planting errors.

Breakpoint Properties
---------------------
Properties
^^^^^^^^^^
+-----------------------+--------------+--------------------------------------+
| Name                  | Type         | Description                          |
+=======================+==============+======================================+
| PROP_ACCESS_MODE      | |int|        | The access mode that will trigger    |
|                       |              | the breakpoint. Access mode can be a |
|                       |              | bitwise OR of the values defined in  |
|                       |              | `Access Modes`_.                     |
+-----------------------+--------------+--------------------------------------+
| PROP_CLIENT_DATA      | |dict|       | Properties set by the client.        |
+-----------------------+--------------+--------------------------------------+
| PROP_COLUMN           | |int|        | The source code column number of     |
|                       |              | breakpoint location.                 |
+-----------------------+--------------+--------------------------------------+
| PROP_CONDITION        | |basestring| | Expression that must evaluate to     |
|                       |              | true before the breakpoint is        |
|                       |              | triggered.                           |
+-----------------------+--------------+--------------------------------------+
| PROP_CONTEXT_IDS      | |list|       | Context identifiers for which this   |
|                       |              | breakpoint should be installed.      |
+-----------------------+--------------+--------------------------------------+
| PROP_CONTEXT_NAMES    | |list|       | Contexts names (such as a            |
|                       |              | process/thread name) for which this  |
|                       |              | breakpoint should be installed.      |
+-----------------------+--------------+--------------------------------------+
| PROP_CONTEXT_QUERY    | |basestring| | See :mod:`tcf.services.contextquery` |
+-----------------------+--------------+--------------------------------------+
| PROP_ENABLED          | |bool|       | If true, the breakpoint is enabled.  |
+-----------------------+--------------+--------------------------------------+
| PROP_EVENT_ARGS       | |basestring| | Eventpoint arguments.                |
+-----------------------+--------------+--------------------------------------+
| PROP_EVENT_TYPE       | |basestring| | Breakpoint event type.               |
+-----------------------+--------------+--------------------------------------+
| PROP_EXECUTABLE_PATHS | |list|       | All the target executable paths for  |
|                       |              | which this breakpoint should be      |
|                       |              | installed.                           |
+-----------------------+--------------+--------------------------------------+
| PROP_FILE             | |basestring| | The source code file name of         |
|                       |              | breakpoint location.                 |
+-----------------------+--------------+--------------------------------------+
| PROP_ID               | |basestring| | Breakpoint ID. This is the only      |
|                       |              | required property.                   |
+-----------------------+--------------+--------------------------------------+
| PROP_IGNORE_COUNT     | |int|        | Number of times this breakpoint is   |
|                       |              | to be ignored before it is triggered.|
|                       |              | The ignore count is tested after all |
|                       |              | other Location and Condition         |
|                       |              | properties are validated.            |
+-----------------------+--------------+--------------------------------------+
| PROP_LINE             | |int|        | The source code line number of       |
|                       |              | breakpoint location.                 |
+-----------------------+--------------+--------------------------------------+
| PROP_LOCATION         | |basestring| | Defines location of the breakpoint.  |
|                       |              | The expression evaluates either to a |
|                       |              | memory address or a register         |
|                       |              | location.                            |
+-----------------------+--------------+--------------------------------------+
| PROP_MASK             | |int|        | A mask which is bitwise ANDed with   |
|                       |              | the value accessed.                  |
+-----------------------+--------------+--------------------------------------+
| PROP_PATTERN          | |int|        | A mask value which may be further    |
|                       |              | refined with a mask.                 |
+-----------------------+--------------+--------------------------------------+
| PROP_SCALE            | |basestring| | The scale for the time value. See    |
|                       |              | `Time Scales`_.                      |
+-----------------------+--------------+--------------------------------------+
| PROP_SIZE             | |int|        | The number of bytes starting at      |
|                       |              | address given by the location        |
|                       |              | expression.                          |
+-----------------------+--------------+--------------------------------------+
| PROP_STOP_GROUP       | |list|       | TCF Context identifiers representing |
|                       |              | contexts to be stopped when this     |
|                       |              | breakpoint is triggered. This is an  |
|                       |              | *Action* property that is used to    |
|                       |              | stop contexts in addition to the one |
|                       |              | that triggered the breakpoint.       |
+-----------------------+--------------+--------------------------------------+
| PROP_TEMPORARY        | |bool|       | If set, results in the breakpoint    |
|                       |              | being removed after it is triggered  |
|                       |              | once. The default value for this     |
|                       |              | property is **False**.               |
+-----------------------+--------------+--------------------------------------+
| PROP_TIME             | |int|        | The time value in the execution of   |
|                       |              | the program at which to set the      |
|                       |              | breakpoint.                          |
+-----------------------+--------------+--------------------------------------+
| PROP_TYPE             | |basestring| | The breakpoint type. See `Types`_.   |
+-----------------------+--------------+--------------------------------------+
| PROP_UNITS            | |basestring| | The units for the time value. See    |
|                       |              | `Time Units`_.                       |
+-----------------------+--------------+--------------------------------------+

Access Modes
^^^^^^^^^^^^
According to its **PROP_ACCESS_MODE** property, the breakpoints is triggered
on one of these access modes:

+--------------------+----------+---------------------------------------------+
| Name               | Value    | Description                                 |
+====================+==========+=============================================+
| ACCESSMODE_CHANGE  | 0x08     | Breakpoint is triggered by a data change    |
|                    |          | (not an explicit write) at the breakpoint   |
|                    |          | location.                                   |
+--------------------+----------+---------------------------------------------+
| ACCESSMODE_EXECUTE | 0x04     | Breakpoint is triggered by an instruction   |
|                    |          | execution at the breakpoint location.       |
|                    |          | Whether the breakpoint is triggered before  |
|                    |          | or after the instruction execution depends  |
|                    |          | on the target support for this mode. This is|
|                    |          | the default for Line and Address            |
|                    |          | breakpoints.                                |
+--------------------+----------+---------------------------------------------+
| ACCESSMODE_READ    | 0x01     | Breakpoints is triggered by a read from the |
|                    |          | breakpoint location.                        |
+--------------------+----------+---------------------------------------------+
| ACCESSMODE_WRITE   | 0x02     | Breakpoint is triggered by a write to the   |
|                    |          | breakpoint location.                        |
+--------------------+----------+---------------------------------------------+

Time Scales
^^^^^^^^^^^
+--------------------+--------------------------------------------------------+
| Name               | Description                                            |
+====================+========================================================+
| TIMESCALE_ABSOLUTE | Time value in the absolute time scale.                 |
+--------------------+--------------------------------------------------------+
| TIMESCALE_RELATIVE | Time value in the relative time scale. This is the     |
|                    | default value for this property. In the relative time  |
|                    | scale, the Time property may have a negative value.    |
+--------------------+--------------------------------------------------------+

Time Units
^^^^^^^^^^
+----------------------------+------------------------------------------------+
| Name                       | Description                                    |
+============================+================================================+
| TIMEUNIT_CYCLE_COUNT       | Time value in cycles. This is the default type.|
+----------------------------+------------------------------------------------+
| TIMEUNIT_INSTRUCTION_COUNT | Time value in instructions.                    |
+----------------------------+------------------------------------------------+
| TIMEUNIT_NSECS             | Time value in nano seconds.                    |
+----------------------------+------------------------------------------------+

Types
^^^^^
+---------------+-------------------------------------------------------------+
| Name          | Description                                                 |
+===============+=============================================================+
| TYPE_HARDWARE | Hardware breakpoint type.                                   |
+---------------+-------------------------------------------------------------+
| TYPE_AUTO     | Auto breakpoint type.                                       |
+---------------+-------------------------------------------------------------+
| TYPE_SOFTWARE | Software breakpoint type.                                   |
+---------------+-------------------------------------------------------------+


Status
^^^^^^
+------------------+--------------+-------------------------------------------+
| Name             | Type         | Description                               |
+==================+==============+===========================================+
| STATUS_COLUMN    | |int|        | Breakpoint column.                        |
+------------------+--------------+-------------------------------------------+
| STATUS_ERROR     | |basestring| | Breakpoint status error.                  |
+------------------+--------------+-------------------------------------------+
| STATUS_FILE      | |basestring| | Breakpoint file.                          |
+------------------+--------------+-------------------------------------------+
| STATUS_INSTANCES | |list|       | Breakpoint status instance. See           |
|                  |              | `Status Instances`_.                      |
+------------------+--------------+-------------------------------------------+
| STATUS_LINE      | |int|        | Breakpoint line.                          |
+------------------+--------------+-------------------------------------------+

Status Instances
^^^^^^^^^^^^^^^^
+-------------------------+--------------+------------------------------------+
| Name                    | Type         | Description                        |
+=========================+==============+====================================+
| INSTANCE_ADDRESS        | |int|        | Breakpoint address.                |
+-------------------------+--------------+------------------------------------+
| INSTANCE_CONTEXT        | |basestring| | Breakpoint context.                |
+-------------------------+--------------+------------------------------------+
| INSTANCE_ERROR          | |basestring| | Breakpoint status instance error.  |
+-------------------------+--------------+------------------------------------+
| INSTANCE_HIT_COUNT      | |int|        | Breakpoint hit count.              |
+-------------------------+--------------+------------------------------------+
| INSTANCE_MEMORY_CONTEXT | |basestring| | Breakpoint memory context.         |
+-------------------------+--------------+------------------------------------+
| INSTANCE_SIZE           | |int|        | Breakpoint size.                   |
+-------------------------+--------------+------------------------------------+
| INSTANCE_TYPE           | |basestring| | Breakpoint type.                   |
+-------------------------+--------------+------------------------------------+

Service Capabilities
^^^^^^^^^^^^^^^^^^^^
All capabilities are of |bool| type, but the **CAPABILITY_CONTEXT_ID** which is
of |basestring| type.

+----------------------------+------------------------------------------------+
+ Name                       | Description                                    |
+============================+================================================+
| CAPABILITY_ACCESS_MODE     | If **True**, **PROP_ACCESS_MODE** breakpoint   |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_BREAKPOINT_TYPE | If **True**, **PROP_TYPE** breakpoint property |
|                            | is supported.                                  |
+----------------------------+------------------------------------------------+
| CAPABILITY_CLIENT_DATA     | If **True**, **PROP_CLIENT_DATA** breakpoint   |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_CONDITION       | If **True**, **PROP_CONDITION** breakpoint     |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_CONTEXT_ID      | ID of a context that was used to query         |
|                            | capabilities.                                  |
+----------------------------+------------------------------------------------+
| CAPABILITY_CONTEXT_IDS     | If **True**, **PROP_CONTEXT_IDS** breakpoint   |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_CONTEXT_NAMES   | If **True**, **PROP_CONTEXT_NAMES** breakpoint |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_CONTEXT_QUERY   | If **True**, **PROP_CONTEXT_QUERY** breakpoint |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_FILE_LINE       | If **True**, **PROP_FILE**, **PROP_LINE** and  |
|                            | **PROP_COLUMN** breakpoint properties are      |
|                            | supported.                                     |
+----------------------------+------------------------------------------------+
| CAPABILITY_FILE_MAPPING    | If **True**, **PROP_FILE_MAPPING** breakpoint  |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_HAS_CHILDREN    | If **True**, children of the context can have  |
|                            | different capabilities.                        |
+----------------------------+------------------------------------------------+
| CAPABILITY_IGNORE_COUNT    | If **True**, **PROP_IGNORE_COUNT** breakpoint  |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_LOCATION        | If **True**, **PROP_LOCATION** breakpoint      |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_STOP_GROUP      | If **True**, **PROP_STOP_GROUP** breakpoint    |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+
| CAPABILITY_TEMPORARY       | If **True**, **PROP_TEMPORARY** breakpoint     |
|                            | property is supported.                         |
+----------------------------+------------------------------------------------+

Service Methods
---------------
.. autodata:: NAME
.. autoclass:: BreakpointsService

add
^^^
.. automethod:: BreakpointsService.add

addListener
^^^^^^^^^^^
.. automethod:: BreakpointsService.addListener

change
^^^^^^
.. automethod:: BreakpointsService.change

disable
^^^^^^^
.. automethod:: BreakpointsService.disable

enable
^^^^^^
.. automethod:: BreakpointsService.enable

getCapabilities
^^^^^^^^^^^^^^^
.. automethod:: BreakpointsService.getCapabilities

getIDs
^^^^^^
.. automethod:: BreakpointsService.getIDs

getName
^^^^^^^
.. automethod:: BreakpointsService.getName

getProperties
^^^^^^^^^^^^^
.. automethod:: BreakpointsService.getProperties

getStatus
^^^^^^^^^
.. automethod:: BreakpointsService.getStatus

remove
^^^^^^
.. automethod:: BreakpointsService.remove

removeListener
^^^^^^^^^^^^^^
.. automethod:: BreakpointsService.removeListener

set
^^^
.. automethod:: BreakpointsService.set

Callback Classes
----------------
DoneCommand
^^^^^^^^^^^
.. autoclass:: DoneCommand
    :members:

DoneGetCapabilities
^^^^^^^^^^^^^^^^^^^
.. autoclass:: DoneGetCapabilities
    :members:

DoneGetIDs
^^^^^^^^^^
.. autoclass:: DoneGetIDs
    :members:

DoneGetProperties
^^^^^^^^^^^^^^^^^
.. autoclass:: DoneGetProperties
    :members:

DoneGetStatus
^^^^^^^^^^^^^^^^^^^
.. autoclass:: DoneGetStatus
    :members:

Listener
--------
.. autoclass:: BreakpointsListener
    :members:

Helper Classes
--------------
BreakpointInstance
^^^^^^^^^^^^^^^^^^
.. autoclass:: BreakpointInstance
    :members:

BreakpointStatus
^^^^^^^^^^^^^^^^
.. autoclass:: BreakpointStatus
    :members:
"""

from .. import services

# Service name.
NAME = "Breakpoints"
"""Breakpoints service name."""

# Breakpoint property names.
PROP_ID = "ID"
PROP_ENABLED = "Enabled"
PROP_TYPE = "BreakpointType"
PROP_CONTEXT_NAMES = "ContextNames"
PROP_CONTEXT_IDS = "ContextIds"
PROP_EXECUTABLE_PATHS = "ExecPaths"
PROP_CONTEXT_QUERY = "ContextQuery"
PROP_LOCATION = "Location"
PROP_SIZE = "Size"
PROP_ACCESS_MODE = "AccessMode"
PROP_FILE = "File"
PROP_LINE = "Line"
PROP_COLUMN = "Column"
PROP_PATTERN = "MaskValue"
PROP_MASK = "Mask"
PROP_STOP_GROUP = "StopGroup"
PROP_IGNORE_COUNT = "IgnoreCount"
PROP_TIME = "Time"
PROP_SCALE = "TimeScale"
PROP_UNITS = "TimeUnits"
PROP_CONDITION = "Condition"
PROP_TEMPORARY = "Temporary"
PROP_EVENT_TYPE = "EventType"
PROP_EVENT_ARGS = "EventArgs"
PROP_CLIENT_DATA = "ClientData"

# Deprecated
PROP_CONTEXTNAMES = "ContextNames"
PROP_CONTEXTIDS = "ContextIds"
PROP_EXECUTABLEPATHS = "ExecPaths"
PROP_ACCESSMODE = "AccessMode"
PROP_IGNORECOUNT = "IgnoreCount"


# BreakpointType values
TYPE_SOFTWARE = "Software"
TYPE_HARDWARE = "Hardware"
TYPE_AUTO = "Auto"

# AccessMode values
ACCESSMODE_READ = 0x01
ACCESSMODE_WRITE = 0x02
ACCESSMODE_EXECUTE = 0x04
ACCESSMODE_CHANGE = 0x08

# TimeScale values
TIMESCALE_RELATIVE = "Relative"
TIMESCALE_ABSOLUTE = "Absolute"

# TimeUnits values
TIMEUNIT_NSECS = "Nanoseconds"
TIMEUNIT_CYCLE_COUNT = "CycleCount"
TIMEUNIT_INSTRUCTION_COUNT = "InstructionCount"

# Breakpoint status field names.
STATUS_INSTANCES = "Instances"
STATUS_ERROR = "Error"
STATUS_FILE = "File"
STATUS_LINE = "Line"
STATUS_COLUMN = "Column"

# Breakpoint instance field names.
INSTANCE_ERROR = "Error"
INSTANCE_CONTEXT = "LocationContext"
INSTANCE_ADDRESS = "Address"
INSTANCE_SIZE = "Size"
INSTANCE_TYPE = "BreakpointType"
INSTANCE_MEMORY_CONTEXT = "MemoryContext"
INSTANCE_HIT_COUNT = "HitCount"

# Breakpoint service capabilities.
CAPABILITY_CONTEXT_ID = "ID"
CAPABILITY_HAS_CHILDREN = "HasChildren"
CAPABILITY_BREAKPOINT_TYPE = "BreakpointType"
CAPABILITY_LOCATION = "Location"
CAPABILITY_CONDITION = "Condition"
CAPABILITY_FILE_LINE = "FileLine"
CAPABILITY_FILE_MAPPING = "FileMapping"
CAPABILITY_CONTEXT_IDS = "ContextIds"
CAPABILITY_CONTEXT_NAMES = "ContextNames"
CAPABILITY_CONTEXT_QUERY = "ContextQuery"
CAPABILITY_STOP_GROUP = "StopGroup"
CAPABILITY_TEMPORARY = "Temporary"
CAPABILITY_IGNORE_COUNT = "IgnoreCount"
CAPABILITY_ACCESS_MODE = "AccessMode"
CAPABILITY_CLIENT_DATA = "ClientData"

# Deprecated
CAPABILITY_CONTEXTNAMES = "ContextNames"
CAPABILITY_CONTEXTIDS = "ContextIds"
CAPABILITY_IGNORECOUNT = "IgnoreCount"
CAPABILITY_ACCESSMODE = "AccessMode"


class BreakpointsService(services.Service):
    """TCF Breakpoints service interface."""

    def getName(self):
        """Get this service name.

        :returns: A |basestring| representing this service name, which is the
                  value of :const:`NAME`
        """
        return NAME

    def set(self, properties, done):  # @ReservedAssignment
        """Download breakpoints data to target agent.

        The command is intended to be used only to initialize target
        breakpoints table when communication channel is open. After that, host
        should notify target about (incremental) changes in breakpoint data by
        sending |add|, |change| and |remove| commands.

        :param properties: List of breakpoints to set.
        :type properties: |list|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def add(self, properties, done):
        """Called when breakpoint is added into breakpoints table.

        :param properties: Breakpoint properties. See `Properties`_.
        :type properties: |dict|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def change(self, properties, done):
        """Called when breakpoint properties are changed.

        :param properties: Breakpoint properties. See `Properties`_.
        :type properties: |dict|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def enable(self, ids, done):
        """Tell target to change (only) **PROP_ENABLED** breakpoint property to
        **True**.

        See `Properties`_ for **PROP_ENABLED** description.

        :param ids: A list of enabled breakpoint identifiers.
        :type ids: |list| or |tuple| of |basestring|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def disable(self, ids, done):
        """Tell target to change (only) **PROP_ENABLED** breakpoint property to
        **False**.

        See `Properties`_ for **PROP_ENABLED** description.

        :param ids: A list of disabled breakpoint identifiers.
        :type ids: |list| or |tuple| of |basestring|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def remove(self, ids, done):
        """Tell target to remove breakpoints.

        :param id: unique breakpoint identifier.
        :type id: |basestring|
        :param done: Command result call back object.
        :type done: |DoneCommand|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def getIDs(self, done):
        """Upload IDs of breakpoints known to target agent.

        :param done: Command result call back object.
        :type done: |DoneGetIDs|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def getProperties(self, bpID, done):
        """Upload properties of given breakpoint from target agent breakpoint
        table.

        :param bpID: Unique breakpoint identifier.
        :type bpID: |basestring|
        :param done: Command result call back object.
        :type done: |DoneGetProperties|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def getStatus(self, bpID, done):
        """Upload status of given breakpoint from target agent.

        :param bpID: Unique breakpoint identifier.
        :type bpID: |basestring|
        :param done: Command result call back object.
        :type done: |DoneGetStatus|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def getCapabilities(self, bpID, done):
        """Report breakpoint service capabilities to clients so they can adjust
        to different implementations of the service.

        When called with a **None** context ID the global capabilities are
        returned, otherwise context specific capabilities are returned. A
        special capability property is used to indicate that all child contexts
        have the same capabilities.

        :param bpID: A context ID or **None**.
        :type bpID: |basestring| or **None**
        :param done: command result call back object.
        :type done: |DoneGetCapabilities|

        :returns: Pending command handle.
        """
        raise NotImplementedError("Abstract method")

    def addListener(self, listener):
        """Add breakpoints service event listener.

        :param listener: Object that implements |BreakpointsListener| interface
                         to add to the channel.
        :type listener: |BreakpointsListener|
        """
        raise NotImplementedError("Abstract method")

    def removeListener(self, listener):
        """Remove breakpoints service event listener.

        :param listener: Listener to remove from this breakpoints service
                         channel.
        :type listener: |BreakpointsListener|
        """
        raise NotImplementedError("Abstract method")


class BreakpointInstance(object):
    """A class to represent a breakpoint status instances.

    :param props: The properties to initialise the breakpoint status instance
                  with. See `Status Instances`_.
    :type props: |dict|
    """
    def __init__(self, props):
        self._properties = props or {}

    def __repr__(self):
        return self.__class__.__name__ + '(' + str(self._properties) + ')'

    def __str__(self):
        res = self.__class__.__name__ + ' ['
        res += 'Context=' + self.context
        res += ', ' + INSTANCE_ADDRESS + '=' + str(self.address)
        res += ', ' + INSTANCE_HIT_COUNT + '=' + str(self.hitcount)
        res += ', ' + INSTANCE_TYPE + '=' + str(self.type)
        res += ', ' + INSTANCE_SIZE + '=' + str(self.size)
        res += ', ' + INSTANCE_MEMORY_CONTEXT + '=' + str(self.memorycontext)
        res += ', ' + INSTANCE_ERROR + '=' + str(self.error)
        res += ']'
        return res

    @property
    def address(self):
        """Breakpoint status instance address.

        :returns: An |int| representing the address this breakpoint status
                  instance occurred at, or **None** if unknown.
        """
        return self._properties.get(INSTANCE_ADDRESS, None)

    @property
    def context(self):
        """ID of the context this Breakpoint status instance occurred for.

        :returns: A |basestring| representing the ID of the context this
                  breakpoint status instance occurred for, or **None**
                  if unknown.
        """
        return self._properties.get(INSTANCE_CONTEXT, None)

    @property
    def error(self):
        """Potential error for this Breakpoint status instance.

        :returns: A |basestring| representing the error for this breakpoint
                  status instance, or **None** if there is no error.
        """
        return self._properties.get(INSTANCE_ERROR, None)

    @property
    def hitcount(self):
        """Number of breakpoint hit count for this breakpoint status instance.

        :returns: An |int| representing the number of times this breakpoint
                  status instance has been hit, or **None** if unknown.
        """
        return self._properties.get(INSTANCE_HIT_COUNT, None)

    @property
    def memorycontext(self):
        """ID of the memory context this Breakpoint status instance occurred
        for.

        :returns: A |basestring| representing the ID of the memory context this
                  breakpoint status instance occurred for, or **None**
                  if unknown.
        """
        return self._properties.get(INSTANCE_MEMORY_CONTEXT, None)

    @property
    def size(self):
        """The size of this breakpoint.

        :returns: An |int| representing the size of the breakpoint this status
                  instance occured for, or **None**
                  if unknown.
        """
        return self._properties.get(INSTANCE_SIZE, None)

    @property
    def type(self):
        """The type of this breakpoint.

        See `Types`_.

        :returns: A |basestring| representing the type of the breakpoint this
                  status instance occured for, or **None** if unknown.

        .. seealso:: `Types`_
        """
        return self._properties.get(INSTANCE_SIZE, None)


class BreakpointStatus(object):
    """A class to represent a breakpoint status.

    :param props: The properties to initialise the breakpoint status with.
                  See `Status`_.
    :type props: |dict|
    """
    def __init__(self, props):
        self._properties = props or {}
        iprops = self._properties.get(STATUS_INSTANCES, [])
        self._instances = []
        for iprop in iprops:
            self._instances.append(BreakpointInstance(iprop))

    def __repr__(self):
        return self.__class__.__name__ + '(' + str(self._properties) + ')'

    def __str__(self):
        res = self.__class__.__name__ + ' ['
        res += STATUS_FILE + '=' + str(self.file)
        res += ', ' + STATUS_LINE + '=' + str(self.line)
        res += ', ' + STATUS_COLUMN + '=' + str(self.column)
        res += ', ' + STATUS_ERROR + '=' + str(self.error)
        res += ', ' + STATUS_INSTANCES + '=['
        firstInstance = True
        for instance in self._instances:
            if not firstInstance:
                res += ', '
            res += str(instance)
            firstInstance = False
        res += ']'
        res += ']'
        return res

    @property
    def column(self):
        """Column in *file* the breakpoint is planted at.

        :returns: An |int| representing the column at which this breakpoint
                  status occurred in *file*, or **None** if unknown.
        """
        return self._properties.get(STATUS_COLUMN, None)

    @property
    def error(self):
        """Breakpoint status error.

        A breakpoint status may have an error.

        :returns: A |basestring| representing this breakpoint status error, or
                  **None**.
        """
        return self._properties.get(STATUS_ERROR, None)

    @property
    def file(self):
        """File the breakpoint is planted in.

        :returns: A |basestring| representing the path of the file the
                  breakpoint is planted in, or **None** if the file is not
                  known, or unreachable.
        """
        return self._properties.get(STATUS_FILE, None)

    @property
    def instances(self):
        """Breakpoint status instances.

        :returns: A |tuple| of |BreakpointInstance| objects representing the
                  various instances of this breakpoint status.
        """
        return self._instances

    @property
    def line(self):
        """Line in *file* the breakpoint is planted at.

        :returns: An |int| representing the line at which this breakpoint
                  status occurred in *file*, or **None** if unknown.
        """
        return self._properties.get(STATUS_LINE, None)


class DoneCommand(object):
    """Call back interface for breakpoint service commands.

    ..seealso:: |add|, |change|, |disable|, |enable|, |remove|, |set|
    """

    def doneCommand(self, token, error):
        """Called when command is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        """
        pass


class DoneGetIDs(object):
    """Call back interface for |getIDs| command."""

    def doneGetIDs(self, token, error, ids):
        """Called when |getIDs| command is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param ids: IDs of breakpoints known to target agent.
        :type ids: |list| or |tuple| of |basestring|
        """
        pass


class DoneGetProperties(object):
    """Call back interface for |getProperties| command."""

    def doneGetProperties(self, token, error, properties):
        """Called when |getProperties| command is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param properties: Properties of the breakpoint.
        :type properties: |dict|

        .. seealso:: `Properties`_
        """
        pass


class DoneGetStatus(object):
    """Call back interface for :meth:`~BreakpointsService.getStatus` command.
    """
    def doneGetStatus(self, token, error, status):
        """Called when |getStatus| command is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param status: Status of the breakpoint.
        :type status: |BreakpointStatus|
        """
        pass


class DoneGetCapabilities(object):
    """Call back interface for |getCapabilities| command."""

    def doneGetCapabilities(self, token, error, capabilities):
        """Called when |getCapabilities| command is done.

        :param token: Pending command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param capabilities: Breakpoints service capabilities description.
        :type capabilities: |dict|
        """
        pass


class BreakpointsListener(object):
    """Breakpoints service events listener.

    .. note:: Note that |contextAdded|, |contextChanged| and |contextRemoved|
              events carry exactly same set of breakpoint properties that was
              sent by a client to a target. The purpose of these events is to
              let all clients know about breakpoints that were created by other
              clients.
    """

    def breakpointStatusChanged(self, bpID, status):
        """Called when breakpoint status changes.

        :param bpID: Unique breakpoint identifier.
        :type bpID: |basestring|
        :param status: Breakpoint status.
        :type status: |dict|
        """
        pass

    def contextAdded(self, bps):
        """Called when new breakpoints are added.

        :param bps: Array of breakpoints.
        :type bps: |list| or |tuple| of |dict|
        """
        pass

    def contextChanged(self, bps):
        """Called when breakpoint properties change.

        :param bps: Array of breakpoints.
        :type bps: |list| or |tuple| of |dict|
        """
        pass

    def contextRemoved(self, ids):
        """Called when breakpoints are removed.

        :param ids: Array of breakpoint IDs.
        :type ids: |list| of |basestring|
        """
        pass

Back to the top