1
1
import json
2
2
import sys
3
3
import threading
4
-
4
+ from nopdb import nopdb
5
5
from vertx import EventBus
6
6
7
- from nopdb import nopdb
8
7
from sourceplusplus .models .command .CommandType import CommandType
9
8
from sourceplusplus .models .command .LiveInstrumentCommand import LiveInstrumentCommand
10
9
from sourceplusplus .models .command .LiveInstrumentContext import LiveInstrumentContext
11
10
from sourceplusplus .models .instrument .LiveBreakpoint import LiveBreakpoint
12
11
from sourceplusplus .models .instrument .LiveLog import LiveLog
12
+ from sourceplusplus .models .instrument .LiveMeter import LiveMeter
13
13
from sourceplusplus .models .instrument .common .LiveInstrumentType import LiveInstrumentType
14
14
from sourceplusplus .models .instrument .common .LiveSourceLocation import LiveSourceLocation
15
15
@@ -25,55 +25,50 @@ def __init__(self, eb: EventBus):
25
25
LiveInstrumentRemote .dbg .start ()
26
26
threading .settrace (sys .gettrace ())
27
27
28
- def add_live_log (self , context : LiveInstrumentContext ):
29
- for i in context .instruments :
30
- live_log = LiveLog .from_json (i )
31
- bp = LiveInstrumentRemote .dbg .breakpoint (file = live_log .location .source , line = live_log .location .line )
32
- LiveInstrumentRemote .instruments [live_log .id ] = [bp , live_log ]
33
- bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
34
- "ContextReceiver.do_log('" + live_log .id + "',globals(),locals())" )
35
- self .eb .publish (address = "spp.platform.status.live-log-applied" , body = json .loads (i ))
36
-
37
- def remove_live_log (self , context : LiveInstrumentContext ):
38
- print ("Removing live log(s)" )
39
- for i in context .instruments :
40
- live_log = LiveLog .from_json (i )
41
- try :
42
- LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (live_log .id )[0 ]._handle )
43
- except KeyError :
44
- pass
45
- for i in context .locations :
46
- loc = LiveSourceLocation .from_json (i )
47
- delete = []
48
- for key , val in LiveInstrumentRemote .instruments .items ():
49
- if isinstance (val [1 ], LiveLog ) and val [1 ].location == loc :
50
- delete .append (key )
51
- for i in delete :
52
- del LiveInstrumentRemote .instruments [i ]
53
-
54
- def add_live_breakpoint (self , context : LiveInstrumentContext ):
55
- print ("Adding live breakpoint(s)" )
28
+ def add_live_instrument (self , context : LiveInstrumentContext , instrument_type : LiveInstrumentType ):
56
29
for i in context .instruments :
57
- live_bp = LiveBreakpoint .from_json (i )
58
- bp = LiveInstrumentRemote .dbg .breakpoint (file = live_bp .location .source , line = live_bp .location .line )
59
- LiveInstrumentRemote .instruments [live_bp .id ] = [bp , live_bp ]
60
- bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
61
- "ContextReceiver.do_breakpoint('" + live_bp .id + "',globals(),locals())" )
62
- self .eb .publish (address = "spp.platform.status.live-breakpoint-applied" , body = json .loads (i ))
30
+ if instrument_type == LiveInstrumentType .BREAKPOINT :
31
+ live_instrument = LiveBreakpoint .from_json (i )
32
+ elif instrument_type == LiveInstrumentType .LOG :
33
+ live_instrument = LiveLog .from_json (i )
34
+ else :
35
+ live_instrument = LiveMeter .from_json (i )
36
+ bp = LiveInstrumentRemote .dbg .breakpoint (
37
+ file = live_instrument .location .source ,
38
+ line = live_instrument .location .line
39
+ )
40
+ LiveInstrumentRemote .instruments [live_instrument .id ] = [bp , live_instrument ]
41
+ if instrument_type == LiveInstrumentType .BREAKPOINT :
42
+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
43
+ "ContextReceiver.apply_breakpoint('" + live_instrument .id + "',globals(),locals())" )
44
+ self .eb .publish (address = "spp.platform.status.live-breakpoint-applied" , body = json .loads (i ))
45
+ elif instrument_type == LiveInstrumentType .LOG :
46
+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
47
+ "ContextReceiver.apply_log('" + live_instrument .id + "',globals(),locals())" )
48
+ self .eb .publish (address = "spp.platform.status.live-log-applied" , body = json .loads (i ))
49
+ else :
50
+ bp .exec ("import sourceplusplus.control.ContextReceiver as ContextReceiver\n "
51
+ "ContextReceiver.apply_meter('" + live_instrument .id + "',globals(),locals())" )
52
+ self .eb .publish (address = "spp.platform.status.live-meter-applied" , body = json .loads (i ))
63
53
64
- def remove_live_breakpoint (self , context : LiveInstrumentContext ):
65
- print ("Removing live breakpoint (s)" )
54
+ def remove_live_instrument (self , context : LiveInstrumentContext , type : LiveInstrumentType ):
55
+ print ("Removing live instrument (s)" )
66
56
for i in context .instruments :
67
- live_bp = LiveBreakpoint .from_json (i )
57
+ if type == LiveInstrumentType .BREAKPOINT :
58
+ instrument = LiveBreakpoint .from_json (i )
59
+ elif type == LiveInstrumentType .LOG :
60
+ instrument = LiveLog .from_json (i )
61
+ else :
62
+ instrument = LiveMeter .from_json (i )
68
63
try :
69
- LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (live_bp .id )[0 ]._handle )
64
+ LiveInstrumentRemote .dbg .remove_callback (LiveInstrumentRemote .instruments .pop (instrument .id )[0 ]._handle )
70
65
except KeyError :
71
66
pass
72
67
for i in context .locations :
73
68
loc = LiveSourceLocation .from_json (i )
74
69
delete = []
75
70
for key , val in LiveInstrumentRemote .instruments .items ():
76
- if isinstance ( val [1 ], LiveBreakpoint ) and val [1 ].location == loc :
71
+ if val [1 ]. type == type and val [1 ].location == loc :
77
72
delete .append (key )
78
73
for i in delete :
79
74
del LiveInstrumentRemote .instruments [i ]
@@ -82,11 +77,10 @@ def handle_instrument_command(self, command: LiveInstrumentCommand, instrument_t
82
77
print ("Received command: " + command .command_type )
83
78
if command .command_type == CommandType .ADD_LIVE_INSTRUMENT :
84
79
if instrument_type == LiveInstrumentType .BREAKPOINT :
85
- self .add_live_breakpoint (command .context )
80
+ self .add_live_instrument (command .context , LiveInstrumentType .BREAKPOINT )
81
+ elif instrument_type == LiveInstrumentType .LOG :
82
+ self .add_live_instrument (command .context , LiveInstrumentType .LOG )
86
83
else :
87
- self .add_live_log (command .context )
84
+ self .add_live_instrument (command .context , LiveInstrumentType . METER )
88
85
elif command .command_type == CommandType .REMOVE_LIVE_INSTRUMENT :
89
- if instrument_type == LiveInstrumentType .BREAKPOINT :
90
- self .remove_live_breakpoint (command .context )
91
- else :
92
- self .remove_live_log (command .context )
86
+ self .remove_live_instrument (command .context , instrument_type )
0 commit comments